Skip to content

keyboard-fw: keyboard does not always present help when keys are pressed in power-off

When first switching on the Pocket Reform, pressing keys on the keyboard will cause a help message to display on the OLED directing the user to press Hyper+Enter to open the menu, or hold Hyper+Enter to power on. I believe that it is the intention that this is the behavior any time the Pocket is powered off (both in the sense that I think it should do that, and I think that the code is trying to do that), but it is not reliable.

In particular, if I:

  1. Power on the Pocket Reform
  2. Shut down by executing /sbin/shutdown
  3. Wait for the power to go completely off
  4. Press some keys

... then the help display does NOT come on.

Pressing Hyper+Enter and then 0 causes the help display to start working again.

This bug has been in place for some time; going back to at least the Sept 29 revision e453a6cc. It was not present in the firmware revision on my Pocket as shipped in late July/early August.

I believe the problem is with this conditional in main():

      if (!remote_get_power_state()) {
        if (pressed_keys>0 && menu_state != MENU_STATE_ACTIVE && !hyper_key && !last_menu_key) {
          execute_menu_function(KEY_H);
        }
      }

Specifically, I suspect the return value of remote_get_power_state() at this point, but I have not had the opportunity to verify that hypothesis. I have fair confidence in the values of menu_state, hyper_key, and last_menu_key from manual code inspection. I believe that there is likely to be an access bug with pressed_keys (it is modified in interrupt context by hid_task(), yet not marked volatile, and I think it is reasonable for the compiler to assume that it does not change during the while (1) loop in main; however, it does not appear in practice to be doing that). I have employed several ways to fix or mitigate that access bug (which I will eventually submit a patch for), however, and I do not believe that it is the problem in this case.