From e876f4df6d240bd2e319b1e63be95a625f049a97 Mon Sep 17 00:00:00 2001 From: Lorenzo Miori Date: Tue, 10 Sep 2013 22:48:34 +0200 Subject: Samsung YP-R1 target port This is the basic port to the new target Samsung YP-R1, which runs on a similar platform as YP-R0. Port is usable, although there are still some optimizations that have to be done. Change-Id: If83a8e386369e413581753780c159026d9e41f04 --- .../target/hosted/samsungypr/ypr1/button-ypr1.c | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 firmware/target/hosted/samsungypr/ypr1/button-ypr1.c (limited to 'firmware/target/hosted/samsungypr/ypr1/button-ypr1.c') diff --git a/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c b/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c new file mode 100644 index 0000000000..09891cfaf6 --- /dev/null +++ b/firmware/target/hosted/samsungypr/ypr1/button-ypr1.c @@ -0,0 +1,130 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $ + * + * Copyright (C) 2013 Lorenzo Miori + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "button.h" +#include "kernel.h" +#include "system.h" +#include "button-target.h" + +#include /* For headphones sense and buttons */ +#include "mcs5000.h" /* Touchscreen controller */ +#include "ioctl-ypr1.h" + +enum { + STATE_UNKNOWN, + STATE_UP, + STATE_DOWN, +}; + +static int last_x = 0; +static int last_y = 0; +static int last_touch_state = STATE_UNKNOWN; + +int button_read_device(int *data) +{ + int key = BUTTON_NONE; + int read_size; + struct mcs5000_raw_data touchpad_data; + + /* Check for all the keys */ + if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_VOL_UP_KEY, 0, 0)) { + key |= BUTTON_VOL_UP; + } + if (!gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_VOL_DOWN_KEY, 0, 0)) { + key |= BUTTON_VOL_DOWN; + } + if (gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_POWER_KEY, 0, 0)) { + key |= BUTTON_POWER; + } + + read_size = mcs5000_read(&touchpad_data); + + if (read_size == sizeof(struct mcs5000_raw_data)) { + /* Generate UP and DOWN events */ + if (touchpad_data.inputInfo & INPUT_TYPE_SINGLE) { + last_touch_state = STATE_DOWN; + } + else { + last_touch_state = STATE_UP; + } + /* Swap coordinates here */ +#if CONFIG_ORIENTATION == SCREEN_PORTRAIT + last_x = (touchpad_data.yHigh << 8) | touchpad_data.yLow; + last_y = (touchpad_data.xHigh << 8) | touchpad_data.xLow; +#else + last_x = (touchpad_data.xHigh << 8) | touchpad_data.xLow; + last_y = (touchpad_data.yHigh << 8) | touchpad_data.yLow; +#endif + } + + int tkey = touchscreen_to_pixels(last_x, last_y, data); + + if (last_touch_state == STATE_DOWN) { + key |= tkey; + } + + return key; +} + +#ifndef HAS_BUTTON_HOLD +void touchscreen_enable_device(bool en) +{ + if (en) { + mcs5000_power(); + } + else { + mcs5000_shutdown(); + } +} +#endif + +bool headphones_inserted(void) +{ + /* GPIO low - 0 - means headphones inserted */ + return !gpio_control(DEV_CTRL_GPIO_IS_HIGH, GPIO_HEADPHONE_SENSE, 0, 0); +} + +void button_init_device(void) +{ + /* Setup GPIO pin for headphone sense, copied from OF + * Pins for the other buttons are already set up by OF button module + */ + gpio_control(DEV_CTRL_GPIO_SET_MUX, GPIO_HEADPHONE_SENSE, 4, 0); + gpio_control(DEV_CTRL_GPIO_SET_INPUT, GPIO_HEADPHONE_SENSE, 4, 0); + + /* Turn on touchscreen */ + mcs5000_init(); + mcs5000_power(); + mcs5000_set_hand(RIGHT_HAND); +} + +#ifdef BUTTON_DRIVER_CLOSE +/* I'm not sure it's called at shutdown...give a check! */ +void button_close_device(void) +{ + gpio_control(DEV_CTRL_GPIO_UNSET_MUX, GPIO_HEADPHONE_SENSE, 0, 0); + + /* Turn off touchscreen device */ + mcs5000_shutdown(); + mcs5000_close(); +} +#endif /* BUTTON_DRIVER_CLOSE */ -- cgit v1.2.3