From bcefa774cd5df74376800479c7bbd0697d698076 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 16 Apr 2023 18:23:54 +0200 Subject: [PATCH 1/4] added dfu button to debug app --- firmware/application/apps/ui_debug.cpp | 8 +++++--- firmware/application/irq_controls.cpp | 6 ++++-- firmware/application/irq_controls.hpp | 3 ++- firmware/application/portapack.cpp | 2 +- .../boards/PORTAPACK_APPLICATION/board.cpp | 1 + firmware/common/pins.hpp | 1 + firmware/common/portapack_hal.hpp | 2 +- firmware/common/portapack_io.cpp | 7 ++++++- firmware/common/portapack_io.hpp | 4 ++++ firmware/common/ui.hpp | 3 ++- 10 files changed, 27 insertions(+), 10 deletions(-) diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index 05633e3f..4b402483 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -266,7 +266,7 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) { } void ControlsSwitchesWidget::paint(Painter& painter) { - const std::array button_rects { { + const std::array button_rects { { { 64, 32, 16, 16 }, // Right { 0, 32, 16, 16 }, // Left { 32, 64, 16, 16 }, // Down @@ -274,10 +274,12 @@ void ControlsSwitchesWidget::paint(Painter& painter) { { 32, 32, 16, 16 }, // Select { 16, 96, 16, 16 }, // Encoder phase 0 { 48, 96, 16, 16 }, // Encoder phase 1 + { 64, 0, 16, 16 }, // Dfu } }; const auto pos = screen_pos(); - auto switches_raw = control::debug::switches(); - auto switches_debounced = get_switches_state().to_ulong(); + auto switches_raw = control::debug::switches(); // all 7 + dfu + auto switches_debounced = get_switches_state().to_ulong(); // stops at 5, 6 is dfu + switches_debounced = (switches_debounced & 0x1f) | ((switches_debounced >> 5) << 7); auto switches_event = key_event_mask; for(const auto r : button_rects) { diff --git a/firmware/application/irq_controls.cpp b/firmware/application/irq_controls.cpp index c0fb82c8..d10b2b88 100644 --- a/firmware/application/irq_controls.cpp +++ b/firmware/application/irq_controls.cpp @@ -42,7 +42,7 @@ using namespace hackrf::one; static Thread* thread_controls_event = NULL; -static std::array switch_debounce; +static std::array switch_debounce; static Encoder encoder; @@ -193,11 +193,13 @@ void controls_init() { SwitchesState get_switches_state() { SwitchesState result; - for(size_t i=0; i; +using SwitchesState = std::bitset<6>; using EncoderPosition = uint32_t; diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index c7237171..6a4a18dc 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -61,7 +61,7 @@ portapack::IO io { portapack::gpio_io_stbx, portapack::gpio_addr, portapack::gpio_lcd_te, - portapack::gpio_unused, + portapack::gpio_dfu, }; portapack::BacklightCAT4004 backlight_cat4004; diff --git a/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp b/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp index affe8e3e..294997a7 100755 --- a/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp +++ b/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp @@ -508,6 +508,7 @@ static const std::array pins_setup_portapack { { { 2, 1, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* U0_RXD: PortaPack P2_1/ADDR */ { 2, 3, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SDA: PortaPack P2_3/LCD_TE */ { 2, 4, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SCL: PortaPack P2_4/LCD_RDX */ + //TODO: find right settings { 2, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/ */ { 2, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_9: 10K PD, BOOT3, PortaPack P2_9/LCD_WRX */ { 2, 13, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_13: PortaPack P2_13/DIR */ diff --git a/firmware/common/pins.hpp b/firmware/common/pins.hpp index bbb74d01..cee70e8d 100644 --- a/firmware/common/pins.hpp +++ b/firmware/common/pins.hpp @@ -215,6 +215,7 @@ constexpr GPIO gpio[] = { [GPIO5_4] = { pins[P2_4], 5, 4, 4 }, [GPIO5_5] = { pins[P2_5], 5, 5, 4 }, [GPIO5_6] = { pins[P2_6], 5, 6, 4 }, + //TODO: find right settings [GPIO5_7] = { pins[P2_8], 5, 7, 4 }, [GPIO5_8] = { pins[P3_1], 5, 8, 4 }, [GPIO5_9] = { pins[P3_2], 5, 9, 4 }, diff --git a/firmware/common/portapack_hal.hpp b/firmware/common/portapack_hal.hpp index 56aa9c07..8605646d 100644 --- a/firmware/common/portapack_hal.hpp +++ b/firmware/common/portapack_hal.hpp @@ -36,7 +36,7 @@ namespace portapack { constexpr GPIO gpio_io_stbx = gpio[GPIO5_0]; /* P2_0 */ constexpr GPIO gpio_addr = gpio[GPIO5_1]; /* P2_1 */ constexpr GPIO gpio_lcd_te = gpio[GPIO5_3]; /* P2_3 */ -constexpr GPIO gpio_unused = gpio[GPIO5_7]; /* P2_8 */ +constexpr GPIO gpio_dfu = gpio[GPIO5_7]; /* P2_8 */ constexpr GPIO gpio_lcd_rdx = gpio[GPIO5_4]; /* P2_4 */ constexpr GPIO gpio_lcd_wrx = gpio[GPIO1_10]; /* P2_9 */ constexpr GPIO gpio_dir = gpio[GPIO1_13]; /* P2_13 */ diff --git a/firmware/common/portapack_io.cpp b/firmware/common/portapack_io.cpp index e3a8e0d0..beed82f1 100644 --- a/firmware/common/portapack_io.cpp +++ b/firmware/common/portapack_io.cpp @@ -48,7 +48,11 @@ void IO::init() { gpio_io_stbx.output(); gpio_addr.output(); gpio_rot_a.input(); + + //TODO: find right settings + //gpio_rot_b.set(); gpio_rot_b.input(); + //gpio_rot_b.configure(); } void IO::lcd_backlight(const bool value) { @@ -110,7 +114,8 @@ uint32_t IO::io_update(const TouchPinsConfig write_value) { } gpio_addr.write(addr); - return switches_raw; + auto dfu_btn = portapack::io.dfu_read(); + return (switches_raw & 0x7f) | (dfu_btn << 7 ); } } diff --git a/firmware/common/portapack_io.hpp b/firmware/common/portapack_io.hpp index 148670d2..eee394cd 100644 --- a/firmware/common/portapack_io.hpp +++ b/firmware/common/portapack_io.hpp @@ -214,6 +214,10 @@ public: return gpio_rot_a.read(); } + uint32_t dfu_read() { + return gpio_rot_b.read(); + } + private: const GPIO gpio_dir; const GPIO gpio_lcd_rdx; diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index 4dcf4fbf..2c27fd33 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -325,7 +325,8 @@ enum class KeyEvent { Down = 2, Up = 3, Select = 4, - Back = 5, /* Left and Up together */ + Dfu = 5, + Back = 6, /* Left and Up together */ }; using EncoderEvent = int32_t; From d74fd924513d636e0aa339d0774867f78250da33 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 16 Apr 2023 19:51:06 +0200 Subject: [PATCH 2/4] added dfu button to debug app --- firmware/application/apps/ui_debug.cpp | 7 ++++--- .../boards/PORTAPACK_APPLICATION/board.cpp | 3 +-- firmware/common/portapack_io.cpp | 8 ++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index 4b402483..338891db 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -274,13 +274,14 @@ void ControlsSwitchesWidget::paint(Painter& painter) { { 32, 32, 16, 16 }, // Select { 16, 96, 16, 16 }, // Encoder phase 0 { 48, 96, 16, 16 }, // Encoder phase 1 - { 64, 0, 16, 16 }, // Dfu + { 80, 0, 16, 16 }, // Dfu } }; const auto pos = screen_pos(); auto switches_raw = control::debug::switches(); // all 7 + dfu auto switches_debounced = get_switches_state().to_ulong(); // stops at 5, 6 is dfu - switches_debounced = (switches_debounced & 0x1f) | ((switches_debounced >> 5) << 7); - auto switches_event = key_event_mask; + switches_debounced = (switches_debounced & 0x1f) | ((switches_debounced & 0x40) << 2); + auto switches_event = key_event_mask; // 5 keys, 6 is "back", 7 is dfu + key_event_mask = (key_event_mask & 0x1f) | ((key_event_mask & 0x80) << 1); for(const auto r : button_rects) { const auto c = diff --git a/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp b/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp index 294997a7..3a9aa622 100755 --- a/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp +++ b/firmware/chibios-portapack/boards/PORTAPACK_APPLICATION/board.cpp @@ -508,8 +508,7 @@ static const std::array pins_setup_portapack { { { 2, 1, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* U0_RXD: PortaPack P2_1/ADDR */ { 2, 3, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SDA: PortaPack P2_3/LCD_TE */ { 2, 4, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SCL: PortaPack P2_4/LCD_RDX */ - //TODO: find right settings - { 2, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/ */ + { 2, 8, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/ */ { 2, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_9: 10K PD, BOOT3, PortaPack P2_9/LCD_WRX */ { 2, 13, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_13: PortaPack P2_13/DIR */ { 7, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_8: PortaPack GPIO3_8(IO) */ diff --git a/firmware/common/portapack_io.cpp b/firmware/common/portapack_io.cpp index beed82f1..ad939739 100644 --- a/firmware/common/portapack_io.cpp +++ b/firmware/common/portapack_io.cpp @@ -48,11 +48,7 @@ void IO::init() { gpio_io_stbx.output(); gpio_addr.output(); gpio_rot_a.input(); - - //TODO: find right settings - //gpio_rot_b.set(); gpio_rot_b.input(); - //gpio_rot_b.configure(); } void IO::lcd_backlight(const bool value) { @@ -114,8 +110,8 @@ uint32_t IO::io_update(const TouchPinsConfig write_value) { } gpio_addr.write(addr); - auto dfu_btn = portapack::io.dfu_read(); - return (switches_raw & 0x7f) | (dfu_btn << 7 ); + auto dfu_btn = portapack::io.dfu_read() & 0x01; + return (switches_raw & 0x7f) | (dfu_btn << 7); } } From dc560ba01f92826932bf4c41202fc5350cd1f3c2 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 16 Apr 2023 20:31:14 +0200 Subject: [PATCH 3/4] improved debug app layout --- firmware/application/apps/ui_debug.cpp | 75 +++++++++++++++++++------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index 338891db..d0d0f9b9 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -265,7 +265,11 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) { return true; } +#define RECT_UNUSED { 0, 0, 0, 0 } + void ControlsSwitchesWidget::paint(Painter& painter) { + const auto pos = screen_pos(); + const std::array button_rects { { { 64, 32, 16, 16 }, // Right { 0, 32, 16, 16 }, // Left @@ -274,30 +278,63 @@ void ControlsSwitchesWidget::paint(Painter& painter) { { 32, 32, 16, 16 }, // Select { 16, 96, 16, 16 }, // Encoder phase 0 { 48, 96, 16, 16 }, // Encoder phase 1 - { 80, 0, 16, 16 }, // Dfu + { 96, 0, 16, 16 }, // Dfu } }; - const auto pos = screen_pos(); - auto switches_raw = control::debug::switches(); // all 7 + dfu - auto switches_debounced = get_switches_state().to_ulong(); // stops at 5, 6 is dfu - switches_debounced = (switches_debounced & 0x1f) | ((switches_debounced & 0x40) << 2); - auto switches_event = key_event_mask; // 5 keys, 6 is "back", 7 is dfu - key_event_mask = (key_event_mask & 0x1f) | ((key_event_mask & 0x80) << 1); for(const auto r : button_rects) { - const auto c = - ((switches_event & 1) ? - Color::red() : - ((switches_debounced & 1) ? - Color::green() : - ((switches_raw & 1) ? - Color::yellow() : - Color::blue() - ) - ) - ); - painter.fill_rectangle(r + pos, c); + painter.fill_rectangle(r + pos, Color::blue()); + } + + const std::array raw_rects { { + { 64 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Right + { 0 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Left + { 32 + 1, 64 + 1, 16 - 2, 16 - 2 }, // Down + { 32 + 1, 0 + 1, 16 - 2, 16 - 2 }, // Up + { 32 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Select + { 16 + 1, 96 + 1, 16 - 2, 16 - 2 }, // Encoder phase 0 + { 48 + 1, 96 + 1, 16 - 2, 16 - 2 }, // Encoder phase 1 + { 96 + 1, 0 + 1, 16 - 2, 16 - 2 }, // Dfu + } }; + + auto switches_raw = control::debug::switches(); + for(const auto r : raw_rects) { + if (switches_raw & 1) + painter.fill_rectangle(r + pos, Color::yellow()); + switches_raw >>= 1; + } + + const std::array debounced_rects { { + { 64 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Right + { 0 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Left + { 32 + 2, 64 + 2, 16 - 4, 16 - 4 }, // Down + { 32 + 2, 0 + 2, 16 - 4, 16 - 4 }, // Up + { 32 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Select + { 96 + 2, 0 + 2, 16 - 4, 16 - 4 }, // Dfu + } }; + + auto switches_debounced = get_switches_state().to_ulong(); + for(const auto r : debounced_rects) { + if (switches_debounced & 1) + painter.fill_rectangle(r + pos, Color::green()); + switches_debounced >>= 1; + } + + const std::array events_rects { { + { 64 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Right + { 0 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Left + { 32 + 3, 64 + 3, 16 - 6, 16 - 6 }, // Down + { 32 + 3, 0 + 3, 16 - 6, 16 - 6 }, // Up + { 32 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Select + { 96 + 3, 0 + 3, 16 - 6, 16 - 6 }, // Dfu + } }; + + auto switches_event = key_event_mask; + for(const auto r : events_rects) { + if (switches_event & 1) + painter.fill_rectangle(r + pos, Color::red()); + switches_event >>= 1; } } From 0acf7ec2c28d0822d78ec44d2a6af051126624e1 Mon Sep 17 00:00:00 2001 From: Bernd Herzog Date: Sun, 16 Apr 2023 20:33:02 +0200 Subject: [PATCH 4/4] refactoring --- firmware/application/apps/ui_debug.cpp | 2 -- firmware/common/pins.hpp | 1 - 2 files changed, 3 deletions(-) diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index d0d0f9b9..79866b70 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -265,8 +265,6 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) { return true; } -#define RECT_UNUSED { 0, 0, 0, 0 } - void ControlsSwitchesWidget::paint(Painter& painter) { const auto pos = screen_pos(); diff --git a/firmware/common/pins.hpp b/firmware/common/pins.hpp index cee70e8d..bbb74d01 100644 --- a/firmware/common/pins.hpp +++ b/firmware/common/pins.hpp @@ -215,7 +215,6 @@ constexpr GPIO gpio[] = { [GPIO5_4] = { pins[P2_4], 5, 4, 4 }, [GPIO5_5] = { pins[P2_5], 5, 5, 4 }, [GPIO5_6] = { pins[P2_6], 5, 6, 4 }, - //TODO: find right settings [GPIO5_7] = { pins[P2_8], 5, 7, 4 }, [GPIO5_8] = { pins[P3_1], 5, 8, 4 }, [GPIO5_9] = { pins[P3_2], 5, 9, 4 },