mirror of
https://github.com/Noltari/pico-uart-bridge.git
synced 2025-06-29 04:06:16 +00:00
Add hardware flow-control
This commit is contained in:
parent
05e4815f6b
commit
e729db5942
3 changed files with 46 additions and 6 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
option(FLOW_CONTROL "Enable Hardware Flow-control on the UARTs" FALSE)
|
||||
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(pico_uart_bridge)
|
||||
|
@ -19,4 +21,8 @@ target_link_libraries(uart_bridge
|
|||
pico_stdlib
|
||||
tinyusb_device)
|
||||
|
||||
if(FLOW_CONTROL)
|
||||
target_compile_definitions(uart_bridge PUBLIC FLOW_CONTROL=1)
|
||||
endif()
|
||||
|
||||
pico_add_extra_outputs(uart_bridge)
|
||||
|
|
16
README.md
16
README.md
|
@ -12,8 +12,22 @@ Raspberry Pi Pico Pinout
|
|||
------------------------
|
||||
|
||||
| Raspberry Pi Pico GPIO | Function |
|
||||
|:----------------------:|:--------:|
|
||||
|:----------------------:|:---------:|
|
||||
| GPIO0 (Pin 1) | UART0 TX |
|
||||
| GPIO1 (Pin 2) | UART0 RX |
|
||||
| GPIO2 (Pin 4) | UART0 CTS |
|
||||
| GPIO3 (Pin 5) | UART0 RTS |
|
||||
| GPIO4 (Pin 6) | UART1 TX |
|
||||
| GPIO5 (Pin 7) | UART1 RX |
|
||||
| GPIO6 (Pin 9) | UART1 CTS |
|
||||
| GPIO7 (Pin 10) | UART1 RTS |
|
||||
|
||||
Optional Hardware Flow-control
|
||||
------------------------------
|
||||
|
||||
Hardware Flow-control is disabled by default, but can be compiled in by running:
|
||||
|
||||
``` bash
|
||||
cmake -DFLOW_CONTROL .
|
||||
make
|
||||
```
|
||||
|
|
|
@ -28,6 +28,10 @@ typedef struct {
|
|||
uart_inst_t *const inst;
|
||||
uint8_t tx_pin;
|
||||
uint8_t rx_pin;
|
||||
#ifdef FLOW_CONTROL
|
||||
uint8_t rts_pin;
|
||||
uint8_t cts_pin;
|
||||
#endif
|
||||
} uart_id_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -47,10 +51,18 @@ const uart_id_t UART_ID[CFG_TUD_CDC] = {
|
|||
.inst = uart0,
|
||||
.tx_pin = 0,
|
||||
.rx_pin = 1,
|
||||
#ifdef FLOW_CONTROL
|
||||
.cts_pin = 2,
|
||||
.rts_pin = 3,
|
||||
#endif
|
||||
}, {
|
||||
.inst = uart1,
|
||||
.tx_pin = 4,
|
||||
.rx_pin = 5,
|
||||
#ifdef FLOW_CONTROL
|
||||
.cts_pin = 6,
|
||||
.rts_pin = 7,
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -233,6 +245,10 @@ void init_uart_data(uint8_t itf) {
|
|||
/* Pinmux */
|
||||
gpio_set_function(ui->tx_pin, GPIO_FUNC_UART);
|
||||
gpio_set_function(ui->rx_pin, GPIO_FUNC_UART);
|
||||
#ifdef FLOW_CONTROL
|
||||
gpio_set_function(ui->rts_pin, GPIO_FUNC_UART);
|
||||
gpio_set_function(ui->cts_pin, GPIO_FUNC_UART);
|
||||
#endif
|
||||
|
||||
/* USB CDC LC */
|
||||
ud->usb_lc.bit_rate = DEF_BIT_RATE;
|
||||
|
@ -257,7 +273,11 @@ void init_uart_data(uint8_t itf) {
|
|||
|
||||
/* UART start */
|
||||
uart_init(ui->inst, ud->usb_lc.bit_rate);
|
||||
#ifdef FLOW_CONTROL
|
||||
uart_set_hw_flow(ui->inst, true, true);
|
||||
#else
|
||||
uart_set_hw_flow(ui->inst, false, false);
|
||||
#endif
|
||||
uart_set_format(ui->inst, databits_usb2uart(ud->usb_lc.data_bits),
|
||||
stopbits_usb2uart(ud->usb_lc.stop_bits),
|
||||
parity_usb2uart(ud->usb_lc.parity));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue