lyra24p  2.1.0.0
lyra24p.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 LYRA24P_H
29 #define LYRA24P_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 LYRA24P_CMD_AT "AT"
74 #define LYRA24P_CMD_ATPS "AT%S"
75 #define LYRA24P_CMD_ATF "AT&F"
76 #define LYRA24P_CMD_ATW "AT&W"
77 #define LYRA24P_CMD_ATI "ATI"
78 #define LYRA24P_CMD_ATS "ATS"
79 
84 #define LYRA24P_CMD_ATBNDD "AT+BNDD"
85 #define LYRA24P_CMD_ATBNDT "AT+BNDT"
86 #define LYRA24P_CMD_ATBNDX "AT+BNDX"
87 
92 #define LYRA24P_CMD_ATGCTM "AT+GCTM"
93 #define LYRA24P_CMD_ATGCFA "AT+GCFA"
94 #define LYRA24P_CMD_ATGCRD "AT+GCRD"
95 #define LYRA24P_CMD_ATGCWA "AT+GCWA"
96 #define LYRA24P_CMD_ATGCWC "AT+GCWC"
97 #define LYRA24P_CMD_ATLMTU "AT+LMTU"
98 
103 #define LYRA24P_CMD_ATGSMD "AT+GSMD"
104 #define LYRA24P_CMD_ATGSCB "AT+GSCB"
105 #define LYRA24P_CMD_ATGSCE "AT+GSCE"
106 #define LYRA24P_CMD_ATGSSB "AT+GSSB"
107 #define LYRA24P_CMD_ATGSSE "AT+GSSE"
108 #define LYRA24P_CMD_ATGSNO "AT+GSNO"
109 #define LYRA24P_CMD_ATGSWC "AT+GSWC"
110 #define LYRA24P_CMD_ATUUID "AT+UUID"
111 
116 #define LYRA24P_CMD_ATI2R "AT+I2R"
117 #define LYRA24P_CMD_ATI2W "AT+I2W"
118 
123 #define LYRA24P_CMD_ATAARA "AT+AARA"
124 #define LYRA24P_CMD_ATACMT "AT+ACMT"
125 #define LYRA24P_CMD_ATADAD "AT+ADAD"
126 #define LYRA24P_CMD_ATARST "AT+ARST"
127 #define LYRA24P_CMD_ATASRA "AT+ASRA"
128 #define LYRA24P_CMD_ATLADV "AT+LADV"
129 #define LYRA24P_CMD_ATLADVX "AT+LADVX"
130 #define LYRA24P_CMD_ATEADV "AT+EADV"
131 
136 #define LYRA24P_CMD_ATCSEC "AT+CSEC"
137 #define LYRA24P_CMD_ATLCON "AT+LCON"
138 #define LYRA24P_CMD_ATLDSC "AT+LDSC"
139 #define LYRA24P_CMD_ATLENC "AT+LENC"
140 
145 #define LYRA24P_CMD_ATSFMT "AT+SFMT"
146 #define LYRA24P_CMD_ATLSCN "AT+LSCN"
147 #define LYRA24P_CMD_ATLSCNX "AT+LSCNX"
148 
153 #define LYRA24P_CMD_LPHY "AT+LPHY"
154 
159 #define LYRA24P_CMD_ATPAIR "AT+PAIR"
160 #define LYRA24P_CMD_ATPCFG "AT+PCFG"
161 #define LYRA24P_CMD_ATPCNF "AT+PCNF"
162 #define LYRA24P_CMD_ATPKEY "AT+PKEY"
163 #define LYRA24P_CMD_ATPRSP "AT+PRSP"
164 #define LYRA24P_CMD_ATOOBL "AT+OOBL"
165 #define LYRA24P_CMD_ATOOBR "AT+OOBR"
166 #define LYRA24P_CMD_ATSIOC "AT+SIOC"
167 #define LYRA24P_CMD_ATSIOR "AT+SIOR"
168 #define LYRA24P_CMD_ATSIOW "AT+SIOW"
169 
174 #define LYRA24P_CMD_ATSPR "AT+SPR"
175 #define LYRA24P_CMD_ATSPW "AT+SPW"
176 
181 #define LYRA24P_CMD_ATREG "AT+REG"
182 #define LYRA24P_CMD_ATTXPO "AT+TXPO"
183 
188 #define LYRA24P_CMD_ATUFU "AT+UFU"
189 
194 #define LYRA24P_CMD_ATD "ATD"
195 #define LYRA24P_CMD_ATLVSP "AT+LVSP"
196 
201 #define LYRA24P_CMD_ATZ "ATZ"
202 
207 #define LYRA24P_ATI_ARG_DEV_NAME "0"
208 #define LYRA24P_ATI_ARG_FW_VER "3"
209 #define LYRA24P_ATI_ARG_BT_ADDR "4"
210 
215 #define LYRA24P_ATS_ARG_DEVNAME_FORMAT "103"
216 #define LYRA24P_ATS_VAL_DEVNAME "0"
217 
222 #define LYRA24P_RSP_OK "OK"
223 #define LYRA24P_RSP_ERROR "ERROR"
224 
229 #define LYRA24P_PREFIX_SYMBOL_END "\r\n"
230 #define LYRA24P_PREFIX_SYMBOL_QUERY "?"
231 #define LYRA24P_PREFIX_SYMBOL_SET_VAL "="
232 #define LYRA24P_PREFIX_SYMBOL_PLUS "+"
233 #define LYRA24P_PREFIX_SYMBOL_SEPARATOR ","
234 #define LYRA24P_PREFIX_SYMBOL_SPACE " "
235 #define LYRA24P_PREFIX_SYMBOL_PERCENT "%"
236 #define LYRA24P_PREFIX_SYMBOL_NULL ""
237 #define LYRA24P_PREFIX_SYMBOL_QUOTE "\""
238 #define LYRA24P_PREFIX_SYMBOL_ZERO "0"
239 
244 #define LYRA24P_PIN_STATE_LOW 0
245 #define LYRA24P_PIN_STATE_HIGH 1
246 
251 #define LYRA24P_QUERY_DIS 0
252 #define LYRA24P_QUERY_EN 1
253 
259 #define LYRA24P_TX_DRV_BUFFER_SIZE 100
260 #define LYRA24P_RX_DRV_BUFFER_SIZE 300
261  // lyra24p_cmd
263 
278 #define LYRA24P_MAP_MIKROBUS( cfg, mikrobus ) \
279  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
280  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
281  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
282  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
283  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
284  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
285  // lyra24p_map // lyra24p
288 
293 typedef struct
294 {
295  // Output pins
296  digital_out_t rst;
297  digital_out_t bt;
298  digital_out_t rts;
300  // Input pins
301  digital_in_t cts;
303  // Modules
304  uart_t uart;
306  // Buffers
307  uint8_t uart_rx_buffer[ LYRA24P_RX_DRV_BUFFER_SIZE ];
308  uint8_t uart_tx_buffer[ LYRA24P_TX_DRV_BUFFER_SIZE ];
310 } lyra24p_t;
311 
316 typedef struct
317 {
318  // Communication gpio pins
319  pin_name_t rx_pin;
320  pin_name_t tx_pin;
322  // Additional gpio pins
323  pin_name_t rst;
324  pin_name_t rts;
325  pin_name_t bt;
326  pin_name_t cts;
328  // Static variable
329  uint32_t baud_rate;
331  uart_data_bits_t data_bit;
332  uart_parity_t parity_bit;
333  uart_stop_bits_t stop_bit;
335 } lyra24p_cfg_t;
336 
341 typedef enum
342 {
344  LYRA24P_ERROR = -1
345 
347 
364 
378 err_t lyra24p_init ( lyra24p_t *ctx, lyra24p_cfg_t *cfg );
379 
389 
399 void lyra24p_set_bt_pin ( lyra24p_t *ctx, uint8_t state );
400 
410 void lyra24p_request_to_send ( lyra24p_t *ctx, uint8_t state );
411 
421 
434 err_t lyra24p_generic_write ( lyra24p_t *ctx, uint8_t *data_in, uint16_t len );
435 
448 err_t lyra24p_generic_read ( lyra24p_t *ctx, uint8_t *data_out, uint16_t len );
449 
461 err_t lyra24p_write_command ( lyra24p_t *ctx, uint8_t *command );
462 
478 err_t lyra24p_write_cmd_param ( lyra24p_t *ctx, uint8_t *command, uint8_t *cmd_val, uint8_t *prefix, uint8_t *param );
479 
491 err_t lyra24p_set_device_name ( lyra24p_t *ctx, uint8_t *device_name );
492 
507 err_t lyra24p_inquire_command ( lyra24p_t *ctx, uint8_t *command, uint8_t *cmd_val, uint8_t en_query );
508 
509 #ifdef __cplusplus
510 }
511 #endif
512 #endif // LYRA24P_H
513  // lyra24p
515 
516 // ------------------------------------------------------------------------ END
lyra24p_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lyra24p.h:332
LYRA24P_OK
@ LYRA24P_OK
Definition: lyra24p.h:343
lyra24p_cfg_t::uart_blocking
bool uart_blocking
Definition: lyra24p.h:330
LYRA24P_RX_DRV_BUFFER_SIZE
#define LYRA24P_RX_DRV_BUFFER_SIZE
Definition: lyra24p.h:260
lyra24p_cfg_setup
void lyra24p_cfg_setup(lyra24p_cfg_t *cfg)
LYRA 24P configuration object setup function.
lyra24p_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lyra24p.h:319
lyra24p_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lyra24p.h:333
lyra24p_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lyra24p.h:320
lyra24p_write_cmd_param
err_t lyra24p_write_cmd_param(lyra24p_t *ctx, uint8_t *command, uint8_t *cmd_val, uint8_t *prefix, uint8_t *param)
LYRA 24P command - command value - prefix - parameter writing function.
lyra24p_inquire_command
err_t lyra24p_inquire_command(lyra24p_t *ctx, uint8_t *command, uint8_t *cmd_val, uint8_t en_query)
LYRA 24P inquire command function.
lyra24p_t::rst
digital_out_t rst
Definition: lyra24p.h:296
lyra24p_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lyra24p.h:331
lyra24p_t::rts
digital_out_t rts
Definition: lyra24p.h:298
lyra24p_generic_write
err_t lyra24p_generic_write(lyra24p_t *ctx, uint8_t *data_in, uint16_t len)
LYRA 24P data writing function.
lyra24p_write_command
err_t lyra24p_write_command(lyra24p_t *ctx, uint8_t *command)
LYRA 24P command writing function.
lyra24p_cfg_t::rts
pin_name_t rts
Definition: lyra24p.h:324
lyra24p_cfg_t
LYRA 24P Click configuration object.
Definition: lyra24p.h:317
lyra24p_return_value_t
lyra24p_return_value_t
LYRA 24P Click return value data.
Definition: lyra24p.h:342
lyra24p_generic_read
err_t lyra24p_generic_read(lyra24p_t *ctx, uint8_t *data_out, uint16_t len)
LYRA 24P data reading function.
lyra24p_cfg_t::baud_rate
uint32_t baud_rate
Definition: lyra24p.h:329
lyra24p_hw_reset
void lyra24p_hw_reset(lyra24p_t *ctx)
LYRA 24P HW reset function.
lyra24p_cfg_t::bt
pin_name_t bt
Definition: lyra24p.h:325
LYRA24P_TX_DRV_BUFFER_SIZE
#define LYRA24P_TX_DRV_BUFFER_SIZE
LYRA 24P driver buffer size.
Definition: lyra24p.h:259
lyra24p_init
err_t lyra24p_init(lyra24p_t *ctx, lyra24p_cfg_t *cfg)
LYRA 24P initialization function.
lyra24p_cfg_t::cts
pin_name_t cts
Definition: lyra24p.h:326
lyra24p_cfg_t::rst
pin_name_t rst
Definition: lyra24p.h:323
lyra24p_set_bt_pin
void lyra24p_set_bt_pin(lyra24p_t *ctx, uint8_t state)
LYRA 24P set BT pin state function.
lyra24p_t::cts
digital_in_t cts
Definition: lyra24p.h:301
lyra24p_clear_to_send
uint8_t lyra24p_clear_to_send(lyra24p_t *ctx)
LYRA 24P get clear to send pin state function.
lyra24p_t
LYRA 24P Click context object.
Definition: lyra24p.h:294
lyra24p_t::bt
digital_out_t bt
Definition: lyra24p.h:297
lyra24p_request_to_send
void lyra24p_request_to_send(lyra24p_t *ctx, uint8_t state)
LYRA 24P set request to send pin state function.
lyra24p_set_device_name
err_t lyra24p_set_device_name(lyra24p_t *ctx, uint8_t *device_name)
LYRA 24P set device name function.
LYRA24P_ERROR
@ LYRA24P_ERROR
Definition: lyra24p.h:344
lyra24p_t::uart
uart_t uart
Definition: lyra24p.h:304