From 14cc93aab01770d02b20913600885862aab026b7 Mon Sep 17 00:00:00 2001 From: pszsh Date: Tue, 3 Mar 2026 21:04:21 -0800 Subject: [PATCH] Bugfixes --- .gitmodules | 3 --- CMakeLists.txt | 1 + btstack_config.h | 1 + lib/Control-Surface | 1 - main.cpp | 15 +++++++++++++++ src/encoder.h | 7 +++---- src/encoder.pio | 47 --------------------------------------------- 7 files changed, 20 insertions(+), 55 deletions(-) delete mode 160000 lib/Control-Surface delete mode 100644 src/encoder.pio diff --git a/.gitmodules b/.gitmodules index b6f5a0f..f96c7e3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lib/Control-Surface"] - path = lib/Control-Surface - url = https://github.com/tttapa/Control-Surface.git [submodule "lib/cs-midi"] path = lib/cs-midi url = https://git.else-if.org/jess/cs-midi.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a6c4411..e213de3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ target_link_libraries(fractional_looper pico_btstack_ble pico_btstack_classic pico_btstack_cyw43 + pico_btstack_flash_bank hardware_adc cs_midi ) diff --git a/btstack_config.h b/btstack_config.h index 9467c04..c5280bc 100644 --- a/btstack_config.h +++ b/btstack_config.h @@ -53,5 +53,6 @@ #define ENABLE_SOFTWARE_AES128 #define ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS +#define ENABLE_TLV_FLASH_EXPLICIT_DELETE_FIELD #endif diff --git a/lib/Control-Surface b/lib/Control-Surface deleted file mode 160000 index 3a75d0c..0000000 --- a/lib/Control-Surface +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3a75d0cc19052b6331ad72ca01e18f65111156d1 diff --git a/main.cpp b/main.cpp index 55e2347..37e5fa3 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,11 @@ #include #include "pico/stdlib.h" #include "pico/cyw43_arch.h" +#include "pico/btstack_flash_bank.h" +#include "btstack_tlv_flash_bank.h" +#include "hci.h" +#include "ble/le_device_db_tlv.h" +#include "classic/btstack_link_key_db_tlv.h" #include #include "encoder.h" @@ -39,7 +44,17 @@ int main() { } printf("FractionalLooper: CYW43 initialized\n"); + // Persistent bonding storage — survives power cycles + static btstack_tlv_flash_bank_t tlv_context; + const hal_flash_bank_t *flash_bank = pico_flash_bank_instance(); + const btstack_tlv_t *tlv_impl = btstack_tlv_flash_bank_init_instance( + &tlv_context, flash_bank, NULL); + btstack_tlv_set_instance(tlv_impl, &tlv_context); + le_device_db_tlv_configure(tlv_impl, &tlv_context); + hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context)); + cs::BluetoothMIDI_Interface ble; + ble.ble_settings.initiate_security = true; ble.begin(); printf("BLE MIDI started\n"); diff --git a/src/encoder.h b/src/encoder.h index 18aa203..8c143ff 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -4,10 +4,9 @@ #define NUM_ENCODERS 4 -// A/B swapped on encoders 0-2 to correct rotation direction. -// Encoder 0 rewired to GPIO 17/18. Encoder 3 left as-is (already correct). -static constexpr uint8_t ENC_PIN_A[NUM_ENCODERS] = {17, 5, 8, 9}; -static constexpr uint8_t ENC_PIN_B[NUM_ENCODERS] = {18, 3, 6, 11}; +// A/B swapped on encoders +static constexpr uint8_t ENC_PIN_A[NUM_ENCODERS] = {2, 5, 8, 9}; +static constexpr uint8_t ENC_PIN_B[NUM_ENCODERS] = {0, 3, 6, 11}; static constexpr uint8_t BTN_PINS[NUM_ENCODERS] = {1, 4, 7, 10}; void encoders_init(); diff --git a/src/encoder.pio b/src/encoder.pio deleted file mode 100644 index 448507a..0000000 --- a/src/encoder.pio +++ /dev/null @@ -1,47 +0,0 @@ -.pio_version 0 - -; Quadrature encoder decoder for non-adjacent A/B pins. -; -; Pin layout per encoder: A = in_base+0, (switch = in_base+1), B = in_base+2. -; On each B transition, samples A and B into the ISR and pushes to RX FIFO. -; Software decodes direction from the state table. -; -; Set clock divider for ~10 kHz to filter mechanical bounce. - -.program encoder -.wrap_target - wait 1 pin 2 ; wait for B (base+2) to go high - in pins, 3 ; sample A, switch, B (3 bits from base) - push noblock - wait 0 pin 2 ; wait for B to go low - in pins, 3 ; sample again - push noblock -.wrap - -% c-sdk { -#include "hardware/clocks.h" -#include "hardware/gpio.h" - -static inline void encoder_program_init(PIO pio, uint sm, uint offset, - uint pin_a) { - // Pin layout: A = pin_a, switch = pin_a+1, B = pin_a+2 - uint pin_sw = pin_a + 1; - uint pin_b = pin_a + 2; - - pio_gpio_init(pio, pin_a); - pio_gpio_init(pio, pin_b); - gpio_pull_up(pin_a); - gpio_pull_up(pin_b); - pio_sm_set_consecutive_pindirs(pio, sm, pin_a, 3, false); - - pio_sm_config c = encoder_program_get_default_config(offset); - sm_config_set_in_pins(&c, pin_a); - sm_config_set_in_shift(&c, false, false, 32); - - float div = (float)clock_get_hz(clk_sys) / 10000.0f; - sm_config_set_clkdiv(&c, div); - - pio_sm_init(pio, sm, offset, &c); - pio_sm_set_enabled(pio, sm, true); -} -%}