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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_analog_in.h"
48 #include "drv_uart.h"
49 
70 #define BLE10_CMD_AT "AT" // Attention
71 #define BLE10_CMD_ATRST "ATRST" // Software Reset
72 #define BLE10_CMD_ATFRST "ATFRST" // Factory Reset
73 #define BLE10_CMD_ATSN "ATSN" // Set Device Name
74 #define BLE10_CMD_ATP "ATP" // List Pairings
75 #define BLE10_CMD_ATCP "ATCP" // Clear Pairings
76 #define BLE10_CMD_ATDI "ATDI" // Discover Nearby Devices
77 #define BLE10_CMD_ATT "ATT" // Get temperature
78 
84 #define DRV_BUFFER_SIZE 500
85  // ble10_cmd
87 
102 #define BLE10_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
104  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
105  cfg.ain = MIKROBUS( mikrobus, MIKROBUS_AN ); \
106  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
107  cfg.pio3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
108  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT ); \
109  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS );
110  // ble10_map // ble10
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t rst;
122  digital_out_t cts;
124  // Input pins
125  digital_in_t rts;
126  digital_in_t pio3;
128  // Modules
129  uart_t uart;
130  analog_in_t adc;
132  // Buffers
133  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
134  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
136 } ble10_t;
137 
142 typedef struct
143 {
144  // Communication gpio pins
145  pin_name_t rx_pin;
146  pin_name_t tx_pin;
147  pin_name_t ain;
149  // Additional gpio pins
150  pin_name_t rst;
151  pin_name_t cts;
152  pin_name_t rts;
153  pin_name_t pio3;
155  // Static variable
156  uint32_t baud_rate;
158  uart_data_bits_t data_bit;
159  uart_parity_t parity_bit;
160  uart_stop_bits_t stop_bit;
162  analog_in_resolution_t resolution;
163  float vref;
165 } ble10_cfg_t;
166 
171 typedef enum
172 {
173  BLE10_OK = 0,
174  BLE10_ERROR = -1
175 
177 
194 
209 err_t ble10_init ( ble10_t *ctx, ble10_cfg_t *cfg );
210 
222 
236 err_t ble10_generic_write ( ble10_t *ctx, char *data_buf, uint16_t len );
237 
251 err_t ble10_generic_read ( ble10_t *ctx, char *data_buf, uint16_t max_len );
252 
261 uint8_t ble10_get_rts_pin ( ble10_t *ctx );
262 
271 uint8_t ble10_get_pio3_pin ( ble10_t *ctx );
272 
282 void ble10_set_cts_pin ( ble10_t *ctx, uint8_t state );
283 
293 void ble10_set_rst_pin ( ble10_t *ctx, uint8_t state );
294 
303 void ble10_hw_reset ( ble10_t *ctx );
304 
316 err_t ble10_sw_reset ( ble10_t *ctx );
317 
330 
343 err_t ble10_send_cmd ( ble10_t *ctx, char *at_cmd_buf );
344 
358 err_t ble10_send_cmd_with_parameter ( ble10_t *ctx, char *at_cmd_buf, char *param_buf );
359 
372 err_t ble10_send_cmd_check ( ble10_t *ctx, char *at_cmd_buf );
373 
386 
399 
412 err_t ble10_set_device_name ( ble10_t *ctx, char *dev_name );
413 
426 
440 
453 err_t ble10_read_an_pin_value ( ble10_t *ctx, uint16_t *data_out );
454 
469 err_t ble10_read_an_pin_voltage ( ble10_t *ctx, float *data_out );
470 
471 #ifdef __cplusplus
472 }
473 #endif
474 #endif // BLE10_H
475  // ble10
477 
478 // ------------------------------------------------------------------------ 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:143
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:147
ble10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble10.h:160
ble10_cfg_t::cts
pin_name_t cts
Definition: ble10.h:151
ble10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble10.h:145
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:84
ble10_cfg_t::vref
float vref
Definition: ble10.h:163
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:125
ble10_cfg_t::uart_blocking
bool uart_blocking
Definition: ble10.h:157
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:121
BLE10_OK
@ BLE10_OK
Definition: ble10.h:173
BLE10_ERROR
@ BLE10_ERROR
Definition: ble10.h:174
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:126
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:150
ble10_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble10.h:158
ble10_t
BLE 10 Click context object.
Definition: ble10.h:119
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:129
ble10_t::adc
analog_in_t adc
Definition: ble10.h:130
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:122
ble10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble10.h:159
ble10_return_value_t
ble10_return_value_t
BLE 10 Click return value data.
Definition: ble10.h:172
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:156
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:146
ble10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ble10.h:162
ble10_cfg_t::pio3
pin_name_t pio3
Definition: ble10.h:153
ble10_cfg_t::rts
pin_name_t rts
Definition: ble10.h:152
ble10_get_pio3_pin
uint8_t ble10_get_pio3_pin(ble10_t *ctx)
BLE 10 get PIO3 pin function.