Fix Phase 1 skeleton: add build system, fix compilation errors

- Add CMakeLists.txt for project and all components
- Add idf_component.yml with TinyUSB dependency
- Create switch_stub.cpp implementation
- Fix app_task.h to match .cpp implementation (2-param signature)
- Fix led_stub.h/cpp class naming (DefaultLedStub)
- Fix midi_transport.cpp TinyUSB API usage (tud_midi_*)
- Move main.cpp to main/ directory
- Add sdkconfig.defaults for ESP32-S3
This commit is contained in:
2026-06-23 08:59:53 +00:00
parent db4b63c755
commit 458cb5060f
15 changed files with 234 additions and 200 deletions
+3
View File
@@ -0,0 +1,3 @@
idf_component_register(SRCS "led_stub.cpp" "switch_stub.cpp"
INCLUDE_DIRS "."
REQUIRES )
+41 -55
View File
@@ -1,62 +1,48 @@
// hal/led_stub.cpp
// components/hal/led_stub.cpp
#include "hal/led_stub.h"
#include "esp_log.h"
static const char* TAG = "led_stub";
class DefaultLedStub : public LedStub {
private:
LedState led_states[10]; // Support up to 10 LEDs
bool initialized;
public:
DefaultLedStub() : initialized(false) {
// Initialize all LEDs to off state
for (int i = 0; i < 10; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
}
DefaultLedStub::DefaultLedStub() : initialized(false) {
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
led_states[i].note = 0;
led_states[i].channel = 0;
led_states[i].timestamp = 0;
}
void begin() override {
// GPIO initialization would go here
// For Phase 1, this is a stub
initialized = true;
ESP_LOGI(TAG, "LED stub initialized (GPIO pins not configured yet)");
}
void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) override {
if (!initialized) return;
// For Phase 1, we assume note 0-9 maps directly to LED 0-9
// This is configurable in the PadMapping
uint8_t led_index = note_to_index(note);
if (led_index < 10) {
led_states[led_index].note = note;
led_states[led_index].channel = channel;
led_states[led_index].velocity = velocity;
led_states[led_index].active = (velocity > 0);
led_states[led_index].timestamp = 0; // TODO: Add proper timestamp
ESP_LOGI(TAG, "LED STATE: Note %d -> LED %d Channel %d Velocity %d (%s)",
note, led_index, channel, velocity,
velocity > 0 ? "ON" : "OFF");
} else {
ESP_LOGW(TAG, "LED index out of range: %d (Note: %d)", led_index, note);
}
}
void clear_all() override {
for (int i = 0; i < 10; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
}
ESP_LOGI(TAG, "All LEDs cleared");
}
};
}
// Factory function to create the default LED stub
LedStub* create_led_stub() {
return new DefaultLedStub();
}
void DefaultLedStub::begin() {
initialized = true;
ESP_LOGI(TAG, "LED stub initialized (GPIO pins not configured yet)");
}
void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) {
if (!initialized) return;
uint8_t led_index = note_to_index(note);
if (led_index < NUM_LEDS) {
led_states[led_index].note = note;
led_states[led_index].channel = channel;
led_states[led_index].velocity = velocity;
led_states[led_index].active = (velocity > 0);
led_states[led_index].timestamp = 0;
ESP_LOGI(TAG, "LED STATE: Note %d -> LED %d Channel %d Velocity %d (%s)",
note, led_index, channel, velocity,
velocity > 0 ? "ON" : "OFF");
} else {
ESP_LOGW(TAG, "LED index out of range: %d (Note: %d)", led_index, note);
}
}
void DefaultLedStub::clear_all() {
for (int i = 0; i < NUM_LEDS; i++) {
led_states[i].active = false;
led_states[i].velocity = 0;
}
ESP_LOGI(TAG, "All LEDs cleared");
}
+18 -4
View File
@@ -1,6 +1,8 @@
// hal/led_stub.h
// components/hal/led_stub.h
#pragma once
#include <cstdint>
class LedStub {
public:
virtual ~LedStub() {}
@@ -11,8 +13,6 @@ public:
// Helper function to map MIDI note to LED index
virtual uint8_t note_to_index(uint8_t note) {
// Default implementation - direct mapping
// Can be overridden by specific implementations
return note;
}
};
@@ -24,4 +24,18 @@ struct LedState {
uint8_t velocity; // Color/brightness (0-127)
uint32_t timestamp; // When state was set
bool active; // Current on/off state
};
};
// Default stub implementation
class DefaultLedStub : public LedStub {
private:
static const uint8_t NUM_LEDS = 10;
LedState led_states[NUM_LEDS];
bool initialized;
public:
DefaultLedStub();
void begin() override;
void set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) override;
void clear_all() override;
};
+41
View File
@@ -0,0 +1,41 @@
// components/hal/switch_stub.cpp
#include "hal/switch_stub.h"
#include "esp_log.h"
static const char* TAG = "switch_stub";
DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].id = i;
switch_states[i].gpio_pin = 0;
switch_states[i].current_state = false;
switch_states[i].previous_state = false;
switch_states[i].last_change_time = 0;
switch_states[i].debounce_time = 50;
}
}
void DefaultSwitchStub::begin() {
initialized = true;
ESP_LOGI(TAG, "Switch stub initialized (GPIO pins not configured yet)");
}
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
if (!initialized || switch_id >= NUM_SWITCHES) {
return false;
}
return switch_states[switch_id].current_state;
}
void DefaultSwitchStub::configure_switch(uint8_t switch_id, uint8_t gpio_pin) {
if (switch_id >= NUM_SWITCHES) return;
switch_states[switch_id].gpio_pin = gpio_pin;
ESP_LOGI(TAG, "Switch %d configured to GPIO %d", switch_id, gpio_pin);
}
void DefaultSwitchStub::set_debounce_time(uint32_t time_ms) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].debounce_time = time_ms;
}
ESP_LOGI(TAG, "Debounce time set to %lu ms", time_ms);
}
+19 -2
View File
@@ -1,6 +1,8 @@
// hal/switch_stub.h
// components/hal/switch_stub.h
#pragma once
#include <cstdint>
class SwitchStub {
public:
virtual ~SwitchStub() {}
@@ -21,4 +23,19 @@ struct SwitchState {
bool previous_state; // Previous state (for debounce)
uint32_t last_change_time; // Timestamp of last state change
uint32_t debounce_time; // Debounce time in ms
};
};
// Default stub implementation
class DefaultSwitchStub : public SwitchStub {
private:
static const uint8_t NUM_SWITCHES = 10;
SwitchState switch_states[NUM_SWITCHES];
bool initialized;
public:
DefaultSwitchStub();
void begin() override;
bool is_pressed(uint8_t switch_id) override;
void configure_switch(uint8_t switch_id, uint8_t gpio_pin) override;
void set_debounce_time(uint32_t time_ms) override;
};