summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/dev/eve.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/dev/eve.c')
-rw-r--r--fw/fe310/eos/dev/eve.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/fw/fe310/eos/dev/eve.c b/fw/fe310/eos/dev/eve.c
new file mode 100644
index 0000000..0f98fed
--- /dev/null
+++ b/fw/fe310/eos/dev/eve.c
@@ -0,0 +1,152 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "platform.h"
+
+#include "eos.h"
+#include "event.h"
+
+#include "board.h"
+
+#include "soc/interrupt.h"
+#include "soc/pwr.h"
+#include "soc/i2s.h"
+
+#include "eve/eve.h"
+#include "eve/eve_touch_engine.h"
+
+#include "eve.h"
+
+static void handle_time(unsigned char type) {
+ if (!eos_eve_running()) return;
+
+ eve_spi_start();
+ eve_handle_time();
+ eve_spi_stop();
+}
+
+static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+ if (!eos_eve_running()) return;
+
+ eve_spi_start();
+ eve_handle_intr();
+ eve_spi_stop();
+
+ GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
+}
+
+static void handle_intr(void) {
+ GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
+ GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR);
+ eos_evtq_push_isr(EOS_EVT_EVE | EVE_ETYPE_INTR, NULL, 0);
+}
+
+static void _start(void) {
+ eve_touch_start();
+ eve_start();
+
+ GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR);
+ GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
+
+ eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR);
+}
+
+static void _stop(void) {
+ eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR);
+
+ GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << EVE_PIN_INTR);
+
+ eve_touch_stop();
+ eve_stop();
+}
+
+int eos_eve_init(uint8_t wakeup_cause) {
+ int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
+ int rv = EVE_OK;
+
+ eve_spi_start();
+ if (rst) {
+ rv = eve_init();
+ if (!rv) {
+ eve_gpio_set_dir(EVE_GPIO_DIR);
+ eve_touch_init_engine();
+ }
+ } else {
+ eve_activate();
+ }
+ eve_spi_stop();
+
+ if (rv) return EOS_ERR;
+
+ eve_touch_init();
+
+ eos_evtq_set_handler(EOS_EVT_EVE, handle_evt);
+ eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time);
+ eos_intr_set_handler(INT_GPIO_BASE + EVE_PIN_INTR, handle_intr);
+ eos_intr_set_priority(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_EVE);
+
+ return EOS_OK;
+}
+
+void eos_eve_calibrate(void) {
+ uint32_t matrix[6];
+ int r;
+
+ eve_spi_start();
+
+ eve_brightness(0x40);
+ eve_touch_set_extended(0);
+
+ eve_cmd(CMD_TEXT, "hhhhs", EVE_HSIZE/2, EVE_VSIZE/2, 27, EVE_OPT_CENTER, "Please tap on the dot.");
+ eve_cmd(CMD_CALIBRATE, "w", 0);
+ eve_cmd_exec(0);
+
+ do {
+ r = eve_cmd_done();
+ if (r < 0) break;
+ eve_spi_stop();
+ eos_evtq_exec();
+ eve_spi_start();
+ } while (!r);
+
+ eve_touch_set_extended(1);
+ eve_brightness(0);
+
+ eve_touch_get_matrix(matrix);
+ eve_spi_stop();
+
+ printf("TOUCH MATRIX:\n");
+ printf("uint32_t touch_matrix[6] = {0x%x,0x%x,0x%x,0x%x,0x%x,0x%x}\n", matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
+}
+
+void eos_eve_set_touch_matrix(const uint32_t *matrix) {
+ eve_spi_start();
+ eve_touch_set_matrix(matrix);
+ eve_spi_stop();
+}
+
+int eos_eve_run(uint8_t wakeup_cause) {
+ eve_spi_start();
+ _start();
+ eve_start_clk();
+ eve_spi_stop();
+
+ return EOS_OK;
+}
+
+void eos_eve_start(void) {
+ eve_spi_start();
+ _start();
+ eve_spi_stop();
+}
+
+void eos_eve_stop(void) {
+ eve_spi_start();
+ _stop();
+ eve_spi_stop();
+}
+
+int eos_eve_running(void) {
+ return !!(GPIO_REG(GPIO_INPUT_EN) & (1 << EVE_PIN_INTR));
+}