From a41db06404670b18c7a0809009d611a4bc807e90 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sun, 25 Oct 2026 09:23:27 +0100 Subject: Initial commit, firmware skeleton --- firmware/src/adc.hpp | 25 +++++++++++++++++++++++++ firmware/src/debug.hpp | 12 ++++++++++++ firmware/src/display.hpp | 22 ++++++++++++++++++++++ firmware/src/firmware.cpp | 35 +++++++++++++++++++++++++++++++++++ firmware/src/midi.hpp | 15 +++++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 firmware/src/adc.hpp create mode 100644 firmware/src/debug.hpp create mode 100644 firmware/src/display.hpp create mode 100644 firmware/src/firmware.cpp create mode 100644 firmware/src/midi.hpp (limited to 'firmware/src') diff --git a/firmware/src/adc.hpp b/firmware/src/adc.hpp new file mode 100644 index 0000000..a3bd0b0 --- /dev/null +++ b/firmware/src/adc.hpp @@ -0,0 +1,25 @@ +#include +#include + +namespace adc +{ + +struct Sample +{ + std::uint8_t value {0}; + bool changed {false}; +}; + +void +init() +{ +} + +std::array +get_samples() +{ + // TODO: scale 12-bit range into MIDI 7-bit range with hysteresis + return std::array{{{}, {}}}; +} + +} diff --git a/firmware/src/debug.hpp b/firmware/src/debug.hpp new file mode 100644 index 0000000..856da38 --- /dev/null +++ b/firmware/src/debug.hpp @@ -0,0 +1,12 @@ +#include + +namespace debug +{ + +void +init() +{ + stdio_init_all(); +} + +} diff --git a/firmware/src/display.hpp b/firmware/src/display.hpp new file mode 100644 index 0000000..e2dabf2 --- /dev/null +++ b/firmware/src/display.hpp @@ -0,0 +1,22 @@ +#include "hardware/i2c.h" + +namespace display +{ + +// I2C0 on GPIO8 (SDA) and GPIO9 (SCL) running at 400KHz +constexpr auto I2C_PORT = i2c0; +constexpr unsigned I2C_SDA = 8; +constexpr unsigned I2C_SCL = 9; + +void +init() +{ + i2c_init(I2C_PORT, 400*1000); + + gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); + gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); + gpio_pull_up(I2C_SDA); + gpio_pull_up(I2C_SCL); +} + +} diff --git a/firmware/src/firmware.cpp b/firmware/src/firmware.cpp new file mode 100644 index 0000000..fc5bdd7 --- /dev/null +++ b/firmware/src/firmware.cpp @@ -0,0 +1,35 @@ +#include "pico/stdlib.h" + +#include "debug.hpp" +#include "display.hpp" +#include "adc.hpp" +#include "midi.hpp" + +void +update() +{ + for (auto const [value, changed] : adc::get_samples()) + { + if (!changed) continue; + + midi::send_message(); + // update framebuffer + } + + // send frame to display +} + +[[noreturn]] int +main() +{ + debug::init(); + display::init(); + adc::init(); + midi::init(); + + while (true) + { + update(); + sleep_ms(50); + } +} diff --git a/firmware/src/midi.hpp b/firmware/src/midi.hpp new file mode 100644 index 0000000..c2d639a --- /dev/null +++ b/firmware/src/midi.hpp @@ -0,0 +1,15 @@ + +namespace midi +{ + +void +init() +{ +} + +void +send_message() +{ +} + +} -- cgit v1.2.3