2007-09-22 14:21:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2009-07-12 09:43:44 +00:00
|
|
|
* $Id$
|
2007-09-22 14:21:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Jonathan Gordon
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-22 14:21:07 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "spi.h"
|
|
|
|
#include "tsc2100.h"
|
|
|
|
|
2009-04-28 05:20:31 +00:00
|
|
|
/* adc_data contains the last readings from the tsc2100 */
|
|
|
|
static short adc_data[10];
|
2009-05-02 23:25:55 +00:00
|
|
|
static short adc_status;
|
2009-04-28 05:20:31 +00:00
|
|
|
|
|
|
|
void tsc2100_read_data(void)
|
2007-09-22 14:21:07 +00:00
|
|
|
{
|
|
|
|
int page = 0, address = 0;
|
2009-04-28 05:20:31 +00:00
|
|
|
unsigned int i;
|
2007-09-22 14:21:07 +00:00
|
|
|
unsigned short command = 0x8000|(page << 11)|(address << 5);
|
|
|
|
unsigned char out[] = {command >> 8, command & 0xff};
|
2009-04-28 05:20:31 +00:00
|
|
|
unsigned char *p_adc_data=(unsigned char *)&adc_data;
|
|
|
|
|
2009-05-02 23:25:55 +00:00
|
|
|
adc_status|=tsc2100_readreg(TSSTAT_PAGE, TSSTAT_ADDRESS);
|
|
|
|
|
2009-06-24 04:17:15 +00:00
|
|
|
spi_block_transfer(SPI_target_TSC2100,
|
2009-04-28 05:20:31 +00:00
|
|
|
out, sizeof(out), (char *)adc_data, sizeof(adc_data));
|
|
|
|
|
|
|
|
for(i=0; i<sizeof(adc_data); i+=2)
|
|
|
|
adc_data[i>>1]=(short)(p_adc_data[i]<<8|p_adc_data[i+1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read X, Y, Z1, Z2 touchscreen coordinates. */
|
2009-05-02 23:25:55 +00:00
|
|
|
bool tsc2100_read_touch(short *x, short* y, short *z1, short *z2)
|
2009-04-28 05:20:31 +00:00
|
|
|
{
|
2009-12-12 18:36:52 +00:00
|
|
|
if( adc_status&(3<<9) ) {
|
2009-05-02 23:25:55 +00:00
|
|
|
*x = adc_data[0];
|
|
|
|
*y = adc_data[1];
|
|
|
|
*z1 = adc_data[2];
|
|
|
|
*z2 = adc_data[3];
|
|
|
|
|
|
|
|
adc_status&=~(3<<9);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-28 05:20:31 +00:00
|
|
|
}
|
2007-09-22 14:21:07 +00:00
|
|
|
|
2009-05-02 23:25:55 +00:00
|
|
|
bool tsc2100_read_volt(short *bat1, short *bat2, short *aux)
|
2009-04-28 05:20:31 +00:00
|
|
|
{
|
2009-12-12 18:36:52 +00:00
|
|
|
if( adc_status&(7<<4) ) {
|
2009-05-02 23:25:55 +00:00
|
|
|
*bat1 = adc_data[5];
|
|
|
|
*bat2 = adc_data[6];
|
|
|
|
*aux = adc_data[7];
|
|
|
|
|
|
|
|
adc_status&=~(7<<4);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-28 05:20:31 +00:00
|
|
|
}
|
|
|
|
|
2009-05-02 23:25:55 +00:00
|
|
|
void tsc2100_set_mode(bool poweron, unsigned char scan_mode)
|
2009-04-28 05:20:31 +00:00
|
|
|
{
|
|
|
|
short tsadc=(scan_mode<<TSADC_ADSCM_SHIFT)| /* mode */
|
|
|
|
(0x3<<TSADC_RESOL_SHIFT)| /* 12 bit resolution */
|
2011-02-06 19:26:31 +00:00
|
|
|
(0x2<<TSADC_ADAVG_SHIFT)| /* 8 or 9 sample average */
|
2009-04-28 05:20:31 +00:00
|
|
|
(0x2<<TSADC_ADCR_SHIFT )| /* 2 MHz internal clock */
|
2011-02-06 19:26:31 +00:00
|
|
|
(0x3<<TSADC_PVSTC_SHIFT)| /* 1 ms stabalization */
|
|
|
|
(TSADC_AVGFS); /* Median filter ( 9 sample ) */
|
2009-04-28 05:20:31 +00:00
|
|
|
|
2009-05-02 23:25:55 +00:00
|
|
|
if(!poweron)
|
|
|
|
{
|
|
|
|
tsadc|=TSADC_ADST;
|
|
|
|
}
|
|
|
|
|
2009-04-28 05:20:31 +00:00
|
|
|
if(scan_mode<6)
|
|
|
|
tsadc|=TSADC_PSTCM;
|
|
|
|
|
|
|
|
tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tsc2100_adc_init(void)
|
|
|
|
{
|
|
|
|
/* Set the TSC2100 to read touchscreen */
|
2009-12-12 18:36:52 +00:00
|
|
|
tsc2100_set_mode(true, 0x02);
|
2009-05-02 23:25:55 +00:00
|
|
|
|
2009-04-28 05:20:31 +00:00
|
|
|
tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS,
|
|
|
|
(0x1<<TSSTAT_PINTDAV_SHIFT) /* Data available only */
|
|
|
|
);
|
2009-05-02 23:25:55 +00:00
|
|
|
|
|
|
|
/* An additional 2 mA can be saved here by powering down vref between
|
|
|
|
* conversions, but it adds a click to the audio on the M:Robe 500
|
|
|
|
*/
|
2009-04-28 05:20:31 +00:00
|
|
|
tsc2100_writereg(TSREF_PAGE, TSREF_ADDRESS,
|
|
|
|
TSREF_VREFM|TSREF_IREFV);
|
2007-09-22 14:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short tsc2100_readreg(int page, int address)
|
|
|
|
{
|
|
|
|
unsigned short command = 0x8000|(page << 11)|(address << 5);
|
|
|
|
unsigned char out[] = {command >> 8, command & 0xff};
|
|
|
|
unsigned char in[2];
|
2009-06-24 04:17:15 +00:00
|
|
|
spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), in, sizeof(in));
|
2007-09-22 14:21:07 +00:00
|
|
|
return (in[0]<<8)|in[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void tsc2100_writereg(int page, int address, short value)
|
|
|
|
{
|
2007-10-22 13:53:19 +00:00
|
|
|
unsigned short command = (page << 11)|(address << 5);
|
2007-09-22 14:21:07 +00:00
|
|
|
unsigned char out[4] = {command >> 8, command & 0xff,
|
|
|
|
value >> 8, value & 0xff};
|
2009-06-24 04:17:15 +00:00
|
|
|
spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), NULL, 0);
|
2007-09-22 14:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tsc2100_keyclick(void)
|
|
|
|
{
|
|
|
|
// 1100 0100 0001 0000
|
2008-04-27 13:38:24 +00:00
|
|
|
//short val = 0xC410;
|
2007-10-22 13:53:19 +00:00
|
|
|
tsc2100_writereg(TSAC2_PAGE, TSAC2_ADDRESS, tsc2100_readreg(TSAC2_PAGE, TSAC2_ADDRESS)&0x8000);
|
2007-09-22 14:21:07 +00:00
|
|
|
}
|
2009-05-02 23:25:55 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_HARDWARE_BEEP
|
|
|
|
|
|
|
|
void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude)
|
|
|
|
{
|
|
|
|
tsc2100_keyclick();
|
|
|
|
}
|
|
|
|
#endif
|