defines.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. //main
  60. #define __SD_USE_ONE_LINE_MODE__
  61. // server_file + Helper
  62. #define FILE_PATH_MAX (255) //Max length a file path can have on storage
  63. //server_file +(ota_page.html + upload_script.html)
  64. #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!
  65. #define MAX_FILE_SIZE_STR "8MB"
  66. #define LOGFILE_LAST_PART_BYTES 80 * 1024 // 80 kBytes // Size of partial log file to return
  67. #define SERVER_FILER_SCRATCH_BUFSIZE 4096
  68. #define SERVER_HELPER_SCRATCH_BUFSIZE 4096
  69. #define SERVER_OTA_SCRATCH_BUFSIZE 1024
  70. //server_file + server_help
  71. #define IS_FILE_EXT(filename, ext) \
  72. (strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
  73. //server_ota
  74. #define HASH_LEN 32 // SHA-256 digest length
  75. #define OTA_URL_SIZE 256
  76. //ClassFlow + ClassFlowImage + server_tflite
  77. #define LOGFILE_TIME_FORMAT "%Y%m%d-%H%M%S"
  78. #define LOGFILE_TIME_FORMAT_DATE_EXTR substr(0, 8)
  79. #define LOGFILE_TIME_FORMAT_HOUR_EXTR substr(9, 2)
  80. //ClassFlowControll
  81. #define READOUT_TYPE_VALUE 0
  82. #define READOUT_TYPE_PREVALUE 1
  83. #define READOUT_TYPE_RAWVALUE 2
  84. #define READOUT_TYPE_ERROR 3
  85. //ClassFlowControll: Serve alg_roi.jpg from memory as JPG
  86. #define ALGROI_LOAD_FROM_MEM_AS_JPG // Load ALG_ROI.JPG as rendered JPG from RAM
  87. //ClassFlowMQTT
  88. #define LWT_TOPIC "connection"
  89. #define LWT_CONNECTED "connected"
  90. #define LWT_DISCONNECTED "connection lost"
  91. //ClassFlowPostProcessing
  92. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S%z"
  93. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  94. //CImageBasis
  95. #define HTTP_BUFFER_SENT 1024
  96. #define MAX_JPG_SIZE 128000
  97. //make_stb + stb_image_resize + stb_image_write + stb_image //do not work if not in make_stb.cpp
  98. //#define STB_IMAGE_IMPLEMENTATION
  99. //#define STB_IMAGE_WRITE_IMPLEMENTATION
  100. //#define STB_IMAGE_RESIZE_IMPLEMENTATION
  101. #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)
  102. //interface_influxdb
  103. #define MAX_HTTP_OUTPUT_BUFFER 2048
  104. //server_mqtt
  105. #define LWT_TOPIC "connection"
  106. #define LWT_CONNECTED "connected"
  107. #define LWT_DISCONNECTED "connection lost"
  108. // connect_wlan.cpp
  109. //******************************
  110. /* WIFI roaming functionalities 802.11k+v (uses ca. 6kB - 8kB internal RAM; if SCAN CACHE activated: + 1kB / beacon)
  111. PLEASE BE AWARE: The following CONFIG parameters have to to be set in
  112. sdkconfig.defaults before use of this function is possible!!
  113. CONFIG_WPA_11KV_SUPPORT=y
  114. CONFIG_WPA_SCAN_CACHE=n
  115. CONFIG_WPA_MBO_SUPPORT=n
  116. CONFIG_WPA_11R_SUPPORT=n
  117. */
  118. //#define WLAN_USE_MESH_ROAMING // 802.11v (BSS Transition Management) + 802.11k (Radio Resource Management) (ca. 6kB - 8kB internal RAM neccessary)
  119. //#define WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES // Client can send query to AP requesting to roam (if RSSI lower than RSSI threshold)
  120. /* WIFI roaming only client triggered by scanning the channels after each round (only if RSSI < RSSIThreshold) and trigger a disconnect to switch AP */
  121. #define WLAN_USE_ROAMING_BY_SCANNING
  122. //ClassFlowCNNGeneral
  123. #define Analog_error 3
  124. #define AnalogToDigtalFehler 0.8
  125. #define Digit_Uncertainty 0.2
  126. #define DigitBand 3
  127. #define Digit_Transition_Range_Predecessor 2
  128. #define Digit_Transition_Area_Predecessor 0.7 // 9.3 - 0.7
  129. #define Digit_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards
  130. //#define DEBUG_DETAIL_ON
  131. /////////////////////////////////////////////
  132. //// PSRAM Allocations ////
  133. /////////////////////////////////////////////
  134. #define MAX_MODEL_SIZE (unsigned int)(1.3 * 1024 * 1024) // Space for the currently largest model (1.1 MB) + some spare
  135. #define TENSOR_ARENA_SIZE 800 * 1024 // Space for the Tensor Arena, (819200 Bytes)
  136. #define IMAGE_SIZE 640 * 480 * 3 // Space for a extracted image (921600 Bytes)
  137. /////////////////////////////////////////////
  138. //// Conditionnal definitions ////
  139. /////////////////////////////////////////////
  140. // ******* Board type
  141. #if defined(BOARD_WROVER_KIT) // WROVER-KIT PIN Map
  142. // SD card (operated with SDMMC peripheral)
  143. //-------------------------------------------------
  144. #define GPIO_SDCARD_CLK GPIO_NUM_14
  145. #define GPIO_SDCARD_CMD GPIO_NUM_15
  146. #define GPIO_SDCARD_D0 GPIO_NUM_2
  147. #ifndef __SD_USE_ONE_LINE_MODE__
  148. #define GPIO_SDCARD_D1 GPIO_NUM_4
  149. #define GPIO_SDCARD_D2 GPIO_NUM_12
  150. #define GPIO_SDCARD_D3 GPIO_NUM_13
  151. #else
  152. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  153. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  154. #define GPIO_SDCARD_D3 GPIO_NUM_13
  155. #endif
  156. #define CAM_PIN_PWDN GPIO_NUM_NC //power down is not used
  157. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  158. #define CAM_PIN_XCLK GPIO_NUM_21
  159. #define CAM_PIN_SIOD GPIO_NUM_26
  160. #define CAM_PIN_SIOC GPIO_NUM_27
  161. #define CAM_PIN_D7 GPIO_NUM_35
  162. #define CAM_PIN_D6 GPIO_NUM_34
  163. #define CAM_PIN_D5 GPIO_NUM_39
  164. #define CAM_PIN_D4 GPIO_NUM_36
  165. #define CAM_PIN_D3 GPIO_NUM_19
  166. #define CAM_PIN_D2 GPIO_NUM_18
  167. #define CAM_PIN_D1 GPIO_NUM_5
  168. #define CAM_PIN_D0 GPIO_NUM_4
  169. #define CAM_PIN_VSYNC GPIO_NUM_25
  170. #define CAM_PIN_HREF GPIO_NUM_23
  171. #define CAM_PIN_PCLK GPIO_NUM_22
  172. //Statusled + ClassControllCamera
  173. #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
  174. //ClassControllCamera
  175. #define FLASH_GPIO GPIO_NUM_12 // PIN for flashlight LED
  176. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  177. #elif defined(BOARD_M5STACK_PSRAM) // M5STACK PSRAM PIN Map
  178. #define CAM_PIN_PWDN GPIO_NUM_NC
  179. #define CAM_PIN_RESET GPIO_NUM_15
  180. #define CAM_PIN_XCLK GPIO_NUM_27
  181. #define CAM_PIN_SIOD GPIO_NUM_25
  182. #define CAM_PIN_SIOC GPIO_NUM_23
  183. #define CAM_PIN_D7 GPIO_NUM_19
  184. #define CAM_PIN_D6 GPIO_NUM_36
  185. #define CAM_PIN_D5 GPIO_NUM_18
  186. #define CAM_PIN_D4 GPIO_NUM_39
  187. #define CAM_PIN_D3 GPIO_NUM_5
  188. #define CAM_PIN_D2 GPIO_NUM_34
  189. #define CAM_PIN_D1 GPIO_NUM_35
  190. #define CAM_PIN_D0 GPIO_NUM_32
  191. #define CAM_PIN_VSYNC GPIO_NUM_22
  192. #define CAM_PIN_HREF GPIO_NUM_26
  193. #define CAM_PIN_PCLK GPIO_NUM_21
  194. //Statusled + ClassControllCamera
  195. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  196. //ClassControllCamera
  197. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  198. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  199. #elif defined(BOARD_ESP32CAM_AITHINKER) // ESP32Cam (AiThinker) PIN Map
  200. // SD card (operated with SDMMC peripheral)
  201. //-------------------------------------------------
  202. #define GPIO_SDCARD_CLK GPIO_NUM_14
  203. #define GPIO_SDCARD_CMD GPIO_NUM_15
  204. #define GPIO_SDCARD_D0 GPIO_NUM_2
  205. #ifndef __SD_USE_ONE_LINE_MODE__
  206. #define GPIO_SDCARD_D1 GPIO_NUM_4
  207. #define GPIO_SDCARD_D2 GPIO_NUM_12
  208. #define GPIO_SDCARD_D3 GPIO_NUM_13
  209. #else
  210. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  211. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  212. #define GPIO_SDCARD_D3 GPIO_NUM_13
  213. #endif
  214. #define CAM_PIN_PWDN GPIO_NUM_32
  215. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  216. #define CAM_PIN_XCLK GPIO_NUM_0
  217. #define CAM_PIN_SIOD GPIO_NUM_26
  218. #define CAM_PIN_SIOC GPIO_NUM_27
  219. #define CAM_PIN_D7 GPIO_NUM_35
  220. #define CAM_PIN_D6 GPIO_NUM_34
  221. #define CAM_PIN_D5 GPIO_NUM_39
  222. #define CAM_PIN_D4 GPIO_NUM_36
  223. #define CAM_PIN_D3 GPIO_NUM_21
  224. #define CAM_PIN_D2 GPIO_NUM_19
  225. #define CAM_PIN_D1 GPIO_NUM_18
  226. #define CAM_PIN_D0 GPIO_NUM_5
  227. #define CAM_PIN_VSYNC GPIO_NUM_25
  228. #define CAM_PIN_HREF GPIO_NUM_23
  229. #define CAM_PIN_PCLK GPIO_NUM_22
  230. //Statusled + ClassControllCamera
  231. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  232. //ClassControllCamera
  233. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  234. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  235. #elif defined(BOARD_ESP32_S3_ALEKSEI) // Sonderversion für Aleksei mit ESP32s3 und Ethernet (PoE)
  236. // HIGH=ENABLE
  237. // ETH_EN activates power for the Ethernet
  238. // PER_EN activates power for camera,leds,and SDcard, Battery measurement voltage divider
  239. #define ETH_EN GPIO_NUM_45
  240. #define PER_EN GPIO_NUM_46
  241. // SD card (operated with SDMMC peripheral)
  242. //-------------------------------------------------
  243. #define GPIO_SDCARD_CLK GPIO_NUM_40
  244. #define GPIO_SDCARD_CMD GPIO_NUM_42
  245. #define GPIO_SDCARD_D0 GPIO_NUM_41
  246. #ifndef __SD_USE_ONE_LINE_MODE__
  247. #define GPIO_SDCARD_D1 GPIO_NUM_4
  248. #define GPIO_SDCARD_D2 GPIO_NUM_12
  249. #define GPIO_SDCARD_D3 GPIO_NUM_13
  250. #else
  251. #define GPIO_SDCARD_D1 GPIO_NUM_NC
  252. #define GPIO_SDCARD_D2 GPIO_NUM_NC
  253. #define GPIO_SDCARD_D3 GPIO_NUM_13
  254. #endif
  255. /*
  256. #define PWDN_GPIO_NUM -1
  257. #define RESET_GPIO_NUM -1
  258. #define XCLK_GPIO_NUM GPIO_NUM_15
  259. #define SIOD_GPIO_NUM GPIO_NUM_4
  260. #define SIOC_GPIO_NUM GPIO_NUM_5
  261. #define Y9_GPIO_NUM GPIO_NUM_16
  262. #define Y8_GPIO_NUM GPIO_NUM_17
  263. #define Y7_GPIO_NUM GPIO_NUM_18
  264. #define Y6_GPIO_NUM GPIO_NUM_12
  265. #define Y5_GPIO_NUM GPIO_NUM_10
  266. #define Y4_GPIO_NUM GPIO_NUM_8
  267. #define Y3_GPIO_NUM GPIO_NUM_9
  268. #define Y2_GPIO_NUM GPIO_NUM_11
  269. #define VSYNC_GPIO_NUM GPIO_NUM_6
  270. #define HREF_GPIO_NUM GPIO_NUM_7
  271. #define PCLK_GPIO_NUM GPIO_NUM_13
  272. */
  273. #define CAM_PIN_PWDN GPIO_NUM_NC
  274. #define CAM_PIN_RESET GPIO_NUM_NC //software reset will be performed
  275. #define CAM_PIN_XCLK GPIO_NUM_15
  276. #define CAM_PIN_SIOD GPIO_NUM_4
  277. #define CAM_PIN_SIOC GPIO_NUM_5
  278. #define CAM_PIN_D7 GPIO_NUM_16
  279. #define CAM_PIN_D6 GPIO_NUM_17
  280. #define CAM_PIN_D5 GPIO_NUM_18
  281. #define CAM_PIN_D4 GPIO_NUM_12
  282. #define CAM_PIN_D3 GPIO_NUM_10
  283. #define CAM_PIN_D2 GPIO_NUM_8
  284. #define CAM_PIN_D1 GPIO_NUM_9
  285. #define CAM_PIN_D0 GPIO_NUM_11
  286. #define CAM_PIN_VSYNC GPIO_NUM_6
  287. #define CAM_PIN_HREF GPIO_NUM_7
  288. #define CAM_PIN_PCLK GPIO_NUM_13
  289. //Statusled + ClassControllCamera
  290. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  291. //ClassControllCamera
  292. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  293. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  294. #else
  295. #error "Board not selected"
  296. #endif //Board PIN Map
  297. // ******* LED definition
  298. #ifdef USE_PWM_LEDFLASH
  299. //// PWM für Flash-LED
  300. #define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0
  301. #define LEDC_MODE LEDC_LOW_SPEED_MODE
  302. #define LEDC_OUTPUT_IO FLASH_GPIO // Define the output GPIO
  303. #define LEDC_CHANNEL LEDC_CHANNEL_1
  304. #define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
  305. //#define LEDC_DUTY (195) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
  306. #define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
  307. #endif //USE_PWM_LEDFLASH
  308. //softAP
  309. #ifdef ENABLE_SOFTAP
  310. #define EXAMPLE_ESP_WIFI_SSID "AI-on-the-Edge"
  311. #define EXAMPLE_ESP_WIFI_PASS ""
  312. #define EXAMPLE_ESP_WIFI_CHANNEL 11
  313. #define EXAMPLE_MAX_STA_CONN 1
  314. #endif // ENABLE_SOFTAP
  315. #endif // ifndef defines_h