Skip to content

Commit

Permalink
Merge pull request #2 from pimoroni/feature/cdc-reset-knock
Browse files Browse the repository at this point in the history
Add CDC serial for a secret reset knock.
  • Loading branch information
Gadgetoid authored Nov 13, 2024
2 parents 51900f2 + 8950ccd commit 81904da
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 139 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
name: Linux
cache-key: linux
cmake-args: '-DPIMORONI_PICO_PATH=$GITHUB_WORKSPACE/pimoroni-pico -DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk'
apt-packages: clang-tidy gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib

runs-on: ${{matrix.os}}

Expand Down Expand Up @@ -60,11 +59,10 @@ jobs:
ref: sdk-2.0.0
submodules: true

# Linux deps
- name: Install deps
if: runner.os == 'Linux'
run: |
sudo apt update && sudo apt install ${{matrix.apt-packages}}
- name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '12.2.Rel1'

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ include(drivers/button/button)
add_executable(${NAME})

target_sources(${NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/i2s_audio.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/i2s_audio.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/board.cpp
)

Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Pico TinyUSB i2s Speaker
# Picade Max: Audio And Volume Control Board

A USB speaker firmware for the RP2040/Pico using TinyUSB and i2s.
Firmware for the Picade Max audio board. Includes encoder volume control with
push-button mute.

## Status LED

* Red - Lights up when board is muted
* Green - Should idle blink at 1s intervals, and flash quickly when audio is streaming
* Blue - Brightness indicates volume

## Updating the firmware for the board

Push the volume button in for 2 seconds and hold.

Alternatively run `echo "multiverse:_usb" > /dev/serial/by-id/usb-Pimoroni_Picade_USB_Audio_*-if02` via SSH or a terminal.

This will put the audio board into bootloader mode.

If you're using Recalbox, you may see a pop up that states a new USB device named RPI-RP2 has been discovered and asks you if you wish to initialise. You can ignore this screen.
If you're using Recalbox, you may see a pop up that states a new USB device named RPI-RP2 has been discovered and asks you if you wish to initialise. You can ignore this screen.

If you don't have any other external USB devices plugged in, you should be able to access the bootloader at:

Expand Down
8 changes: 8 additions & 0 deletions reset-picade-audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import glob
import serial

picade = glob.glob("/dev/serial/by-id/usb-Pimoroni_Picade_USB_Audio_*")[0]

device = serial.Serial(picade)

device.write(b"multiverse:_usb")
77 changes: 38 additions & 39 deletions src/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,51 @@ Button button(BUTTON, pimoroni::ACTIVE_LOW, 0);
bool pressed = false;
absolute_time_t pressed_time;

extern "C" {
void system_init() {
// Apply a modest overvolt, default is 1.10v.
// this is required for a stable 250MHz on some RP2040s
vreg_set_voltage(VREG_VOLTAGE_1_20);
sleep_ms(10);
set_sys_clock_khz(250000, true);

// DCDC PSM control
// 0: PFM mode (best efficiency)
// 1: PWM mode (improved ripple)
gpio_init(PIN_DCDC_PSM_CTRL);
gpio_set_dir(PIN_DCDC_PSM_CTRL, GPIO_OUT);
gpio_put(PIN_DCDC_PSM_CTRL, 1); // PWM mode for less Audio noise
void system_init() {
// Apply a modest overvolt, default is 1.10v.
// this is required for a stable 250MHz on some RP2040s
vreg_set_voltage(VREG_VOLTAGE_1_20);
sleep_ms(10);
set_sys_clock_khz(250000, true);

volume_control.init();
}
// DCDC PSM control
// 0: PFM mode (best efficiency)
// 1: PWM mode (improved ripple)
gpio_init(PIN_DCDC_PSM_CTRL);
gpio_set_dir(PIN_DCDC_PSM_CTRL, GPIO_OUT);
gpio_put(PIN_DCDC_PSM_CTRL, 1); // PWM mode for less Audio noise

int32_t get_volume_delta() {
return volume_control.delta();
}
volume_control.init();
}

bool get_mute_button_pressed() {
return button.read();
}
int32_t get_volume_delta() {
return volume_control.delta();
}

bool get_mute_button_pressed() {
return button.read();
}

void handle_mute_button_held() {
void handle_mute_button_held() {
#ifdef DEBUG_BOOTLOADER_SHORTCUT
bool current = button.raw();
if(current && pressed) {
if (absolute_time_diff_us(pressed_time, get_absolute_time()) >= 2000000ul) {
sleep_ms(500);
save_and_disable_interrupts();
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_ENABLE << ROSC_CTRL_ENABLE_LSB;
reset_usb_boot(0, 0);
}
} else if (current) {
pressed_time = get_absolute_time();
pressed = true;
} else {
pressed = false;
bool current = button.raw();
if(current && pressed) {
if (absolute_time_diff_us(pressed_time, get_absolute_time()) >= 2000000ul) {
sleep_ms(500);
save_and_disable_interrupts();
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_ENABLE << ROSC_CTRL_ENABLE_LSB;
reset_usb_boot(0, 0);
}
#endif
} else if (current) {
pressed_time = get_absolute_time();
pressed = true;
} else {
pressed = false;
}
#endif
}

void system_led(uint8_t r, uint8_t g, uint8_t b) {
rgbled.set_rgb(r, g, b);
}
void system_led(uint8_t r, uint8_t g, uint8_t b) {
rgbled.set_rgb(r, g, b);
}
2 changes: 1 addition & 1 deletion src/i2s_audio.c → src/i2s_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void i2s_audio_init() {

// initialize for 48k we allow changing later
static audio_format_t audio_format_48k = {
.format = AUDIO_BUFFER_FORMAT_PCM_S16,
.sample_freq = 48000,
.format = AUDIO_BUFFER_FORMAT_PCM_S16,
.channel_count = 2,
};

Expand Down
Loading

0 comments on commit 81904da

Please sign in to comment.