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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define BLE7_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define BLE7_RETVAL uint8_t
78 
79 #define BLE7_OK 0x00
80 #define BLE7_INIT_ERROR 0xFF
81 
82 #define BLE7_END_BUFF 0
83 
89 #define DRV_RX_BUFFER_SIZE 200
90 #define DRV_TX_BUFFER_SIZE 100
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t rst;
107  digital_out_t gp1;
108  digital_out_t cts;
109 
110  // Input pins
111 
112  digital_in_t gp0;
113  digital_in_t rts;
114 
115  // Modules
116 
117  uart_t uart;
118 
119  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
120  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
121 
122 } ble7_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t rx_pin;
132  pin_name_t tx_pin;
133 
134  // Additional gpio pins
135 
136  pin_name_t gp0;
137  pin_name_t rst;
138  pin_name_t rts;
139  pin_name_t gp1;
140  pin_name_t cts;
141 
142  // static variable
143 
144  uint32_t baud_rate; // Clock speed.
146  uart_data_bits_t data_bit; // Data bits.
147  uart_parity_t parity_bit; // Parity bit.
148  uart_stop_bits_t stop_bit; // Stop bits.
149 
150 } ble7_cfg_t;
151 
155 typedef uint8_t ble7_error_t;
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
188 
194 void ble7_reset ( ble7_t *ctx );
195 
205 void ble7_generic_write ( ble7_t *ctx, char *data_buf, uint16_t len );
206 
218 int32_t ble7_generic_read ( ble7_t *ctx, char *data_buf, uint16_t max_len );
219 
231 void ble7_send_command ( ble7_t *ctx, char *command );
232 
242 uint8_t ble7_get_gp0 ( ble7_t *ctx );
243 
253 uint8_t ble7_get_rts ( ble7_t *ctx );
254 
263 void ble7_set_gp1 ( ble7_t *ctx, uint8_t state );
264 
273 void ble7_set_cts ( ble7_t *ctx, uint8_t state );
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // _BLE7_H_
279  // End public_function group
282 
283 // ------------------------------------------------------------------------- END
ble7_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble7.h:132
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:89
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:136
ble7_cfg_t::rst
pin_name_t rst
Definition: ble7.h:137
ble7_t
Click ctx object definition.
Definition: ble7.h:103
ble7_t::gp1
digital_out_t gp1
Definition: ble7.h:107
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:131
ble7_t::cts
digital_out_t cts
Definition: ble7.h:108
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:128
ble7_t::rst
digital_out_t rst
Definition: ble7.h:106
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:145
ble7_t::uart
uart_t uart
Definition: ble7.h:117
ble7_cfg_t::rts
pin_name_t rts
Definition: ble7.h:138
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:155
ble7_t::gp0
digital_in_t gp0
Definition: ble7.h:112
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:146
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: ble7.h:90
ble7_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble7.h:148
ble7_cfg_t::gp1
pin_name_t gp1
Definition: ble7.h:139
ble7_cfg_t::cts
pin_name_t cts
Definition: ble7.h:140
ble7_reset
void ble7_reset(ble7_t *ctx)
Reset function.
BLE7_RETVAL
#define BLE7_RETVAL
Definition: ble7.h:77
ble7_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble7.h:144
ble7_t::rts
digital_in_t rts
Definition: ble7.h:113
ble7_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble7.h:147
ble7_send_command
void ble7_send_command(ble7_t *ctx, char *command)
Transmit function.