First reading out of the touchpad!

disabled power handling for now, so the device will power off when unplugged again (because there is no other poweroff method provided)


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18480 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Frank Gevaerts 2008-09-10 19:08:46 +00:00
parent 5a0c3ec9e2
commit 3637ef9b32
2 changed files with 175 additions and 29 deletions

View file

@ -47,10 +47,164 @@
#include <stdarg.h>
char version[] = APPSVERSION;
#define LONG_DELAY 200000
#define SHORT_DELAY 50000
#define PAUSE_DELAY 50000
#define SPIDELAY(_x) void(_x);
#define SETMOSI() PDAT1 |= (1 << 6)
#define CLRMOSI() PDAT1 &= ~(1 << 6)
#define MISO ((PDAT0 >> 3) & 1)
#define RDY (PDAT1 & (1 << 5))
#define SETCLK() PDAT0 |= (1 << 1)
#define CLRCLK() PDAT0 &= ~(1 << 1)
#define SETSS() PDAT0 |= (1 << 0)
#define CLRSS() PDAT0 &= ~(1 << 0)
#define SPISPEED 10000
#define QT_CT 0x00800000
#define QT_AKS_DISABLED 0x00000000
#define QT_AKS_GLOBAL 0x00010000
#define QT_AKS_MODE1 0x00020000
#define QT_AKS_MODE2 0x00030000
#define QT_AKS_MODE3 0x00040000
#define QT_AKS_MODE4 0x00050000
#define QT_SLD_WHEEL 0x00000000
#define QT_SLD_SLIDER 0x00080000
#define QT_KEY7_NORMAL 0x00000000
#define QT_KEY7_PROX 0x00100000
#define QT_MODE_FREE 0x00000000
#define QT_MODE_LP1 0x00000100
#define QT_MODE_LP2 0x00000200
#define QT_MODE_LP3 0x00000300
#define QT_MODE_LP4 0x00000400
#define QT_MODE_SYNC 0x00000500
#define QT_MODE_SLEEP 0x00000600
#define QT_LPB 0x00000800
#define QT_DI 0x00001000
#define QT_MOD_10 0x00000000
#define QT_MOD_20 0x00002000
#define QT_MOD_60 0x00004000
#define QT_MOD_INF 0x00006000
#define QT_CAL_ALL 0x00000000
#define QT_CAL_KEYS 0x00000008
#define QT_CAL_WHEEL 0x00000010
#define QT_RES_4 0x00000020
#define QT_RES_8 0x00000040
#define QT_RES_16 0x00000060
#define QT_RES_32 0x00000080
#define QT_RES_64 0x000000A0
#define QT_RES_128 0x000000C0
#define QT_RES_256 0x000000E0
static inline void delay(int duration)
{
volatile int i;
for(i=0;i<duration;i++);
}
void init_qt1106(void)
{
int oldval;
oldval = PCON0;
//Set P0.0 and P0.1 to output, set P0.3 to input
PCON0 = ((oldval & ~(3 << 0 || 3 << 2 || 3 << 6)) | (1 << 0 | 1 << 2));
oldval = PCON1;
//Set P1.5 to input, set P1.6 to input
PCON1 = ((oldval & ~(0xf << 20 || 0xf << 24)) | (1 << 24));
SETSS();
SETCLK();
}
unsigned read_qt1106(unsigned int input)
{
int output = 0;
int i;
while(!RDY) {}
delay(10); // < 470 us
CLRSS();
delay(13); // > 22 us
for (i = 0; i < 24; i++) {
CLRCLK();
if (input & (1 << 23))
SETMOSI();
else
CLRMOSI();
input <<= 1;
delay(20); // >> 6.7 us
SETCLK();
output |= MISO;
output <<= 1;
delay(20); // >> 6.7 us
}
SETSS();
return (output & 0x00FFFFFF);
}
void bl_debug(bool bit)
{
if (bit)
{
PDAT0 ^= (1 << 2); //Toggle backlight
delay(LONG_DELAY);
PDAT0 ^= (1 << 2); //Toggle backlight
delay(LONG_DELAY);
//for(i=0;i<pause_delay;i++);
}
else
{
PDAT0 ^= (1 << 2); //Toggle backlight
delay(SHORT_DELAY);
PDAT0 ^= (1 << 2); //Toggle backlight
delay(SHORT_DELAY);
//for(i=0;i<pause_delay;i++);
}
}
void bl_debug_int(unsigned int input)
{
unsigned int i;
for (i = 0; i < input; i++)
{
PDAT0 ^= (1 << 2); //Toggle backlight
delay(SHORT_DELAY);
PDAT0 ^= (1 << 2); //Toggle backlight
delay(2*SHORT_DELAY);
}
delay(SHORT_DELAY*6);
}
void main(void)
{
int counter=0;
//Set backlight pin to output and enable
int oldval = PCON0;
PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
@ -60,37 +214,27 @@ void main(void)
oldval = PCON1;
PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16));
//Set the piezo pins to output
oldval = PCON5;
PCON5 = ((oldval & ~((0xf << 4) | (0xf << 8))) | ((1 << 0) | (1 << 4)));
PDAT5 &= ~((1 << 1) | (1 << 2)); //should not be needed
init_qt1106();
PDAT5 |= (1 << 1); //Toggle piezo +
// Wait for play to be pressed
while(!(PDAT1 & (1 << 4)));
// Wait for play to be released
while((PDAT1 & (1 << 4)));
PDAT0 ^= (1 << 2); //Toggle backlight
//toggle backlight on PLAY
while(counter<20)
/* Calibrate the lot */
read_qt1106(QT_MODE_FREE | QT_MOD_INF | QT_DI | QT_SLD_SLIDER | QT_CAL_WHEEL | QT_CAL_KEYS | QT_RES_4);
/* Set to maximum sensitivity */
read_qt1106(QT_CT | (0x00 << 8) );
while(true)
{
// Wait for play to be pressed
while(!(PDAT1 & (1 << 4)))
{
}
PDAT5 ^= (1 << 1); //Toggle piezo +
PDAT0 ^= (1 << 2); //Toggle backlight
counter++;
// Wait for play to be released
while(PDAT1 & (1 << 4))
{
}
}
//toggle a few times to warn that we're done
for(counter=0;counter<10;counter++)
{
volatile int i;
for(i=0;i<50000;i++);
PDAT0 ^= (1 << 2); //Toggle backlight
int slider = read_qt1106(QT_MODE_FREE | QT_MOD_INF | QT_DI | QT_SLD_SLIDER | QT_RES_4);
bl_debug_int(((slider&0xff)) + 1);
}
//power off
PDAT1&=~(1<<3);
}

View file

@ -39,6 +39,7 @@ start:
newstart:
msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
#if 0
/* set PWRON to 1 */
ldr r1, =0x3CF00014
ldr r2, [r1]
@ -50,7 +51,8 @@ newstart:
bic r2, r2, #0xf000
orr r2, r2, #0x1000
str r2, [r1]
#endif
/* Initialise bss section to zero */
ldr r2, =_edata
ldr r3, =_end