summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2009-04-28 05:07:25 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2009-04-28 05:07:25 +0000
commit57ca7ccf36728fec7096931a064adc0b0e212ae0 (patch)
treed97c3a9477eac4cf2c7d7a4e0602a0b772d5805f /firmware
parent4e747f1c5ccc98d99c24354c6fef0d6abf87d220 (diff)
downloadrockbox-57ca7ccf36728fec7096931a064adc0b0e212ae0.tar.gz
rockbox-57ca7ccf36728fec7096931a064adc0b0e212ae0.zip
M:Robe 500: Rearrage TSC2100 reads to make touchscreen more reliable, add hack to get lcd_sleep working/called again, fix the panic handler so that it waits for the power button to be pressed instead of freezing the player
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20818 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/config-mrobe500.h8
-rw-r--r--firmware/export/tsc2100.h15
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/adc-mr500.c43
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/adc-target.h15
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/backlight-mr500.c7
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c77
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-target.h3
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/lcd-mr500.c52
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/lcd-target.h1
-rwxr-xr-xfirmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c32
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c6
11 files changed, 104 insertions, 155 deletions
diff --git a/firmware/export/config-mrobe500.h b/firmware/export/config-mrobe500.h
index 29c2670f9e..78802e3adf 100644
--- a/firmware/export/config-mrobe500.h
+++ b/firmware/export/config-mrobe500.h
@@ -79,14 +79,12 @@
#define LCD_DEPTH 16 /* 65k colours */
#define LCD_PIXELFORMAT RGB565 /* rgb565 */
-/* Define this if your LCD can be enabled/disabled */
-#define HAVE_LCD_ENABLE
-
-#define HAVE_LCD_SLEEP_SETTING
-
/* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE
should be defined as well. */
#define HAVE_LCD_SLEEP
+//#define HAVE_LCD_SLEEP_SETTING
+/* Do this for now till lcd sleeping is working properly */
+#define LCD_SLEEP_TIMEOUT 0
/* remote LCD */
#define HAVE_REMOTE_LCD
diff --git a/firmware/export/tsc2100.h b/firmware/export/tsc2100.h
index 8d0ee529ff..06714db862 100644
--- a/firmware/export/tsc2100.h
+++ b/firmware/export/tsc2100.h
@@ -21,8 +21,11 @@
#ifndef __TSC2100_H_
#define __TSC2100_H_
-/* Read X, Y, Z1, Z2 touchscreen coordinates. */
-void tsc2100_read_values(short *x, short* y, short *z1, short *z2);
+void tsc2100_read_data(void);
+void tsc2100_read_touch(short *x, short* y, short *z1, short *z2);
+void tsc2100_read_volt(short *bat1, short *bat2, short *aux);
+void tsc2100_set_mode(unsigned char scan_mode);
+void tsc2100_adc_init(void);
/* read a register */
short tsc2100_readreg(int page, int address);
@@ -69,6 +72,14 @@ void tsc2100_keyclick(void);
#define TSSTAT_T2STAT (1<<1)
// Bit 0 is reserved (1<<0)
+/* ts Reference Control */
+#define TSREF_PAGE 1
+#define TSREF_ADDRESS 0x03
+#define TSREF_VREFM (1<<4)
+#define TSREF_RPWUDL_SHIFT 2
+#define TSREF_RPWDN (1<<1)
+#define TSREF_IREFV (1<<0)
+
/* ts Reset Control */
#define TSRESET_PAGE 1
#define TSRESET_ADDRESS 0x04
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/adc-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/adc-mr500.c
index 0a1389a226..da3e2e9f44 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/adc-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/adc-mr500.c
@@ -23,27 +23,38 @@
#include "adc.h"
#include "adc-target.h"
#include "kernel.h"
+#include "tsc2100.h"
+#include "button-target.h"
-/* prototypes */
-static void adc_tick(void);
+void read_battery_inputs(void);
void adc_init(void)
{
- /* attach the adc reading to the tick */
- tick_add_task(adc_tick);
+ /* Initialize the touchscreen and the battery readout */
+ tsc2100_adc_init();
+
+ /* Enable the tsc2100 interrupt */
+ IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
}
-/* Called to get the recent ADC reading */
-inline unsigned short adc_read(int channel)
+/* Touchscreen data available interupt */
+void GIO14(void)
{
- return (short)channel;
+ short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
+ short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
+
+ /* Always read all registers in one go to clear any missed flags */
+ tsc2100_read_data();
+
+ switch (adscm)
+ {
+ case 1:
+ case 2:
+ touch_read_coord();
+ break;
+ case 0x0B:
+ read_battery_inputs();
+ break;
+ }
+ IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
}
-
-/* add this to the tick so that the ADC converts are done in the background */
-static void adc_tick(void)
-{
-}
-
-
-
-
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/adc-target.h b/firmware/target/arm/tms320dm320/mrobe-500/adc-target.h
index 58aa19afcb..45e646cbb3 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/adc-target.h
+++ b/firmware/target/arm/tms320dm320/mrobe-500/adc-target.h
@@ -22,19 +22,4 @@
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
-/* only two channels used by the Gigabeat */
-#define NUM_ADC_CHANNELS 2
-
-#define ADC_BATTERY 0
-#define ADC_HPREMOTE 1
-#define ADC_UNKNOWN_3 2
-#define ADC_UNKNOWN_4 3
-#define ADC_UNKNOWN_5 4
-#define ADC_UNKNOWN_6 5
-#define ADC_UNKNOWN_7 6
-#define ADC_UNKNOWN_8 7
-
-#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
-#define ADC_READ_ERROR 0xFFFF
-
#endif
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/backlight-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/backlight-mr500.c
index bdd91e2e20..ab2289822b 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/backlight-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/backlight-mr500.c
@@ -27,6 +27,7 @@
#include "lcd.h"
#include "power.h"
#include "spi-target.h"
+#include "lcd-target.h"
int _backlight_brightness=DEFAULT_BRIGHTNESS_SETTING;
@@ -38,15 +39,15 @@ static void _backlight_write_brightness(int brightness)
void _backlight_on(void)
{
-#ifdef HAVE_LCD_ENABLE
- lcd_enable(true); /* power on lcd + visible display */
-#endif
+ lcd_awake(); /* power on lcd + visible display */
+
_backlight_write_brightness(_backlight_brightness);
}
void _backlight_off(void)
{
_backlight_write_brightness(0);
+ lcd_sleep(); /* HACK to get lcd_sleep called again */
}
/* Assumes that the backlight has been initialized */
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
index 2daae7e5d5..09ff6cbd78 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
@@ -35,7 +35,10 @@
#include "touchscreen.h"
static bool touch_available = false;
-static bool hold_button = false;
+static bool hold_button = false;
+
+static short touch_x, touch_y, touch_z1, touch_z2;
+static long last_touch = 0;
static struct touch_calibration_point topleft, bottomright;
@@ -49,16 +52,16 @@ static struct touch_calibration_point topleft, bottomright;
* (640,480) = 3880, 3900
*/
-static int touch_to_pixels(short val_x, short val_y)
+static int touch_to_pixels(short *val_x, short *val_y)
{
short x,y;
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
- x=val_x;
- y=val_y;
+ x=*val_x;
+ y=*val_y;
#else
- x=val_y;
- y=val_x;
+ x=*val_y;
+ y=*val_x;
#endif
x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x;
@@ -74,6 +77,8 @@ static int touch_to_pixels(short val_x, short val_y)
else if (y>=LCD_HEIGHT)
y=LCD_HEIGHT-1;
+ *val_x=x;
+ *val_y=y;
return (x<<16)|y;
}
@@ -103,18 +108,6 @@ void button_init_device(void)
bottomright.px_x = LCD_WIDTH;
bottomright.px_y = LCD_HEIGHT;
-
- /* Enable the touchscreen interrupt */
- IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
-#if 0
- tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS,
- TSADC_PSTCM|
- (0x2<<TSADC_ADSCM_SHIFT)| /* scan x,y,z1,z2 */
- (0x1<<TSADC_RESOL_SHIFT) /* 8 bit resolution */
- );
- /* doesnt work for some reason...
- setting to 8bit would probably be better than the 12bit currently */
-#endif
}
inline bool button_hold(void)
@@ -122,46 +115,35 @@ inline bool button_hold(void)
return hold_button;
}
+/* This is called from the tsc2100 interupt handler in adc-mr500.c */
+void touch_read_coord(void)
+{
+ touch_available = true;
+ tsc2100_read_touch(&touch_x, &touch_y, &touch_z1, &touch_z2);
+}
+
int button_read_device(int *data)
{
int button_read = BUTTON_NONE;
- static int button_old = BUTTON_NONE;
static bool hold_button_old = false;
- static long last_touch = 0;
*data = 0;
/* Handle touchscreen */
if (touch_available)
{
- short x,y;
- short last_z1, last_z2;
-
- tsc2100_read_values(&x, &y, &last_z1, &last_z2);
-
- *data = touch_to_pixels(x, y);
- button_read |= touchscreen_to_pixels((*data&0xffff0000)>>16,
- *data&0x0000ffff, data);
- button_old = button_read;
+ *data = touch_to_pixels(&touch_x, &touch_y);
+ button_read |= touchscreen_to_pixels(touch_x, touch_y, data);
touch_available = false;
last_touch=current_tick;
}
- else
- {
- /* Touch hasn't happened in a while, clear the bits */
- if(last_touch+3>current_tick)
- button_old&=(0xFF);
- }
/* Handle power button */
if ((IO_GIO_BITSET0&0x01) == 0)
{
button_read |= BUTTON_POWER;
- button_old = button_read;
}
- else
- button_old&=~BUTTON_POWER;
/* Read data from the remote */
button_read |= remote_read_device();
@@ -180,27 +162,8 @@ int button_read_device(int *data)
if (hold_button)
{
button_read = BUTTON_NONE;
- button_old = button_read;
}
return button_read;
}
-/* Touchscreen data available interupt */
-void read_battery_inputs(void);
-void GIO14(void)
-{
- short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
- short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
- switch (adscm)
- {
- case 1:
- case 2:
- touch_available = true;
- break;
- case 0xb:
- read_battery_inputs();
- break;
- }
- IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
-}
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-target.h b/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
index 5b888b3e0a..b3a2960e01 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
@@ -30,6 +30,9 @@ bool button_hold(void);
void button_init_device(void);
int button_read_device(int *data);
+/* This is called from the tsc2100 interupt handler in adc-mr500.c */
+void touch_read_coord(void);
+
struct touch_calibration_point {
short px_x; /* known pixel value */
short px_y;
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/lcd-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/lcd-mr500.c
index e26a88704d..20b830b02d 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/lcd-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/lcd-mr500.c
@@ -38,9 +38,8 @@
extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
int width, int height);
+#if defined(HAVE_LCD_SLEEP)
static bool lcd_on = true;
-#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
-static bool lcd_powered = true;
#endif
/*
@@ -49,7 +48,7 @@ static bool lcd_powered = true;
extern unsigned fg_pattern;
extern unsigned bg_pattern;
-#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
+#if defined(HAVE_LCD_SLEEP)
bool lcd_active(void)
{
return lcd_on;
@@ -59,12 +58,8 @@ bool lcd_active(void)
#if defined(HAVE_LCD_SLEEP)
void lcd_sleep()
{
- if (lcd_powered)
+ if (lcd_on)
{
- /* "not powered" implies "disabled" */
- if (lcd_on)
- lcd_enable(false);
-
/* Disabling these saves another ~15mA */
IO_OSD_OSDWINMD0&=~(0x01);
IO_VID_ENC_VMOD&=~(0x01);
@@ -73,42 +68,29 @@ void lcd_sleep()
/* Disabling the LCD saves ~50mA */
IO_GIO_BITCLR2=1<<4;
- lcd_powered=false;
+ lcd_on = false;
}
}
-#endif
-#if defined(HAVE_LCD_ENABLE)
-void lcd_enable(bool state)
+void lcd_awake(void)
{
- if (state == lcd_on)
- return;
-
- if(state)
+ /* "enabled" implies "powered" */
+ if (!lcd_on)
{
- /* "enabled" implies "powered" */
- if (!lcd_powered)
- {
- lcd_powered=true;
-
- IO_OSD_OSDWINMD0|=0x01;
- IO_VID_ENC_VMOD|=0x01;
+ lcd_on=true;
- sleep(2);
- IO_GIO_BITSET2=1<<4;
- /* Wait long enough for a frame to be written - yes, it
- * takes awhile. */
- sleep(HZ/5);
- }
-
- lcd_on = true;
+ IO_OSD_OSDWINMD0|=0x01;
+ IO_VID_ENC_VMOD|=0x01;
+
+ sleep(2);
+ IO_GIO_BITSET2=1<<4;
+ /* Wait long enough for a frame to be written - yes, it
+ * takes awhile. */
+ sleep(HZ/5);
+
lcd_update();
lcd_activation_call_hook();
}
- else
- {
- lcd_on = false;
- }
}
#endif
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/lcd-target.h b/firmware/target/arm/tms320dm320/mrobe-500/lcd-target.h
index 5175765bc1..2415fdb928 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/lcd-target.h
+++ b/firmware/target/arm/tms320dm320/mrobe-500/lcd-target.h
@@ -20,4 +20,5 @@
****************************************************************************/
extern void lcd_enable(bool state);
+extern void lcd_awake(void);
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
index f3746c8c98..654ec96591 100755
--- a/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
@@ -25,7 +25,7 @@
#include "tsc2100.h"
#include "kernel.h"
-unsigned short current_voltage = 3910;
+static unsigned short current_voltage = 3910;
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
0
@@ -47,38 +47,28 @@ const unsigned short percent_to_volt_charge[11] =
{
100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320,
};
+
void read_battery_inputs(void)
{
- short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
- short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
- if (adscm == 0xb) /* battery is available */
- {
- current_voltage = tsc2100_readreg(0, 5); /* BAT1 */
- tsc2100_readreg(0, 6); /* BAT2 */
- tsc2100_readreg(0, 7); /* AUX */
- /* reset the TSC2100 to read touches */
- tsadc &= ~(TSADC_PSTCM|TSADC_ADST|TSADC_ADSCM_MASK);
- tsadc |= TSADC_PSTCM|(0x2<<TSADC_ADSCM_SHIFT);
- tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc);
- tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS, 2<<TSSTAT_PINTDAV_SHIFT);
- }
+ short dummy1, dummy2;
+ tsc2100_read_volt(&current_voltage, &dummy1, &dummy2);
+
+ /* Set the TSC2100 back to read touches */
+ tsc2100_set_mode(0x01);
}
/* Returns battery voltage from ADC [millivolts] */
unsigned int battery_adc_voltage(void)
{
static unsigned last_tick = 0;
- short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
+
if (TIME_BEFORE(last_tick+2*HZ, current_tick))
{
- tsadc &= ~(TSADC_PSTCM|TSADC_ADST|TSADC_ADSCM_MASK);
- tsadc |= 0xb<<TSADC_ADSCM_SHIFT;
- tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc&(~(1<<15)));
- tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS, 2<<TSSTAT_PINTDAV_SHIFT);
+ /* Set the TSC2100 to read voltages */
+ tsc2100_set_mode(0x0B);
last_tick = current_tick;
}
- else
- read_battery_inputs();
+
return current_voltage;
}
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index e8d732351f..638e378159 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -188,7 +188,11 @@ void system_reboot(void)
void system_exception_wait(void)
{
- while (1);
+ /* Mask all Interrupts. */
+ IO_INTC_EINT0 = 0;
+ IO_INTC_EINT1 = 0;
+ IO_INTC_EINT2 = 0;
+ while ((IO_GIO_BITSET0&0x01) != 0); /* Wait for power button */
}
void system_init(void)