================================================================================
          DivineAcademix v2.0 - ESP32 SCHOOL BELL REDISTRIBUTION GUIDE
================================================================================

This directory contains the pre-compiled binary files for flashing the DivineAcademix
Automatic School Bell client onto a standard ESP32 Development Module (ESP32-WROOM-32).

--------------------------------------------------------------------------------
1. FLASHING INSTRUCTIONS (ESPRESSIF FLASH DOWNLOAD TOOL)
--------------------------------------------------------------------------------

To write these binaries to your ESP32 board, download and open the official 
"Espressif Flash Download Tool" (for Windows) and configure it as follows:

A. Initial Setup Pop-up:
   - ChipType: ESP32
   - WorkMode: Develop

B. Binary Files & Memory Address Mappings:
   In the grid at the top of the tool, load the following files from this folder, 
   set their addresses, and make sure the checkboxes next to them are CHECKED:

   [File Name]          [Memory Address]
   -------------------------------------
   bootloader.bin  ---> 0x1000   (Note: 0x1000 for ESP32, NOT 0x0)
   partitions.bin  ---> 0x8000
   boot_app0.bin   ---> 0xe000
   firmware.bin    ---> 0x10000

C. Flash Parameters (SPI Configuration):
   - SPI SPEED: 40MHz
   - SPI MODE:  DIO (Dual I/O)
   - DETECTED INFO: (Leave default / Auto)

D. Sio / UART Config (Bottom of window):
   - COM: Select the COM port corresponding to your ESP32 board (CH340 or CP2102)
   - BAUD: 921600 (Recommended for fast flashing) or 115200 (If flashing fails)

E. Execution Steps:
   1. Connect the ESP32 to your PC using a high-quality Micro-USB or USB-C cable.
   2. Select the correct COM port and set the baud rate.
   3. Click "ERASE" first to wipe any old WiFi credentials/partition data.
   4. Click "START".
   5. If the status panel shows "Connecting..." and waits, press and hold the 
      "BOOT" (or "IO0") button on the ESP32 board until the green progress bar 
      starts moving, then release the button.
   6. Once the status shows "FINISH", press the "EN" (or "RST") button on the 
      ESP32 board to reboot and run the Bell firmware.

--------------------------------------------------------------------------------
2. HARDWARE WIRING MATRIX
--------------------------------------------------------------------------------

Connect your hardware components to the ESP32 board pins as outlined below:

A. PCM5102 I2S Audio DAC (Output Stage)
   - VIN  ---> ESP32 5V (VIN)
   - GND  ---> Common GND
   - BCK  ---> ESP32 GPIO 27 (I2S Bit Clock)
   - WSEL ---> ESP32 GPIO 26 (I2S Left/Right Word Select)
   - DIN  ---> ESP32 GPIO 25 (I2S Serial Data Line)
   * Note: Leave DE, FIL, MU, FM unconnected. Onboard solder bridges default them.

B. 5V Optocoupler-Isolated Relay Module (Amplifier Power Control)
   - VCC  ---> ESP32 5V (VIN)
   - GND  ---> Common GND
   - IN   ---> ESP32 GPIO 33 (Relay Trigger Signal)

C. SSD1306 0.96" I2C OLED Display (Status Screen)
   - VCC  ---> ESP32 3.3V (3V3)
   - GND  ---> Common GND
   - SDA  ---> ESP32 GPIO 21 (I2C Data)
   - SCL  ---> ESP32 GPIO 22 (I2C Clock)

D. Common Cathode RGB LED (Indicator Lights)
   - Cathode (Longest leg) ---> Common GND
   - Red Lead   ---> 220Ω Resistor ---> ESP32 GPIO 13
   - Green Lead ---> 220Ω Resistor ---> ESP32 GPIO 14
   - Blue Lead  ---> 220Ω Resistor ---> ESP32 GPIO 15

E. Active 5V Buzzer (Beep Alarms)
   - Positive (+) ---> ESP32 GPIO 32
   - Negative (-) ---> Common GND

* IMPORTANT: All Grounds (GND) must be connected to a single common ground point.

--------------------------------------------------------------------------------
3. CAPTIVE PORTAL WIFI SETUP
--------------------------------------------------------------------------------

Once successfully flashed and powered on, the OLED screen will display 
"Connecting..." as it searches for WiFi. Follow these steps to configure it:

1. Open the WiFi settings on your phone or computer.
2. Find and connect to the network named: "DA-BellSetup-<device_id>".
3. A portal page should open automatically. If it does not, open a browser and 
   go to: http://192.168.4.1
4. Click "Configure WiFi".
5. Enter your Wi-Fi name (SSID), password, school database Server Host (IP/Domain), 
   Server Port (default 80/443), and select the School ID.
6. Click "Save". The ESP32 will reboot, connect to your network, self-register, 
   and show the idle status screen.
================================================================================
