summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fw/fe310/eos/dev/lcd.c125
-rw-r--r--fw/fe310/eos/dev/lcd.h5
2 files changed, 130 insertions, 0 deletions
diff --git a/fw/fe310/eos/dev/lcd.c b/fw/fe310/eos/dev/lcd.c
new file mode 100644
index 0000000..69651d0
--- /dev/null
+++ b/fw/fe310/eos/dev/lcd.c
@@ -0,0 +1,125 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "encoding.h"
+#include "platform.h"
+
+#include "eos.h"
+
+#include "board.h"
+
+#include "soc/timer.h"
+#include "soc/pwr.h"
+#include "eve/eve.h"
+
+#include "eve.h"
+#include "gt911.h"
+#include "ili9806e.h"
+
+#include "lcd.h"
+
+static int lcd_enable(void) {
+ int rv;
+
+ rv = eos_spi_select(EOS_SPI_DEV_EVE);
+ if (rv) return rv;
+
+ eve_gpio_set(EVE_GPIO_LCD_EN, 1);
+ eos_spi_deselect();
+
+ return EOS_OK;
+}
+
+static int lcd_disable(void) {
+ int rv;
+
+ rv = eos_spi_select(EOS_SPI_DEV_EVE);
+ if (rv) return rv;
+
+ eve_gpio_set(EVE_GPIO_LCD_EN, 0);
+ eos_spi_deselect();
+
+ return EOS_OK;
+}
+
+int lcd_select(void) {
+ int rv;
+
+ 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;
+}
+
+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);
+}
+
+int eos_lcd_init(uint8_t wakeup_cause) {
+ int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
+ int rv;
+
+ rv = eos_lcd_wake();
+ if (rv) return rv;
+
+ eos_gt911_init();
+ if (rst) {
+ eos_gt911_reset();
+ } else {
+ /* There is a problem with GT911 and sleep */
+ // eos_gt911_wake();
+ eos_gt911_reset();
+ }
+ return EOS_OK;
+}
+
+int eos_lcd_sleep(void) {
+ int rv;
+
+ rv = lcd_select();
+ if (rv) return rv;
+
+ eos_ili9806e_sleep();
+ lcd_deselect();
+
+ rv = lcd_disable();
+ if (rv) return rv;
+
+ /* There is a problem with GT911 and sleep */
+ // eos_gt911_sleep();
+ return EOS_OK;
+}
+
+int eos_lcd_wake(void) {
+ int rv;
+
+ rv = lcd_enable();
+ if (rv) return rv;
+
+ eos_time_sleep(200);
+
+ rv = lcd_select();
+ if (rv) {
+ lcd_disable();
+ return rv;
+ }
+
+ rv = eos_ili9806e_init();
+ if (rv == EOS_ERR_ABSENT) eve_lcd_absent();
+ lcd_deselect();
+
+ if (rv) lcd_disable();
+ return rv;
+}
diff --git a/fw/fe310/eos/dev/lcd.h b/fw/fe310/eos/dev/lcd.h
new file mode 100644
index 0000000..7ca2f7d
--- /dev/null
+++ b/fw/fe310/eos/dev/lcd.h
@@ -0,0 +1,5 @@
+#include <stdint.h>
+
+int eos_lcd_init(uint8_t wakeup_cause);
+int eos_lcd_sleep(void);
+int eos_lcd_wake(void);