summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2008-12-31 21:02:56 +0000
committerBjörn Stenberg <bjorn@haxx.se>2008-12-31 21:02:56 +0000
commit9e3844db07e684365837ca5d5f9bcd4a2cb993a6 (patch)
tree7fde79118324291a685400ca133ec2705ea8d4af
parent5bf0cf59102f6a0fa812d7f60f954b5cc9ab834a (diff)
downloadrockbox-9e3844db07e684365837ca5d5f9bcd4a2cb993a6.zip
rockbox-9e3844db07e684365837ca5d5f9bcd4a2cb993a6.tar.gz
rockbox-9e3844db07e684365837ca5d5f9bcd4a2cb993a6.tar.bz2
rockbox-9e3844db07e684365837ca5d5f9bcd4a2cb993a6.tar.xz
Updated Fuze button code. FS#9645 by Thomas Martitz.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19629 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/keymaps/keymap-fuze.c77
-rw-r--r--firmware/target/arm/as3525/clock-target.h2
-rw-r--r--firmware/target/arm/as3525/sansa-fuze/button-fuze.c257
-rw-r--r--firmware/target/arm/as3525/sansa-fuze/button-target.h11
4 files changed, 228 insertions, 119 deletions
diff --git a/apps/keymaps/keymap-fuze.c b/apps/keymaps/keymap-fuze.c
index 7c84833..0f34c6b 100644
--- a/apps/keymaps/keymap-fuze.c
+++ b/apps/keymaps/keymap-fuze.c
@@ -19,7 +19,7 @@
* KIND, either express or implied.
*
****************************************************************************/
-/* Button Code Definitions for Sandisk Sansa Fuze target, based on e200 keymap*/
+/* Button Code Definitions for Sandisk Fuze target */
#include "config.h"
#include "action.h"
@@ -40,13 +40,15 @@ static const struct button_mapping button_context_standard[] = {
{ ACTION_STD_NEXT, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_STD_NEXTREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_STD_MENU, BUTTON_HOME|BUTTON_REL, BUTTON_DOWN },
+ { ACTION_STD_MENU, BUTTON_DOWN|BUTTON_REL, BUTTON_DOWN },
+ { ACTION_STD_REC, BUTTON_HOME|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT },
{ ACTION_STD_OK, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_STD_CANCEL, BUTTON_LEFT, BUTTON_NONE },
+ { ACTION_STD_CANCEL, BUTTON_POWER, BUTTON_NONE },
- { ACTION_STD_QUICKSCREEN, BUTTON_HOME|BUTTON_REPEAT, BUTTON_HOME },
+ { ACTION_STD_QUICKSCREEN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_DOWN },
{ ACTION_STD_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT },
LAST_ITEM_IN_LIST
@@ -65,9 +67,9 @@ static const struct button_mapping button_context_wps[] = {
{ ACTION_WPS_SEEKFWD, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_WPS_STOPSEEK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT|BUTTON_REPEAT },
- { ACTION_WPS_ABSETB_NEXTDIR, BUTTON_HOME|BUTTON_RIGHT, BUTTON_HOME },
- { ACTION_WPS_ABSETA_PREVDIR, BUTTON_HOME|BUTTON_LEFT, BUTTON_HOME },
- { ACTION_WPS_ABRESET, BUTTON_HOME|BUTTON_UP, BUTTON_HOME },
+ { ACTION_WPS_ABSETB_NEXTDIR, BUTTON_POWER|BUTTON_RIGHT, BUTTON_POWER },
+ { ACTION_WPS_ABSETA_PREVDIR, BUTTON_POWER|BUTTON_LEFT, BUTTON_POWER },
+ { ACTION_WPS_ABRESET, BUTTON_POWER|BUTTON_UP, BUTTON_POWER },
{ ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
@@ -77,35 +79,36 @@ static const struct button_mapping button_context_wps[] = {
{ ACTION_WPS_BROWSE, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT },
{ ACTION_WPS_CONTEXT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT },
- { ACTION_WPS_QUICKSCREEN, BUTTON_HOME|BUTTON_REPEAT, BUTTON_HOME },
+ { ACTION_WPS_QUICKSCREEN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_DOWN },
- { ACTION_WPS_MENU, BUTTON_HOME|BUTTON_REL, BUTTON_HOME },
+ { ACTION_WPS_MENU, BUTTON_DOWN|BUTTON_REL, BUTTON_DOWN },
+ { ACTION_WPS_REC, BUTTON_HOME|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_WPS_PITCHSCREEN, BUTTON_HOME|BUTTON_UP, BUTTON_HOME },
- { ACTION_WPS_ID3SCREEN, BUTTON_HOME|BUTTON_DOWN, BUTTON_HOME },
+ { ACTION_WPS_PITCHSCREEN, BUTTON_SELECT|BUTTON_UP, BUTTON_SELECT },
+ { ACTION_WPS_ID3SCREEN, BUTTON_SELECT|BUTTON_DOWN, BUTTON_SELECT },
LAST_ITEM_IN_LIST
}; /* button_context_wps */
static const struct button_mapping button_context_settings[] = {
- { ACTION_STD_CANCEL, BUTTON_HOME, BUTTON_NONE },
- { ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE },
- { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_FWD|BUTTON_REPEAT,BUTTON_NONE },
- { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
- { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_BACK|BUTTON_REPEAT,BUTTON_NONE },
+ { ACTION_STD_CANCEL, BUTTON_POWER, BUTTON_NONE },
+ { ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE },
+ { ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
+ { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
+ { ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE },
- { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE },
- { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_SETTINGS_RESET, BUTTON_SELECT, BUTTON_NONE },
+ { ACTION_STD_PREV, BUTTON_LEFT, BUTTON_NONE },
+ { ACTION_STD_PREVREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
+ { ACTION_STD_NEXT, BUTTON_RIGHT, BUTTON_NONE },
+ { ACTION_STD_NEXTREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
+ { ACTION_SETTINGS_RESET, BUTTON_SELECT, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD),
}; /* button_context_settings */
static const struct button_mapping button_context_list[] = {
{ ACTION_LISTTREE_PGUP, BUTTON_HOME|BUTTON_SCROLL_BACK, BUTTON_HOME },
- { ACTION_LISTTREE_PGDOWN, BUTTON_HOME|BUTTON_SCROLL_FWD, BUTTON_HOME },
+ { ACTION_LISTTREE_PGDOWN, BUTTON_HOME|BUTTON_SCROLL_FWD, BUTTON_HOME },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_list */
@@ -149,7 +152,7 @@ static const struct button_mapping button_context_yesno[] = {
static const struct button_mapping button_context_quickscreen[] = {
{ ACTION_NONE, BUTTON_LEFT, BUTTON_NONE },
- { ACTION_STD_CANCEL, BUTTON_HOME|BUTTON_REL, BUTTON_NONE },
+ { ACTION_STD_CANCEL, BUTTON_POWER|BUTTON_REL, BUTTON_NONE },
{ ACTION_QS_DOWNINV, BUTTON_UP|BUTTON_REL, BUTTON_NONE },
{ ACTION_QS_DOWNINV, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_QS_DOWN, BUTTON_DOWN|BUTTON_REL, BUTTON_NONE },
@@ -165,7 +168,7 @@ static const struct button_mapping button_context_quickscreen[] = {
static const struct button_mapping button_context_settings_right_is_inc[] = {
{ ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_SETTINGS_INCREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
+ { ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT,BUTTON_NONE },
{ ACTION_STD_PREV, BUTTON_UP|BUTTON_REL, BUTTON_NONE },
@@ -175,8 +178,8 @@ static const struct button_mapping button_context_settings_right_is_inc[] = {
{ ACTION_NONE, BUTTON_SELECT, BUTTON_NONE },
{ ACTION_STD_OK, BUTTON_SELECT|BUTTON_REL, BUTTON_NONE },
{ ACTION_NONE, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT },
- { ACTION_NONE, BUTTON_LEFT, BUTTON_NONE },
- { ACTION_STD_CANCEL, BUTTON_LEFT|BUTTON_REL, BUTTON_NONE },
+ { ACTION_NONE, BUTTON_POWER, BUTTON_NONE },
+ { ACTION_STD_CANCEL, BUTTON_POWER|BUTTON_REL, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD),
}; /* button_context_settings_right_is_inc */
@@ -199,9 +202,9 @@ static const struct button_mapping button_context_pitchscreen[] = {
{ ACTION_PS_NUDGE_LEFTOFF, BUTTON_LEFT|BUTTON_REL, BUTTON_NONE },
{ ACTION_PS_NUDGE_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_PS_NUDGE_RIGHTOFF, BUTTON_RIGHT|BUTTON_REL, BUTTON_NONE },
- { ACTION_PS_TOGGLE_MODE, BUTTON_DOWN, BUTTON_NONE },
+ { ACTION_PS_TOGGLE_MODE, BUTTON_HOME, BUTTON_NONE },
{ ACTION_PS_RESET, BUTTON_SELECT, BUTTON_NONE },
- { ACTION_PS_EXIT, BUTTON_HOME, BUTTON_NONE },
+ { ACTION_PS_EXIT, BUTTON_POWER, BUTTON_NONE },
{ ACTION_PS_EXIT, BUTTON_UP, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD),
@@ -210,8 +213,8 @@ static const struct button_mapping button_context_pitchscreen[] = {
/** Recording Screen **/
static const struct button_mapping button_context_recscreen[] = {
{ ACTION_REC_PAUSE, BUTTON_UP|BUTTON_REL, BUTTON_UP },
- { ACTION_STD_CANCEL, BUTTON_HOME|BUTTON_REL, BUTTON_HOME },
- { ACTION_REC_NEWFILE, BUTTON_DOWN|BUTTON_REL, BUTTON_DOWN },
+ { ACTION_STD_CANCEL, BUTTON_POWER|BUTTON_REL, BUTTON_POWER },
+ { ACTION_REC_NEWFILE, BUTTON_HOME|BUTTON_REL, BUTTON_HOME },
{ ACTION_STD_MENU, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_SELECT},
{ ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
@@ -221,7 +224,7 @@ static const struct button_mapping button_context_recscreen[] = {
{ ACTION_STD_PREV, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_NONE, BUTTON_DOWN, BUTTON_DOWN },
+ { ACTION_NONE, BUTTON_DOWN|BUTTON_REL, BUTTON_DOWN },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_recscreen */
@@ -242,23 +245,21 @@ static const struct button_mapping button_context_keyboard[] = {
{ ACTION_KBD_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_KBD_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
-/*
- { ACTION_KBD_CURSOR_LEFT, BUTTON_REC|BUTTON_LEFT, BUTTON_NONE },
- { ACTION_KBD_CURSOR_LEFT, BUTTON_REC|BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT, BUTTON_NONE },
- { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
-*/
+ { ACTION_KBD_CURSOR_LEFT, BUTTON_HOME|BUTTON_LEFT, BUTTON_NONE },
+ { ACTION_KBD_CURSOR_LEFT, BUTTON_HOME|BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
+ { ACTION_KBD_CURSOR_RIGHT, BUTTON_HOME|BUTTON_RIGHT, BUTTON_NONE },
+ { ACTION_KBD_CURSOR_RIGHT, BUTTON_HOME|BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_KBD_UP, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_KBD_UP, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_KBD_DOWN, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_KBD_DOWN, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
- { ACTION_KBD_PAGE_FLIP, BUTTON_HOME|BUTTON_SELECT, BUTTON_HOME },
+ { ACTION_KBD_PAGE_FLIP, BUTTON_HOME|BUTTON_SELECT, BUTTON_HOME },
{ ACTION_KBD_BACKSPACE, BUTTON_DOWN, BUTTON_NONE },
{ ACTION_KBD_BACKSPACE, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_KBD_SELECT, BUTTON_SELECT, BUTTON_NONE },
{ ACTION_KBD_DONE, BUTTON_UP, BUTTON_NONE },
- { ACTION_KBD_ABORT, BUTTON_HOME|BUTTON_REL, BUTTON_NONE },
+ { ACTION_KBD_ABORT, BUTTON_POWER, BUTTON_NONE },
LAST_ITEM_IN_LIST
}; /* button_context_keyboard */
diff --git a/firmware/target/arm/as3525/clock-target.h b/firmware/target/arm/as3525/clock-target.h
index 1e55753..a227f46 100644
--- a/firmware/target/arm/as3525/clock-target.h
+++ b/firmware/target/arm/as3525/clock-target.h
@@ -53,7 +53,7 @@
#elif defined(SANSA_M200V4)
#define AS3525_DBOP_FREQ 8000000
#elif defined(SANSA_FUZE)
-#define AS3525_DBOP_FREQ 24000000
+#define AS3525_DBOP_FREQ 8000000
#elif defined(SANSA_E200V2)
#define AS3525_DBOP_FREQ 8000000
#elif defined(SANSA_C200V2)
diff --git a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
index 36a0f3a..2414900 100644
--- a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
+++ b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
@@ -7,7 +7,8 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Barry Wardell
+ * Copyright (C) 2008 by Thomas Martitz
+ * Copyright (C) 2008 by Dominik Wenger
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -19,118 +20,229 @@
*
****************************************************************************/
-/* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */
+
+/* Basic button driver for the Fuze
+ *
+ * TODO: - Get the wheel working with interrupts
+ * - find that Home button
+ */
#include "system.h"
#include "button.h"
+#include "button-target.h"
#include "backlight.h"
-#include "powermgmt.h"
-#define WHEEL_REPEAT_INTERVAL 300000
-#define WHEEL_FAST_ON_INTERVAL 20000
-#define WHEEL_FAST_OFF_INTERVAL 60000
+#define WHEEL_REPEAT_INTERVAL 30
#define WHEELCLICKS_PER_ROTATION 48 /* wheelclicks per full rotation */
-/* Clickwheel */
#ifndef BOOTLOADER
-static unsigned int old_wheel_value = 0;
-static unsigned int wheel_repeat = BUTTON_NONE;
-static unsigned int wheel_click_count = 0;
-static unsigned int wheel_delta = 0;
-static int wheel_fast_mode = 0;
-static unsigned long last_wheel_usec = 0;
-static unsigned long wheel_velocity = 0;
-static long last_wheel_post = 0;
-static long next_backlight_on = 0;
/* Buttons */
static bool hold_button = false;
static bool hold_button_old = false;
-#define _button_hold() hold_button
#else
-#define _button_hold() false /* FIXME */
-#endif /* BOOTLOADER */
-static int int_btn = BUTTON_NONE;
+#define hold_button false
+#endif /* !BOOTLOADER */
+static int int_btn = BUTTON_NONE;
+static short dbop_din = BUTTON_NONE;
void button_init_device(void)
{
+ GPIOA_DIR |= (1<<1);
+ GPIOA_PIN(1) = (1<<1);
+}
+
+/* clickwheel */
+#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL)
+static void get_wheel(void)
+{
+ static unsigned int old_wheel_value = 0;
+ static unsigned int wheel_value = 0;
+ static unsigned int wheel_repeat = BUTTON_NONE;
+ /* getting BUTTON_REPEAT works like this: We increment repeat by if the
+ * wheel was turned, and decrement it by 1 each tick,
+ * that means: if you change the wheel fast enough, repeat will be >1 and
+ * we send BUTTON_REPEAT
+ */
+ static int repeat;
+ /* we omit 3 of 4 posts to the button_queue, that works better, so count */
+ static int counter = 0;
+ /* Read wheel
+ * Bits 13 and 14 of DBOP_DIN change as follows:
+ * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00
+ * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00
+ */
+ static const unsigned char wheel_tbl[2][4] =
+ {
+ { 2, 0, 3, 1 }, /* Clockwise rotation */
+ { 1, 3, 0, 2 }, /* Counter-clockwise */
+ };
+ wheel_value = dbop_din & (1<<13|1<<14);
+ wheel_value >>= 13;
+ /* did the wheel value change? */
+ if (!hold_button)
+ {
+ unsigned int btn = BUTTON_NONE;
+ if (old_wheel_value == wheel_tbl[0][wheel_value])
+ btn = BUTTON_SCROLL_FWD;
+ else if (old_wheel_value == wheel_tbl[1][wheel_value])
+ btn = BUTTON_SCROLL_BACK;
+
+ if (btn != BUTTON_NONE)
+ {
+ if (btn != wheel_repeat)
+ {
+ /* direction reversals nullify repeats */
+ wheel_repeat = btn;
+ repeat = 0;
+ }
+ if (btn != BUTTON_NONE)
+ {
+ /* generate repeats if quick enough */
+ if (repeat > 0)
+ {
+ btn |= BUTTON_REPEAT;
+ }
+ repeat += 2;
+ /* the wheel is more reliable if we don't send ever change,
+ * every 4th is basically one "physical click" is 1 item in
+ * the rockbox menus */
+ if (queue_empty(&button_queue) && ++counter >= 4)
+ {
+ backlight_on();
+ /* 1<<24 is rather arbitary, seems to work well */
+ queue_post(&button_queue, btn, 1<<24);
+ /* message posted - reset count */
+ counter = 0;
+ }
+ }
+ }
+ }
+ if (repeat > 0)
+ repeat--;
+ else
+ repeat = 0;
+ old_wheel_value = wheel_value;
+}
+#endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */
+
+#if !defined(BOOTLOADER)
+/* get hold button state */
+static void get_hold(void)
+{
+ hold_button = dbop_din & (1<<12);
}
+#endif
bool button_hold(void)
{
- return _button_hold();
+ return hold_button;
}
-/* clickwheel */
-#ifndef BOOTLOADER
-void clickwheel_int(void)
+static void get_power(void)
{
+ if (dbop_din & (1<<8))
+ int_btn |= BUTTON_POWER;
}
-#endif /* BOOTLOADER */
-/* device buttons */
+static void get_button_from_dbob(void)
+{
+ int_btn &= ~(BUTTON_HOLD|
+ BUTTON_POWER);
+
+ /* Wait for fifo to empty */
+ while ((DBOP_STAT & (1<<10)) == 0);
+
+ DBOP_CTRL |= (1<<19);
+ DBOP_CTRL &= ~(1<<16); /* disable output */
+
+ DBOP_TIMPOL_01 = 0xe167e167;
+ DBOP_TIMPOL_23 = 0xe167006e;
+ int loop = 0;
+ do
+ {
+ asm volatile ("nop\n");
+ loop++;
+ } while(loop < 64);
+
+ DBOP_CTRL |= (1<<15); /* start read */
+ int temp;
+ do
+ {
+ temp = DBOP_STAT;
+ } while ((temp & (1<<16)) == 0); /* wait for valid data */
+
+ dbop_din = DBOP_DIN; /* now read */
+
+ DBOP_TIMPOL_01 = 0x6e167;
+ DBOP_TIMPOL_23 = 0xa167e06f;
+
+ DBOP_CTRL |= (1<<16);
+ DBOP_CTRL &= ~(1<<19);
-/* device buttons */
-void button_int(void)
+#if !defined(BOOTLOADER)
+ get_hold();
+#if defined(HAVE_SCROLLWHEEL)
+ get_wheel();
+#endif
+#endif
+ get_power();
+}
+
+static void get_button_from_gpio(void)
{
- int dir_save_b = 0;
- int afsel_save_b = 0;
- int dir_save_c = 0;
- int afsel_save_c = 0;
-
- int_btn = BUTTON_NONE;
-
- /* Save the current direction and afsel */
- dir_save_b = GPIOB_DIR;
- afsel_save_b = GPIOB_AFSEL;
- dir_save_c = GPIOC_DIR;
- afsel_save_c = GPIOC_AFSEL;
-
- GPIOB_DIR = 0;
- GPIOB_AFSEL = 0;
- GPIOC_DIR = 0;
- GPIOC_AFSEL = 0;
-
- /* These should not be needed with button event interupts */
- /* they are necessary now to clear out lcd data */
- GPIOC_PIN(0) |= 1;
- GPIOC_PIN(1) |= 1;
- GPIOC_PIN(2) |= 1;
- GPIOC_PIN(3) |= 1;
- GPIOC_PIN(4) |= 1;
- GPIOC_PIN(5) |= 1;
- GPIOC_PIN(6) |= 1;
- GPIOC_PIN(7) |= 1;
+ /* reset buttons we're going to read */
+ int_btn &= ~(BUTTON_LEFT|
+ BUTTON_RIGHT|
+ BUTTON_UP|
+ BUTTON_DOWN|
+ BUTTON_SELECT);
+ if(hold_button)
+ return;
+ /* set afsel, so that we can read our buttons */
+ GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
+ /* set dir so we can read our buttons (but reset the C pins first) */
+ GPIOB_DIR &= ~(1<<4);
+ GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6);
+ GPIOC_PIN(2) |= (1<<2);
+ GPIOC_PIN(3) |= (1<<3);
+ GPIOC_PIN(4) |= (1<<4);
+ GPIOC_PIN(5) |= (1<<5);
+ GPIOC_PIN(6) |= (1<<6);
+
+ GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
+
+ /* small delay needed to read buttons correctly */
+ int delay = 50;
+ while(delay >0) delay--;
/* direct GPIO connections */
- if (GPIOB_PIN(4))
- int_btn |= BUTTON_POWER;
+ if (!GPIOC_PIN(3))
+ int_btn |= BUTTON_LEFT;
+ if (!GPIOC_PIN(2))
+ int_btn |= BUTTON_UP;
if (!GPIOC_PIN(6))
int_btn |= BUTTON_DOWN;
if (!GPIOC_PIN(5))
int_btn |= BUTTON_RIGHT;
if (!GPIOC_PIN(4))
int_btn |= BUTTON_SELECT;
- if (!GPIOC_PIN(3))
- int_btn |= BUTTON_LEFT;
- if (!GPIOC_PIN(2))
- int_btn |= BUTTON_UP;
-
/* return to settings needed for lcd */
- GPIOB_DIR = dir_save_b;
- GPIOB_AFSEL = afsel_save_b;
- GPIOC_DIR = dir_save_c;
- GPIOC_AFSEL = afsel_save_c;
+ GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6);
+ GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6);
}
+static inline void get_buttons_from_hw(void)
+{
+ get_button_from_dbob();
+ get_button_from_gpio();
+}
/*
* Get button pressed from hardware
*/
int button_read_device(void)
{
-#ifdef BOOTLOADER
- /* Read buttons directly in the bootloader */
- button_int();
-#else
+ get_buttons_from_hw();
+#ifndef BOOTLOADER
/* light handling */
if (hold_button != hold_button_old)
{
@@ -139,6 +251,5 @@ int button_read_device(void)
}
#endif /* BOOTLOADER */
- /* The int_btn variable is set in the button interrupt handler */
- return int_btn;
+ return int_btn; /* set in button_int */
}
diff --git a/firmware/target/arm/as3525/sansa-fuze/button-target.h b/firmware/target/arm/as3525/sansa-fuze/button-target.h
index be72e1a..75ce3d0 100644
--- a/firmware/target/arm/as3525/sansa-fuze/button-target.h
+++ b/firmware/target/arm/as3525/sansa-fuze/button-target.h
@@ -27,13 +27,9 @@
#define HAS_BUTTON_HOLD
-bool button_hold(void);
void button_init_device(void);
+bool button_hold(void);
int button_read_device(void);
-#ifndef BOOTLOADER
-void clickwheel_int(void);
-#endif
-void button_int(void);
/* Sandisk Sansa Fuze button codes */
@@ -51,11 +47,12 @@ void button_int(void);
#define BUTTON_SCROLL_BACK 0x00000080
#define BUTTON_SCROLL_FWD 0x00000100
-#define BUTTON_HOLD 0x00000200
+#define BUTTON_HOLD 0x00000400
#define BUTTON_MAIN (BUTTON_HOME|BUTTON_DOWN|BUTTON_RIGHT|BUTTON_LEFT \
|BUTTON_SELECT|BUTTON_UP|BUTTON_POWER \
- |BUTTON_SCROLLBACK|BUTTON_SCROLL_FWD|BUTTON_HOLD)
+ |BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD| \
+ |BUTTON_HOLD)
/* No Remote control */
#define BUTTON_REMOTE 0