Fix non-integer display_zoom for charcell.
[maemo-rb.git] / firmware / target / hosted / ypr0 / button-ypr0.c
blobe66ca2273700068a2150a0113890acf7da1fe42d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
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 ****************************************************************************/
22 #include "config.h"
23 #include "button.h"
24 #include "kernel.h"
25 #include "system.h"
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)) {
35 key |= BUTTON_USER;
37 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_CENTRAL_KEY, 0, 0)) {
38 key |= BUTTON_SELECT;
40 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_UP_KEY, 0, 0)) {
41 key |= BUTTON_UP;
43 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_DOWN_KEY, 0, 0)) {
44 key |= BUTTON_DOWN;
46 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_LEFT_KEY, 0, 0)) {
47 key |= BUTTON_LEFT;
49 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_RIGHT_KEY, 0, 0)) {
50 key |= BUTTON_RIGHT;
52 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_MENU_KEY, 0, 0)) {
53 key |= BUTTON_MENU;
55 if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_BACK_KEY, 0, 0)) {
56 key |= BUTTON_BACK;
58 if (gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_POWER_KEY, 0, 0)) {
59 key |= BUTTON_POWER;
62 return key;
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 */