ble7  2.0.0.0
ble7.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 BLE7_H
36 #define BLE7_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define BLE7_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
61 
67 #define BLE7_RETVAL uint8_t
68 
69 #define BLE7_OK 0x00
70 #define BLE7_INIT_ERROR 0xFF
71 
72 #define BLE7_END_BUFF 0
73 
74 #define BLE7_RSP_READY 1
75 #define BLE7_RSP_NOT_READY 0
76 
82 #define BLE7_MODULE_POWER_ON 1
83 #define BLE7_MODULE_POWER_OFF 0
84 
90 #define DRV_RX_BUFFER_SIZE 500
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef void ( *ble7_hdl_t )( uint8_t* );
104 
108 typedef struct
109 {
110  // Output pins
111 
112  digital_out_t rst;
113  digital_out_t gp1;
114  digital_out_t cts;
115 
116  // Input pins
117 
118  digital_in_t gp0;
119  digital_in_t rts;
120 
121  // Modules
122 
123  uart_t uart;
124 
125  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
126  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
127 
128  uint8_t rsp_rdy;
130 
131 } ble7_t;
132 
136 typedef struct
137 {
138  // Communication gpio pins
139 
140  pin_name_t rx_pin;
141  pin_name_t tx_pin;
142 
143  // Additional gpio pins
144 
145  pin_name_t gp0;
146  pin_name_t rst;
147  pin_name_t rts;
148  pin_name_t gp1;
149  pin_name_t cts;
150 
151  // static variable
152 
153  uint32_t baud_rate; // Clock speed.
155  uart_data_bits_t data_bit; // Data bits.
156  uart_parity_t parity_bit; // Parity bit.
157  uart_stop_bits_t stop_bit; // Stop bits.
158 
159 } ble7_cfg_t;
160 
164 typedef uint8_t ble7_error_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
186 void ble7_cfg_setup ( ble7_cfg_t *cfg );
187 
196 BLE7_RETVAL ble7_init ( ble7_t *ctx, ble7_cfg_t *cfg );
197 
203 void ble7_reset ( ble7_t *ctx );
204 
214 void ble7_generic_write ( ble7_t *ctx, char *data_buf, uint16_t len );
215 
227 int32_t ble7_generic_read ( ble7_t *ctx, char *data_buf, uint16_t max_len );
228 
240 void ble7_send_command ( ble7_t *ctx, char *command );
241 
251 void ble7_response_handler_set ( ble7_t *ctx, void ( *handler )( uint8_t* ) );
252 
261 void ble7_uart_isr ( ble7_t *ctx, uint8_t rx_dat );
262 
272 uint8_t ble7_response_ready ( ble7_t *ctx );
273 
283 uint8_t ble7_get_gp0 ( ble7_t *ctx );
284 
294 uint8_t ble7_get_rts ( ble7_t *ctx );
295 
304 void ble7_set_gp1 ( ble7_t *ctx, uint8_t state );
305 
314 void ble7_set_cts ( ble7_t *ctx, uint8_t state );
315 
316 void ble7_receive_command( ble7_t *ctx, char* data_buf);
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // _BLE7_H_
322  // End public_function group
325 
326 // ------------------------------------------------------------------------- END
ble7_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble7.h:141
ble7_cfg_setup
void ble7_cfg_setup(ble7_cfg_t *cfg)
Config Object Initialization function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: ble7.h:90
ble7_set_cts
void ble7_set_cts(ble7_t *ctx, uint8_t state)
CTS Pin Setting function.
ble7_cfg_t::gp0
pin_name_t gp0
Definition: ble7.h:145
ble7_response_handler_set
void ble7_response_handler_set(ble7_t *ctx, void(*handler)(uint8_t *))
Handler Setting function.
ble7_cfg_t::rst
pin_name_t rst
Definition: ble7.h:146
ble7_hdl_t
void(* ble7_hdl_t)(uint8_t *)
Handler definition.
Definition: ble7.h:103
ble7_t
Click ctx object definition.
Definition: ble7.h:108
ble7_t::gp1
digital_out_t gp1
Definition: ble7.h:113
ble7_t::driver_hdl
ble7_hdl_t driver_hdl
Definition: ble7.h:129
ble7_t::rsp_rdy
uint8_t rsp_rdy
Definition: ble7.h:128
ble7_set_gp1
void ble7_set_gp1(ble7_t *ctx, uint8_t state)
GP1 Pin Setting function.
ble7_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble7.h:140
ble7_t::cts
digital_out_t cts
Definition: ble7.h:114
ble7_init
BLE7_RETVAL ble7_init(ble7_t *ctx, ble7_cfg_t *cfg)
Initialization function.
ble7_cfg_t
Click configuration structure definition.
Definition: ble7.h:136
ble7_t::rst
digital_out_t rst
Definition: ble7.h:112
ble7_get_gp0
uint8_t ble7_get_gp0(ble7_t *ctx)
GP0 Pin Getting function.
ble7_cfg_t::uart_blocking
bool uart_blocking
Definition: ble7.h:154
ble7_t::uart
uart_t uart
Definition: ble7.h:123
ble7_response_ready
uint8_t ble7_response_ready(ble7_t *ctx)
Response Ready function.
ble7_cfg_t::rts
pin_name_t rts
Definition: ble7.h:147
ble7_generic_read
int32_t ble7_generic_read(ble7_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
ble7_error_t
uint8_t ble7_error_t
Error type.
Definition: ble7.h:164
ble7_t::gp0
digital_in_t gp0
Definition: ble7.h:118
ble7_generic_write
void ble7_generic_write(ble7_t *ctx, char *data_buf, uint16_t len)
Generic write function.
ble7_get_rts
uint8_t ble7_get_rts(ble7_t *ctx)
RTS Pin Getting function.
ble7_uart_isr
void ble7_uart_isr(ble7_t *ctx, uint8_t rx_dat)
UART ISR function.
ble7_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble7.h:155
ble7_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble7.h:157
ble7_cfg_t::gp1
pin_name_t gp1
Definition: ble7.h:148
ble7_cfg_t::cts
pin_name_t cts
Definition: ble7.h:149
ble7_reset
void ble7_reset(ble7_t *ctx)
Reset function.
ble7_receive_command
void ble7_receive_command(ble7_t *ctx, char *data_buf)
BLE7_RETVAL
#define BLE7_RETVAL
Definition: ble7.h:67
ble7_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble7.h:153
ble7_t::rts
digital_in_t rts
Definition: ble7.h:119
ble7_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble7.h:156
ble7_send_command
void ble7_send_command(ble7_t *ctx, char *command)
Transmit function.