thyonei  2.1.0.0
thyonei.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 THYONEI_H
29 #define THYONEI_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 
73 #define THYONEI_CMD_BROADCAST_DATA_REQ 0x06
74 #define THYONEI_CMD_MULTICAST_DATA_REQ 0x05
75 #define THYONEI_CMD_UNICAST_DATA_REQ 0x04
76 #define THYONEI_CMD_MULTICAST_DATA_EX_REQ 0x08
77 #define THYONEI_CMD_UNICAST_DATA_EX_REQ 0x07
78 #define THYONEI_CMD_DATA_CNF 0x44
79 #define THYONEI_CMD_TXCOMPLETE_RSP 0xC4
80 #define THYONEI_CMD_DATA_IND 0x84
81 #define THYONEI_CMD_SNIFFER_IND 0x99
82 #define THYONEI_CMD_SET_REQ 0x11
83 #define THYONEI_CMD_GET_REQ 0x10
84 #define THYONEI_CMD_START_IND 0x73
85 #define THYONEI_CMD_GETSTATE_REQ 0x01
86 #define THYONEI_CMD_RESET_REQ 0x00
87 #define THYONEI_CMD_SLEEP_REQ 0x02
88 #define THYONEI_CMD_FACTORY_RESET_REQ 0x1C
89 #define THYONEI_CMD_BOOTLOADER_REQ 0x1F
90 #define THYONEI_CMD_TRANSPARENT_MODE_REQ 0x1B
91 #define THYONEI_CMD_SETCHANNEL_REQ 0x19
92 #define THYONEI_CMD_GPIO_LOCAL_SET_CONFIG_REQ 0x25
93 #define THYONEI_CMD_GPIO_LOCAL_GET_CONFIG_REQ 0x26
94 #define THYONEI_CMD_GPIO_REMOTE_SET_CONFIG_REQ 0x29
95 #define THYONEI_CMD_GPIO_REMOTE_GET_CONFIG_REQ 0x2A
96 #define THYONEI_CMD_GPIO_LOCAL_WRITE_REQ 0x27
97 #define THYONEI_CMD_GPIO_LOCAL_READ_REQ 0x28
98 #define THYONEI_CMD_GPIO_REMOTE_WRITE_REQ 0x2B
99 #define THYONEI_CMD_GPIO_REMOTE_READ_REQ 0x2C
100 #define THYONEI_CMD_GPIO_REMOTE_SET_CONFIG_IND 0xA9
101 #define THYONEI_CMD_GPIO_REMOTE_WRITE_IND 0xAB
102 #define THYONEI_CMD_ERROR_IND 0xA2
103 #define THYONEI_CMD_DTM_START_REQ 0x1D
104 #define THYONEI_CMD_DTM_REQ 0x1E
105 
110 #define THYONEI_INDEX_SERIAL_NUMBER 0x01
111 #define THYONEI_INDEX_FW_VERSION 0x02
112 #define THYONEI_INDEX_UART_CONFIG 0x04
113 #define THYONEI_INDEX_UART_MODE 0x05
114 #define THYONEI_INDEX_UART_TRANSPARENT_TIMEOUT 0x06
115 #define THYONEI_INDEX_RF_CHANNEL 0x07
116 #define THYONEI_INDEX_ENCRYPTION_MODE 0x08
117 #define THYONEI_INDEX_RF_PROFILE 0x09
118 #define THYONEI_INDEX_RF_NUM_RETRIES 0x0A
119 #define THYONEI_INDEX_RF_TX_POWER 0x0B
120 #define THYONEI_INDEX_RF_RP_NUM_SLOTS 0x0C
121 #define THYONEI_INDEX_MAC_SOURCE_ADDRESS 0x10
122 #define THYONEI_INDEX_MAC_DEST_ADDRESS 0x11
123 #define THYONEI_INDEX_MAC_GROUP_ID 0x12
124 #define THYONEI_INDEX_MAC_TRANSPARENT_ADDR_MODE 0x13
125 #define THYONEI_INDEX_MAC_ENCRYPTION_KEY 0x14
126 #define THYONEI_INDEX_MAC_TTL 0x15
127 #define THYONEI_INDEX_CCA_MODE 0x16
128 #define THYONEI_INDEX_CCA_THRESHOLD 0x17
129 #define THYONEI_INDEX_GPIO_BLOCK_REMOTE 0x18
130 #define THYONEI_INDEX_UART_TRANSP_ETX_CONFIG 0x19
131 #define THYONEI_INDEX_UART_TRANSP_ETX 0x1A
132 #define THYONEI_INDEX_UART_TRANSP_ETC_ENABLE 0x1B
133 #define THYONEI_INDEX_UART_TRANSP_ETC 0x1C
134 #define THYONEI_INDEX_RF_REPRATER_THRESHOLD 0x1D
135 #define THYONEI_INDEX_MODULE_MODE 0x20
136 
141 #define THYONEI_RESPONSE_CODE 0x40
142 #define THYONEI_START_SIGNAL 0x02
143 
148 #define THYONE_PIN_MODE_HIGH 0x01
149 #define THYONE_PIN_MODE_LOW 0x00
150 
156 #define THYONEI_TX_DRV_BUFFER_SIZE 300
157 #define THYONEI_RX_DRV_BUFFER_SIZE 300
158  // thyonei_cmd
160 
175 #define THYONEI_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
177  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
178  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
179  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
180  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
181  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
182  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
183  // thyonei_map // thyonei
186 
191 typedef struct
192 {
193  // Output pins
194  digital_out_t bt;
195  digital_out_t rst;
196  digital_out_t rts;
197  digital_out_t wup;
199  // Input pins
200  digital_in_t cts;
202  // Modules
203  uart_t uart;
205  // Buffers
206  uint8_t uart_rx_buffer[ THYONEI_RX_DRV_BUFFER_SIZE ];
207  uint8_t uart_tx_buffer[ THYONEI_TX_DRV_BUFFER_SIZE ];
209 } thyonei_t;
210 
215 typedef struct
216 {
217  // Communication gpio pins
218  pin_name_t rx_pin;
219  pin_name_t tx_pin;
221  // Additional gpio pins
222  pin_name_t bt;
223  pin_name_t rst;
224  pin_name_t rts;
225  pin_name_t wup;
226  pin_name_t cts;
228  // Static variable
229  uint32_t baud_rate;
231  uart_data_bits_t data_bit;
232  uart_parity_t parity_bit;
233  uart_stop_bits_t stop_bit;
235 } thyonei_cfg_t;
236 
241 typedef enum
242 {
244  THYONEI_ERROR = -1
245 
247 
264 
278 err_t thyonei_init ( thyonei_t *ctx, thyonei_cfg_t *cfg );
279 
291 
304 err_t thyonei_generic_write ( thyonei_t *ctx, uint8_t *data_in, uint16_t len );
305 
318 err_t thyonei_generic_read ( thyonei_t *ctx, uint8_t *data_out, uint16_t len );
319 
329 
339 void thyonei_set_bt ( thyonei_t *ctx, uint8_t pin_state );
340 
350 void thyonei_set_rst ( thyonei_t *ctx, uint8_t pin_state );
351 
361 void thyonei_set_rts ( thyonei_t *ctx, uint8_t pin_state );
362 
372 void thyonei_set_wup ( thyonei_t *ctx, uint8_t pin_state );
373 
384 
399 err_t thyonei_send_command ( thyonei_t *ctx, uint8_t command, uint16_t payload_length, uint8_t *payload );
400 
415 err_t thyonei_set_req ( thyonei_t *ctx, uint8_t settings_index, uint8_t parameters_length, uint8_t *parameters );
416 
431 err_t thyonei_get_req ( thyonei_t *ctx, uint8_t settings_index, uint8_t *param_len, uint8_t *parameter );
432 
447 err_t thyonei_broadcast_data_req ( thyonei_t *ctx, uint8_t message_len, uint8_t *message );
448 
463 err_t thyonei_multicast_data_req ( thyonei_t *ctx, uint8_t message_len, uint8_t *message );
464 
479 err_t thyonei_unicast_data_req ( thyonei_t *ctx, uint8_t message_len, uint8_t *message );
480 
481 #ifdef __cplusplus
482 }
483 #endif
484 #endif // THYONEI_H
485  // thyonei
487 
488 // ------------------------------------------------------------------------ END
thyonei_t::bt
digital_out_t bt
Definition: thyonei.h:194
thyonei_generic_write
err_t thyonei_generic_write(thyonei_t *ctx, uint8_t *data_in, uint16_t len)
Thyone-I data writing function.
THYONEI_ERROR
@ THYONEI_ERROR
Definition: thyonei.h:244
thyonei_cfg_t::wup
pin_name_t wup
Definition: thyonei.h:225
thyonei_init
err_t thyonei_init(thyonei_t *ctx, thyonei_cfg_t *cfg)
Thyone-I initialization function.
THYONEI_RX_DRV_BUFFER_SIZE
#define THYONEI_RX_DRV_BUFFER_SIZE
Definition: thyonei.h:157
thyonei_cfg_setup
void thyonei_cfg_setup(thyonei_cfg_t *cfg)
Thyone-I configuration object setup function.
thyonei_cfg_t::tx_pin
pin_name_t tx_pin
Definition: thyonei.h:219
thyonei_t
Thyone-I Click context object.
Definition: thyonei.h:192
thyonei_set_rts
void thyonei_set_rts(thyonei_t *ctx, uint8_t pin_state)
Thyone-I set RTS pin function.
thyonei_cfg_t::rx_pin
pin_name_t rx_pin
Definition: thyonei.h:218
thyonei_set_req
err_t thyonei_set_req(thyonei_t *ctx, uint8_t settings_index, uint8_t parameters_length, uint8_t *parameters)
Thyone-I set individual parameters function.
thyonei_cfg_t::rst
pin_name_t rst
Definition: thyonei.h:223
THYONEI_TX_DRV_BUFFER_SIZE
#define THYONEI_TX_DRV_BUFFER_SIZE
Thyone-I driver buffer size.
Definition: thyonei.h:156
thyonei_cfg_t::bt
pin_name_t bt
Definition: thyonei.h:222
thyonei_hw_reset
void thyonei_hw_reset(thyonei_t *ctx)
Thyone-I hardware reser function.
thyonei_get_cts_state
uint8_t thyonei_get_cts_state(thyonei_t *ctx)
Thyone-I get CTS pin function.
thyonei_get_req
err_t thyonei_get_req(thyonei_t *ctx, uint8_t settings_index, uint8_t *param_len, uint8_t *parameter)
Thyone-I get individual parameters function.
thyonei_t::uart
uart_t uart
Definition: thyonei.h:203
thyonei_t::wup
digital_out_t wup
Definition: thyonei.h:197
thyonei_send_command
err_t thyonei_send_command(thyonei_t *ctx, uint8_t command, uint16_t payload_length, uint8_t *payload)
Thyone-I send command function.
thyonei_set_rst
void thyonei_set_rst(thyonei_t *ctx, uint8_t pin_state)
Thyone-I set RST pin function.
thyonei_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: thyonei.h:232
thyonei_broadcast_data_req
err_t thyonei_broadcast_data_req(thyonei_t *ctx, uint8_t message_len, uint8_t *message)
Thyone-I brodcast data function.
thyonei_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: thyonei.h:233
thyonei_generic_read
err_t thyonei_generic_read(thyonei_t *ctx, uint8_t *data_out, uint16_t len)
Thyone-I data reading function.
thyonei_set_bt
void thyonei_set_bt(thyonei_t *ctx, uint8_t pin_state)
Thyone-I set BT pin function.
thyonei_unicast_data_req
err_t thyonei_unicast_data_req(thyonei_t *ctx, uint8_t message_len, uint8_t *message)
Thyone-I unicast data function.
THYONEI_OK
@ THYONEI_OK
Definition: thyonei.h:243
thyonei_t::rts
digital_out_t rts
Definition: thyonei.h:196
thyonei_t::cts
digital_in_t cts
Definition: thyonei.h:200
thyonei_cfg_t::cts
pin_name_t cts
Definition: thyonei.h:226
thyonei_cfg_t::uart_blocking
bool uart_blocking
Definition: thyonei.h:230
thyonei_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: thyonei.h:231
thyonei_cfg_t::rts
pin_name_t rts
Definition: thyonei.h:224
thyonei_t::rst
digital_out_t rst
Definition: thyonei.h:195
thyonei_set_wup
void thyonei_set_wup(thyonei_t *ctx, uint8_t pin_state)
Thyone-I set WUP pin function.
thyonei_cfg_t
Thyone-I Click configuration object.
Definition: thyonei.h:216
thyonei_cfg_t::baud_rate
uint32_t baud_rate
Definition: thyonei.h:229
thyonei_return_value_t
thyonei_return_value_t
Thyone-I Click return value data.
Definition: thyonei.h:242
thyonei_default_cfg
void thyonei_default_cfg(thyonei_t *ctx)
Thyone-I default configuration function.
thyonei_multicast_data_req
err_t thyonei_multicast_data_req(thyonei_t *ctx, uint8_t message_len, uint8_t *message)
Thyone-I multicast data function.