btez  2.0.0.0
btez.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 BTEZ_H
36 #define BTEZ_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define BTEZ_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define BTEZ_RETVAL uint8_t
65 
66 #define BTEZ_OK 0x00
67 #define BTEZ_INIT_ERROR 0xFF
68 
74 #define DRV_RX_BUFFER_SIZE 500
75 #define DRV_TX_BUFFER_SIZE 200
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t rst;
92  digital_out_t cts;
93 
94  // Input pins
95 
96  digital_in_t rts;
97 
98  // Modules
99 
100  uart_t uart;
101 
102  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
103  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
104 
105 } btez_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t rx_pin;
115  pin_name_t tx_pin;
116 
117  // Additional gpio pins
118 
119  pin_name_t rst;
120  pin_name_t cts;
121  pin_name_t rts;
122 
123  // static variable
124 
125  uint32_t baud_rate; // Clock speed.
127  uart_data_bits_t data_bit; // Data bits.
128  uart_parity_t parity_bit; // Parity bit.
129  uart_stop_bits_t stop_bit; // Stop bits.
130 
131 } btez_cfg_t;
132 
136 typedef uint8_t btez_error_t;
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
169 
175 void btez_module_reset ( btez_t *ctx );
176 
184 void btez_generic_write ( btez_t *ctx, char *data_buf, uint16_t len );
185 
194 int32_t btez_generic_read ( btez_t *ctx, char *data_buf, uint16_t max_len );
195 
202 void btez_send_command ( btez_t *ctx, char *command );
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 #endif // _BTEZ_H_
208  // End public_function group
211 
212 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: btez.h:74
btez_t::rst
digital_out_t rst
Definition: btez.h:91
btez_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: btez.h:129
btez_cfg_t
Click configuration structure definition.
Definition: btez.h:111
btez_cfg_t::tx_pin
pin_name_t tx_pin
Definition: btez.h:115
btez_cfg_t::cts
pin_name_t cts
Definition: btez.h:120
btez_cfg_t::rx_pin
pin_name_t rx_pin
Definition: btez.h:114
btez_cfg_t::baud_rate
uint32_t baud_rate
Definition: btez.h:125
btez_send_command
void btez_send_command(btez_t *ctx, char *command)
Send command function.
btez_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: btez.h:128
BTEZ_RETVAL
#define BTEZ_RETVAL
Definition: btez.h:64
btez_t::rts
digital_in_t rts
Definition: btez.h:96
btez_module_reset
void btez_module_reset(btez_t *ctx)
Reset module.
btez_error_t
uint8_t btez_error_t
Error type.
Definition: btez.h:136
btez_t
Click ctx object definition.
Definition: btez.h:88
btez_t::cts
digital_out_t cts
Definition: btez.h:92
btez_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: btez.h:127
btez_cfg_t::rts
pin_name_t rts
Definition: btez.h:121
btez_cfg_setup
void btez_cfg_setup(btez_cfg_t *cfg)
Config Object Initialization function.
btez_init
BTEZ_RETVAL btez_init(btez_t *ctx, btez_cfg_t *cfg)
Initialization function.
btez_t::uart
uart_t uart
Definition: btez.h:100
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: btez.h:75
btez_generic_write
void btez_generic_write(btez_t *ctx, char *data_buf, uint16_t len)
Generic write function.
btez_generic_read
int32_t btez_generic_read(btez_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
btez_cfg_t::uart_blocking
bool uart_blocking
Definition: btez.h:126
btez_cfg_t::rst
pin_name_t rst
Definition: btez.h:119