@@ -1015,14 +1015,14 @@ func (uart *UART) Configure(config UARTConfig) error {
1015
1015
if ! ok {
1016
1016
return ErrInvalidOutputPin
1017
1017
}
1018
- var txPinOut uint32
1018
+ var txPadOut uint32
1019
1019
// See CTRLA.RXPO bits of the SERCOM USART peripheral (page 945-946) for how
1020
1020
// pads are mapped to pinout values.
1021
1021
switch txPad {
1022
1022
case 0 :
1023
- txPinOut = 0
1023
+ txPadOut = 0
1024
1024
default :
1025
- // TODO: flow control (RTS/CTS)
1025
+ // should be flow control (RTS/CTS) pin
1026
1026
return ErrInvalidOutputPin
1027
1027
}
1028
1028
@@ -1033,12 +1033,32 @@ func (uart *UART) Configure(config UARTConfig) error {
1033
1033
}
1034
1034
// As you can see in the CTRLA.RXPO bits of the SERCOM USART peripheral
1035
1035
// (page 945), input pins are mapped directly.
1036
- rxPinOut := rxPad
1036
+ rxPadOut := rxPad
1037
1037
1038
1038
// configure pins
1039
1039
config .TX .Configure (PinConfig {Mode : txPinMode })
1040
1040
config .RX .Configure (PinConfig {Mode : rxPinMode })
1041
1041
1042
+ // configure RTS/CTS pins if provided
1043
+ if config .RTS != 0 && config .CTS != 0 {
1044
+ rtsPinMode , _ , ok := findPinPadMapping (uart .SERCOM , config .RTS )
1045
+ if ! ok {
1046
+ return ErrInvalidOutputPin
1047
+ }
1048
+
1049
+ ctsPinMode , _ , ok := findPinPadMapping (uart .SERCOM , config .CTS )
1050
+ if ! ok {
1051
+ return ErrInvalidInputPin
1052
+ }
1053
+
1054
+ // See CTRLA.RXPO bits of the SERCOM USART peripheral (page 945-946) for how
1055
+ // pads are mapped to pinout values.
1056
+ txPadOut = 2
1057
+
1058
+ config .RTS .Configure (PinConfig {Mode : rtsPinMode })
1059
+ config .CTS .Configure (PinConfig {Mode : ctsPinMode })
1060
+ }
1061
+
1042
1062
// reset SERCOM
1043
1063
uart .Bus .CTRLA .SetBits (sam .SERCOM_USART_INT_CTRLA_SWRST )
1044
1064
for uart .Bus .CTRLA .HasBits (sam .SERCOM_USART_INT_CTRLA_SWRST ) ||
@@ -1075,8 +1095,8 @@ func (uart *UART) Configure(config UARTConfig) error {
1075
1095
// set UART pads. This is not same as pins...
1076
1096
// SERCOM_USART_CTRLA_TXPO(txPad) |
1077
1097
// SERCOM_USART_CTRLA_RXPO(rxPad);
1078
- uart .Bus .CTRLA .SetBits ((txPinOut << sam .SERCOM_USART_INT_CTRLA_TXPO_Pos ) |
1079
- (rxPinOut << sam .SERCOM_USART_INT_CTRLA_RXPO_Pos ))
1098
+ uart .Bus .CTRLA .SetBits ((txPadOut << sam .SERCOM_USART_INT_CTRLA_TXPO_Pos ) |
1099
+ (rxPadOut << sam .SERCOM_USART_INT_CTRLA_RXPO_Pos ))
1080
1100
1081
1101
// Enable Transceiver and Receiver
1082
1102
//sercom->USART.CTRLB.reg |= SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN ;
0 commit comments