calypso  2.1.0.0
calypso.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 CALYPSO_H
29 #define CALYPSO_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_i2c_master.h"
52 #include "drv_uart.h"
53 
74 #define CALYPSO_CMD_AT "AT"
75 #define CALYPSO_CMD_AT_START "AT+start"
76 #define CALYPSO_CMD_AT_TEST "AT+test"
77 #define CALYPSO_CMD_AT_REBOOT "AT+reboot"
78 #define CALYPSO_CMD_AT_GET "AT+get"
79 #define CALYPSO_CMD_AT_SET "AT+set"
80 #define CALYPSO_CMD_AT_WLAN_SET_MODE "AT+wlanSetMode"
81 #define CALYPSO_CMD_AT_WLAN_SCAN "AT+wlanScan"
82 #define CALYPSO_CMD_AT_WLAN_CONNECT "AT+wlanConnect"
83 #define CALYPSO_CMD_AT_WLAN_DISCONNECT "AT+wlanDisconnect"
84 #define CALYPSO_CMD_AT_WLAN_PROFILE_ADD "AT+wlanProfileAdd"
85 #define CALYPSO_CMD_AT_WLAN_PROFILE_GET "AT+wlanProfileGet"
86 #define CALYPSO_CMD_AT_WLAN_PROFILE_DEL "AT+wlanProfileDel"
87 #define CALYPSO_CMD_AT_WLAN_SET "AT+wlanSet"
88 #define CALYPSO_CMD_AT_WLAN_GET "AT+wlanGet"
89 #define CALYPSO_CMD_AT_WLAN_POLICY_SET "AT+wlanPolicySet"
90 #define CALYPSO_CMD_AT_WLAN_POLICY_GET "AT+wlanPolicyGet"
91 #define CALYPSO_CMD_AT_NET_CFG_SET "AT+netCfgSet"
92 #define CALYPSO_CMD_AT_NET_CFG_GET "AT+netCfgGet"
93 #define CALYPSO_CMD_AT_SOCKET "AT+socket"
94 #define CALYPSO_CMD_AT_CLOSE "AT+close"
95 #define CALYPSO_CMD_AT_BIND "AT+bind"
96 #define CALYPSO_CMD_AT_LISTEN "AT+listen"
97 #define CALYPSO_CMD_AT_CONNECT "AT+connect"
98 #define CALYPSO_CMD_AT_ACCEPT "AT+accept"
99 #define CALYPSO_CMD_AT_SELECT "AT+select"
100 #define CALYPSO_CMD_AT_SET_SOCK_OPT "AT+setSockOpt"
101 #define CALYPSO_CMD_AT_GET_SOCK_OPT "AT+getSockOpt"
102 #define CALYPSO_CMD_AT_RECV "AT+recv"
103 #define CALYPSO_CMD_AT_RECV_FROM "AT+recvFrom"
104 #define CALYPSO_CMD_AT_SEND "AT+send"
105 #define CALYPSO_CMD_AT_SEND_TO "AT+sendTo"
106 #define CALYPSO_CMD_AT_GPIO_GET "AT+gpioGet"
107 #define CALYPSO_CMD_AT_GPIO_SET "AT+gpioSet"
108 
113 #define CALYPSO_RSP_OK "OK"
114 #define CALYPSO_RSP_ERROR "ERROR"
115 #define CALYPSO_RSP_READY "+eventstartup"
116 #define CALYPSO_RSP_CONNECTED "+eventwlan:connect"
117 
122 #define CALYPSO_APP_MODE_AT_COMMAND 0x00
123 #define CALYPSO_APP_MODE_OTA 0x01
124 #define CALYPSO_APP_MODE_PROVISIONIG 0x02
125 #define CALYPSO_APP_MODE_TRANSPARENT 0x03
126 
131 #define CALYPSO_REG_INPUT_PORT 0x00
132 #define CALYPSO_REG_OUTPUT_PORT 0x01
133 #define CALYPSO_REG_POLARITY_INVERSION 0x02
134 #define CALYPSO_REG_CONFIGURATION 0x03
135 
141 #define CALYPSO_TX_DRV_BUFFER_SIZE 256
142 #define CALYPSO_RX_DRV_BUFFER_SIZE 256
143 
149 #define CALYPSO_PIN_NONE_MASK 0x00
150 #define CALYPSO_PIN_ALL_MASK 0x0F
151 #define CALYPSO_PIN_AP0_MASK 0x01
152 #define CALYPSO_PIN_AP1_MASK 0x02
153 #define CALYPSO_PIN_BOOT_MASK 0x04
154 #define CALYPSO_PIN_RM2_MASK 0x08
155 
160 #define CALYPSO_PIN_STATE_HIGH 0x01
161 #define CALYPSO_PIN_STATE_LOW 0x00
162 
168 #define CALYPSO_DEVICE_ADDRESS 0x41
169  // calypso_cmd
171 
186 #define CALYPSO_MAP_MIKROBUS( cfg, mikrobus ) \
187  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
188  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
189  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
190  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
191  cfg.rm0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
192  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
193  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
194  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
195  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
196  // calypso_map // calypso
199 
204 typedef struct
205 {
206  // Output pins
207  digital_out_t rst;
208  digital_out_t cts;
209  digital_out_t wup;
211  // Input pins
212  digital_in_t rm0;
213  digital_in_t rts;
215  // Modules
216  uart_t uart;
217  i2c_master_t i2c;
219  // Buffers
220  uint8_t uart_rx_buffer[ CALYPSO_RX_DRV_BUFFER_SIZE ];
221  uint8_t uart_tx_buffer[ CALYPSO_TX_DRV_BUFFER_SIZE ];
223  // I2C slave address
224  uint8_t slave_address;
226 } calypso_t;
227 
232 typedef struct
233 {
234  // Communication gpio pins
235  pin_name_t rx_pin;
236  pin_name_t tx_pin;
237  pin_name_t scl;
238  pin_name_t sda;
240  // Additional gpio pins
241  pin_name_t rm0;
242  pin_name_t rst;
243  pin_name_t cts;
244  pin_name_t wup;
245  pin_name_t rts;
247  // Static variable
248  uint32_t baud_rate;
250  uart_data_bits_t data_bit;
251  uart_parity_t parity_bit;
252  uart_stop_bits_t stop_bit;
253  uint32_t i2c_speed;
254  uint8_t i2c_address;
256 } calypso_cfg_t;
257 
262 typedef enum
263 {
269 
271 
288 
302 err_t calypso_init ( calypso_t *ctx, calypso_cfg_t *cfg );
303 
317 
330 err_t calypso_generic_write ( calypso_t *ctx, uint8_t *data_in, uint16_t len );
331 
344 err_t calypso_generic_read ( calypso_t *ctx, uint8_t *data_out, uint16_t len );
345 
358 err_t calypso_port_expander_write ( calypso_t *ctx, uint8_t reg, uint8_t data_in );
359 
372 err_t calypso_port_expander_read ( calypso_t *ctx, uint8_t reg, uint8_t *data_out );
373 
386 err_t calypso_set_pins ( calypso_t *ctx, uint8_t set_mask, uint8_t clr_mask );
387 
400 err_t calypso_set_app_mode ( calypso_t *ctx, uint8_t mode_sel );
401 
411 void calypso_set_rst_pin ( calypso_t *ctx, uint8_t pin_state );
412 
422 void calypso_set_cts_pin ( calypso_t *ctx, uint8_t pin_state );
423 
433 void calypso_set_wup_pin ( calypso_t *ctx, uint8_t pin_state );
434 
444 
454 
464 
474 void calypso_send_cmd ( calypso_t *ctx, uint8_t *at_cmd_buf );
475 
486 void calypso_send_cmd_with_par ( calypso_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
487 
497 void calypso_send_cmd_check ( calypso_t *ctx, uint8_t *at_cmd_buf );
498 
499 #ifdef __cplusplus
500 }
501 #endif
502 #endif // CALYPSO_H
503  // calypso
505 
506 // ------------------------------------------------------------------------ END
calypso_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: calypso.h:250
calypso_t::rm0
digital_in_t rm0
Definition: calypso.h:212
calypso_set_pins
err_t calypso_set_pins(calypso_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Calypso set port expander pin function.
calypso_cfg_setup
void calypso_cfg_setup(calypso_cfg_t *cfg)
Calypso configuration object setup function.
calypso_send_cmd
void calypso_send_cmd(calypso_t *ctx, uint8_t *at_cmd_buf)
Calypso send command function.
calypso_port_expander_read
err_t calypso_port_expander_read(calypso_t *ctx, uint8_t reg, uint8_t *data_out)
Calypso port expander data reading function.
calypso_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: calypso.h:251
calypso_t::rst
digital_out_t rst
Definition: calypso.h:207
calypso_port_expander_write
err_t calypso_port_expander_write(calypso_t *ctx, uint8_t reg, uint8_t data_in)
Calypso port expander data writing function.
CALYPSO_ERROR
@ CALYPSO_ERROR
Definition: calypso.h:265
calypso_hw_reset
void calypso_hw_reset(calypso_t *ctx)
Calypso HW reset function.
calypso_t::cts
digital_out_t cts
Definition: calypso.h:208
calypso_t::rts
digital_in_t rts
Definition: calypso.h:213
calypso_cfg_t::wup
pin_name_t wup
Definition: calypso.h:244
calypso_cfg_t::baud_rate
uint32_t baud_rate
Definition: calypso.h:248
calypso_cfg_t
Calypso Click configuration object.
Definition: calypso.h:233
calypso_generic_read
err_t calypso_generic_read(calypso_t *ctx, uint8_t *data_out, uint16_t len)
Calypso data reading function.
calypso_cfg_t::uart_blocking
bool uart_blocking
Definition: calypso.h:249
calypso_t::uart
uart_t uart
Definition: calypso.h:216
calypso_set_cts_pin
void calypso_set_cts_pin(calypso_t *ctx, uint8_t pin_state)
Calypso set CTS pin function.
calypso_cfg_t::scl
pin_name_t scl
Definition: calypso.h:237
calypso_cfg_t::cts
pin_name_t cts
Definition: calypso.h:243
calypso_cfg_t::rx_pin
pin_name_t rx_pin
Definition: calypso.h:235
calypso_get_rts_pin
uint8_t calypso_get_rts_pin(calypso_t *ctx)
Calypso get RTS pin state function.
calypso_t
Calypso Click context object.
Definition: calypso.h:205
CALYPSO_ERROR_CMD
@ CALYPSO_ERROR_CMD
Definition: calypso.h:267
CALYPSO_RX_DRV_BUFFER_SIZE
#define CALYPSO_RX_DRV_BUFFER_SIZE
Definition: calypso.h:142
calypso_cfg_t::rts
pin_name_t rts
Definition: calypso.h:245
calypso_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: calypso.h:252
calypso_t::wup
digital_out_t wup
Definition: calypso.h:209
calypso_cfg_t::rst
pin_name_t rst
Definition: calypso.h:242
calypso_set_app_mode
err_t calypso_set_app_mode(calypso_t *ctx, uint8_t mode_sel)
Calypso set app mode function.
calypso_cfg_t::i2c_address
uint8_t i2c_address
Definition: calypso.h:254
calypso_send_cmd_check
void calypso_send_cmd_check(calypso_t *ctx, uint8_t *at_cmd_buf)
Calypso send command check function.
calypso_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: calypso.h:253
calypso_cfg_t::tx_pin
pin_name_t tx_pin
Definition: calypso.h:236
CALYPSO_ERROR_UNKNOWN
@ CALYPSO_ERROR_UNKNOWN
Definition: calypso.h:268
calypso_send_cmd_with_par
void calypso_send_cmd_with_par(calypso_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Calypso send command with parameter function.
calypso_t::i2c
i2c_master_t i2c
Definition: calypso.h:217
CALYPSO_ERROR_TIMEOUT
@ CALYPSO_ERROR_TIMEOUT
Definition: calypso.h:266
calypso_cfg_t::rm0
pin_name_t rm0
Definition: calypso.h:241
CALYPSO_TX_DRV_BUFFER_SIZE
#define CALYPSO_TX_DRV_BUFFER_SIZE
Calypso driver buffer size.
Definition: calypso.h:141
CALYPSO_OK
@ CALYPSO_OK
Definition: calypso.h:264
calypso_default_cfg
err_t calypso_default_cfg(calypso_t *ctx)
Calypso default configuration function.
calypso_t::slave_address
uint8_t slave_address
Definition: calypso.h:224
calypso_get_rm0_pin
uint8_t calypso_get_rm0_pin(calypso_t *ctx)
Calypso get RM0 pin state function.
calypso_cfg_t::sda
pin_name_t sda
Definition: calypso.h:238
calypso_init
err_t calypso_init(calypso_t *ctx, calypso_cfg_t *cfg)
Calypso initialization function.
calypso_return_value_t
calypso_return_value_t
Calypso Click return value data.
Definition: calypso.h:263
calypso_set_wup_pin
void calypso_set_wup_pin(calypso_t *ctx, uint8_t pin_state)
Calypso set WUP pin function.
calypso_set_rst_pin
void calypso_set_rst_pin(calypso_t *ctx, uint8_t pin_state)
Calypso set RST pin function.
calypso_generic_write
err_t calypso_generic_write(calypso_t *ctx, uint8_t *data_in, uint16_t len)
Calypso data writing function.