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