... | ... | @@ -7,8 +7,8 @@ To get started, create a folder called `led` in `src/shared/drivers`. |
|
|
In it, create a file called `SimpleLed.h` and write:
|
|
|
|
|
|
```cpp
|
|
|
/* Copyright (c) 2017 Skyward Experimental Rocketry
|
|
|
* Authors: YOUR_NAME_HERE
|
|
|
/* Copyright (c) <YEAR_HERE> Skyward Experimental Rocketry
|
|
|
* Author: <YOUR_NAME_HERE>
|
|
|
*
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
... | ... | @@ -22,16 +22,14 @@ In it, create a file called `SimpleLed.h` and write: |
|
|
*
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
* THE SOFTWARE.
|
|
|
*/
|
|
|
|
|
|
// Header guards : alternativeley use "#pragma once"
|
|
|
#ifndef SIMPLE_LED_H
|
|
|
#define SIMPLE_LED_H
|
|
|
#pragma once
|
|
|
|
|
|
/* Includes basic useful stuff, e.g. the miosix kernel*/
|
|
|
#include <Common.h>
|
... | ... | @@ -74,13 +72,11 @@ class SimpleLed |
|
|
bool state;
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif /* SIMPLE_LED_H */
|
|
|
```
|
|
|
|
|
|
Please note a few things that are part of our [coding standards](Coding-Guidelines):
|
|
|
- Copyright at the start (write your name in the authors and the right date)
|
|
|
- `#ifndef` instruction, to prevent multiple re-inclusions
|
|
|
- `#pragma once` directive, to prevent multiple re-inclusions
|
|
|
- `#include <Common.h>`, a bunch of useful includes :)
|
|
|
- `typedef miosix::Gpio<XXX, YYY>` is how GPIO pins are declared in Miosix: `<GPIOD_BASE, 14>` means pin `PD14` of the discovery board
|
|
|
- Comments on top of the class and before each function, with a description of the argument and/or the return value
|
... | ... | @@ -91,7 +87,7 @@ Now, create another file called `SimpleLed.cpp` in the same folder and add: |
|
|
|
|
|
```cpp
|
|
|
/* Copyright (c) <YEAR_HERE> Skyward Experimental Rocketry
|
|
|
* Authors: <YOUR_NAME_HERE>
|
|
|
* Author: <YOUR_NAME_HERE>
|
|
|
*
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
... | ... | @@ -105,7 +101,7 @@ Now, create another file called `SimpleLed.cpp` in the same folder and add: |
|
|
*
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
... | ... | @@ -147,7 +143,7 @@ You can find more information about how to use the GPIO and what pins you can us |
|
|
To write a program that uses this driver, an entrypoint is needed as before: in `src/entrypoints` add a file called `test-led-driver.cpp` and write:
|
|
|
|
|
|
```cpp
|
|
|
#include <Common.h>board
|
|
|
#include <Common.h>
|
|
|
#include <drivers/led/SimpleLed.h>
|
|
|
|
|
|
using namespace miosix;
|
... | ... | @@ -158,7 +154,7 @@ int main() |
|
|
|
|
|
while(1)
|
|
|
{
|
|
|
led.switchToState( !(led.getState()) );
|
|
|
led.switchToState(!led.getState());
|
|
|
miosix::Thread::sleep(200);
|
|
|
}
|
|
|
}
|
... | ... | @@ -166,35 +162,28 @@ int main() |
|
|
|
|
|
## Compile with SBS
|
|
|
|
|
|
Just as before we have to add what we wrote to `sbs.conf`. This time though
|
|
|
we will also have to compile `SimpleLed.cpp` with our entrypoint.
|
|
|
Just as before we have to add what we wrote to `CMakeLists.txt`. This time though we will also have to compile `SimpleLed.cpp` with our entrypoint.
|
|
|
|
|
|
Add a new `srcfiles` group in `sbs.conf`, after `#srcfiles`:
|
|
|
Add a new `SIMPLE_LED_SOURCES` variable in `cmake/dependencies.cmake`:
|
|
|
|
|
|
```
|
|
|
[simple_led_include]
|
|
|
Type: srcfiles
|
|
|
Files: src/shared/drivers/led/SimpleLed.cpp
|
|
|
```cmake
|
|
|
set(SIMPLE_LED_SOURCES src/shared/drivers/led/SimpleLed.cpp)
|
|
|
```
|
|
|
|
|
|
Now you can add the entrypoint (a.k.a _board_, because it's a software that will
|
|
|
run on a board).
|
|
|
Now you can add the entrypoint in `CMakeLists.txt`:
|
|
|
|
|
|
```
|
|
|
[test-led-driver]
|
|
|
Type: board
|
|
|
BoardId: stm32f407vg_stm32f4discovery
|
|
|
BinName: test-led-driver
|
|
|
Include: %simple_led_include
|
|
|
Defines:
|
|
|
Main: test-led-driver
|
|
|
```cmake
|
|
|
add_executable(test-led-driver
|
|
|
src/entrypoints/test-led-driver.cpp
|
|
|
${SIMPLE_LED_SOURCES}
|
|
|
)
|
|
|
sbs_target(test-led-driver stm32f407vg_stm32f4discovery)
|
|
|
```
|
|
|
|
|
|
#### Note
|
|
|
As before, please note that you have to choose the correct board in order for your
|
|
|
code to run on your specific target board, if it's not a STM32F407VG Discovery.
|
|
|
As before, please note that you have to choose the correct board in order for your code to run on your specific target board, if it's not a STM32F407VG Discovery.
|
|
|
Also consider that the available LEDs and the pins to which they are connected can change according to the board you use. You should check the board's datasheet or its user manual.
|
|
|
Otherwise you can use any of the available pins and connect an external LED.
|
|
|
|
|
|
## Run it!
|
|
|
Same as before: build the entrypoint with `python sbs -b test-led-driver` and [flash the binary on the board](Flashing-on-a-Target-Board). |
|
|
\ No newline at end of file |
|
|
Same as before: build and [flash](Flashing-on-a-Target-Board) the entrypoint with the SBS script: `./sbs -f test-led-driver`. |
|
|
\ No newline at end of file |