ble10  2.0.0.0
ble10.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 BLE10_H
29 #define BLE10_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_analog_in.h"
38 #include "drv_uart.h"
39 
60 #define BLE10_CMD_AT "AT" // Attention
61 #define BLE10_CMD_ATRST "ATRST" // Software Reset
62 #define BLE10_CMD_ATFRST "ATFRST" // Factory Reset
63 #define BLE10_CMD_ATSN "ATSN" // Set Device Name
64 #define BLE10_CMD_ATP "ATP" // List Pairings
65 #define BLE10_CMD_ATCP "ATCP" // Clear Pairings
66 #define BLE10_CMD_ATDI "ATDI" // Discover Nearby Devices
67 #define BLE10_CMD_ATT "ATT" // Get temperature
68 
74 #define DRV_BUFFER_SIZE 500
75  // ble10_cmd
77 
92 #define BLE10_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95  cfg.ain = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
97  cfg.pio3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT ); \
99  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS );
100  // ble10_map // ble10
103 
108 typedef struct
109 {
110  // Output pins
111  digital_out_t rst;
112  digital_out_t cts;
114  // Input pins
115  digital_in_t rts;
116  digital_in_t pio3;
118  // Modules
119  uart_t uart;
120  analog_in_t adc;
122  // Buffers
123  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
124  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
126 } ble10_t;
127 
132 typedef struct
133 {
134  // Communication gpio pins
135  pin_name_t rx_pin;
136  pin_name_t tx_pin;
137  pin_name_t ain;
139  // Additional gpio pins
140  pin_name_t rst;
141  pin_name_t cts;
142  pin_name_t rts;
143  pin_name_t pio3;
145  // Static variable
146  uint32_t baud_rate;
148  uart_data_bits_t data_bit;
149  uart_parity_t parity_bit;
150  uart_stop_bits_t stop_bit;
152  analog_in_resolution_t resolution;
153  float vref;
155 } ble10_cfg_t;
156 
161 typedef enum
162 {
163  BLE10_OK = 0,
164  BLE10_ERROR = -1
165 
167 
184 
199 err_t ble10_init ( ble10_t *ctx, ble10_cfg_t *cfg );
200 
212 
226 err_t ble10_generic_write ( ble10_t *ctx, char *data_buf, uint16_t len );
227 
241 err_t ble10_generic_read ( ble10_t *ctx, char *data_buf, uint16_t max_len );
242 
251 uint8_t ble10_get_rts_pin ( ble10_t *ctx );
252 
261 uint8_t ble10_get_pio3_pin ( ble10_t *ctx );
262 
272 void ble10_set_cts_pin ( ble10_t *ctx, uint8_t state );
273 
283 void ble10_set_rst_pin ( ble10_t *ctx, uint8_t state );
284 
293 void ble10_hw_reset ( ble10_t *ctx );
294 
306 err_t ble10_sw_reset ( ble10_t *ctx );
307 
320 
333 err_t ble10_send_cmd ( ble10_t *ctx, char *at_cmd_buf );
334 
348 err_t ble10_send_cmd_with_parameter ( ble10_t *ctx, char *at_cmd_buf, char *param_buf );
349 
362 err_t ble10_send_cmd_check ( ble10_t *ctx, char *at_cmd_buf );
363 
376 
389 
402 err_t ble10_set_device_name ( ble10_t *ctx, char *dev_name );
403 
416 
430 
443 err_t ble10_read_an_pin_value ( ble10_t *ctx, uint16_t *data_out );
444 
459 err_t ble10_read_an_pin_voltage ( ble10_t *ctx, float *data_out );
460 
461 #ifdef __cplusplus
462 }
463 #endif
464 #endif // BLE10_H
465  // ble10
467 
468 // ------------------------------------------------------------------------ END
ble10_hw_reset
void ble10_hw_reset(ble10_t *ctx)
BLE 10 hw reset function.
ble10_cfg_t
BLE 10 Click configuration object.
Definition: ble10.h:133
ble10_init
err_t ble10_init(ble10_t *ctx, ble10_cfg_t *cfg)
BLE 10 initialization function.
ble10_default_cfg
void ble10_default_cfg(ble10_t *ctx)
BLE 10 default configuration function.
ble10_cfg_t::ain
pin_name_t ain
Definition: ble10.h:137
ble10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble10.h:150
ble10_cfg_t::cts
pin_name_t cts
Definition: ble10.h:141
ble10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble10.h:135
ble10_sw_reset
err_t ble10_sw_reset(ble10_t *ctx)
BLE 10 software reset function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
BLE 10 driver buffer size.
Definition: ble10.h:74
ble10_cfg_t::vref
float vref
Definition: ble10.h:153
ble10_set_device_name
err_t ble10_set_device_name(ble10_t *ctx, char *dev_name)
BLE 10 set local device name function.
ble10_get_rts_pin
uint8_t ble10_get_rts_pin(ble10_t *ctx)
BLE 10 get ready to send pin function.
ble10_factory_reset
err_t ble10_factory_reset(ble10_t *ctx)
BLE 10 factory reset function.
ble10_read_an_pin_value
err_t ble10_read_an_pin_value(ble10_t *ctx, uint16_t *data_out)
BLE 10 read AIN pin value function.
ble10_t::rts
digital_in_t rts
Definition: ble10.h:115
ble10_cfg_t::uart_blocking
bool uart_blocking
Definition: ble10.h:147
ble10_list_pairings
err_t ble10_list_pairings(ble10_t *ctx)
BLE 10 list current pairings function.
ble10_t::rst
digital_out_t rst
Definition: ble10.h:111
BLE10_OK
@ BLE10_OK
Definition: ble10.h:163
BLE10_ERROR
@ BLE10_ERROR
Definition: ble10.h:164
ble10_remove_pairings
err_t ble10_remove_pairings(ble10_t *ctx)
BLE 10 remove pairings function.
ble10_send_cmd_with_parameter
err_t ble10_send_cmd_with_parameter(ble10_t *ctx, char *at_cmd_buf, char *param_buf)
BLE 10 send command with parameter function.
ble10_cfg_setup
void ble10_cfg_setup(ble10_cfg_t *cfg)
BLE 10 configuration object setup function.
ble10_t::pio3
digital_in_t pio3
Definition: ble10.h:116
ble10_send_cmd_check
err_t ble10_send_cmd_check(ble10_t *ctx, char *at_cmd_buf)
BLE 10 send command check function.
ble10_cfg_t::rst
pin_name_t rst
Definition: ble10.h:140
ble10_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble10.h:148
ble10_t
BLE 10 Click context object.
Definition: ble10.h:109
ble10_discover_nearby_devices
err_t ble10_discover_nearby_devices(ble10_t *ctx)
BLE 10 discover nearby devices function.
ble10_read_an_pin_voltage
err_t ble10_read_an_pin_voltage(ble10_t *ctx, float *data_out)
BLE 10 read AIN pin voltage level function.
ble10_t::uart
uart_t uart
Definition: ble10.h:119
ble10_t::adc
analog_in_t adc
Definition: ble10.h:120
ble10_send_cmd
err_t ble10_send_cmd(ble10_t *ctx, char *at_cmd_buf)
BLE 10 send command function.
ble10_t::cts
digital_out_t cts
Definition: ble10.h:112
ble10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble10.h:149
ble10_return_value_t
ble10_return_value_t
BLE 10 Click return value data.
Definition: ble10.h:162
ble10_set_rst_pin
void ble10_set_rst_pin(ble10_t *ctx, uint8_t state)
BLE 10 set reset pin function.
ble10_set_cts_pin
void ble10_set_cts_pin(ble10_t *ctx, uint8_t state)
BLE 10 set clear to send pin function.
ble10_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble10.h:146
ble10_generic_read
err_t ble10_generic_read(ble10_t *ctx, char *data_buf, uint16_t max_len)
BLE 10 data reading function.
ble10_get_temperature
err_t ble10_get_temperature(ble10_t *ctx)
BLE 10 get temperature function.
ble10_generic_write
err_t ble10_generic_write(ble10_t *ctx, char *data_buf, uint16_t len)
BLE 10 data writing function.
ble10_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble10.h:136
ble10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ble10.h:152
ble10_cfg_t::pio3
pin_name_t pio3
Definition: ble10.h:143
ble10_cfg_t::rts
pin_name_t rts
Definition: ble10.h:142
ble10_get_pio3_pin
uint8_t ble10_get_pio3_pin(ble10_t *ctx)
BLE 10 get PIO3 pin function.