/
supla_esp.h
217 lines (162 loc) · 5.11 KB
/
supla_esp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef SUPLA_ESP_H_
#define SUPLA_ESP_H_
#define MEMLEAK_DEBUG
#include "supla-dev/proto.h"
#include "board/supla_esp_board.h"
#include "espmissingincludes.h"
#define SUPLA_ESP_SOFTVER "2.7.0"
#define LO_VALUE 0
#define HI_VALUE 1
#define RELAY_INIT_VALUE LO_VALUE
#define SAVE_STATE_DELAY 1000
#ifndef CFG_BTN_PRESS_TIME
#define CFG_BTN_PRESS_TIME 5000
#endif /*CFG_BTN_PRESS_TIME*/
#ifndef GET_CFG_PRESS_TIME
#define GET_CFG_PRESS_TIME supla_esp_gpio_get_cfg_press_time
#endif /*GET_CFG_PRESS_TIME*/
#ifndef INPUT_MAX_COUNT
#define INPUT_MAX_COUNT 7
#endif /*INPUT_MAX_COUNT*/
#ifndef RELAY_MAX_COUNT
#define RELAY_MAX_COUNT 4
#endif /*RELAY_MAX_COUNT*/
#ifndef RS_MAX_COUNT
#define RS_MAX_COUNT 2
#endif /*RS_MAX_COUNT*/
#ifndef CFG_TIME1_COUNT
#define CFG_TIME1_COUNT 2
#endif /*CFG_TIME1_COUNT*/
#ifndef CFG_TIME2_COUNT
#define CFG_TIME2_COUNT 2
#endif /*CFG_TIME2_COUNT*/
#ifndef SMOOTH_MAX_COUNT
#define SMOOTH_MAX_COUNT 1
#endif /*SMOOTH_MAX_COUNT*/
#define INPUT_FLAG_PULLUP 0x01
#define INPUT_FLAG_CFG_BTN 0x02
#define INPUT_FLAG_FACTORY_RESET 0x04
#define INPUT_FLAG_DISABLE_INTR 0x08
#define INPUT_TYPE_SENSOR 1
#define INPUT_TYPE_BTN_MONOSTABLE 2
#define INPUT_TYPE_BTN_MONOSTABLE_RS 3
#define INPUT_TYPE_BTN_BISTABLE 4
#define INPUT_TYPE_BTN_BISTABLE_RS 5
#define INPUT_TYPE_CUSTOM 200
// milliseconds
#ifndef RS_START_DELAY
#define RS_START_DELAY 1000
#endif
// milliseconds
#ifndef RS_STOP_DELAY
#define RS_STOP_DELAY 500
#endif
// microseconds
#ifndef RELAY_MIN_DELAY
#define RELAY_MIN_DELAY 100000
#endif
#ifndef MAIN_ICACHE_FLASH
#define MAIN_ICACHE_FLASH ICACHE_FLASH_ATTR
#endif
#ifndef GPIO_ICACHE_FLASH
#define GPIO_ICACHE_FLASH ICACHE_FLASH_ATTR
#endif
#ifndef DEVCONN_ICACHE_FLASH
#define DEVCONN_ICACHE_FLASH ICACHE_FLASH_ATTR
#endif
#ifndef CFG_ICACHE_FLASH_ATTR
#define CFG_ICACHE_FLASH_ATTR ICACHE_FLASH_ATTR
#endif
#ifndef DHT_ICACHE_FLASH
#define DHT_ICACHE_FLASH ICACHE_FLASH_ATTR
#endif
#ifndef BTN1_DEFAULT
#define BTN1_DEFAULT BTN_TYPE_MONOSTABLE
#endif
#ifndef BTN2_DEFAULT
#define BTN2_DEFAULT BTN_TYPE_BISTABLE
#endif
void supla_esp_board_set_device_name(char *buffer, uint8 buffer_size);
void supla_esp_board_set_channels(TDS_SuplaDeviceChannel_B *channels, unsigned char *channel_count);
void supla_esp_board_relay_before_change_state(void);
void supla_esp_board_relay_after_change_state(void);
void supla_esp_board_gpio_init(void);
#ifdef __FOTA
#define RSA_NUM_BYTES 512
#define RSA_PUBLIC_EXPONENT 65537
extern const uint8_t rsa_public_key_bytes[RSA_NUM_BYTES];
#endif
#ifndef GPIO_PORT_INIT
#define GPIO_PORT_INIT \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4); \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5); \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); \
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14)
#endif
// PWM ----------------------------------
#ifndef PWM_0_OUT_IO_MUX
#define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_GPIO4_U
#define PWM_0_OUT_IO_NUM 4
#define PWM_0_OUT_IO_FUNC FUNC_GPIO4
#endif
#ifndef PWM_1_OUT_IO_MUX
#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U
#define PWM_1_OUT_IO_NUM 5
#define PWM_1_OUT_IO_FUNC FUNC_GPIO5
#endif
#ifndef PWM_2_OUT_IO_MUX
#define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U
#define PWM_2_OUT_IO_NUM 12
#define PWM_2_OUT_IO_FUNC FUNC_GPIO12
#endif
#ifndef PWM_3_OUT_IO_MUX
#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U
#define PWM_3_OUT_IO_NUM 13
#define PWM_3_OUT_IO_FUNC FUNC_GPIO13
#endif
#ifndef PWM_4_OUT_IO_MUX
#define PWM_4_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U
#define PWM_4_OUT_IO_NUM 14
#define PWM_4_OUT_IO_FUNC FUNC_GPIO14
#endif
#ifndef PWM_PERIOD
#define PWM_PERIOD 1000
#endif
// --------------------------------------
#ifndef AP_SSID
#ifdef ESP8285
#define AP_SSID "SUPLA-ESP8285"
#else
#define AP_SSID "SUPLA-ESP8266"
#endif
#endif
#define SPI_FLASH_SEC_SIZE 4096
#define SERVER_MAXSIZE 100
#define WIFI_SSID_MAXSIZE 32
#define WIFI_PWD_MAXSIZE 64
#define STATE_MAXSIZE 200
#define RECVBUFF_MAXSIZE 1024
#define ACTIVITY_TIMEOUT 10
#ifndef WATCHDOG_TIMEOUT
#define WATCHDOG_TIMEOUT 60000000
#endif /*WATCHDOG_TIMEOUT*/
#ifndef RELAY_DOUBLE_TRY
#define RELAY_DOUBLE_TRY 10000
#endif
#endif /* SUPLA_ESP_H_ */