summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2006-07-28 12:41:13 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2006-07-28 12:41:13 +0000
commitd17d08c268290b9ffc2f6e62876f1e0a05b56a6e (patch)
tree8536a67ffa5c88f7ec38e5a74046c28705b95220 /firmware
parent38719f87cbf6cd5fcefafe14780543eb1dad3f63 (diff)
downloadrockbox-d17d08c268290b9ffc2f6e62876f1e0a05b56a6e.tar.gz
rockbox-d17d08c268290b9ffc2f6e62876f1e0a05b56a6e.zip
LCD remote support for iAudio X5
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10352 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/backlight.c20
-rwxr-xr-xfirmware/drivers/lcd-remote-2bit-vi.c123
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/lcd-remote-target.h6
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/lcd-remote-x5.c130
4 files changed, 239 insertions, 40 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 2539bb642a..cd1fbaf1ba 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -336,12 +336,21 @@ static void _backlight_off(void)
}
#ifdef HAVE_REMOTE_LCD
-#ifndef TARGET_TREE
+#ifdef SIMULATOR
static void __remote_backlight_on(void)
{
-#ifdef SIMULATOR
sim_remote_backlight(100);
-#elif defined(IRIVER_H300_SERIES)
+}
+
+static void __remote_backlight_off(void)
+{
+ sim_remote_backlight(0);
+}
+#else
+#ifndef TARGET_TREE
+static void __remote_backlight_on(void)
+{
+#if defined(IRIVER_H300_SERIES)
and_l(~0x00000002, &GPIO1_OUT);
#else
and_l(~0x00000800, &GPIO_OUT);
@@ -350,9 +359,7 @@ static void __remote_backlight_on(void)
static void __remote_backlight_off(void)
{
-#ifdef SIMULATOR
- sim_remote_backlight(0);
-#elif defined(IRIVER_H300_SERIES)
+#if defined(IRIVER_H300_SERIES)
or_l(0x00000002, &GPIO1_OUT);
#else
or_l(0x00000800, &GPIO_OUT);
@@ -360,6 +367,7 @@ static void __remote_backlight_off(void)
}
#endif /* TARGET_TREE */
#endif /* HAVE_REMOTE_LCD */
+#endif /* SIMULATOR */
void backlight_thread(void)
{
diff --git a/firmware/drivers/lcd-remote-2bit-vi.c b/firmware/drivers/lcd-remote-2bit-vi.c
index cf486b5d0d..eefbae1de3 100755
--- a/firmware/drivers/lcd-remote-2bit-vi.c
+++ b/firmware/drivers/lcd-remote-2bit-vi.c
@@ -33,6 +33,7 @@
#include "font.h"
#include "rbunicode.h"
#include "bidi.h"
+#include "lcd-remote-target.h"
#define SCROLLABLE_LINES (((LCD_REMOTE_HEIGHT+4)/5 < 32) ? (LCD_REMOTE_HEIGHT+4)/5 : 32)
@@ -67,18 +68,12 @@ static const char scroll_tick_table[16] = {
100, 80, 64, 50, 40, 32, 25, 20, 16, 12, 10, 8, 6, 5, 4, 3
};
-
-/* LCD init */
-void lcd_remote_init(void)
-{
- lcd_remote_clear_display();
-#if 0 /* FIXME */
- /* Call device specific init */
- remote_init();
+/* remote hotplug */
+#ifndef SIMULATOR
+static struct event_queue remote_scroll_queue;
+#define REMOTE_INIT_LCD 1
+#define REMOTE_DEINIT_LCD 2
#endif
- create_thread(scroll_thread, scroll_stack,
- sizeof(scroll_stack), scroll_name);
-}
/*** parameter handling ***/
@@ -1020,6 +1015,51 @@ void lcd_remote_puts_scroll_style_offset(int x, int y, const unsigned char *stri
scrolling_lines &= ~(1<<y);
}
+#ifndef SIMULATOR
+/* Monitor remote hotswap */
+static void remote_tick(void)
+{
+ static bool last_status = false;
+ static int countdown = 0;
+ static int init_delay = 0;
+ bool current_status;
+
+ current_status = remote_detect();
+
+ /* Only report when the status has changed */
+ if (current_status != last_status)
+ {
+ last_status = current_status;
+ countdown = current_status ? 20*HZ : 1;
+ }
+ else
+ {
+ /* Count down until it gets negative */
+ if (countdown >= 0)
+ countdown--;
+
+ if (current_status)
+ {
+ if (!(countdown % 8))
+ {
+ if (--init_delay <= 0)
+ {
+ queue_post(&remote_scroll_queue, REMOTE_INIT_LCD, 0);
+ init_delay = 6;
+ }
+ }
+ }
+ else
+ {
+ if (countdown == 0)
+ {
+ queue_post(&remote_scroll_queue, REMOTE_DEINIT_LCD, 0);
+ }
+ }
+ }
+}
+#endif
+
static void scroll_thread(void)
{
struct font* pf;
@@ -1027,11 +1067,42 @@ static void scroll_thread(void)
int index;
int xpos, ypos;
int lastmode;
+ long delay = 0;
+ long next_tick = current_tick;
+#ifndef SIMULATOR
+ struct event ev;
+#endif
/* initialize scroll struct array */
scrolling_lines = 0;
while ( 1 ) {
+
+#ifdef SIMULATOR
+ sleep(delay);
+#else
+ if (remote_initialized)
+ queue_wait_w_tmo(&remote_scroll_queue, &ev, delay);
+ else
+ queue_wait(&remote_scroll_queue, &ev);
+
+ switch (ev.id)
+ {
+ case REMOTE_INIT_LCD:
+ lcd_remote_on();
+ lcd_remote_update();
+ break;
+
+ case REMOTE_DEINIT_LCD:
+ lcd_remote_off();
+ break;
+ }
+
+ delay = next_tick - current_tick - 1;
+ if (delay >= 0)
+ continue;
+#endif
+
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
/* really scroll? */
if ( !(scrolling_lines&(1<<index)) )
@@ -1080,6 +1151,34 @@ static void scroll_thread(void)
lcd_remote_update_rect(xpos, ypos, LCD_REMOTE_WIDTH - xpos, pf->height);
}
- sleep(scroll_ticks);
+
+ next_tick += scroll_ticks;
+ delay = next_tick - current_tick - 1;
+ if (delay < 0)
+ {
+ next_tick = current_tick + 1;
+ delay = 0;
+ }
}
}
+
+/* LCD init */
+#ifdef SIMULATOR
+void lcd_remote_init(void)
+{
+ create_thread(scroll_thread, scroll_stack,
+ sizeof(scroll_stack), scroll_name);
+}
+#else
+void lcd_remote_init(void)
+{
+ /* Call device specific init */
+ lcd_remote_init_device();
+
+ lcd_remote_clear_display();
+ queue_clear(&remote_scroll_queue); /* no queue_init() -- private queue */
+ tick_add_task(remote_tick);
+ create_thread(scroll_thread, scroll_stack,
+ sizeof(scroll_stack), scroll_name);
+}
+#endif
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h b/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h
index 72d4ed9fb2..8c20526ff3 100755
--- a/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h
+++ b/firmware/target/coldfire/iaudio/x5/lcd-remote-target.h
@@ -19,12 +19,16 @@
#ifndef LCD_REMOTE_TARGET_H
#define LCD_REMOTE_TARGET_H
+void lcd_remote_init_device(void);
void lcd_remote_write_command(int cmd);
void lcd_remote_write_command_ex(int cmd, int data);
void lcd_remote_write_data(const unsigned char* p_bytes, int count);
bool remote_detect(void);
void lcd_remote_powersave(bool on);
void lcd_remote_set_contrast(int val);
-void remote_set_row_and_col(int row, int col);
+void lcd_remote_on(void);
+void lcd_remote_off(void);
+
+extern bool remote_initialized;
#endif
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
index c1ec00f0e7..586104fc0a 100755
--- a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "system.h"
#include "kernel.h"
+#include "lcd-remote.h"
/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */
@@ -39,6 +40,7 @@
#define LCD_SET_GRAY 0x88
#define LCD_SET_PWM_FRC 0x90
#define LCD_SET_POWER_SAVE 0xa8
+#define LCD_REVERSE 0xa6
#define CS_LO and_l(~0x00000020, &GPIO1_OUT)
#define CS_HI or_l(0x00000020, &GPIO1_OUT)
@@ -51,8 +53,12 @@
#define LCD_REMOTE_DEFAULT_CONTRAST 0x18;
+/* cached settings values */
+static bool cached_invert = false;
+static bool cached_flip = false;
static int cached_contrast = LCD_REMOTE_DEFAULT_CONTRAST;
-static bool remote_initialized = false;
+
+bool remote_initialized = false;
static void remote_write(unsigned char byte, bool is_command)
{
@@ -94,13 +100,6 @@ void lcd_remote_write_data(const unsigned char* p_bytes, int count)
remote_write(*p_bytes++, false);
}
-void remote_set_row_and_col(int row, int col)
-{
- lcd_remote_write_command(LCD_SET_PAGE | (row & 0xf));
- lcd_remote_write_command_ex(LCD_SET_COLUMN | ((col >> 4) & 0xf),
- col & 0xf);
-}
-
int lcd_remote_default_contrast(void)
{
return LCD_REMOTE_DEFAULT_CONTRAST;
@@ -108,24 +107,27 @@ int lcd_remote_default_contrast(void)
void lcd_remote_powersave(bool on)
{
- if (on)
- lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
- else
- lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
+ if(remote_initialized) {
+ if (on)
+ lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
+ else
+ lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
+ }
}
void lcd_remote_set_contrast(int val)
{
cached_contrast = val;
- lcd_remote_write_command_ex(LCD_SET_VOLUME, val);
+ if(remote_initialized)
+ lcd_remote_write_command_ex(LCD_SET_VOLUME, val);
}
bool remote_detect(void)
{
- return (GPIO_READ & 0x01000000);
+ return (GPIO_READ & 0x01000000)?false:true;
}
-void remote_init(void)
+void lcd_remote_init_device(void)
{
or_l(0x0000e000, &GPIO_OUT);
or_l(0x0000e000, &GPIO_ENABLE);
@@ -135,17 +137,18 @@ void remote_init(void)
or_l(0x00000020, &GPIO1_ENABLE);
or_l(0x00000020, &GPIO1_FUNCTION);
+ and_l(~0x01000000, &GPIO_OUT);
+ and_l(~0x01000000, &GPIO_ENABLE);
+ or_l(0x01000000, &GPIO_FUNCTION);
+}
+
+void lcd_remote_on(void)
+{
sleep(10);
lcd_remote_write_command(LCD_SET_DUTY_RATIO);
lcd_remote_write_command(0x70); /* 1/128 */
- lcd_remote_write_command(LCD_SELECT_ADC | 1); /* Reverse direction */
- lcd_remote_write_command(LCD_SELECT_SHL | 8); /* Reverse direction */
-
- lcd_remote_write_command(LCD_SET_COM0);
- lcd_remote_write_command(0x00);
-
lcd_remote_write_command(LCD_OSC_ON);
lcd_remote_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */
@@ -173,5 +176,90 @@ void remote_init(void)
remote_initialized = true;
+ lcd_remote_set_flip(cached_flip);
lcd_remote_set_contrast(cached_contrast);
+ lcd_remote_set_invert_display(cached_invert);
+}
+
+void lcd_remote_off(void)
+{
+ remote_initialized = false;
+ CS_HI;
+ RS_HI;
+}
+
+/* Update the display.
+ This must be called after all other LCD functions that change the display. */
+void lcd_remote_update(void) ICODE_ATTR;
+void lcd_remote_update(void)
+{
+ int y;
+ if(remote_initialized) {
+ for(y = 0;y < LCD_REMOTE_HEIGHT/8;y++) {
+ /* Copy display bitmap to hardware.
+ The COM48-COM63 lines are not connected so we have to skip
+ them. Further, the column address doesn't wrap, so we
+ have to update one page at a time. */
+ lcd_remote_write_command(LCD_SET_PAGE | (y>5?y+2:y));
+ lcd_remote_write_command_ex(LCD_SET_COLUMN | 0, 0);
+ lcd_remote_write_data((unsigned char *)lcd_remote_framebuffer[y],
+ LCD_REMOTE_WIDTH*2);
+ }
+ }
+}
+
+/* Update a fraction of the display. */
+void lcd_remote_update_rect(int, int, int, int) ICODE_ATTR;
+void lcd_remote_update_rect(int x, int y, int width, int height)
+{
+ if(remote_initialized) {
+ int ymax;
+
+ /* The Y coordinates have to work on even 8 pixel rows */
+ ymax = (y + height-1) >> 3;
+ y >>= 3;
+
+ if(x + width > LCD_REMOTE_WIDTH)
+ width = LCD_REMOTE_WIDTH - x;
+ if (width <= 0)
+ return; /* nothing left to do, 0 is harmful to lcd_write_data() */
+ if(ymax >= LCD_REMOTE_HEIGHT)
+ ymax = LCD_REMOTE_HEIGHT-1;
+
+ /* Copy specified rectangle bitmap to hardware
+ COM48-COM63 are not connected, so we need to skip those */
+ for (; y <= ymax; y++)
+ {
+ lcd_remote_write_command(LCD_SET_PAGE |
+ ((y > 5?y + 2:y) & 0xf));
+ lcd_remote_write_command_ex(LCD_SET_COLUMN | ((x >> 4) & 0xf),
+ x & 0xf);
+
+ lcd_remote_write_data (
+ (unsigned char *)&lcd_remote_framebuffer[y][x], width*2);
+ }
+ }
+}
+
+void lcd_remote_set_invert_display(bool yesno)
+{
+ cached_invert = yesno;
+ if(remote_initialized)
+ lcd_remote_write_command(LCD_REVERSE | yesno);
+}
+
+void lcd_remote_set_flip(bool yesno)
+{
+ cached_flip = yesno;
+ if(remote_initialized) {
+ if(yesno) {
+ lcd_remote_write_command(LCD_SELECT_ADC | 0);
+ lcd_remote_write_command(LCD_SELECT_SHL | 0);
+ lcd_remote_write_command_ex(LCD_SET_COM0, 16);
+ } else {
+ lcd_remote_write_command(LCD_SELECT_ADC | 1);
+ lcd_remote_write_command(LCD_SELECT_SHL | 8);
+ lcd_remote_write_command_ex(LCD_SET_COM0, 0);
+ }
+ }
}