Index: firmware/target/arm/iriver/h10/button-h10.c =================================================================== --- firmware/target/arm/iriver/h10/button-h10.c (revision 17201) +++ firmware/target/arm/iriver/h10/button-h10.c (working copy) @@ -35,10 +35,10 @@ { /* Enable REW, FF, Play, Left, Right, Hold buttons */ GPIO_SET_BITWISE(GPIOA_ENABLE, 0xfc); - + /* Enable POWER button */ GPIO_SET_BITWISE(GPIOB_ENABLE, 0x01); - + /* We need to output to pin 6 of GPIOD when reading the scroll pad value */ GPIO_SET_BITWISE(GPIOD_ENABLE, 0x40); GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x40); @@ -55,14 +55,28 @@ return adc_scan(ADC_REMOTE) < 0x2B; } +/* touchpad sliding defines */ +#define SCALE 2 /* call it sensitivity if you like*/ +#define UP_ZONE (0x1C0>>SCALE) /* above this we act as up button */ +#define DOWN_ZONE (0x1C0>>SCALE) /* below this we act as downbutton*/ +#define MIN_STILL_COUNT 80 /* hold still detection readcount */ +#define SLIDE_TRESH (0x40>>SCALE) /* treshold to accept sliding */ +#define SLIDE_DEBOUNCE (0x4>>SCALE) /* pos delta needed to slide */ +#define TOUCH_READ_HOLDOFF 20 /* nr of readings to ignore */ + /* * Get button pressed from hardware */ int button_read_device(void) { int btn = BUTTON_NONE; - int data; - unsigned char state; + int data; /* raw data from pad */ + int pos = 0; /* position (processed) */ + static int pos_prev = 0; /* previous position */ + static int pos_down = 0; /* position of downpress */ + static int still_count = 0; /* number of readings on same position */ + static int touch_read_holdoff; /* time between detection and accepting */ + unsigned char state; /* GPIO state */ static bool hold_button = false; static bool remote_hold_button = false; bool hold_button_old; @@ -90,27 +104,77 @@ if ((state & 0x20) == 0) btn |= BUTTON_REW; if ((state & 0x40) == 0) btn |= BUTTON_RIGHT; if ((state & 0x80) == 0) btn |= BUTTON_LEFT; - + /* Read power button */ if (GPIOB_INPUT_VAL & 0x1) btn |= BUTTON_POWER; - + /* Read scroller */ if ( GPIOD_INPUT_VAL & 0x20 ) { - GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x40); - udelay(250); - data = adc_scan(ADC_SCROLLPAD); - GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40); - - if(data < 0x224) + if(touch_read_holdoff-- < 0) { - btn |= BUTTON_SCROLL_DOWN; - } else { - btn |= BUTTON_SCROLL_UP; + /* we wait a bit before touch detection to filter the effects + of the finger touching */ + GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x40); + udelay(250); + data = adc_scan(ADC_SCROLLPAD); + GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40); + pos = data >> SCALE; } } + else + { + /* tip-touching: act as button + NOTE: this part is not working yet! + if((pos_down > 0) && (pos_prev > 0)) + { + if((pos_down > UP_ZONE) && (pos_prev > UP_ZONE)) + btn |= BUTTON_SCROLL_UP; + if((pos_down < DOWN_ZONE) && (pos_prev < DOWN_ZONE)) + btn |= BUTTON_SCROLL_DOWN; + } */ + pos = 0; + pos_prev = 0; + pos_down = 0; + still_count = 0; + touch_read_holdoff = TOUCH_READ_HOLDOFF; + } + + if(pos) + { + /* mark down event */ + if(!pos_down) + { + pos_down = pos; + pos_prev = pos; + } + + if(abs(pos-pos_down) < SLIDE_TRESH) + { + /* holding still */ + if(still_count++ > MIN_STILL_COUNT) + { + if(pos < DOWN_ZONE) + btn |= BUTTON_SCROLL_DOWN; + else if(pos > UP_ZONE) + btn |= BUTTON_SCROLL_UP; + } + } + else + { + /* sliding */ + if((pos_down > UP_ZONE) && (pos < (pos_prev - SLIDE_DEBOUNCE))) + btn |= BUTTON_SCROLL_DOWN; + else if((pos_down < DOWN_ZONE) && + (pos > (pos_prev + SLIDE_DEBOUNCE))) + btn |= BUTTON_SCROLL_UP; + still_count = 0; + } + + pos_prev = pos; + } } - + /* remote buttons */ remote_hold_button_old = remote_hold_button; @@ -142,6 +206,6 @@ /* remote play button should be dead if hold */ if (!remote_hold_button && !(GPIOA_INPUT_VAL & 0x1)) btn |= BUTTON_RC_PLAY; - + return btn; }