gps3  2.0.0.0
gps3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef GPS3_H
36 #define GPS3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define GPS3_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
57 
63 #define GPS3_RETVAL uint8_t
64 
65 #define GPS3_OK 0x00
66 #define GPS3_INIT_ERROR 0xFF
67 
73 #define GPS3_NEMA_GPGGA 1
74 #define GPS3_NEMA_GPGLL 3
75 #define GPS3_NEMA_GPGGA_NUM_ELEMENT 15
76 #define GPS3_NEMA_GPGLL_NUM_ELEMENT 5
77 
83 #define GPS3_GPGGA_TIME 1
84 #define GPS3_GPGGA_LATITUDE 2
85 #define GPS3_GPGGA_LATITUDE_SIDE 3
86 #define GPS3_GPGGA_LONGITUDE 4
87 #define GPS3_GPGGA_LONGITUDE_SIDE 5
88 #define GPS3_GPGGA_QUALITY_INDICATOR 6
89 #define GPS3_GPGGA_NUMBER_OF_SATELLITES 7
90 #define GPS3_GPGGA_H_DILUTION_OF_POS 8
91 #define GPS3_GPGGA_ALTITUDE 9
92 #define GPS3_GPGGA_ALTITUDE_UNIT 10
93 #define GPS3_GPGGA_GEOIDAL_SEPARATION 11
94 #define GPS3_GPGGA_GEOIDAL_SEPARATION_UNIT 12
95 #define GPS3_GPGGA_TIME_SINCE_LAST_DGPS 13
96 #define GPS3_GPGGA_DGPS_REFERENCE_STATION_ID 14
97 
103 #define GPS3_GPGLL_LATITUDE 1
104 #define GPS3_GPGLL_LATITUDE_SIDE 2
105 #define GPS3_GPGLL_LONGITUDE 3
106 #define GPS3_GPGLL_LONGITUDE_SIDE 4
107 
113 #define GPS3_ERROR_COMMAND_OR_ELEMENT 0xFF
114 #define GPS3_ERROR_START_OR_END_COMMAND 0x8F
115 #define GPS3_ERROR_NEXT_ELEMENT 0x4F
116 #define GPS3_ERROR_CURRENT_ELEMENT 0x2F
117 #define GPS3_NO_ERROR 0x00
118 
124 #define DRV_RX_BUFFER_SIZE 1000
125  // End group macro
128 // --------------------------------------------------------------- PUBLIC TYPES
136 typedef struct
137 {
138  // Output pins
139 
140  digital_out_t rst;
141 
142  // Modules
143 
144  uart_t uart;
145 
146  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
147  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
148 
149 } gps3_t;
150 
154 typedef struct
155 {
156  // Communication gpio pins
157 
158  pin_name_t rx_pin;
159  pin_name_t tx_pin;
160 
161  // Additional gpio pins
162 
163  pin_name_t rst;
164 
165  // static variable
166 
167  uint32_t baud_rate; // Clock speed.
169  uart_data_bits_t data_bit; // Data bits.
170  uart_parity_t parity_bit; // Parity bit.
171  uart_stop_bits_t stop_bit; // Stop bits.
172 
173 } gps3_cfg_t;
174 
178 typedef uint8_t gps3_error_t;
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
200 void gps3_cfg_setup ( gps3_cfg_t *cfg );
201 
209 GPS3_RETVAL gps3_init ( gps3_t *ctx, gps3_cfg_t *cfg );
210 
215 void gps3_module_wakeup ( gps3_t *ctx );
216 
222 void gps3_set_rst_pin ( gps3_t *ctx, uint8_t state );
223 
230 void gps3_generic_write ( gps3_t *ctx, char *data_buf, uint16_t len );
231 
239 int16_t gps3_generic_read ( gps3_t *ctx, char *data_buf, uint16_t max_len );
240 
250 (
251  char *rsp, uint8_t command,
252  uint8_t element, char *parser_buf
253 );
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // _GPS3_H_
259  // End public_function group
262 
263 // ------------------------------------------------------------------------- END
void gps3_generic_write(gps3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void gps3_cfg_setup(gps3_cfg_t *cfg)
Config Object Initialization function.
pin_name_t rx_pin
Definition: gps3.h:158
void gps3_module_wakeup(gps3_t *ctx)
Wake-up module.
void gps3_set_rst_pin(gps3_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
bool uart_blocking
Definition: gps3.h:168
GPS3_RETVAL gps3_init(gps3_t *ctx, gps3_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition: gps3.h:136
#define GPS3_RETVAL
Definition: gps3.h:63
Click configuration structure definition.
Definition: gps3.h:154
gps3_error_t gps3_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
pin_name_t tx_pin
Definition: gps3.h:159
uart_data_bits_t data_bit
Definition: gps3.h:169
uart_stop_bits_t stop_bit
Definition: gps3.h:171
digital_out_t rst
Definition: gps3.h:140
#define DRV_RX_BUFFER_SIZE
Definition: gps3.h:124
uint32_t baud_rate
Definition: gps3.h:167
uart_parity_t parity_bit
Definition: gps3.h:170
pin_name_t rst
Definition: gps3.h:163
uint8_t gps3_error_t
Error type.
Definition: gps3.h:178
uart_t uart
Definition: gps3.h:144
int16_t gps3_generic_read(gps3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.