defines.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 tflite-micro-esp-examples
  45. #define XTENSA
  46. //#define CONFIG_IDF_TARGET_ARCH_XTENSA //not needed with platformio/espressif32 @ 5.2.0
  47. //Statusled + ClassControllCamera
  48. #define BLINK_GPIO GPIO_NUM_33 // PIN for red board LED
  49. //ClassControllCamera
  50. #define FLASH_GPIO GPIO_NUM_4 // PIN for flashlight LED
  51. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  52. #define CAM_LIVESTREAM_REFRESHRATE 500 // Camera livestream feature: Waiting time in milliseconds to refresh image
  53. //ClassControllCamera + ClassFlowTakeImage
  54. #define CAMERA_MODEL_AI_THINKER
  55. #define BOARD_ESP32CAM_AITHINKER
  56. //server_GPIO
  57. #define __LEDGLOBAL
  58. //server_GPIO + server_file + SoftAP
  59. #define CONFIG_FILE "/sdcard/config/config.ini"
  60. #define CONFIG_FILE_BACKUP "/sdcard/config/config.bak"
  61. //interface_mqtt + read_wlanini
  62. #define __HIDE_PASSWORD
  63. //ClassFlowControll + Main + SoftAP
  64. #define WLAN_CONFIG_FILE "/sdcard/wlan.ini"
  65. //main
  66. #define __SD_USE_ONE_LINE_MODE__
  67. // server_file + Helper
  68. #define FILE_PATH_MAX (255) //Max length a file path can have on storage
  69. //server_file +(ota_page.html + upload_script.html)
  70. #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!
  71. #define MAX_FILE_SIZE_STR "8MB"
  72. #define LOGFILE_LAST_PART_BYTES 80 * 1024 // 80 kBytes // Size of partial log file to return
  73. #define SERVER_FILER_SCRATCH_BUFSIZE 4096
  74. #define SERVER_HELPER_SCRATCH_BUFSIZE 8192
  75. #define SERVER_OTA_SCRATCH_BUFSIZE 1024
  76. //server_file + server_help
  77. #define IS_FILE_EXT(filename, ext) \
  78. (strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
  79. //server_ota
  80. #define HASH_LEN 32 // SHA-256 digest length
  81. #define OTA_URL_SIZE 256
  82. //ClassFlow + ClassFlowImage + server_tflite
  83. #define LOGFILE_TIME_FORMAT "%Y%m%d-%H%M%S"
  84. #define LOGFILE_TIME_FORMAT_DATE_EXTR substr(0, 8)
  85. #define LOGFILE_TIME_FORMAT_HOUR_EXTR substr(9, 2)
  86. //ClassFlowControll
  87. #define READOUT_TYPE_VALUE 0
  88. #define READOUT_TYPE_PREVALUE 1
  89. #define READOUT_TYPE_RAWVALUE 2
  90. #define READOUT_TYPE_ERROR 3
  91. //ClassFlowControll: Serve alg_roi.jpg from memory as JPG
  92. #define ALGROI_LOAD_FROM_MEM_AS_JPG // Load ALG_ROI.JPG as rendered JPG from RAM
  93. //ClassFlowMQTT
  94. #define LWT_TOPIC "connection"
  95. #define LWT_CONNECTED "connected"
  96. #define LWT_DISCONNECTED "connection lost"
  97. //ClassFlowPostProcessing
  98. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S%z"
  99. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  100. //CImageBasis
  101. #define HTTP_BUFFER_SENT 1024
  102. #define MAX_JPG_SIZE 128000
  103. //make_stb + stb_image_resize + stb_image_write + stb_image //do not work if not in make_stb.cpp
  104. //#define STB_IMAGE_IMPLEMENTATION
  105. //#define STB_IMAGE_WRITE_IMPLEMENTATION
  106. //#define STB_IMAGE_RESIZE_IMPLEMENTATION
  107. #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)
  108. //interface_influxdb
  109. #define MAX_HTTP_OUTPUT_BUFFER 2048
  110. //server_mqtt
  111. #define LWT_TOPIC "connection"
  112. #define LWT_CONNECTED "connected"
  113. #define LWT_DISCONNECTED "connection lost"
  114. //CTfLiteClass
  115. #define TFLITE_MINIMAL_CHECK(x) \
  116. if (!(x)) { \
  117. fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); \
  118. exit(1); \
  119. }
  120. #define SUPRESS_TFLITE_ERRORS // use, to avoid error messages from TFLITE
  121. // connect_wlan.cpp
  122. //******************************
  123. /* WIFI roaming functionalities 802.11k+v (uses ca. 6kB - 8kB internal RAM; if SCAN CACHE activated: + 1kB / beacon)
  124. PLEASE BE AWARE: The following CONFIG parameters have to to be set in
  125. sdkconfig.defaults before use of this function is possible!!
  126. CONFIG_WPA_11KV_SUPPORT=y
  127. CONFIG_WPA_SCAN_CACHE=n
  128. CONFIG_WPA_MBO_SUPPORT=n
  129. CONFIG_WPA_11R_SUPPORT=n
  130. */
  131. //#define WLAN_USE_MESH_ROAMING // 802.11v (BSS Transition Management) + 802.11k (Radio Resource Management) (ca. 6kB - 8kB internal RAM neccessary)
  132. //#define WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES // Client can send query to AP requesting to roam (if RSSI lower than RSSI threshold)
  133. /* WIFI roaming only client triggered by scanning the channels after each round (only if RSSI < RSSIThreshold) and trigger a disconnect to switch AP */
  134. #define WLAN_USE_ROAMING_BY_SCANNING
  135. //ClassFlowCNNGeneral
  136. #define Analog_error 3
  137. #define AnalogToDigtalFehler 0.8
  138. #define Digital_Uncertainty 0.2
  139. #define DigitalBand 3
  140. #define Digital_Transition_Range_Predecessor 2
  141. #define Digital_Transition_Area_Predecessor 0.7 // 9.3 - 0.7
  142. #define Digital_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards
  143. //#define DEBUG_DETAIL_ON
  144. /////////////////////////////////////////////
  145. //// Conditionnal definitions ////
  146. /////////////////////////////////////////////
  147. //******* camera model
  148. #if defined(CAMERA_MODEL_WROVER_KIT)
  149. #define PWDN_GPIO_NUM -1
  150. #define RESET_GPIO_NUM -1
  151. #define XCLK_GPIO_NUM 21
  152. #define SIOD_GPIO_NUM 26
  153. #define SIOC_GPIO_NUM 27
  154. #define Y9_GPIO_NUM 35
  155. #define Y8_GPIO_NUM 34
  156. #define Y7_GPIO_NUM 39
  157. #define Y6_GPIO_NUM 36
  158. #define Y5_GPIO_NUM 19
  159. #define Y4_GPIO_NUM 18
  160. #define Y3_GPIO_NUM 5
  161. #define Y2_GPIO_NUM 4
  162. #define VSYNC_GPIO_NUM 25
  163. #define HREF_GPIO_NUM 23
  164. #define PCLK_GPIO_NUM 22
  165. #elif defined(CAMERA_MODEL_M5STACK_PSRAM)
  166. #define PWDN_GPIO_NUM -1
  167. #define RESET_GPIO_NUM 15
  168. #define XCLK_GPIO_NUM 27
  169. #define SIOD_GPIO_NUM 25
  170. #define SIOC_GPIO_NUM 23
  171. #define Y9_GPIO_NUM 19
  172. #define Y8_GPIO_NUM 36
  173. #define Y7_GPIO_NUM 18
  174. #define Y6_GPIO_NUM 39
  175. #define Y5_GPIO_NUM 5
  176. #define Y4_GPIO_NUM 34
  177. #define Y3_GPIO_NUM 35
  178. #define Y2_GPIO_NUM 32
  179. #define VSYNC_GPIO_NUM 22
  180. #define HREF_GPIO_NUM 26
  181. #define PCLK_GPIO_NUM 21
  182. #elif defined(CAMERA_MODEL_AI_THINKER)
  183. #define PWDN_GPIO_NUM GPIO_NUM_32
  184. #define RESET_GPIO_NUM -1
  185. #define XCLK_GPIO_NUM GPIO_NUM_0
  186. #define SIOD_GPIO_NUM GPIO_NUM_26
  187. #define SIOC_GPIO_NUM GPIO_NUM_27
  188. #define Y9_GPIO_NUM GPIO_NUM_35
  189. #define Y8_GPIO_NUM GPIO_NUM_34
  190. #define Y7_GPIO_NUM GPIO_NUM_39
  191. #define Y6_GPIO_NUM GPIO_NUM_36
  192. #define Y5_GPIO_NUM GPIO_NUM_21
  193. #define Y4_GPIO_NUM GPIO_NUM_19
  194. #define Y3_GPIO_NUM GPIO_NUM_18
  195. #define Y2_GPIO_NUM GPIO_NUM_5
  196. #define VSYNC_GPIO_NUM GPIO_NUM_25
  197. #define HREF_GPIO_NUM GPIO_NUM_23
  198. #define PCLK_GPIO_NUM GPIO_NUM_22
  199. #else
  200. #error "Camera model not selected"
  201. #endif //camera model
  202. // ******* Board type
  203. #ifdef BOARD_WROVER_KIT // WROVER-KIT PIN Map
  204. #define CAM_PIN_PWDN -1 //power down is not used
  205. #define CAM_PIN_RESET -1 //software reset will be performed
  206. #define CAM_PIN_XCLK 21
  207. #define CAM_PIN_SIOD 26
  208. #define CAM_PIN_SIOC 27
  209. #define CAM_PIN_D7 35
  210. #define CAM_PIN_D6 34
  211. #define CAM_PIN_D5 39
  212. #define CAM_PIN_D4 36
  213. #define CAM_PIN_D3 19
  214. #define CAM_PIN_D2 18
  215. #define CAM_PIN_D1 5
  216. #define CAM_PIN_D0 4
  217. #define CAM_PIN_VSYNC 25
  218. #define CAM_PIN_HREF 23
  219. #define CAM_PIN_PCLK 22
  220. #endif //// WROVER-KIT PIN Map
  221. #ifdef BOARD_ESP32CAM_AITHINKER // ESP32Cam (AiThinker) PIN Map
  222. #define CAM_PIN_PWDN 32
  223. #define CAM_PIN_RESET -1 //software reset will be performed
  224. #define CAM_PIN_XCLK 0
  225. #define CAM_PIN_SIOD 26
  226. #define CAM_PIN_SIOC 27
  227. #define CAM_PIN_D7 35
  228. #define CAM_PIN_D6 34
  229. #define CAM_PIN_D5 39
  230. #define CAM_PIN_D4 36
  231. #define CAM_PIN_D3 21
  232. #define CAM_PIN_D2 19
  233. #define CAM_PIN_D1 18
  234. #define CAM_PIN_D0 5
  235. #define CAM_PIN_VSYNC 25
  236. #define CAM_PIN_HREF 23
  237. #define CAM_PIN_PCLK 22
  238. #endif // ESP32Cam (AiThinker) PIN Map
  239. // ******* LED definition
  240. #ifdef USE_PWM_LEDFLASH
  241. //// PWM für Flash-LED
  242. #define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0
  243. #define LEDC_MODE LEDC_LOW_SPEED_MODE
  244. #define LEDC_OUTPUT_IO FLASH_GPIO // Define the output GPIO
  245. #define LEDC_CHANNEL LEDC_CHANNEL_1
  246. #define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
  247. //#define LEDC_DUTY (195) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
  248. #define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
  249. #endif //USE_PWM_LEDFLASH
  250. //softAP
  251. #ifdef ENABLE_SOFTAP
  252. #define EXAMPLE_ESP_WIFI_SSID "AI-on-the-Edge"
  253. #define EXAMPLE_ESP_WIFI_PASS ""
  254. #define EXAMPLE_ESP_WIFI_CHANNEL 11
  255. #define EXAMPLE_MAX_STA_CONN 1
  256. #endif // ENABLE_SOFTAP
  257. #endif // ifndef defines_h