M:Robe 500 - Fix some of the Keymaps, touchscreen improvements to decrease inacurate reads, add support for dynamic frequency (was running at 87.5 MHz, now it runs at 175 MHz when boosted), disable clock to unneded modules (decreased power by 20 mA), LCD turnoff now works without graphic glitches, battery ADC read now returns scaled voltage, define backlight fading

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20846 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2009-05-02 23:25:55 +00:00
parent d5f7dab230
commit fe2319372a
14 changed files with 220 additions and 117 deletions

View file

@ -26,8 +26,6 @@
#include "tsc2100.h"
#include "button-target.h"
void read_battery_inputs(void);
void adc_init(void)
{
/* Initialize the touchscreen and the battery readout */
@ -48,13 +46,24 @@ void GIO14(void)
switch (adscm)
{
case 1:
case 2:
touch_read_coord();
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
/* do a battery read - this will shutdown the adc till the next tick
*/
// tsc2100_set_mode(true, 0x0B);
break;
case 0x06:
case 0x07:
case 0x08:
case 0x09:
case 0x0B:
read_battery_inputs();
tsc2100_set_mode(true, 0x01);
break;
}
IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
}

View file

@ -34,7 +34,7 @@ int _backlight_brightness=DEFAULT_BRIGHTNESS_SETTING;
static void _backlight_write_brightness(int brightness)
{
uint8_t bl_command[] = {0xa4, 0x00, brightness, 0xbb};
spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
spi_block_transfer(SPI_target_BACKLIGHT, false, bl_command, 4, 0, 0);
}
void _backlight_on(void)
@ -47,7 +47,6 @@ void _backlight_on(void)
void _backlight_off(void)
{
_backlight_write_brightness(0);
lcd_sleep(); /* HACK to get lcd_sleep called again */
}
/* Assumes that the backlight has been initialized */

View file

