@@ -82,10 +82,11 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
82
82
}
83
83
84
84
85
- /* -------------------------------------------------------------------------- */
86
- UART::UART (int _pin_tx, int _pin_rx) :
85
+ UART::UART (int _pin_tx, int _pin_rx, int _pin_rts, int _pin_cts):
87
86
tx_pin(_pin_tx),
88
87
rx_pin(_pin_rx),
88
+ rts_pin(_pin_rts),
89
+ cts_pin(_pin_cts),
89
90
init_ok(false ) {
90
91
/* -------------------------------------------------------------------------- */
91
92
uart_cfg.txi_irq = FSP_INVALID_VECTOR;
@@ -94,9 +95,6 @@ UART::UART(int _pin_tx, int _pin_rx) :
94
95
uart_cfg.eri_irq = FSP_INVALID_VECTOR;
95
96
}
96
97
97
-
98
-
99
-
100
98
/* -------------------------------------------------------------------------- */
101
99
bool UART::setUpUartIrqs (uart_cfg_t &cfg) {
102
100
/* -------------------------------------------------------------------------- */
@@ -181,9 +179,14 @@ bool UART::cfg_pins(int max_index) {
181
179
/* actually configuring PIN function */
182
180
ioport_peripheral_t ioport_tx = USE_SCI_EVEN_CFG (cfg_tx) ? IOPORT_PERIPHERAL_SCI0_2_4_6_8 : IOPORT_PERIPHERAL_SCI1_3_5_7_9;
183
181
ioport_peripheral_t ioport_rx = USE_SCI_EVEN_CFG (cfg_rx) ? IOPORT_PERIPHERAL_SCI0_2_4_6_8 : IOPORT_PERIPHERAL_SCI1_3_5_7_9;
184
-
182
+
185
183
R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[tx_pin].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | ioport_tx));
186
184
R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[rx_pin].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | ioport_rx));
185
+ if (rts_pin != -1 && cts_pin != -1 ) {
186
+ // hopefully people using flow control have read the datasheet so let's avoid the double check
187
+ R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[rts_pin].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | ioport_rx));
188
+ R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[cts_pin].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | ioport_rx));
189
+ }
187
190
188
191
return true ;
189
192
}
@@ -213,6 +216,9 @@ void UART::begin(unsigned long baudrate, uint16_t config) {
213
216
uart_cfg_extend.p_baud_setting = &uart_baud;
214
217
uart_cfg_extend.flow_control = SCI_UART_FLOW_CONTROL_RTS;
215
218
uart_cfg_extend.flow_control_pin = (bsp_io_port_pin_t ) UINT16_MAX;
219
+ if (rts_pin != -1 && cts_pin != -1 ) {
220
+ uart_cfg_extend.flow_control = SCI_UART_FLOW_CONTROL_HARDWARE_CTSRTS;
221
+ }
216
222
uart_cfg_extend.rs485_setting .enable = SCI_UART_RS485_DISABLE;
217
223
uart_cfg_extend.rs485_setting .polarity = SCI_UART_RS485_DE_POLARITY_HIGH;
218
224
uart_cfg_extend.rs485_setting .de_control_pin = (bsp_io_port_pin_t ) UINT16_MAX;
0 commit comments