defines.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #pragma once
  2. #ifndef defines_h
  3. #define defines_h
  4. /////////////////////////////////////////////
  5. //// Global definitions ////
  6. /////////////////////////////////////////////
  7. //********* debug options : *************
  8. //can be set in platformio with -D OPTION_TO_ACTIVATE
  9. //#define DEBUG_DETAIL_ON
  10. //#define DEBUG_DISABLE_BROWNOUT_DETECTOR
  11. //#define DEBUG_ENABLE_SYSINFO
  12. //#define DEBUG_ENABLE_PERFMON
  13. //#define DEBUG_HIMEM_MEMORY_CHECK
  14. // need [env:esp32cam-dev-himem]
  15. //=> CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
  16. //=> CONFIG_SPIRAM_BANKSWITCH_RESERVE=4
  17. // use himem //https://github.com/jomjol/AI-on-the-edge-device/issues/1842
  18. #if (CONFIG_SPIRAM_BANKSWITCH_ENABLE)
  19. #define USE_HIMEM_IF_AVAILABLE 1
  20. #endif
  21. /* Uncomment this to generate task list with stack sizes using the /heap handler
  22. PLEASE BE AWARE: The following CONFIG parameters have to to be set in
  23. sdkconfig.defaults before use of this function is possible!!
  24. CONFIG_FREERTOS_USE_TRACE_FACILITY=1
  25. CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
  26. CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
  27. */
  28. // server_tflite.cpp
  29. //#define TASK_ANALYSIS_ON
  30. //Memory leak tracing
  31. //https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/heap_debug.html#heap-information
  32. //need CONFIG_HEAP_TRACING_STANDALONE=y or #define CONFIG_HEAP_TRACING_STANDALONE
  33. //all setup is predifined in [env:esp32cam-dev-task-analysis]
  34. //#define HEAP_TRACING_MAIN_WIFI || HEAP_TRACING_MAIN_START //enable heap tracing per function in main.cpp
  35. //all defines in [env:esp32cam-dev-task-analysis]
  36. //#define HEAP_TRACING_MAIN_WIFI
  37. //#define HEAP_TRACING_MAIN_START
  38. //#define HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
  39. /* Uncomment this to keep the logfile open for appending.
  40. * If commented out, the logfile gets opened/closed for each log measage (old behaviour) */
  41. // ClassLogFile
  42. //#define KEEP_LOGFILE_OPEN_FOR_APPENDING
  43. //****************************************
  44. //compiler optimization for esp-tflite-micro
  45. #define XTENSA
  46. //#define CONFIG_IDF_TARGET_ARCH_XTENSA //not needed with platformio/espressif32 @ 5.2.0
  47. //ClassControllCamera
  48. #define CAM_LIVESTREAM_REFRESHRATE 500 // Camera livestream feature: Waiting time in milliseconds to refresh image
  49. // #define GRAYSCALE_AS_DEFAULT
  50. //server_GPIO
  51. #define __LEDGLOBAL
  52. //server_GPIO + server_file + SoftAP
  53. #define CONFIG_FILE "/sdcard/config/config.ini"
  54. #define CONFIG_FILE_BACKUP "/sdcard/config/config.bak"
  55. //interface_mqtt + read_wlanini
  56. #define __HIDE_PASSWORD
  57. //ClassFlowControll + Main + SoftAP
  58. #define WLAN_CONFIG_FILE "/sdcard/wlan.ini"
  59. #define LAN_CONFIG_FILE "/sdcard/lan.ini"
  60. //main
  61. #define __SD_USE_ONE_LINE_MODE__
  62. // server_file + Helper
  63. #define FILE_PATH_MAX (255) //Max length a file path can have on storage
  64. //server_file +(ota_page.html + upload_script.html)
  65. #define MAX_FILE_SIZE (8000*1024) // 8 MB Max size of an individual file. Make sure this value is same as that set in upload_script.html and ota_page.html!
  66. #define MAX_FILE_SIZE_STR "8MB"
  67. #define LOGFILE_LAST_PART_BYTES 80 * 1024 // 80 kBytes // Size of partial log file to return
  68. #define SERVER_FILER_SCRATCH_BUFSIZE 1024
  69. #define SERVER_HELPER_SCRATCH_BUFSIZE 1024
  70. #define SERVER_OTA_SCRATCH_BUFSIZE 1024
  71. //server_file + server_help
  72. #define IS_FILE_EXT(filename, ext) \
  73. (strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
  74. //server_ota
  75. #define HASH_LEN 32 // SHA-256 digest length
  76. #define OTA_URL_SIZE 256
  77. //ClassFlow + ClassFlowImage + server_tflite
  78. #define LOGFILE_TIME_FORMAT "%Y%m%d-%H%M%S"
  79. #define LOGFILE_TIME_FORMAT_DATE_EXTR substr(0, 8)
  80. #define LOGFILE_TIME_FORMAT_HOUR_EXTR substr(9, 2)
  81. //ClassFlowControll
  82. #define READOUT_TYPE_VALUE 0
  83. #define READOUT_TYPE_PREVALUE 1
  84. #define READOUT_TYPE_RAWVALUE 2
  85. #define READOUT_TYPE_ERROR 3
  86. //ClassFlowControll: Serve alg_roi.jpg from memory as JPG
  87. #define ALGROI_LOAD_FROM_MEM_AS_JPG // Load ALG_ROI.JPG as rendered JPG from RAM
  88. //ClassFlowMQTT
  89. #define LWT_TOPIC "connection"
  90. #define LWT_CONNECTED "connected"
  91. #define LWT_DISCONNECTED "connection lost"
  92. //ClassFlowPostProcessing
  93. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S%z"
  94. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  95. //CImageBasis
  96. #define HTTP_BUFFER_SENT 1024
  97. #define MAX_JPG_SIZE 128000
  98. //make_stb + stb_image_resize + stb_image_write + stb_image //do not work if not in make_stb.cpp
  99. //#define STB_IMAGE_IMPLEMENTATION
  100. //#define STB_IMAGE_WRITE_IMPLEMENTATION
  101. //#define STB_IMAGE_RESIZE_IMPLEMENTATION
  102. #define STBI_ONLY_JPEG // (save 2% of Flash, but breaks the alignment mark generation, see https://github.com/jomjol/AI-on-the-edge-device/issues/1721)
  103. //interface_influxdb
  104. #define MAX_HTTP_OUTPUT_BUFFER 2048
  105. //server_mqtt
  106. #define LWT_TOPIC "connection"
  107. #define LWT_CONNECTED "connected"
  108. #define LWT_DISCONNECTED "connection lost"
  109. // connect_wlan.cpp
  110. //******************************
  111. /* WIFI roaming functionalities 802.11k+v (uses ca. 6kB - 8kB internal RAM; if SCAN CACHE activated: + 1kB / beacon)
  112. PLEASE BE AWARE: The following CONFIG parameters have to to be set in
  113. sdkconfig.defaults before use of this function is possible!!
  114. CONFIG_WPA_11KV_SUPPORT=y
  115. CONFIG_WPA_SCAN_CACHE=n
  116. CONFIG_WPA_MBO_SUPPORT=n
  117. CONFIG_WPA_11R_SUPPORT=n
  118. */
  119. //#define WLAN_USE_MESH_ROAMING // 802.11v (BSS Transition Management) + 802.11k (Radio Resource Management) (ca. 6kB - 8kB internal RAM neccessary)
  120. //#define WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES // Client can send query to AP requesting to roam (if RSSI lower than RSSI threshold)
  121. /* WIFI roaming only client triggered by scanning the channels after each round (only if RSSI < RSSIThreshold) and trigger a disconnect to switch AP */
  122. // #define WLAN_USE_ROAMING_BY_SCANNING
  123. //ClassFlowCNNGeneral
  124. #define Analog_error 3
  125. #define AnalogToDigtalFehler 0.8
  126. #define Digit_Uncertainty 0.2
  127. #define DigitBand 3
  128. #define Digit_Transition_Range_Predecessor 2
  129. #define Digit_Transition_Area_Predecessor 0.7 // 9.3 - 0.7
  130. #define Digit_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards
  131. //#define DEBUG_DETAIL_ON
  132. /////////////////////////////////////////////
  133. //// PSRAM Allocations ////
  134. /////////////////////////////////////////////
  135. #define MAX_MODEL_SIZE (unsigned int)(1.3 * 1024 * 1024) // Space for the currently largest model (1.1 MB) + some spare
  136. #define TENSOR_ARENA_SIZE 800 * 1024 // Space for the Tensor Arena, (819200 Bytes)
  137. #define IMAGE_SIZE 640 * 480 * 3 // Space for a extracted image (921600 Bytes)
  138. /////////////////////////////////////////////
  139. //// Conditionnal definitions ////
  140. /////////////////////////////////////////////
  141. // ******* Board type
  142. #if defined(BOARD_WROVER_KIT) // WROVER-KIT PIN Map
  143. // SD card (operated with SDMMC peripheral)
  144. //-------------------------------------------------
  145. #define GPIO_SDCARD_CLK GPIO_NUM_14
  146. #define GPIO_SDCARD_CMD GPIO_NUM_15
  147. #define GPIO_SDCARD_D0 GPIO_NUM_2
  148. #ifndef __SD_USE_ONE_LINE_MODE__
  149. #define GPIO_SDCARD_D1 GPIO_NUM_4
  150. #define GPIO_SDCARD_D2 GPIO_NUM_12
  151. #define GPIO_SDCARD_D3 GPIO_NUM_13
  152. #else
  153. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  154. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  155. #define GPIO_SDCARD_D3 GPIO_NUM_13
  156. #endif
  157. #define CAM_PIN_PWDN GPIO_NUM_NC //power down is not used
  158. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  159. #define CAM_PIN_XCLK GPIO_NUM_21
  160. #define CAM_PIN_SIOD GPIO_NUM_26
  161. #define CAM_PIN_SIOC GPIO_NUM_27
  162. #define CAM_PIN_D7 GPIO_NUM_35
  163. #define CAM_PIN_D6 GPIO_NUM_34
  164. #define CAM_PIN_D5 GPIO_NUM_39
  165. #define CAM_PIN_D4 GPIO_NUM_36
  166. #define CAM_PIN_D3 GPIO_NUM_19
  167. #define CAM_PIN_D2 GPIO_NUM_18
  168. #define CAM_PIN_D1 GPIO_NUM_5
  169. #define CAM_PIN_D0 GPIO_NUM_4
  170. #define CAM_PIN_VSYNC GPIO_NUM_25
  171. #define CAM_PIN_HREF GPIO_NUM_23
  172. #define CAM_PIN_PCLK GPIO_NUM_22
  173. //Statusled + ClassControllCamera
  174. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED, On the board the LED is on the IO2, but it is used for the SD
  175. //ClassControllCamera
  176. #define FLASH_GPIO GPIO_NUM_12 // PIN for flashlight LED
  177. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  178. #elif defined(BOARD_M5STACK_PSRAM) // M5STACK PSRAM PIN Map
  179. #define CAM_PIN_PWDN GPIO_NUM_NC
  180. #define CAM_PIN_RESET GPIO_NUM_15
  181. #define CAM_PIN_XCLK GPIO_NUM_27
  182. #define CAM_PIN_SIOD GPIO_NUM_25
  183. #define CAM_PIN_SIOC GPIO_NUM_23
  184. #define CAM_PIN_D7 GPIO_NUM_19
  185. #define CAM_PIN_D6 GPIO_NUM_36
  186. #define CAM_PIN_D5 GPIO_NUM_18
  187. #define CAM_PIN_D4 GPIO_NUM_39
  188. #define CAM_PIN_D3 GPIO_NUM_5
  189. #define CAM_PIN_D2 GPIO_NUM_34
  190. #define CAM_PIN_D1 GPIO_NUM_35
  191. #define CAM_PIN_D0 GPIO_NUM_32
  192. #define CAM_PIN_VSYNC GPIO_NUM_22
  193. #define CAM_PIN_HREF GPIO_NUM_26
  194. #define CAM_PIN_PCLK GPIO_NUM_21
  195. //Statusled + ClassControllCamera
  196. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  197. //ClassControllCamera
  198. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  199. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  200. #elif defined(BOARD_ESP32CAM_AITHINKER) // ESP32Cam (AiThinker) PIN Map
  201. // SD card (operated with SDMMC peripheral)
  202. //-------------------------------------------------
  203. #define GPIO_SDCARD_CLK GPIO_NUM_14
  204. #define GPIO_SDCARD_CMD GPIO_NUM_15
  205. #define GPIO_SDCARD_D0 GPIO_NUM_2
  206. #ifndef __SD_USE_ONE_LINE_MODE__
  207. #define GPIO_SDCARD_D1 GPIO_NUM_4
  208. #define GPIO_SDCARD_D2 GPIO_NUM_12
  209. #define GPIO_SDCARD_D3 GPIO_NUM_13
  210. #else
  211. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  212. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  213. #define GPIO_SDCARD_D3 GPIO_NUM_13
  214. #endif
  215. #define CAM_PIN_PWDN GPIO_NUM_32
  216. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  217. #define CAM_PIN_XCLK GPIO_NUM_0
  218. #define CAM_PIN_SIOD GPIO_NUM_26
  219. #define CAM_PIN_SIOC GPIO_NUM_27
  220. #define CAM_PIN_D7 GPIO_NUM_35
  221. #define CAM_PIN_D6 GPIO_NUM_34
  222. #define CAM_PIN_D5 GPIO_NUM_39
  223. #define CAM_PIN_D4 GPIO_NUM_36
  224. #define CAM_PIN_D3 GPIO_NUM_21
  225. #define CAM_PIN_D2 GPIO_NUM_19
  226. #define CAM_PIN_D1 GPIO_NUM_18
  227. #define CAM_PIN_D0 GPIO_NUM_5
  228. #define CAM_PIN_VSYNC GPIO_NUM_25
  229. #define CAM_PIN_HREF GPIO_NUM_23
  230. #define CAM_PIN_PCLK GPIO_NUM_22
  231. //Statusled + ClassControllCamera
  232. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  233. //ClassControllCamera
  234. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  235. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  236. #elif defined(BOARD_ESP32_S3_ALEKSEI) // Sonderversion für Aleksei mit ESP32s3 und Ethernet (PoE)
  237. // HIGH=ENABLE
  238. // ETH_EN activates power for the Ethernet
  239. // PER_EN activates power for camera,leds,and SDcard, Battery measurement voltage divider
  240. #define ETH_ENABLE GPIO_NUM_45
  241. #define PER_ENABLE GPIO_NUM_46
  242. // Ethernet (operated with SPI peripheral)
  243. #define W5500_SPI_HOST SPI2_HOST
  244. #define ETH_MOSI GPIO_NUM_1
  245. #define ETH_MISO GPIO_NUM_14
  246. #define ETH_CLK GPIO_NUM_21
  247. #define ETH_CS GPIO_NUM_39
  248. #define ETH_INT GPIO_NUM_38
  249. // SD card (operated with SDMMC peripheral)
  250. //-------------------------------------------------
  251. #define GPIO_SDCARD_CLK GPIO_NUM_40
  252. #define GPIO_SDCARD_CMD GPIO_NUM_42
  253. #define GPIO_SDCARD_D0 GPIO_NUM_41
  254. #ifndef __SD_USE_ONE_LINE_MODE__
  255. #define GPIO_SDCARD_D1 GPIO_NUM_4
  256. #define GPIO_SDCARD_D2 GPIO_NUM_12
  257. #define GPIO_SDCARD_D3 GPIO_NUM_13
  258. #else
  259. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  260. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  261. #define GPIO_SDCARD_D3 GPIO_NUM_13
  262. #endif
  263. #define CAM_PIN_PWDN GPIO_NUM_NC
  264. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  265. #define CAM_PIN_XCLK GPIO_NUM_15
  266. #define CAM_PIN_SIOD GPIO_NUM_4
  267. #define CAM_PIN_SIOC GPIO_NUM_5
  268. #define CAM_PIN_D7 GPIO_NUM_16
  269. #define CAM_PIN_D6 GPIO_NUM_17
  270. #define CAM_PIN_D5 GPIO_NUM_18
  271. #define CAM_PIN_D4 GPIO_NUM_12
  272. #define CAM_PIN_D3 GPIO_NUM_10
  273. #define CAM_PIN_D2 GPIO_NUM_8
  274. #define CAM_PIN_D1 GPIO_NUM_9
  275. #define CAM_PIN_D0 GPIO_NUM_11
  276. #define CAM_PIN_VSYNC GPIO_NUM_6
  277. #define CAM_PIN_HREF GPIO_NUM_7
  278. #define CAM_PIN_PCLK GPIO_NUM_13
  279. //Statusled + ClassControllCamera
  280. #define BLINK_GPIO GPIO_NUM_48 // PIN for red board LED
  281. //ClassControllCamera
  282. #define FLASH_GPIO GPIO_NUM_48 // PIN for flashlight LED
  283. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  284. #else
  285. #error "Board not selected"
  286. #endif //Board PIN Map
  287. // ******* LED definition
  288. #ifdef USE_PWM_LEDFLASH
  289. //// PWM für Flash-LED
  290. #define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0
  291. #define LEDC_MODE LEDC_LOW_SPEED_MODE
  292. #define LEDC_OUTPUT_IO FLASH_GPIO // Define the output GPIO
  293. #define LEDC_CHANNEL LEDC_CHANNEL_1
  294. #define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
  295. //#define LEDC_DUTY (195) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
  296. #define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
  297. #endif //USE_PWM_LEDFLASH
  298. //softAP
  299. #ifdef ENABLE_SOFTAP
  300. #define EXAMPLE_ESP_WIFI_SSID "AI-on-the-Edge"
  301. #define EXAMPLE_ESP_WIFI_PASS ""
  302. #define EXAMPLE_ESP_WIFI_CHANNEL 11
  303. #define EXAMPLE_MAX_STA_CONN 1
  304. #endif // ENABLE_SOFTAP
  305. #endif // ifndef defines_h