aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/_summary.md1
-rw-r--r--docs/uart_driver.md90
2 files changed, 91 insertions, 0 deletions
diff --git a/docs/_summary.md b/docs/_summary.md
index 9bc0b193a..526caf926 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -138,6 +138,7 @@
138 * [WS2812 Driver](ws2812_driver.md) 138 * [WS2812 Driver](ws2812_driver.md)
139 * [EEPROM Driver](eeprom_driver.md) 139 * [EEPROM Driver](eeprom_driver.md)
140 * ['serial' Driver](serial_driver.md) 140 * ['serial' Driver](serial_driver.md)
141 * [UART Driver](uart_driver.md)
141 * [GPIO Controls](internals_gpio_control.md) 142 * [GPIO Controls](internals_gpio_control.md)
142 * [Keyboard Guidelines](hardware_keyboard_guidelines.md) 143 * [Keyboard Guidelines](hardware_keyboard_guidelines.md)
143 144
diff --git a/docs/uart_driver.md b/docs/uart_driver.md
new file mode 100644
index 000000000..4d1716975
--- /dev/null
+++ b/docs/uart_driver.md
@@ -0,0 +1,90 @@
1# UART Driver
2
3The UART drivers used in QMK have a set of common functions to allow portability between MCUs.
4
5Currently, this driver does not support enabling hardware flow control (the `RTS` and `CTS` pins) if available, but may do so in future.
6
7## AVR Configuration
8
9No special setup is required - just connect the `RX` and `TX` pins of your UART device to the opposite pins on the MCU:
10
11|MCU |`TX`|`RX`|`CTS`|`RTS`|
12|-------------|----|----|-----|-----|
13|ATmega16/32U2|`D3`|`D2`|`D7` |`D6` |
14|ATmega16/32U4|`D3`|`D2`|`D5` |`B7` |
15|AT90USB64/128|`D3`|`D2`|*n/a*|*n/a*|
16|ATmega32A |`D1`|`D0`|*n/a*|*n/a*|
17|ATmega328/P |`D1`|`D0`|*n/a*|*n/a*|
18
19## ChibiOS/ARM Configuration
20
21You'll need to determine which pins can be used for UART -- as an example, STM32 parts generally have multiple UART peripherals, labeled USART1, USART2, USART3 etc.
22
23To enable UART, modify your board's `halconf.h` to enable the serial driver:
24
25```c
26#define HAL_USE_SERIAL TRUE
27```
28
29Then, modify your board's `mcuconf.h` to enable the peripheral you've chosen, for example:
30
31```c
32#undef STM32_SERIAL_USE_USART2
33#define STM32_SERIAL_USE_USART2 TRUE
34```
35
36Configuration-wise, you'll need to set up the peripheral as per your MCU's datasheet -- the defaults match the pins for a Proton-C, i.e. STM32F303.
37
38|`config.h` override |Description |Default Value|
39|--------------------------|---------------------------------------------------------------|-------------|
40|`#define SERIAL_DRIVER` |USART peripheral to use - USART1 -> `SD1`, USART2 -> `SD2` etc.|`SD1` |
41|`#define SD1_TX_PIN` |The pin to use for TX |`A9` |
42|`#define SD1_TX_PAL_MODE` |The alternate function mode for TX |`7` |
43|`#define SD1_RX_PIN` |The pin to use for RX |`A10` |
44|`#define SD1_RX_PAL_MODE` |The alternate function mode for RX |`7` |
45|`#define SD1_CTS_PIN` |The pin to use for CTS |`A11` |
46|`#define SD1_CTS_PAL_MODE`|The alternate function mode for CTS |`7` |
47|`#define SD1_RTS_PIN` |The pin to use for RTS |`A12` |
48|`#define SD1_RTS_PAL_MODE`|The alternate function mode for RTS |`7` |
49
50## Functions
51
52### `void uart_init(uint32_t baud)`
53
54Initialize the UART driver. This function must be called only once, before any of the below functions can be called.
55
56#### Arguments
57
58 - `uint32_t baud`
59 The baud rate to transmit and receive at. This may depend on the device you are communicating with. Common values are 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200.
60
61---
62
63### `void uart_putchar(uint8_t c)`
64
65Transmit a single byte.
66
67#### Arguments
68
69 - `uint8_t c`
70 The byte (character) to send, from 0 to 255.
71
72---
73
74### `uint8_t uart_getchar(void)`
75
76Receive a single byte.
77
78#### Return Value
79
80The byte read from the receive buffer.
81
82---
83
84### `bool uart_available(void)`
85
86Return whether the receive buffer contains data. Call this function to determine if `uart_getchar()` will return meaningful data.
87
88#### Return Value
89
90`true` if the receive buffer length is non-zero.