nanobeacon 2.1.0.0
nanobeacon.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 NANOBEACON_H
29#define NANOBEACON_H
30
31#ifdef __cplusplus
32extern "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 NANOBEACON_OPCODE_READY 0x01
74#define NANOBEACON_OPCODE_READY_ACK 0x80
75#define NANOBEACON_OPCODE_READY_NACK 0x81
76#define NANOBEACON_OPCODE_RATE 0x02
77#define NANOBEACON_OPCODE_READ_REG 0x03
78#define NANOBEACON_OPCODE_READ_REG_RESP 0x83
79#define NANOBEACON_OPCODE_WRITE_REG 0x04
80#define NANOBEACON_OPCODE_WRITE_REG_RESP 0x84
81#define NANOBEACON_OPCODE_READ_MEM 0x05
82#define NANOBEACON_OPCODE_READ_MEM_RESP 0x85
83#define NANOBEACON_OPCODE_WRITE_MEM 0x06
84#define NANOBEACON_OPCODE_WRITE_MEM_RESP 0x86
85#define NANOBEACON_OPCODE_READ_EFUSE 0x07
86#define NANOBEACON_OPCODE_READ_EFUSE_RESP 0x87
87#define NANOBEACON_OPCODE_WRITE_EFUSE 0x08
88#define NANOBEACON_OPCODE_WRITE_EFUSE_RESP 0x88
89
94#define NANOBEACON_PACKET_HEADER 0xAE
95#define NANOBEACON_PACKET_TAIL 0xEA
96#define NANOBEACON_PAYLOAD_READY 0xAA
97#define NANOBEACON_PACKET_PAYLOAD_SIZE 128
98#define NANOBEACON_TIMEOUT_MS 3000
99#define NANOBEACON_CHECK_COMM_NUM_TRIES 5
100
106#define NANOBEACON_TX_DRV_BUFFER_SIZE ( NANOBEACON_PACKET_PAYLOAD_SIZE + 4 )
107#define NANOBEACON_RX_DRV_BUFFER_SIZE ( NANOBEACON_PACKET_PAYLOAD_SIZE + 4 )
108
109 // nanobeacon_cmd
110
125#define NANOBEACON_MAP_MIKROBUS( cfg, mikrobus ) \
126 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
127 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
128 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
129 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
130 cfg.dq = MIKROBUS( mikrobus, MIKROBUS_PWM );
131
132 // nanobeacon_map
133 // nanobeacon
134
139typedef struct
140{
141 uint8_t opcode;
142 uint8_t payload_len;
146
151typedef struct
152{
153 // Output pins
154 digital_out_t en;
155 digital_out_t dq;
157 // Input pins
158 digital_in_t an;
160 // Modules
161 uart_t uart;
163 // Buffers
164 uint8_t uart_rx_buffer[ NANOBEACON_RX_DRV_BUFFER_SIZE ];
165 uint8_t uart_tx_buffer[ NANOBEACON_TX_DRV_BUFFER_SIZE ];
168
173typedef struct
174{
175 // Communication gpio pins
176 pin_name_t rx_pin;
177 pin_name_t tx_pin;
179 // Additional gpio pins
180 pin_name_t an;
181 pin_name_t en;
182 pin_name_t dq;
184 // Static variable
185 uint32_t baud_rate;
187 uart_data_bits_t data_bit;
188 uart_parity_t parity_bit;
189 uart_stop_bits_t stop_bit;
192
203
220
235
248err_t nanobeacon_generic_write ( nanobeacon_t *ctx, uint8_t *data_in, uint16_t len );
249
262err_t nanobeacon_generic_read ( nanobeacon_t *ctx, uint8_t *data_out, uint16_t len );
263
273
283void nanobeacon_set_en_pin ( nanobeacon_t *ctx, uint8_t state );
284
294void nanobeacon_set_dq_pin ( nanobeacon_t *ctx, uint8_t state );
295
305
319
333
345
358err_t nanobeacon_write_reg ( nanobeacon_t *ctx, uint16_t address, uint32_t data_in );
359
372err_t nanobeacon_read_reg ( nanobeacon_t *ctx, uint16_t address, uint32_t *data_out );
373
386err_t nanobeacon_write_mem ( nanobeacon_t *ctx, uint16_t address, uint32_t data_in );
387
400err_t nanobeacon_read_mem ( nanobeacon_t *ctx, uint16_t address, uint32_t *data_out );
401
414err_t nanobeacon_write_efuse ( nanobeacon_t *ctx, uint8_t aid, uint16_t data_in );
415
428err_t nanobeacon_read_efuse ( nanobeacon_t *ctx, uint8_t aid, uint16_t *data_out );
429
442err_t nanobeacon_set_advertising ( uint8_t *mac_address, uint16_t interval, uint8_t *adv_raw_data, uint8_t len );
443
455
467
468#ifdef __cplusplus
469}
470#endif
471#endif // NANOBEACON_H
472
473 // nanobeacon
474
475// ------------------------------------------------------------------------ END
#define NANOBEACON_PACKET_PAYLOAD_SIZE
Definition nanobeacon.h:97
#define NANOBEACON_RX_DRV_BUFFER_SIZE
Definition nanobeacon.h:107
#define NANOBEACON_TX_DRV_BUFFER_SIZE
NanoBeacon driver buffer size.
Definition nanobeacon.h:106
uint8_t nanobeacon_get_an_pin(nanobeacon_t *ctx)
NanoBeacon get an pin function.
err_t nanobeacon_read_efuse(nanobeacon_t *ctx, uint8_t aid, uint16_t *data_out)
NanoBeacon read efuse function.
err_t nanobeacon_set_advertising(uint8_t *mac_address, uint16_t interval, uint8_t *adv_raw_data, uint8_t len)
NanoBeacon set advertising function.
err_t nanobeacon_write_efuse(nanobeacon_t *ctx, uint8_t aid, uint16_t data_in)
NanoBeacon write efuse function.
err_t nanobeacon_read_packet(nanobeacon_t *ctx, nanobeacon_packet_t *pkt_out)
NanoBeacon read packet function.
err_t nanobeacon_send_packet(nanobeacon_t *ctx, nanobeacon_packet_t pkt_in)
NanoBeacon send packet function.
err_t nanobeacon_start_advertising(nanobeacon_t *ctx)
NanoBeacon start advertising function.
err_t nanobeacon_generic_read(nanobeacon_t *ctx, uint8_t *data_out, uint16_t len)
NanoBeacon data reading function.
err_t nanobeacon_init(nanobeacon_t *ctx, nanobeacon_cfg_t *cfg)
NanoBeacon initialization function.
err_t nanobeacon_read_reg(nanobeacon_t *ctx, uint16_t address, uint32_t *data_out)
NanoBeacon read reg function.
void nanobeacon_set_en_pin(nanobeacon_t *ctx, uint8_t state)
NanoBeacon set EN pin function.
void nanobeacon_cfg_setup(nanobeacon_cfg_t *cfg)
NanoBeacon configuration object setup function.
void nanobeacon_restart_device(nanobeacon_t *ctx)
NanoBeacon restart device function.
err_t nanobeacon_generic_write(nanobeacon_t *ctx, uint8_t *data_in, uint16_t len)
NanoBeacon data writing function.
err_t nanobeacon_load_adv_to_ram(nanobeacon_t *ctx)
NanoBeacon load adv to ram function.
void nanobeacon_set_dq_pin(nanobeacon_t *ctx, uint8_t state)
NanoBeacon set DQ pin function.
err_t nanobeacon_write_mem(nanobeacon_t *ctx, uint16_t address, uint32_t data_in)
NanoBeacon write mem function.
err_t nanobeacon_write_reg(nanobeacon_t *ctx, uint16_t address, uint32_t data_in)
NanoBeacon write reg function.
err_t nanobeacon_read_mem(nanobeacon_t *ctx, uint16_t address, uint32_t *data_out)
NanoBeacon read mem function.
err_t nanobeacon_check_communication(nanobeacon_t *ctx)
NanoBeacon check communication function.
nanobeacon_return_value_t
NanoBeacon Click return value data.
Definition nanobeacon.h:198
@ NANOBEACON_OK
Definition nanobeacon.h:199
@ NANOBEACON_ERROR
Definition nanobeacon.h:200
NanoBeacon Click configuration object.
Definition nanobeacon.h:174
uint32_t baud_rate
Definition nanobeacon.h:185
bool uart_blocking
Definition nanobeacon.h:186
uart_data_bits_t data_bit
Definition nanobeacon.h:187
pin_name_t tx_pin
Definition nanobeacon.h:177
pin_name_t rx_pin
Definition nanobeacon.h:176
uart_stop_bits_t stop_bit
Definition nanobeacon.h:189
pin_name_t en
Definition nanobeacon.h:181
uart_parity_t parity_bit
Definition nanobeacon.h:188
pin_name_t dq
Definition nanobeacon.h:182
pin_name_t an
Definition nanobeacon.h:180
NanoBeacon Click packet object.
Definition nanobeacon.h:140
uint8_t opcode
Definition nanobeacon.h:141
uint8_t payload_len
Definition nanobeacon.h:142
NanoBeacon Click context object.
Definition nanobeacon.h:152
uart_t uart
Definition nanobeacon.h:161
digital_out_t dq
Definition nanobeacon.h:155
digital_in_t an
Definition nanobeacon.h:158
digital_out_t en
Definition nanobeacon.h:154