mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 15:29:37 -05:00
commit
c5738c46d5
@ -266,7 +266,9 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ControlsSwitchesWidget::paint(Painter& painter) {
|
void ControlsSwitchesWidget::paint(Painter& painter) {
|
||||||
const std::array<Rect, 7> button_rects { {
|
const auto pos = screen_pos();
|
||||||
|
|
||||||
|
const std::array<Rect, 8> button_rects { {
|
||||||
{ 64, 32, 16, 16 }, // Right
|
{ 64, 32, 16, 16 }, // Right
|
||||||
{ 0, 32, 16, 16 }, // Left
|
{ 0, 32, 16, 16 }, // Left
|
||||||
{ 32, 64, 16, 16 }, // Down
|
{ 32, 64, 16, 16 }, // Down
|
||||||
@ -274,27 +276,63 @@ void ControlsSwitchesWidget::paint(Painter& painter) {
|
|||||||
{ 32, 32, 16, 16 }, // Select
|
{ 32, 32, 16, 16 }, // Select
|
||||||
{ 16, 96, 16, 16 }, // Encoder phase 0
|
{ 16, 96, 16, 16 }, // Encoder phase 0
|
||||||
{ 48, 96, 16, 16 }, // Encoder phase 1
|
{ 48, 96, 16, 16 }, // Encoder phase 1
|
||||||
|
{ 96, 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_event = key_event_mask;
|
|
||||||
|
|
||||||
for(const auto r : button_rects) {
|
for(const auto r : button_rects) {
|
||||||
const auto c =
|
painter.fill_rectangle(r + pos, Color::blue());
|
||||||
((switches_event & 1) ?
|
}
|
||||||
Color::red() :
|
|
||||||
((switches_debounced & 1) ?
|
const std::array<Rect, 8> raw_rects { {
|
||||||
Color::green() :
|
{ 64 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Right
|
||||||
((switches_raw & 1) ?
|
{ 0 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Left
|
||||||
Color::yellow() :
|
{ 32 + 1, 64 + 1, 16 - 2, 16 - 2 }, // Down
|
||||||
Color::blue()
|
{ 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
|
||||||
painter.fill_rectangle(r + pos, c);
|
{ 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;
|
switches_raw >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::array<Rect, 6> 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;
|
switches_debounced >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::array<Rect, 6> 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;
|
switches_event >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ using namespace hackrf::one;
|
|||||||
|
|
||||||
static Thread* thread_controls_event = NULL;
|
static Thread* thread_controls_event = NULL;
|
||||||
|
|
||||||
static std::array<Debounce, 7> switch_debounce;
|
static std::array<Debounce, 8> switch_debounce;
|
||||||
|
|
||||||
static Encoder encoder;
|
static Encoder encoder;
|
||||||
|
|
||||||
@ -193,11 +193,13 @@ void controls_init() {
|
|||||||
|
|
||||||
SwitchesState get_switches_state() {
|
SwitchesState get_switches_state() {
|
||||||
SwitchesState result;
|
SwitchesState result;
|
||||||
for(size_t i=0; i<result.size(); i++) {
|
for(size_t i=0; i<result.size()-1; i++) {
|
||||||
// TODO: Ignore multiple keys at the same time?
|
// TODO: Ignore multiple keys at the same time?
|
||||||
result[i] = switch_debounce[i].state();
|
result[i] = switch_debounce[i].state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result[result.size()-1] = switch_debounce[switch_debounce.size()-1].state();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,10 @@ enum class Switch {
|
|||||||
Down = 2,
|
Down = 2,
|
||||||
Up = 3,
|
Up = 3,
|
||||||
Sel = 4,
|
Sel = 4,
|
||||||
|
Dfu = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
using SwitchesState = std::bitset<5>;
|
using SwitchesState = std::bitset<6>;
|
||||||
|
|
||||||
using EncoderPosition = uint32_t;
|
using EncoderPosition = uint32_t;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ portapack::IO io {
|
|||||||
portapack::gpio_io_stbx,
|
portapack::gpio_io_stbx,
|
||||||
portapack::gpio_addr,
|
portapack::gpio_addr,
|
||||||
portapack::gpio_lcd_te,
|
portapack::gpio_lcd_te,
|
||||||
portapack::gpio_unused,
|
portapack::gpio_dfu,
|
||||||
};
|
};
|
||||||
|
|
||||||
portapack::BacklightCAT4004 backlight_cat4004;
|
portapack::BacklightCAT4004 backlight_cat4004;
|
||||||
|
@ -508,7 +508,7 @@ static const std::array<scu_setup_t, 26> 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, 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, 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 */
|
{ 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 */
|
||||||
{ 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/<unused> */
|
{ 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/<unused> */
|
||||||
{ 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, 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 */
|
{ 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) */
|
{ 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) */
|
||||||
|
@ -36,7 +36,7 @@ namespace portapack {
|
|||||||
constexpr GPIO gpio_io_stbx = gpio[GPIO5_0]; /* P2_0 */
|
constexpr GPIO gpio_io_stbx = gpio[GPIO5_0]; /* P2_0 */
|
||||||
constexpr GPIO gpio_addr = gpio[GPIO5_1]; /* P2_1 */
|
constexpr GPIO gpio_addr = gpio[GPIO5_1]; /* P2_1 */
|
||||||
constexpr GPIO gpio_lcd_te = gpio[GPIO5_3]; /* P2_3 */
|
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_rdx = gpio[GPIO5_4]; /* P2_4 */
|
||||||
constexpr GPIO gpio_lcd_wrx = gpio[GPIO1_10]; /* P2_9 */
|
constexpr GPIO gpio_lcd_wrx = gpio[GPIO1_10]; /* P2_9 */
|
||||||
constexpr GPIO gpio_dir = gpio[GPIO1_13]; /* P2_13 */
|
constexpr GPIO gpio_dir = gpio[GPIO1_13]; /* P2_13 */
|
||||||
|
@ -110,7 +110,8 @@ uint32_t IO::io_update(const TouchPinsConfig write_value) {
|
|||||||
}
|
}
|
||||||
gpio_addr.write(addr);
|
gpio_addr.write(addr);
|
||||||
|
|
||||||
return switches_raw;
|
auto dfu_btn = portapack::io.dfu_read() & 0x01;
|
||||||
|
return (switches_raw & 0x7f) | (dfu_btn << 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,10 @@ public:
|
|||||||
return gpio_rot_a.read();
|
return gpio_rot_a.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t dfu_read() {
|
||||||
|
return gpio_rot_b.read();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GPIO gpio_dir;
|
const GPIO gpio_dir;
|
||||||
const GPIO gpio_lcd_rdx;
|
const GPIO gpio_lcd_rdx;
|
||||||
|
@ -325,7 +325,8 @@ enum class KeyEvent {
|
|||||||
Down = 2,
|
Down = 2,
|
||||||
Up = 3,
|
Up = 3,
|
||||||
Select = 4,
|
Select = 4,
|
||||||
Back = 5, /* Left and Up together */
|
Dfu = 5,
|
||||||
|
Back = 6, /* Left and Up together */
|
||||||
};
|
};
|
||||||
|
|
||||||
using EncoderEvent = int32_t;
|
using EncoderEvent = int32_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user