irnss  2.0.0.0
irnss.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef IRNSS_H
29 #define IRNSS_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define IRNSS_RSP_START "$"
60 #define IRNSS_RSP_DELIMITER ","
61 #define IRNSS_RSP_GNGGA "$GNGGA"
62 
67 #define IRNSS_GNGGA_ELEMENT_SIZE 15
68 #define IRNSS_GNGGA_TIME 1
69 #define IRNSS_GNGGA_LATITUDE 2
70 #define IRNSS_GNGGA_LATITUDE_SIDE 3
71 #define IRNSS_GNGGA_LONGITUDE 4
72 #define IRNSS_GNGGA_LONGITUDE_SIDE 5
73 #define IRNSS_GNGGA_QUALITY_INDICATOR 6
74 #define IRNSS_GNGGA_NUMBER_OF_SATELLITES 7
75 #define IRNSS_GNGGA_H_DILUTION_OF_POS 8
76 #define IRNSS_GNGGA_ALTITUDE 9
77 #define IRNSS_GNGGA_ALTITUDE_UNIT 10
78 #define IRNSS_GNGGA_GEOIDAL_SEPARATION 11
79 #define IRNSS_GNGGA_GEOIDAL_SEPARATION_UNIT 12
80 #define IRNSS_GNGGA_TIME_SINCE_LAST_DGPS 13
81 #define IRNSS_GNGGA_DGPS_REFERENCE_STATION_ID 14
82 
88 #define DRV_RX_BUFFER_SIZE 300
89 #define DRV_TX_BUFFER_SIZE 100
90  // irnss_set
92 
107 #define IRNSS_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
109  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
110  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
111  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
112 
113  // irnss_map // irnss
115 
120 typedef struct
121 {
122  // Output pins
123  digital_out_t rst;
124  digital_out_t wkp;
126  // Modules
127  uart_t uart;
129  // Buffers
130  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
131  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
133 } irnss_t;
134 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
145  // Additional gpio pins
146  pin_name_t rst;
147  pin_name_t wkp;
149  // Static variable
150  uint32_t baud_rate;
152  uart_data_bits_t data_bit;
153  uart_parity_t parity_bit;
154  uart_stop_bits_t stop_bit;
156 } irnss_cfg_t;
157 
162 typedef enum
163 {
164  IRNSS_OK = 0,
165  IRNSS_ERROR = -1
166 
168 
185 
199 err_t irnss_init ( irnss_t *ctx, irnss_cfg_t *cfg );
200 
213 err_t irnss_generic_write ( irnss_t *ctx, char *data_buf, uint16_t len );
214 
227 err_t irnss_generic_read ( irnss_t *ctx, char *data_buf, uint16_t max_len );
228 
239 void irnss_set_rst_pin_state ( irnss_t *ctx, uint8_t state );
240 
251 void irnss_set_wkp_pin_state ( irnss_t *ctx, uint8_t state );
252 
264 err_t irnss_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // IRNSS_H
270  // irnss
272 
273 // ------------------------------------------------------------------------ END
irnss_cfg_setup
void irnss_cfg_setup(irnss_cfg_t *cfg)
IRNSS configuration object setup function.
irnss_return_value_t
irnss_return_value_t
IRNSS Click return value data.
Definition: irnss.h:163
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
IRNSS driver buffer size.
Definition: irnss.h:88
irnss_t::rst
digital_out_t rst
Definition: irnss.h:123
irnss_cfg_t::baud_rate
uint32_t baud_rate
Definition: irnss.h:150
irnss_set_rst_pin_state
void irnss_set_rst_pin_state(irnss_t *ctx, uint8_t state)
Sets state of the rst pin setting.
irnss_cfg_t::tx_pin
pin_name_t tx_pin
Definition: irnss.h:143
irnss_parse_gngga
err_t irnss_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
IRNSS parse GNGGA function.
irnss_cfg_t::rx_pin
pin_name_t rx_pin
Definition: irnss.h:142
irnss_cfg_t::rst
pin_name_t rst
Definition: irnss.h:146
irnss_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: irnss.h:153
irnss_init
err_t irnss_init(irnss_t *ctx, irnss_cfg_t *cfg)
IRNSS initialization function.
irnss_generic_write
err_t irnss_generic_write(irnss_t *ctx, char *data_buf, uint16_t len)
IRNSS data writing function.
irnss_generic_read
err_t irnss_generic_read(irnss_t *ctx, char *data_buf, uint16_t max_len)
IRNSS data reading function.
IRNSS_OK
@ IRNSS_OK
Definition: irnss.h:164
IRNSS_ERROR
@ IRNSS_ERROR
Definition: irnss.h:165
irnss_t
IRNSS Click context object.
Definition: irnss.h:121
irnss_cfg_t::wkp
pin_name_t wkp
Definition: irnss.h:147
irnss_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: irnss.h:152
irnss_cfg_t::uart_blocking
bool uart_blocking
Definition: irnss.h:151
irnss_t::uart
uart_t uart
Definition: irnss.h:127
irnss_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: irnss.h:154
irnss_cfg_t
IRNSS Click configuration object.
Definition: irnss.h:140
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: irnss.h:89
irnss_t::wkp
digital_out_t wkp
Definition: irnss.h:124
irnss_set_wkp_pin_state
void irnss_set_wkp_pin_state(irnss_t *ctx, uint8_t state)
Sets state of the wkp pin setting.