1
+ /* !
2
+ * @file drvUartUs100.h
3
+ *
4
+ * UART driver for a GPS component
5
+ *
6
+ * Adafruit invests time and resources providing this open source code,
7
+ * please support Adafruit and open-source hardware by purchasing
8
+ * products from Adafruit!
9
+ *
10
+ * Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11
+ *
12
+ * MIT license, all text here must be included in any redistribution.
13
+ *
14
+ */
15
+
16
+ #ifndef DRV_UART_GPS_H
17
+ #define DRV_UART_GPS_H
18
+ #include " drvUartBase.h"
19
+ #include " ../../gps/controller.h"
20
+
21
+
22
+ /* !
23
+ @brief Provides an interface for the US-100 Ultrasonic Distance Sensor over
24
+ UART.
25
+ */
26
+ class drvUartGps : public drvUartBase {
27
+
28
+ public:
29
+ /* !
30
+ @brief Instantiates a US-100 UART device.
31
+ @param hw_serial
32
+ Pointer to a HardwareSerial instance.
33
+ @param driver_name
34
+ The name of the driver.
35
+ @param port_num
36
+ The port number for the UART device corresponding to the Serial
37
+ instance.
38
+ */
39
+ drvUartGps (HardwareSerial *hw_serial, const char *driver_name,
40
+ uint32_t port_num)
41
+ : drvUartBase(hw_serial, driver_name, port_num) {
42
+ // Handled by drvUartBase constructor
43
+ }
44
+
45
+ #if HAS_SW_SERIAL
46
+ /* !
47
+ @brief Instantiates a US-100 UART device.
48
+ @param sw_serial
49
+ Pointer to a SoftwareSerial instance.
50
+ @param driver_name
51
+ The name of the driver.
52
+ @param port_num
53
+ The port number for the UART device corresponding to the Serial
54
+ instance.
55
+ */
56
+ drvUartGps (SoftwareSerial *sw_serial, const char *driver_name,
57
+ uint32_t port_num)
58
+ : drvUartBase(sw_serial, driver_name, port_num) {
59
+ // Handled by drvUartBase constructor
60
+ }
61
+ #endif // HAS_SW_SERIAL
62
+
63
+ /* !
64
+ @brief Destructor for a UART GPS.
65
+ */
66
+ ~drvUartGps () { /* TODO: Add back dtor */ }
67
+
68
+ /* !
69
+ @brief Initializes a UART GPS device.
70
+ @returns True if initialized successfully, False otherwise.
71
+ */
72
+ bool begin () override {
73
+ if (_hw_serial == nullptr )
74
+ return false ;
75
+
76
+ _gps = new GPSController ();
77
+ // TODO TUES: Note that _hw_serial isnt a pointer to the UARTHardware
78
+ // and instead the raw hw serial. This is fine
79
+ // but we'll have to refactor the GPS controller iface to take in
80
+ // a hardwareserial ptr rather than a UARTHardware ptr.
81
+ if (!_gps->SetInterface (_hw_serial)) {
82
+ WS_DEBUG_PRINTLN (" [uart] ERROR: Failed to set GPS interface!" );
83
+ delete _gps; // cleanup
84
+ _gps = nullptr ;
85
+ return false ;
86
+ }
87
+ WS_DEBUG_PRINTLN (" [uart] Initializing GPS device..." );
88
+ if (!_gps->begin ()) {
89
+ WS_DEBUG_PRINTLN (" [uart] ERROR: Failed to initialize GPS device!" );
90
+ delete _gps; // cleanup
91
+ _gps = nullptr ;
92
+ return false ;
93
+ }
94
+ WS_DEBUG_PRINTLN (" [uart] GPS device initialized successfully!" );
95
+ return true ;
96
+ }
97
+
98
+
99
+ protected:
100
+ GPSController *_gps;
101
+ };
102
+ #endif // DRV_UART_US100_H
0 commit comments