Implements the first working feature: the device records audio to the microSD
card, toggled by the button, with LED status and per-recording JSON metadata.
What changed:
- firmware/src/audio.{h,cpp}: mic capture via the core-bundled ESP_I2S. Dev board
uses I2S standard mode (INMP441/ICS-43434); XIAO uses PDM mode (onboard mic).
Presents 16-bit PCM mono to callers regardless of board.
- firmware/src/storage.{h,cpp}: microSD on a dedicated HSPI bus + a streaming
WavWriter that writes a 44-byte PCM header and patches RIFF/data sizes on close;
plus sidecar JSON metadata writer.
- firmware/src/recorder.{h,cpp}: idle/recording state machine; creates
/recordings/<id>.wav, pumps mic chunks in on update(), finalises + writes
<id>.json (Recording schema from api/openapi.yaml) on stop.
- firmware/src/ux.{h,cpp}: debounced button (short press toggles) + status LED
patterns (idle/recording/error), active-low aware.
- firmware/src/main.cpp: wires ux + recorder; loop toggles on button and drains
the mic while recording.
- firmware/include/audio_config.h: 16 kHz mono 16-bit, chunk size, rec dir.
- firmware/include/pins.h: added XIAO PDM mic + onboard SD pins, LED active-low flag.
- state/: TODO, ARCHITECTURE, NOTES updated for M1 and the deferred follow-ups.
Why:
- Recording is the foundation every later milestone (transfer, upload, transcription)
builds on. Kept dependency-free (only core-bundled ESP_I2S + SD) for simple CI builds.
Notes:
- Not compiled locally (no PlatformIO on the dev host) or hardware-verified; Forgejo
Actions CI builds both board profiles. Follow-ups tracked in state/TODO.md:
INMP441 16-bit level calibration, and real NTP timestamps (ids are uptime-based
until M2 brings WiFi/NTP).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
//
|
|
// OpenScribe firmware entry point.
|
|
//
|
|
// M1 (recording core): boots audio + storage, then records to a WAV file on the microSD
|
|
// card, toggled by the button, with the status LED showing idle/recording/error. Each
|
|
// recording gets a sidecar JSON metadata file matching the Recording schema in
|
|
// api/openapi.yaml.
|
|
//
|
|
// Later milestones add the remaining module seams:
|
|
// power - battery ADC, charge/VBUS detect -> mode switch (M3)
|
|
// config - NVS settings (WiFi, upload target, codec, token) (M2/M3)
|
|
// net_wifi - WiFi join/reconnect + mDNS (M2)
|
|
// api_http - on-device REST server (api/openapi.yaml) (M2)
|
|
// uploader - S3/WebDAV upload when powered (M3)
|
|
// ble - GATT control + WiFi provisioning (M4)
|
|
// ota - firmware update over HTTP (M9)
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "recorder.h"
|
|
#include "ux.h"
|
|
|
|
static const char *FIRMWARE_VERSION = "0.1.0";
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(300);
|
|
Serial.printf("\nOpenScribe firmware %s booting\n", FIRMWARE_VERSION);
|
|
|
|
#if defined(OPENSCRIBE_BOARD_XIAO)
|
|
Serial.println("Board: XIAO ESP32-S3 (PDM mic + onboard SD)");
|
|
#else
|
|
Serial.println("Board: ESP32-S3 dev (I2S mic + SD module)");
|
|
#endif
|
|
|
|
if (!psramFound()) {
|
|
Serial.println("WARNING: no PSRAM detected - audio buffering needs a PSRAM board");
|
|
}
|
|
|
|
ux::begin();
|
|
|
|
if (!recorder::begin()) {
|
|
Serial.println("ERROR: audio or SD init failed - check the mic wiring and SD card");
|
|
ux::setLed(ux::Led::Error);
|
|
return; // stay in error state; loop() still services the LED
|
|
}
|
|
|
|
Serial.println("Ready. Short-press the button to start/stop recording.");
|
|
ux::setLed(ux::Led::Idle);
|
|
}
|
|
|
|
void loop() {
|
|
// Button: a short press toggles recording.
|
|
if (ux::poll()) {
|
|
if (recorder::toggle()) {
|
|
if (recorder::state() == recorder::State::Recording) {
|
|
Serial.printf("Recording started: %s\n", recorder::currentId().c_str());
|
|
ux::setLed(ux::Led::Recording);
|
|
} else {
|
|
Serial.printf("Recording stopped: %s (%lu PCM bytes)\n",
|
|
recorder::currentId().c_str(),
|
|
static_cast<unsigned long>(recorder::recordedBytes()));
|
|
ux::setLed(ux::Led::Idle);
|
|
}
|
|
} else {
|
|
Serial.println("ERROR: could not open recording file on SD");
|
|
ux::setLed(ux::Led::Error);
|
|
}
|
|
}
|
|
|
|
// While recording, drain the mic into the file.
|
|
recorder::update();
|
|
}
|