spirit2 2.0.0.0
spirit2.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 SPIRIT2_H
29#define SPIRIT2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
39// -------------------------------------------------------------- PUBLIC MACROS
49#define SPIRIT2_MAP_MIKROBUS( cfg, mikrobus ) \
50 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
51 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
52 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
53 cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_CS ); \
54 cfg.shd = MIKROBUS( mikrobus, MIKROBUS_PWM )
61#define SPIRIT2_MODULE_POWER_ON 1
62#define SPIRIT2_MODULE_POWER_OFF 0
69#define DRV_RX_BUFFER_SIZE 500
70#define DRV_TX_BUFFER_SIZE 200
77#define SPIRIT2_OPERATING_MODE 0x01
78#define SPIRIT2_COMMAND_MODE 0x00
79
80#define SPIRIT2_MODULE_WAKE_UP 0x01
81#define SPIRIT2_MODULE_SHUTDOWN 0x00
88#define SPIRIT2_CMD_ENTER_COMMAND_MODE "+++"
89#define SPIRIT2_CMD_ENTER_OPERATING_MODE "ATO"
90#define SPIRIT2_CMD_READ_MODULE_VERSION "AT/V"
91#define SPIRIT2_CMD_READ_ALL_CONFIG_REG "AT/S"
92#define SPIRIT2_CMD_STORE_CURRENT_CONFIG "AT/C"
93#define SPIRIT2_CMD_RESET_CONFIG "ATR"
94#define SPIRIT2_CMD_RESET_MODULE "ATZ"
101#define SPIRIT2_CMD_READ_INFO_PER "ATI0"
102#define SPIRIT2_CMD_READ_INFO_PSSI "ATI1"
103#define SPIRIT2_CMD_READ_INFO_LQI "ATI2"
104#define SPIRIT2_CMD_READ_INFO_PQI "ATI3"
105#define SPIRIT2_CMD_READ_INFO_SQI "ATI4"
106#define SPIRIT2_CMD_READ_INFO_PACKET_COUNT "ATI5"
107#define SPIRIT2_CMD_READ_INFO_PACKETS_LOST "ATI6"
114#define SPIRIT2_CMD_CFG_BAUD_RATE "ATS00"
115#define SPIRIT2_CMD_CFG_FREQUENCY "ATS01"
116#define SPIRIT2_CMD_CFG_DATA_RATE "ATS02"
117#define SPIRIT2_CMD_CFG_MODULATION "ATS03"
118#define SPIRIT2_CMD_CFG_OUTPUT_POWER "ATS04"
119#define SPIRIT2_CMD_CFG_FREQ_DEVIATION "ATS05"
120#define SPIRIT2_CMD_CFG_RX_FILTER "ATS06"
121#define SPIRIT2_CMD_CFG_CS_MODE "ATS07"
122#define SPIRIT2_CMD_CFG_RSSI_THRESHOLD "ATS08"
123#define SPIRIT2_CMD_CFG_PREAMBLE_LEN "ATS09"
124#define SPIRIT2_CMD_CFG_SYNC_LENGTH "ATS10"
125#define SPIRIT2_CMD_CFG_SYNC_VALUE "ATS11"
126#define SPIRIT2_CMD_CFG_CRC_MODE "ATS12"
127#define SPIRIT2_CMD_CFG_WHITENING "ATS13"
128#define SPIRIT2_CMD_CFG_FEC "ATS14"
129#define SPIRIT2_CMD_CFG_SOURCE_ADDR "ATS15"
130#define SPIRIT2_CMD_CFG_DESTINATION_ADDR "ATS16"
131#define SPIRIT2_CMD_CFG_MULTICAST_ADDR "ATS17"
132#define SPIRIT2_CMD_CFG_BROADCAST_ADDR "ATS18"
133#define SPIRIT2_CMD_CFG_FILTER_CRC "ATS19"
134#define SPIRIT2_CMD_CFG_FILTER_SOURCE "ATS20"
135#define SPIRIT2_CMD_CFG_FILTER_DESTINATION "ATS21"
136#define SPIRIT2_CMD_CFG_FILTER_MULTICAST "ATS22"
137#define SPIRIT2_CMD_CFG_FILTER_BROADCAST "ATS23"
138#define SPIRIT2_CMD_CFG_TXRX_LED "ATS24"
139#define SPIRIT2_CMD_CFG_ESCAPE_SEQ "ATS26"
140#define SPIRIT2_CMD_CFG_SOURCE_FILT_MASK "ATS27"
141#define SPIRIT2_CMD_CFG_PAYLOAD_SIZE "ATS28"
148#define SPIRIT2_PCFG_ENABLE "1"
149#define SPIRIT2_PCFG_DISABLE "0"
156#define SPIRIT2_PCFG_BAUD_RATE_9600 "9600"
157#define SPIRIT2_PCFG_BAUD_RATE_19200 "19200"
158#define SPIRIT2_PCFG_BAUD_RATE_38400 "38400"
159#define SPIRIT2_PCFG_BAUD_RATE_56000 "56000"
160#define SPIRIT2_PCFG_BAUD_RATE_57600 "57600"
161#define SPIRIT2_PCFG_BAUD_RATE_115200 "115200"
162#define SPIRIT2_PCFG_BAUD_RATE_128000 "128000"
163#define SPIRIT2_PCFG_BAUD_RATE_256000 "256000"
170#define SPIRIT2_PCFG_CSMODE_STATIC_SENSING "0"
171#define SPIRIT2_PCFG_CSMODE_DYNAMIC_SENSING_6dB "1"
172#define SPIRIT2_PCFG_CSMODE_DYNAMIC_SENSING_12dB "2"
173#define SPIRIT2_PCFG_CSMODE_DYNAMIC_SENSING_18dB "3"
180#define SPIRIT2_PCFG_CRCMODE_POLY_0x07 "1"
181#define SPIRIT2_PCFG_CRCMODE_POLY_0x8005 "2"
182#define SPIRIT2_PCFG_CRCMODE_POLY_0x1021 "3"
183#define SPIRIT2_PCFG_CRCMODE_POLY_0x864CFB "4"
190#define SPIRIT2_PCFG_TXRXLED_DISABLED "0"
191#define SPIRIT2_PCFG_TXRXLED_OPEN_DRAIN "1"
192#define SPIRIT2_PCFG_TXRXLED_PUSH_PULL "2"
199#define SPIRIT2_PCFG_MODULATION_2_FSK "0"
200#define SPIRIT2_PCFG_MODULATION_GFSK05 "1"
201#define SPIRIT2_PCFG_MODULATION_GFSK1 "2"
202#define SPIRIT2_PCFG_MODULATION_GMSK "3"
203#define SPIRIT2_PCFG_MODULATION_OOK "4"
204#define SPIRIT2_PCFG_MODULATION_ASK "5"
211#define SPIRIT2_CMD_SET_RF_TEST_MODE_DISABLE "AT/T0"
212#define SPIRIT2_CMD_SET_RF_TEST_MODE_PN9 "AT/T1"
213#define SPIRIT2_CMD_SET_RF_TEST_MODE_CW "AT/T2"
220typedef struct
221{
222 // Output pins
223 digital_out_t rst;
224 digital_out_t cmd;
225 digital_out_t shd;
227 // Modules
228 uart_t uart;
230 // Buffers
231 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
232 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
234} spirit2_t;
235
240typedef struct
241{
242 // Communication gpio pins
243
244 pin_name_t rx_pin;
245 pin_name_t tx_pin;
247 // Additional gpio pins
248
249 pin_name_t rst;
250 pin_name_t cmd;
251 pin_name_t shd;
253 // Static variable
254
255 uint32_t baud_rate;
257 uart_data_bits_t data_bit;
258 uart_parity_t parity_bit;
259 uart_stop_bits_t stop_bit;
262
267typedef enum
268{
270 SPIRIT2_ERROR = -1
271
273
290
306
315void spirit2_power_module ( spirit2_t *ctx, uint8_t power_state );
316
325
334void spirit2_set_mode ( spirit2_t *ctx, uint8_t mode );
335
349void spirit2_generic_write ( spirit2_t *ctx, char *data_buf, uint16_t len );
350
364int32_t spirit2_generic_read ( spirit2_t *ctx, char *data_buf, uint16_t max_len );
365
375void spirit2_send_cmd ( spirit2_t *ctx, char *cmd );
376
387void spirit2_send_cmd_with_parameter ( spirit2_t *ctx, char *at_cmd_buf, char *param_buf );
388
398void spirit2_send_cmd_check ( spirit2_t *ctx, char *at_cmd_buf );
399
409void spirit2_send_cmd_parameter_check ( spirit2_t *ctx, char *at_cmd_buf );
410
411#ifdef __cplusplus
412}
413#endif
414#endif // SPIRIT2_H
415 // spirit2
417
418// ------------------------------------------------------------------------ END
#define DRV_RX_BUFFER_SIZE
Definition: spirit2.h:69
#define DRV_TX_BUFFER_SIZE
Definition: spirit2.h:70
uint32_t baud_rate
Definition: spirit2.h:255
digital_out_t cmd
Definition: spirit2.h:224
spirit2_return_value_t
SPIRIT 2 Click return value data.
Definition: spirit2.h:268
bool uart_blocking
Definition: spirit2.h:256
pin_name_t cmd
Definition: spirit2.h:250
uart_data_bits_t data_bit
Definition: spirit2.h:257
uart_t uart
Definition: spirit2.h:228
pin_name_t tx_pin
Definition: spirit2.h:245
pin_name_t rx_pin
Definition: spirit2.h:244
pin_name_t shd
Definition: spirit2.h:251
digital_out_t rst
Definition: spirit2.h:223
uart_stop_bits_t stop_bit
Definition: spirit2.h:259
uart_parity_t parity_bit
Definition: spirit2.h:258
pin_name_t rst
Definition: spirit2.h:249
digital_out_t shd
Definition: spirit2.h:225
@ SPIRIT2_OK
Definition: spirit2.h:269
@ SPIRIT2_ERROR
Definition: spirit2.h:270
void spirit2_send_cmd_parameter_check(spirit2_t *ctx, char *at_cmd_buf)
Check the command parameters.
void spirit2_send_cmd_with_parameter(spirit2_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void spirit2_cfg_setup(spirit2_cfg_t *cfg)
SPIRIT 2 configuration object setup function.
void spirit2_generic_write(spirit2_t *ctx, char *data_buf, uint16_t len)
SPIRIT 2 data writing function.
void spirit2_reset(spirit2_t *ctx)
Software reset function.
int32_t spirit2_generic_read(spirit2_t *ctx, char *data_buf, uint16_t max_len)
SPIRIT 2 data reading function.
void spirit2_send_cmd(spirit2_t *ctx, char *cmd)
Send command function.
err_t spirit2_init(spirit2_t *ctx, spirit2_cfg_t *cfg)
SPIRIT 2 initialization function.
void spirit2_power_module(spirit2_t *ctx, uint8_t power_state)
Power module function.
void spirit2_set_mode(spirit2_t *ctx, uint8_t mode)
Set mode function.
void spirit2_send_cmd_check(spirit2_t *ctx, char *at_cmd_buf)
Check the sent command.
SPIRIT 2 Click configuration object.
Definition: spirit2.h:241
SPIRIT 2 Click context object.
Definition: spirit2.h:221