Moved the X5 button driver to the target tree


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10339 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/Makefile b/apps/Makefile
index 0fd52bb..53a0d37 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES= -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I. -I$(BUILDDIR)	\
+INCLUDES= $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I. -I$(BUILDDIR)	\
  -I$(BUILDDIR)/bitmaps -I$(OBJDIR)
 
 DEPFILE = $(OBJDIR)/dep-apps
diff --git a/apps/codecs/lib/Makefile b/apps/codecs/lib/Makefile
index 18f478c..865e3b5 100644
--- a/apps/codecs/lib/Makefile
+++ b/apps/codecs/lib/Makefile
@@ -10,7 +10,7 @@
 # ../.. for the codec.h in the apps dir
 # .. for stuff in the codecs dir
 # . for stuff in the codeclib dir
-INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export	\
+INCLUDES=-I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export	\
  -I$(FIRMDIR)/common -I$(BUILDDIR)
 
 ifdef APPEXTRA
diff --git a/apps/plugins/Makefile b/apps/plugins/Makefile
index 2dd8ab2..0b2974f 100644
--- a/apps/plugins/Makefile
+++ b/apps/plugins/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common \
+INCLUDES = $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common \
  -I$(FIRMDIR)/drivers -I$(APPSDIR) -Ilib -I$(BUILDDIR) \
  -I$(BUILDDIR)/pluginbitmaps
 CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET) $(EXTRA_DEFINES)	\
diff --git a/apps/plugins/chessbox/Makefile b/apps/plugins/chessbox/Makefile
index eb2df44..66381be 100644
--- a/apps/plugins/chessbox/Makefile
+++ b/apps/plugins/chessbox/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(GCCOPTS) -O2 $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
diff --git a/apps/plugins/databox/Makefile b/apps/plugins/databox/Makefile
index 1205234..507a861 100644
--- a/apps/plugins/databox/Makefile
+++ b/apps/plugins/databox/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(INCLUDES) $(GCCOPTS) -O3 $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
diff --git a/apps/plugins/doom/Makefile b/apps/plugins/doom/Makefile
index 0eef697..b79f5be 100644
--- a/apps/plugins/doom/Makefile
+++ b/apps/plugins/doom/Makefile
@@ -3,7 +3,10 @@
 # $Id$
 #
 # $Log$
-# Revision 1.3  2006/04/14 21:07:56  kkurbjun
+# Revision 1.4  2006/07/27 13:27:19  linus
+# Moved the X5 button driver to the target tree
+#
+# Revision 1.3  2006-04-14 21:07:56  kkurbjun
 # Start of profiling support for doom.
 #
 # Revision 1.2  2006-03-29 21:16:45  kkurbjun
@@ -14,7 +17,7 @@
 #
 # 
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN \
diff --git a/apps/plugins/lib/Makefile b/apps/plugins/lib/Makefile
index 916c632..8482b1f 100644
--- a/apps/plugins/lib/Makefile
+++ b/apps/plugins/lib/Makefile
@@ -10,7 +10,7 @@
 # ../.. for the plugin.h in the apps dir
 # .. for stuff in the plugins dir
 # . for stuff in the pluginlib dir
-INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export	\
+INCLUDES=-I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export	\
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(BUILDDIR)
 
 ifdef APPEXTRA
diff --git a/apps/plugins/pacbox/Makefile b/apps/plugins/pacbox/Makefile
index 0b7f4b9..4a5442c 100644
--- a/apps/plugins/pacbox/Makefile
+++ b/apps/plugins/pacbox/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(INCLUDES) $(GCCOPTS) -O2 $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
diff --git a/apps/plugins/rockboy/Makefile b/apps/plugins/rockboy/Makefile
index 694dcde..39e684e 100644
--- a/apps/plugins/rockboy/Makefile
+++ b/apps/plugins/rockboy/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(INCLUDES) $(GCCOPTS) -O2 $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN -finline-functions
diff --git a/apps/plugins/searchengine/Makefile b/apps/plugins/searchengine/Makefile
index 21b53cb..92e9f03 100644
--- a/apps/plugins/searchengine/Makefile
+++ b/apps/plugins/searchengine/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(INCLUDES) $(GCCOPTS) -O3 $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
diff --git a/apps/plugins/sudoku/Makefile b/apps/plugins/sudoku/Makefile
index 9b9c1c6..eef0512 100644
--- a/apps/plugins/sudoku/Makefile
+++ b/apps/plugins/sudoku/Makefile
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-INCLUDES = -I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
  -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
 CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
  -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
