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 
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 RN4678_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.sw_btn = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.wkup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define RN4678_RETVAL uint8_t
78 
79 #define RN4678_INIT_OK 0x00
80 #define RN4678_INIT_ERROR 0xFF
81 
87 #define RN4678_CMD 0x01
88 #define RN4678_AOK 0x02
89 #define RN4678_CONN 0x03
90 #define RN4678_DONE 0x04
91 #define RN4678_ERR 0x00
92 #define RN4678_OK 0x01
93 
99 #define DRV_RX_BUFFER_SIZE 500
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
111 typedef struct
112 {
113  // Output pins
114 
115  digital_out_t rst;
116  digital_out_t cts;
117  digital_out_t sw_btn;
118  digital_out_t wkup;
119 
120  // Modules
121  digital_in_t rts;
122 
123  uart_t uart;
124 
125  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
126  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
127 
128 } rn4678_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136 
137  pin_name_t rx_pin;
138  pin_name_t tx_pin;
139 
140  // Additional gpio pins
141 
142  pin_name_t rst;
143  pin_name_t wkup;
144  pin_name_t cts;
145  pin_name_t sw_btn;
146  pin_name_t rts;
147 
148  // static variable
149 
150  uint32_t baud_rate; // Clock speed.
152  uart_data_bits_t data_bit; // Data bits.
153  uart_parity_t parity_bit; // Parity bit.
154  uart_stop_bits_t stop_bit; // Stop bits.
155 
156 } rn4678_cfg_t;
157 
161 typedef uint8_t rn4678_error_t;
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
193 
200 void rn4678_generic_write ( rn4678_t *ctx, char *data_buf, uint16_t len );
201 
209 int32_t rn4678_generic_read ( rn4678_t *ctx, char *data_buf, uint16_t max_len );
210 
217 void rn4678_write_command ( rn4678_t *ctx, char *data_buf, uint16_t len );
218 
230 void rn4678_set_cts_pin ( rn4678_t *ctx, uint8_t state );
231 
240 void rn4678_enable ( rn4678_t *ctx );
241 
251 void rn4678_hw_reset ( rn4678_t *ctx );
252 
262 
272 
282 
292 void rn4678_set_device_name ( rn4678_t *ctx, uint8_t *name );
293 
318 void rn4678_set_operating_mode ( rn4678_t *ctx, uint8_t op_mode );
319 
329 
339 
356 void rn4678_set_authentication ( rn4678_t *ctx, uint8_t auth_value );
357 
376 void rn4678_set_break ( rn4678_t *ctx, uint8_t break_signal );
377 
390 RN4678_RETVAL rn4678_set_cod ( rn4678_t *ctx, uint8_t *msw, uint8_t *lsw );
391 
401 
411 void rn4678_set_discoverability ( rn4678_t *ctx, uint8_t *d_hex_value );
412 
422 void rn4678_setConnectability ( rn4678_t *ctx, uint8_t *c_hex_value );
423 
441 RN4678_RETVAL rn4678_set_uart_parity ( rn4678_t *ctx, uint8_t character );
442 
454 void rn4678_set_extended_status_string ( rn4678_t *ctx, uint8_t *es_string );
455 
470 
492 RN4678_RETVAL rn4678_set_special_config ( rn4678_t *ctx, uint16_t special_config );
493 
505 void rn4678_set_remote_address ( rn4678_t *ctx, uint8_t *r_addr );
506 
528 RN4678_RETVAL rn4678_set_baud_rate ( rn4678_t *ctx, uint32_t baud_rate );
529 
539 
549 
558 void rn4678_reboot ( rn4678_t *ctx );
559 
583 RN4678_RETVAL rn4678_set_profile ( rn4678_t *ctx, uint8_t profile );
584 
594 
604 
614 void rn4678_connect_to_remote_address ( rn4678_t *ctx, uint8_t *r_addr );
615 
626 
636 
645 void rn4678_get_help ( rn4678_t *ctx );
646 
656 
666 
676 
686 
696 
706 
725 
735 
736 #ifdef __cplusplus
737 }
738 #endif
739 #endif // _RN4678_H_
740  // End public_function group
743 
744 // ------------------------------------------------------------------------- END
rn4678_disable_bonding
void rn4678_disable_bonding(rn4678_t *ctx)
Set bonding disable function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rn4678.h:99
rn4678_t::rts
digital_in_t rts
Definition: rn4678.h:121
rn4678_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rn4678.h:138
rn4678_connect_to_remote_address_fast_mode
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.
rn4678_cfg_t::sw_btn
pin_name_t sw_btn
Definition: rn4678.h:145
rn4678_reboot
void rn4678_reboot(rn4678_t *ctx)
Reboot the module function.
rn4678_get_extended_settings
void rn4678_get_extended_settings(rn4678_t *ctx)
Get displays the device�s extended settings function.
rn4678_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rn4678.h:153
rn4678_set_extended_status_string
void rn4678_set_extended_status_string(rn4678_t *ctx, uint8_t *es_string)
Set extended status string function.
rn4678_set_authentication
void rn4678_set_authentication(rn4678_t *ctx, uint8_t auth_value)
Set the authentication function.
rn4678_set_uart_parity
RN4678_RETVAL rn4678_set_uart_parity(rn4678_t *ctx, uint8_t character)
Set UART parity function.
rn4678_scans_device
void rn4678_scans_device(rn4678_t *ctx)
Scans for Bluetooth devices in pairing mode function.
rn4678_set_device_name
void rn4678_set_device_name(rn4678_t *ctx, uint8_t *name)
Set the device name function.
rn4678_t::sw_btn
digital_out_t sw_btn
Definition: rn4678.h:117
rn4678_enable_bonding
void rn4678_enable_bonding(rn4678_t *ctx)
Set bonding enable function.
rn4678_set_security_pin_code
RN4678_RETVAL rn4678_set_security_pin_code(rn4678_t *ctx, uint8_t *sp_code)
Set security pin code function.
rn4678_set_quiet_mode
RN4678_RETVAL rn4678_set_quiet_mode(rn4678_t *ctx, uint8_t q_mode)
Set quiet mode function.
rn4678_init
RN4678_RETVAL rn4678_init(rn4678_t *ctx, rn4678_cfg_t *cfg)
Initialization function.
rn4678_disable_role_switch
void rn4678_disable_role_switch(rn4678_t *ctx)
Disables the role switch function.
rn4678_endspecial_config
void rn4678_endspecial_config(rn4678_t *ctx)
Ends configuration and puts the device into fast data mode function.
rn4678_get_basic_settings
void rn4678_get_basic_settings(rn4678_t *ctx)
Get displays basic settings function.
rn4678_enable_7_bit_data_mode
void rn4678_enable_7_bit_data_mode(rn4678_t *ctx)
Enable 7-Bit data mode function.
rn4678_set_discoverability
void rn4678_set_discoverability(rn4678_t *ctx, uint8_t *d_hex_value)
Set enable an inquiry scan function.
rn4678_cfg_t::uart_blocking
bool uart_blocking
Definition: rn4678.h:151
rn4678_generic_write
void rn4678_generic_write(rn4678_t *ctx, char *data_buf, uint16_t len)
Generic write function.
rn4678_exit_command_mode
void rn4678_exit_command_mode(rn4678_t *ctx)
Exit the command mode function.
rn4678_cfg_t::cts
pin_name_t cts
Definition: rn4678.h:144
rn4678_enter_command_mode
void rn4678_enter_command_mode(rn4678_t *ctx)
Enter the command mode function.
rn4678_t::cts
digital_out_t cts
Definition: rn4678.h:116
rn4678_generic_read
int32_t rn4678_generic_read(rn4678_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
rn4678_set_remote_address
void rn4678_set_remote_address(rn4678_t *ctx, uint8_t *r_addr)
Set the remote Bluetooth address function.
rn4678_get_firmware_version
void rn4678_get_firmware_version(rn4678_t *ctx)
Get firmware version function.
rn4678_set_special_config
RN4678_RETVAL rn4678_set_special_config(rn4678_t *ctx, uint16_t special_config)
Set special configuration settings function.
rn4678_t
Click ctx object definition.
Definition: rn4678.h:112
rn4678_cfg_t::wkup
pin_name_t wkup
Definition: rn4678.h:143
rn4678_error_t
uint8_t rn4678_error_t
Error type.
Definition: rn4678.h:161
rn4678_set_baud_rate
RN4678_RETVAL rn4678_set_baud_rate(rn4678_t *ctx, uint32_t baud_rate)
Set the baud rate function.
rn4678_cfg_t::baud_rate
uint32_t baud_rate
Definition: rn4678.h:150
rn4678_get_signal_status
void rn4678_get_signal_status(rn4678_t *ctx)
Displays the remote side modem signal status function.
rn4678_disable_7_bit_data_mode
void rn4678_disable_7_bit_data_mode(rn4678_t *ctx)
Disable 7-Bit data mode function.
rn4678_set_cts_pin
void rn4678_set_cts_pin(rn4678_t *ctx, uint8_t state)
CTS Pin Setting function.
rn4678_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rn4678.h:154
rn4678_set_factory_defaults
void rn4678_set_factory_defaults(rn4678_t *ctx)
Set factory defaults settings function.
rn4678_cfg_t::rts
pin_name_t rts
Definition: rn4678.h:146
rn4678_connect_to_remote_address
void rn4678_connect_to_remote_address(rn4678_t *ctx, uint8_t *r_addr)
Connect the device to a remote address function.
rn4678_set_cod
RN4678_RETVAL rn4678_set_cod(rn4678_t *ctx, uint8_t *msw, uint8_t *lsw)
Sets the class of device (COD) function.
rn4678_enable
void rn4678_enable(rn4678_t *ctx)
Enable device function.
rn4678_cfg_t::rst
pin_name_t rst
Definition: rn4678.h:142
rn4678_cfg_t
Click configuration structure definition.
Definition: rn4678.h:134
rn4678_get_help
void rn4678_get_help(rn4678_t *ctx)
Get displays a list of help command function.
rn4678_toggle_echo
void rn4678_toggle_echo(rn4678_t *ctx)
Toggles echo function.
rn4678_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rn4678.h:137
rn4678_t::wkup
digital_out_t wkup
Definition: rn4678.h:118
rn4678_t::uart
uart_t uart
Definition: rn4678.h:123
rn4678_hw_reset
void rn4678_hw_reset(rn4678_t *ctx)
Hardwere reset function.
rn4678_get_device_address
void rn4678_get_device_address(rn4678_t *ctx)
Get displays the device�s eBluetooth address function.
RN4678_RETVAL
#define RN4678_RETVAL
Definition: rn4678.h:77
rn4678_set_profile
RN4678_RETVAL rn4678_set_profile(rn4678_t *ctx, uint8_t profile)
Set the profile function.
rn4678_write_command
void rn4678_write_command(rn4678_t *ctx, char *data_buf, uint16_t len)
Write command function.
rn4678_cfg_setup
void rn4678_cfg_setup(rn4678_cfg_t *cfg)
Config Object Initialization function.
rn4678_set_operating_mode
void rn4678_set_operating_mode(rn4678_t *ctx, uint8_t op_mode)
Set the operating mode function.
rn4678_enable_role_switch
void rn4678_enable_role_switch(rn4678_t *ctx)
Enables the role switch function.
rn4678_set_undiscoverable
void rn4678_set_undiscoverable(rn4678_t *ctx)
Set undiscoverable mode function.
rn4678_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rn4678.h:152
rn4678_set_break
void rn4678_set_break(rn4678_t *ctx, uint8_t break_signal)
Set the break function.
rn4678_t::rst
digital_out_t rst
Definition: rn4678.h:115
rn4678_setConnectability
void rn4678_setConnectability(rn4678_t *ctx, uint8_t *c_hex_value)
Set enable page scanning function.