https://forum.pjrc.com/threads/29446-Teensy-Hardware-Flow-Control-RTS-CTS?p=80425#post80425teensy4-core
@@ -113,6 +113,8 @@ void serial_begin(uint32_t divisor); | |||
void serial_format(uint32_t format); | |||
void serial_end(void); | |||
void serial_set_transmit_pin(uint8_t pin); | |||
int serial_set_rts(uint8_t pin); | |||
int serial_set_cts(uint8_t pin); | |||
void serial_putchar(uint32_t c); | |||
void serial_write(const void *buf, unsigned int count); | |||
void serial_flush(void); | |||
@@ -130,6 +132,8 @@ void serial2_begin(uint32_t divisor); | |||
void serial2_format(uint32_t format); | |||
void serial2_end(void); | |||
void serial2_set_transmit_pin(uint8_t pin); | |||
int serial2_set_rts(uint8_t pin); | |||
int serial2_set_cts(uint8_t pin); | |||
void serial2_putchar(uint32_t c); | |||
void serial2_write(const void *buf, unsigned int count); | |||
void serial2_flush(void); | |||
@@ -143,6 +147,8 @@ void serial3_begin(uint32_t divisor); | |||
void serial3_format(uint32_t format); | |||
void serial3_end(void); | |||
void serial3_set_transmit_pin(uint8_t pin); | |||
int serial3_set_rts(uint8_t pin); | |||
int serial3_set_cts(uint8_t pin); | |||
void serial3_putchar(uint32_t c); | |||
void serial3_write(const void *buf, unsigned int count); | |||
void serial3_flush(void); |
@@ -172,6 +172,36 @@ void serial_set_transmit_pin(uint8_t pin) | |||
#endif | |||
} | |||
int serial_set_rts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return 0; | |||
if (pin == 6) { | |||
CORE_PIN6_CONFIG = PORT_PCR_MUX(3); | |||
} else if (pin == 19) { | |||
CORE_PIN19_CONFIG = PORT_PCR_MUX(3); | |||
} else { | |||
UART0_MODEM &= ~UART_MODEM_RXRTSE; | |||
return 0; | |||
} | |||
UART0_MODEM |= UART_MODEM_RXRTSE; | |||
return 1; | |||
} | |||
int serial_set_cts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return 0; | |||
if (pin == 18) { | |||
CORE_PIN18_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown? | |||
} else if (pin == 20) { | |||
CORE_PIN20_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown? | |||
} else { | |||
UART0_MODEM &= ~UART_MODEM_TXCTSE; | |||
return 0; | |||
} | |||
UART0_MODEM |= UART_MODEM_TXCTSE; | |||
return 1; | |||
} | |||
void serial_putchar(uint32_t c) | |||
{ | |||
uint32_t head, n; |
@@ -177,6 +177,32 @@ void serial2_set_transmit_pin(uint8_t pin) | |||
#endif | |||
} | |||
int serial2_set_rts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return 0; | |||
if (pin == 22) { | |||
CORE_PIN22_CONFIG = PORT_PCR_MUX(3); | |||
} else { | |||
UART1_MODEM &= ~UART_MODEM_RXRTSE; | |||
return 0; | |||
} | |||
UART1_MODEM |= UART_MODEM_RXRTSE; | |||
return 1; | |||
} | |||
int serial2_set_cts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return 0; | |||
if (pin == 23) { | |||
CORE_PIN23_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown? | |||
} else { | |||
UART1_MODEM &= ~UART_MODEM_TXCTSE; | |||
return 0; | |||
} | |||
UART1_MODEM |= UART_MODEM_TXCTSE; | |||
return 1; | |||
} | |||
void serial2_putchar(uint32_t c) | |||
{ | |||
uint32_t head, n; |
@@ -161,6 +161,32 @@ void serial3_set_transmit_pin(uint8_t pin) | |||
#endif | |||
} | |||
int serial3_set_rts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return 0; | |||
if (pin == 2) { | |||
CORE_PIN2_CONFIG = PORT_PCR_MUX(3); | |||
} else { | |||
UART2_MODEM &= ~UART_MODEM_RXRTSE; | |||
return 0; | |||
} | |||
UART2_MODEM |= UART_MODEM_RXRTSE; | |||
return 1; | |||
} | |||
int serial3_set_cts(uint8_t pin) | |||
{ | |||
if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return 0; | |||
if (pin == 14) { | |||
CORE_PIN14_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown? | |||
} else { | |||
UART2_MODEM &= ~UART_MODEM_TXCTSE; | |||
return 0; | |||
} | |||
UART2_MODEM |= UART_MODEM_TXCTSE; | |||
return 1; | |||
} | |||
void serial3_putchar(uint32_t c) | |||
{ | |||
uint32_t head, n; |