diff options
Diffstat (limited to 'drivers/chibios/uart.c')
| -rw-r--r-- | drivers/chibios/uart.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/chibios/uart.c b/drivers/chibios/uart.c new file mode 100644 index 000000000..6e94899b9 --- /dev/null +++ b/drivers/chibios/uart.c | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* Copyright 2021 | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "uart.h" | ||
| 18 | |||
| 19 | #include "quantum.h" | ||
| 20 | |||
| 21 | static SerialConfig serialConfig = { | ||
| 22 | SERIAL_DEFAULT_BITRATE, | ||
| 23 | SD1_CR1, | ||
| 24 | SD1_CR2, | ||
| 25 | SD1_CR3 | ||
| 26 | }; | ||
| 27 | |||
| 28 | void uart_init(uint32_t baud) { | ||
| 29 | static bool is_initialised = false; | ||
| 30 | |||
| 31 | if (!is_initialised) { | ||
| 32 | is_initialised = true; | ||
| 33 | |||
| 34 | serialConfig.speed = baud; | ||
| 35 | |||
| 36 | #if defined(USE_GPIOV1) | ||
| 37 | palSetLineMode(SD1_TX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); | ||
| 38 | palSetLineMode(SD1_RX_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); | ||
| 39 | #else | ||
| 40 | palSetLineMode(SD1_TX_PIN, PAL_MODE_ALTERNATE(SD1_TX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
| 41 | palSetLineMode(SD1_RX_PIN, PAL_MODE_ALTERNATE(SD1_RX_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | ||
| 42 | #endif | ||
| 43 | sdStart(&SERIAL_DRIVER, &serialConfig); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | void uart_putchar(uint8_t c) { | ||
| 48 | sdPut(&SERIAL_DRIVER, c); | ||
| 49 | } | ||
| 50 | |||
| 51 | uint8_t uart_getchar(void) { | ||
| 52 | msg_t res = sdGet(&SERIAL_DRIVER); | ||
| 53 | |||
| 54 | return (uint8_t)res; | ||
| 55 | } | ||
| 56 | |||
| 57 | bool uart_available(void) { | ||
| 58 | return !sdGetWouldBlock(&SERIAL_DRIVER); | ||
| 59 | } | ||
