1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Bertrik Sikken
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 ****************************************************************************/
28 #include "button-target.h"
30 /* Button driver for the touch keys on the Samsung YP-S3
32 The exact controller is not known, but it is likely from Melfas.
34 The protocol is as follows:
35 * the communication is done using three signals: DRDY, DCLK and DOUT
36 * in the idle state these signals are all high.
37 * when a key is touched or released, the key controller pulls down DRDY
38 and outputs the first bit of a 20-bit word on its DOUT signal.
39 * the CPU stores the bit, then acknowledges it by toggling the DCLK signal.
40 * the key controller prepares the next bit, then toggles its DRDY output,
41 unless all 20 bits have been transferred (in that case it stays high).
42 * the 20-bit word contains separate bits for each button, some fixed bits
43 and a bit indicating the number of keys pressed (modulo 2).
47 void button_init_device(void)
49 /* P0.5/P1.0 power switch input */
53 /* P1.3 headphones detect input */
56 /* P1.5 DATA, P1.6 DRDY inputs (touch key controller) */
59 /* P3.4 DCLK output (touch key controller) */
60 PCON3
= (PCON3
& ~0x000F0000) | 0x00010000;
63 /* P4.3 hold switch input */
67 /* returns the raw 20-bit word from the touch key controller */
68 static int tkey_read(void)
74 if (PDAT1
& (1 << 6)) {
80 for (i
= 0; i
< 10; i
++) {
81 /* sample bit from falling edge of DRDY */
82 while ((PDAT1
& (1 << 6)) != 0);
84 if (PDAT1
& (1 << 5)) {
88 /* acknowledge on DCLK */
91 /* sample bit from rising edge of DRDY */
92 while ((PDAT1
& (1 << 6)) == 0);
94 if (PDAT1
& (1 << 5)) {
98 /* acknowledge on DCLK */
105 int button_read_device(void)
116 if (PDAT1
& (1 << 0)) {
117 buttons
|= BUTTON_POWER
;
121 tkey_data
= tkey_read();
122 if (tkey_data
& (1 << 9)) {
123 buttons
|= BUTTON_BACK
;
125 if (tkey_data
& (1 << 8)) {
126 buttons
|= BUTTON_UP
;
128 if (tkey_data
& (1 << 7)) {
129 buttons
|= BUTTON_MENU
;
131 if (tkey_data
& (1 << 6)) {
132 buttons
|= BUTTON_LEFT
;
134 if (tkey_data
& (1 << 5)) {
135 buttons
|= BUTTON_SELECT
;
137 if (tkey_data
& (1 << 4)) {
138 buttons
|= BUTTON_RIGHT
;
140 if (tkey_data
& (1 << 3)) {
141 buttons
|= BUTTON_DOWN
;
147 bool button_hold(void)
149 return (PDAT4
& (1 << 3));
152 bool headphones_inserted(void)
154 return ((PDAT1
& (1 << 3)) == 0);