config.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. // Board- and application-wide configuration.
  3. //
  4. // Wi-Fi credentials, the outdoor sensor URL, the timezone and the NTP server
  5. // are runtime settings held in NVS and entered through the setup portal — see
  6. // src/settings.h and src/portal.h. The values below are compile-time
  7. // constants and safe to commit.
  8. // ---------------------------------------------------------------- display ---
  9. // The panel is a 300 x 400 ST7305 reflective LCD. The application runs it
  10. // rotated (U8G2_R1), so the drawing surface is 400 wide by 300 high.
  11. #define LCD_NATIVE_WIDTH 300
  12. #define LCD_NATIVE_HEIGHT 400
  13. #define DISPLAY_WIDTH 400
  14. #define DISPLAY_HEIGHT 300
  15. #define RLCD_SCK_PIN 11
  16. #define RLCD_MOSI_PIN 12
  17. #define RLCD_DC_PIN 5
  18. #define RLCD_CS_PIN 40
  19. #define RLCD_RST_PIN 41
  20. #define RLCD_TE_PIN 6 // tearing effect output, unused
  21. // Layout: top 60% is time + date, bottom 40% is indoor | outdoor.
  22. #define LAYOUT_SPLIT_Y 180
  23. #define LAYOUT_MID_X 200
  24. // ------------------------------------------------------------------- i2c ---
  25. #define I2C_SDA_PIN 13
  26. #define I2C_SCL_PIN 14
  27. #define I2C_FREQ_HZ 400000
  28. #define PCF85063_ADDR 0x51
  29. #define SHTC3_ADDR 0x70
  30. // BH1750 ambient light sensor, wired to the same bus on the expansion header.
  31. // Optional: without it the display falls back to quiet hours from the clock.
  32. // The part answers on 0x23 with ADDR low and 0x5C with ADDR high; both are
  33. // probed at boot.
  34. #define BH1750_ADDR_LOW 0x23
  35. #define BH1750_ADDR_HIGH 0x5C
  36. // --------------------------------------------------------------- battery ---
  37. // 18650 voltage divider, per the vendor's 03_ADC_Test: ADC1 channel 3 with a
  38. // 1:3 divider, so the measured millivolts are multiplied by three.
  39. #define BATTERY_ADC_PIN 4
  40. #define BATTERY_DIVIDER 3.0f
  41. #define BATTERY_SAMPLES 16 // oversampling per reading
  42. #define BATTERY_READ_MS 60000UL
  43. // --------------------------------------------------------------- buttons ---
  44. // Both onboard buttons are active low. KEY is the application button; BOOT is
  45. // avoided because holding it at reset also enters the ROM download mode.
  46. #define KEY_BUTTON_PIN 18
  47. #define BOOT_BUTTON_PIN 0
  48. // Hold KEY for this long during power-up to force the setup portal.
  49. #define KEY_FORCE_SETUP_MS 1500
  50. // ------------------------------------------------------------------ time ---
  51. // Defaults for a freshly erased device; both are editable in the setup portal.
  52. #define NTP_SERVER_1 "pool.ntp.org"
  53. #define NTP_SERVER_2 "time.google.com"
  54. // POSIX TZ string for Australia/Hobart (AEST-10, AEDT from Oct to Apr).
  55. #define TIMEZONE_POSIX "AEST-10AEDT,M10.1.0,M4.1.0/3"
  56. // Clock and date presentation defaults; all three are editable in the setup
  57. // portal. DATE_FORMAT is a strftime(3) string — "%A %e %B" is "MONDAY 24
  58. // AUGUST".
  59. #define CLOCK_24H_DEFAULT true
  60. #define DATE_FORMAT "%A %e %B"
  61. #define DATE_UPPERCASE_DEFAULT true
  62. // ----------------------------------------------------------------- setup ---
  63. // Soft-AP the device raises when it has nothing to connect to. The password
  64. // must be at least 8 characters or the AP comes up open.
  65. #define SETUP_AP_SSID "TempDisplay-Setup"
  66. #define SETUP_AP_PASSWORD "temp1234"
  67. #define DEVICE_HOSTNAME "temp-display"
  68. // ------------------------------------------------------------ power save ---
  69. // 80 MHz is the lowest the ESP32-S3 can run with Wi-Fi active and leaves the
  70. // 80 MHz APB clock — and so the display SPI — untouched.
  71. #define CPU_FREQ_MHZ 80
  72. // Defaults for the power-saving settings, all editable in the setup portal.
  73. #define SHOW_BATTERY_DEFAULT true
  74. #define SLEEP_WHEN_DARK_DEFAULT true
  75. #define PANEL_LOW_POWER_DEFAULT true
  76. #define DARK_LUX_DEFAULT 5 // below this the room is unreadable
  77. #define QUIET_START_HOUR_DEFAULT 23 // used only when no sensor is fitted
  78. #define QUIET_END_HOUR_DEFAULT 6
  79. // Hysteresis, so a flickering or marginal reading cannot chatter the display
  80. // in and out of sleep. Waking needs a clearly brighter room than sleeping.
  81. #define DARK_LUX_HYSTERESIS 3.0f
  82. // While asleep in a dark room, wake this often to re-check the light level.
  83. // Short enough that the clock is at most one minute stale when the lights come
  84. // on, long enough that the duty cycle is well under 1%.
  85. #define DARK_RECHECK_MS 20000UL
  86. // -------------------------------------------------------------- intervals ---
  87. #define WIFI_CONNECT_TIMEOUT_MS 20000UL // give up on a connect attempt
  88. #define WIFI_RETRY_MS 60000UL // then retry this often
  89. #define NTP_RESYNC_MS (6UL * 60UL * 60UL * 1000UL)
  90. #define INDOOR_READ_MS 30000UL
  91. #define OUTDOOR_POLL_MS 30000UL
  92. #define OUTDOOR_STALE_MS (10UL * 60UL * 1000UL) // mark reading stale
  93. #define DISPLAY_TICK_MS 1000UL // check-for-change rate
  94. // ----------------------------------------------------------------- audio ---
  95. // The board carries two analog MEMS microphones feeding an ES7210 ADC, and an
  96. // ES8311 DAC driving the speaker, on one shared I2S bus. Only the capture half
  97. // is used here. Pins are from the vendor's 07_Audio_Test and match Waveshare's
  98. // own ESPHome example for this board.
  99. #define I2S_MCLK_PIN 16
  100. #define I2S_BCLK_PIN 9
  101. #define I2S_LRCLK_PIN 45
  102. #define ES7210_DIN_PIN 10 // ADC -> ESP32, the microphones
  103. #define ES8311_DOUT_PIN 8 // ESP32 -> DAC, unused: playback is not built
  104. #define SPEAKER_PA_PIN 46 // amplifier enable, held low so we stay silent
  105. #define ES7210_ADDR 0x40
  106. #define ES8311_ADDR 0x18
  107. // 16 kHz mono at 32 kbps is speech-grade and about 4 kB/s. The ES7210 always
  108. // hands over two channels; MIC1 and MIC2 are averaged when recording mono.
  109. #define AUDIO_SAMPLE_RATE 16000
  110. #define AUDIO_BITRATE_KBPS 32
  111. #define AUDIO_STEREO_DEFAULT false
  112. // ES7210 analog gain, 0-14 in 3 dB steps. 7 is ~21 dB: enough for a voice at
  113. // desk distance without clipping a hand clap.
  114. #define AUDIO_MIC_GAIN 7
  115. // MP3 encoding is far too slow at CPU_FREQ_MHZ, so the clock is raised for the
  116. // duration of a recording and dropped back the moment it ends.
  117. #define AUDIO_CPU_FREQ_MHZ 240
  118. // PSRAM recordings stop at this size rather than filling the heap. At 32 kbps
  119. // mono, 5 MB is a little over 20 minutes.
  120. #define AUDIO_PSRAM_MAX_BYTES (5UL * 1024UL * 1024UL)
  121. // MP3 frames waiting to be written to their destination. One 16 kHz mono frame
  122. // is 576 samples, so this is about 4 seconds of slack for an SD write or a
  123. // stalled TCP connection.
  124. #define AUDIO_RING_BYTES (32UL * 1024UL)
  125. // Bytes pushed to a streaming client per loop() pass. Small enough that the
  126. // clock never waits long on the network, large enough to stay ahead of a
  127. // 4 kB/s encoder.
  128. #define AUDIO_STREAM_CHUNK 1460
  129. // microSD, wired for SDMMC in 1-bit mode per the vendor's 06_SD_Card.
  130. #define SD_CLK_PIN 38
  131. #define SD_CMD_PIN 21
  132. #define SD_D0_PIN 39
  133. // ---------------------------------------------------------------- outdoor ---
  134. // HTTP timeout for one outdoor poll.
  135. #define OUTDOOR_HTTP_TIMEOUT_MS 5000
  136. // Plausible temperature range; readings outside it are rejected.
  137. #define TEMP_MIN_VALID -50.0f
  138. #define TEMP_MAX_VALID 80.0f
  139. // Optional development conveniences. include/secrets.h is gitignored; when it
  140. // exists its values seed a freshly erased device so a bench unit does not need
  141. // to be re-provisioned through the portal after every flash erase.
  142. #if __has_include("secrets.h")
  143. #include "secrets.h"
  144. #endif