rn4678 2.0.0.0
rn4678.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 RN4678_H
36#define RN4678_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define RN4678_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.sw_btn = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.wkup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
81#define RN4678_RETVAL uint8_t
82
83#define RN4678_INIT_OK 0x00
84#define RN4678_INIT_ERROR 0xFF
91#define RN4678_CMD 0x01
92#define RN4678_AOK 0x02
93#define RN4678_CONN 0x03
94#define RN4678_DONE 0x04
95#define RN4678_ERR 0x00
96#define RN4678_OK 0x01
103#define DRV_RX_BUFFER_SIZE 500
106 // End group macro
107// --------------------------------------------------------------- PUBLIC TYPES
115typedef struct
116{
117 // Output pins
118
119 digital_out_t rst;
120 digital_out_t cts;
121 digital_out_t sw_btn;
122 digital_out_t wkup;
123
124 // Modules
125 digital_in_t rts;
126
127 uart_t uart;
128
129 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
130 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
131
132} rn4678_t;
133
137typedef struct
138{
139 // Communication gpio pins
140
141 pin_name_t rx_pin;
142 pin_name_t tx_pin;
143
144 // Additional gpio pins
145
146 pin_name_t rst;
147 pin_name_t wkup;
148 pin_name_t cts;
149 pin_name_t sw_btn;
150 pin_name_t rts;
151
152 // static variable
153
154 uint32_t baud_rate; // Clock speed.
156 uart_data_bits_t data_bit; // Data bits.
157 uart_parity_t parity_bit; // Parity bit.
158 uart_stop_bits_t stop_bit; // Stop bits.
159
161
165typedef uint8_t rn4678_error_t;
166
167 // End types group
168// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
169
175#ifdef __cplusplus
176extern "C"{
177#endif
178
188
197
204void rn4678_generic_write ( rn4678_t *ctx, char *data_buf, uint16_t len );
205
213int32_t rn4678_generic_read ( rn4678_t *ctx, char *data_buf, uint16_t max_len );
214
221void rn4678_write_command ( rn4678_t *ctx, char *data_buf, uint16_t len );
222
234void rn4678_set_cts_pin ( rn4678_t *ctx, uint8_t state );
235
245
256
266
276
286
296void rn4678_set_device_name ( rn4678_t *ctx, uint8_t *name );
297
322void rn4678_set_operating_mode ( rn4678_t *ctx, uint8_t op_mode );
323
333
343
360void rn4678_set_authentication ( rn4678_t *ctx, uint8_t auth_value );
361
380void rn4678_set_break ( rn4678_t *ctx, uint8_t break_signal );
381
394RN4678_RETVAL rn4678_set_cod ( rn4678_t *ctx, uint8_t *msw, uint8_t *lsw );
395
405
415void rn4678_set_discoverability ( rn4678_t *ctx, uint8_t *d_hex_value );
416
426void rn4678_setConnectability ( rn4678_t *ctx, uint8_t *c_hex_value );
427
446
458void rn4678_set_extended_status_string ( rn4678_t *ctx, uint8_t *es_string );
459
474
496RN4678_RETVAL rn4678_set_special_config ( rn4678_t *ctx, uint16_t special_config );
497
509void rn4678_set_remote_address ( rn4678_t *ctx, uint8_t *r_addr );
510
532RN4678_RETVAL rn4678_set_baud_rate ( rn4678_t *ctx, uint32_t baud_rate );
533
543
553
563
587RN4678_RETVAL rn4678_set_profile ( rn4678_t *ctx, uint8_t profile );
588
598
608
618void rn4678_connect_to_remote_address ( rn4678_t *ctx, uint8_t *r_addr );
619
630
640
650
660
670
680
690
700
710
729
739
740#ifdef __cplusplus
741}
742#endif
743#endif // _RN4678_H_
744
745 // End public_function group
747
748// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition rn4678.h:103
#define RN4678_RETVAL
Definition rn4678.h:81
RN4678_RETVAL rn4678_set_profile(rn4678_t *ctx, uint8_t profile)
Set the profile function.
void rn4678_get_help(rn4678_t *ctx)
Get displays a list of help command function.
void rn4678_exit_command_mode(rn4678_t *ctx)
Exit the command mode function.
void rn4678_disable_7_bit_data_mode(rn4678_t *ctx)
Disable 7-Bit data mode function.
void rn4678_disable_bonding(rn4678_t *ctx)
Set bonding disable function.
void rn4678_set_discoverability(rn4678_t *ctx, uint8_t *d_hex_value)
Set enable an inquiry scan function.
void rn4678_hw_reset(rn4678_t *ctx)
Hardwere reset function.
void rn4678_get_extended_settings(rn4678_t *ctx)
Get displays the device�s extended settings function.
void rn4678_get_firmware_version(rn4678_t *ctx)
Get firmware version function.
RN4678_RETVAL rn4678_set_quiet_mode(rn4678_t *ctx, uint8_t q_mode)
Set quiet mode function.
void rn4678_enter_command_mode(rn4678_t *ctx)
Enter the command mode function.
void rn4678_enable_bonding(rn4678_t *ctx)
Set bonding enable function.
void rn4678_set_factory_defaults(rn4678_t *ctx)
Set factory defaults settings function.
void rn4678_set_remote_address(rn4678_t *ctx, uint8_t *r_addr)
Set the remote Bluetooth address function.
RN4678_RETVAL rn4678_set_uart_parity(rn4678_t *ctx, uint8_t character)
Set UART parity function.
void rn4678_reboot(rn4678_t *ctx)
Reboot the module function.
void rn4678_enable_role_switch(rn4678_t *ctx)
Enables the role switch function.
void rn4678_setConnectability(rn4678_t *ctx, uint8_t *c_hex_value)
Set enable page scanning function.
void rn4678_generic_write(rn4678_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void rn4678_connect_to_remote_address_fast_mode(rn4678_t *ctx, uint8_t *r_addr)
Connect the device to a remote address fast mode function.
void rn4678_set_break(rn4678_t *ctx, uint8_t break_signal)
Set the break function.
void rn4678_disable_role_switch(rn4678_t *ctx)
Disables the role switch function.
RN4678_RETVAL rn4678_set_security_pin_code(rn4678_t *ctx, uint8_t *sp_code)
Set security pin code function.
RN4678_RETVAL rn4678_set_special_config(rn4678_t *ctx, uint16_t special_config)
Set special configuration settings function.
void rn4678_get_basic_settings(rn4678_t *ctx)
Get displays basic settings function.
void rn4678_scans_device(rn4678_t *ctx)
Scans for Bluetooth devices in pairing mode function.
void rn4678_enable_7_bit_data_mode(rn4678_t *ctx)
Enable 7-Bit data mode function.
void rn4678_endspecial_config(rn4678_t *ctx)
Ends configuration and puts the device into fast data mode function.
void rn4678_set_device_name(rn4678_t *ctx, uint8_t *name)
Set the device name function.
void rn4678_set_cts_pin(rn4678_t *ctx, uint8_t state)
CTS Pin Setting function.
void rn4678_toggle_echo(rn4678_t *ctx)
Toggles echo function.
void rn4678_set_authentication(rn4678_t *ctx, uint8_t auth_value)
Set the authentication function.
void rn4678_set_extended_status_string(rn4678_t *ctx, uint8_t *es_string)
Set extended status string function.
void rn4678_connect_to_remote_address(rn4678_t *ctx, uint8_t *r_addr)
Connect the device to a remote address function.
RN4678_RETVAL rn4678_set_cod(rn4678_t *ctx, uint8_t *msw, uint8_t *lsw)
Sets the class of device (COD) function.
void rn4678_set_undiscoverable(rn4678_t *ctx)
Set undiscoverable mode function.
RN4678_RETVAL rn4678_set_baud_rate(rn4678_t *ctx, uint32_t baud_rate)
Set the baud rate function.
int32_t rn4678_generic_read(rn4678_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rn4678_enable(rn4678_t *ctx)
Enable device function.
void rn4678_cfg_setup(rn4678_cfg_t *cfg)
Config Object Initialization function.
RN4678_RETVAL rn4678_init(rn4678_t *ctx, rn4678_cfg_t *cfg)
Initialization function.
void rn4678_set_operating_mode(rn4678_t *ctx, uint8_t op_mode)
Set the operating mode function.
void rn4678_get_signal_status(rn4678_t *ctx)
Displays the remote side modem signal status function.
void rn4678_get_device_address(rn4678_t *ctx)
Get displays the device�s eBluetooth address function.
void rn4678_write_command(rn4678_t *ctx, char *data_buf, uint16_t len)
Write command function.
uint8_t rn4678_error_t
Error type.
Definition rn4678.h:165
Click configuration structure definition.
Definition rn4678.h:138
pin_name_t rts
Definition rn4678.h:150
uint32_t baud_rate
Definition rn4678.h:154
pin_name_t cts
Definition rn4678.h:148
pin_name_t wkup
Definition rn4678.h:147
bool uart_blocking
Definition rn4678.h:155
uart_data_bits_t data_bit
Definition rn4678.h:156
pin_name_t tx_pin
Definition rn4678.h:142
pin_name_t sw_btn
Definition rn4678.h:149
pin_name_t rx_pin
Definition rn4678.h:141
uart_stop_bits_t stop_bit
Definition rn4678.h:158
uart_parity_t parity_bit
Definition rn4678.h:157
pin_name_t rst
Definition rn4678.h:146
Click ctx object definition.
Definition rn4678.h:116
digital_out_t sw_btn
Definition rn4678.h:121
digital_out_t wkup
Definition rn4678.h:122
uart_t uart
Definition rn4678.h:127
digital_in_t rts
Definition rn4678.h:125
digital_out_t rst
Definition rn4678.h:119
digital_out_t cts
Definition rn4678.h:120