... | ... | @@ -31,9 +31,12 @@ In it, create a file called `SimpleLed.h` and write: |
|
|
|
|
|
#pragma once
|
|
|
|
|
|
/* Includes basic useful stuff, e.g. the miosix kernel*/
|
|
|
/* Includes basic useful stuff, e.g. the miosix kernel */
|
|
|
#include <Common.h>
|
|
|
|
|
|
namespace Boardcore
|
|
|
{
|
|
|
|
|
|
/* Define the PD14 pin as ledPin */
|
|
|
typedef miosix::Gpio<GPIOD_BASE, 14> ledPin;
|
|
|
|
... | ... | @@ -72,12 +75,15 @@ class SimpleLed |
|
|
bool state;
|
|
|
|
|
|
};
|
|
|
|
|
|
} // namespace Boardcore
|
|
|
```
|
|
|
|
|
|
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)
|
|
|
- `#pragma once` directive, to prevent multiple re-inclusions
|
|
|
- `#include <Common.h>`, a bunch of useful includes :)
|
|
|
- `namespace Boardcore`, to avoid name collisions
|
|
|
- `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
|
|
|
|
... | ... | @@ -110,6 +116,9 @@ Now, create another file called `SimpleLed.cpp` in the same folder and add: |
|
|
|
|
|
#include <drivers/led/SimpleLed.h>
|
|
|
|
|
|
namespace Boardcore
|
|
|
{
|
|
|
|
|
|
using namespace miosix;
|
|
|
|
|
|
SimpleLed::SimpleLed() : state(false)
|
... | ... | @@ -134,6 +143,7 @@ void SimpleLed::switchToState(bool newState) |
|
|
state = newState;
|
|
|
}
|
|
|
|
|
|
} // namespace Boardcore
|
|
|
```
|
|
|
As you can see, `PD14` is set as an `output` pin in the constructor and its digital value can be set to `high` or `low`.
|
|
|
You can find more information about how to use the GPIO and what pins you can use, in the [GPIO Usage](GPIO-Usage-&-Used-Pins) page.
|
... | ... | @@ -169,6 +179,7 @@ To write a program that uses this driver, an entrypoint is needed as before: in |
|
|
#include <drivers/led/SimpleLed.h>
|
|
|
|
|
|
using namespace miosix;
|
|
|
using namespace Boardcore;
|
|
|
|
|
|
int main()
|
|
|
{
|
... | ... | |