#include #include #include "platform.h" #include "board.h" #include "eos.h" #include "soc/pwr.h" #include "soc/i2s.h" #include "soc/timer.h" #include "eve/eve.h" #include "egpio.h" #include "spi.h" #include "eve.h" #include "pwr.h" #include "drv/ili9806e.h" #include "lcd.h" static int lcd_enable(void) { int rv; if (eos_i2s_running() || !eos_egpio_get_val(EGPIO_PIN_DISP_SEL)) return EOS_ERR_BUSY; rv = eos_egpio_set_val(EGPIO_PIN_LCD_EN, 1); return rv; } static int lcd_disable(void) { int rv; if (eos_i2s_running() || !eos_egpio_get_val(EGPIO_PIN_DISP_SEL)) return EOS_ERR_BUSY; rv = eos_egpio_set_val(EGPIO_PIN_LCD_EN, 0); return rv; } static int lcd_select(void) { int rv; if (eos_i2s_running() || !eos_egpio_get_val(EGPIO_PIN_DISP_SEL)) return EOS_ERR_BUSY; GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_EN) |= (1 << SPI_CSPIN_LCD); rv = eos_spi_select(EOS_SPI_DEV_LCD); if (rv) { GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << SPI_CSPIN_LCD); return rv; } return EOS_OK; } static void lcd_deselect(void) { eos_spi_deselect(); GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << SPI_CSPIN_LCD); GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << SPI_CSPIN_LCD); } static int lcd_init(void) { int rv; rv = lcd_enable(); if (rv) return rv; eos_sleep(200); rv = lcd_select(); if (rv) { lcd_disable(); return rv; } rv = ili9806e_init(); if (rv == EOS_ERR_NOTFOUND) eve_lcd_absent(); lcd_deselect(); if (rv) lcd_disable(); return rv; } static int lcd_sleep(void) { int rv; rv = lcd_select(); if (rv) return rv; ili9806e_sleep(); lcd_deselect(); rv = lcd_disable(); return rv; } int eos_lcd_init(void) { uint8_t wakeup_cause; int rv, rst; wakeup_cause = eos_pwr_wakeup_cause(); rst = (wakeup_cause == EOS_PWR_WAKE_RST); if (rst) { rv = lcd_init(); } else { rv = eos_lcd_wake(); } return rv; } int eos_lcd_sleep(void) { int rv; rv = lcd_sleep(); return rv; } int eos_lcd_wake(void) { int rv; rv = lcd_init(); return rv; }