bletiny 2.0.0.0
bletiny.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 BLETINY_H
29#define BLETINY_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#include "drv_analog_in.h"
53
74#define BLETINY_CMD_ATR "ATr"
75#define BLETINY_CMD_ATZ "ATZ"
76#define BLETINY_CMD_GAPDISCONNECT "AT+GAPDISCONNECT"
77#define BLETINY_CMD_ATI "ATI"
78#define BLETINY_CMD_ATRI "ATrI"
79#define BLETINY_CMD_BDADDR "AT+BDADDR"
80#define BLETINY_CMD_RSSI "AT+RSSI"
81#define BLETINY_CMD_CHECK_MEM "AT+MEM=0"
82#define BLETINY_CMD_CLEAR_MEM "AT+MEM=0,"
83
84 // bletiny_reg
85
100#define BLETINY_RSP_OK "OK"
101#define BLETINY_RSP_ERROR "ERROR"
102#define BLETINY_CONNECTED "+CONNECTED"
103#define BLETINY_DISCONNECTED "+DISCONNECTED"
104
109#define BLETINY_SPI_CFG_SPEED_2MHZ 0
110#define BLETINY_SPI_CFG_SPEED_4MHZ 1
111#define BLETINY_SPI_CFG_SPEED_8MHZ 2
112#define BLETINY_SPI_CFG_MODE0 0
113#define BLETINY_SPI_CFG_MODE1 1
114#define BLETINY_SPI_CFG_MODE2 2
115#define BLETINY_SPI_CFG_MODE3 3
116
121#define BLETINY_I2C_CFG_SPEED_100KHZ 100
122#define BLETINY_I2C_CFG_SPEED_400KHZ 400
123#define BLETINY_I2C_CFG_REG_LEN_1BYTE 8
124#define BLETINY_I2C_CFG_REG_LEN_1BYTES 16
125
131#define DRV_BUFFER_SIZE 500
132
133 // bletiny_set
134
149#define BLETINY_MAP_MIKROBUS( cfg, mikrobus ) \
150 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
151 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
152 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
153
154 // bletiny_map
155 // bletiny
156
161typedef struct
162{
163 // Output pins
164 digital_out_t rst;
166 // Modules
167 uart_t uart;
169 // Buffers
170 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
171 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
173} bletiny_t;
174
179typedef struct
180{
181 // Communication gpio pins
182 pin_name_t rx_pin;
183 pin_name_t tx_pin;
185 // Additional gpio pins
186 pin_name_t rst;
188 // Static variable
189 uint32_t baud_rate;
191 uart_data_bits_t data_bit;
192 uart_parity_t parity_bit;
193 uart_stop_bits_t stop_bit;
196
210
227
243
258
272err_t bletiny_generic_write ( bletiny_t *ctx, char *data_buf, uint16_t len );
273
287err_t bletiny_generic_read ( bletiny_t *ctx, char *data_buf, uint16_t max_len );
288
298void bletiny_send_cmd ( bletiny_t *ctx, char *cmd );
299
310void bletiny_spi_config ( bletiny_t *ctx, uint8_t speed, uint8_t mode );
311
325err_t bletiny_spi_write ( bletiny_t *ctx, char *data_buf, uint8_t len );
326
340err_t bletiny_spi_read ( bletiny_t *ctx, char *data_buf, uint8_t len );
341
358err_t bletiny_spi_write_then_read ( bletiny_t *ctx, uint8_t *data_write, uint8_t write_len, char *data_read, uint8_t read_len );
359
370void bletiny_i2c_config ( bletiny_t *ctx, uint8_t speed, uint8_t reg_len );
371
386err_t bletiny_i2c_write ( bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t reg_data );
387
403err_t bletiny_i2c_read ( bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t *data_buf, uint8_t len );
404
405#ifdef __cplusplus
406}
407#endif
408#endif // BLETINY_H
409
410 // bletiny
411
412// ------------------------------------------------------------------------ END
bletiny_return_value_t
BLE TINY Click return value data.
Definition bletiny.h:202
@ BLETINY_ERROR_TIMEOUT
Definition bletiny.h:205
@ BLETINY_ERROR
Definition bletiny.h:204
@ BLETINY_ERROR_UNKNOWN
Definition bletiny.h:207
@ BLETINY_ERROR_RETURN
Definition bletiny.h:206
@ BLETINY_OK
Definition bletiny.h:203
#define DRV_BUFFER_SIZE
BLE TINY driver buffer size.
Definition bletiny.h:131
err_t bletiny_i2c_read(bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t *data_buf, uint8_t len)
Send command to read data from slave device via I2C communication.
err_t bletiny_init(bletiny_t *ctx, bletiny_cfg_t *cfg)
BLE TINY initialization function.
err_t bletiny_spi_write_then_read(bletiny_t *ctx, uint8_t *data_write, uint8_t write_len, char *data_read, uint8_t read_len)
Send command to write data to and then read data from slave device via SPI communication.
err_t bletiny_generic_read(bletiny_t *ctx, char *data_buf, uint16_t max_len)
BLE TINY data reading function.
err_t bletiny_spi_read(bletiny_t *ctx, char *data_buf, uint8_t len)
Send command to read data from slave device via SPI communication.
err_t bletiny_default_cfg(bletiny_t *ctx)
BLE TINY default configuration function.
err_t bletiny_generic_write(bletiny_t *ctx, char *data_buf, uint16_t len)
BLE TINY data writing function.
void bletiny_spi_config(bletiny_t *ctx, uint8_t speed, uint8_t mode)
Configure Click board for SPI master communication.
err_t bletiny_i2c_write(bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t reg_data)
Send command to write data to reg address of slave device via I2C communication.
err_t bletiny_spi_write(bletiny_t *ctx, char *data_buf, uint8_t len)
Send command to write data to slave device via SPI communication.
void bletiny_send_cmd(bletiny_t *ctx, char *cmd)
Send command function.
void bletiny_cfg_setup(bletiny_cfg_t *cfg)
BLE TINY configuration object setup function.
void bletiny_i2c_config(bletiny_t *ctx, uint8_t speed, uint8_t reg_len)
Configure Click board for I2C master communication.
BLE TINY Click configuration object.
Definition bletiny.h:180
uint32_t baud_rate
Definition bletiny.h:189
bool uart_blocking
Definition bletiny.h:190
uart_data_bits_t data_bit
Definition bletiny.h:191
pin_name_t tx_pin
Definition bletiny.h:183
pin_name_t rx_pin
Definition bletiny.h:182
uart_stop_bits_t stop_bit
Definition bletiny.h:193
uart_parity_t parity_bit
Definition bletiny.h:192
pin_name_t rst
Definition bletiny.h:186
BLE TINY Click context object.
Definition bletiny.h:162
uart_t uart
Definition bletiny.h:167
digital_out_t rst
Definition bletiny.h:164