Xduoo X3 Add tree scrolling FS#13240, Emulate Multibutton presses

Fixes deficiencies with the button system on the X3

  The x3 has an interesting button layout.
  Multiple key presses are NOT supported unless
  [BUTTON_POWER] is one of the combined keys

  As you can imagine this causes problems as the power button takes
  precedence in the button system and initiates a shutdown if the
  key is held too long
  instead of BUTTON_POWER use BUTTON_PWRALT in combination with other keys
  IF using as a prerequsite button then BUTTON_POWER should be used

  Multiple buttons are emulated by button_read_device but there are a few
  caveats to be aware of:

  Button Order Matters!
   different keys have different priorities, higher priority keys 'overide'
   the lower priority keys
  VOLUP[7] VOLDN[6] PREV[5] NEXT[4] PLAY[3] OPTION[2] HOME[1]

  There will be no true release or repeat events, the user can let off the
   button pressed initially and it will still continue to appear to be
   pressed as long as the second key is held

Tree scrolling is PLAY+NEXT or PLAY+PREV

Change-Id: I88dfee1c70a6a99659e8227f5becacc50cc43910
This commit is contained in:
William Wilgus 2020-09-12 05:03:12 -04:00 committed by William Wilgus
parent 6b674a6a0a
commit c62493e98a
14 changed files with 101 additions and 34 deletions

View file

@ -32,7 +32,7 @@
#define BUTTON_PLAY 0x00000020
#define BUTTON_VOL_UP 0x00000040
#define BUTTON_VOL_DOWN 0x00000080
#define BUTTON_PWRALT 0x00000100 /* BUTTON_POWER combo with other buttons */
#define BUTTON_LEFT 0
#define BUTTON_RIGHT 0

View file

@ -56,6 +56,8 @@
#define ADC_MASK 0x0FFF
static volatile unsigned short bat_val, key_val;
static volatile int btn_last = BUTTON_NONE;
static volatile long btn_last_tick;
bool headphones_inserted(void)
{
@ -108,52 +110,82 @@ bool button_hold(void)
}
/* NOTE: Due to how this is wired, button combinations are not allowed
unless one of the two buttons is the POWER
*/
* unless one of the two buttons is the POWER
*
* Note --Update 2020
* by toggling BOP common I was able to remove BACK, OPTION, PLAY from the
* loop selectively and test which keys were pressed but this took two adc rounds
* and proved to be minimally useful for the added overhead
*
* NOW multiple button presses are emulated but button priority needs to be taken
* into consideration; higher priority keys 'overide' the lower priority keys
* VOLUP[7] VOLDN[6] PREV[5] NEXT[4] PLAY[3] OPTION[2] HOME[1]
*/
int button_read_device(void)
{
unsigned short key;
int btn = BUTTON_NONE;
unsigned short key = (key_val & ADC_MASK);
int btn_pwr = BUTTON_NONE;
if (button_hold())
return BUTTON_NONE;
if (KEY_IS_DOWN(PIN_BTN_POWER))
btn |= BUTTON_POWER;
btn_pwr = BUTTON_POWER;
if (!KEY_IS_DOWN(PIN_KEY_INT))
return btn;
{
__intc_mask_irq(IRQ_SADC);
REG_SADC_ADENA &= ~ADENA_AUXEN;
return btn_pwr;
}
key = (key_val & ADC_MASK);
/* Don't initiate a new request if we have one pending */
if(!(REG_SADC_ADENA & (ADENA_AUXEN)))
{
REG_SADC_ADENA |= ADENA_AUXEN;
}
if (key < 261)
btn |= BUTTON_VOL_UP;
btn = BUTTON_VOL_UP;
else
if (key < 653)
btn |= BUTTON_VOL_DOWN;
btn = BUTTON_VOL_DOWN;
else
if (key < 1101)
btn |= BUTTON_PREV;
btn = BUTTON_PREV;
else
if (key < 1498)
btn |= BUTTON_NEXT;
btn = BUTTON_NEXT;
else
if (key < 1839)
btn |= BUTTON_PLAY;
btn = BUTTON_PLAY;
else
if (key < 2213)
btn |= BUTTON_OPTION;
btn = BUTTON_OPTION;
else
if (key < 2600)
btn |= BUTTON_HOME;
btn = BUTTON_HOME;
return btn;
if (btn_last == BUTTON_NONE && TIME_AFTER(current_tick, btn_last_tick + HZ/20))
btn_last = btn;
if (btn_pwr != BUTTON_NONE)
btn |= BUTTON_PWRALT;
return btn | btn_last;
}
/* called on button press interrupt */
void KEY_INT_IRQ(void)
{
/* Don't initiate a new request if we have one pending */
if(!(REG_SADC_ADENA & (ADENA_AUXEN)))
REG_SADC_ADENA |= ADENA_AUXEN;
btn_last = BUTTON_NONE;
key_val = ADC_MASK;
__intc_unmask_irq(IRQ_SADC);
REG_SADC_ADENA |= ADENA_AUXEN;
btn_last_tick = current_tick;
}
/* Notes on batteries
@ -238,6 +270,7 @@ void adc_init(void)
REG_SADC_ADCFG = ADCFG_VBAT_SEL | ADCFG_CMD_AUX(1); /* VBAT_SEL is undocumented but required! */
REG_SADC_ADCLK = (199 << 16) | (1 << 8) | 61;
system_enable_irq(IRQ_SADC);
REG_SADC_ADENA |= ADENA_AUXEN | ADENA_VBATEN;
}
void adc_close(void)
@ -260,8 +293,6 @@ void SADC(void)
if(state & ADCTRL_ARDYM)
{
key_val = REG_SADC_ADADAT;
if (KEY_IS_DOWN(PIN_KEY_INT)) /* key(s) are down kick off another read */
REG_SADC_ADENA = ADENA_AUXEN;
}
else if(UNLIKELY(state & ADCTRL_VRDYM))
{