ltecat1us  2.0.0.0
ltecat1us.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 LTECAT1US_H
29 #define LTECAT1US_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 
60 #define LTECAT1US_CMD_AT "AT"
61 #define LTECAT1US_CMD_ATI "ATI"
62 #define LTECAT1US_CMD_CGMR "AT+CGMR"
63 
64 #define LTECAT1US_CMD_CFUN "AT+CFUN"
65 #define LTECAT1US_CMD_CREG "AT+CREG"
66 #define LTECAT1US_CMD_CEREG "AT+CEREG"
67 #define LTECAT1US_CMD_CGDCONT "AT+CGDCONT"
68 #define LTECAT1US_CMD_CIMI "AT+CIMI"
69 #define LTECAT1US_CMD_CGATT "AT+CGATT"
70 #define LTECAT1US_CMD_CSQ "AT+CSQ"
71 #define LTECAT1US_CMD_CESQ "AT+CESQ"
72 #define LTECAT1US_CMD_COPS "AT+COPS"
73 
74 
80 #define DRV_RX_BUFFER_SIZE 500
81 #define DRV_TX_BUFFER_SIZE 100
82  // ltecat1us_set
84 
99 #define LTECAT1US_MAP_MIKROBUS( cfg, mikrobus ) \
100  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
101  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
102  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
103  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
104  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
105  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
106  // ltecat1us_map // ltecat1us
109 
114 typedef struct
115 {
116  // Output pins
117  digital_out_t rst;
118  digital_out_t cs;
119  digital_out_t rts;
120 
121  // Input pins
122  digital_in_t cts;
123 
124  // Modules
125  uart_t uart;
127  // Buffers
128  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
129  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
131 } ltecat1us_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140  pin_name_t rx_pin;
141  pin_name_t tx_pin;
143  // Additional gpio pins
144  //pin_name_t an;
145  pin_name_t rst;
146  pin_name_t cts;
147  pin_name_t cs;
148  pin_name_t rts;
149 
150  // Static variable
151  uint32_t baud_rate;
152  bool uart_blocking;
153  uart_data_bits_t data_bit;
154  uart_parity_t parity_bit;
155  uart_stop_bits_t stop_bit;
158 
163 typedef enum
164 {
166  LTECAT1US_ERROR = -1
167 
169 
186 
201 err_t ltecat1us_init ( ltecat1us_t *ctx, ltecat1us_cfg_t *cfg );
202 
214 void ltecat1us_generic_write ( ltecat1us_t *ctx, char *data_buf, uint16_t len );
215 
229 err_t ltecat1us_generic_read ( ltecat1us_t *ctx, char *data_buf, uint16_t max_len );
230 
231 
239 void ltecat1us_power_on ( ltecat1us_t *ctx );
240 
249 void ltecat1us_set_rst ( ltecat1us_t *ctx, uint8_t state );
250 
259 void ltecat1us_set_rts ( ltecat1us_t *ctx, uint8_t state );
260 
269 uint8_t ltecat1us_get_cts ( ltecat1us_t *ctx );
270 
280 void ltecat1us_send_cmd ( ltecat1us_t *ctx, char *cmd );
281 
292 void ltecat1us_send_cmd_with_parameter ( ltecat1us_t *ctx, char *at_cmd_buf, char *param_buf );
293 
303 void ltecat1us_send_cmd_check ( ltecat1us_t *ctx, char *at_cmd_buf );
304 
314 void ltecat1us_send_cmd_parameter_check ( ltecat1us_t *ctx, char *at_cmd_buf );
315 
325 void ltecat1us_set_sim_apn ( ltecat1us_t *ctx, char *sim_apn );
326 
337 void ltecat1us_send_text_message ( ltecat1us_t *ctx, char *phone_number, char *message_context );
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // LTECAT1US_H
343  // ltecat1us
345 
346 // ------------------------------------------------------------------------ END
ltecat1us_cfg_t
LTE Cat.1-US Click configuration object.
Definition: ltecat1us.h:136
ltecat1us_set_rst
void ltecat1us_set_rst(ltecat1us_t *ctx, uint8_t state)
Sets state of the RST pin.
ltecat1us_return_value_t
ltecat1us_return_value_t
LTE Cat.1-US Click return value data.
Definition: ltecat1us.h:162
ltecat1us_send_text_message
void ltecat1us_send_text_message(ltecat1us_t *ctx, char *phone_number, char *message_context)
LTE Cat.1-US send text message.
ltecat1us_t
LTE Cat.1-US Click context object.
Definition: ltecat1us.h:113
LTECAT1US_OK
Definition: ltecat1us.h:164
ltecat1us_set_sim_apn
void ltecat1us_set_sim_apn(ltecat1us_t *ctx, char *sim_apn)
Set sim card APN.
ltecat1us_set_rts
void ltecat1us_set_rts(ltecat1us_t *ctx, uint8_t state)
Sets state of the RTS pin.
ltecat1us_send_cmd_with_parameter
void ltecat1us_send_cmd_with_parameter(ltecat1us_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
ltecat1us_generic_write
void ltecat1us_generic_write(ltecat1us_t *ctx, char *data_buf, uint16_t len)
LTE Cat.1-US data writing function.
ltecat1us_send_cmd_check
void ltecat1us_send_cmd_check(ltecat1us_t *ctx, char *at_cmd_buf)
Check the sent command.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
LTE Cat.1-US driver buffer size.
Definition: ltecat1us.h:79
ltecat1us_cfg_setup
void ltecat1us_cfg_setup(ltecat1us_cfg_t *cfg)
LTE Cat.1-US configuration object setup function.
LTECAT1US_ERROR
Definition: ltecat1us.h:165
ltecat1us_send_cmd
void ltecat1us_send_cmd(ltecat1us_t *ctx, char *cmd)
Send command function.
ltecat1us_send_cmd_parameter_check
void ltecat1us_send_cmd_parameter_check(ltecat1us_t *ctx, char *at_cmd_buf)
Check the command parameters.
ltecat1us_generic_read
err_t ltecat1us_generic_read(ltecat1us_t *ctx, char *data_buf, uint16_t max_len)
LTE Cat.1-US data reading function.
ltecat1us_init
err_t ltecat1us_init(ltecat1us_t *ctx, ltecat1us_cfg_t *cfg)
LTE Cat.1-US initialization function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: ltecat1us.h:80
ltecat1us_get_cts
uint8_t ltecat1us_get_cts(ltecat1us_t *ctx)
CTS Pin Get function.
ltecat1us_power_on
void ltecat1us_power_on(ltecat1us_t *ctx)
LTE Cat.1-US module power on.