From 295367686ec9855c4d90f68a6003e819fef8e7ab Mon Sep 17 00:00:00 2001 From: Marcoen Hirschberg Date: Fri, 29 Dec 2006 02:49:12 +0000 Subject: merge a big part of the unofficial gigabeat cvs back. Includes working bootloader and rockbox with audio. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11850 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/gigabeat/meg-fx/button-meg-fx.c | 141 +++++++++++++++------ 1 file changed, 105 insertions(+), 36 deletions(-) (limited to 'firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c') diff --git a/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c index 88a1b4de09..210febb7db 100644 --- a/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c +++ b/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c @@ -27,58 +27,127 @@ #include "adc.h" #include "system.h" +static bool headphones_detect; + +static int const remote_buttons[] = +{ + BUTTON_NONE, /* Headphones connected - remote disconnected */ + BUTTON_SELECT, + BUTTON_MENU, /* could be changed to BUTTON_A */ + BUTTON_LEFT, + BUTTON_RIGHT, + BUTTON_UP, /* could be changed to BUTTON_VOL_UP */ + BUTTON_DOWN, /* could be changed to BUTTON_VOL_DOWN */ + BUTTON_NONE, /* Remote control attached - no buttons pressed */ + BUTTON_NONE, /* Nothing in the headphone socket */ +}; + + + + + void button_init_device(void) { /* Power, Remote Play & Hold switch */ } -bool button_hold(void) + + +inline bool button_hold(void) { return (GPGDAT & (1 << 15)); } -int button_read_device(void) -{ - int btn = BUTTON_NONE; - int touchpad = GPJDAT; - int buttons = GPGDAT; - - /* Check for hold first */ - if (buttons & (1 << 15)) - return btn; - /* the side buttons */ - if (buttons & (1 << 0)) - btn |= BUTTON_POWER; - - if (buttons & (1 << 1)) - btn |= BUTTON_MENU; - - if (buttons & (1 << 2)) - btn |= BUTTON_VOL_UP; - - if (buttons & (1 << 3)) - btn |= BUTTON_VOL_DOWN; - - if (buttons & (1 << 4)) - btn |= BUTTON_A; +int button_read_device(void) +{ + int btn; + int touchpad; + int buttons; + static int lastbutton; + unsigned short remote_adc; + + /* Check for hold first - exit if asserted with no button pressed */ + if (button_hold()) + return BUTTON_NONE; + + /* See header for ADC values when remote control buttons are pressed */ + /* Only one button can be sensed at a time on the remote. */ + /* Need to filter the remote button because the ADC is so fast */ + remote_adc = adc_read(ADC_HPREMOTE); + btn = remote_buttons[(remote_adc + 64) / 128]; + if (btn != lastbutton) + { + /* if the buttons dont agree twice in a row, then its none */ + lastbutton = btn; + btn = BUTTON_NONE; + } + + /* + * Code can be added that overrides the side buttons when the remote is + * plugged in: Check for remote_adc > 64 && remote_adc < 930 then skip + * reading the side and touch volume buttons, right, left, up, down, etc. + * but keep reading the Power and 'A'. + * For now, the buttons from remote and side and touch are used together. + */ + + + /* the side buttons - Check before doing all of the work on each bit */ + buttons = GPGDAT & 0x1F; + if (buttons) + { + if (buttons & (1 << 0)) + btn |= BUTTON_POWER; + + if (buttons & (1 << 1)) + btn |= BUTTON_MENU; + + if (buttons & (1 << 2)) + btn |= BUTTON_VOL_UP; + + if (buttons & (1 << 3)) + btn |= BUTTON_VOL_DOWN; + + if (buttons & (1 << 4)) + btn |= BUTTON_A; + } + /* the touchpad */ - if (touchpad & (1 << 0)) - btn |= BUTTON_UP; + touchpad = GPJDAT & 0x10C9; + if (touchpad) + { + if (touchpad & (1 << 0)) + btn |= BUTTON_UP; - if (touchpad & (1 << 12)) - btn |= BUTTON_RIGHT; + if (touchpad & (1 << 12)) + btn |= BUTTON_RIGHT; - if (touchpad & (1 << 6)) - btn |= BUTTON_DOWN; + if (touchpad & (1 << 6)) + btn |= BUTTON_DOWN; - if (touchpad & (1 << 7)) - btn |= BUTTON_LEFT; - - if (touchpad & (1 << 3)) - btn |= BUTTON_SELECT; + if (touchpad & (1 << 7)) + btn |= BUTTON_LEFT; + if (touchpad & (1 << 3)) + btn |= BUTTON_SELECT; + } + return btn; } + + +bool headphones_inserted(void) +{ + unsigned short remote_adc = adc_read(ADC_HPREMOTE); + if (remote_adc != ADC_READ_ERROR) + { + /* If there is nothing in the headphone socket, the ADC reads high */ + if (remote_adc < 940) + headphones_detect = true; + else + headphones_detect = false; + } + return headphones_detect; +} -- cgit v1.2.3