summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/aigo/button-erosq.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-10-08 09:47:40 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-10-11 16:37:17 -0400
commit2a471e288c16b91a7186a60b3fb84dd55a494c7a (patch)
tree3e746212c5fa69b59f61d19b6e29d11aa8a5e31b /firmware/target/hosted/aigo/button-erosq.c
parent5efaa9ef8073bb216e3dcdbb4476f2fa7c672b76 (diff)
downloadrockbox-2a471e288c.tar.gz
rockbox-2a471e288c.tar.bz2
rockbox-2a471e288c.zip
New port: AIGO EROS Q / EROS K
The Q and K have a slightly different case, but the hardware under the shell is completely identical. These models are rebadged versions: * Hifiwalker H2 (== Q) * AGPTek H3 (== K) * Surfans F20 (== K) Other notes: * Significant improvements in the shared Hiby-platform launcher/loader * SD card can theoretically be hot-swapped now * Support external USB mass storage! * Some consolidation of Hiby-platform targets * Some consolidation of plugin keymaps Todo/known issues: * Keymaps need to be gone over properly * Convert to HAVE_SCROLLWHEEL? Change-Id: I5a8a4f22c38a5b69392ca7c0a8ad8c4e07d9523c
Diffstat (limited to 'firmware/target/hosted/aigo/button-erosq.c')
-rw-r--r--firmware/target/hosted/aigo/button-erosq.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/firmware/target/hosted/aigo/button-erosq.c b/firmware/target/hosted/aigo/button-erosq.c
new file mode 100644
index 0000000000..2735c48c71
--- /dev/null
+++ b/firmware/target/hosted/aigo/button-erosq.c
@@ -0,0 +1,188 @@
+/***************************************************************************
+ * __________ __ ___
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 Marcin Bukat
+ * Copyright (C) 2020 Solomon Peachy
+ *
+ * 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 <poll.h>
+//#include <dir.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <linux/input.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "sysfs.h"
+#include "button.h"
+#include "button-target.h"
+#include "panic.h"
+
+#include "kernel.h"
+#include "backlight.h"
+#include "backlight-target.h"
+#include "erosqlinux_codec.h"
+
+#define NR_POLL_DESC 3
+static struct pollfd poll_fds[NR_POLL_DESC];
+
+static int button_map(int keycode)
+{
+ switch(keycode)
+ {
+ case KEY_POWER:
+ return BUTTON_POWER;
+
+ case KEY_MENU:
+ return BUTTON_MENU;
+
+ case KEY_BACK:
+ return BUTTON_BACK;
+
+ case KEY_NEXTSONG:
+ return BUTTON_PREV;
+
+ case KEY_PREVIOUSSONG:
+ return BUTTON_NEXT; // Yes, backwards!
+
+ case KEY_PLAYPAUSE:
+ return BUTTON_PLAY;
+
+ case KEY_LEFT:
+ return BUTTON_SCROLL_BACK;
+
+ case KEY_RIGHT:
+ return BUTTON_SCROLL_FWD;
+
+ case KEY_VOLUMEUP:
+ return BUTTON_VOL_UP;
+
+ case KEY_VOLUMEDOWN:
+ return BUTTON_VOL_DOWN;
+
+ default:
+ return 0;
+ }
+}
+
+void button_init_device(void)
+{
+ const char * const input_devs[] = {
+ "/dev/input/event0", // Rotary encoder
+ "/dev/input/event1" // Keys
+ };
+
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
+
+ if(fd < 0)
+ {
+ panicf("Cannot open input device: %s\n", input_devs[i]);
+ }
+
+ poll_fds[i].fd = fd;
+ poll_fds[i].events = POLLIN;
+ poll_fds[i].revents = 0;
+ }
+}
+
+int button_read_device(void)
+{
+ static int button_bitmap = 0;
+ struct input_event event;
+
+ // FIXME TODO: Make this work via HAVE_SCROLL_WHEEL instead
+
+ /* Wheel gives us press+release back to back, clear them after time elapses */
+ static long last_tick = 0;
+ if (button_bitmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD) &&
+ current_tick - last_tick >= 2)
+ {
+ button_bitmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
+ }
+
+ /* check if there are any events pending and process them */
+ while(poll(poll_fds, NR_POLL_DESC, 0))
+ {
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ /* read only if non-blocking */
+ if(poll_fds[i].revents & POLLIN)
+ {
+ int size = read(poll_fds[i].fd, &event, sizeof(event));
+ if(size == (int)sizeof(event))
+ {
+ int keycode = event.code;
+ /* event.value == 1 means press
+ * event.value == 0 means release
+ */
+ bool press = event.value ? true : false;
+
+ /* map linux event code to rockbox button bitmap */
+ if(press)
+ {
+ int bmap = button_map(keycode);
+ if (bmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD))
+ last_tick = current_tick;
+ button_bitmap |= bmap;
+ }
+ else
+ {
+ /* Wheel gives us press+release back to back; ignore the release */
+ int bmap = button_map(keycode) & ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
+ button_bitmap &= ~bmap;
+ }
+ }
+ }
+ }
+ }
+
+ return button_bitmap;
+}
+
+bool headphones_inserted(void)
+{
+#ifdef BOOTLOADER
+ int ps = 0;
+#else
+ int ps = erosq_get_outputs();
+#endif
+
+ return (ps == 2);
+}
+
+bool lineout_inserted(void)
+{
+#ifdef BOOTLOADER
+ int ps = 0;
+#else
+ int ps = erosq_get_outputs();
+#endif
+
+ return (ps == 1);
+}
+
+void button_close_device(void)
+{
+ /* close descriptors */
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ close(poll_fds[i].fd);
+ }
+}