diff --git a/firmware/SOURCES b/firmware/SOURCES
index bef54c0..70a4c4a 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -217,6 +217,7 @@
 target/coldfire/iaudio/x5/power-x5.c
 #ifndef SIMULATOR
 drivers/generic_i2c.c
+target/coldfire/iaudio/x5/button-x5.c
 target/coldfire/iaudio/x5/lcd-x5.c
 target/coldfire/iaudio/x5/pcf50606-x5.c
 target/coldfire/iaudio/x5/adc-x5.c
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 216c51e..d9f9ae2 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -44,6 +44,10 @@
 #include "lcd-remote.h"
 #endif
 
+#ifdef TARGET_TREE
+#include "button-target.h"
+#endif
+
 struct event_queue button_queue;
 
 static long lastbtn;   /* Last valid button status */
@@ -72,10 +76,7 @@
     (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
 #define POWEROFF_BUTTON BUTTON_PLAY
 #define POWEROFF_COUNT 40
-#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
-#define POWEROFF_BUTTON BUTTON_POWER
-#define POWEROFF_COUNT 10
-#else
+#elif !defined(TARGET_TREE)
 #define POWEROFF_BUTTON BUTTON_OFF
 #define POWEROFF_COUNT 10
 #endif
@@ -603,7 +604,10 @@
 void button_init(void)
 {
     /* hardware inits */
-#if CONFIG_KEYPAD == IRIVER_H100_PAD
+#ifdef TARGET_TREE
+    button_init_device();
+    
+#elif CONFIG_KEYPAD == IRIVER_H100_PAD
     /* Set GPIO33, GPIO37, GPIO38  and GPIO52 as general purpose inputs */
     GPIO1_FUNCTION |= 0x00100062;
     GPIO1_ENABLE &= ~0x00100060;
@@ -614,11 +618,6 @@
     /* Set GPIO33, GPIO37, GPIO38  and GPIO52 as general purpose inputs */
     GPIO1_ENABLE &= ~0x00100060;
     GPIO1_FUNCTION |= 0x00100062;
-#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
-    /* Power, Remote Play & Hold switch */
-    GPIO_FUNCTION |= 0x0e000000;
-    GPIO_ENABLE &= ~0x0e000000;
-
 #elif CONFIG_KEYPAD == RECORDER_PAD
     /* Set PB4 and PB8 as input pins */
     PBCR1 &= 0xfffc;  /* PB8MD = 00 */
@@ -833,9 +832,14 @@
 {
     int btn = BUTTON_NONE;
     int retval;
+#ifndef TARGET_TREE
     int data;
+#endif
 
-#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
+#ifdef TARGET_TREE
+    btn = button_read_device();
+    
+#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
     static bool hold_button = false;
     static bool remote_hold_button = false;
     static int prev_data = 0xff;
@@ -1238,86 +1242,6 @@
     (void)data;
     btn = ipod_3g_button_read();
 
-#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
-    static bool hold_button = false;
-    static bool remote_hold_button = false;
-
-    /* light handling */
-    if (hold_button && !button_hold())
-    {
-        backlight_on();
-    }
-    /* TODO: add light handling for the remote */
-
-    hold_button = button_hold();
-    remote_hold_button = remote_button_hold();
-
-    /* normal buttons */
-    if (!hold_button)
-    {
-        data = adc_scan(ADC_BUTTONS);
-        if (data < 0xf0)
-        {
-            if(data < 0x7c)
-                if(data < 0x42)
-                    btn = BUTTON_LEFT;
-                else
-                    if(data < 0x62)
-                        btn = BUTTON_RIGHT;
-                    else
-                        btn = BUTTON_SELECT;
-            else
-                if(data < 0xb6)
-                    if(data < 0x98)
-                        btn = BUTTON_REC;
-                    else
-                        btn = BUTTON_PLAY;
-                else
-                    if(data < 0xd3)
-                        btn = BUTTON_DOWN;
-                    else
-                        btn = BUTTON_UP;
-        }
-    }
-
-    /* remote buttons */
-    data = adc_scan(ADC_REMOTE);
-    if(data < 0x17)
-        remote_hold_button = true;
-
-    if(!remote_hold_button)
-    {
-        if (data < 0xee)
-        {
-            if(data < 0x7a)
-                if(data < 0x41)
-                    btn |= BUTTON_RC_REW;
-                else
-                    if(data < 0x61)
-                        btn |= BUTTON_RC_FF;
-                    else
-                        btn |= BUTTON_RC_MODE;
-            else
-                if(data < 0xb4)
-                    if(data < 0x96)
-                        btn |= BUTTON_RC_REC;
-                    else
-                        btn |= BUTTON_RC_MENU;
-                else
-                    if(data < 0xd1)
-                        btn |= BUTTON_RC_VOL_UP;
-                    else
-                        btn |= BUTTON_RC_VOL_DOWN;
-        }
-    }
-
-    data = GPIO_READ;
-    if (!(data & 0x04000000))
-        btn |= BUTTON_POWER;
-
-    if (!(data & 0x02000000))
-        btn |= BUTTON_RC_PLAY;
-
 #endif /* CONFIG_KEYPAD */
 
 #ifdef HAVE_LCD_BITMAP
@@ -1375,18 +1299,6 @@
 }
 #endif
 
-#if (CONFIG_KEYPAD == IAUDIO_X5_PAD)
-bool button_hold(void)
-{
-    return (GPIO_READ & 0x08000000)?false:true;
-}
-
-bool remote_button_hold(void)
-{
-    return false; /* TODO X5 */
-}
-#endif
-
 int button_status(void)
 {
     return lastbtn;
diff --git a/firmware/export/button.h b/firmware/export/button.h
index 93e6443..92c9415 100644
--- a/firmware/export/button.h
+++ b/firmware/export/button.h
@@ -23,8 +23,7 @@
 #include <stdbool.h>
 #include "config.h"
 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
-    (CONFIG_KEYPAD == IRIVER_H300_PAD) || \
-    (CONFIG_KEYPAD == IAUDIO_X5_PAD)
+    (CONFIG_KEYPAD == IRIVER_H300_PAD)
 #define HAS_BUTTON_HOLD
 #define HAS_REMOTE_BUTTON_HOLD
 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
@@ -64,6 +63,10 @@
 #define BUTTON_REPEAT       0x04000000
 
 
+#ifdef TARGET_TREE
+#include "button-target.h"
+#else
+
   /* Target specific button codes */
 
 #if (CONFIG_KEYPAD == IRIVER_H100_PAD)\
@@ -258,44 +261,6 @@
 
 #define BUTTON_REMOTE 0
 
-#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
-
-/* iaudio X5 specific button codes */
-
-    /* Main unit's buttons */
-#define BUTTON_POWER        0x00000001
-#define BUTTON_REC          0x00000002
-
-#define BUTTON_LEFT         0x00000004
-#define BUTTON_RIGHT        0x00000008
-#define BUTTON_UP           0x00000010
-#define BUTTON_DOWN         0x00000020
-
-#define BUTTON_PLAY         0x00000040
-#define BUTTON_SELECT       0x00000080
-
-#define BUTTON_MAIN (BUTTON_POWER|BUTTON_PLAY|BUTTON_LEFT|BUTTON_RIGHT\
-                |BUTTON_UP|BUTTON_DOWN|BUTTON_REC|BUTTON_SELECT)
-
-    /* Remote control's buttons */
-#define BUTTON_RC_PLAY      0x00100000
-
-#define BUTTON_RC_REW       0x00080000
-#define BUTTON_RC_FF        0x00040000
-#define BUTTON_RC_VOL_UP    0x00020000
-#define BUTTON_RC_VOL_DOWN  0x00010000
-
-#define BUTTON_RC_REC       0x00008000
-#define BUTTON_RC_MENU      0x00004000
-
-#define BUTTON_RC_MODE      0x00002000
-
-#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN\
-                |BUTTON_RC_REW|BUTTON_RC_FF\
-                |BUTTON_RC_REC|BUTTON_RC_MENU|BUTTON_RC_MODE)
-
-
-
 #elif CONFIG_KEYPAD == GIGABEAT_PAD
 /* Toshiba Gigabeat specific button codes */
 
@@ -337,5 +302,7 @@
 
 #endif /* RECORDER/PLAYER/ONDIO/GMINI KEYPAD */
 
+#endif /* TARGET_TREE */
+
 #endif /* _BUTTON_H_ */
 
diff --git a/firmware/target/coldfire/iaudio/x5/button-target.h b/firmware/target/coldfire/iaudio/x5/button-target.h
new file mode 100755
index 0000000..998522f
--- /dev/null
+++ b/firmware/target/coldfire/iaudio/x5/button-target.h
@@ -0,0 +1,70 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _BUTTON_TARGET_H_
+#define _BUTTON_TARGET_H_
+
+#include <stdbool.h>
+#include "config.h"
+
+#define HAS_BUTTON_HOLD
+#define HAS_REMOTE_BUTTON_HOLD
+
+bool button_hold(void);
+bool remote_button_hold(void);
+void button_init_device(void);
+int button_read_device(void);
+
+/* iaudio X5 specific button codes */
+
+    /* Main unit's buttons */
+#define BUTTON_POWER        0x00000001
+#define BUTTON_REC          0x00000002
+
+#define BUTTON_LEFT         0x00000004
+#define BUTTON_RIGHT        0x00000008
+#define BUTTON_UP           0x00000010
+#define BUTTON_DOWN         0x00000020
+
+#define BUTTON_PLAY         0x00000040
+#define BUTTON_SELECT       0x00000080
+
+#define BUTTON_MAIN (BUTTON_POWER|BUTTON_PLAY|BUTTON_LEFT|BUTTON_RIGHT\
+                |BUTTON_UP|BUTTON_DOWN|BUTTON_REC|BUTTON_SELECT)
+
+    /* Remote control's buttons */
+#define BUTTON_RC_PLAY      0x00100000
+
+#define BUTTON_RC_REW       0x00080000
+#define BUTTON_RC_FF        0x00040000
+#define BUTTON_RC_VOL_UP    0x00020000
+#define BUTTON_RC_VOL_DOWN  0x00010000
+
+#define BUTTON_RC_REC       0x00008000
+#define BUTTON_RC_MENU      0x00004000
+
+#define BUTTON_RC_MODE      0x00002000
+
+#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN\
+                |BUTTON_RC_REW|BUTTON_RC_FF\
+                |BUTTON_RC_REC|BUTTON_RC_MENU|BUTTON_RC_MODE)
+
+#define POWEROFF_BUTTON BUTTON_POWER
+#define POWEROFF_COUNT 10
+
+#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/coldfire/iaudio/x5/button-x5.c b/firmware/target/coldfire/iaudio/x5/button-x5.c
new file mode 100755
index 0000000..07bc7bf
--- /dev/null
+++ b/firmware/target/coldfire/iaudio/x5/button-x5.c
@@ -0,0 +1,131 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include "config.h"
+#include "cpu.h"
+#include "system.h"
+#include "button.h"
+#include "kernel.h"
+#include "backlight.h"
+#include "adc.h"
+#include "system.h"
+
+void button_init_device(void)
+{
+    /* Power, Remote Play & Hold switch */
+    GPIO_FUNCTION |= 0x0e000000;
+    GPIO_ENABLE &= ~0x0e000000;
+}
+
+bool button_hold(void)
+{
+    return (GPIO_READ & 0x08000000)?false:true;
+}
+
+bool remote_button_hold(void)
+{
+    return false; /* TODO X5 */
+}
+
+int button_read_device(void)
+{
+    int data;
+    int btn = BUTTON_NONE;
+    static bool hold_button = false;
+    static bool remote_hold_button = false;
+
+    /* backlight handling */
+    if (hold_button && !button_hold())
+    {
+        backlight_on();
+    }
+    /* TODO: add light handling for the remote */
+
+    hold_button = button_hold();
+    remote_hold_button = remote_button_hold();
+
+    /* normal buttons */
+    if (!hold_button)
+    {
+        data = adc_scan(ADC_BUTTONS);
+        if (data < 0xf0)
+        {
+            if(data < 0x7c)
+                if(data < 0x42)
+                    btn = BUTTON_LEFT;
+                else
+                    if(data < 0x62)
+                        btn = BUTTON_RIGHT;
+                    else
+                        btn = BUTTON_SELECT;
+            else
+                if(data < 0xb6)
+                    if(data < 0x98)
+                        btn = BUTTON_REC;
+                    else
+                        btn = BUTTON_PLAY;
+                else
+                    if(data < 0xd3)
+                        btn = BUTTON_DOWN;
+                    else
+                        btn = BUTTON_UP;
+        }
+    }
+
+    /* remote buttons */
+    data = adc_scan(ADC_REMOTE);
+    if(data < 0x17)
+        remote_hold_button = true;
+
+    if(!remote_hold_button)
+    {
+        if (data < 0xee)
+        {
+            if(data < 0x7a)
+                if(data < 0x41)
+                    btn |= BUTTON_RC_REW;
+                else
+                    if(data < 0x61)
+                        btn |= BUTTON_RC_FF;
+                    else
+                        btn |= BUTTON_RC_MODE;
+            else
+                if(data < 0xb4)
+                    if(data < 0x96)
+                        btn |= BUTTON_RC_REC;
+                    else
+                        btn |= BUTTON_RC_MENU;
+                else
+                    if(data < 0xd1)
+                        btn |= BUTTON_RC_VOL_UP;
+                    else
+                        btn |= BUTTON_RC_VOL_DOWN;
+        }
+    }
+
+    data = GPIO_READ;
+    if (!(data & 0x04000000))
+        btn |= BUTTON_POWER;
+
+    if (!(data & 0x02000000))
+        btn |= BUTTON_RC_PLAY;
+
+    return btn;
+}
diff --git a/uisimulator/common/Makefile b/uisimulator/common/Makefile
index e4f3dd9..1024349 100644
--- a/uisimulator/common/Makefile
+++ b/uisimulator/common/Makefile
@@ -23,7 +23,7 @@
 DEBUG = -g
 
 # Use this for simulator-only files
-INCLUDES = -I. -I$(OBJDIR) -I$(FIRMDIR)/export -I$(APPSDIR)	\
+INCLUDES = -I. -I$(OBJDIR) $(TARGET_INC) -I$(FIRMDIR)/export -I$(APPSDIR)	\
 -I$(ROOTDIR)/uisimulator/$(SIMVER) -I$(BUILDDIR)
 
 # This sets up 'SRC' based on the files mentioned in SOURCES
diff --git a/uisimulator/sdl/Makefile b/uisimulator/sdl/Makefile
index 5c5693e..0ebf103 100644
--- a/uisimulator/sdl/Makefile
+++ b/uisimulator/sdl/Makefile
@@ -25,7 +25,7 @@
 DEBUG = -g
 
 # Use this for simulator-only files
-INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) -I$(FIRMDIR)/export -I$(APPSDIR) \
+INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) $(TARGET_INC) -I$(FIRMDIR)/export -I$(APPSDIR) \
  -I$(BUILDDIR)
 
 # This sets up 'SRC' based on the files mentioned in SOURCES