Ich habe für jede Hardware-Ressource ein struct definiert, in dem alle
Parameter enthalten sind, die die entsprechende Ressource benötigt. Die
wird dann der Init-Routine übergeben.
Als Beispiel mal ein Uart. In dem struct werden nicht nur die
zugehörigen IO-Pins definiert, sondern auch die verwendeten DMA Kanäle:
1 | typedef struct{
|
2 | USART_TypeDef* Uart; // a.e. UART4 or USART1
|
3 |
|
4 | int DmaRxStreamNr; // a.e. 2
|
5 | DMA_Stream_TypeDef* DmaRxStream; // a.e. DMA1_Stream2
|
6 | uint32_t DmaRxChannel; // a.e. DMA_CHANNEL_4
|
7 |
|
8 | int DmaTxStreamNr; // a.e. 2
|
9 | DMA_Stream_TypeDef* DmaTxStream; // a.e. DMA1_Stream4
|
10 | uint32_t DmaTxChannel; // a.e. DMA_CHANNEL_4
|
11 |
|
12 | IRQn_Type IRQnRx; // a.e. DMA1_Stream2_IRQn
|
13 | uint32_t IRQnRxPrio; // a.e. 0..15 0 = high
|
14 | uint32_t IRQnRxSubPrio; // a.e. 0..15 0 = high
|
15 |
|
16 | IRQn_Type IRQnTx; // a.e. DMA1_Stream4_IRQn
|
17 | uint32_t IRQnTxPrio; // a.e. 0..15 0 = high
|
18 | uint32_t IRQnTxSubPrio; // a.e. 0..15 0 = high
|
19 |
|
20 | IRQn_Type IRQnTcTx; // a.e. Uart TC IRQ
|
21 | uint32_t IRQnTcTxPrio; // a.e. 0..15 0 = high
|
22 | uint32_t IRQnTcTxSubPrio; // a.e. 0..15 0 = high
|
23 |
|
24 | GPIO_TypeDef* GpioRxPort; // a.e. GPIOA
|
25 | uint32_t GpioRxAfPinMapping; // a.e. GPIO_AF_UART4
|
26 | uint32_t GpioRxPin; // a.e. 1
|
27 |
|
28 | GPIO_TypeDef* GpioTxPort; // a.e. GPIOA
|
29 | uint32_t GpioTxAfPinMapping; // a.e. GPIO_AF_UART4
|
30 | uint32_t GpioTxPin; // a.e. 0
|
31 |
|
32 | } USART_ConfigurationTypeDef;
|
Diese struct lege ich für jede Hardware Komonente einmal konstant an.
Gruß, Stefan