|
| 1 | +/** |
| 2 | + * @file uart.h |
| 3 | + * @brief GD32 |
| 4 | + */ |
| 5 | +/* Copyright (C) 2026 by Arjan van Vught mailto:info@gd32-dmx.org |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | +
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | +
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef UART_H_ |
| 27 | +#define UART_H_ |
| 28 | + |
| 29 | +#include "gd32_uart.h" |
| 30 | + |
| 31 | +namespace uart { |
| 32 | + inline constexpr auto BITS_8 = gd32::kUartBits8; |
| 33 | + inline constexpr auto BITS_9 = gd32::kUartBits9; |
| 34 | + |
| 35 | + inline constexpr auto PARITY_NONE = gd32::kUartParityNone; |
| 36 | + inline constexpr auto PARITY_ODD = gd32::kUartParityOdd; |
| 37 | + inline constexpr auto PARITY_EVEN = gd32::kUartParityEven; |
| 38 | + |
| 39 | + inline constexpr auto STOP_1BIT = gd32::kUartStop1Bit; |
| 40 | + inline constexpr auto STOP_2BITS = gd32::kUartStop2Bits; |
| 41 | + |
| 42 | +inline void Begin(uint32_t uart_base, uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop_bits) { |
| 43 | + Gd32UartBegin(uart_base, baudrate, bits, parity, stop_bits); |
| 44 | +} |
| 45 | + |
| 46 | +inline void SetBaudrate(uint32_t uart_base, uint32_t baudrate) { |
| 47 | + Gd32UartSetBaudrate(uart_base, baudrate); |
| 48 | +} |
| 49 | + |
| 50 | +inline void Transmit(uint32_t uart_base, const uint8_t* data, uint32_t length) { |
| 51 | + Gd32UartTransmit(uart_base, data, length); |
| 52 | +} |
| 53 | + |
| 54 | +inline void TransmitString(uint32_t uart_base, const char* data) { |
| 55 | + Gd32UartTransmitString(uart_base, data); |
| 56 | +} |
| 57 | + |
| 58 | +inline uint32_t GetRxFifoLevel(uint32_t uart_base) { |
| 59 | + return Gd32UartGetRxFifoLevel(uart_base); |
| 60 | +} |
| 61 | + |
| 62 | +inline uint8_t GetRxData(uint32_t uart_base) { |
| 63 | + return Gd32UartGetRxData(uart_base); |
| 64 | +} |
| 65 | +} // namespace uart |
| 66 | + |
| 67 | +#endif // UART_H_ |
0 commit comments