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 ****************************************************************************/
27 #include "button-target.h"
29 /* Button driver for the touch keys on the Samsung YP-S3
31 The exact controller is not known, but it is likely from Melfas.
33 The protocol is as follows:
34 * the communication is done using three signals: DRDY, DCLK and DOUT
35 * in the idle state these signals are all high.
36 * when a key is touched or released, the key controller pulls down DRDY
37 and outputs the first bit of a 20-bit word on its DOUT signal.
38 * the CPU stores the bit, then acknowledges it by toggling the DCLK signal.
39 * the key controller prepares the next bit, then toggles its DRDY output,
40 unless all 20 bits have been transferred (in that case it stays high).
41 * the 20-bit word contains separate bits for each button, some fixed bits
42 and a bit indicating the number of keys pressed (modulo 2).
46 void button_init_device(void)
48 /* P0.5/P1.0 power switch input */
52 /* P1.3 headphones detect input */
55 /* P1.5 DATA, P1.6 DRDY inputs (touch key controller) */
58 /* P3.4 DCLK output (touch key controller) */
59 PCON3
= (PCON3
& ~0x000F0000) | 0x00010000;
62 /* P4.3 hold switch input */
66 static unsigned int tkey_read(void)
72 if (PDAT1
& (1 << 6)) {
78 for (i
= 0; i
< 10; i
++) {
79 /* sample bit from falling edge of DRDY */
80 while ((PDAT1
& (1 << 6)) != 0);
82 if (PDAT1
& (1 << 5)) {
86 /* acknowledge on DCLK */
89 /* sample bit from rising edge of DRDY */
90 while ((PDAT1
& (1 << 6)) == 0);
92 if (PDAT1
& (1 << 5)) {
96 /* acknowledge on DCLK */
103 int button_read_device(void)
106 static unsigned int data
;
114 if (PDAT1
& (1 << 0)) {
115 buttons
|= BUTTON_POWER
;
120 if (data
& (1 << 9)) {
121 buttons
|= BUTTON_BACK
;
123 if (data
& (1 << 8)) {
124 buttons
|= BUTTON_UP
;
126 if (data
& (1 << 7)) {
127 buttons
|= BUTTON_MENU
;
129 if (data
& (1 << 6)) {
130 buttons
|= BUTTON_LEFT
;
132 if (data
& (1 << 5)) {
133 buttons
|= BUTTON_SELECT
;
135 if (data
& (1 << 4)) {
136 buttons
|= BUTTON_RIGHT
;
138 if (data
& (1 << 3)) {
139 buttons
|= BUTTON_DOWN
;
145 bool button_hold(void)
147 return (PDAT4
& (1 << 3));
150 bool headphones_inserted(void)
152 return ((PDAT1
& (1 << 3)) == 0);