From 3520d8e90e7f6e3ffc88f8d1ff47fa3cc0efe960 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Wed, 17 Jun 2009 19:55:27 +0000 Subject: Sansa c200v2 : lcd & backlight support, using the c200v1 lcd driver The LCD driver is unified and lcd_send_command now takes 2 arguments : the command and its argument. If there is no argument, it's set to 0 and a NOP command is issued If there is more than one argument (set X/Y address), the 2nd argument is sent as a 2nd command, and a NOP command is issued after it. Benefit : c200v2 transfers the command and the argument in one 16 bits transfer Performance should not be affected since commands without argument are only used in lcd_init() and lcd_enable() lcd_send_data() now transfers whole lines (or columns) instead of single pixels yuv is disabled for c200v2 for now Some buttons can be read, including left button (bit 6 of DBOP_DIN), but for some reason they have no effect in rockbox: to be investigated git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21321 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/as3525/sansa-c200v2/button-c200v2.c | 85 ++++++++++++++-------- 1 file changed, 54 insertions(+), 31 deletions(-) (limited to 'firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c') diff --git a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c index 86a6eb0c73..d3504c97e9 100644 --- a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c +++ b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c @@ -19,47 +19,70 @@ * ****************************************************************************/ -/* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */ - #include "system.h" +#include "button-target.h" #include "button.h" #include "backlight.h" #include "powermgmt.h" -#ifndef BOOTLOADER -/* Buttons */ +unsigned short _dbop_din = 0; + +/* in the lcd driver */ +extern bool lcd_button_support(void); + static bool hold_button = false; +#ifndef BOOTLOADER static bool hold_button_old = false; -#define _button_hold() hold_button -#else -#define _button_hold() false /* FIXME */ -#endif /* BOOTLOADER */ -static int int_btn = BUTTON_NONE; +#endif void button_init_device(void) { + GPIOA_DIR &= ~(1<<3); } bool button_hold(void) { - return _button_hold(); + return hold_button; +} + +static void button_read_dbop(void) +{ + /* Set up dbop for input */ + DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */ + DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ + DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ + DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ + + int i = 50; + while(i--) asm volatile ("nop\n"); + + DBOP_CTRL |= (1<<15); /* start read */ + while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ + + _dbop_din = DBOP_DIN; /* Read dbop data*/ + + /* Reset dbop for output */ + DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ + DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ + DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ + DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */ } -/* device buttons */ -void button_int(void) +/* + * Get button pressed from hardware + */ +int button_read_device(void) { - int delay = 0x50; + int delay; int dir_save_c = 0; int afsel_save_c = 0; - - int_btn = BUTTON_NONE; + int btn = BUTTON_NONE; /* Save the current direction and afsel */ dir_save_c = GPIOC_DIR; afsel_save_c = GPIOC_AFSEL; - GPIOA_DIR &= ~(1<<3); GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3); GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3); @@ -72,32 +95,32 @@ void button_int(void) GPIOC_PIN(3) = (1<<3); GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3); - while(delay--); + delay = 100; + while(delay--) + asm volatile("nop\n"); /* direct GPIO connections */ if (GPIOA_PIN(3)) - int_btn |= BUTTON_POWER; + btn |= BUTTON_POWER; if (!GPIOC_PIN(6)) - int_btn |= BUTTON_RIGHT; + btn |= BUTTON_RIGHT; if (!GPIOC_PIN(5)) - int_btn |= BUTTON_UP; + btn |= BUTTON_UP; if (!GPIOC_PIN(4)) - int_btn |= BUTTON_SELECT; + btn |= BUTTON_SELECT; if (!GPIOC_PIN(3)) - int_btn |= BUTTON_DOWN; + btn |= BUTTON_DOWN; /* return to settings needed for lcd */ GPIOC_DIR = dir_save_c; GPIOC_AFSEL = afsel_save_c; -} -/* - * Get button pressed from hardware - */ -int button_read_device(void) -{ - /* Read buttons directly */ - button_int(); + if(lcd_button_support()) + button_read_dbop(); + + if(_dbop_din & (1<<6)) + btn |= BUTTON_LEFT; + #ifndef BOOTLOADER /* light handling */ if (hold_button != hold_button_old) @@ -107,5 +130,5 @@ int button_read_device(void) } #endif /* BOOTLOADER */ - return int_btn; + return btn; } -- cgit v1.2.3