proteuse  2.1.0.0
proteuse.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 PROTEUSE_H
29 #define PROTEUSE_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 PROTEUSE_START_BYTE 0x02
74 
79 #define PROTEUSE_CMD_TYPE_REQ 0x00
80 #define PROTEUSE_CMD_TYPE_CNF 0x40
81 #define PROTEUSE_CMD_TYPE_IND 0x80
82 #define PROTEUSE_CMD_TYPE_RSP 0xC0
83 #define PROTEUSE_CMD_TYPE_MASK 0xC0
84 
89 #define PROTEUSE_CMD_REQ_RESET 0x00
90 #define PROTEUSE_CMD_REQ_GET_STATE 0x01
91 #define PROTEUSE_CMD_REQ_SLEEP 0x02
92 #define PROTEUSE_CMD_REQ_DATA 0x04
93 #define PROTEUSE_CMD_REQ_DISCONNECT 0x07
94 #define PROTEUSE_CMD_REQ_DELETE_BONDS 0x0E
95 #define PROTEUSE_CMD_REQ_GET_BONDS 0x0F
96 #define PROTEUSE_CMD_REQ_GET 0x10
97 #define PROTEUSE_CMD_REQ_SET 0x11
98 #define PROTEUSE_CMD_REQ_PHY_UPDATE 0x1A
99 #define PROTEUSE_CMD_REQ_UART_DISABLE 0x1B
100 #define PROTEUSE_CMD_REQ_FACTORY_RESET 0x1C
101 #define PROTEUSE_CMD_REQ_DTM_START 0x1D
102 #define PROTEUSE_CMD_REQ_DTM 0x1E
103 #define PROTEUSE_CMD_REQ_GET_RAM 0x20
104 #define PROTEUSE_CMD_REQ_SET_RAM 0x21
105 #define PROTEUSE_CMD_REQ_GPIO_LOCAL_WRITE_CFG 0x25
106 #define PROTEUSE_CMD_REQ_GPIO_LOCAL_WRITE 0x26
107 #define PROTEUSE_CMD_REQ_GPIO_LOCAL_READ 0x27
108 #define PROTEUSE_CMD_REQ_GPIO_REMOTE_WRITE_CFG 0x28
109 #define PROTEUSE_CMD_REQ_GPIO_REMOTE_WRITE 0x29
110 #define PROTEUSE_CMD_REQ_GPIO_REMOTE_READ 0x2A
111 #define PROTEUSE_CMD_REQ_GPIO_LOCAL_READ_CFG 0x2B
112 #define PROTEUSE_CMD_REQ_GPIO_REMOTE_READ_CFG 0x2C
113 #define PROTEUSE_CMD_REQ_ALLOW_UNBONDED_CONN 0x2D
114 
119 #define PROTEUSE_CMD_CNF_RESET 0x40
120 #define PROTEUSE_CMD_CNF_GET_STATE 0x41
121 #define PROTEUSE_CMD_CNF_SLEEP 0x42
122 #define PROTEUSE_CMD_CNF_DATA 0x44
123 #define PROTEUSE_CMD_CNF_DISCONNECT 0x47
124 #define PROTEUSE_CMD_CNF_DELETE_BONDS 0x4E
125 #define PROTEUSE_CMD_CNF_GET_BONDS 0x4F
126 #define PROTEUSE_CMD_CNF_GET 0x50
127 #define PROTEUSE_CMD_CNF_SET 0x51
128 #define PROTEUSE_CMD_CNF_PHY_UPDATE 0x5A
129 #define PROTEUSE_CMD_CNF_UART_DISABLE 0x5B
130 #define PROTEUSE_CMD_CNF_FACTORY_RESET 0x5C
131 #define PROTEUSE_CMD_CNF_DTM_START 0x5D
132 #define PROTEUSE_CMD_CNF_DTM 0x5E
133 #define PROTEUSE_CMD_CNF_GET_RAM 0x60
134 #define PROTEUSE_CMD_CNF_SET_RAM 0x61
135 #define PROTEUSE_CMD_CNF_GPIO_LOCAL_WRITE_CFG 0x65
136 #define PROTEUSE_CMD_CNF_GPIO_LOCAL_WRITE 0x66
137 #define PROTEUSE_CMD_CNF_GPIO_LOCAL_READ 0x67
138 #define PROTEUSE_CMD_CNF_GPIO_REMOTE_WRITE_CFG 0x68
139 #define PROTEUSE_CMD_CNF_GPIO_REMOTE_WRITE 0x69
140 #define PROTEUSE_CMD_CNF_GPIO_REMOTE_READ 0x6A
141 #define PROTEUSE_CMD_CNF_GPIO_LOCAL_READ_CFG 0x6B
142 #define PROTEUSE_CMD_CNF_GPIO_REMOTE_READ_CFG 0x6C
143 #define PROTEUSE_CMD_CNF_ALLOW_UNBONDED_CONN 0x6D
144 
149 #define PROTEUSE_CMD_IND_SLEEP 0x82
150 #define PROTEUSE_CMD_IND_DATA 0x84
151 #define PROTEUSE_CMD_IND_CONNECT 0x86
152 #define PROTEUSE_CMD_IND_DISCONNECT 0x87
153 #define PROTEUSE_CMD_IND_SECURITY 0x88
154 #define PROTEUSE_CMD_IND_PHY_UPDATE 0x9A
155 #define PROTEUSE_CMD_IND_UART_ENABLE 0x9B
156 #define PROTEUSE_CMD_IND_ERROR 0xA2
157 #define PROTEUSE_CMD_IND_GPIO_LOCAL_WRITE 0xA6
158 #define PROTEUSE_CMD_IND_GPIO_REMOTE_WRITE_CFG 0xA8
159 #define PROTEUSE_CMD_IND_GPIO_REMOTE_WRITE 0xA9
160 
165 #define PROTEUSE_CMD_RSP_TX_COMPLETE 0xC4
166 #define PROTEUSE_CMD_RSP_CHANNEL_OPEN 0xC6
167 
172 #define PROTEUSE_SET_IDX_FS_FW_VERSION 0x01
173 #define PROTEUSE_SET_IDX_RF_DEVICE_NAME 0x02
174 #define PROTEUSE_SET_IDX_FS_MAC 0x03
175 #define PROTEUSE_SET_IDX_FS_BTMAC 0x04
176 #define PROTEUSE_SET_IDX_UART_TRANSP_ETX 0x05
177 #define PROTEUSE_SET_IDX_UART_TRANSP_ETX_CFG 0x06
178 #define PROTEUSE_SET_IDX_RF_ADV_TIMEOUT 0x07
179 #define PROTEUSE_SET_IDX_RF_CONN_INTERVAL 0x08
180 #define PROTEUSE_SET_IDX_RF_ADV_INTERVAL 0x09
181 #define PROTEUSE_SET_IDX_UART_CFG_INDEX 0x0B
182 #define PROTEUSE_SET_IDX_RF_SEC_FLAGS 0x0C
183 #define PROTEUSE_SET_IDX_RF_ADV_DATA 0x0D
184 #define PROTEUSE_SET_IDX_RF_SCAN_RSP_DATA 0x0E
185 #define PROTEUSE_SET_IDX_FS_DEVICE_INFO 0x0F
186 #define PROTEUSE_SET_IDX_FS_SERIAL_NUMBER 0x10
187 #define PROTEUSE_SET_IDX_RF_TX_POWER 0x11
188 #define PROTEUSE_SET_IDX_RF_STATIC_PASSKEY 0x12
189 #define PROTEUSE_SET_IDX_RF_APPEARANCE 0x19
190 #define PROTEUSE_SET_IDX_RF_SPP_BASE_UUID 0x1A
191 #define PROTEUSE_SET_IDX_RF_CFG_FLAGS 0x1C
192 #define PROTEUSE_SET_IDX_RF_SPP_SERVICE_UUID 0x20
193 #define PROTEUSE_SET_IDX_RF_SPP_RX_UUID 0x21
194 #define PROTEUSE_SET_IDX_RF_SPP_TX_UUID 0x22
195 #define PROTEUSE_SET_IDX_UART_TRANSP_TIMEOUT 0x24
196 #define PROTEUSE_SET_IDX_UART_TRANSP_MAX_PL 0x25
197 
202 #define PROTEUSE_CNF_GET_STATUS_OK 0x00
203 #define PROTEUSE_CNF_GET_STATUS_FAILED 0x01
204 #define PROTEUSE_CNF_GET_STATUS_NOT_PERMITTED 0xFF
205 
210 #define PROTEUSE_CNF_DATA_STATUS_OK 0x00
211 #define PROTEUSE_CNF_DATA_STATUS_FAILED 0x01
212 #define PROTEUSE_CNF_DATA_STATUS_NOT_PERMITTED 0xFF
213 
218 #define PROTEUSE_IND_DISC_REASON_TIMEOUT 0x08
219 #define PROTEUSE_IND_DISC_REASON_USER_TERM 0x13
220 #define PROTEUSE_IND_DISC_REASON_HOST_TERM 0x16
221 #define PROTEUSE_IND_DISC_REASON_CONN_INTERVAL 0x3B
222 #define PROTEUSE_IND_DISC_REASON_MIC_FAILURE 0x3D
223 #define PROTEUSE_IND_DISC_REASON_SETUP_FAILED 0x3E
224 
229 #define PROTEUSE_IND_SEC_STATUS_RE_BONDED 0x00
230 #define PROTEUSE_IND_SEC_STATUS_BONDED 0x01
231 #define PROTEUSE_IND_SEC_STATUS_PAIRED 0x02
232 
237 #define PROTEUSE_RSP_TIMEOUT_1000MS 1000
238 #define PROTEUSE_WAIT_TIME_1S 1
239 
245 #define PROTEUSE_TX_DRV_BUFFER_SIZE 300
246 #define PROTEUSE_RX_DRV_BUFFER_SIZE 300
247 #define PROTEUSE_PAYLOAD_BUFFER_SIZE 256
248  // proteuse_cmd
250 
265 #define PROTEUSE_MAP_MIKROBUS( cfg, mikrobus ) \
266  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
267  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
268  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
269  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
270  // proteuse_map // proteuse
273 
278 typedef struct
279 {
280  uint8_t cmd; // Command code
281  uint8_t payload[ PROTEUSE_PAYLOAD_BUFFER_SIZE ]; // Payload buffer
282  uint8_t payload_len; // Payload length
283 
285 
290 typedef struct
291 {
292  // Output pins
293  digital_out_t en;
294  digital_out_t rst;
296  // Modules
297  uart_t uart;
299  // Buffers
300  uint8_t uart_rx_buffer[ PROTEUSE_RX_DRV_BUFFER_SIZE ];
301  uint8_t uart_tx_buffer[ PROTEUSE_TX_DRV_BUFFER_SIZE ];
303  proteuse_packet_t cmd_pkt; // Command packet structure
304  proteuse_packet_t evt_pkt; // Confirmation/Indication/Response event packet structure
305 
306 } proteuse_t;
307 
312 typedef struct
313 {
314  // Communication gpio pins
315  pin_name_t rx_pin;
316  pin_name_t tx_pin;
318  // Additional gpio pins
319  pin_name_t en;
320  pin_name_t rst;
322  // Static variable
323  uint32_t baud_rate;
325  uart_data_bits_t data_bit;
326  uart_parity_t parity_bit;
327  uart_stop_bits_t stop_bit;
330 
335 typedef enum
336 {
338  PROTEUSE_ERROR = -1
339 
341 
358 
373 
387 
400 err_t proteuse_generic_write ( proteuse_t *ctx, uint8_t *data_in, uint16_t len );
401 
414 err_t proteuse_generic_read ( proteuse_t *ctx, uint8_t *data_out, uint16_t len );
415 
425 void proteuse_set_rst_pin ( proteuse_t *ctx, uint8_t state );
426 
437 
447 void proteuse_set_en_pin ( proteuse_t *ctx, uint8_t state );
448 
458 
468 
482 
495 err_t proteuse_wait_for_event ( proteuse_t *ctx, uint8_t cmd, uint8_t max_time_s );
496 
506 
519 err_t proteuse_set_user_setting ( proteuse_t *ctx, uint8_t set_idx, uint8_t *data_in, uint8_t len );
520 
532 err_t proteuse_get_user_setting ( proteuse_t *ctx, uint8_t set_idx );
533 
534 #ifdef __cplusplus
535 }
536 #endif
537 #endif // PROTEUSE_H
538  // proteuse
540 
541 // ------------------------------------------------------------------------ END
proteuse_cfg_t::rx_pin
pin_name_t rx_pin
Definition: proteuse.h:315
proteuse_t::rst
digital_out_t rst
Definition: proteuse.h:294
proteuse_t::cmd_pkt
proteuse_packet_t cmd_pkt
Definition: proteuse.h:303
PROTEUSE_PAYLOAD_BUFFER_SIZE
#define PROTEUSE_PAYLOAD_BUFFER_SIZE
Definition: proteuse.h:247
proteuse_cfg_t
Proteus-e Click configuration object.
Definition: proteuse.h:313
proteuse_set_user_setting
err_t proteuse_set_user_setting(proteuse_t *ctx, uint8_t set_idx, uint8_t *data_in, uint8_t len)
Proteus-e set user settings function.
proteuse_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: proteuse.h:327
proteuse_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: proteuse.h:326
proteuse_packet_t::cmd
uint8_t cmd
Definition: proteuse.h:280
PROTEUSE_RX_DRV_BUFFER_SIZE
#define PROTEUSE_RX_DRV_BUFFER_SIZE
Definition: proteuse.h:246
proteuse_t::uart
uart_t uart
Definition: proteuse.h:297
proteuse_read_event
err_t proteuse_read_event(proteuse_t *ctx)
Proteus-e read event function.
proteuse_packet_t
Proteus-e Click command packet structure object.
Definition: proteuse.h:279
proteuse_t::en
digital_out_t en
Definition: proteuse.h:293
proteuse_cfg_t::rst
pin_name_t rst
Definition: proteuse.h:320
proteuse_set_rst_pin
void proteuse_set_rst_pin(proteuse_t *ctx, uint8_t state)
Proteus-e set RST pin function.
proteuse_generic_read
err_t proteuse_generic_read(proteuse_t *ctx, uint8_t *data_out, uint16_t len)
Proteus-e data reading function.
proteuse_return_value_t
proteuse_return_value_t
Proteus-e Click return value data.
Definition: proteuse.h:336
proteuse_cfg_t::uart_blocking
bool uart_blocking
Definition: proteuse.h:324
proteuse_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: proteuse.h:325
PROTEUSE_TX_DRV_BUFFER_SIZE
#define PROTEUSE_TX_DRV_BUFFER_SIZE
Proteus-e driver buffer size.
Definition: proteuse.h:245
proteuse_get_user_setting
err_t proteuse_get_user_setting(proteuse_t *ctx, uint8_t set_idx)
Proteus-e get user settings function.
proteuse_t::evt_pkt
proteuse_packet_t evt_pkt
Definition: proteuse.h:304
proteuse_send_cmd
void proteuse_send_cmd(proteuse_t *ctx)
Proteus-e send command function.
proteuse_wait_for_event
err_t proteuse_wait_for_event(proteuse_t *ctx, uint8_t cmd, uint8_t max_time_s)
Proteus-e wait for event function.
proteuse_generic_write
err_t proteuse_generic_write(proteuse_t *ctx, uint8_t *data_in, uint16_t len)
Proteus-e data writing function.
proteuse_cfg_t::tx_pin
pin_name_t tx_pin
Definition: proteuse.h:316
proteuse_enable_uart
void proteuse_enable_uart(proteuse_t *ctx)
Proteus-e enable uart function.
proteuse_clear_buffers
void proteuse_clear_buffers(proteuse_t *ctx)
Proteus-e clear buffers function.
PROTEUSE_ERROR
@ PROTEUSE_ERROR
Definition: proteuse.h:338
proteuse_cfg_t::baud_rate
uint32_t baud_rate
Definition: proteuse.h:323
proteuse_set_en_pin
void proteuse_set_en_pin(proteuse_t *ctx, uint8_t state)
Proteus-e set EN pin function.
proteuse_init
err_t proteuse_init(proteuse_t *ctx, proteuse_cfg_t *cfg)
Proteus-e initialization function.
proteuse_cfg_t::en
pin_name_t en
Definition: proteuse.h:319
proteuse_t
Proteus-e Click context object.
Definition: proteuse.h:291
proteuse_cfg_setup
void proteuse_cfg_setup(proteuse_cfg_t *cfg)
Proteus-e configuration object setup function.
proteuse_default_cfg
err_t proteuse_default_cfg(proteuse_t *ctx)
Proteus-e default configuration function.
proteuse_packet_t::payload_len
uint8_t payload_len
Definition: proteuse.h:282
PROTEUSE_OK
@ PROTEUSE_OK
Definition: proteuse.h:337
proteuse_reset_device
err_t proteuse_reset_device(proteuse_t *ctx)
Proteus-e reset device function.