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 
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_analog_in.h"
52 #include "drv_uart.h"
53 
74 #define BLE10_CMD_AT "AT" // Attention
75 #define BLE10_CMD_ATRST "ATRST" // Software Reset
76 #define BLE10_CMD_ATFRST "ATFRST" // Factory Reset
77 #define BLE10_CMD_ATSN "ATSN" // Set Device Name
78 #define BLE10_CMD_ATP "ATP" // List Pairings
79 #define BLE10_CMD_ATCP "ATCP" // Clear Pairings
80 #define BLE10_CMD_ATDI "ATDI" // Discover Nearby Devices
81 #define BLE10_CMD_ATT "ATT" // Get temperature
82 
88 #define DRV_BUFFER_SIZE 500
89  // ble10_cmd
91 
106 #define BLE10_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
108  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
109  cfg.ain = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
111  cfg.pio3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
112  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT ); \
113  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS );
114  // ble10_map // ble10
117 
122 typedef struct
123 {
124  // Output pins
125  digital_out_t rst;
126  digital_out_t cts;
128  // Input pins
129  digital_in_t rts;
130  digital_in_t pio3;
132  // Modules
133  uart_t uart;
134  analog_in_t adc;
136  // Buffers
137  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
138  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
140 } ble10_t;
141 
146 typedef struct
147 {
148  // Communication gpio pins
149  pin_name_t rx_pin;
150  pin_name_t tx_pin;
151  pin_name_t ain;
153  // Additional gpio pins
154  pin_name_t rst;
155  pin_name_t cts;
156  pin_name_t rts;
157  pin_name_t pio3;
159  // Static variable
160  uint32_t baud_rate;
162  uart_data_bits_t data_bit;
163  uart_parity_t parity_bit;
164  uart_stop_bits_t stop_bit;
166  analog_in_resolution_t resolution;
167  float vref;
169 } ble10_cfg_t;
170 
175 typedef enum
176 {
177  BLE10_OK = 0,
178  BLE10_ERROR = -1
179 
181 
198 
213 err_t ble10_init ( ble10_t *ctx, ble10_cfg_t *cfg );
214 
226 
240 err_t ble10_generic_write ( ble10_t *ctx, char *data_buf, uint16_t len );
241 
255 err_t ble10_generic_read ( ble10_t *ctx, char *data_buf, uint16_t max_len );
256 
265 uint8_t ble10_get_rts_pin ( ble10_t *ctx );
266 
275 uint8_t ble10_get_pio3_pin ( ble10_t *ctx );
276 
286 void ble10_set_cts_pin ( ble10_t *ctx, uint8_t state );
287 
297 void ble10_set_rst_pin ( ble10_t *ctx, uint8_t state );
298 
307 void ble10_hw_reset ( ble10_t *ctx );
308 
320 err_t ble10_sw_reset ( ble10_t *ctx );
321 
334 
347 err_t ble10_send_cmd ( ble10_t *ctx, char *at_cmd_buf );
348 
362 err_t ble10_send_cmd_with_parameter ( ble10_t *ctx, char *at_cmd_buf, char *param_buf );
363 
376 err_t ble10_send_cmd_check ( ble10_t *ctx, char *at_cmd_buf );
377 
390 
403 
416 err_t ble10_set_device_name ( ble10_t *ctx, char *dev_name );
417 
430 
444 
457 err_t ble10_read_an_pin_value ( ble10_t *ctx, uint16_t *data_out );
458 
473 err_t ble10_read_an_pin_voltage ( ble10_t *ctx, float *data_out );
474 
475 #ifdef __cplusplus
476 }
477 #endif
478 #endif // BLE10_H
479  // ble10
481 
482 // ------------------------------------------------------------------------ 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:147
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:151
ble10_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble10.h:164
ble10_cfg_t::cts
pin_name_t cts
Definition: ble10.h:155
ble10_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble10.h:149
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:88
ble10_cfg_t::vref
float vref
Definition: ble10.h:167
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:129
ble10_cfg_t::uart_blocking
bool uart_blocking
Definition: ble10.h:161
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:125
BLE10_OK
@ BLE10_OK
Definition: ble10.h:177
BLE10_ERROR
@ BLE10_ERROR
Definition: ble10.h:178
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:130
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:154
ble10_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble10.h:162
ble10_t
BLE 10 Click context object.
Definition: ble10.h:123
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:133
ble10_t::adc
analog_in_t adc
Definition: ble10.h:134
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:126
ble10_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble10.h:163
ble10_return_value_t
ble10_return_value_t
BLE 10 Click return value data.
Definition: ble10.h:176
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:160
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:150
ble10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ble10.h:166
ble10_cfg_t::pio3
pin_name_t pio3
Definition: ble10.h:157
ble10_cfg_t::rts
pin_name_t rts
Definition: ble10.h:156
ble10_get_pio3_pin
uint8_t ble10_get_pio3_pin(ble10_t *ctx)
BLE 10 get PIO3 pin function.