diff options
| author | Ryan <fauxpark@gmail.com> | 2025-01-26 23:46:46 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-26 13:46:46 +0100 |
| commit | 291d154d7b13efb83f24c76df26277f32b9f0a58 (patch) | |
| tree | d7d2e05a18bdfbdd83258c8a91a70f16e57792e9 /platforms/chibios | |
| parent | e4f736e68518a09a922caf4638fca10f2ee3f38c (diff) | |
Unify UART headers (#24855)
* Remove deprecated defines
* Move default config to .c files
* Unify UART headers
* Clean up docs
* Reorganise PAL mode defaults
Diffstat (limited to 'platforms/chibios')
| -rw-r--r-- | platforms/chibios/drivers/uart.h | 200 | ||||
| -rw-r--r-- | platforms/chibios/drivers/uart_serial.c | 83 | ||||
| -rw-r--r-- | platforms/chibios/drivers/uart_sio.c | 67 |
3 files changed, 150 insertions, 200 deletions
diff --git a/platforms/chibios/drivers/uart.h b/platforms/chibios/drivers/uart.h deleted file mode 100644 index c1945575f1..0000000000 --- a/platforms/chibios/drivers/uart.h +++ /dev/null | |||
| @@ -1,200 +0,0 @@ | |||
| 1 | // Copyright 2024 Stefan Kerkmann | ||
| 2 | // Copyright 2021 QMK | ||
| 3 | // Copyright 2024 Stefan Kerkmann | ||
| 4 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 5 | |||
| 6 | #pragma once | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <stdbool.h> | ||
| 10 | |||
| 11 | #include <hal.h> | ||
| 12 | |||
| 13 | #include "gpio.h" | ||
| 14 | #include "chibios_config.h" | ||
| 15 | |||
| 16 | // ======== DEPRECATED DEFINES - DO NOT USE ======== | ||
| 17 | #ifdef SERIAL_DRIVER | ||
| 18 | # define UART_DRIVER SERIAL_DRIVER | ||
| 19 | #endif | ||
| 20 | #ifdef SD1_TX_PIN | ||
| 21 | # define UART_TX_PIN SD1_TX_PIN | ||
| 22 | #endif | ||
| 23 | #ifdef SD1_RX_PIN | ||
| 24 | # define UART_RX_PIN SD1_RX_PIN | ||
| 25 | #endif | ||
| 26 | #ifdef SD1_CTS_PIN | ||
| 27 | # define UART_CTS_PIN SD1_CTS_PIN | ||
| 28 | #endif | ||
| 29 | #ifdef SD1_RTS_PIN | ||
| 30 | # define UART_RTS_PIN SD1_RTS_PIN | ||
| 31 | #endif | ||
| 32 | #ifdef SD1_TX_PAL_MODE | ||
| 33 | # define UART_TX_PAL_MODE SD1_TX_PAL_MODE | ||
| 34 | #endif | ||
| 35 | #ifdef SD1_RX_PAL_MODE | ||
| 36 | # define UART_RX_PAL_MODE SD1_RX_PAL_MODE | ||
| 37 | #endif | ||
| 38 | #ifdef SD1_CTS_PAL_MODE | ||
| 39 | # define UART_RTS_PAL_MODE SD1_CTS_PAL_MODE | ||
| 40 | #endif | ||
| 41 | #ifdef SD1_RTS_PAL_MODE | ||
| 42 | # define UART_TX_PAL_MODE SD1_RTS_PAL_MODE | ||
| 43 | #endif | ||
| 44 | #ifdef SD1_CR1 | ||
| 45 | # define UART_CR1 SD1_CR1 | ||
| 46 | #endif | ||
| 47 | #ifdef SD1_CR2 | ||
| 48 | # define UART_CR2 SD1_CR2 | ||
| 49 | #endif | ||
| 50 | #ifdef SD1_CR3 | ||
| 51 | # define UART_CR3 SD1_CR3 | ||
| 52 | #endif | ||
| 53 | #ifdef SD1_WRDLEN | ||
| 54 | # define UART_WRDLEN SD1_WRDLEN | ||
| 55 | #endif | ||
| 56 | #ifdef SD1_STPBIT | ||
| 57 | # define UART_STPBIT SD1_STPBIT | ||
| 58 | #endif | ||
| 59 | #ifdef SD1_PARITY | ||
| 60 | # define UART_PARITY SD1_PARITY | ||
| 61 | #endif | ||
| 62 | #ifdef SD1_ATFLCT | ||
| 63 | # define UART_ATFLCT SD1_ATFLCT | ||
| 64 | #endif | ||
| 65 | // ======== | ||
| 66 | |||
| 67 | #ifndef UART_DRIVER | ||
| 68 | # if (HAL_USE_SERIAL == TRUE) | ||
| 69 | # define UART_DRIVER SD1 | ||
| 70 | # elif (HAL_USE_SIO == TRUE) | ||
| 71 | # define UART_DRIVER SIOD1 | ||
| 72 | # endif | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifndef UART_TX_PIN | ||
| 76 | # define UART_TX_PIN A9 | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #ifndef UART_RX_PIN | ||
| 80 | # define UART_RX_PIN A10 | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #ifndef UART_CTS_PIN | ||
| 84 | # define UART_CTS_PIN A11 | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #ifndef UART_RTS_PIN | ||
| 88 | # define UART_RTS_PIN A12 | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #ifdef USE_GPIOV1 | ||
| 92 | # ifndef UART_TX_PAL_MODE | ||
| 93 | # define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 94 | # endif | ||
| 95 | # ifndef UART_RX_PAL_MODE | ||
| 96 | # define UART_RX_PAL_MODE PAL_MODE_INPUT | ||
| 97 | # endif | ||
| 98 | # ifndef UART_CTS_PAL_MODE | ||
| 99 | # define UART_CTS_PAL_MODE PAL_MODE_INPUT | ||
| 100 | # endif | ||
| 101 | # ifndef UART_RTS_PAL_MODE | ||
| 102 | # define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 103 | # endif | ||
| 104 | #else | ||
| 105 | # ifndef UART_TX_PAL_MODE | ||
| 106 | # define UART_TX_PAL_MODE 7 | ||
| 107 | # endif | ||
| 108 | |||
| 109 | # ifndef UART_RX_PAL_MODE | ||
| 110 | # define UART_RX_PAL_MODE 7 | ||
| 111 | # endif | ||
| 112 | |||
| 113 | # ifndef UART_CTS_PAL_MODE | ||
| 114 | # define UART_CTS_PAL_MODE 7 | ||
| 115 | # endif | ||
| 116 | |||
| 117 | # ifndef UART_RTS_PAL_MODE | ||
| 118 | # define UART_RTS_PAL_MODE 7 | ||
| 119 | # endif | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef UART_CR1 | ||
| 123 | # define UART_CR1 0 | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #ifndef UART_CR2 | ||
| 127 | # define UART_CR2 0 | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #ifndef UART_CR3 | ||
| 131 | # define UART_CR3 0 | ||
| 132 | #endif | ||
| 133 | |||
| 134 | #ifndef UART_WRDLEN | ||
| 135 | # define UART_WRDLEN 3 | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #ifndef UART_STPBIT | ||
| 139 | # define UART_STPBIT 0 | ||
| 140 | #endif | ||
| 141 | |||
| 142 | #ifndef UART_PARITY | ||
| 143 | # define UART_PARITY 0 | ||
| 144 | #endif | ||
| 145 | |||
| 146 | #ifndef UART_ATFLCT | ||
| 147 | # define UART_ATFLCT 0 | ||
| 148 | #endif | ||
| 149 | |||
| 150 | /** | ||
| 151 | * @brief Initialize the UART driver. This function must be called only once, | ||
| 152 | * before any of the below functions can be called. | ||
| 153 | * | ||
| 154 | * @param baud The baud rate to transmit and receive at. This may depend on the | ||
| 155 | * device you are communicating with. Common values are 1200, 2400, 4800, 9600, | ||
| 156 | * 19200, 38400, 57600, and 115200. | ||
| 157 | */ | ||
| 158 | void uart_init(uint32_t baud); | ||
| 159 | |||
| 160 | /** | ||
| 161 | * @brief Transmit a single byte. | ||
| 162 | * | ||
| 163 | * @param data The byte to transmit. | ||
| 164 | */ | ||
| 165 | void uart_write(uint8_t data); | ||
| 166 | |||
| 167 | /** | ||
| 168 | * @brief Receive a single byte. | ||
| 169 | * | ||
| 170 | * @return uint8_t The byte read from the receive buffer. This function will | ||
| 171 | * block if the buffer is empty (ie. no data to read). | ||
| 172 | */ | ||
| 173 | uint8_t uart_read(void); | ||
| 174 | |||
| 175 | /** | ||
| 176 | * @brief Transmit multiple bytes. | ||
| 177 | * | ||
| 178 | * @param data A pointer to the data to write from. | ||
| 179 | * @param length The number of bytes to write. Take care not to overrun the | ||
| 180 | * length of `data`. | ||
| 181 | */ | ||
| 182 | void uart_transmit(const uint8_t *data, uint16_t length); | ||
| 183 | |||
| 184 | /** | ||
| 185 | * @brief Receive multiple bytes. | ||
| 186 | * | ||
| 187 | * @param data A pointer to the buffer to read into. | ||
| 188 | * @param length The number of bytes to read. Take care not to overrun the | ||
| 189 | * length of `data`. | ||
| 190 | */ | ||
| 191 | void uart_receive(uint8_t *data, uint16_t length); | ||
| 192 | |||
| 193 | /** | ||
| 194 | * @brief Return whether the receive buffer contains data. Call this function | ||
| 195 | * to determine if `uart_read()` will return data immediately. | ||
| 196 | * | ||
| 197 | * @return true If there is data available to read. | ||
| 198 | * @return false If there is no data available to read. | ||
| 199 | */ | ||
| 200 | bool uart_available(void); | ||
diff --git a/platforms/chibios/drivers/uart_serial.c b/platforms/chibios/drivers/uart_serial.c index 6aff4eae47..e0afb9768a 100644 --- a/platforms/chibios/drivers/uart_serial.c +++ b/platforms/chibios/drivers/uart_serial.c | |||
| @@ -3,6 +3,89 @@ | |||
| 3 | // SPDX-License-Identifier: GPL-2.0-or-later | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | 4 | ||
| 5 | #include "uart.h" | 5 | #include "uart.h" |
| 6 | #include "gpio.h" | ||
| 7 | #include "chibios_config.h" | ||
| 8 | #include <hal.h> | ||
| 9 | |||
| 10 | #ifndef UART_DRIVER | ||
| 11 | # define UART_DRIVER SD1 | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifndef UART_TX_PIN | ||
| 15 | # define UART_TX_PIN A9 | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifndef UART_TX_PAL_MODE | ||
| 19 | # ifdef USE_GPIOV1 | ||
| 20 | # define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 21 | # else | ||
| 22 | # define UART_TX_PAL_MODE 7 | ||
| 23 | # endif | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #ifndef UART_RX_PIN | ||
| 27 | # define UART_RX_PIN A10 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef UART_RX_PAL_MODE | ||
| 31 | # ifdef USE_GPIOV1 | ||
| 32 | # define UART_RX_PAL_MODE PAL_MODE_INPUT | ||
| 33 | # else | ||
| 34 | # define UART_RX_PAL_MODE 7 | ||
| 35 | # endif | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifndef UART_CTS_PIN | ||
| 39 | # define UART_CTS_PIN A11 | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #ifndef UART_CTS_PAL_MODE | ||
| 43 | # ifdef USE_GPIOV1 | ||
| 44 | # define UART_CTS_PAL_MODE PAL_MODE_INPUT | ||
| 45 | # else | ||
| 46 | # define UART_CTS_PAL_MODE 7 | ||
| 47 | # endif | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifndef UART_RTS_PIN | ||
| 51 | # define UART_RTS_PIN A12 | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifndef UART_RTS_PAL_MODE | ||
| 55 | # ifdef USE_GPIOV1 | ||
| 56 | # define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 57 | # else | ||
| 58 | # define UART_RTS_PAL_MODE 7 | ||
| 59 | # endif | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #ifndef UART_CR1 | ||
| 63 | # define UART_CR1 0 | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef UART_CR2 | ||
| 67 | # define UART_CR2 0 | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #ifndef UART_CR3 | ||
| 71 | # define UART_CR3 0 | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #ifndef UART_WRDLEN | ||
| 75 | # define UART_WRDLEN 3 | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #ifndef UART_STPBIT | ||
| 79 | # define UART_STPBIT 0 | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifndef UART_PARITY | ||
| 83 | # define UART_PARITY 0 | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #ifndef UART_ATFLCT | ||
| 87 | # define UART_ATFLCT 0 | ||
| 88 | #endif | ||
| 6 | 89 | ||
| 7 | #if defined(MCU_KINETIS) | 90 | #if defined(MCU_KINETIS) |
| 8 | static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE}; | 91 | static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE}; |
diff --git a/platforms/chibios/drivers/uart_sio.c b/platforms/chibios/drivers/uart_sio.c index 442df1c54d..fc12f0abed 100644 --- a/platforms/chibios/drivers/uart_sio.c +++ b/platforms/chibios/drivers/uart_sio.c | |||
| @@ -3,6 +3,73 @@ | |||
| 3 | // SPDX-License-Identifier: GPL-2.0-or-later | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | 4 | ||
| 5 | #include "uart.h" | 5 | #include "uart.h" |
| 6 | #include "gpio.h" | ||
| 7 | #include "chibios_config.h" | ||
| 8 | #include <hal.h> | ||
| 9 | |||
| 10 | #ifndef UART_DRIVER | ||
| 11 | # define UART_DRIVER SIOD1 | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifndef UART_TX_PIN | ||
| 15 | # define UART_TX_PIN A9 | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifndef UART_TX_PAL_MODE | ||
| 19 | # ifdef USE_GPIOV1 | ||
| 20 | # define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 21 | # else | ||
| 22 | # define UART_TX_PAL_MODE 7 | ||
| 23 | # endif | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #ifndef UART_RX_PIN | ||
| 27 | # define UART_RX_PIN A10 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef UART_RX_PAL_MODE | ||
| 31 | # ifdef USE_GPIOV1 | ||
| 32 | # define UART_RX_PAL_MODE PAL_MODE_INPUT | ||
| 33 | # else | ||
| 34 | # define UART_RX_PAL_MODE 7 | ||
| 35 | # endif | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifndef UART_CTS_PIN | ||
| 39 | # define UART_CTS_PIN A11 | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #ifndef UART_CTS_PAL_MODE | ||
| 43 | # ifdef USE_GPIOV1 | ||
| 44 | # define UART_CTS_PAL_MODE PAL_MODE_INPUT | ||
| 45 | # else | ||
| 46 | # define UART_CTS_PAL_MODE 7 | ||
| 47 | # endif | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifndef UART_RTS_PIN | ||
| 51 | # define UART_RTS_PIN A12 | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifndef UART_RTS_PAL_MODE | ||
| 55 | # ifdef USE_GPIOV1 | ||
| 56 | # define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL | ||
| 57 | # else | ||
| 58 | # define UART_RTS_PAL_MODE 7 | ||
| 59 | # endif | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #ifndef UART_CR1 | ||
| 63 | # define UART_CR1 0 | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef UART_CR2 | ||
| 67 | # define UART_CR2 0 | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #ifndef UART_CR3 | ||
| 71 | # define UART_CR3 0 | ||
| 72 | #endif | ||
| 6 | 73 | ||
| 7 | #if defined(MCU_RP) | 74 | #if defined(MCU_RP) |
| 8 | // 38400 baud, 8 data bits, 1 stop bit, no parity, no flow control | 75 | // 38400 baud, 8 data bits, 1 stop bit, no parity, no flow control |
