#include #include #include "eos.h" #include "event.h" #include "soc/pwr.h" #include "soc/timer.h" #include "eve/eve.h" #include "eve/eve_touch_engine.h" #include "egpio.h" #include "spi.h" #include "aon.h" #include "pwr.h" #include "eve.h" #ifdef EOS_DEBUG #include #endif static void handle_time(unsigned char type) { int rv; rv = eve_select(); if (rv) return; eve_handle_time(); eve_deselect(); } int eos_eve_handle_intr(void) { uint16_t intr_flags; int rv; rv = eve_select(); if (rv) return 0; intr_flags = eve_handle_intr(); eve_deselect(); if (intr_flags == 0) return 0; return 1; } int eos_eve_init(void) { uint8_t wakeup_cause; uint16_t gpio_reg; int rst, rv; rv = eve_select(); if (rv) return rv; wakeup_cause = eos_pwr_wakeup_cause(); rst = (wakeup_cause == EOS_PWR_WAKE_RST); if (rst) { rv = eve_init(); if (rv) goto eve_init_fin; eve_gpio_write(EVE_GPIO_DEFAULT); eve_gpio_write_dir(EVE_GPIO_DIR); eve_touch_init_engine(eos_egpio_get_val(EGPIO_PIN_CTP_SEL) ? EVE_TOUCH_ENGINE_HOST : EVE_TOUCH_ENGINE_GOODIX); gpio_reg = EVE_GPIO_DEFAULT; } else { uint8_t pwr_state; pwr_state = eos_aon_load4eve(); eve_pwr_set_state(pwr_state); eve_activate(); gpio_reg = eve_gpio_read(); eve_cmd_set_offset(); if (gpio_reg & EVE_GPIO_DISP) { eve_pwr_set_state(EVE_PSTATE_ACTIVE); } eve_deactivate(); } eve_init_fin: eve_deselect(); if (rv) return rv; eos_egpio_eve_set(gpio_reg); eve_touch_init(); eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time); return EOS_OK; } int eos_eve_run(void) { int rv; if (eve_pwr_state() != EVE_PSTATE_ACTIVE) return EOS_ERR_BUSY; rv = eve_select(); if (rv) return rv; eve_touch_intr_enable(); eve_touch_start(); eve_intr_enable(); eve_clk_start(); eve_deselect(); return EOS_OK; } int eos_eve_sleep(void) { int rv; rv = eve_select(); if (rv) return rv; eos_aon_save4eve(eve_pwr_state()); eve_clk_stop(); eve_intr_disable(); eve_touch_stop(); eve_touch_intr_disable(); eve_pwr_sleep(); eve_deselect(); return EOS_OK; } void eve_calibrate(void) { int rv, d; #ifdef EOS_DEBUG uint32_t matrix[6]; #endif if (!eve_selected()) { #ifdef EOS_DEBUG printf("EVE CALIBRATE: NOT SELECTED\n"); #endif return; } 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); rv = EOS_OK; do { d = eve_cmd_done(); if (d < 0) { rv = d; break; } eve_deselect(); eos_evtq_exec(); rv = eve_select(); if (rv) { #ifdef EOS_DEBUG printf("EVE CALIBRATE ERR:%d\n", rv); #endif return; } } while (!d); eve_touch_set_extended(1); #ifdef EOS_DEBUG if (rv) { printf("EVE CALIBRATE ERR:%d\n", rv); return; } eve_touch_get_matrix(matrix); 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]); #endif } int eve_select(void) { int rv; rv = eos_spi_select(EOS_SPI_DEV_EVE); return rv; } void eve_deselect(void) { eos_spi_deselect(); } int eve_selected(void) { return (eos_spi_dev() == EOS_SPI_DEV_EVE); }