ltecat4  2.1.0.0
ltecat4.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 LTECAT4_H
29 #define LTECAT4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 #include "drv_uart.h"
53 
74 #define LTECAT4_MAX9860_REG_INTR_STATS 0x00
75 #define LTECAT4_MAX9860_REG_MIC_NG_AGC 0x01
76 #define LTECAT4_MAX9860_REG_INTR_EN 0x02
77 #define LTECAT4_MAX9860_REG_SYS_CLK 0x03
78 #define LTECAT4_MAX9860_REG_STEREO_CLK_MSB 0x04
79 #define LTECAT4_MAX9860_REG_STEREO_CLK_LSB 0x05
80 #define LTECAT4_MAX9860_REG_AUDIO_INTERFACE_1 0x06
81 #define LTECAT4_MAX9860_REG_AUDIO_INTERFACE_2 0x07
82 #define LTECAT4_MAX9860_REG_VOICE_FILTER 0x08
83 #define LTECAT4_MAX9860_REG_DAC_ATTENUATION 0x09
84 #define LTECAT4_MAX9860_REG_ADC_OUTPUT_LEVELS 0x0A
85 #define LTECAT4_MAX9860_REG_DAC_GAIN 0x0B
86 #define LTECAT4_MAX9860_REG_MIC_GAIN 0x0C
87 #define LTECAT4_MAX9860_REG_MIC_AGC 0x0E
88 #define LTECAT4_MAX9860_REG_NOISE_GATE 0x0F
89 #define LTECAT4_MAX9860_REG_SYS_SHUTDOWN 0x10
90 
95 #define LTECAT4_PSCLK_24MHZ 0x20
96 #define LTECAT4_LRCLK_8MHZ_MSB 0x10
97 #define LTECAT4_LRCLK_8MHZ_LSB 0x62
98 #define LTECAT4_DBCI_FALLING_EDGE 0x20
99 #define LTECAT4_HIZ_ENABLE 0x08
100 #define LTECAT4_TDM_ENABLE 0x04
101 #define LTECAT4_ABCI_FALLING_EDGE 0x20
102 #define LTECAT4_ADLY_ENABLE 0x10
103 #define LTECAT4_STEREO_ENABLE 0x08
104 #define LTECAT4_AVFLT_DISABLE 0x00
105 #define LTECAT4_DVFLT_DISABLE 0x00
106 #define LTECAT4_DVA_GAIN_0 0x06
107 #define LTECAT4_ADC_GAIN_3 0x00
108 #define LTECAT4_DAC_GAIN_0 0x00
109 #define LTECAT4_DVST_GAIN_0 0x01
110 #define LTECAT4_MIC_GAIN_30 0x60
111 #define LTECAT4_PGAM_GAIN_20 0x00
112 #define LTECAT4_AGCSRC_ENABLE 0x80
113 #define LTECAT4_AGCHLD_50 0x01
114 #define LTECAT4_ANTH_DISABLE 0x00
115 #define LTECAT4_AGCTH_MINUS_3 0x00
116 #define LTECAT4_POWER_ON 0x80
117 #define LTECAT4_DAC_ENABLE 0x08
118 #define LTECAT4_ADCL_ADCR_ENABLE 0x03
119 
124 #define LTECAT4_CMD_AT "AT"
125 #define LTECAT4_CMD_GET_MODEL_ID "AT+CGMM"
126 #define LTECAT4_CMD_GET_SW_VERSION "AT+CGMR"
127 #define LTECAT4_CMD_GET_SERIAL_NUM "AT+CGSN"
128 #define LTECAT4_CMD_FACTORY_RESET "AT&F"
129 #define LTECAT4_CMD_SET_UE_FUNCTIONALITY "AT+CFUN"
130 #define LTECAT4_CMD_NETWORK_REGISTRATION "AT+CREG"
131 #define LTECAT4_CMD_SIGNAL_QUALITY_REPORT "AT+CSQ"
132 #define LTECAT4_CMD_OPERATOR_SELECTION "AT+COPS"
133 #define LTECAT4_CMD_SEND_SMS "AT+CMGS"
134 #define LTECAT4_CMD_SELECT_SMS_FORMAT "AT+CMGF"
135 #define LTECAT4_CMD_DEFINE_PDP_CONTEXT "AT+CGDCONT"
136 #define LTECAT4_CMD_SHOW_PDP_ADDRESS "AT+CGPADDR"
137 #define LTECAT4_CMD_ACTIVATE_PDP_CONTEXT "AT+QIACT"
138 #define LTECAT4_CMD_OPEN_SOCKET "AT+QIOPEN"
139 #define LTECAT4_CMD_CLOSE_SOCKET "AT+QICLOSE"
140 #define LTECAT4_CMD_SEND_DATA "AT+QISEND"
141 #define LTECAT4_CMD_RECEIVE_DATA "AT+QIRD"
142 #define LTECAT4_CMD_TURN_ON_GNSS "AT+QGPS"
143 #define LTECAT4_CMD_ACQUIRE_NMEA_SENTENCES "AT+QGPSGNMEA"
144 #define LTECAT4_CMD_SET_MIC_GAIN "AT+QMIC"
145 #define LTECAT4_CMD_CONFIG_AUDIO_INTERFACE "AT+QDAI"
146 #define LTECAT4_CMD_DIAL_NUMBER "ATD"
147 #define LTECAT4_CMD_TERMINATE_CALL "ATH"
148 #define LTECAT4_CMD_ANSWER_CALL "ATA"
149 #define LTECAT4_CMD_LIST_CALLS "AT+CLCC"
150 #define LTECAT4_CMD_CONFIG_URC_INDICATION "AT+QURCCFG"
151 
156 #define LTECAT4_RSP_START "$"
157 #define LTECAT4_RSP_DELIMITER ","
158 #define LTECAT4_RSP_END "\r\n"
159 #define LTECAT4_RSP_GGA "GGA"
160 
165 #define LTECAT4_RSP_OK "OK"
166 #define LTECAT4_RSP_ERROR "ERROR"
167 
172 #define LTECAT4_URC_RECEIVED_DATA "+QIURC:"
173 #define LTECAT4_URC_RING "RING"
174 #define LTECAT4_URC_NO_CARRIER "NO CARRIER"
175 
180 #define LTECAT4_POWER_STATE_OFF 0
181 #define LTECAT4_POWER_STATE_ON 1
182 
187 #define LTECAT4_GGA_ELEMENT_SIZE 15
188 #define LTECAT4_GGA_TIME 1
189 #define LTECAT4_GGA_LATITUDE 2
190 #define LTECAT4_GGA_LATITUDE_SIDE 3
191 #define LTECAT4_GGA_LONGITUDE 4
192 #define LTECAT4_GGA_LONGITUDE_SIDE 5
193 #define LTECAT4_GGA_QUALITY_INDICATOR 6
194 #define LTECAT4_GGA_NUMBER_OF_SATELLITES 7
195 #define LTECAT4_GGA_H_DILUTION_OF_POS 8
196 #define LTECAT4_GGA_ALTITUDE 9
197 #define LTECAT4_GGA_ALTITUDE_UNIT 10
198 #define LTECAT4_GGA_GEOIDAL_SEPARATION 11
199 #define LTECAT4_GGA_GEOIDAL_SEPARATION_UNIT 12
200 #define LTECAT4_GGA_TIME_SINCE_LAST_DGPS 13
201 #define LTECAT4_GGA_DGPS_REFERENCE_STATION_ID 14
202 
208 #define LTECAT4_TX_DRV_BUFFER_SIZE 256
209 #define LTECAT4_RX_DRV_BUFFER_SIZE 256
210 
216 #define LTECAT4_DEVICE_ADDRESS 0x10
217  // ltecat4_cmd
219 
234 #define LTECAT4_MAP_MIKROBUS( cfg, mikrobus ) \
235  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
236  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
237  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
238  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
239  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
240  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
241  cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
242  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
243  // ltecat4_map // ltecat4
246 
251 typedef struct
252 {
253  // Output pins
254  digital_out_t pwr;
255  digital_out_t rts;
257  // Input pins
258  digital_in_t ring;
259  digital_in_t cts;
261  // Modules
262  i2c_master_t i2c;
263  uart_t uart;
265  // I2C slave address
266  uint8_t slave_address;
268  // Buffers
269  uint8_t uart_rx_buffer[ LTECAT4_RX_DRV_BUFFER_SIZE ];
270  uint8_t uart_tx_buffer[ LTECAT4_TX_DRV_BUFFER_SIZE ];
271  uint8_t cmd_buffer[ LTECAT4_TX_DRV_BUFFER_SIZE ];
273 } ltecat4_t;
274 
279 typedef struct
280 {
281  // Communication gpio pins
282  pin_name_t rx_pin;
283  pin_name_t tx_pin;
284  pin_name_t scl;
285  pin_name_t sda;
287  // Additional gpio pins
288  pin_name_t pwr;
289  pin_name_t rts;
290  pin_name_t ring;
291  pin_name_t cts;
293  // Static variable
294  uint32_t baud_rate;
296  uart_data_bits_t data_bit;
297  uart_parity_t parity_bit;
298  uart_stop_bits_t stop_bit;
299  uint32_t i2c_speed;
300  uint8_t i2c_address;
302 } ltecat4_cfg_t;
303 
308 typedef enum
309 {
315 
317 
334 
348 err_t ltecat4_init ( ltecat4_t *ctx, ltecat4_cfg_t *cfg );
349 
362 err_t ltecat4_write_register ( ltecat4_t *ctx, uint8_t reg, uint8_t data_in );
363 
376 err_t ltecat4_read_register ( ltecat4_t *ctx, uint8_t reg, uint8_t *data_out );
377 
390 
403 err_t ltecat4_generic_write ( ltecat4_t *ctx, uint8_t *data_in, uint16_t len );
404 
417 err_t ltecat4_generic_read ( ltecat4_t *ctx, uint8_t *data_out, uint16_t len );
418 
428 void ltecat4_set_pwr_pin ( ltecat4_t *ctx, uint8_t state );
429 
439 void ltecat4_set_rts_pin ( ltecat4_t *ctx, uint8_t state );
440 
450 
460 
472 void ltecat4_set_power_state ( ltecat4_t *ctx, uint8_t state );
473 
483 void ltecat4_send_cmd ( ltecat4_t *ctx, uint8_t *cmd );
484 
495 void ltecat4_send_cmd_par ( ltecat4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
496 
506 void ltecat4_send_cmd_check ( ltecat4_t *ctx, uint8_t *at_cmd_buf );
507 
517 void ltecat4_set_sim_apn ( ltecat4_t *ctx, uint8_t *sim_apn );
518 
529 void ltecat4_send_sms_text ( ltecat4_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
530 
544 err_t ltecat4_send_sms_pdu ( ltecat4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
545 
555 void ltecat4_dial_number ( ltecat4_t *ctx, uint8_t *phone_number );
556 
568 err_t ltecat4_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
569 
570 #ifdef __cplusplus
571 }
572 #endif
573 #endif // LTECAT4_H
574  // ltecat4
576 
577 // ------------------------------------------------------------------------ END
ltecat4_t::rts
digital_out_t rts
Definition: ltecat4.h:255
ltecat4_t::pwr
digital_out_t pwr
Definition: ltecat4.h:254
ltecat4_cfg_t::cts
pin_name_t cts
Definition: ltecat4.h:291
ltecat4_send_sms_text
void ltecat4_send_sms_text(ltecat4_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.4 send SMS in text mode.
ltecat4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ltecat4.h:298
ltecat4_cfg_setup
void ltecat4_cfg_setup(ltecat4_cfg_t *cfg)
LTE Cat.4 configuration object setup function.
ltecat4_set_sim_apn
void ltecat4_set_sim_apn(ltecat4_t *ctx, uint8_t *sim_apn)
Set sim card APN.
ltecat4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ltecat4.h:297
ltecat4_cfg_t::pwr
pin_name_t pwr
Definition: ltecat4.h:288
LTECAT4_RX_DRV_BUFFER_SIZE
#define LTECAT4_RX_DRV_BUFFER_SIZE
Definition: ltecat4.h:209
ltecat4_return_value_t
ltecat4_return_value_t
LTE Cat.4 Click return value data.
Definition: ltecat4.h:309
ltecat4_send_cmd_par
void ltecat4_send_cmd_par(ltecat4_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
ltecat4_parse_gga
err_t ltecat4_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
LTE Cat.4 parse GGA function.
ltecat4_get_ring_pin
uint8_t ltecat4_get_ring_pin(ltecat4_t *ctx)
LTE Cat.4 get RING pin function.
ltecat4_send_cmd
void ltecat4_send_cmd(ltecat4_t *ctx, uint8_t *cmd)
Send command function.
LTECAT4_ERROR_TIMEOUT
@ LTECAT4_ERROR_TIMEOUT
Definition: ltecat4.h:312
ltecat4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ltecat4.h:282
ltecat4_t::slave_address
uint8_t slave_address
Definition: ltecat4.h:266
LTECAT4_TX_DRV_BUFFER_SIZE
#define LTECAT4_TX_DRV_BUFFER_SIZE
LTE Cat.4 driver buffer size.
Definition: ltecat4.h:208
ltecat4_t::uart
uart_t uart
Definition: ltecat4.h:263
ltecat4_cfg_t
LTE Cat.4 Click configuration object.
Definition: ltecat4.h:280
ltecat4_t::ring
digital_in_t ring
Definition: ltecat4.h:258
ltecat4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ltecat4.h:299
ltecat4_init
err_t ltecat4_init(ltecat4_t *ctx, ltecat4_cfg_t *cfg)
LTE Cat.4 initialization function.
ltecat4_t::i2c
i2c_master_t i2c
Definition: ltecat4.h:262
ltecat4_cfg_t::uart_blocking
bool uart_blocking
Definition: ltecat4.h:295
ltecat4_cfg_t::scl
pin_name_t scl
Definition: ltecat4.h:284
ltecat4_cfg_t::i2c_address
uint8_t i2c_address
Definition: ltecat4.h:300
ltecat4_cfg_t::baud_rate
uint32_t baud_rate
Definition: ltecat4.h:294
ltecat4_set_rts_pin
void ltecat4_set_rts_pin(ltecat4_t *ctx, uint8_t state)
LTE Cat.4 set RTS pin function.
ltecat4_cfg_t::sda
pin_name_t sda
Definition: ltecat4.h:285
ltecat4_config_codec
err_t ltecat4_config_codec(ltecat4_t *ctx)
LTE Cat.4 config codec function.
ltecat4_generic_write
err_t ltecat4_generic_write(ltecat4_t *ctx, uint8_t *data_in, uint16_t len)
LTE Cat.4 data writing function.
ltecat4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ltecat4.h:283
ltecat4_cfg_t::ring
pin_name_t ring
Definition: ltecat4.h:290
ltecat4_read_register
err_t ltecat4_read_register(ltecat4_t *ctx, uint8_t reg, uint8_t *data_out)
LTE Cat.4 MAX9860 reading function.
ltecat4_send_sms_pdu
err_t ltecat4_send_sms_pdu(ltecat4_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.4 send SMS in PDU mode.
LTECAT4_ERROR_CMD
@ LTECAT4_ERROR_CMD
Definition: ltecat4.h:313
ltecat4_dial_number
void ltecat4_dial_number(ltecat4_t *ctx, uint8_t *phone_number)
LTE Cat.4 dial number.
ltecat4_set_pwr_pin
void ltecat4_set_pwr_pin(ltecat4_t *ctx, uint8_t state)
LTE Cat.4 set PWR pin function.
ltecat4_set_power_state
void ltecat4_set_power_state(ltecat4_t *ctx, uint8_t state)
LTE Cat.4 set power state function.
ltecat4_generic_read
err_t ltecat4_generic_read(ltecat4_t *ctx, uint8_t *data_out, uint16_t len)
LTE Cat.4 data reading function.
ltecat4_t::cts
digital_in_t cts
Definition: ltecat4.h:259
LTECAT4_OK
@ LTECAT4_OK
Definition: ltecat4.h:310
LTECAT4_ERROR_UNKNOWN
@ LTECAT4_ERROR_UNKNOWN
Definition: ltecat4.h:314
ltecat4_cfg_t::rts
pin_name_t rts
Definition: ltecat4.h:289
ltecat4_send_cmd_check
void ltecat4_send_cmd_check(ltecat4_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
ltecat4_get_cts_pin
uint8_t ltecat4_get_cts_pin(ltecat4_t *ctx)
LTE Cat.4 get CTS pin function.
LTECAT4_ERROR
@ LTECAT4_ERROR
Definition: ltecat4.h:311
ltecat4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ltecat4.h:296
ltecat4_t
LTE Cat.4 Click context object.
Definition: ltecat4.h:252
ltecat4_write_register
err_t ltecat4_write_register(ltecat4_t *ctx, uint8_t reg, uint8_t data_in)
LTE Cat.4 MAX9860 writing function.