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 600
125 #define DRV_TX_BUFFER_SIZE 50
126  // End group macro
129 // --------------------------------------------------------------- PUBLIC TYPES
137 typedef struct
138 {
139  // Output pins
140 
141  digital_out_t rst;
142 
143  // Modules
144 
145  uart_t uart;
146 
147  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
148  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
149 
150 } gps3_t;
151 
155 typedef struct
156 {
157  // Communication gpio pins
158 
159  pin_name_t rx_pin;
160  pin_name_t tx_pin;
161 
162  // Additional gpio pins
163 
164  pin_name_t rst;
165 
166  // static variable
167 
168  uint32_t baud_rate; // Clock speed.
170  uart_data_bits_t data_bit; // Data bits.
171  uart_parity_t parity_bit; // Parity bit.
172  uart_stop_bits_t stop_bit; // Stop bits.
173 
174 } gps3_cfg_t;
175 
179 typedef uint8_t gps3_error_t;
180  // End types group
182 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
183 
189 #ifdef __cplusplus
190 extern "C"{
191 #endif
192 
202 
211 
217 
223 void gps3_set_rst_pin ( gps3_t *ctx, uint8_t state );
224 
231 void gps3_generic_write ( gps3_t *ctx, char *data_buf, uint16_t len );
232 
240 int32_t gps3_generic_read ( gps3_t *ctx, char *data_buf, uint16_t max_len );
241 
251 (
252  char *rsp, uint8_t command,
253  uint8_t element, char *parser_buf
254 );
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif // _GPS3_H_
260  // End public_function group
263 
264 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps3.h:124
gps3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps3.h:172
gps3_t::rst
digital_out_t rst
Definition: gps3.h:141
GPS3_RETVAL
#define GPS3_RETVAL
Definition: gps3.h:63
gps3_init
GPS3_RETVAL gps3_init(gps3_t *ctx, gps3_cfg_t *cfg)
Initialization function.
gps3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps3.h:171
gps3_cfg_setup
void gps3_cfg_setup(gps3_cfg_t *cfg)
Config Object Initialization function.
gps3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps3.h:170
gps3_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps3.h:168
gps3_cfg_t::rst
pin_name_t rst
Definition: gps3.h:164
gps3_generic_read
int32_t gps3_generic_read(gps3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gps3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps3.h:160
gps3_generic_parser
gps3_error_t gps3_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
gps3_t
Click ctx object definition.
Definition: gps3.h:138
gps3_module_wakeup
void gps3_module_wakeup(gps3_t *ctx)
Wake-up module.
gps3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps3.h:159
gps3_cfg_t::uart_blocking
bool uart_blocking
Definition: gps3.h:169
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps3.h:125
gps3_t::uart
uart_t uart
Definition: gps3.h:145
gps3_error_t
uint8_t gps3_error_t
Error type.
Definition: gps3.h:179
gps3_set_rst_pin
void gps3_set_rst_pin(gps3_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
gps3_cfg_t
Click configuration structure definition.
Definition: gps3.h:156
gps3_generic_write
void gps3_generic_write(gps3_t *ctx, char *data_buf, uint16_t len)
Generic write function.