mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
hm60x/hm801: Add hold button support.
Change-Id: I05557ecfbf0bd821d8966862a38f7f22656b36ef
This commit is contained in:
parent
362ade3892
commit
97250a0156
4 changed files with 55 additions and 1 deletions
|
|
@ -23,15 +23,40 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "backlight.h"
|
||||||
|
|
||||||
void button_init_device(void) {
|
void button_init_device(void) {
|
||||||
/* setup button gpio as input */
|
/* setup button gpio as input */
|
||||||
GPIO_PCCON &= ~(POWEROFF_BUTTON);
|
GPIO_PCCON &= ~(POWEROFF_BUTTON);
|
||||||
|
GPIO_PACON &= ~(1);
|
||||||
|
|
||||||
|
/* setup button gpio as pulldown */
|
||||||
|
SCU_GPIOUPCON |= (1<<17) |
|
||||||
|
1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool button_hold() {
|
||||||
|
return (GPIO_PADR & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int button_read_device(void) {
|
int button_read_device(void) {
|
||||||
int adc_val = adc_read(ADC_BUTTONS);
|
int adc_val = adc_read(ADC_BUTTONS);
|
||||||
int gpio_btn = GPIO_PCDR & BUTTON_POWER;
|
int gpio_btn = GPIO_PCDR & BUTTON_POWER;
|
||||||
|
static bool hold_button = false;
|
||||||
|
bool hold_button_old;
|
||||||
|
|
||||||
|
hold_button_old = hold_button;
|
||||||
|
hold_button = button_hold();
|
||||||
|
|
||||||
|
#ifndef BOOTLOADER
|
||||||
|
if (hold_button != hold_button_old) {
|
||||||
|
backlight_hold_changed(hold_button);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (hold_button) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (adc_val < 380) { /* 0 - 379 */
|
if (adc_val < 380) { /* 0 - 379 */
|
||||||
if (adc_val < 250) { /* 0 - 249 */
|
if (adc_val < 250) { /* 0 - 249 */
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
#ifndef _BUTTON_TARGET_H_
|
#ifndef _BUTTON_TARGET_H_
|
||||||
#define _BUTTON_TARGET_H_
|
#define _BUTTON_TARGET_H_
|
||||||
|
|
||||||
|
#define HAS_BUTTON_HOLD
|
||||||
|
|
||||||
#define BUTTON_UP 0x00000001
|
#define BUTTON_UP 0x00000001
|
||||||
#define BUTTON_POWER 0x00000002
|
#define BUTTON_POWER 0x00000002
|
||||||
#define BUTTON_DOWN 0x00000004
|
#define BUTTON_DOWN 0x00000004
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "backlight.h"
|
||||||
|
|
||||||
enum keyboard_type_t {
|
enum keyboard_type_t {
|
||||||
KEYBOARD_V1,
|
KEYBOARD_V1,
|
||||||
|
|
@ -34,6 +35,12 @@ static enum keyboard_type_t kbd_type;
|
||||||
void button_init_device(void) {
|
void button_init_device(void) {
|
||||||
/* setup button gpio as input */
|
/* setup button gpio as input */
|
||||||
GPIO_PCCON &= ~(POWEROFF_BUTTON);
|
GPIO_PCCON &= ~(POWEROFF_BUTTON);
|
||||||
|
GPIO_PACON &= ~1;
|
||||||
|
|
||||||
|
|
||||||
|
/* setup button gpio as pulldown */
|
||||||
|
SCU_GPIOUPCON |= (1<<17) |
|
||||||
|
1 ;
|
||||||
|
|
||||||
/* identify keyboard type */
|
/* identify keyboard type */
|
||||||
SCU_IOMUXB_CON &= ~(1<<2);
|
SCU_IOMUXB_CON &= ~(1<<2);
|
||||||
|
|
@ -45,6 +52,10 @@ void button_init_device(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool button_hold() {
|
||||||
|
return (GPIO_PADR & 1);
|
||||||
|
}
|
||||||
|
|
||||||
static int button_read_device_v1(void) {
|
static int button_read_device_v1(void) {
|
||||||
int adc_val = adc_read(ADC_BUTTONS);
|
int adc_val = adc_read(ADC_BUTTONS);
|
||||||
int button = 0;
|
int button = 0;
|
||||||
|
|
@ -125,7 +136,21 @@ static int button_read_device_v2(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int button_read_device(void) {
|
int button_read_device(void) {
|
||||||
if (kbd_type == KEYBOARD_V1) {
|
static bool hold_button = false;
|
||||||
|
bool hold_button_old;
|
||||||
|
|
||||||
|
hold_button_old = hold_button;
|
||||||
|
hold_button = button_hold();
|
||||||
|
|
||||||
|
#ifndef BOOTLOADER
|
||||||
|
if (hold_button != hold_button_old) {
|
||||||
|
backlight_hold_changed(hold_button);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (hold_button) {
|
||||||
|
return 0;
|
||||||
|
} else if (kbd_type == KEYBOARD_V1) {
|
||||||
return button_read_device_v1();
|
return button_read_device_v1();
|
||||||
} else {
|
} else {
|
||||||
return button_read_device_v2();
|
return button_read_device_v2();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
#ifndef _BUTTON_TARGET_H_
|
#ifndef _BUTTON_TARGET_H_
|
||||||
#define _BUTTON_TARGET_H_
|
#define _BUTTON_TARGET_H_
|
||||||
|
|
||||||
|
#define HAS_BUTTON_HOLD
|
||||||
|
|
||||||
#define BUTTON_UP 0x00000001
|
#define BUTTON_UP 0x00000001
|
||||||
#define BUTTON_POWER 0x00000002
|
#define BUTTON_POWER 0x00000002
|
||||||
#define BUTTON_DOWN 0x00000004
|
#define BUTTON_DOWN 0x00000004
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue