1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $
10 * Copyright (C) 2011 Lorenzo Miori
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 ****************************************************************************/
26 #include "button-target.h"
27 #include <gpio_ypr0.h> /* For headphones sense and buttons */
29 int button_read_device(void)
31 int key
= BUTTON_NONE
;
33 /* Check for all the keys */
34 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_USER_KEY
, 0, 0)) {
37 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_CENTRAL_KEY
, 0, 0)) {
40 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_UP_KEY
, 0, 0)) {
43 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_DOWN_KEY
, 0, 0)) {
46 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_LEFT_KEY
, 0, 0)) {
49 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_RIGHT_KEY
, 0, 0)) {
52 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_MENU_KEY
, 0, 0)) {
55 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_BACK_KEY
, 0, 0)) {
58 if (gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_POWER_KEY
, 0, 0)) {
65 bool headphones_inserted(void)
67 /* GPIO low - 0 - means headphones inserted */
68 return !gpio_control(DEV_CTRL_GPIO_IS_HIGH
, GPIO_HEADPHONE_SENSE
, 0, 0);
71 void button_init_device(void)
73 /* Setup GPIO pin for headphone sense, copied from OF */
74 gpio_control(DEV_CTRL_GPIO_SET_MUX
, GPIO_HEADPHONE_SENSE
, CONFIG_SION
, PAD_CTL_47K_PU
);
75 gpio_control(DEV_CTRL_GPIO_SET_INPUT
, GPIO_HEADPHONE_SENSE
, CONFIG_SION
, PAD_CTL_47K_PU
);
77 /* No need to initialize any GPIO pin, since this is done loading the r0Btn module */
80 #ifdef BUTTON_DRIVER_CLOSE
81 /* I'm not sure it's called at shutdown...give a check! */
82 void button_close_device(void)
84 /* Don't know the precise meaning, but it's done as in the OF, so copied there */
85 gpio_control(DEV_CTRL_GPIO_UNSET_MUX
, GPIO_HEADPHONE_SENSE
, CONFIG_SION
, 0);
87 #endif /* BUTTON_DRIVER_CLOSE */