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 
79 #define DRV_RX_BUFFER_SIZE 200
80 #define DRV_TX_BUFFER_SIZE 100
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
92 typedef struct
93 {
94  // Output pins
95 
96  digital_out_t rst;
97  digital_out_t gp1;
98  digital_out_t cts;
99 
100  // Input pins
101 
102  digital_in_t gp0;
103  digital_in_t rts;
104 
105  // Modules
106 
107  uart_t uart;
108 
109  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
110  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
111 
112 } ble7_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t rx_pin;
122  pin_name_t tx_pin;
123 
124  // Additional gpio pins
125 
126  pin_name_t gp0;
127  pin_name_t rst;
128  pin_name_t rts;
129  pin_name_t gp1;
130  pin_name_t cts;
131 
132  // static variable
133 
134  uint32_t baud_rate; // Clock speed.
136  uart_data_bits_t data_bit; // Data bits.
137  uart_parity_t parity_bit; // Parity bit.
138  uart_stop_bits_t stop_bit; // Stop bits.
139 
140 } ble7_cfg_t;
141 
145 typedef uint8_t ble7_error_t;
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
184 void ble7_reset ( ble7_t *ctx );
185 
195 void ble7_generic_write ( ble7_t *ctx, char *data_buf, uint16_t len );
196 
208 int32_t ble7_generic_read ( ble7_t *ctx, char *data_buf, uint16_t max_len );
209 
221 void ble7_send_command ( ble7_t *ctx, char *command );
222 
232 uint8_t ble7_get_gp0 ( ble7_t *ctx );
233 
243 uint8_t ble7_get_rts ( ble7_t *ctx );
244 
253 void ble7_set_gp1 ( ble7_t *ctx, uint8_t state );
254 
263 void ble7_set_cts ( ble7_t *ctx, uint8_t state );
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // _BLE7_H_
269  // End public_function group
272 
273 // ------------------------------------------------------------------------- END
ble7_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble7.h:122
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:79
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:126
ble7_cfg_t::rst
pin_name_t rst
Definition: ble7.h:127
ble7_t
Click ctx object definition.
Definition: ble7.h:93
ble7_t::gp1
digital_out_t gp1
Definition: ble7.h:97
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:121
ble7_t::cts
digital_out_t cts
Definition: ble7.h:98
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:118
ble7_t::rst
digital_out_t rst
Definition: ble7.h:96
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:135
ble7_t::uart
uart_t uart
Definition: ble7.h:107
ble7_cfg_t::rts
pin_name_t rts
Definition: ble7.h:128
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:145
ble7_t::gp0
digital_in_t gp0
Definition: ble7.h:102
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_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble7.h:136
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: ble7.h:80
ble7_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble7.h:138
ble7_cfg_t::gp1
pin_name_t gp1
Definition: ble7.h:129
ble7_cfg_t::cts
pin_name_t cts
Definition: ble7.h:130
ble7_reset
void ble7_reset(ble7_t *ctx)
Reset function.
BLE7_RETVAL
#define BLE7_RETVAL
Definition: ble7.h:67
ble7_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble7.h:134
ble7_t::rts
digital_in_t rts
Definition: ble7.h:103
ble7_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble7.h:137
ble7_send_command
void ble7_send_command(ble7_t *ctx, char *command)
Transmit function.