Add lang strings to hotkey setting macros
[kugel-rb.git] / firmware / drivers / tsc2100.c
blobb8edb7d52dcc80a70ecf385c225407630e8de6bd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "cpu.h"
24 #include "system.h"
25 #include "spi.h"
26 #include "tsc2100.h"
28 /* adc_data contains the last readings from the tsc2100 */
29 static short adc_data[10];
30 static short adc_status;
32 void tsc2100_read_data(void)
34 int page = 0, address = 0;
35 unsigned int i;
36 unsigned short command = 0x8000|(page << 11)|(address << 5);
37 unsigned char out[] = {command >> 8, command & 0xff};
38 unsigned char *p_adc_data=(unsigned char *)&adc_data;
40 adc_status|=tsc2100_readreg(TSSTAT_PAGE, TSSTAT_ADDRESS);
42 spi_block_transfer(SPI_target_TSC2100,
43 out, sizeof(out), (char *)adc_data, sizeof(adc_data));
45 for(i=0; i<sizeof(adc_data); i+=2)
46 adc_data[i>>1]=(short)(p_adc_data[i]<<8|p_adc_data[i+1]);
49 /* Read X, Y, Z1, Z2 touchscreen coordinates. */
50 bool tsc2100_read_touch(short *x, short* y, short *z1, short *z2)
52 if( adc_status&(3<<9) ) {
53 *x = adc_data[0];
54 *y = adc_data[1];
55 *z1 = adc_data[2];
56 *z2 = adc_data[3];
58 adc_status&=~(3<<9);
60 return true;
61 } else {
62 return false;
66 bool tsc2100_read_volt(short *bat1, short *bat2, short *aux)
68 if( adc_status&(7<<4) ) {
69 *bat1 = adc_data[5];
70 *bat2 = adc_data[6];
71 *aux = adc_data[7];
73 adc_status&=~(7<<4);
74 return true;
75 } else {
76 return false;
80 void tsc2100_set_mode(bool poweron, unsigned char scan_mode)
82 short tsadc=(scan_mode<<TSADC_ADSCM_SHIFT)| /* mode */
83 (0x3<<TSADC_RESOL_SHIFT)| /* 12 bit resolution */
84 (0x2<<TSADC_ADCR_SHIFT )| /* 2 MHz internal clock */
85 (0x2<<TSADC_PVSTC_SHIFT);
87 if(!poweron)
89 tsadc|=TSADC_ADST;
92 if(scan_mode<6)
93 tsadc|=TSADC_PSTCM;
95 tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc);
98 void tsc2100_adc_init(void)
100 /* Set the TSC2100 to read touchscreen */
101 tsc2100_set_mode(true, 0x02);
103 tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS,
104 (0x1<<TSSTAT_PINTDAV_SHIFT) /* Data available only */
107 /* An additional 2 mA can be saved here by powering down vref between
108 * conversions, but it adds a click to the audio on the M:Robe 500
110 tsc2100_writereg(TSREF_PAGE, TSREF_ADDRESS,
111 TSREF_VREFM|TSREF_IREFV);
114 short tsc2100_readreg(int page, int address)
116 unsigned short command = 0x8000|(page << 11)|(address << 5);
117 unsigned char out[] = {command >> 8, command & 0xff};
118 unsigned char in[2];
119 spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), in, sizeof(in));
120 return (in[0]<<8)|in[1];
123 void tsc2100_writereg(int page, int address, short value)
125 unsigned short command = (page << 11)|(address << 5);
126 unsigned char out[4] = {command >> 8, command & 0xff,
127 value >> 8, value & 0xff};
128 spi_block_transfer(SPI_target_TSC2100, out, sizeof(out), NULL, 0);
131 void tsc2100_keyclick(void)
133 // 1100 0100 0001 0000
134 //short val = 0xC410;
135 tsc2100_writereg(TSAC2_PAGE, TSAC2_ADDRESS, tsc2100_readreg(TSAC2_PAGE, TSAC2_ADDRESS)&0x8000);
138 #ifdef HAVE_HARDWARE_BEEP
140 void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude)
142 tsc2100_keyclick();
144 #endif