Skip to content

Commit

Permalink
Allow hotkeys to be configured for momentary action.
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Apr 26, 2021
1 parent b367dd0 commit 40d06c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ extern struct packed config {
/* Mask of user pins driven HIGH by this hotkey.
* Pins in @pin_mod but not in @pin_high are driven LOW. */
uint8_t pin_high;
uint16_t flags;
/* HKF_momentary: Pins are driven the opposite way on key release. */
#define HKF_momentary 1
char str[30];
} hotkey[10];

Expand Down
13 changes: 10 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,20 @@ static void update_amiga_keys(void)
hk_pressed = amiga_key_pressed(AMI_F(i+1));
if (!((hk_latch>>i & 1) ^ hk_pressed))
continue;
/* Calculate the GPIO set/reset masks. */
s = (uint16_t)hk->pin_high << pin_u0;
r = (uint16_t)(hk->pin_mod & ~hk->pin_high) << pin_u0;
/* State has changed: Is the hotkey now pressed? */
hk_latch ^= 1u << i;
if (!hk_pressed)
if (!hk_pressed) {
if (hk->flags & HKF_momentary) {
/* Momentary hotkeys have their action reversed on release. */
gpio_user->bsrr = ((uint32_t)s << 16) | r;
notify.on = FALSE;
}
continue;
}
/* Hotkey is now pressed: Perform configured action. */
s = (uint16_t)hk->pin_high << pin_u0;
r = (uint16_t)(hk->pin_mod & ~hk->pin_high) << pin_u0;
gpio_user->bsrr = ((uint32_t)r << 16) | s;
if (*(p = hk->str)) {
notify.cols = notify.rows = 0;
Expand Down

0 comments on commit 40d06c0

Please sign in to comment.