@@ -171,12 +171,16 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
171
171
break ;
172
172
}
173
173
uart_set_format (_uart, bits, stop, parity);
174
+ _fcnTx = gpio_get_function (_tx);
175
+ _fcnRx = gpio_get_function (_rx);
174
176
gpio_set_function (_tx, GPIO_FUNC_UART);
175
177
gpio_set_function (_rx, GPIO_FUNC_UART);
176
178
if (_rts != UART_PIN_NOT_DEFINED) {
179
+ _fcnRts = gpio_get_function (_rts);
177
180
gpio_set_function (_rts, GPIO_FUNC_UART);
178
181
}
179
182
if (_cts != UART_PIN_NOT_DEFINED) {
183
+ _fcnCts = gpio_get_function (_cts);
180
184
gpio_set_function (_cts, GPIO_FUNC_UART);
181
185
}
182
186
uart_set_hw_flow (_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
@@ -211,6 +215,7 @@ void SerialUART::end() {
211
215
irq_set_enabled (UART1_IRQ, false );
212
216
}
213
217
}
218
+
214
219
// Paranoia - ensure nobody else is using anything here at the same time
215
220
mutex_enter_blocking (&_mutex);
216
221
mutex_enter_blocking (&_fifoMutex);
@@ -219,6 +224,16 @@ void SerialUART::end() {
219
224
// Reset the mutexes once all is off/cleaned up
220
225
mutex_exit (&_fifoMutex);
221
226
mutex_exit (&_mutex);
227
+
228
+ // Restore pin functions
229
+ gpio_set_function (_tx, _fcnTx);
230
+ gpio_set_function (_rx, _fcnRx);
231
+ if (_rts != UART_PIN_NOT_DEFINED) {
232
+ gpio_set_function (_rts, _fcnRts);
233
+ }
234
+ if (_cts != UART_PIN_NOT_DEFINED) {
235
+ gpio_set_function (_cts, _fcnCts);
236
+ }
222
237
}
223
238
224
239
void SerialUART::_pumpFIFO () {
0 commit comments