summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2009-07-26 14:26:14 +0000
committerRobert Kukla <roolku@rockbox.org>2009-07-26 14:26:14 +0000
commit275a30092e84f9d026a18bcf90b2f29721302a33 (patch)
tree8c8c84673fbee68dd79d65a8269744c82669392a /firmware
parent682a991f0f5df93a4b32042d64d9a9ccb1d0dcdf (diff)
downloadrockbox-275a30092e84f9d026a18bcf90b2f29721302a33.tar.gz
rockbox-275a30092e84f9d026a18bcf90b2f29721302a33.tar.bz2
rockbox-275a30092e84f9d026a18bcf90b2f29721302a33.zip
initial commit of remote support for m:robe 100 courtesy of lowlight; simulator support including small fixes for the m:robe 500
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22053 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/export/config-mrobe100.h24
-rw-r--r--firmware/target/arm/olympus/mrobe-100/backlight-mr100.c13
-rw-r--r--firmware/target/arm/olympus/mrobe-100/backlight-target.h5
-rw-r--r--firmware/target/arm/olympus/mrobe-100/button-mr100.c72
-rw-r--r--firmware/target/arm/olympus/mrobe-100/button-target.h30
-rw-r--r--firmware/target/arm/olympus/mrobe-100/lcd-remote-mr100.c562
-rw-r--r--firmware/target/arm/olympus/mrobe-100/lcd-remote-target.h40
-rw-r--r--firmware/target/arm/olympus/mrobe-100/power-mr100.c5
-rw-r--r--firmware/target/arm/system-pp502x.c6
10 files changed, 739 insertions, 19 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 3a6e49d0d2..46c1f58cb3 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -909,6 +909,7 @@ target/arm/tms320dm320/creative-zvm/usb-creativezvm.c
#ifndef SIMULATOR
#ifndef BOOTLOADER
drivers/synaptics-mep.c
+target/arm/olympus/mrobe-100/lcd-remote-mr100.c
#endif /* BOOTLOADER */
drivers/sw_i2c.c
target/arm/ata-as-arm.S
diff --git a/firmware/export/config-mrobe100.h b/firmware/export/config-mrobe100.h
index b1299a820a..3fcef555d4 100644
--- a/firmware/export/config-mrobe100.h
+++ b/firmware/export/config-mrobe100.h
@@ -45,7 +45,24 @@
/*#define IRAM_LCDFRAMEBUFFER IDATA_ATTR */ /* put the lcd frame buffer in IRAM */
-#define CONFIG_KEYPAD MROBE100_PAD
+#ifndef BOOTLOADER
+/* Define this if you have an remote lcd */
+#define HAVE_REMOTE_LCD
+
+#define LCD_REMOTE_WIDTH 79
+#define LCD_REMOTE_HEIGHT 16
+#define LCD_REMOTE_DEPTH 1
+#define LCD_REMOTE_PIXELFORMAT VERTICAL_PACKING
+
+/* Remote display colours, for screenshots and sim (0xRRGGBB) */
+#define LCD_REMOTE_DARKCOLOR 0x000000
+#define LCD_REMOTE_BRIGHTCOLOR 0x5a915a
+#define LCD_REMOTE_BL_DARKCOLOR 0x000000
+#define LCD_REMOTE_BL_BRIGHTCOLOR 0x82b4fa
+#endif /* BOOTLOADER */
+
+#define CONFIG_KEYPAD MROBE100_PAD
+#define CONFIG_REMOTE_KEYPAD MROBE_REMOTE
/* Define this if you do software codec */
#define CONFIG_CODEC SWCODEC
@@ -90,6 +107,11 @@
#define HAVE_BUTTONLIGHT_BRIGHTNESS
+/* Remote LCD contrast range and defaults */
+#define MIN_REMOTE_CONTRAST_SETTING 0
+#define MAX_REMOTE_CONTRAST_SETTING 15
+#define DEFAULT_REMOTE_CONTRAST_SETTING 8
+
/* Define this if your LCD can be enabled/disabled */
/* TODO: #define HAVE_LCD_ENABLE */
diff --git a/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c b/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c
index f3891c5000..7dd80946cd 100644
--- a/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c
+++ b/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "system.h"
#include "backlight-target.h"
+#include "lcd-remote-target.h"
#define MIN_BRIGHTNESS 0x80ff08ff
@@ -62,3 +63,15 @@ void _buttonlight_off(void)
/* turn off all touchpad leds */
GPIOA_OUTPUT_VAL &= ~BUTTONLIGHT_ALL;
}
+
+#ifdef HAVE_REMOTE_LCD
+void _remote_backlight_on(void)
+{
+ lcd_remote_backlight(true);
+}
+
+void _remote_backlight_off(void)
+{
+ lcd_remote_backlight(false);
+}
+#endif
diff --git a/firmware/target/arm/olympus/mrobe-100/backlight-target.h b/firmware/target/arm/olympus/mrobe-100/backlight-target.h
index ca5c548eff..df25106d1a 100644
--- a/firmware/target/arm/olympus/mrobe-100/backlight-target.h
+++ b/firmware/target/arm/olympus/mrobe-100/backlight-target.h
@@ -26,6 +26,11 @@ bool _backlight_init(void); /* Returns backlight current state (true=ON). */
void _backlight_hw_on(void);
void _backlight_hw_off(void);
+#ifdef HAVE_REMOTE_LCD
+void _remote_backlight_on(void);
+void _remote_backlight_off(void);
+#endif
+
#ifdef BOOTLOADER
#define _backlight_on() _backlight_hw_on()
#define _backlight_off() _backlight_hw_off()
diff --git a/firmware/target/arm/olympus/mrobe-100/button-mr100.c b/firmware/target/arm/olympus/mrobe-100/button-mr100.c
index d4479278ef..e7979a4174 100644
--- a/firmware/target/arm/olympus/mrobe-100/button-mr100.c
+++ b/firmware/target/arm/olympus/mrobe-100/button-mr100.c
@@ -25,6 +25,12 @@
#include "backlight-target.h"
#include "synaptics-mep.h"
+#ifdef HAVE_REMOTE_LCD
+#include "lcd-remote-target.h"
+static bool remote_hold = false;
+static bool headphones_status = true;
+#endif
+
#define LOGF_ENABLE
#include "logf.h"
@@ -56,6 +62,13 @@ void button_init_device(void)
{
logf("touchpad not ready");
}
+
+ /* headphone detection bit */
+ GPIOD_OUTPUT_EN &= ~0x80;
+ GPIOD_ENABLE |= 0x80;
+
+ /* remote detection (via headphone state) */
+ headphones_int();
}
/*
@@ -102,13 +115,35 @@ void button_init_device(void){}
*/
int button_read_device(void)
{
- int btn = int_btn;
+ int btn = BUTTON_NONE;
- if(button_hold())
- return BUTTON_NONE;
-
- if (~GPIOA_INPUT_VAL & 0x40)
- btn |= BUTTON_POWER;
+#ifdef HAVE_REMOTE_LCD
+ unsigned char data[5];
+
+ if (lcd_remote_read_device(data))
+ {
+ remote_hold = (data[2] & 0x80) ? true : false;
+ if (!remote_hold)
+ {
+ if (data[1] & 0x1) btn |= BUTTON_RC_PLAY;
+ if (data[1] & 0x2) btn |= BUTTON_RC_DOWN;
+ if (data[1] & 0x4) btn |= BUTTON_RC_FF;
+ if (data[1] & 0x8) btn |= BUTTON_RC_REW;
+ if (data[1] & 0x10) btn |= BUTTON_RC_VOL_UP;
+ if (data[1] & 0x20) btn |= BUTTON_RC_VOL_DOWN;
+ if (data[1] & 0x40) btn |= BUTTON_RC_MODE;
+ if (data[1] & 0x80) btn |= BUTTON_RC_HEART;
+ }
+ }
+#endif
+
+ if(!button_hold())
+ {
+ btn |= int_btn;
+
+ if (~GPIOA_INPUT_VAL & 0x40)
+ btn |= BUTTON_POWER;
+ }
return btn;
}
@@ -118,7 +153,32 @@ bool button_hold(void)
return (GPIOD_INPUT_VAL & 0x10) ? false : true;
}
+#ifdef HAVE_REMOTE_LCD
+bool remote_button_hold(void)
+{
+ return remote_hold;
+}
+
+bool headphones_inserted(void)
+{
+ return headphones_status;
+}
+
+void headphones_int(void)
+{
+ int state = 0x80 & ~GPIOD_INPUT_VAL;
+ headphones_status = (state) ? true : false;
+
+ GPIO_CLEAR_BITWISE(GPIOD_INT_EN, 0x80);
+ GPIO_WRITE_BITWISE(GPIOD_INT_LEV, state, 0x80);
+ GPIO_WRITE_BITWISE(GPIOD_INT_CLR, 0x80, 0x80);
+ GPIO_SET_BITWISE(GPIOD_INT_EN, 0x80);
+
+ lcd_remote_on();
+}
+#else
bool headphones_inserted(void)
{
return (GPIOD_INPUT_VAL & 0x80) ? false : true;
}
+#endif
diff --git a/firmware/target/arm/olympus/mrobe-100/button-target.h b/firmware/target/arm/olympus/mrobe-100/button-target.h
index 900211ebe4..93d42d62fb 100644
--- a/firmware/target/arm/olympus/mrobe-100/button-target.h
+++ b/firmware/target/arm/olympus/mrobe-100/button-target.h
@@ -29,22 +29,14 @@
#define MEP_BUTTON_ID 0x09
#define MEP_ABSOLUTE_HEADER 0x0b
-#define HAS_BUTTON_HOLD
-
bool button_hold(void);
void button_init_device(void);
-int button_read_device(void);
+int button_read_device(void);
#ifndef BOOTLOADER
void button_int(void);
#endif
-#define POWEROFF_BUTTON BUTTON_POWER
-#define POWEROFF_COUNT 10
-
-/* FIXME: Until the buttons are figured out, we use the button definitions
- for the H10 keypad & remote. THESE ARE NOT CORRECT! */
-
/* Main unit's buttons */
#define BUTTON_PLAY 0x00000001
#define BUTTON_MENU 0x00000002
@@ -61,18 +53,32 @@ void button_int(void);
|BUTTON_RIGHT|BUTTON_SELECT|BUTTON_UP|BUTTON_SLIDE_UP\
|BUTTON_DOWN|BUTTON_SLIDE_DOWN|BUTTON_POWER)
+#define HAS_BUTTON_HOLD
+
+#define POWEROFF_BUTTON BUTTON_POWER
+#define POWEROFF_COUNT 10
+
+#ifdef HAVE_REMOTE_LCD
+void headphones_int(void);
+bool remote_button_hold(void);
+
/* Remote control's buttons */
#define BUTTON_RC_PLAY 0x00010000
#define BUTTON_RC_REW 0x00020000
#define BUTTON_RC_FF 0x00040000
-#define BUTTON_RC_DISPLAY 0x00080000
-#define BUTTON_RC_FAV 0x00100000
+#define BUTTON_RC_DOWN 0x00080000
+#define BUTTON_RC_HEART 0x00100000
#define BUTTON_RC_MODE 0x00200000
#define BUTTON_RC_VOL_UP 0x00400000
#define BUTTON_RC_VOL_DOWN 0x00800000
#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_REW|BUTTON_RC_FF\
- |BUTTON_RC_DISPLAY|BUTTON_RC_FAV|BUTTON_RC_MODE\
+ |BUTTON_RC_DOWN|BUTTON_RC_HEART|BUTTON_RC_MODE\
|BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN)
+
+#define HAS_REMOTE_BUTTON_HOLD
#define RC_POWEROFF_BUTTON BUTTON_RC_PLAY
+#else
+#define BUTTON_REMOTE 0
+#endif /* HAVE_REMOTE_LCD */
#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/olympus/mrobe-100/lcd-remote-mr100.c b/firmware/target/arm/olympus/mrobe-100/lcd-remote-mr100.c
new file mode 100644
index 0000000000..036b6ae71c
--- /dev/null
+++ b/firmware/target/arm/olympus/mrobe-100/lcd-remote-mr100.c
@@ -0,0 +1,562 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2009 Mark Arigo
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "cpu.h"
+#include "kernel.h"
+#include "thread.h"
+#include "system.h"
+#include "lcd-remote.h"
+#include "button.h"
+#include "button-target.h"
+
+/* Temporary defines until we sort out why the gui stuff doesn't like this size
+ (I believe the status bar isn't doing sanity checks and is writing outside
+ the frame buffer size). */
+#define RC_WIDTH 79
+#define RC_HEIGHT 16
+
+#define RC_CONTRAST_MASK 0x000000ff
+#define RC_SCREEN_ON 0x00000100
+#define RC_BACKLIGHT_ON 0x00000200
+
+#define RC_DEV_INIT 0x00001000
+#define RC_DETECTED 0x00002000
+#define RC_AWAKE 0x00004000
+#define RC_POWER_OFF 0x00008000
+
+#define RC_UPDATE_LCD 0x00010000
+#define RC_UPDATE_CONTROLLER 0x00020000
+#define RC_UPDATE_ICONS 0x00040000
+#define RC_UPDATE_MASK (RC_UPDATE_LCD|RC_UPDATE_CONTROLLER|RC_UPDATE_ICONS)
+
+#define RC_TX_ERROR 0x00100000
+#define RC_RX_ERROR 0x00200000
+#define RC_TIMEOUT_ERROR 0x00400000
+#define RC_ERROR_MASK (RC_TX_ERROR|RC_RX_ERROR|RC_TIMEOUT_ERROR)
+
+#define RC_FORCE_DETECT 0x80000000
+
+#define RX_READY 0x01
+#define TX_READY 0x20
+
+#define POLL_TIMEOUT 50000
+
+bool remote_initialized = false;
+unsigned int rc_status = 0;
+unsigned char rc_buf[5];
+
+/* ================================================== */
+/* Remote thread functions */
+/* These functions are private to the remote thread */
+/* ================================================== */
+static struct wakeup rc_thread_wakeup;
+static unsigned int remote_thread_id;
+static int remote_stack[256/sizeof(int)];
+static const char * const remote_thread_name = "remote";
+
+static bool remote_wait_ready(int ready_mask)
+{
+ unsigned long current;
+ unsigned long start = USEC_TIMER;
+ unsigned long timeout = start + POLL_TIMEOUT;
+
+ rc_status &= ~RC_TIMEOUT_ERROR;
+
+ if (start <= timeout)
+ {
+ do
+ {
+ if (SER1_LSR & ready_mask)
+ return true;
+
+ //~ sleep(1);
+
+ current = USEC_TIMER;
+ } while (current < timeout);
+ }
+ else
+ {
+ do
+ {
+ if (SER1_LSR & ready_mask)
+ return true;
+
+ //~ sleep(1);
+
+ current = USEC_TIMER - POLL_TIMEOUT;
+ } while (current < start);
+ }
+
+ rc_status |= RC_TIMEOUT_ERROR;
+ return false;
+}
+
+static bool remote_rx(void)
+{
+ int i;
+ unsigned char chksum[2];
+
+ rc_status &= ~RC_RX_ERROR;
+
+ for (i = 0; i < 5; i++)
+ {
+ if (!remote_wait_ready(RX_READY))
+ {
+ rc_status |= RC_RX_ERROR;
+ return false;
+ }
+
+ rc_buf[i] = SER1_RBR;
+ }
+
+ /* check opcode */
+ if ((rc_buf[0] & 0xf0) != 0xf0)
+ {
+ rc_status |= RC_RX_ERROR;
+ return false;
+ }
+
+ /* verify the checksums */
+ chksum[0] = chksum[1] = 0;
+ for (i = 0; i < 3; i++)
+ {
+ chksum[0] ^= rc_buf[i];
+ chksum[1] += rc_buf[i];
+ }
+
+ if ((chksum[0] != rc_buf[3]) && (chksum[1] != rc_buf[4]))
+ {
+ rc_status |= RC_RX_ERROR;
+ return false;
+ }
+
+ /* reception error */
+ if ((rc_buf[0] & 0x1) || (rc_buf[0] & 0x2) || (rc_buf[0] & 0x4))
+ {
+ rc_status |= RC_RX_ERROR;
+ return false;
+ }
+
+ return true;
+}
+
+static bool remote_tx(unsigned char *data, int len)
+{
+ int i;
+ unsigned char chksum[2];
+
+ rc_status &= ~RC_TX_ERROR;
+
+ chksum[0] = chksum[1] = 0;
+
+ for (i = 0; i < len; i++)
+ {
+ if (!remote_wait_ready(TX_READY))
+ {
+ rc_status |= RC_TX_ERROR;
+ return false;
+ }
+
+ SER1_THR = data[i];
+ chksum[0] ^= data[i];
+ chksum[1] += data[i];
+ }
+
+ for (i = 0; i < 2; i++)
+ {
+ if (!remote_wait_ready(TX_READY))
+ {
+ rc_status |= RC_TX_ERROR;
+ return false;
+ }
+
+ SER1_THR = chksum[i];
+ }
+
+ return remote_rx();
+}
+
+static void remote_dev_enable(bool enable)
+{
+ if (enable)
+ {
+ outl(inl(0x70000018) | 0xaa000, 0x70000018);
+ DEV_INIT2 &= ~0x800;
+
+ GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
+ GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x80);
+
+ DEV_EN |= DEV_SER1;
+
+ SER1_RBR;
+ SER1_LCR = 0x80;
+ SER1_DLL = 0x50;
+ SER1_DLM = 0x00;
+ SER1_LCR = 0x03;
+ SER1_FCR = 0x07;
+
+ rc_status |= RC_DEV_INIT;
+ }
+ else
+ {
+ outl(inl(0x70000018) & ~0xaa000, 0x70000018);
+ DEV_INIT2 &= ~0x800;
+
+ GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
+ GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x80);
+
+ DEV_RS |= DEV_SER1;
+ nop;
+ DEV_RS &= ~DEV_SER1;
+
+ DEV_EN &= ~DEV_SER1;
+
+ rc_status &= ~RC_DEV_INIT;
+ }
+}
+
+void remote_update_lcd(void)
+{
+ int x, y, draw_now;
+ unsigned char data[RC_WIDTH + 7];
+
+ /* If the draw_now bit is set, the draw occurs directly on the LCD.
+ Otherwise, the data is stored in an off-screen buffer and displayed
+ the next time a draw operation is executed with this flag set. */
+ draw_now = 0;
+
+ for (y = 0; y < 2; y++)
+ {
+ data[0] = 0x51;
+ data[1] = draw_now << 7;
+ data[2] = RC_WIDTH; /* width */
+ data[3] = 0; /* x1 */
+ data[4] = y << 3; /* y1 */
+ data[5] = RC_WIDTH; /* x2 */
+ data[6] = (y + 1) << 3; /* y2 */
+
+ for (x = 0; x < RC_WIDTH; x++)
+ data[x + 7] = lcd_remote_framebuffer[y][x];
+
+ remote_tx(data, RC_WIDTH + 7);
+
+ draw_now = 1;
+ }
+}
+
+static void remote_update_controller(void)
+{
+ unsigned char data[3];
+
+ data[0] = 0x31;
+ data[1] = 0x00;
+ if (rc_status & RC_SCREEN_ON)
+ data[1] |= 0x80;
+ if (rc_status & RC_BACKLIGHT_ON)
+ data[1] |= 0x40;
+ data[2] = (unsigned char)(rc_status & RC_CONTRAST_MASK);
+ remote_tx(data, 3);
+}
+
+#if 0
+static void remote_update_icons(unsigned char symbols)
+{
+ unsigned char data[2];
+
+ if (!(rc_status & RC_AWAKE) && !(rc_status & RC_SCREEN_ON))
+ return;
+
+ data[0] = 0x41;
+ data[1] = symbols;
+ remote_tx(data, 2);
+}
+#endif
+
+static bool remote_nop(void)
+{
+ unsigned char val[2];
+
+ val[0] = 0x11;
+ val[1] = 0x30;
+ return remote_tx(val, 2);
+}
+
+static void remote_wake(void)
+{
+ if (remote_nop())
+ {
+ rc_status |= RC_AWAKE;
+ return;
+ }
+
+ rc_status &= ~RC_AWAKE;
+ return;
+}
+
+static void remote_sleep(void)
+{
+ unsigned char data[2];
+
+ if (rc_status & RC_AWAKE)
+ {
+ data[0] = 0x71;
+ data[1] = 0x30;
+ remote_tx(data, 2);
+
+ udelay(25000);
+ }
+
+ rc_status &= ~RC_AWAKE;
+}
+
+static void remote_off(void)
+{
+ if (rc_status & RC_AWAKE)
+ remote_sleep();
+
+ if (rc_status & RC_DEV_INIT)
+ remote_dev_enable(false);
+
+ rc_status &= ~(RC_DETECTED | RC_ERROR_MASK | RC_UPDATE_MASK);
+ remote_initialized = false;
+}
+
+static void remote_on(void)
+{
+ if (!(rc_status & RC_DEV_INIT))
+ remote_dev_enable(true);
+
+ remote_wake();
+
+ if (rc_status & RC_AWAKE)
+ {
+ rc_status |= RC_DETECTED;
+ remote_initialized = true;
+
+ rc_status |= (RC_UPDATE_MASK | RC_SCREEN_ON | RC_BACKLIGHT_ON);
+ //~ remote_update_icons(0xf0); /* show battery */
+ }
+ else
+ {
+ rc_status &= ~RC_DETECTED;
+ remote_initialized = false;
+ }
+}
+
+static void remote_thread(void)
+{
+ int rc_thread_sleep_count = 10;
+ int rc_thread_wait_timeout = TIMEOUT_BLOCK;
+
+ while (1)
+ {
+ wakeup_wait(&rc_thread_wakeup, rc_thread_wait_timeout);
+
+ /* Error handling (most likely due to remote not present) */
+ if (rc_status & RC_ERROR_MASK)
+ {
+ if (--rc_thread_sleep_count == 0)
+ rc_status |= RC_POWER_OFF;
+ }
+
+ /* Power-off (thread sleeps) */
+ if (rc_status & RC_POWER_OFF)
+ {
+ remote_off();
+
+ rc_thread_sleep_count = 10;
+ rc_thread_wait_timeout = TIMEOUT_BLOCK;
+
+ continue;
+ }
+
+ /* Detection */
+ if (!(rc_status & RC_DETECTED))
+ {
+ rc_thread_wait_timeout = HZ;
+
+ if (headphones_inserted())
+ {
+ remote_on();
+
+ if (rc_status & RC_AWAKE)
+ {
+ rc_thread_sleep_count = 10;
+ rc_thread_wait_timeout = HZ/20; /* ~50ms for updates */
+ }
+ }
+ else
+ {
+ if (--rc_thread_sleep_count == 0)
+ rc_status &= ~RC_POWER_OFF;
+ }
+
+ continue;
+ }
+
+ /* Update the remote (one per wakeup cycle) */
+ if (headphones_inserted() && (rc_status & RC_AWAKE))
+ {
+ if (rc_status & RC_SCREEN_ON)
+ {
+ /* In order of importance */
+ if (rc_status & RC_UPDATE_CONTROLLER)
+ {
+ remote_update_controller();
+ rc_status &= ~RC_UPDATE_CONTROLLER;
+ }
+ else if (rc_status & RC_UPDATE_LCD)
+ {
+ remote_update_lcd();
+ rc_status &= ~RC_UPDATE_LCD;
+ }
+ else
+ {
+ remote_nop();
+ }
+ }
+ else
+ {
+ remote_nop();
+ }
+ }
+ }
+}
+
+/* ============================================= */
+/* Public functions */
+/* These should only set the update flags that */
+/* will be executed in the remote thread. */
+/* ============================================= */
+bool lcd_remote_read_device(unsigned char *data)
+{
+ if (!(rc_status & RC_AWAKE) || (rc_status & RC_ERROR_MASK))
+ return false;
+
+ /* Return the most recent data. While the remote is plugged,
+ this is updated ~50ms */
+ data[0] = rc_buf[0];
+ data[1] = rc_buf[1];
+ data[2] = rc_buf[2];
+ data[3] = rc_buf[3];
+ data[4] = rc_buf[4];
+
+ return true;
+}
+
+void lcd_remote_set_invert_display(bool yesno)
+{
+ /* dummy function...need to introduce HAVE_LCD_REMOTE_INVERT */
+ (void)yesno;
+}
+
+/* turn the display upside down (call lcd_remote_update() afterwards) */
+void lcd_remote_set_flip(bool yesno)
+{
+ /* dummy function...need to introduce HAVE_LCD_REMOTE_FLIP */
+ (void)yesno;
+}
+
+int lcd_remote_default_contrast(void)
+{
+ return DEFAULT_REMOTE_CONTRAST_SETTING;
+}
+
+void lcd_remote_set_contrast(int val)
+{
+ rc_status = (rc_status & ~RC_CONTRAST_MASK) | (val & RC_CONTRAST_MASK);
+ rc_status |= RC_UPDATE_CONTROLLER;
+}
+
+void lcd_remote_backlight(bool on)
+{
+ if (on)
+ rc_status |= RC_BACKLIGHT_ON;
+ else
+ rc_status &= ~RC_BACKLIGHT_ON;
+
+ rc_status |= RC_UPDATE_CONTROLLER;
+}
+
+void lcd_remote_off(void)
+{
+ /* should only be used to power off at shutdown */
+ rc_status |= RC_POWER_OFF;
+ wakeup_signal(&rc_thread_wakeup);
+
+ /* wait until the things are powered off */
+ while (rc_status & RC_DEV_INIT)
+ sleep(HZ/10);
+}
+
+void lcd_remote_on(void)
+{
+ /* Only wake the remote thread if it's in the blocked state. */
+ struct thread_entry *rc_thread = thread_id_entry(remote_thread_id);
+ if (rc_thread->state == STATE_BLOCKED || (rc_status & RC_FORCE_DETECT))
+ {
+ rc_status &= ~RC_FORCE_DETECT;
+ rc_status &= ~RC_POWER_OFF;
+ wakeup_signal(&rc_thread_wakeup);
+ }
+}
+
+bool remote_detect(void)
+{
+ return (rc_status & RC_DETECTED);
+}
+
+void lcd_remote_init_device(void)
+{
+ /* reset */
+ remote_dev_enable(false);
+ rc_status |= RC_FORCE_DETECT; /* force detection at startup */
+
+ /* unknown */
+ GPIO_SET_BITWISE(GPIOL_ENABLE, 0x80);
+ GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
+ GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x80);
+
+ /* a thread is required to poll & update the remote */
+ wakeup_init(&rc_thread_wakeup);
+ remote_thread_id = create_thread(remote_thread, remote_stack,
+ sizeof(remote_stack), 0, remote_thread_name
+ IF_PRIO(, PRIORITY_SYSTEM)
+ IF_COP(, CPU));
+}
+
+/* Update the display.
+ This must be called after all other LCD functions that change the display. */
+void lcd_remote_update(void)
+{
+ rc_status |= RC_UPDATE_LCD;
+}
+
+/* Update a fraction of the display. */
+void lcd_remote_update_rect(int x, int y, int width, int height)
+{
+ (void)x;
+ (void)y;
+ (void)width;
+ (void)height;
+
+ rc_status |= RC_UPDATE_LCD;
+}
diff --git a/firmware/target/arm/olympus/mrobe-100/lcd-remote-target.h b/firmware/target/arm/olympus/mrobe-100/lcd-remote-target.h
new file mode 100644
index 0000000000..b5a501046a
--- /dev/null
+++ b/firmware/target/arm/olympus/mrobe-100/lcd-remote-target.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: lcd-remote-target.h 11967 2007-01-09 23:29:07Z linus $
+ *
+ * Copyright (C) 2007 by Jens Arnold
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef LCD_REMOTE_TARGET_H
+#define LCD_REMOTE_TARGET_H
+
+bool remote_detect(void); /* returns detection status */
+
+void lcd_remote_set_invert_display(bool yesno);
+void lcd_remote_set_flip(bool yesno);
+void lcd_remote_backlight(bool on);
+
+void lcd_remote_init_device(void);
+void lcd_remote_on(void);
+void lcd_remote_off(void);
+void lcd_remote_update(void);
+void lcd_remote_update_rect(int, int, int, int);
+bool lcd_remote_read_device(unsigned char *data);
+
+extern bool remote_initialized;
+extern unsigned int rc_status;
+extern unsigned char rc_buf[5];
+#endif
diff --git a/firmware/target/arm/olympus/mrobe-100/power-mr100.c b/firmware/target/arm/olympus/mrobe-100/power-mr100.c
index 25757f62c1..26dd4ef14f 100644
--- a/firmware/target/arm/olympus/mrobe-100/power-mr100.c
+++ b/firmware/target/arm/olympus/mrobe-100/power-mr100.c
@@ -27,6 +27,7 @@
#include "power.h"
#include "logf.h"
#include "usb.h"
+#include "lcd-remote-target.h"
void power_init(void)
{
@@ -57,6 +58,10 @@ bool ide_powered(void)
void power_off(void)
{
+#ifdef HAVE_REMOTE_LCD
+ lcd_remote_off();
+#endif
+
/* Disable interrupts on this core */
disable_interrupt(IRQ_FIQ_STATUS);
diff --git a/firmware/target/arm/system-pp502x.c b/firmware/target/arm/system-pp502x.c
index 967144ad0b..6ce45a12f3 100644
--- a/firmware/target/arm/system-pp502x.c
+++ b/firmware/target/arm/system-pp502x.c
@@ -29,6 +29,9 @@
#include "button-target.h"
#include "usb-target.h"
#include "usb_drv.h"
+#ifdef HAVE_REMOTE_LCD
+#include "lcd-remote-target.h"
+#endif
#ifndef BOOTLOADER
extern void TIMER1(void);
@@ -121,6 +124,9 @@ void __attribute__((interrupt("IRQ"))) irq_handler(void)
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
if (GPIOD_INT_STAT & 0x02)
button_int();
+ if (GPIOD_INT_STAT & 0x80)
+ headphones_int();
+
}
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
if (GPIOL_INT_STAT & 0x04)