1+ #include "MF_SerialUartTask_RP2040.h"
2+
13
24//Arduino version string
35#define HAL_ARDUINO_STR "Arduino-Pico v" ARDUINO_PICO_VERSION_STR
@@ -165,9 +167,12 @@ void hal_print_pin_name(int pinnum) {
165167}
166168
167169
170+
171+ //SerialUartTask version
172+ #include "MF_SerialUartTask_RP2040.h"
173+
168174//create/get Serial bus (late binding)
169175//Serial BUS (&Serial, &Serial1, &Serial2) - ser0 &Serial is used for CLI via uart->USB converter
170-
171176MF_Serial * hal_get_ser_bus (int bus_id , int baud , MF_SerialMode mode , bool invert ) {
172177 if (bus_id < 0 || bus_id >= HAL_SER_NUM ) return nullptr ;
173178
@@ -186,16 +191,73 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
186191 break ;
187192 }
188193
189- /*
190- //uncomment one: SerialIRQ, SerialUART or SerialPIO and use uart0 or uart1
191- auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, ser1_txbuf, sizeof(ser1_txbuf), cfg.pin_ser1_rx, ser1_rxbuf, sizeof(ser1_rxbuf));
192- //auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
193- //auto *ser = new SerialDMA(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
194- //auto *ser = new SerialUART(uart1, cfg.pin_ser1_tx, pin_ser1_rx); //SerialUART default Arduino impementation (had some problems with this)
195- //auto *ser = new SerialPIO(cfg.pin_ser1_tx, pin_ser1_rx, 32); //PIO uarts, any pin allowed (not tested, but expect same as SerialUART)
196- hal_ser[1] = new MF_SerialPtrWrapper<decltype(ser)>( ser );
197- */
194+ //SerialUART default Arduino impementation (does not have TX buffer -> problem for ublox gps and mavlink ...)
195+ int pin_tx = -1 ;
196+ int pin_rx = -1 ;
197+ uart_inst_t * uart ;
198+ char taskname [16 ];
199+ switch (bus_id ) {
200+ case 0 :
201+ pin_tx = cfg .pin_ser0_tx ;
202+ pin_rx = cfg .pin_ser0_rx ;
203+ uart = uart0 ;
204+ strcpy (taskname , "uart0" );
205+ break ;
206+ case 1 :
207+ pin_tx = cfg .pin_ser1_tx ;
208+ pin_rx = cfg .pin_ser1_rx ;
209+ uart = uart1 ;
210+ strcpy (taskname , "uart1" );
211+ break ;
212+ default :
213+ return nullptr ;
214+ }
215+
216+ //exit if no pins defined
217+ if (pin_tx < 0 && pin_rx < 0 ) return nullptr ;
198218
219+ //create new MF_Serial
220+ if (!hal_ser [bus_id ]) {
221+ SerialUART * ser = new SerialUART (uart , pin_rx , pin_tx );
222+ hal_ser [bus_id ] = new MF_SerialUartTask (ser , taskname );
223+ }
224+
225+ //get ser from MF_SerialPtrWrapper, and configure it
226+ SerialUART * ser = ((MF_SerialUartTask * )hal_ser [bus_id ])-> _serial ;
227+ ser -> end ();
228+ ser -> setRX (pin_rx );
229+ ser -> setTX (pin_tx );
230+ ser -> setFIFOSize (256 );
231+ ser -> setInvertTX (invert );
232+ ser -> setInvertRX (invert );
233+ ser -> begin (baud , config );
234+
235+ return hal_ser [bus_id ];
236+ }
237+
238+
239+
240+ /* //SerialUART version - works
241+
242+ //create/get Serial bus (late binding)
243+ //Serial BUS (&Serial, &Serial1, &Serial2) - ser0 &Serial is used for CLI via uart->USB converter
244+ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert) {
245+ if(bus_id < 0 || bus_id >= HAL_SER_NUM) return nullptr;
246+
247+ uint16_t config;
248+
249+ switch(mode) {
250+ case MF_SerialMode::mf_SERIAL_8N1:
251+ config=SERIAL_8N1;
252+ break;
253+ case MF_SerialMode::mf_SERIAL_8E2:
254+ config=SERIAL_8E2;
255+ break;
256+ default:
257+ Serial.printf("\nERROR: hal_get_ser_bus bus_id=%d invalid mode\n\n", bus_id);
258+ return nullptr;
259+ break;
260+ }
199261
200262 //SerialUART default Arduino impementation (does not have TX buffer -> problem for ublox gps and mavlink ...)
201263 int pin_tx = -1;
@@ -238,6 +300,23 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
238300 return hal_ser[bus_id];
239301}
240302
303+
304+ */
305+
306+
307+
308+
309+
310+ /*
311+ //uncomment one: SerialIRQ, SerialUART or SerialPIO and use uart0 or uart1
312+ auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, ser1_txbuf, sizeof(ser1_txbuf), cfg.pin_ser1_rx, ser1_rxbuf, sizeof(ser1_rxbuf));
313+ //auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
314+ //auto *ser = new SerialDMA(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
315+ //auto *ser = new SerialUART(uart1, cfg.pin_ser1_tx, pin_ser1_rx); //SerialUART default Arduino impementation (had some problems with this)
316+ //auto *ser = new SerialPIO(cfg.pin_ser1_tx, pin_ser1_rx, 32); //PIO uarts, any pin allowed (not tested, but expect same as SerialUART)
317+ hal_ser[1] = new MF_SerialPtrWrapper<decltype(ser)>( ser );
318+ */
319+
241320/*
242321
243322MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert) {
0 commit comments