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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 #include "drv_analog_in.h"
39 
60 #define BLETINY_CMD_ATR "ATr"
61 #define BLETINY_CMD_ATZ "ATZ"
62 #define BLETINY_CMD_GAPDISCONNECT "AT+GAPDISCONNECT"
63 #define BLETINY_CMD_ATI "ATI"
64 #define BLETINY_CMD_ATRI "ATrI"
65 #define BLETINY_CMD_BDADDR "AT+BDADDR"
66 #define BLETINY_CMD_RSSI "AT+RSSI"
67 #define BLETINY_CMD_CHECK_MEM "AT+MEM=0"
68 #define BLETINY_CMD_CLEAR_MEM "AT+MEM=0,"
69  // bletiny_reg
71 
86 #define BLETINY_RSP_OK "OK"
87 #define BLETINY_RSP_ERROR "ERROR"
88 #define BLETINY_CONNECTED "+CONNECTED"
89 #define BLETINY_DISCONNECTED "+DISCONNECTED"
90 
95 #define BLETINY_SPI_CFG_SPEED_2MHZ 0
96 #define BLETINY_SPI_CFG_SPEED_4MHZ 1
97 #define BLETINY_SPI_CFG_SPEED_8MHZ 2
98 #define BLETINY_SPI_CFG_MODE0 0
99 #define BLETINY_SPI_CFG_MODE1 1
100 #define BLETINY_SPI_CFG_MODE2 2
101 #define BLETINY_SPI_CFG_MODE3 3
102 
107 #define BLETINY_I2C_CFG_SPEED_100KHZ 100
108 #define BLETINY_I2C_CFG_SPEED_400KHZ 400
109 #define BLETINY_I2C_CFG_REG_LEN_1BYTE 8
110 #define BLETINY_I2C_CFG_REG_LEN_1BYTES 16
111 
117 #define DRV_BUFFER_SIZE 500
118  // bletiny_set
120 
135 #define BLETINY_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
137  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
138  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
139  // bletiny_map // bletiny
142 
147 typedef struct
148 {
149  // Output pins
150  digital_out_t rst;
152  // Modules
153  uart_t uart;
155  // Buffers
156  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
157  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
159 } bletiny_t;
160 
165 typedef struct
166 {
167  // Communication gpio pins
168  pin_name_t rx_pin;
169  pin_name_t tx_pin;
171  // Additional gpio pins
172  pin_name_t rst;
174  // Static variable
175  uint32_t baud_rate;
176  bool uart_blocking;
177  uart_data_bits_t data_bit;
178  uart_parity_t parity_bit;
179  uart_stop_bits_t stop_bit;
181 } bletiny_cfg_t;
182 
187 typedef enum
188 {
194 
196 
212 void bletiny_cfg_setup ( bletiny_cfg_t *cfg );
213 
228 err_t bletiny_init ( bletiny_t *ctx, bletiny_cfg_t *cfg );
229 
243 err_t bletiny_default_cfg ( bletiny_t *ctx );
244 
258 err_t bletiny_generic_write ( bletiny_t *ctx, char *data_buf, uint16_t len );
259 
273 err_t bletiny_generic_read ( bletiny_t *ctx, char *data_buf, uint16_t max_len );
274 
284 void bletiny_send_cmd ( bletiny_t *ctx, char *cmd );
285 
296 void bletiny_spi_config ( bletiny_t *ctx, uint8_t speed, uint8_t mode );
297 
311 err_t bletiny_spi_write ( bletiny_t *ctx, char *data_buf, uint8_t len );
312 
326 err_t bletiny_spi_read ( bletiny_t *ctx, char *data_buf, uint8_t len );
327 
344 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 );
345 
356 void bletiny_i2c_config ( bletiny_t *ctx, uint8_t speed, uint8_t reg_len );
357 
372 err_t bletiny_i2c_write ( bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t reg_data );
373 
389 err_t bletiny_i2c_read ( bletiny_t *ctx, uint8_t slave_address, uint16_t reg, uint8_t *data_buf, uint8_t len );
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 #endif // BLETINY_H
395  // bletiny
397 
398 // ------------------------------------------------------------------------ END
BLETINY_ERROR_UNKNOWN
Definition: bletiny.h:192
bletiny_generic_read
err_t bletiny_generic_read(bletiny_t *ctx, char *data_buf, uint16_t max_len)
BLE TINY data reading function.
bletiny_generic_write
err_t bletiny_generic_write(bletiny_t *ctx, char *data_buf, uint16_t len)
BLE TINY data writing function.
bletiny_init
err_t bletiny_init(bletiny_t *ctx, bletiny_cfg_t *cfg)
BLE TINY initialization function.
bletiny_return_value_t
bletiny_return_value_t
BLE TINY Click return value data.
Definition: bletiny.h:186
bletiny_cfg_t
BLE TINY Click configuration object.
Definition: bletiny.h:164
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
BLE TINY driver buffer size.
Definition: bletiny.h:116
bletiny_send_cmd
void bletiny_send_cmd(bletiny_t *ctx, char *cmd)
Send command function.
bletiny_default_cfg
err_t bletiny_default_cfg(bletiny_t *ctx)
BLE TINY default configuration function.
bletiny_i2c_read
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.
bletiny_cfg_setup
void bletiny_cfg_setup(bletiny_cfg_t *cfg)
BLE TINY configuration object setup function.
BLETINY_ERROR_TIMEOUT
Definition: bletiny.h:190
bletiny_t
BLE TINY Click context object.
Definition: bletiny.h:146
bletiny_spi_read
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.
BLETINY_OK
Definition: bletiny.h:188
BLETINY_ERROR
Definition: bletiny.h:189
bletiny_i2c_config
void bletiny_i2c_config(bletiny_t *ctx, uint8_t speed, uint8_t reg_len)
Configure Click board for I2C master communication.
bletiny_spi_config
void bletiny_spi_config(bletiny_t *ctx, uint8_t speed, uint8_t mode)
Configure Click board for SPI master communication.
BLETINY_ERROR_RETURN
Definition: bletiny.h:191
bletiny_spi_write
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.
bletiny_spi_write_then_read
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.
bletiny_i2c_write
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.