lteiot  2.0.0.0
lteiot.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 LTEIOT_H
36 #define LTEIOT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LTEIOT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
60 
66 #define LTEIOT_RETVAL uint8_t
67 
68 #define LTEIOT_OK 0x00
69 #define LTEIOT_INIT_ERROR 0xFF
70 
76 #define LTEIOT_MODULE_POWER_ON 1
77 #define LTEIOT_MODULE_POWER_OFF 0
78 
84 #define DRV_RX_BUFFER_SIZE 500
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t pwr;
101  digital_out_t rst;
102  digital_out_t cs;
103 
104  // Input pins
105 
106  digital_in_t ri;
107  digital_in_t rts;
108 
109  // Modules
110 
111  uart_t uart;
112 
113  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
114  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
115 
116 } lteiot_t;
117 
121 typedef struct
122 {
123  // Communication gpio pins
124 
125  pin_name_t rx_pin;
126  pin_name_t tx_pin;
127 
128  // Additional gpio pins
129 
130  pin_name_t pwr;
131  pin_name_t rst;
132  pin_name_t cs;
133  pin_name_t ri;
134  pin_name_t rts;
135 
136  // static variable
137 
138  uint32_t baud_rate; // Clock speed.
140  uart_data_bits_t data_bit; // Data bits.
141  uart_parity_t parity_bit; // Parity bit.
142  uart_stop_bits_t stop_bit; // Stop bits.
143 
144 } lteiot_cfg_t;
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
166 void lteiot_cfg_setup ( lteiot_cfg_t *cfg );
167 
176 
184 void lteiot_module_power( lteiot_t *ctx, uint8_t power_state );
185 
193 void lteiot_generic_write ( lteiot_t *ctx, char *data_buf, uint16_t len );
194 
204 int32_t lteiot_generic_read ( lteiot_t *ctx, char *data_buf, uint16_t max_len );
205 
212 void lteiot_send_command ( lteiot_t *ctx, char *command );
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif // _LTEIOT_H_
218  // End public_function group
221 
222 // ------------------------------------------------------------------------- END
pin_name_t rts
Definition: lteiot.h:134
int32_t lteiot_generic_read(lteiot_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
digital_out_t pwr
Definition: lteiot.h:100
pin_name_t cs
Definition: lteiot.h:132
bool uart_blocking
Definition: lteiot.h:139
digital_out_t rst
Definition: lteiot.h:101
pin_name_t tx_pin
Definition: lteiot.h:126
pin_name_t rx_pin
Definition: lteiot.h:125
pin_name_t ri
Definition: lteiot.h:133
uart_parity_t parity_bit
Definition: lteiot.h:141
digital_in_t rts
Definition: lteiot.h:107
void lteiot_cfg_setup(lteiot_cfg_t *cfg)
Config Object Initialization function.
uint32_t baud_rate
Definition: lteiot.h:138
void lteiot_send_command(lteiot_t *ctx, char *command)
Send command.
Click ctx object definition.
Definition: lteiot.h:96
#define DRV_RX_BUFFER_SIZE
Definition: lteiot.h:84
uart_stop_bits_t stop_bit
Definition: lteiot.h:142
uart_t uart
Definition: lteiot.h:111
pin_name_t rst
Definition: lteiot.h:131
void lteiot_generic_write(lteiot_t *ctx, char *data_buf, uint16_t len)
Generic write function.
#define LTEIOT_RETVAL
Definition: lteiot.h:66
pin_name_t pwr
Definition: lteiot.h:130
digital_in_t ri
Definition: lteiot.h:106
uart_data_bits_t data_bit
Definition: lteiot.h:140
Click configuration structure definition.
Definition: lteiot.h:121
LTEIOT_RETVAL lteiot_init(lteiot_t *ctx, lteiot_cfg_t *cfg)
Initialization function.
digital_out_t cs
Definition: lteiot.h:102
void lteiot_module_power(lteiot_t *ctx, uint8_t power_state)
Power module.