bm78  2.1.0.0
bm78.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BM78_H
29 #define BM78_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 #include "bm78_config.h"
53 
74 #define BM78_HCI_COMMAND_PACKET 0x01
75 #define BM78_HCI_ACL_DATA_PACKET 0x02
76 #define BM78_HCI_SYNCHRONOUS_DATA_PACKET 0x03
77 #define BM78_HCI_EVENT_PACKET 0x04
78 #define BM78_HCI_ISO_DATA_PACKET 0x05
79 #define BM78_HCI_COMMAND_COMPLETE 0x0E
80 #define BM78_HCI_COMMAND_IND_SUCCESS 0x00
81 
86 #define BM78_PAGE_WRITE_NUMBER 0x08
87 
92 #define BM78_PIN_STATE_HIGH 0x01
93 #define BM78_PIN_STATE_LOW 0x00
94 
99 #define BM78_OPCODE_RESET_CMD 0x030C
100 #define BM78_HCI_EEPROM_WR_PG_NUM_CMD 0x2DFC
101 #define BM78_HCI_EEPROM_WRITE_CMD 0x27FC
102 #define BM78_HCI_EEPROM_READ_CMD 0x29FC
103 
109 #define BM78_TX_DRV_BUFFER_SIZE 100
110 #define BM78_RX_DRV_BUFFER_SIZE 300
111  // bm78_cmd
113 
128 #define BM78_MAP_MIKROBUS( cfg, mikrobus ) \
129  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
130  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
131  cfg.st1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
132  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
133  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
134  cfg.st2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
135  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
136  // bm78_map // bm78
139 
144 typedef struct
145 {
146  // Output pins
147  digital_out_t rst;
148  digital_out_t cts;
150  // Input pins
151  digital_in_t st1;
152  digital_in_t st2;
153  digital_in_t rts;
155  // Modules
156  uart_t uart;
158  // Buffers
159  uint8_t uart_rx_buffer[ BM78_RX_DRV_BUFFER_SIZE ];
160  uint8_t uart_tx_buffer[ BM78_TX_DRV_BUFFER_SIZE ];
162 } bm78_t;
163 
168 typedef struct
169 {
170  // Communication gpio pins
171  pin_name_t rx_pin;
172  pin_name_t tx_pin;
174  // Additional gpio pins
175  pin_name_t st1;
176  pin_name_t rst;
177  pin_name_t cts;
178  pin_name_t st2;
179  pin_name_t rts;
181  // Static variable
182  uint32_t baud_rate;
184  uart_data_bits_t data_bit;
185  uart_parity_t parity_bit;
186  uart_stop_bits_t stop_bit;
188 } bm78_cfg_t;
189 
194 typedef enum
195 {
196  BM78_OK = 0,
197  BM78_ERROR = -1
198 
200 
217 
231 err_t bm78_init ( bm78_t *ctx, bm78_cfg_t *cfg );
232 
245 err_t bm78_generic_write ( bm78_t *ctx, uint8_t *data_in, uint16_t len );
246 
259 err_t bm78_generic_read ( bm78_t *ctx, uint8_t *data_out, uint16_t len );
260 
270 void bm78_set_rst_pin ( bm78_t *ctx, uint8_t pin_state );
271 
281 void bm78_set_cts_pin ( bm78_t *ctx, uint8_t pin_state );
282 
292 uint8_t bm78_get_st1_pin ( bm78_t *ctx );
293 
303 uint8_t bm78_get_st2_pin ( bm78_t *ctx );
304 
314 uint8_t bm78_get_rts_pin ( bm78_t *ctx );
315 
324 void bm78_hw_reset ( bm78_t *ctx );
325 
339 err_t bm78_eeprom_send_cmd ( bm78_t *ctx, uint16_t op_code, uint8_t *param, uint8_t len );
340 
354 err_t bm78_eeprom_get_event ( bm78_t *ctx, uint8_t *ev_type, uint8_t *len, uint8_t *data_rx );
355 
366 err_t bm78_reset_cmd ( bm78_t *ctx );
367 
379 
394 err_t bm78_eeprom_write ( bm78_t *ctx, uint16_t address, uint8_t *data_in, uint8_t len );
395 
411 err_t bm78_eeprom_read ( bm78_t *ctx, uint16_t address, uint8_t *data_out, uint8_t len );
412 
423 err_t bm78_flash_eeprom ( bm78_t *ctx );
424 
425 #ifdef __cplusplus
426 }
427 #endif
428 #endif // BM78_H
429  // bm78
431 
432 // ------------------------------------------------------------------------ END
bm78_t::st1
digital_in_t st1
Definition: bm78.h:151
bm78_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: bm78.h:184
BM78_OK
@ BM78_OK
Definition: bm78.h:196
BM78_RX_DRV_BUFFER_SIZE
#define BM78_RX_DRV_BUFFER_SIZE
Definition: bm78.h:110
bm78_eeprom_write_number
err_t bm78_eeprom_write_number(bm78_t *ctx)
BM78 write EEPROM number function.
bm78_set_rst_pin
void bm78_set_rst_pin(bm78_t *ctx, uint8_t pin_state)
BM78 set RST pin function.
bm78_cfg_t::uart_blocking
bool uart_blocking
Definition: bm78.h:183
bm78_cfg_t::rst
pin_name_t rst
Definition: bm78.h:176
bm78_init
err_t bm78_init(bm78_t *ctx, bm78_cfg_t *cfg)
BM78 initialization function.
bm78_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: bm78.h:186
bm78_eeprom_write
err_t bm78_eeprom_write(bm78_t *ctx, uint16_t address, uint8_t *data_in, uint8_t len)
BM78 EEPROM write function.
bm78_cfg_t::st2
pin_name_t st2
Definition: bm78.h:178
bm78_generic_write
err_t bm78_generic_write(bm78_t *ctx, uint8_t *data_in, uint16_t len)
BM78 data writing function.
bm78_get_st1_pin
uint8_t bm78_get_st1_pin(bm78_t *ctx)
BM78 get ST1 pin function.
bm78_eeprom_read
err_t bm78_eeprom_read(bm78_t *ctx, uint16_t address, uint8_t *data_out, uint8_t len)
BM78 EEPROM read function.
bm78_eeprom_send_cmd
err_t bm78_eeprom_send_cmd(bm78_t *ctx, uint16_t op_code, uint8_t *param, uint8_t len)
BM78 EEPROM send command function.
bm78_cfg_t
BM78 Click configuration object.
Definition: bm78.h:169
bm78_t::st2
digital_in_t st2
Definition: bm78.h:152
bm78_cfg_t::rts
pin_name_t rts
Definition: bm78.h:179
bm78_t::cts
digital_out_t cts
Definition: bm78.h:148
bm78_hw_reset
void bm78_hw_reset(bm78_t *ctx)
BM78 Hardware reset function.
bm78_get_st2_pin
uint8_t bm78_get_st2_pin(bm78_t *ctx)
BM78 get ST2 pin function.
bm78_set_cts_pin
void bm78_set_cts_pin(bm78_t *ctx, uint8_t pin_state)
BM78 set CTS pin function.
bm78_cfg_setup
void bm78_cfg_setup(bm78_cfg_t *cfg)
BM78 configuration object setup function.
bm78_cfg_t::rx_pin
pin_name_t rx_pin
Definition: bm78.h:171
bm78_generic_read
err_t bm78_generic_read(bm78_t *ctx, uint8_t *data_out, uint16_t len)
BM78 data reading function.
bm78_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: bm78.h:185
bm78_get_rts_pin
uint8_t bm78_get_rts_pin(bm78_t *ctx)
BM78 get RTS pin function.
bm78_t::uart
uart_t uart
Definition: bm78.h:156
bm78_cfg_t::tx_pin
pin_name_t tx_pin
Definition: bm78.h:172
bm78_cfg_t::st1
pin_name_t st1
Definition: bm78.h:175
bm78_config.h
bm78_t::rst
digital_out_t rst
Definition: bm78.h:147
bm78_t
BM78 Click context object.
Definition: bm78.h:145
bm78_cfg_t::cts
pin_name_t cts
Definition: bm78.h:177
bm78_return_value_t
bm78_return_value_t
BM78 Click return value data.
Definition: bm78.h:195
BM78_ERROR
@ BM78_ERROR
Definition: bm78.h:197
bm78_flash_eeprom
err_t bm78_flash_eeprom(bm78_t *ctx)
BM78 EEPROM flash function.
bm78_eeprom_get_event
err_t bm78_eeprom_get_event(bm78_t *ctx, uint8_t *ev_type, uint8_t *len, uint8_t *data_rx)
BM78 EEPROM get event function.
bm78_reset_cmd
err_t bm78_reset_cmd(bm78_t *ctx)
BM78 reset function.
BM78_TX_DRV_BUFFER_SIZE
#define BM78_TX_DRV_BUFFER_SIZE
BM78 driver buffer size.
Definition: bm78.h:109
bm78_cfg_t::baud_rate
uint32_t baud_rate
Definition: bm78.h:182
bm78_t::rts
digital_in_t rts
Definition: bm78.h:153