1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#ifndef _TSC2000_H_
29#define _TSC2000_H_
30
31
32#define CON_MUX0 (gpio->PCCON = (gpio->PCCON & 0x0FFFFFCFF) | 0x00000100)
33#define CLR_MUX0 (gpio->PCDAT &= 0x0FFEF)
34#define SET_MUX0 (gpio->PCDAT |= 0x00010)
35
36#define CON_MUX1 (gpio->PCCON = (gpio->PCCON & 0x0FFFFF3FF) | 0x00000400)
37#define CLR_MUX1 (gpio->PCDAT &= 0x0FFDF)
38#define SET_MUX1 (gpio->PCDAT |= 0x00020)
39
40#define CON_MUX1_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFFCFFF) | 0x00001000)
41#define CLR_MUX1_ENABLE (gpio->PCDAT |= 0x00040)
42#define SET_MUX1_ENABLE (gpio->PCDAT &= 0x0FFBF)
43
44#define CON_MUX2_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFF3FFF) | 0x00004000)
45#define CLR_MUX2_ENABLE (gpio->PCDAT |= 0x00080)
46#define SET_MUX2_ENABLE (gpio->PCDAT &= 0x0FF7F)
47
48#define CON_MUX3_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFFCFFFF) | 0x00010000)
49#define CLR_MUX3_ENABLE (gpio->PCDAT |= 0x00100)
50#define SET_MUX3_ENABLE (gpio->PCDAT &= 0x0FEFF)
51
52#define CON_MUX4_ENABLE (gpio->PCCON = (gpio->PCCON & 0x0FFF3FFFF) | 0x00040000)
53#define CLR_MUX4_ENABLE (gpio->PCDAT |= 0x00200)
54#define SET_MUX4_ENABLE (gpio->PCDAT &= 0x0FDFF)
55
56#define CON_SEL_TEMP_V_0 (gpio->PCCON = (gpio->PCCON & 0x0FFCFFFFF) | 0x00100000)
57#define CLR_SEL_TEMP_V_0 (gpio->PCDAT &= 0x0FBFF)
58#define SET_SEL_TEMP_V_0 (gpio->PCDAT |= 0x00400)
59
60#define CON_SEL_TEMP_V_1 (gpio->PCCON = (gpio->PCCON & 0x0FF3FFFFF) | 0x00400000)
61#define CLR_SEL_TEMP_V_1 (gpio->PCDAT &= 0x0F7FF)
62#define SET_SEL_TEMP_V_1 (gpio->PCDAT |= 0x00800)
63
64#define CON_SEL_TEMP_V_2 (gpio->PCCON = (gpio->PCCON & 0x0FCFFFFFF) | 0x01000000)
65#define CLR_SEL_TEMP_V_2 (gpio->PCDAT &= 0x0EFFF)
66#define SET_SEL_TEMP_V_2 (gpio->PCDAT |= 0x01000)
67
68#define CON_SEL_TEMP_V_3 (gpio->PCCON = (gpio->PCCON & 0x0F3FFFFFF) | 0x04000000)
69#define CLR_SEL_TEMP_V_3 (gpio->PCDAT &= 0x0DFFF)
70#define SET_SEL_TEMP_V_3 (gpio->PCDAT |= 0x02000)
71
72
73#define TSC2000_REG_X ((0 << 11) | (0 << 5))
74#define TSC2000_REG_Y ((0 << 11) | (1 << 5))
75#define TSC2000_REG_Z1 ((0 << 11) | (2 << 5))
76#define TSC2000_REG_Z2 ((0 << 11) | (3 << 5))
77#define TSC2000_REG_BAT1 ((0 << 11) | (5 << 5))
78#define TSC2000_REG_BAT2 ((0 << 11) | (6 << 5))
79#define TSC2000_REG_AUX1 ((0 << 11) | (7 << 5))
80#define TSC2000_REG_AUX2 ((0 << 11) | (8 << 5))
81#define TSC2000_REG_TEMP1 ((0 << 11) | (9 << 5))
82#define TSC2000_REG_TEMP2 ((0 << 11) | (0xA << 5))
83#define TSC2000_REG_DAC ((0 << 11) | (0xB << 5))
84#define TSC2000_REG_ZERO ((0 << 11) | (0x10 << 5))
85#define TSC2000_REG_ADC ((1 << 11) | (0 << 5))
86#define TSC2000_REG_DACCTL ((1 << 11) | (2 << 5))
87#define TSC2000_REG_REF ((1 << 11) | (3 << 5))
88#define TSC2000_REG_RESET ((1 << 11) | (4 << 5))
89#define TSC2000_REG_CONFIG ((1 << 11) | (5 << 5))
90
91
92#define TC_PSM (1 << 15)
93#define TC_STS (1 << 14)
94#define TC_AD3 (1 << 13)
95#define TC_AD2 (1 << 12)
96#define TC_AD1 (1 << 11)
97#define TC_AD0 (1 << 10)
98#define TC_RS1 (1 << 9)
99#define TC_RS0 (1 << 8)
100#define TC_AV1 (1 << 7)
101#define TC_AV0 (1 << 6)
102#define TC_CL1 (1 << 5)
103#define TC_CL0 (1 << 4)
104#define TC_PV2 (1 << 3)
105#define TC_PV1 (1 << 2)
106#define TC_PV0 (1 << 1)
107
108
109#define DEFAULT_ADC (TC_PV1 | TC_AV0 | TC_AV1 | TC_RS0)
110
111#define TSC2000_DELAY_BASE 500
112#define TSC2000_NO_SENSOR -0x10000
113
114#define ERROR_BATTERY 220
115
116void tsc2000_write(unsigned short, unsigned short);
117unsigned short tsc2000_read (unsigned short);
118u16 tsc2000_read_channel (unsigned int);
119void tsc2000_set_mux (unsigned int);
120void tsc2000_set_range (unsigned int);
121void tsc2000_reg_init (void);
122s32 tsc2000_contact_temp (void);
123void spi_wait_transmit_done (void);
124void tsc2000_spi_init(void);
125int tsc2000_interpolate(long value, long data[][2], long *result);
126void adc_wait_conversion_done(void);
127
128
129static inline void SET_CS_TOUCH(void)
130{
131 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
132
133 gpio->PDDAT &= 0x5FF;
134}
135
136
137static inline void CLR_CS_TOUCH(void)
138{
139 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
140
141 gpio->PDDAT |= 0x200;
142}
143
144#endif
145