Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
devboard_click.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * CLICK sensor interface for devboard
30 */
31 
32 #ifndef DEVBOARD_CLICK_H
33 #define DEVBOARD_CLICK_H
34 
35 #include "ca821x_error.h"
36 
37 /* devboard comms interface configuration */
38 #define I2C_PORTNUM 1 // CLICK interface port for I2C
39 #define SPI_PORTNUM 1 // CLICK interface port for SPI
40 
41 /* 36 hours (24-bit @ 1 sec / 128) */
42 #define DVBD_MAX_SLEEP_TIME 0x07B98A00
43 
44 /* number of mikrobus CLICK interfaces on devboard */
45 #define DVBD_NUM_MIKROBUS 2
46 
47 /* power-down of click sensors when power control (crowbar) is used */
48 #define DVBD_CLICK_POWER_ON 0
49 #define DVBD_CLICK_POWER_OFF 1
50 
51 /* power ocntrol pin for crowbar is on pin 12 */
52 #define DVBD_CLICK_POWER_PIN 12
53 
54 /* devboard pin assignments (chili2 pins) for mikrobus click interface */
55 #define CLICK_AN_PIN 36
56 #define CLICK_RST_PIN 6
57 #define CLICK_CS_PIN 34
58 #define CLICK_SCK_PIN 33
59 #define CLICK_MISO_PIN 32
60 #define CLICK_MOSI_PIN 31
61 #define CLICK_PWM_PIN 35
62 #define CLICK_INT_PIN 5
63 // Tx (UART) not connected
64 // Rx (UART) not connected
65 #define CLICK_SCL_PIN 2
66 #define CLICK_SDA_PIN 4
67 
68 typedef enum dvbd_click_type
69 {
75  STYPE_SHT = 5,
80  STYPE_FAN = 10,
83 
84 /* structures for click sensor data */
85 
86 /* data structure for THERMO */
87 typedef struct
88 {
89  uint8_t status; // airquality4_status
90  uint16_t thermocouple_temperature; // T['C] = compl(uint16_t / 4)
91  uint16_t junction_temperature; // T['C] = compl(uint16_t / 16)
92 } data_thermo;
93 
94 /* data structure for THERMO3 */
95 typedef struct
96 {
97  uint8_t status; // thermo3_status
98  uint16_t temperature; // T['C] = compl(uint16_t / 16)
99 } data_thermo3;
100 
101 /* data structure for AIRQUALITY4 */
102 typedef struct
103 {
104  uint8_t status; // airquality4_status
105  uint16_t co2_h2; // AIRQUALITY4_MEASURE_RAW_SIGNALS = 0: CO2 [ppm];
106  // AIRQUALITY4_MEASURE_RAW_SIGNALS = 1: H2 (raw value)
107  uint16_t tvoc_eth; // AIRQUALITY4_MEASURE_RAW_SIGNALS = 0: TVOC [ppb]
108  // AIRQUALITY4_MEASURE_RAW_SIGNALS = 1: ETH (raw value)
110 
111 /* data structure for ENVIRONMENT2 */
112 typedef struct
113 {
114  uint8_t status; // environment2_status
115  int16_t humidity; // RH[%] = int16_t / 100
116  int16_t temperature; // T['C] = int16_t / 100
117  uint16_t air_quality; // [0-65535] (raw value)
118  int32_t voc_index; // [0-500]
120 
121 /* data structure for SHT */
122 typedef struct
123 {
124  uint8_t status; // environment2_status
125  int16_t humidity; // RH[%] = int16_t / 100
126  int16_t temperature; // T['C] = int16_t / 100
127 } data_sht;
128 
129 /* data structure for HVAC */
130 typedef struct
131 {
132  uint8_t status; // hvac_status
133  uint16_t co2content; // CO2 [ppm] (0-40000 ppm)
134  int16_t humidity; // RH[%] = int16_t / 100
135  int16_t temperature; // T['C] = int16_t / 100
136 } data_hvac;
137 
138 /* data structure for MOTION */
139 typedef struct
140 {
141  uint8_t status; // motion_status
142  uint8_t detection_state; // motion_detect_state_changes_t
143  uint32_t detection_time; // Motion Detected Time [ms] (only used if MOTION_USE_INTERRUPT=1, otherwise 0)
144 } data_motion;
145 
146 /* data structure for RELAY */
147 typedef struct
148 {
149  uint8_t status; // relay_status
150  uint8_t relay_1_state; // relay_state for relay 1 (RELAY_OFF / RELAY_ON)
151  uint8_t relay_2_state; // relay_state for relay 2 (RELAY_OFF / RELAY_ON)
152 } data_relay;
153 
154 /* data structure for AMBIENT8 */
155 typedef struct
156 {
157  uint8_t status; // ambient8_status
158  uint32_t illuminance_ch0; // Ev[lux] = uint32_t / 100, channel 0 (VIS+IR), max sensitivity @ 470 nm
159  uint32_t illuminance_ch1; // Ev[lux] = uint32_t / 100, channel 1 (IR), max sensitivity @ 770 nm
160  uint32_t illuminance_ambient; // Ev[lux] = uint32_t / 100, ambient level, calculated
161 } data_ambient8;
162 
163 /* data structure for FAN */
164 typedef struct
165 {
166  uint8_t status; // ambient8_status
167  uint8_t speed_pwm_percent; // speed, 0-100% (pwm equivalent)
168  uint16_t speed_tach_rpm; // speed, rpm (tachometer)
169 } data_fan;
170 
171 
172 /* data structure for EXPAND13 */
173 typedef struct
174 {
175  uint8_t status; // expand13_status
176  uint8_t port0; // port0 value
177 } data_expand13;
178 
179 /* globals */
180 extern uint8_t g_relay_1_state, g_relay_2_state; /* states for controlling RELAY */
181 extern uint8_t g_fan_speed_pwm_percent; /* fan speed pwm percent */
182 extern uint16_t g_fan_speed_tach_rpm; /* fan speed rpm tachometer */
183 
184 /* general functions */
186 ca_error DVBD_click_power_set(uint8_t onoff);
187 
188 /* data acquisition functions */
200 
201 /* separate initialisation functions */
213 
214 #endif // DEVBOARD_CLICK_H
Global error declarations for use across the Cascoda SDK.
ca_error CLICK_MOTION_acquisition(data_motion *data)
Definition: devboard_click.c:214
ca_error CLICK_EXPAND13_acquisition(data_expand13 *data)
Definition: devboard_click.c:281
ca_error CLICK_FAN_acquisition(data_fan *data)
Definition: devboard_click.c:267
ca_error CLICK_RELAY_initialise(void)
Definition: devboard_click.c:368
ca_error CLICK_HVAC_acquisition(data_hvac *data)
Definition: devboard_click.c:192
uint8_t g_fan_speed_pwm_percent
Definition: devboard_click.c:62
ca_error CLICK_AIRQUALITY4_initialise(void)
Definition: devboard_click.c:314
ca_error CLICK_ENVIRONMENT2_acquisition(data_environment2 *data)
Definition: devboard_click.c:151
ca_error CLICK_AIRQUALITY4_acquisition(data_airquality4 *data)
Definition: devboard_click.c:133
ca_error CLICK_AMBIENT8_acquisition(data_ambient8 *data)
Definition: devboard_click.c:248
ca_error CLICK_RELAY_acquisition(data_relay *data)
Definition: devboard_click.c:236
ca_error CLICK_ENVIRONMENT2_initialise(void)
Definition: devboard_click.c:323
ca_error DVBD_click_power_set(uint8_t onoff)
Definition: devboard_click.c:87
uint16_t g_fan_speed_tach_rpm
Definition: devboard_click.c:63
ca_error CLICK_EXPAND13_initialise(void)
Definition: devboard_click.c:402
ca_error CLICK_MOTION_initialise(void)
Definition: devboard_click.c:355
dvbd_click_type
Definition: devboard_click.h:69
@ STYPE_SHT
Definition: devboard_click.h:75
@ STYPE_AMBIENT8
Definition: devboard_click.h:79
@ STYPE_ENVIRONMENT2
Definition: devboard_click.h:74
@ STYPE_EXPAND13
Definition: devboard_click.h:81
@ STYPE_THERMO
Definition: devboard_click.h:71
@ STYPE_HVAC
Definition: devboard_click.h:76
@ STYPE_AIRQUALITY4
Definition: devboard_click.h:73
@ STYPE_FAN
Definition: devboard_click.h:80
@ STYPE_RELAY
Definition: devboard_click.h:78
@ STYPE_MOTION
Definition: devboard_click.h:77
@ STYPE_NONE
Definition: devboard_click.h:70
@ STYPE_THERMO3
Definition: devboard_click.h:72
uint8_t g_relay_2_state
Definition: devboard_click.h:180
ca_error CLICK_AMBIENT8_initialise(void)
Definition: devboard_click.c:378
ca_error CLICK_THERMO3_initialise(void)
Definition: devboard_click.c:291
ca_error CLICK_HVAC_initialise(void)
Definition: devboard_click.c:346
ca_error CLICK_THERMO_acquisition(data_thermo *data)
Definition: devboard_click.c:93
uint8_t g_relay_1_state
Definition: devboard_click.c:59
ca_error CLICK_THERMO3_acquisition(data_thermo3 *data)
Definition: devboard_click.c:111
ca_error CLICK_FAN_initialise(void)
Definition: devboard_click.c:387
ca_error CLICK_SHT_initialise(void)
Definition: devboard_click.c:332
ca_error DVBD_click_power_init(void)
Definition: devboard_click.c:69
ca_error CLICK_THERMO_initialise(void)
Definition: devboard_click.c:305
ca_error CLICK_SHT_acquisition(data_sht *data)
Definition: devboard_click.c:170
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
Definition: devboard_click.h:103
uint8_t status
Definition: devboard_click.h:104
uint16_t tvoc_eth
Definition: devboard_click.h:107
uint16_t co2_h2
Definition: devboard_click.h:105
Definition: devboard_click.h:156
uint8_t status
Definition: devboard_click.h:157
uint32_t illuminance_ch1
Definition: devboard_click.h:159
uint32_t illuminance_ch0
Definition: devboard_click.h:158
uint32_t illuminance_ambient
Definition: devboard_click.h:160
Definition: devboard_click.h:113
uint16_t air_quality
Definition: devboard_click.h:117
uint8_t status
Definition: devboard_click.h:114
int32_t voc_index
Definition: devboard_click.h:118
int16_t temperature
Definition: devboard_click.h:116
int16_t humidity
Definition: devboard_click.h:115
Definition: devboard_click.h:174
uint8_t status
Definition: devboard_click.h:175
uint8_t port0
Definition: devboard_click.h:176
Definition: devboard_click.h:165
uint8_t speed_pwm_percent
Definition: devboard_click.h:167
uint16_t speed_tach_rpm
Definition: devboard_click.h:168
uint8_t status
Definition: devboard_click.h:166
Definition: devboard_click.h:131
uint8_t status
Definition: devboard_click.h:132
uint16_t co2content
Definition: devboard_click.h:133
int16_t humidity
Definition: devboard_click.h:134
int16_t temperature
Definition: devboard_click.h:135
Definition: devboard_click.h:140
uint8_t detection_state
Definition: devboard_click.h:142
uint8_t status
Definition: devboard_click.h:141
uint32_t detection_time
Definition: devboard_click.h:143
Definition: devboard_click.h:148
uint8_t relay_2_state
Definition: devboard_click.h:151
uint8_t status
Definition: devboard_click.h:149
uint8_t relay_1_state
Definition: devboard_click.h:150
Definition: devboard_click.h:123
int16_t humidity
Definition: devboard_click.h:125
int16_t temperature
Definition: devboard_click.h:126
uint8_t status
Definition: devboard_click.h:124
Definition: devboard_click.h:96
uint8_t status
Definition: devboard_click.h:97
uint16_t temperature
Definition: devboard_click.h:98
Definition: devboard_click.h:88
uint8_t status
Definition: devboard_click.h:89
uint16_t junction_temperature
Definition: devboard_click.h:91
uint16_t thermocouple_temperature
Definition: devboard_click.h:90