Skip to content

Commit 02db2a3

Browse files
committed
doc: add detailed documentation for GPS UART driver functions
1 parent 2d830ea commit 02db2a3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

uart/gps_uart/gps_uart.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @file gps_uart.c
3+
* @brief A GPS driver that parses NMEA sentences from a GPS module.
4+
* @author Yousef Yasser, Rasheed Atia, Seif Abbas
5+
* @date 2025-01-21
6+
*/
7+
18
#include "hardware/uart.h"
29
#include "pico/stdlib.h"
310

@@ -22,6 +29,12 @@ typedef struct
2229
} GPSData;
2330

2431

32+
/**
33+
* @brief Initializes the UART interface for GPS communication.
34+
*
35+
* This function sets up the UART interface with the specified baud rate,
36+
* configures the TX and RX pins, and enables the UART FIFO.
37+
*/
2538
void uart_gps_init()
2639
{
2740
uart_init(UART_ID, BAUD_RATE);
@@ -34,6 +47,16 @@ void uart_gps_init()
3447
uart_set_fifo_enabled(UART_ID, true);
3548
}
3649

50+
51+
/**
52+
* @brief Validates the checksum of an NMEA sentence.
53+
*
54+
* This function calculates the checksum of the NMEA sentence and compares it
55+
* with the checksum provided in the sentence. If they match, the sentence is valid.
56+
*
57+
* @param nmea_string The NMEA sentence to validate.
58+
* @return true if the checksum is valid, false otherwise.
59+
*/
3760
bool validate_nmea_checksum(char *nmea_string)
3861
{
3962
int len = strlen(nmea_string);
@@ -71,6 +94,16 @@ bool validate_nmea_checksum(char *nmea_string)
7194
return is_valid;
7295
}
7396

97+
98+
/**
99+
* @brief Converts an NMEA coordinate to decimal degrees.
100+
*
101+
* This function converts an NMEA-formatted coordinate (DDMM.MMMM) to
102+
* decimal degrees (DD.DDDDDD).
103+
*
104+
* @param nmea_coord The NMEA coordinate string to convert.
105+
* @param decimal_coord Pointer to store the converted decimal coordinate.
106+
*/
74107
void convert_nmea_to_decimal(char *nmea_coord, float *decimal_coord)
75108
{
76109
float degrees = atof(nmea_coord) / 100.0;
@@ -80,6 +113,17 @@ void convert_nmea_to_decimal(char *nmea_coord, float *decimal_coord)
80113
*decimal_coord = int_degrees + (minutes / 60.0);
81114
}
82115

116+
117+
/**
118+
* @brief Parses an NMEA sentence and extracts GPS data.
119+
*
120+
* This function parses an NMEA sentence (currently only $GPRMC) and extracts
121+
* latitude, longitude, and validity information. It also validates the checksum.
122+
*
123+
* @param nmea_string The NMEA sentence to parse.
124+
* @param gps_data Pointer to the GPSData structure to store the parsed data.
125+
* @return true if the sentence was successfully parsed, false otherwise.
126+
*/
83127
bool parse_nmea_gps(char *nmea_string, GPSData *gps_data)
84128
{
85129
if (!validate_nmea_checksum(nmea_string))
@@ -129,6 +173,15 @@ bool parse_nmea_gps(char *nmea_string, GPSData *gps_data)
129173
}
130174
}
131175

176+
177+
/**
178+
* @brief Processes incoming GPS data from the UART interface.
179+
*
180+
* This function reads NMEA sentences from the UART interface, validates them,
181+
* and updates the GPSData structure if a valid sentence is received.
182+
*
183+
* @param gps_data Pointer to the GPSData structure to store the parsed data.
184+
*/
132185
void process_gps_data(GPSData *gps_data)
133186
{
134187
char nmea_buffer[MAX_NMEA_LENGTH];
@@ -159,6 +212,12 @@ void process_gps_data(GPSData *gps_data)
159212
}
160213
}
161214

215+
/**
216+
* @brief Main function for the GPS driver example.
217+
*
218+
* This function initializes the UART interface, waits for the GPS module to
219+
* cold start, and continuously processes and prints GPS data.
220+
*/
162221
int main()
163222
{
164223
stdio_init_all();

0 commit comments

Comments
 (0)