@ -19,8 +19,6 @@
*
****************************************************************************/
/* this file also handles the touch screen driver interface */
#include "config.h"
#include "cpu.h"
#include "system.h"
@ -34,12 +32,8 @@
#include "string.h"
#include "touchscreen.h"
static bool touch_available = 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;
/* Jd's tests.. These will hopefully work for everyone so we dont have to
@ -85,7 +79,6 @@ static int touch_to_pixels(short *val_x, short *val_y)
void button_init_device(void)
{
touch_available = false;
/* GIO is the power button, set as input */
IO_GIO_DIR0 |= 0x01;
@ -115,33 +108,25 @@ 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;
short touch_x, touch_y, touch_z1, touch_z2;
static bool hold_button_old = false;
*data = 0;
/* Handle touchscreen */
if (touch_available)
if (tsc2100_read_touch(&touch_x, &touch_y, &touch_z1, &touch_z2))
{
*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;
}
tsc2100_set_mode(true, 0x01);
/* Handle power button */
if ((IO_GIO_BITSET0&0x01) == 0)
{
if ((IO_GIO_BITSET0&0x01) == 0) {
button_read |= BUTTON_POWER;
}
@ -152,8 +137,7 @@ int button_read_device(int *data)
/* Take care of hold notifications */
#ifndef BOOTLOADER
/* give BL notice if HB state chaged */
if (hold_button != hold_button_old)
{
if (hold_button != hold_button_old) {
backlight_hold_changed(hold_button);
hold_button_old=hold_button;
}

View file

@ -60,15 +60,17 @@ void lcd_sleep()
{
if (lcd_on)
{
lcd_on = false;
memset16(FRAME, 0xFFFF, LCD_WIDTH*LCD_HEIGHT);
sleep(HZ/5);
/* Disabling these saves another ~15mA */
IO_OSD_OSDWINMD0&=~(0x01);
IO_VID_ENC_VMOD&=~(0x01);
sleep(HZ/5);
IO_OSD_OSDWINMD0&= ~(0x01);
IO_VID_ENC_VMOD &= ~(0x01);
// IO_CLK_MOD1 &= ~(0x0018);
/* Disabling the LCD saves ~50mA */
IO_GIO_BITCLR2=1<<4;
lcd_on = false;
}
}
@ -79,15 +81,19 @@ void lcd_awake(void)
{
lcd_on=true;
IO_OSD_OSDWINMD0|=0x01;
IO_VID_ENC_VMOD|=0x01;
// IO_CLK_MOD1 |= 0x0018;
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 */
sleep(HZ/20);
lcd_update();
/* Wait long enough for a frame to be written */
sleep(HZ/10);
lcd_activation_call_hook();
}
}

View file

@ -36,37 +36,41 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
0
};
/* 6.10 format */
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
{ 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 },
{ 375, 1125, 1500, 1875, 2250, 2625, 3000, 3375, 3750, 4500, 4950 },
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
const unsigned short percent_to_volt_charge[11] =
{
100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320,
375, 1125, 1500, 1875, 2250, 2625, 3000, 3375, 3750, 4500, 4950,
};
void read_battery_inputs(void)
{
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)
{
short bat1, bat2, aux;
static unsigned last_tick = 0;
short tsadc;
if(tsc2100_read_volt(&bat1, &bat2, &aux)){
current_voltage=((short)((int)(bat1<<10)/4096*6*2.5));
}
if (TIME_BEFORE(last_tick+2*HZ, current_tick))
{
/* Set the TSC2100 to read voltages */
tsc2100_set_mode(0x0B);
last_tick = current_tick;
tsadc=tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
/* Set the TSC2100 to read voltages if not busy with pen */
if(!(tsadc & TSADC_PSTCM))
{
tsc2100_set_mode(true, 0x0B);
last_tick = current_tick;
}
}
return current_voltage;

View file

@ -65,10 +65,14 @@ static void spi_disable_all_targets(void)
}
int spi_block_transfer(enum SPI_target target,
const bool spi_msb_first,
const uint8_t *tx_bytes, unsigned int tx_size,
uint8_t *rx_bytes, unsigned int rx_size)
{
mutex_lock(&spi_mtx);
IO_SERIAL0_MODE = (IO_SERIAL0_MODE& ~(spi_msb_first<<9))|(spi_msb_first<<9);
/* Activate the slave select pin */
*spi_targets[target].setreg = spi_targets[target].bit;
@ -102,8 +106,8 @@ int spi_block_transfer(enum SPI_target target,
void spi_init(void)
{
mutex_init(&spi_mtx);
/* Set SCLK idle level = 0 */
IO_SERIAL0_MODE |= IO_SERIAL0_MODE_SCLK;
IO_SERIAL0_MODE = 0x3607;
/* Enable TX */
IO_SERIAL0_TX_ENABLE = 0x0001;
#ifndef CREATIVE_ZVx

View file

@ -38,6 +38,7 @@ enum SPI_target {
void spi_init(void);
int spi_block_transfer(enum SPI_target target,
const bool spi_msb_first,
const uint8_t *tx_bytes, unsigned int tx_size,
uint8_t *rx_bytes, unsigned int rx_size);

View file

@ -217,6 +217,29 @@ void system_init(void)
IO_INTC_FISEL0 = 0;
IO_INTC_FISEL1 = 0;
IO_INTC_FISEL2 = 0;
/* setup the clocks */
IO_CLK_DIV0=0x0003;
IO_CLK_DIV1=0x0102;
IO_CLK_DIV2=0x021F;
IO_CLK_DIV3=0x1FFF;
IO_CLK_DIV4=0x1F00;
IO_CLK_PLLA=0x80A0;
IO_CLK_PLLB=0x80C0;
IO_CLK_SEL0=0x017E;
IO_CLK_SEL1=0x1000;
IO_CLK_SEL2=0x1001;
/* need to wait before bypassing */
IO_CLK_BYP=0x0000;
/* turn off some unneeded modules */
IO_CLK_MOD0 &= ~0x0018;
IO_CLK_MOD1 = 0x0918;
IO_CLK_MOD2 = ~0x7C58;
/* IRQENTRY only reflects enabled interrupts */
IO_INTC_RAW = 0;
@ -224,6 +247,7 @@ void system_init(void)
IO_INTC_ENTRY_TBA0 = 0;
IO_INTC_ENTRY_TBA1 = 0;
int i;
/* Set interrupt priorities to predefined values */
for(i = 0; i < 23; i++)
@ -275,27 +299,13 @@ int system_memory_guard(int newmode)
}
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
void set_cpu_frequency(long frequency)
{
if (frequency == CPUFREQ_MAX)
{
asm volatile("mov r0, #0\n"
"mrc p15, 0, r0, c1, c0, 0\n"
"orr r0, r0, #3<<30\n" /* set to Asynchronous mode*/
"mcr p15, 0, r0, c1, c0, 0" : : : "r0");
FREQ = CPUFREQ_MAX;
}
else
{
asm volatile("mov r0, #0\n"
"mrc p15, 0, r0, c1, c0, 0\n"
"bic r0, r0, #3<<30\n" /* set to FastBus mode*/
"mcr p15, 0, r0, c1, c0, 0" : : : "r0");
FREQ = CPUFREQ_NORMAL;
if (frequency == CPUFREQ_MAX) {
IO_CLK_DIV0 = 0x0101; /* 175 MHz ARM */
} else {
IO_CLK_DIV0 = 0x0003; /* 87.5 MHz ARM - not much savings, about 3 mA */
}
}
#endif

View file

@ -23,9 +23,9 @@
#include "system-arm.h"
#define CPUFREQ_SLEEP 32768
#define CPUFREQ_DEFAULT 24000000
#define CPUFREQ_NORMAL 30000000
#define CPUFREQ_MAX 80000000
#define CPUFREQ_SLEEP 32768
#define CPUFREQ_DEFAULT 87500000
#define CPUFREQ_NORMAL 87500000
#define CPUFREQ_MAX 175000000
#endif /* SYSTEM_TARGET_H */