bletx 2.0.0.0
bletx.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 BLETX_H
29#define BLETX_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_i2c_master.h"
52
53
74#define BLETX_SEL_INTERFACE_I2C 0
75#define BLETX_SEL_INTERFACE_UART 1
76
81#define BLETX_SEL_BAUD_RATE_9600 9600
82#define BLETX_SEL_BAUD_RATE_115200 115200
83
84 // bletx_sel
85
100#define BLETX_REG_SETTING_1 0x01
101#define BLETX_REG_SETTING_2 0x02
102#define BLETX_REG_SETTING_3 0x03
103#define BLETX_REG_SETTING_4 0x04
104#define BLETX_REG_SETTING_5 0x05
105#define BLETX_REG_SETTING_6 0x06
106#define BLETX_REG_PREAMBLE 0x07
107#define BLETX_REG_ACCESS_ADDRESS_0 0x08
108#define BLETX_REG_ACCESS_ADDRESS_1 0x09
109#define BLETX_REG_ACCESS_ADDRESS_2 0x0A
110#define BLETX_REG_ACCESS_ADDRESS_3 0x0B
111#define BLETX_REG_PDU_HEADER_0 0x0C
112#define BLETX_REG_PDU_HEADER_1 0x0D
113#define BLETX_REG_PDU_ADV_ADDR_0 0x0E
114#define BLETX_REG_PDU_ADV_ADDR_1 0x0F
115#define BLETX_REG_PDU_ADV_ADDR_2 0x10
116#define BLETX_REG_PDU_ADV_ADDR_3 0x11
117#define BLETX_REG_PDU_ADV_ADDR_4 0x12
118#define BLETX_REG_PDU_ADV_ADDR_5 0x13
119#define BLETX_REG_PDU_ADV_DATA_START 0x14
120#define BLETX_REG_PDU_ADV_EDDYSTONE_DATA 0x17
121#define BLETX_REG_PDU_ADV_EDDYSTONE_UID 0x2F
122#define BLETX_REG_CRC_0 0x33
123#define BLETX_REG_CRC_1 0x34
124#define BLETX_REG_CRC_2 0x35
125#define BLETX_REG_MODE 0x36
126#define BLETX_REG_SOFT_RESET 0x3F
127
128 // bletx_reg
129
144#define BLETX_AD_TYPE_FLAGS 0x01
145#define BLETX_AD_TYPE_FLAGS_CLASS_UUID_16 0x02
146#define BLETX_AD_TYPE_FLAGS_COMPLETE_UUID_16 0x03
147#define BLETX_AD_TYPE_FLAGS_SHORT_LOCAL_NAME 0x08
148#define BLETX_AD_TYPE_FLAGS_COMPLETE_LOCAL_NAME 0x09
149#define BLETX_AD_TYPE_FLAGS_TX_POWER_LEVEL 0x0A
150#define BLETX_AD_TYPE_FLAGS_CLASS_OF_DEVICE 0x0D
151#define BLETX_AD_TYPE_FLAGS_SIMPLE_PAIR_HASH_C 0x0E
152#define BLETX_AD_TYPE_FLAGS_DEVICE_ID 0x10
153#define BLETX_AD_TYPE_FLAGS_SERVICE_DATA_UUID_16 0x16
154#define BLETX_AD_TYPE_FLAGS_PUBLIC_TARGET_ADDR 0x17
155#define BLETX_AD_TYPE_FLAGS_RANDOM_TARGET_ADDR 0x18
156#define BLETX_AD_TYPE_FLAGS_APPEARANCE 0x19
157#define BLETX_AD_TYPE_FLAGS_ADVERTISING_INTERVAL 0x1A
158#define BLETX_AD_TYPE_FLAGS_BLE_DEVICE_ADDR 0x1B
159#define BLETX_AD_TYPE_FLAGS_RANDOM_LE_ROLE 0x1C
160#define BLETX_AD_TYPE_FLAGS_URI 0x24
161#define BLETX_AD_TYPE_FLAGS_INDOOR_POSITIONING 0x25
162#define BLETX_AD_TYPE_FLAGS_TRANSPORT_DISCOVERY 0x26
163#define BLETX_AD_TYPE_FLAGS_BROADCAST_CODE 0x2D
164#define BLETX_AD_TYPE_FLAGS_MANUFACTURER_SPEC_DATA 0xFF
165
170#define BLETX_SOFT_RESET_CMD 0xAA
171
176#define BLETX_PREAMBLE 0xAA
177
182#define BLETX_HEADER_PDU_TYPE_ADV_IND 0x00
183#define BLETX_HEADER_PDU_TYPE_ADV_NONCONN_IND 0x02
184#define BLETX_HEADER_PDU_TYPE_ADV_SCAN_IND 0x06
185
190#define BLETX_TX_POWER_LVL_MODE_LOWEST 0x00
191#define BLETX_TX_POWER_LVL_MODE_LOW 0x01
192#define BLETX_TX_POWER_LVL_MODE_MEDIUM 0x02
193#define BLETX_TX_POWER_LVL_MODE_HIGH 0x03
194
199#define BLETX_ADV_DELAY_ENABLE 0x80
200#define BLETX_ADV_DELAY_DISABLE 0x00
201
206#define BLETX_CRC_ENABLE 0x80
207#define BLETX_CRC_DISABLE 0x00
208
213#define BLETX_WHITE_ENABLE 0x40
214#define BLETX_WHITE_DISABLE 0x00
215
220#define BLETX_CHARACTER_CODES_DOT_COM 0x07
221#define BLETX_CHARACTER_CODES_DOT_ORG 0x08
222#define BLETX_CHARACTER_CODES_DOT_EDU 0x09
223#define BLETX_CHARACTER_CODES_DOT_NET 0x0A
224#define BLETX_CHARACTER_CODES_DOT_INFO 0x0B
225#define BLETX_CHARACTER_CODES_DOT_BIZ 0x0C
226#define BLETX_CHARACTER_CODES_DOT_GOV 0x0D
227
232#define BLETX_EDDYSTONE_SPEC_DATA_HTTP_WWW 0x00
233#define BLETX_EDDYSTONE_SPEC_DATA_HTTPS_WWW 0x01
234#define BLETX_EDDYSTONE_SPEC_DATA_HTTP 0x02
235#define BLETX_EDDYSTONE_SPEC_DATA_HTTPS 0x03
236#define BLETX_EDDYSTONE_SPEC_DATA_UDI 0x63
237#define BLETX_EDDYSTONE_SPEC_DATA_TLM 0x63
238
243#define BLETX_EDDYSTONE_SERVICE_UUID 0xAAFE
244#define BLETX_EDDYSTONE_SERVICE_DATA_TYPE_VALUE 0x16
245
250#define BLETX_EDDYSTONE_FRAME_TYPE_UID 0x00
251#define BLETX_EDDYSTONE_FRAME_TYPE_URL 0x10
252#define BLETX_EDDYSTONE_FRAME_TYPE_TLM 0x20
253#define BLETX_EDDYSTONE_FRAME_TYPE_EID 0x30
254
260#define BLETX_SET_DEV_ADDR 0x28
261
267#define BLETX_ACCESS_ADDRESS 0xD6BE898Eul
268
269 // bletx_set
270
285#define BLETX_MAP_MIKROBUS( cfg, mikrobus ) \
286 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
287 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
288 cfg.ui = MIKROBUS( mikrobus, MIKROBUS_CS ); \
289 cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
290 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
291 cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM )
292
293 // bletx_map
294 // bletx
295
300typedef struct
301{
302 // Output pins
303 digital_out_t ui;
304 digital_out_t s0;
305 digital_out_t s1;
306 digital_out_t rst;
308 // Modules
309 i2c_master_t i2c;
311 // I2C slave address
314} bletx_t;
315
320typedef struct
321{
322 pin_name_t scl;
323 pin_name_t sda;
325 pin_name_t ui;
326 pin_name_t s0;
327 pin_name_t s1;
328 pin_name_t rst;
330 uint32_t i2c_speed;
331 uint8_t i2c_address;
334
339typedef struct
340{
345 uint8_t txdata_loop;
346 uint8_t txdata_cw;
347 uint8_t eventnum;
350 uint8_t crc_enb;
351 uint8_t white_enb;
352 uint8_t pdu_len;
353 uint8_t uuid[ 6 ];
354
356
361typedef struct
362{
363 uint8_t preamble;
364 uint32_t access_address;
365 uint16_t pdu_header;
366 uint8_t adv_addr[ 6 ];
367 uint8_t adv_data[ 32 ];
368 uint32_t crc;
369
371
376typedef struct
377{
380 uint16_t eddystone_id;
382 uint8_t service_data;
384 uint8_t power;
385 uint8_t spec_data;
386 uint8_t advdata_url[ 32 ];
387 uint8_t domain;
388 uint8_t name_space_id[ 10 ];
389 uint8_t instance_id[ 6 ];
390 uint8_t tlm_version;
393 uint32_t pdu_count;
395
397
418
435
448
465
470typedef enum
471{
473 BLETX_ERROR = -1
474
476
493
507err_t bletx_init ( bletx_t *ctx, bletx_cfg_t *cfg );
508
522
535
547err_t bletx_power_up ( bletx_t *ctx );
548
560err_t bletx_hw_reset ( bletx_t *ctx );
561
574
589err_t bletx_interface_selection ( bletx_t *ctx, uint8_t sel_interface );
590
603err_t bletx_slave_address_selection ( bletx_t *ctx, uint8_t sel_slave_address ) ;
604
619err_t bletx_baud_rate_selection ( bletx_t *ctx, uint32_t sel_baud_rate );
620
635err_t bletx_generic_write ( bletx_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
636
651err_t bletx_generic_read ( bletx_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
652
665
678
692
706
720
734
747err_t bletx_set_adv_delay ( bletx_t *ctx, float adv_delay_ms );
748
762
776
790
804
818
819#ifdef __cplusplus
820}
821#endif
822#endif // BLETX_H
823
824 // bletx
825
826// ------------------------------------------------------------------------ END
bletx_txdata_value_t
BLE TX Click TX data loop.
Definition bletx.h:441
@ CONTINUOUS_TRANSMISSION
Definition bletx.h:443
@ CONTINUOUS_WAVE
Definition bletx.h:445
@ GFSK
Definition bletx.h:444
@ BURST_TRANSMISSION
Definition bletx.h:442
bletx_tx_output_power_value_t
BLE TX Click TX output power setting.
Definition bletx.h:424
@ TX_POWER_MINUS_15_dBm
Definition bletx.h:430
@ TX_POWER_MINUS_6_dBm
Definition bletx.h:427
@ TX_POWER_MINUS_3_dBm
Definition bletx.h:426
@ TX_POWER_MINUS_9_dBm
Definition bletx.h:428
@ TX_POWER_MINUS_32_dBm
Definition bletx.h:432
@ TX_POWER_0_dBm
Definition bletx.h:425
@ TX_POWER_MINUS_20_dBm
Definition bletx.h:431
@ TX_POWER_MINUS_12_dBm
Definition bletx.h:429
bletx_return_value_t
BLE TX Click return value data.
Definition bletx.h:471
@ BLETX_ERROR
Definition bletx.h:473
@ BLETX_OK
Definition bletx.h:472
bletx_eventnum_value_t
BLE TX Click advertising event setting.
Definition bletx.h:454
@ ADVERTISING_EVENT_2_TIME
Definition bletx.h:457
@ ADVERTISING_EVENT_REPEAT
Definition bletx.h:455
@ ADVERTISING_EVENT_4_TIME
Definition bletx.h:459
@ ADVERTISING_EVENT_1_TIME
Definition bletx.h:456
@ ADVERTISING_EVENT_3_TIME
Definition bletx.h:458
@ ADVERTISING_EVENT_6_TIME
Definition bletx.h:461
@ ADVERTISING_EVENT_7_TIME
Definition bletx.h:462
@ ADVERTISING_EVENT_5_TIME
Definition bletx.h:460
bletx_advch_value_t
BLE TX Click Advertising channel setting.
Definition bletx.h:403
@ ADVCH1_37_Ch_2402_MHz
Definition bletx.h:404
@ ADVCH3_37_Ch_2402_MHz
Definition bletx.h:412
@ ADVCH2_NO_TX_OUTPUT
Definition bletx.h:411
@ ADVCH2_39_Ch_2480_MHz
Definition bletx.h:410
@ ADVCH3_39_Ch_2480_MHz
Definition bletx.h:414
@ ADVCH2_38_Ch_2426_MHz
Definition bletx.h:409
@ ADVCH1_38_Ch_2426_MHz
Definition bletx.h:406
@ ADVCH3_NO_TX_OUTPUT
Definition bletx.h:415
@ ADVCH1_37_Ch_2480_MHz
Definition bletx.h:405
@ ADVCH2_37_Ch_2402_MHz
Definition bletx.h:408
@ ADVCH3_38_Ch_2426_MHz
Definition bletx.h:413
@ ADVCH1_39_Ch_2480_MHz
Definition bletx.h:407
err_t bletx_interface_selection(bletx_t *ctx, uint8_t sel_interface)
BLE TX interface selection function.
err_t bletx_set_tx_data(bletx_t *ctx, bletx_txdata_value_t txdata_data)
BLE TX TX data setting function.
err_t bletx_create_eddystone_uid(bletx_t *ctx, bletx_eddystone_data_t adv_data)
BLE TX create Eddystone™ UID data packet function.
err_t bletx_power_up(bletx_t *ctx)
BLE TX full power up function.
err_t bletx_baud_rate_selection(bletx_t *ctx, uint32_t sel_baud_rate)
BLE TX baud rate selection function.
err_t bletx_soft_reset(bletx_t *ctx)
BLE TX software reset function.
err_t bletx_slave_address_selection(bletx_t *ctx, uint8_t sel_slave_address)
BLE TX slave address selection function.
err_t bletx_set_adv_delay(bletx_t *ctx, float adv_delay_ms)
BLE TX advertising delay setting function.
void bletx_cfg_setup(bletx_cfg_t *cfg)
BLE TX configuration object setup function.
err_t bletx_power_down(bletx_t *ctx)
BLE TX full power down function.
err_t bletx_generic_read(bletx_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
BLE TX I2C reading function.
err_t bletx_default_cfg(bletx_t *ctx)
BLE TX default configuration function.
err_t bletx_stop_advertising(bletx_t *ctx)
BLE TX stop advertising function.
err_t bletx_create_eddystone_tlm(bletx_t *ctx, bletx_eddystone_data_t adv_data)
BLE TX create Eddystone™ TLM data packet function.
err_t bletx_set_output_power(bletx_t *ctx, bletx_tx_output_power_value_t power_data)
BLE TX output power setting function.
err_t bletx_set_configuration(bletx_t *ctx, bletx_adv_cfg_t adv_cfg)
BLE TX configuration setting function.
err_t bletx_hw_reset(bletx_t *ctx)
BLE TX hardware reset function.
err_t bletx_create_adv_data_packet(bletx_t *ctx, bletx_create_adv_data_packet_t adv_data_packet)
BLE TX create advertising data packet function.
err_t bletx_generic_write(bletx_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
BLE TX I2C writing function.
err_t bletx_create_eddystone_uri(bletx_t *ctx, bletx_eddystone_data_t adv_data)
BLE TX create Eddystone™ URI data packet function.
err_t bletx_init(bletx_t *ctx, bletx_cfg_t *cfg)
BLE TX initialization function.
err_t bletx_set_eventnum(bletx_t *ctx, bletx_eventnum_value_t eventnum_data)
BLE TX eventnum setting function.
err_t bletx_set_cfg_adv_channel(bletx_t *ctx, bletx_advch_value_t advch_data)
BLE TX advertising channel setting function.
err_t bletx_start_advertising(bletx_t *ctx)
BLE TX start advertising function.
bletx_adv_cfg_t adv_cfg
Definition main.c:53
bletx_eddystone_data_t adv_data
Definition main.c:54
BLE TX Click advertising settings object.
Definition bletx.h:340
uint8_t pdu_len
Definition bletx.h:352
uint16_t avdintvl_interval_ms
Definition bletx.h:349
uint8_t adv_ch_3_frequency
Definition bletx.h:343
uint8_t txdata_cw
Definition bletx.h:346
uint8_t tx_output_power
Definition bletx.h:344
uint8_t adv_ch_2_frequency
Definition bletx.h:342
uint8_t adv_ch_1_frequency
Definition bletx.h:341
uint8_t eventnum
Definition bletx.h:347
uint8_t crc_enb
Definition bletx.h:350
uint8_t advdelay_enb
Definition bletx.h:348
uint8_t white_enb
Definition bletx.h:351
uint8_t txdata_loop
Definition bletx.h:345
BLE TX Click configuration object.
Definition bletx.h:321
pin_name_t s0
Definition bletx.h:326
uint32_t i2c_speed
Definition bletx.h:330
pin_name_t s1
Definition bletx.h:327
pin_name_t ui
Definition bletx.h:325
pin_name_t scl
Definition bletx.h:322
pin_name_t sda
Definition bletx.h:323
pin_name_t rst
Definition bletx.h:328
uint8_t i2c_address
Definition bletx.h:331
BLE TX Click advertising data packet.
Definition bletx.h:362
uint16_t pdu_header
Definition bletx.h:365
uint8_t preamble
Definition bletx.h:363
uint32_t crc
Definition bletx.h:368
uint32_t access_address
Definition bletx.h:364
BLE TX Click Eddystone™ data packet.
Definition bletx.h:377
uint8_t frame_type_url
Definition bletx.h:383
uint32_t pdu_count
Definition bletx.h:393
uint8_t domain
Definition bletx.h:387
uint16_t battery_voltage
Definition bletx.h:391
uint8_t length_of_service_data
Definition bletx.h:381
uint16_t eddystone_id
Definition bletx.h:380
uint8_t tlm_version
Definition bletx.h:390
uint8_t param_service_list
Definition bletx.h:379
uint8_t spec_data
Definition bletx.h:385
uint8_t service_data
Definition bletx.h:382
float beacon_temperature
Definition bletx.h:392
uint8_t power
Definition bletx.h:384
uint8_t length_of_service_list
Definition bletx.h:378
uint32_t time_since_reboot
Definition bletx.h:394
BLE TX Click context object.
Definition bletx.h:301
i2c_master_t i2c
Definition bletx.h:309
digital_out_t rst
Definition bletx.h:306
uint8_t slave_address
Definition bletx.h:312
digital_out_t s1
Definition bletx.h:305
digital_out_t ui
Definition bletx.h:303
digital_out_t s0
Definition bletx.h:304