ltecat12 2.1.0.0
ltecat12.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 LTECAT12_H
29#define LTECAT12_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "mikrosdk_version.h"
36
37#ifdef __GNUC__
38#if mikroSDK_GET_VERSION < 20800ul
39#include "rcu_delays.h"
40#else
41#include "delays.h"
42#endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_digital_in.h"
47#include "drv_i2c_master.h"
48#include "drv_uart.h"
49
70#define LTECAT12_MAX9860_REG_INTR_STATS 0x00
71#define LTECAT12_MAX9860_REG_MIC_NG_AGC 0x01
72#define LTECAT12_MAX9860_REG_INTR_EN 0x02
73#define LTECAT12_MAX9860_REG_SYS_CLK 0x03
74#define LTECAT12_MAX9860_REG_STEREO_CLK_MSB 0x04
75#define LTECAT12_MAX9860_REG_STEREO_CLK_LSB 0x05
76#define LTECAT12_MAX9860_REG_AUDIO_INTERFACE_1 0x06
77#define LTECAT12_MAX9860_REG_AUDIO_INTERFACE_2 0x07
78#define LTECAT12_MAX9860_REG_VOICE_FILTER 0x08
79#define LTECAT12_MAX9860_REG_DAC_ATTENUATION 0x09
80#define LTECAT12_MAX9860_REG_ADC_OUTPUT_LEVELS 0x0A
81#define LTECAT12_MAX9860_REG_DAC_GAIN 0x0B
82#define LTECAT12_MAX9860_REG_MIC_GAIN 0x0C
83#define LTECAT12_MAX9860_REG_MIC_AGC 0x0E
84#define LTECAT12_MAX9860_REG_NOISE_GATE 0x0F
85#define LTECAT12_MAX9860_REG_SYS_SHUTDOWN 0x10
86
91#define LTECAT12_CMD_AT "AT"
92#define LTECAT12_CMD_ATI "ATI"
93#define LTECAT12_CMD_CFUN "AT+CFUN"
94#define LTECAT12_CMD_CREG "AT+CREG"
95#define LTECAT12_CMD_CGDCONT "AT+CGDCONT"
96#define LTECAT12_CMD_CESQ "AT+CESQ"
97#define LTECAT12_CMD_COPS "AT+COPS"
98#define LTECAT12_CMD_CMGS "AT+CMGS"
99#define LTECAT12_CMD_CMGF "AT+CMGF"
100#define LTECAT12_CMD_CGPADDR "AT+CGPADDR"
101#define LTECAT12_CMD_SICA "AT^SICA"
102#define LTECAT12_CMD_SISS "AT^SISS"
103#define LTECAT12_CMD_SISO "AT^SISO"
104#define LTECAT12_CMD_SISW "AT^SISW"
105#define LTECAT12_CMD_SISR "AT^SISR"
106#define LTECAT12_CMD_SISC "AT^SISC"
107#define LTECAT12_CMD_SGPSC "AT^SGPSC"
108#define LTECAT12_CMD_CHUP "AT+CHUP"
109#define LTECAT12_CMD_SCFG "AT^SCFG"
110#define LTECAT12_CMD_SAIC "AT^SAIC"
111#define LTECAT12_CMD_SNFS "AT^SNFS"
112#define LTECAT12_CMD_ATD "ATD"
113
118#define LTECAT12_PSCLK_12MHZ 0x10
119#define LTECAT12_LRCLK_8MHZ_MSB 0x10
120#define LTECAT12_LRCLK_8MHZ_LSB 0x00
121#define LTECAT12_DBCI_FALLING_EDGE 0x20
122#define LTECAT12_HIZ_ENABLE 0x08
123#define LTECAT12_TDM_ENABLE 0x04
124#define LTECAT12_ABCI_FALLING_EDGE 0x20
125#define LTECAT12_ADLY_ENABLE 0x10
126#define LTECAT12_STEREO_ENABLE 0x08
127#define LTECAT12_AVFLT_DISABLE 0x00
128#define LTECAT12_DVFLT_DISABLE 0x00
129#define LTECAT12_DVA_GAIN_0 0x06
130#define LTECAT12_ADC_GAIN_3 0x00
131#define LTECAT12_DAC_GAIN_0 0x00
132#define LTECAT12_DVST_GAIN_0 0x01
133#define LTECAT12_MIC_GAIN_0 0x20
134#define LTECAT12_PGAM_GAIN_0 0x14
135#define LTECAT12_AGCSRC_ENABLE 0x80
136#define LTECAT12_ANTH_DISABLE 0x00
137#define LTECAT12_AGCTH_MINUS_3 0x00
138#define LTECAT12_POWER_ON 0x80
139#define LTECAT12_DAC_ENABLE 0x08
140#define LTECAT12_ADCL_ADCR_ENABLE 0x03
141
146#define LTECAT12_PIN_STATE_HIGH 0x01
147#define LTECAT12_PIN_STATE_LOW 0x00
148
153#define LTECAT12_RSP_OK "OK"
154#define LTECAT12_RSP_ERROR "ERROR"
155#define LTECAT12_RSP_SYSSTART "^SYSSTART"
156
161#define LTECAT12_POWER_STATE_SWITCH 0
162#define LTECAT12_POWER_STATE_ON 1
163#define LTECAT12_POWER_STATE_REBOOT 2
164
170#define LTECAT12_TX_DRV_BUFFER_SIZE 300
171#define LTECAT12_RX_DRV_BUFFER_SIZE 300
172
178#define LTECAT12_ADDRESS 0x10
179 // ltecat12_cmd
181
196#define LTECAT12_MAP_MIKROBUS( cfg, mikrobus ) \
197 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
198 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
199 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
200 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
201 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
202 cfg.fsd = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
203 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
204 // ltecat12_map // ltecat12
207
212typedef struct
213{
214 // Output pins
215 digital_out_t rts;
216 digital_out_t fsd;
218 // Input pins
219 digital_in_t cts;
221 // Modules
222 i2c_master_t i2c;
223 uart_t uart;
225 // I2C slave address
228 // Buffers
229 uint8_t uart_rx_buffer[ LTECAT12_RX_DRV_BUFFER_SIZE ];
230 uint8_t uart_tx_buffer[ LTECAT12_TX_DRV_BUFFER_SIZE ];
232} ltecat12_t;
233
238typedef struct
239{
240 // Communication gpio pins
241 pin_name_t rx_pin;
242 pin_name_t tx_pin;
243 pin_name_t scl;
244 pin_name_t sda;
246 // Additional gpio pins
247 pin_name_t cts;
248 pin_name_t fsd;
249 pin_name_t rts;
251 // Static variable
252 uint32_t baud_rate;
254 uart_data_bits_t data_bit;
255 uart_parity_t parity_bit;
256 uart_stop_bits_t stop_bit;
257 uint32_t i2c_speed;
258 uint8_t i2c_address;
261
266typedef enum
267{
273
275
292
307
320err_t ltecat12_generic_write ( ltecat12_t *ctx, uint8_t *data_in, uint16_t len );
321
334err_t ltecat12_generic_read ( ltecat12_t *ctx, uint8_t *data_out, uint16_t len );
335
348err_t ltecat12_write_register ( ltecat12_t *ctx, uint8_t reg, uint8_t data_in );
349
362err_t ltecat12_read_register ( ltecat12_t *ctx, uint8_t reg, uint8_t *data_out );
363
376
386void ltecat12_set_fsd_pin ( ltecat12_t *ctx, uint8_t state );
387
397void ltecat12_set_rts_pin ( ltecat12_t *ctx, uint8_t state );
398
408
418void ltecat12_send_cmd ( ltecat12_t *ctx, uint8_t *cmd );
419
430void ltecat12_send_cmd_with_params ( ltecat12_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
431
441void ltecat12_send_cmd_check ( ltecat12_t *ctx, uint8_t *at_cmd_buf );
442
452void ltecat12_send_cmd_parameter_check ( ltecat12_t *ctx, uint8_t *at_cmd_buf );
453
463void ltecat12_set_sim_apn ( ltecat12_t *ctx, uint8_t *sim_apn );
464
475void ltecat12_send_sms_text ( ltecat12_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
476
490err_t ltecat12_send_sms_pdu ( ltecat12_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
491
492#ifdef __cplusplus
493}
494#endif
495#endif // LTECAT12_H
496 // ltecat12
498
499// ------------------------------------------------------------------------ END
#define LTECAT12_RX_DRV_BUFFER_SIZE
Definition: ltecat12.h:171
#define LTECAT12_TX_DRV_BUFFER_SIZE
LTE Cat.1 2 driver buffer size.
Definition: ltecat12.h:170
err_t ltecat12_read_register(ltecat12_t *ctx, uint8_t reg, uint8_t *data_out)
LTE Cat.1 2 MAX9860 reading function.
err_t ltecat12_init(ltecat12_t *ctx, ltecat12_cfg_t *cfg)
LTE Cat.1 2 initialization function.
err_t ltecat12_generic_write(ltecat12_t *ctx, uint8_t *data_in, uint16_t len)
LTE Cat.1 2 data writing function.
err_t ltecat12_max9860_cfg(ltecat12_t *ctx)
LTE Cat.1 2 MAX9860 configuration function.
void ltecat12_cfg_setup(ltecat12_cfg_t *cfg)
LTE Cat.1 2 configuration object setup function.
err_t ltecat12_write_register(ltecat12_t *ctx, uint8_t reg, uint8_t data_in)
LTE Cat.1 2 MAX9860 writing function.
void ltecat12_send_cmd_check(ltecat12_t *ctx, uint8_t *at_cmd_buf)
LTE Cat.1 2 check the sent command.
void ltecat12_set_fsd_pin(ltecat12_t *ctx, uint8_t state)
LTE Cat.1 2 set fsd pin function.
void ltecat12_set_sim_apn(ltecat12_t *ctx, uint8_t *sim_apn)
LTE Cat.1 2 set sim card APN.
err_t ltecat12_generic_read(ltecat12_t *ctx, uint8_t *data_out, uint16_t len)
LTE Cat.1 2 data reading function.
void ltecat12_send_sms_text(ltecat12_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.1 2 send SMS in text mode.
void ltecat12_send_cmd_parameter_check(ltecat12_t *ctx, uint8_t *at_cmd_buf)
LTE Cat.1 2 check the command parameters.
void ltecat12_send_cmd(ltecat12_t *ctx, uint8_t *cmd)
LTE Cat.1 2 send command function.
err_t ltecat12_send_sms_pdu(ltecat12_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
LTE Cat.1 2 send SMS in PDU mode.
uint8_t ltecat12_get_cts_pin(ltecat12_t *ctx)
LTE Cat.1 2 get cts pin function.
void ltecat12_set_rts_pin(ltecat12_t *ctx, uint8_t state)
LTE Cat.1 2 set rts pin function.
void ltecat12_send_cmd_with_params(ltecat12_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
LTE Cat.1 2 send command function with parameter.
ltecat12_return_value_t
LTE Cat.1 2 Click return value data.
Definition: ltecat12.h:267
@ LTECAT12_ERROR_CMD
Definition: ltecat12.h:271
@ LTECAT12_ERROR_TIMEOUT
Definition: ltecat12.h:270
@ LTECAT12_ERROR
Definition: ltecat12.h:269
@ LTECAT12_ERROR_UNKNOWN
Definition: ltecat12.h:272
@ LTECAT12_OK
Definition: ltecat12.h:268
LTE Cat.1 2 Click configuration object.
Definition: ltecat12.h:239
pin_name_t rts
Definition: ltecat12.h:249
uint32_t baud_rate
Definition: ltecat12.h:252
pin_name_t cts
Definition: ltecat12.h:247
uint32_t i2c_speed
Definition: ltecat12.h:257
bool uart_blocking
Definition: ltecat12.h:253
uart_data_bits_t data_bit
Definition: ltecat12.h:254
pin_name_t tx_pin
Definition: ltecat12.h:242
pin_name_t fsd
Definition: ltecat12.h:248
pin_name_t rx_pin
Definition: ltecat12.h:241
uart_stop_bits_t stop_bit
Definition: ltecat12.h:256
pin_name_t scl
Definition: ltecat12.h:243
uart_parity_t parity_bit
Definition: ltecat12.h:255
pin_name_t sda
Definition: ltecat12.h:244
uint8_t i2c_address
Definition: ltecat12.h:258
LTE Cat.1 2 Click context object.
Definition: ltecat12.h:213
digital_out_t fsd
Definition: ltecat12.h:216
digital_out_t rts
Definition: ltecat12.h:215
uart_t uart
Definition: ltecat12.h:223
i2c_master_t i2c
Definition: ltecat12.h:222
digital_in_t cts
Definition: ltecat12.h:219
uint8_t slave_address
Definition: ltecat12.h:226