... | @@ -7,8 +7,8 @@ To get started, create a folder called `led` in `src/shared/drivers`. |
... | @@ -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:
|
|
In it, create a file called `SimpleLed.h` and write:
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
/* Copyright (c) 2017 Skyward Experimental Rocketry
|
|
/* 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
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* of this software and associated documentation files (the "Software"), to deal
|
... | @@ -29,9 +29,7 @@ In it, create a file called `SimpleLed.h` and write: |
... | @@ -29,9 +29,7 @@ In it, create a file called `SimpleLed.h` and write: |
|
* THE SOFTWARE.
|
|
* THE SOFTWARE.
|
|
*/
|
|
*/
|
|
|
|
|
|
// Header guards : alternativeley use "#pragma once"
|
|
#pragma once
|
|
#ifndef SIMPLE_LED_H
|
|
|
|
#define SIMPLE_LED_H
|
|
|
|
|
|
|
|
/* Includes basic useful stuff, e.g. the miosix kernel*/
|
|
/* Includes basic useful stuff, e.g. the miosix kernel*/
|
|
#include <Common.h>
|
|
#include <Common.h>
|
... | @@ -74,13 +72,11 @@ class SimpleLed |
... | @@ -74,13 +72,11 @@ class SimpleLed |
|
bool state;
|
|
bool state;
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
#endif /* SIMPLE_LED_H */
|
|
|
|
```
|
|
```
|
|
|
|
|
|
Please note a few things that are part of our [coding standards](Coding-Guidelines):
|
|
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)
|
|
- 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 :)
|
|
- `#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
|
|
- `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
|
|
- 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: |
... | @@ -91,7 +87,7 @@ Now, create another file called `SimpleLed.cpp` in the same folder and add: |
|
|
|
|
|
```cpp
|
|
```cpp
|
|
/* Copyright (c) <YEAR_HERE> Skyward Experimental Rocketry
|
|
/* 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
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* of this software and associated documentation files (the "Software"), to deal
|
... | @@ -147,7 +143,7 @@ You can find more information about how to use the GPIO and what pins you can us |
... | @@ -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:
|
|
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
|
|
```cpp
|
|
#include <Common.h>board
|
|
#include <Common.h>
|
|
#include <drivers/led/SimpleLed.h>
|
|
#include <drivers/led/SimpleLed.h>
|
|
|
|
|
|
using namespace miosix;
|
|
using namespace miosix;
|
... | @@ -158,7 +154,7 @@ int main() |
... | @@ -158,7 +154,7 @@ int main() |
|
|
|
|
|
while(1)
|
|
while(1)
|
|
{
|
|
{
|
|
led.switchToState( !(led.getState()) );
|
|
led.switchToState(!led.getState());
|
|
miosix::Thread::sleep(200);
|
|
miosix::Thread::sleep(200);
|
|
}
|
|
}
|
|
}
|
|
}
|
... | @@ -166,35 +162,28 @@ int main() |
... | @@ -166,35 +162,28 @@ int main() |
|
|
|
|
|
## Compile with SBS
|
|
## Compile with SBS
|
|
|
|
|
|
Just as before we have to add what we wrote to `sbs.conf`. This time though
|
|
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.
|
|
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`:
|
|
|
|
|
|
```
|
|
```cmake
|
|
[simple_led_include]
|
|
set(SIMPLE_LED_SOURCES src/shared/drivers/led/SimpleLed.cpp)
|
|
Type: srcfiles
|
|
|
|
Files: src/shared/drivers/led/SimpleLed.cpp
|
|
|
|
```
|
|
```
|
|
|
|
|
|
Now you can add the entrypoint (a.k.a _board_, because it's a software that will
|
|
Now you can add the entrypoint in `CMakeLists.txt`:
|
|
run on a board).
|
|
|
|
|
|
|
|
```
|
|
```cmake
|
|
[test-led-driver]
|
|
add_executable(test-led-driver
|
|
Type: board
|
|
src/entrypoints/test-led-driver.cpp
|
|
BoardId: stm32f407vg_stm32f4discovery
|
|
${SIMPLE_LED_SOURCES}
|
|
BinName: test-led-driver
|
|
)
|
|
Include: %simple_led_include
|
|
sbs_target(test-led-driver stm32f407vg_stm32f4discovery)
|
|
Defines:
|
|
|
|
Main: test-led-driver
|
|
|
|
```
|
|
```
|
|
|
|
|
|
#### Note
|
|
#### Note
|
|
As before, please note that you have to choose the correct board in order for your
|
|
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.
|
|
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.
|
|
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.
|
|
Otherwise you can use any of the available pins and connect an external LED.
|
|
|
|
|
|
## Run it!
|
|
## 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). |
|
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 |
|
\ No newline at end of file |