ble8  2.0.0.0
ble8.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef BLE8_H
36 #define BLE8_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define BLE8_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.dsr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define BLE8_RETVAL uint8_t
77 
78 #define BLE8_OK 0x00
79 #define BLE8_INIT_ERROR 0xFF
80 
86 #define BLE8_END_BUFF 0
87 
93 #define BLE8_RSP_READY 1
94 #define BLE8_RSP_NOT_READY 0
95 
101 #define BLE8_ECHO_ON 1
102 #define BLE8_ECHO_OFF 0
103 
109 #define BLE8_COMMAND_MODE 0
110 #define BLE8_DATA_MODE 1
111 #define BLE8_EXT_DATA_MODE 2
112 #define BLE8_PPP_MODE 3
113 
119 #define BLE8_DISABLED_ROLE 0
120 #define BLE8_CENTRAL_ROLE 1
121 #define BLE8_PERIPHERAL_ROLE 2
122 #define BLE8_SIMULTANEOUS_ROLE 3
123 
129 #define BLE8_SEC_DISABLED 1
130 #define BLE8_SEC_JUST_WORKS 2
131 #define BLE8_SEC_DISPLAY_ONLY 3
132 #define BLE8_SEC_DISPLAY_YES_NO 4
133 #define BLE8_SEC_KEYBOARD_ONLY 5
134 #define BLE8_SEC_OUT_OF_BAND 6
135 
141 #define BLE8_GAP_NON_PAIRING_MODE 1
142 #define BLE8_GAP_PAIRING_MODE 2
143 
149 #define BLE8_GAP_NON_CONNECTABLE_MODE 1
150 #define BLE8_GAP_CONNECTABLE_MODE 2
151 
157 #define BLE8_GAP_NON_DISCOVERABLE_MODE 1
158 #define BLE8_GAP_LIMITED_DISCOVERABLE_MODE 2
159 #define BLE8_GAP_GENERAL_DISCOVERABLE_MODE 3
160 
166 #define DRV_RX_BUFFER_SIZE 100
167 #define DRV_TX_BUFFER_SIZE 100
168  // End group macro
171 // --------------------------------------------------------------- PUBLIC TYPES
180 typedef struct
181 {
182  // Output pins
183 
184  digital_out_t rst;
185  digital_out_t cts;
186  digital_out_t dsr;
187 
188  // Input pins
189 
190  digital_in_t dtr;
191  digital_in_t rts;
192 
193  // Modules
194 
195  uart_t uart;
196 
197  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
198  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
199 
200  uint8_t rsp_rdy;
202 
203 } ble8_t;
204 
208 typedef struct
209 {
210  // Communication gpio pins
211 
212  pin_name_t rx_pin;
213  pin_name_t tx_pin;
214 
215  // Additional gpio pins
216 
217  pin_name_t dtr;
218  pin_name_t rst;
219  pin_name_t cts;
220  pin_name_t dsr;
221  pin_name_t rts;
222 
223  // static variable
224 
225  uint32_t baud_rate; // Clock speed.
227  uart_data_bits_t data_bit; // Data bits.
228  uart_parity_t parity_bit; // Parity bit.
229  uart_stop_bits_t stop_bit; // Stop bits.
230 
231 } ble8_cfg_t;
232  // End types group
234 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235 
241 #ifdef __cplusplus
242 extern "C"{
243 #endif
244 
254 
264 
272 void ble8_reset ( ble8_t *ctx );
273 
280 void ble8_generic_write ( ble8_t *ctx, char *data_buf, uint16_t len );
281 
289 int32_t ble8_generic_read ( ble8_t *ctx, char *data_buf, uint16_t max_len );
290 
300 uint8_t ble8_response_ready( ble8_t *ctx );
301 
314 void ble8_send_command ( ble8_t *ctx, char * command, uint8_t term_char );
315 
325 void ble8_fact_rst_cmd ( ble8_t *ctx );
326 
337 
344 
356 void ble8_set_start_mode_cmd ( ble8_t *ctx, uint8_t start_mode );
357 
366 
380 void ble8_enter_mode_cmd ( ble8_t *ctx, uint8_t mode );
381 
391 void ble8_set_echo_cmd ( ble8_t *ctx, uint8_t echo_en );
392 
400 void ble8_get_echo_cmd ( ble8_t *ctx );
401 
414 void ble8_set_local_name_cmd ( ble8_t *ctx, char *local_name );
415 
424 
441 void ble8_set_low_energy_role_cmd ( ble8_t *ctx, uint8_t le_role );
442 
451 
463 
479 
491 
514 void ble8_set_sec_mode_cmd ( ble8_t *ctx, uint8_t sec_mode );
515 
524 
533 void ble8_pairing_en_cmd ( ble8_t *ctx, uint8_t pairing_mode );
534 
543 
552 void ble8_connectability_en_cmd ( ble8_t *ctx, uint8_t conn_mode );
553 
562 
578 void ble8_discoverability_en_cmd ( ble8_t *ctx, uint8_t discover_mode );
579 
588 
596 void ble8_get_info ( ble8_t *ctx );
597 
610 uint8_t ble8_sps_central_pairing ( ble8_t *ctx, uint8_t *local_addr );
611 
623 
636 void ble8_set_cts_pin ( ble8_t *ctx, uint8_t state );
637 
649 void ble8_set_dsr_pin ( ble8_t *ctx, uint8_t state );
650 
663 uint8_t ble8_get_dtr_pin ( ble8_t *ctx );
664 
676 uint8_t ble8_get_rts_pin ( ble8_t *ctx );
677 
678 
679 #ifdef __cplusplus
680 }
681 #endif
682 #endif // _BLE8_H_
683  // End public_function group
686 
687 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: ble8.h:166
ble8_set_low_energy_role_cmd
void ble8_set_low_energy_role_cmd(ble8_t *ctx, uint8_t le_role)
Bluetooth Low Energy Role Setting command.
ble8_get_sec_mode_cmd
void ble8_get_sec_mode_cmd(ble8_t *ctx)
Get Security Mode command.
ble8_check_connectability_cmd
void ble8_check_connectability_cmd(ble8_t *ctx)
Get Connectability Mode command.
ble8_check_pairing_cmd
void ble8_check_pairing_cmd(ble8_t *ctx)
Get Pairing Mode command.
ble8_cfg_t::cts
pin_name_t cts
Definition: ble8.h:219
ble8_discoverability_en_cmd
void ble8_discoverability_en_cmd(ble8_t *ctx, uint8_t discover_mode)
Discoverability Mode Setting command.
ble8_set_echo_cmd
void ble8_set_echo_cmd(ble8_t *ctx, uint8_t echo_en)
Echo On/Off command.
ble8_t::termination_char
uint8_t termination_char
Definition: ble8.h:201
ble8_get_info
void ble8_get_info(ble8_t *ctx)
Get Info command.
ble8_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble8.h:213
ble8_init
BLE8_RETVAL ble8_init(ble8_t *ctx, ble8_cfg_t *cfg)
Initialization function.
ble8_store_cnfg_cmd
void ble8_store_cnfg_cmd(ble8_t *ctx)
Store Current Configuration command.
ble8_cfg_t::dsr
pin_name_t dsr
Definition: ble8.h:220
ble8_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble8.h:212
ble8_get_local_addr_cmd
void ble8_get_local_addr_cmd(ble8_t *ctx)
Get Local Address command.
ble8_fact_rst_cmd
void ble8_fact_rst_cmd(ble8_t *ctx)
Factory Reset command.
ble8_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble8.h:228
ble8_set_sec_mode_cmd
void ble8_set_sec_mode_cmd(ble8_t *ctx, uint8_t sec_mode)
Security Mode Setting command.
ble8_t::rsp_rdy
uint8_t rsp_rdy
Definition: ble8.h:200
ble8_generic_write
void ble8_generic_write(ble8_t *ctx, char *data_buf, uint16_t len)
Generic write function.
ble8_set_cts_pin
void ble8_set_cts_pin(ble8_t *ctx, uint8_t state)
CTS Pin Setting function.
ble8_cfg_t
Click configuration structure definition.
Definition: ble8.h:209
BLE8_RETVAL
#define BLE8_RETVAL
Definition: ble8.h:76
ble8_cfg_t::dtr
pin_name_t dtr
Definition: ble8.h:217
ble8_t::cts
digital_out_t cts
Definition: ble8.h:185
ble8_cfg_t::rst
pin_name_t rst
Definition: ble8.h:218
ble8_enter_mode_cmd
void ble8_enter_mode_cmd(ble8_t *ctx, uint8_t mode)
Enter Data Mode command.
ble8_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble8.h:225
ble8_t
Click ctx object definition.
Definition: ble8.h:181
ble8_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble8.h:227
ble8_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble8.h:229
ble8_set_start_mode_cmd
void ble8_set_start_mode_cmd(ble8_t *ctx, uint8_t start_mode)
Module Start Mode Setting command.
ble8_get_low_energy_role_cmd
void ble8_get_low_energy_role_cmd(ble8_t *ctx)
Get Bluetooth Low Energy Role command.
ble8_set_default_cmd
void ble8_set_default_cmd(ble8_t *ctx)
Default Configuration command.
ble8_pairing_en_cmd
void ble8_pairing_en_cmd(ble8_t *ctx, uint8_t pairing_mode)
Pairing Mode Setting command.
ble8_sps_peripheral_pairing
void ble8_sps_peripheral_pairing(ble8_t *ctx)
SPS Pairing As Peripheral Device command.
ble8_get_server_cnfg_cmd
void ble8_get_server_cnfg_cmd(ble8_t *ctx)
Get Server Configuration command.
ble8_get_dtr_pin
uint8_t ble8_get_dtr_pin(ble8_t *ctx)
Check DTR Pin function.
ble8_get_echo_cmd
void ble8_get_echo_cmd(ble8_t *ctx)
Get Echo Setting command.
ble8_t::dsr
digital_out_t dsr
Definition: ble8.h:186
ble8_response_ready
uint8_t ble8_response_ready(ble8_t *ctx)
Response Ready function.
ble8_t::uart
uart_t uart
Definition: ble8.h:195
ble8_connectability_en_cmd
void ble8_connectability_en_cmd(ble8_t *ctx, uint8_t conn_mode)
Connectability Mode Setting command.
ble8_t::dtr
digital_in_t dtr
Definition: ble8.h:190
ble8_t::rst
digital_out_t rst
Definition: ble8.h:184
ble8_set_local_name_cmd
void ble8_set_local_name_cmd(ble8_t *ctx, char *local_name)
Local Name Setting command.
ble8_get_local_name_cmd
void ble8_get_local_name_cmd(ble8_t *ctx)
Get Local Name command.
ble8_cfg_t::rts
pin_name_t rts
Definition: ble8.h:221
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: ble8.h:167
ble8_cfg_setup
void ble8_cfg_setup(ble8_cfg_t *cfg)
Config Object Initialization function.
ble8_sps_central_pairing
uint8_t ble8_sps_central_pairing(ble8_t *ctx, uint8_t *local_addr)
SPS Pairing As Central Device command.
ble8_get_list_peers_cmd
void ble8_get_list_peers_cmd(ble8_t *ctx)
Get Peer List command.
ble8_generic_read
int32_t ble8_generic_read(ble8_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
ble8_set_dsr_pin
void ble8_set_dsr_pin(ble8_t *ctx, uint8_t state)
Set DSR Pin function.
ble8_cfg_t::uart_blocking
bool uart_blocking
Definition: ble8.h:226
ble8_get_start_mode_cmd
void ble8_get_start_mode_cmd(ble8_t *ctx)
Get Module Start Mode command.
ble8_t::rts
digital_in_t rts
Definition: ble8.h:191
ble8_reset
void ble8_reset(ble8_t *ctx)
Reset function.
ble8_check_discoverability_cmd
void ble8_check_discoverability_cmd(ble8_t *ctx)
Get Discoverability Mode command.
ble8_get_rts_pin
uint8_t ble8_get_rts_pin(ble8_t *ctx)
Check RTS Pin function.
ble8_send_command
void ble8_send_command(ble8_t *ctx, char *command, uint8_t term_char)
Transmit function.