lr14  2.1.0.0
lr14.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 LR14_H
29 #define LR14_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_uart.h"
52 
73 #define LR14_CMD_AT "AT"
74 #define LR14_CMD_TOGGLE_ECHO "ATE"
75 #define LR14_CMD_FACTORY_RESET "ATR"
76 #define LR14_CMD_GET_MODEL_ID "AT+HWMODEL"
77 #define LR14_CMD_GET_FW_VERSION "AT+VER"
78 #define LR14_CMD_GET_SERIAL_NUMBER "AT+SN"
79 #define LR14_CMD_NETWORK_WORK_MODE "AT+NWM"
80 #define LR14_CMD_P2P_MODE_FREQUENCY "AT+PFREQ"
81 #define LR14_CMD_P2P_MODE_SPREADING_FACTOR "AT+PSF"
82 #define LR14_CMD_P2P_MODE_BANDWIDTH "AT+PBW"
83 #define LR14_CMD_P2P_MODE_CODE_RATE "AT+PCR"
84 #define LR14_CMD_P2P_MODE_PREAMBLE_LENGTH "AT+PPL"
85 #define LR14_CMD_P2P_MODE_TX_POWER "AT+PTP"
86 #define LR14_CMD_P2P_RX_MODE "AT+PRECV"
87 #define LR14_CMD_P2P_TX_MODE "AT+PSEND"
88 
93 #define LR14_RSP_OK "OK"
94 #define LR14_RSP_ERROR "AT_ERROR"
95 #define LR14_RSP_PARAM_ERROR "AT_PARAM_ERROR"
96 #define LR14_RSP_BUSY_ERROR "AT_BUSY_ERROR"
97 #define LR14_RSP_TEST_PARAM_OVERFLOW "AT_TEST_PARAM_OVERFLOW"
98 #define LR14_RSP_NO_CLASSB_ENABLE "AT_NO_CLASSB_ENABLE"
99 #define LR14_RSP_NO_NETWORK_JOINED "AT_NO_NETWORK_JOINED"
100 #define LR14_RSP_RX_ERROR "AT_RX_ERROR"
101 #define LR14_RSP_INITIAL "----------------------"
102 
107 #define LR14_EVT_RX_P2P "+EVT:RXP2P"
108 #define LR14_EVT_RX_P2P_ERROR "+EVT:RXP2P RECEIVE ERROR"
109 #define LR14_EVT_RX_P2P_TIMEOUT "+EVT:RXP2P RECEIVE TIMEOUT"
110 #define LR14_EVT_TX_P2P "+EVT:TXP2P"
111 
117 #define LR14_TX_DRV_BUFFER_SIZE 200
118 #define LR14_RX_DRV_BUFFER_SIZE 600
119  // lr14_cmd
121 
136 #define LR14_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
138  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
139  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
140  // lr14_map // lr14
143 
148 typedef struct
149 {
150  // Output pins
151  digital_out_t rst;
153  // Modules
154  uart_t uart;
156  // Buffers
157  uint8_t uart_rx_buffer[ LR14_RX_DRV_BUFFER_SIZE ];
158  uint8_t uart_tx_buffer[ LR14_TX_DRV_BUFFER_SIZE ];
159  uint8_t cmd_buffer[ LR14_TX_DRV_BUFFER_SIZE ];
161 } lr14_t;
162 
167 typedef struct
168 {
169  // Communication gpio pins
170  pin_name_t rx_pin;
171  pin_name_t tx_pin;
173  // Additional gpio pins
174  pin_name_t rst;
176  // Static variable
177  uint32_t baud_rate;
179  uart_data_bits_t data_bit;
180  uart_parity_t parity_bit;
181  uart_stop_bits_t stop_bit;
183 } lr14_cfg_t;
184 
189 typedef enum
190 {
191  LR14_OK = 0,
194  LR14_ERROR_CMD = -3
195 
197 
214 
228 err_t lr14_init ( lr14_t *ctx, lr14_cfg_t *cfg );
229 
242 err_t lr14_generic_write ( lr14_t *ctx, uint8_t *data_in, uint16_t len );
243 
256 err_t lr14_generic_read ( lr14_t *ctx, uint8_t *data_out, uint16_t len );
257 
267 void lr14_set_rst_pin ( lr14_t *ctx, uint8_t state );
268 
277 void lr14_reset_device ( lr14_t *ctx );
278 
288 void lr14_cmd_run ( lr14_t *ctx, uint8_t *cmd );
289 
300 void lr14_cmd_set ( lr14_t *ctx, uint8_t *cmd, uint8_t *value );
301 
311 void lr14_cmd_get ( lr14_t *ctx, uint8_t *cmd );
312 
322 void lr14_cmd_help ( lr14_t *ctx, uint8_t *cmd );
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 #endif // LR14_H
328  // lr14
330 
331 // ------------------------------------------------------------------------ END
lr14_t::uart
uart_t uart
Definition: lr14.h:154
lr14_cmd_get
void lr14_cmd_get(lr14_t *ctx, uint8_t *cmd)
LR 14 cmd get function.
LR14_ERROR_TIMEOUT
@ LR14_ERROR_TIMEOUT
Definition: lr14.h:193
lr14_cfg_t::rst
pin_name_t rst
Definition: lr14.h:174
lr14_init
err_t lr14_init(lr14_t *ctx, lr14_cfg_t *cfg)
LR 14 initialization function.
lr14_cfg_t::baud_rate
uint32_t baud_rate
Definition: lr14.h:177
lr14_cmd_set
void lr14_cmd_set(lr14_t *ctx, uint8_t *cmd, uint8_t *value)
LR 14 cmd set function.
LR14_TX_DRV_BUFFER_SIZE
#define LR14_TX_DRV_BUFFER_SIZE
LR 14 driver buffer size.
Definition: lr14.h:117
lr14_cmd_run
void lr14_cmd_run(lr14_t *ctx, uint8_t *cmd)
LR 14 cmd run function.
lr14_generic_read
err_t lr14_generic_read(lr14_t *ctx, uint8_t *data_out, uint16_t len)
LR 14 data reading function.
lr14_reset_device
void lr14_reset_device(lr14_t *ctx)
LR 14 reset device function.
lr14_t::rst
digital_out_t rst
Definition: lr14.h:151
lr14_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lr14.h:181
lr14_cfg_t
LR 14 Click configuration object.
Definition: lr14.h:168
lr14_generic_write
err_t lr14_generic_write(lr14_t *ctx, uint8_t *data_in, uint16_t len)
LR 14 data writing function.
lr14_cmd_help
void lr14_cmd_help(lr14_t *ctx, uint8_t *cmd)
LR 14 cmd help function.
lr14_set_rst_pin
void lr14_set_rst_pin(lr14_t *ctx, uint8_t state)
LR 14 set RST pin function.
lr14_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lr14.h:170
LR14_OK
@ LR14_OK
Definition: lr14.h:191
lr14_cfg_setup
void lr14_cfg_setup(lr14_cfg_t *cfg)
LR 14 configuration object setup function.
lr14_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lr14.h:171
lr14_t
LR 14 Click context object.
Definition: lr14.h:149
lr14_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lr14.h:180
LR14_ERROR_CMD
@ LR14_ERROR_CMD
Definition: lr14.h:194
lr14_return_value_t
lr14_return_value_t
LR 14 Click return value data.
Definition: lr14.h:190
LR14_ERROR
@ LR14_ERROR
Definition: lr14.h:192
lr14_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lr14.h:179
lr14_cfg_t::uart_blocking
bool uart_blocking
Definition: lr14.h:178
LR14_RX_DRV_BUFFER_SIZE
#define LR14_RX_DRV_BUFFER_SIZE
Definition: lr14.h:118