|
|
|
When designing a new board we need to specify somewhere which are all the used GPIO. This is useful in order to setup a hierarchy of namespaces and to give meaningful names to the needed GPIOs.
|
|
|
|
For example, assuming we are developing a new board for our rocket we will have a set of sensors, such as IMUs and barometers. These sensors will use some communication protocols, such as SPI or I2C, or maybe both.
|
|
|
|
In the `hwmapping.h` file we can list all the GPIOs that we need.
|
|
|
|
|
|
|
|
The `hwmapping.h` file can be found under: `skyward-boardcore/libs/miosix-kernel/arch/<your-arch>/<your-board>/interfaces_impl/`.
|
|
|
|
|
|
|
|
### Example
|
|
|
|
This example shows a simple hardware mapping file:
|
|
|
|
- `myspi`: this namespace is used to define the GPIOs related to an SPI bus, which are `sck`, `miso` and `mosi`.
|
|
|
|
- `mysensor`: it is a sensor that works via the SPI protocol, in fact in this namespace it is defined a chip select GPIO (`cs`). Moreover it defines another GPIO in order to receive interrupts from the sensor.
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
#include "interfaces/gpio.h"
|
|
|
|
|
|
|
|
namespace miosix {
|
|
|
|
|
|
|
|
namespace interfaces {
|
|
|
|
|
|
|
|
namespace myspi {
|
|
|
|
using sck = Gpio<GPIOA_BASE, 5>;
|
|
|
|
using miso = Gpio<GPIOA_BASE, 6>;
|
|
|
|
using mosi = Gpio<GPIOA_BASE, 7>;
|
|
|
|
} //namespace myspi
|
|
|
|
|
|
|
|
} //namespace interfaces
|
|
|
|
|
|
|
|
namespace sensors {
|
|
|
|
|
|
|
|
namespace mysensor {
|
|
|
|
using cs = Gpio<GPIOE_BASE, 7>;
|
|
|
|
using int1 = Gpio<GPIOC_BASE, 13>;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace sensors
|
|
|
|
|
|
|
|
} //namespace miosix
|
|
|
|
``` |
|
|
\ No newline at end of file |