From 48210907f6f5160ce6748dc2fbe262f786bab6dc Mon Sep 17 00:00:00 2001 From: Cheru Berhanu Date: Sun, 27 Oct 2024 11:08:32 -0400 Subject: [PATCH] adapt spade to work w/ HAL (depends on #2450) (#2451) * adapt spade to work w/ HAL (depends on #2450) * Update CMakeLists.txt * consolidate gardenshed & make work w/ all firmwares (#2467) --- firmware/c_scaffold/docker/buildScript.sh | 15 ++ firmware/c_scaffold/docker/dockerfile | 15 ++ .../c_scaffold/docker/importBuildRepos.sh | 10 ++ firmware/c_scaffold/gardenshed.py | 1 + firmware/spade/docker/buildScript.sh | 12 +- firmware/spade/gardenshed.py | 1 + firmware/spade/src/CMakeLists.txt | 3 - firmware/spade/src/pc/jerry/refresh.sh | 2 +- firmware/spade/src/pc/main.c | 16 +- firmware/spade/src/rpi/CMakeLists.txt | 40 +++-- firmware/spade/src/rpi/audio.c | 65 ------- firmware/spade/src/rpi/jerry/refresh.sh | 2 +- firmware/spade/src/rpi/main.c | 164 ++++-------------- firmware/spade/src/shared/js_runtime/js.h | 4 +- .../spade/src/shared/sprig_engine/engine.js | 26 +-- firmware/sprig_hal/CMakeLists.txt | 2 +- scripts/gardenshed.py | 73 ++++++++ scripts/gardenshed/README.md | 10 -- scripts/gardenshed/build.sh | 46 ----- scripts/gardenshed/gardenshed.py | 27 --- scripts/gardenshed/gdb-client.sh | 31 ---- scripts/gardenshed/gdb-server.sh | 3 - scripts/gardenshed/log.sh | 9 - scripts/gardenshed/reflash.sh | 3 - scripts/gardenshed/restart.sh | 3 - 25 files changed, 201 insertions(+), 382 deletions(-) create mode 100644 firmware/c_scaffold/docker/buildScript.sh create mode 100644 firmware/c_scaffold/docker/dockerfile create mode 100644 firmware/c_scaffold/docker/importBuildRepos.sh create mode 120000 firmware/c_scaffold/gardenshed.py create mode 120000 firmware/spade/gardenshed.py delete mode 100644 firmware/spade/src/rpi/audio.c create mode 100644 scripts/gardenshed.py delete mode 100644 scripts/gardenshed/README.md delete mode 100755 scripts/gardenshed/build.sh delete mode 100644 scripts/gardenshed/gardenshed.py delete mode 100755 scripts/gardenshed/gdb-client.sh delete mode 100755 scripts/gardenshed/gdb-server.sh delete mode 100755 scripts/gardenshed/log.sh delete mode 100755 scripts/gardenshed/reflash.sh delete mode 100755 scripts/gardenshed/restart.sh diff --git a/firmware/c_scaffold/docker/buildScript.sh b/firmware/c_scaffold/docker/buildScript.sh new file mode 100644 index 0000000000..7ed6079923 --- /dev/null +++ b/firmware/c_scaffold/docker/buildScript.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +cd ~/sprig/firmware/c_scaffold + +mkdir -p build +cd build + +cmake .. +cmake --build . + +cd .. + +cp build/c_scaffold.uf2 ~/firmware.uf2 +cp ~/firmware.uf2 firmware.uf2 +cp build/c_scaffold.elf ~/firmware.elf diff --git a/firmware/c_scaffold/docker/dockerfile b/firmware/c_scaffold/docker/dockerfile new file mode 100644 index 0000000000..891a9e1829 --- /dev/null +++ b/firmware/c_scaffold/docker/dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.19 + +RUN apk add git python3 clang make cmake entr uglify-js gcc-arm-none-eabi g++-arm-none-eabi gdb-multiarch gcc + +COPY ./importBuildRepos.sh /opt/importBuildRepos.sh + +RUN chmod +x /opt/importBuildRepos.sh + +RUN /opt/importBuildRepos.sh + +COPY ./buildScript.sh /opt/buildScript.sh + +RUN chmod +x /opt/buildScript.sh + +CMD /opt/buildScript.sh \ No newline at end of file diff --git a/firmware/c_scaffold/docker/importBuildRepos.sh b/firmware/c_scaffold/docker/importBuildRepos.sh new file mode 100644 index 0000000000..19e265c2b9 --- /dev/null +++ b/firmware/c_scaffold/docker/importBuildRepos.sh @@ -0,0 +1,10 @@ +mkdir ~/raspberrypi +cd ~/raspberrypi +git clone -b 1.3.1 https://github.com/raspberrypi/pico-sdk.git +git clone https://github.com/raspberrypi/pico-extras.git +cd pico-sdk +git checkout 7070d230c0cdf1add83fa86b6832b47b2da47788 +git submodule update --init +cd ../pico-extras +git checkout 09c64d509f1d7a49ceabde699ed6c74c77e195a1 +git submodule update --init \ No newline at end of file diff --git a/firmware/c_scaffold/gardenshed.py b/firmware/c_scaffold/gardenshed.py new file mode 120000 index 0000000000..419ec946fe --- /dev/null +++ b/firmware/c_scaffold/gardenshed.py @@ -0,0 +1 @@ +../../scripts/gardenshed.py \ No newline at end of file diff --git a/firmware/spade/docker/buildScript.sh b/firmware/spade/docker/buildScript.sh index 2ba423c9c9..5999b8e777 100644 --- a/firmware/spade/docker/buildScript.sh +++ b/firmware/spade/docker/buildScript.sh @@ -1,7 +1,9 @@ -cd ~/spade +#!/usr/bin/env sh + +cd ~/sprig/firmware/spade ./src/pc/jerry/refresh.sh -cd ~/spade +cd ~/sprig/firmware/spade ./src/rpi/jerry/refresh.sh touch game.js @@ -13,5 +15,7 @@ mkdir -p src/shared/sprig_engine/build cmake --preset=rpi cmake --build --preset=rpi -cp rpi_build/src/spade.uf2 ~/spade -cp rpi_build/src/spade.elf ~/spade +cp rpi_build/src/spade.uf2 ~/firmware.uf2 +cp ~/firmware.uf2 firmware.uf2 +cp rpi_build/src/spade.elf ~/firmware.elf +cp ~/firmware.elf firmware.elf \ No newline at end of file diff --git a/firmware/spade/gardenshed.py b/firmware/spade/gardenshed.py new file mode 120000 index 0000000000..419ec946fe --- /dev/null +++ b/firmware/spade/gardenshed.py @@ -0,0 +1 @@ +../../scripts/gardenshed.py \ No newline at end of file diff --git a/firmware/spade/src/CMakeLists.txt b/firmware/spade/src/CMakeLists.txt index 07b307e59a..7f1e36efe9 100644 --- a/firmware/spade/src/CMakeLists.txt +++ b/firmware/spade/src/CMakeLists.txt @@ -13,9 +13,6 @@ target_link_libraries(spade include_directories(${SPADE_TARGET}/jerry/include) include_directories(./) -pico_enable_stdio_usb(${PROJECT_NAME} 1) -pico_enable_stdio_uart(${PROJECT_NAME} 1) - file(READ version.json VERSION_JSON) string(JSON VERSION GET ${VERSION_JSON} version) diff --git a/firmware/spade/src/pc/jerry/refresh.sh b/firmware/spade/src/pc/jerry/refresh.sh index 516c175757..ff3b672235 100755 --- a/firmware/spade/src/pc/jerry/refresh.sh +++ b/firmware/spade/src/pc/jerry/refresh.sh @@ -16,7 +16,7 @@ python3 jerryscript/tools/build.py \ --jerry-cmdline=OFF make -C $(pwd)/example_build install\ -cd ~/spade/src/pc/jerry +cd ~/sprig/firmware/spade/src/pc/jerry cp -r ~/jerryscript_build/example_build/lib ./ rm -rf include cp -r ~/jerryscript_build/example_install/include ./ diff --git a/firmware/spade/src/pc/main.c b/firmware/spade/src/pc/main.c index d284c60756..99b78ee85b 100644 --- a/firmware/spade/src/pc/main.c +++ b/firmware/spade/src/pc/main.c @@ -145,14 +145,14 @@ static void keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bo mfb_close(window); } - if (key == KB_KEY_W) spade_call_press( 5); // map_move(map_get_first('p'), 0, -1); - if (key == KB_KEY_S) spade_call_press( 7); // map_move(map_get_first('p'), 0, 1); - if (key == KB_KEY_A) spade_call_press( 6); // map_move(map_get_first('p'), 1, 0); - if (key == KB_KEY_D) spade_call_press( 8); // map_move(map_get_first('p'), -1, 0); - if (key == KB_KEY_I) spade_call_press(12); // map_move(map_get_first('p'), 0, -1); - if (key == KB_KEY_K) spade_call_press(14); // map_move(map_get_first('p'), 0, 1); - if (key == KB_KEY_J) spade_call_press(13); // map_move(map_get_first('p'), 1, 0); - if (key == KB_KEY_L) spade_call_press(15); // map_move(map_get_first('p'), -1, 0); + if (key == KB_KEY_W) spade_call_press(0); // map_move(map_get_first('p'), 0, -1); + if (key == KB_KEY_S) spade_call_press(1); // map_move(map_get_first('p'), 0, 1); + if (key == KB_KEY_A) spade_call_press(2); // map_move(map_get_first('p'), 1, 0); + if (key == KB_KEY_D) spade_call_press(3); // map_move(map_get_first('p'), -1, 0); + if (key == KB_KEY_I) spade_call_press(4); // map_move(map_get_first('p'), 0, -1); + if (key == KB_KEY_K) spade_call_press(5); // map_move(map_get_first('p'), 0, 1); + if (key == KB_KEY_J) spade_call_press(6); // map_move(map_get_first('p'), 1, 0); + if (key == KB_KEY_L) spade_call_press(7); // map_move(map_get_first('p'), -1, 0); } #endif diff --git a/firmware/spade/src/rpi/CMakeLists.txt b/firmware/spade/src/rpi/CMakeLists.txt index 8ab9ccce77..b94fdb568c 100644 --- a/firmware/spade/src/rpi/CMakeLists.txt +++ b/firmware/spade/src/rpi/CMakeLists.txt @@ -1,27 +1,35 @@ pico_sdk_init() -add_definitions(-DSPADE_EMBEDDED -DSPADE_AUDIO -DPICO_NO_BI_PROGRAM_BUILD_DATE) +add_definitions(-DSPADE_EMBEDDED -DSPADE_AUDIO) set(DCMAKE_BUILD_TYPE Release) target_compile_definitions(spade PRIVATE - # compile time configuration of I2S - PICO_AUDIO_I2S_MONO_INPUT=1 - USE_AUDIO_I2S=1 - PICO_AUDIO_I2S_DATA_PIN=9 - PICO_AUDIO_I2S_CLOCK_PIN_BASE=10 - # PICO_DEFAULT_UART=0 - # PICO_DEFAULT_UART_TX_PIN=28 - # PICO_DEFAULT_UART_RX_PIN=29 + # compile time configuration of I2S + PICO_AUDIO_I2S_MONO_INPUT=1 + USE_AUDIO_I2S=1 + PICO_AUDIO_I2S_DATA_PIN=9 + PICO_AUDIO_I2S_CLOCK_PIN_BASE=10 + # PICO_DEFAULT_UART=0 + # PICO_DEFAULT_UART_TX_PIN=28 + # PICO_DEFAULT_UART_RX_PIN=29 ) +pico_enable_stdio_usb(${PROJECT_NAME} 1) +pico_enable_stdio_uart(${PROJECT_NAME} 1) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../sprig_hal sprig_hal) + target_link_libraries(spade PRIVATE - pico_stdlib - pico_audio_i2s - pico_multicore - hardware_spi - hardware_timer - hardware_pwm - hardware_adc + pico_stdlib + pico_audio_i2s + pico_multicore + hardware_spi + hardware_timer + hardware_pwm + hardware_adc + sprig_hal ) +add_compile_definitions(PICO_HEAP_SIZE=16384) + pico_enable_stdio_usb(spade 1) pico_enable_stdio_uart(spade 0) diff --git a/firmware/spade/src/rpi/audio.c b/firmware/spade/src/rpi/audio.c deleted file mode 100644 index d57b8c37d0..0000000000 --- a/firmware/spade/src/rpi/audio.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Driver for the Raspberry Pi audio system. All actual sound generation code is in shared/audio/piano.c. - */ - -#include "shared/audio/piano.c" - -#include "hardware/clocks.h" -#include "hardware/structs/clocks.h" -#include "pico/audio_i2s.h" -#include "pico/binary_info.h" -bi_decl(bi_3pins_with_names(PICO_AUDIO_I2S_DATA_PIN, "I2S DIN", PICO_AUDIO_I2S_CLOCK_PIN_BASE, "I2S BCK", PICO_AUDIO_I2S_CLOCK_PIN_BASE+1, "I2S LRCK")); - -static struct audio_buffer_pool *audio_buffer_pool_init() { - - static audio_format_t audio_format = { - .format = AUDIO_BUFFER_FORMAT_PCM_S16, - .sample_freq = SAMPLES_PER_SECOND, - .channel_count = 1, - }; - - static struct audio_buffer_format producer_format = { - .format = &audio_format, - .sample_stride = 2 - }; - - struct audio_buffer_pool *producer_pool = audio_new_producer_pool(&producer_format, 3, - SAMPLES_PER_BUFFER); // todo correct size - bool __unused ok; - const struct audio_format *output_format; - - struct audio_i2s_config config = { - .data_pin = PICO_AUDIO_I2S_DATA_PIN, - .clock_pin_base = PICO_AUDIO_I2S_CLOCK_PIN_BASE, - .dma_channel = 0, - .pio_sm = 0, - }; - - output_format = audio_i2s_setup(&audio_format, &config); - if (!output_format) { - panic("PicoAudio: Unable to open audio device.\n"); - } - - ok = audio_i2s_connect(producer_pool); - assert(ok); - audio_i2s_set_enabled(true); - - return producer_pool; -} - -struct audio_buffer_pool *audio_bufpool; - -void audio_init(void) { - audio_bufpool = audio_buffer_pool_init(); -} - -void audio_try_push_samples(void) { - struct audio_buffer *buffer = take_audio_buffer(audio_bufpool, false); - if (buffer == NULL) return; - - piano_fill_sample_buf((int16_t *)buffer->buffer->bytes, buffer->max_sample_count); - buffer->sample_count = buffer->max_sample_count; - - // send to PIO DMA - give_audio_buffer(audio_bufpool, buffer); -} diff --git a/firmware/spade/src/rpi/jerry/refresh.sh b/firmware/spade/src/rpi/jerry/refresh.sh index 2eaa8db11f..89c91f64ae 100755 --- a/firmware/spade/src/rpi/jerry/refresh.sh +++ b/firmware/spade/src/rpi/jerry/refresh.sh @@ -22,7 +22,7 @@ python3 jerryscript/tools/build.py \ --jerry-cmdline=OFF make -C $(pwd)/example_build install\ -cd ~/spade/src/rpi/jerry +cd ~/sprig/firmware/spade/src/rpi/jerry cp -r ~/jerryscript_build/example_build/lib/ lib/ # cp ~/jerryscript_build/example_install/include rm -rf include diff --git a/firmware/spade/src/rpi/main.c b/firmware/spade/src/rpi/main.c index 105a0bb53c..7a236954bd 100644 --- a/firmware/spade/src/rpi/main.c +++ b/firmware/spade/src/rpi/main.c @@ -1,9 +1,6 @@ #include "pico/stdlib.h" -#include "hardware/pwm.h" -#include "hardware/spi.h" #include "hardware/timer.h" #include "hardware/watchdog.h" -#include "hardware/adc.h" #include "pico/util/queue.h" #include "pico/multicore.h" #include "jerryscript.h" @@ -26,12 +23,9 @@ // Debugging shortcut #define yell puts -#ifdef SPADE_AUDIO - #include "audio.c" -#endif +#include "HAL.h" // More firmware stuiff -#include "ST7735_TFT.h" #include "upload.h" // Other imports @@ -40,6 +34,8 @@ #include "shared/js_runtime/jerry_mem.h" #include "shared/js_runtime/jerryxx.c" #include "shared/js_runtime/js.h" +#include "shared/audio/piano.c" +#include "shared/version.h" // screen is 20 characters wide #define SCREEN_WIDTH_CHARS 20 @@ -54,9 +50,9 @@ static void fatal_error() { while (1) { text_clear(); render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + fill_start(); + render(write_pixel); + fill_end(); } } #include "shared/ui/errorbuf.h" @@ -76,21 +72,8 @@ typedef struct { uint8_t last_state; uint8_t ring_i; } ButtonState; -// W, S, A, D, I, K, J, L -uint button_pins[] = { 5, 7, 6, 8, 12, 14, 13, 15 }; -static ButtonState button_states[ARR_LEN(button_pins)] = {0}; -typedef enum { - Button_W, - Button_S, - Button_A, - Button_D, - Button_I, - Button_K, - Button_J, - Button_L, - Button_None -} Button; +static ButtonState button_states[8] = {0}; static bool button_history_read(ButtonState *bs, int i) { // We want to store bools compactly so we have to do some bit twiddling. @@ -104,25 +87,17 @@ static void button_history_write(ButtonState *bs, int i, bool value) { bs->history[i/8] &= ~(1 << (i % 8)); } -static void button_init(void) { - for (int i = 0; i < ARR_LEN(button_pins); i++) { - ButtonState *bs = button_states + i; - gpio_set_dir(button_pins[i], GPIO_IN); - gpio_pull_up(button_pins[i]); - } -} - /** * Poll the buttons and push any keypresses to the main core. * * (Should be run in a loop on a non-primary core.) */ static void button_poll(void) { - for (int i = 0; i < ARR_LEN(button_pins); i++) { + for (int i = 0; i < 8; i++) { ButtonState *bs = button_states + i; bs->ring_i = (bs->ring_i + 1) % HISTORY_LEN; // Incrememnt ringbuffer index - button_history_write(bs, bs->ring_i, gpio_get(button_pins[i])); + button_history_write(bs, bs->ring_i, get_button(i)); // up is true if more than 5/6 are true int up = 0; @@ -135,63 +110,19 @@ static void button_poll(void) { bs->last_state = up; if (!up) { // Send the keypress to the main core - multicore_fifo_push_blocking(button_pins[i]); + multicore_fifo_push_blocking(i); } } } } -// Turn on the power lights and dim them with PWM. -static void power_lights() { - // left white light - const int pin_num_0 = 28; - gpio_set_function(pin_num_0, GPIO_FUNC_PWM); - uint slice_num_0 = pwm_gpio_to_slice_num(pin_num_0); - pwm_set_enabled(slice_num_0, true); - pwm_set_gpio_level(pin_num_0, 65535/8); - - // right blue light - // const pin_num_1 = 4; - // gpio_set_function(pin_num_1, GPIO_FUNC_PWM); - // uint slice_num_1 = pwm_gpio_to_slice_num(pin_num_1); - // pwm_set_enabled(slice_num_1, true); - // pwm_set_gpio_level(pin_num_1, 65535/4); -} - // Entry point for the second core that polls the buttons. static void core1_entry(void) { - button_init(); - while (1) { button_poll(); } } -/** - * Seed the random number generator with entropy from - * random electricity as well as temperature readings. - */ -static void rng_init(void) { - adc_init(); - uint32_t seed = 0; - - // Read some random electricity - for (int i = 0; i < 4; i++) { - adc_select_input(4); - sleep_ms(1); - seed ^= adc_read(); - } - - // Read some temperature data - adc_set_temp_sensor_enabled(true); - adc_select_input(4); - sleep_ms(1); - seed ^= adc_read(); - adc_set_temp_sensor_enabled(false); - - srand(seed); -} - char serial_commands[][128] = { "UPLOAD", "VERSION", @@ -285,27 +216,9 @@ typedef enum { return 10; } - static Button get_button_press() { + static Sprig_Button get_button_press() { if (!multicore_fifo_rvalid()) return Button_None; - - switch (multicore_fifo_pop_blocking()) { - case 5: - return Button_W; - case 7: - return Button_S; - case 6: - return Button_A; - case 8: - return Button_D; - case 12: - return Button_I; - case 14: - return Button_K; - case 13: - return Button_J; - case 15: - return Button_L; - } + return (Sprig_Button) multicore_fifo_pop_blocking(); } typedef struct { @@ -429,7 +342,7 @@ void update_welcome_state(Welcome_State* welcome_state) { set_game(welcome_state->games[welcome_state->games_i]); } - Button button_pressed = get_button_press(); + Sprig_Button button_pressed = get_button_press(); if (welcome_state->screen == GAME_MENU) switch (button_pressed) { @@ -463,18 +376,27 @@ void update_welcome_state(Welcome_State* welcome_state) { } } +void audio_try_push_samples(void) { + struct audio_buffer *buffer = get_audio_buffer(false); + if (buffer == NULL) return; + + piano_fill_sample_buf((int16_t *)buffer->buffer->bytes, buffer->max_sample_count); + buffer->sample_count = buffer->max_sample_count; + + // send to PIO DMA + push_audio_buffer( buffer); +} + int main() { timer_hw->dbgpause = 0; // Overclock the RP2040! set_sys_clock_khz(270000, true); - errorbuf_color = color16(0, 255, 255); // cyan + hw_init(); // init HAL + stdio_init_all(); // Init serial port - power_lights(); // Turn on the power lights - stdio_init_all(); // Init serial port - st7735_init(); // Init display - rng_init(); // Init RNG + errorbuf_color = color16(0, 255, 255); // cyan // Init JerryScript jerry_init(JERRY_INIT_MEM_STATS); @@ -487,17 +409,6 @@ int main() { multicore_launch_core1(core1_entry); - /** - * We get a bunch of fake keypresses at startup, so we need to - * drain them from the FIFO queue. - * - * What really needs to be done here is to have button_init - * record when it starts so that we can ignore keypresses after - * that timestamp. - */ - sleep_ms(50); - while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking(); - Welcome_State welcome_state = { .screen = NEW_SLOT, .games = malloc(METADATA_MAX_ENTRIES * sizeof(Game)), // leaks but it's fine since lifetime=program @@ -518,9 +429,9 @@ int main() { strcpy(errorbuf, delete_confirm_screen); render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + fill_start(); + render(write_pixel); + fill_end(); load_new_scripts(); } @@ -544,7 +455,6 @@ int main() { .song_free = piano_jerry_song_free, .song_chars = piano_jerry_song_chars, }); - audio_init(); #endif // Current time for timer handling (see frame_cb in shared/sprig_engine/engine.js) @@ -555,7 +465,7 @@ int main() { while (1) { // Handle any new button presses while (multicore_fifo_rvalid()) { - spade_call_press(multicore_fifo_pop_blocking()); + spade_call_press(get_button_press()); } // Run async code @@ -577,9 +487,9 @@ int main() { // Render render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + fill_start(); + render(write_pixel); + fill_end(); } /** @@ -607,9 +517,9 @@ int main() { " \n" " sprig.hackclub.com \n"); render_errorbuf(); - st7735_fill_start(); - render(st7735_fill_send); - st7735_fill_finish(); + fill_start(); + render(write_pixel); + fill_end(); /** * Watchdog is a mechanism designed to catch infinite loops. It will diff --git a/firmware/spade/src/shared/js_runtime/js.h b/firmware/spade/src/shared/js_runtime/js.h index 84e0bc7975..1dcfb371c5 100644 --- a/firmware/spade/src/shared/js_runtime/js.h +++ b/firmware/spade/src/shared/js_runtime/js.h @@ -118,11 +118,11 @@ static void js_promises(void) { } } -static void spade_call_press(int pin) { +static void spade_call_press(Sprig_Button button) { if (!spade_state.press_cb) return; jerry_value_t this_value = jerry_create_undefined(); - jerry_value_t args[] = { jerry_create_number(pin) }; + jerry_value_t args[] = { jerry_create_number(button) }; jerry_value_t res = jerry_call_function( spade_state.press_cb, diff --git a/firmware/spade/src/shared/sprig_engine/engine.js b/firmware/spade/src/shared/sprig_engine/engine.js index a11b56da84..64dc0fd248 100644 --- a/firmware/spade/src/shared/sprig_engine/engine.js +++ b/firmware/spade/src/shared/sprig_engine/engine.js @@ -97,26 +97,8 @@ exports.afterInput = fn => (console.log('engine.js:afterInputs'), afterInputs.pu // exports.afterInput = fn => afterInputs.push(fn); const button = { - pinToHandlers: { - "5": [], - "7": [], - "6": [], - "8": [], - "12": [], - "14": [], - "13": [], - "15": [], - }, - keyToPin: { - "w": "5", - "s": "7", - "a": "6", - "d": "8", - "i": "12", - "k": "14", - "j": "13", - "l": "15", - } + pinToHandlers: [...Array(8)].map(_ => []), + keys: ["w", "s", "a", "d", "i", "k", "j", "l"] }; native.press_cb(pin => { @@ -172,9 +154,9 @@ native.press_cb(pin => { } exports.onInput = (key, fn) => { - const pin = button.keyToPin[key]; + const pin = button.keys.indexOf(key); - if (pin === undefined) + if (pin === -1) throw new Error(`the sprig doesn't have a "${key}" button!`); button.pinToHandlers[pin].push(fn); diff --git a/firmware/sprig_hal/CMakeLists.txt b/firmware/sprig_hal/CMakeLists.txt index c124a16c50..41707fc4bb 100644 --- a/firmware/sprig_hal/CMakeLists.txt +++ b/firmware/sprig_hal/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.27) project(sprig_hal C CXX ASM) set(CMAKE_C_STANDARD 11) diff --git a/scripts/gardenshed.py b/scripts/gardenshed.py new file mode 100644 index 0000000000..beb80ca420 --- /dev/null +++ b/scripts/gardenshed.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import argparse +import shutil +import subprocess +import os + +deps = ["docker", "openocd"] + +# build +build = """ +docker build ./docker +docker run --security-opt label:disable --rm --volume "$(pwd)/../../":/root/sprig "$(docker images | awk '{print $3}' | awk 'NR==2')" +""" + +# gdb +gdb_server = """ +docker build ./docker +docker run -it --security-opt label:disable --network host --rm --volume "$(pwd)/../../":/root/sprig $(docker images | awk '{print $3}' | awk 'NR==2') /bin/sh -c "/opt/buildScript.sh; /usr/bin/gdb-multiarch -ex 'target remote :3333' /root/firmware.elf" +""" + +gdb_client = """ +sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "set USE_CORE 0" -c "program ./firmware.elf verify reset" +""" + +# log +log = """ +a=`uname` +if [[ "$a" == "Linux" ]]; then + pkill screen + screen /dev/`ls /dev/ | grep ttyACM | tail -n 1` 115200 +else + pkill SCREEN + screen /dev/`ls /dev/ | grep usb | tail -n 1` 115200 +fi +""" + +# flash +flash = """ +sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program ./firmware.elf verify reset exit" +""" + +# restart +restart = """ +sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "init;reset;exit" +""" + + +def run_cmd(cmd): + current_dir = os.path.dirname(__file__) + os.chdir(current_dir) + subprocess.run(["bash", "-c", cmd]) + + +for cmd in deps: + if shutil.which(cmd) is None: + raise Exception("Missing dependency: " + cmd) + +parser = argparse.ArgumentParser() +parser.add_argument("command", type=str, help="build, flash, log, restart, gdb-server, gdb-client") + +command = parser.parse_args().command + +commands = { + "build": build, + "flash": flash, + "log": log, + "restart": restart, + "gdb-server": gdb_server, + "gdb-client": gdb_client, +} + +run_cmd(commands[command]) diff --git a/scripts/gardenshed/README.md b/scripts/gardenshed/README.md deleted file mode 100644 index 38cf309467..0000000000 --- a/scripts/gardenshed/README.md +++ /dev/null @@ -1,10 +0,0 @@ -## Alias configuration - -Shell users should add the following to their terminal startup scripts, such as `.zprofile` on mac or `.bash-rc` on ubuntu: -``` -export SPRIG_DIR=/home/shawn/Sauce/sprig/ #replace with directory of your sprig repo -alias spade="cd $SPRIG_DIR/firmware/spade" -alias gardenshed="python3 $SPRIG_DIR/scripts/gardenshed/gardenshed.py" -alias gs="python3 $SPRIG_DIR/scripts/gardenshed/gardenshed.py" -``` - diff --git a/scripts/gardenshed/build.sh b/scripts/gardenshed/build.sh deleted file mode 100755 index 73768a184b..0000000000 --- a/scripts/gardenshed/build.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -dependencies=("docker" "echo" "whoami" "grep") - -for dep in "${dependencies[@]}"; do - if ! command -v $dep > /dev/null; then - printf "%s not found, please install %s\n" "$dep" "$dep" - exit 1 - fi -done - -echo "Dependencies found successfully" - -echo "Cleaning up previous build artifacts..." -if [ -d rpi_build ]; then - rm -rf rpi_build -fi -if [ -f spade.elf ]; then - rm -f spade.elf -fi -if [ -f spade.uf2 ]; then - rm -f spade.uf2 -fi -if [ -f dockerBuildLog.txt ]; then - rm -f dockerBuildLog.txt -fi - -# Ensure user in docker group if on linux -if id -nG $(whoami) | grep -qw "docker"; then - echo User in docker group, continuing -else - if [[ $OSTYPE != *"linux"* ]]; then - echo "Platform is not linux, skipping docker group check" - else - echo User $(whoami) not in the docker group. Please add user $(whoami) to the docker group and try again - exit 1 - fi -fi - - -case $1 in - "--log") docker build ./docker | tee dockerBuildLog.txt - docker run --security-opt label:disable --rm --volume `pwd`:/root/spade $(docker images | awk '{print $3}' | awk 'NR==2') | tee -a dockerBuildLog.txt ;; - *) docker build ./docker - docker run --security-opt label:disable --rm --volume `pwd`:/root/spade $(docker images | awk '{print $3}' | awk 'NR==2') ;; -esac diff --git a/scripts/gardenshed/gardenshed.py b/scripts/gardenshed/gardenshed.py deleted file mode 100644 index 1c57cfda90..0000000000 --- a/scripts/gardenshed/gardenshed.py +++ /dev/null @@ -1,27 +0,0 @@ -import argparse -import subprocess -import os - - -def runscript(script): - firmwaredir = "spade" - current_dir = os.path.dirname(os.path.realpath(__file__)) # Grabs path to gardenshed directory - bash_script_path_gardenshed = os.path.join(current_dir, script) #Grabs path to script - os.chdir(os.path.join(current_dir,"..", "..","firmware",firmwaredir)) #changes directory to firmware we are operating on - subprocess.run(["bash", os.path.join("..","..","scripts", "gardenshed", script)]) # - - -#argparse arg definitions -parser = argparse.ArgumentParser() -parser.add_argument("command",type=str, help="build, flash, log, restart, gdb-server, gdb-client") - - -#argparse arg interpreting -args = parser.parse_args() - -runscript(args.command+".sh") - - - - - diff --git a/scripts/gardenshed/gdb-client.sh b/scripts/gardenshed/gdb-client.sh deleted file mode 100755 index f408fb05cd..0000000000 --- a/scripts/gardenshed/gdb-client.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -dependencies=("docker" "echo" "whoami" "grep") - -for dep in "${dependencies[@]}"; do - if ! command -v $dep > /dev/null; then - printf "%s not found, please install %s\n" "$dep" "$dep" - exit 1 - fi -done - -echo "Dependencies found successfully" - -# Ensure user in docker group if on linux -if id -nG $(whoami) | grep -qw "docker"; then - echo User in docker group, continuing -else - if [[ $OSTYPE != *"linux"* ]]; then - echo "Platform is not linux, skipping docker group check" - else - echo User $(whoami) not in the docker group. Please add user $(whoami) to the docker group and try again - exit 1 - fi -fi - -case $1 in - "--log") docker build ./docker | tee dockerBuildLog.txt - docker run -it --security-opt label:disable --network host --rm --volume `pwd`:/root/spade $(docker images | awk '{print $3}' | awk 'NR==2') /usr/bin/gdb-multiarch -ex "target remote :3333" /root/spade/spade.elf | tee -a dockerBuildLog.txt ;; - *) docker build ./docker - docker run -it --security-opt label:disable --network host --rm --volume `pwd`:/root/spade $(docker images | awk '{print $3}' | awk 'NR==2') /usr/bin/gdb-multiarch -ex "target remote :3333" /root/spade/spade.elf ;; -esac diff --git a/scripts/gardenshed/gdb-server.sh b/scripts/gardenshed/gdb-server.sh deleted file mode 100755 index 112f404afc..0000000000 --- a/scripts/gardenshed/gdb-server.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "set USE_CORE 0" -c "program ./spade.elf verify reset" diff --git a/scripts/gardenshed/log.sh b/scripts/gardenshed/log.sh deleted file mode 100755 index 24b8c713da..0000000000 --- a/scripts/gardenshed/log.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -a=`uname` -if [[ "$a" == "Linux" ]]; then - pkill screen - screen /dev/`ls /dev/ | grep ttyACM | tail -n 1` 115200 -else - pkill SCREEN - screen /dev/`ls /dev/ | grep usb | tail -n 1` 115200 -fi diff --git a/scripts/gardenshed/reflash.sh b/scripts/gardenshed/reflash.sh deleted file mode 100755 index be66f89d10..0000000000 --- a/scripts/gardenshed/reflash.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program ./spade.elf verify reset exit" diff --git a/scripts/gardenshed/restart.sh b/scripts/gardenshed/restart.sh deleted file mode 100755 index 5a6c31bcf1..0000000000 --- a/scripts/gardenshed/restart.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "init;reset;exit"