summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/eve.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-11-28 23:53:05 +0100
committerUros Majstorovic <majstor@majstor.org>2021-11-28 23:53:05 +0100
commitacce7d8e05ac38776d6340342f6a7868df4f7f28 (patch)
treec0e2f3934b82967e4c2aff4a3dfcc5802bc94232 /fw/fe310/eos/eve/eve.c
parent0b0972ce96a59fb9b59c0b166e0174ba4d8dd198 (diff)
lcd driver added; fixed startup code;
Diffstat (limited to 'fw/fe310/eos/eve/eve.c')
-rw-r--r--fw/fe310/eos/eve/eve.c209
1 files changed, 113 insertions, 96 deletions
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 3447d6b..8cca34b 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -254,15 +254,23 @@ void eve_cmd_dl(uint32_t dl) {
int eve_cmd_done(void) {
uint16_t r = eve_read16(REG_CMD_READ);
+
if (r == 0xfff) {
+ uint16_t ptr;
+
cmd_offset = 0;
+ ptr = eve_read16(REG_COPRO_PATCH_PTR);
eve_write8(REG_CPURESET, 1);
eve_write16(REG_CMD_READ, 0);
eve_write16(REG_CMD_WRITE, 0);
eve_write16(REG_CMD_DL, 0);
eve_write8(REG_CPURESET, 0);
- return -1;
+ eve_write16(REG_COPRO_PATCH_PTR, ptr);
+ eve_write8(REG_PCLK, EVE_PCLK);
+
+ return EVE_ERR;
}
+
return (r == cmd_offset);
}
@@ -270,8 +278,10 @@ int eve_cmd_exec(int w) {
eve_write16(REG_CMD_WRITE, cmd_offset);
if (w) {
int r;
+
do {
r = eve_cmd_done();
+ if (r < 0) break;
} while (!r);
if (r < 0) return EVE_ERR;
}
@@ -293,92 +303,17 @@ void eve_cmd_burst_end(void) {
cmd_burst = 0;
}
-int eve_gpio_get(int gpio) {
- uint16_t reg = eve_read16(REG_GPIOX);
- return !!(reg & (1 << gpio));
-}
-
-void eve_gpio_set(int gpio, int val) {
- uint16_t reg = eve_read16(REG_GPIOX);
- uint16_t reg_val = (1 << gpio);
- if (val) {
- reg |= reg_val;
- } else {
- reg &= ~reg_val;
- }
- eve_write16(REG_GPIOX, reg);
-}
-
-uint8_t eve_gpio_get_dir(void) {
- uint16_t reg = eve_read16(REG_GPIOX_DIR);
- return reg & 0x000f;
-}
-
-void eve_gpio_set_dir(uint8_t dir) {
- uint16_t reg = eve_read16(REG_GPIOX_DIR);
- reg &= 0xfff0;
- reg |= dir & 0x0f;
- eve_write16(REG_GPIOX_DIR, reg);
-}
-
-void eve_active(void) {
- uint16_t gpiox;
-
- eve_command(EVE_ACTIVE, 0);
-
- if (power_state == EVE_PSTATE_SLEEP) {
- eve_time_sleep(40);
- eve_touch_active();
- }
-
- gpiox = eve_read16(REG_GPIOX) | 0x8000;
- eve_write16(REG_GPIOX, gpiox);
-
- power_state = EVE_PSTATE_ACTIVE;
-}
-
-void eve_standby(void) {
- uint16_t gpiox;
-
- if (power_state != EVE_PSTATE_ACTIVE) return;
-
- gpiox = eve_read16(REG_GPIOX) & ~0x8000;
- eve_write16(REG_GPIOX, gpiox);
-
- eve_command(EVE_STANDBY, 0);
-
- power_state = EVE_PSTATE_STANDBY;
-}
-
-void eve_sleep(void) {
- uint16_t gpiox;
-
- if (power_state != EVE_PSTATE_ACTIVE) return;
-
- gpiox = eve_read16(REG_GPIOX) & ~0x8000;
- eve_write16(REG_GPIOX, gpiox);
-
- eve_touch_sleep();
-
- eve_command(EVE_SLEEP, 0);
-
- power_state = EVE_PSTATE_SLEEP;
-}
-
-void eve_brightness(uint8_t b) {
- eve_write8(REG_PWM_DUTY, b);
-}
-
-static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) {
+static int _init(uint8_t gpio_dir) {
uint8_t chipid = 0;
uint8_t reset = 0x07;
uint16_t timeout;
- eve_command(EVE_CORERST, 0);
+ eve_command(EVE_CORERST, 0); /* reset */
+
eve_command(EVE_CLKEXT, 0);
eve_command(EVE_CLKSEL, 0x46); /* set clock to 72 MHz */
eve_command(EVE_ACTIVE, 0); /* start EVE */
- eve_time_sleep(40);
+ eve_time_sleep(4);
timeout = 0;
while (chipid != 0x7c) { /* if chipid is not 0x7c, continue to read it until it is, EVE needs a moment for it's power on self-test and configuration */
@@ -399,23 +334,23 @@ static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir)
eve_write32(REG_FREQUENCY, 72000000); /* tell EVE that we changed the frequency from default to 72MHz for BT8xx */
eve_write8(REG_PWM_DUTY, 0x00);
+ eve_write16(REG_GPIOX, 0x0000);
eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f));
- eve_write16(REG_GPIOX, 0x8000);
/* initialize display */
eve_write16(REG_HCYCLE, EVE_HCYCLE); /* total number of clocks per line, incl front/back porch */
eve_write16(REG_HOFFSET, EVE_HOFFSET); /* start of active line */
eve_write16(REG_HSYNC0, EVE_HSYNC0); /* start of horizontal sync pulse */
eve_write16(REG_HSYNC1, EVE_HSYNC1); /* end of horizontal sync pulse */
+ eve_write16(REG_HSIZE, EVE_HSIZE); /* active display width */
eve_write16(REG_VCYCLE, EVE_VCYCLE); /* total number of lines per screen, including pre/post */
eve_write16(REG_VOFFSET, EVE_VOFFSET); /* start of active screen */
eve_write16(REG_VSYNC0, EVE_VSYNC0); /* start of vertical sync pulse */
eve_write16(REG_VSYNC1, EVE_VSYNC1); /* end of vertical sync pulse */
+ eve_write16(REG_VSIZE, EVE_VSIZE); /* active display height */
eve_write8(REG_SWIZZLE, EVE_SWIZZLE); /* FT8xx output to LCD - pin order */
eve_write8(REG_PCLK_POL, EVE_PCLKPOL); /* LCD data is clocked in on this PCLK edge */
eve_write8(REG_CSPREAD, EVE_CSPREAD); /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */
- eve_write16(REG_HSIZE, EVE_HSIZE); /* active display width */
- eve_write16(REG_VSIZE, EVE_VSIZE); /* active display height */
/* do not set PCLK yet - wait for just after the first display list */
@@ -431,33 +366,115 @@ static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir)
eve_dl_write(DISPLAY());
eve_dl_swap();
- /* nothing is being displayed yet... the pixel clock is still 0x00 */
- eve_write16(REG_GPIOX, 0x8000); /* enable the DISP signal to the LCD panel, it is set to output in REG_GPIOX_DIR by default */
- eve_write8(REG_PCLK, EVE_PCLK); /* now start clocking data to the LCD panel */
-
- eve_cmd(CMD_SETROTATE, "w", 2);
+#ifdef EVE_PCLK_FREQ
+ eve_cmd(CMD_PCLKFREQ, "www", EVE_PCLK_FREQ, 0, 0);
eve_cmd_exec(1);
+#endif
+ /* nothing is being displayed yet... the pixel clock is still 0x00 */
return EVE_OK;
}
int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) {
- int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
-
- eve_spi_start();
+ int rst = (wakeup_cause == EVE_INIT_RST);
if (rst) {
- int rv = _init(touch_calibrate, touch_matrix, gpio_dir);
+ int rv = _init(gpio_dir);
if (rv) return rv;
} else {
- power_state = EVE_PSTATE_SLEEP;
- eve_active();
+ eve_command(EVE_ACTIVE, 0);
+ eve_time_sleep(40);
}
eve_touch_init(wakeup_cause, touch_calibrate, touch_matrix);
eve_platform_init();
- eve_spi_stop();
-
return EVE_OK;
}
+
+void eve_start(uint8_t wakeup_cause) {
+ uint16_t gpiox;
+
+ gpiox = eve_read16(REG_GPIOX) | 0x8000;
+ eve_write16(REG_GPIOX, gpiox); /* enable the DISP signal to the LCD panel, it is set to output in REG_GPIOX_DIR by default */
+ eve_write8(REG_PCLK, EVE_PCLK); /* now start clocking data to the LCD panel */
+
+ eve_touch_start(wakeup_cause);
+}
+
+void eve_stop(void) {
+ uint16_t gpiox;
+
+ eve_touch_stop();
+
+ gpiox = eve_read16(REG_GPIOX) & ~0x8000;
+ eve_write16(REG_GPIOX, gpiox);
+ eve_write8(REG_PCLK, 0);
+}
+
+int eve_gpio_get(int gpio) {
+ uint16_t reg = eve_read16(REG_GPIOX);
+ return !!(reg & (1 << gpio));
+}
+
+void eve_gpio_set(int gpio, int val) {
+ uint16_t reg = eve_read16(REG_GPIOX);
+ uint16_t reg_val = (1 << gpio);
+ if (val) {
+ reg |= reg_val;
+ } else {
+ reg &= ~reg_val;
+ }
+ eve_write16(REG_GPIOX, reg);
+}
+
+uint8_t eve_gpio_get_dir(void) {
+ uint16_t reg = eve_read16(REG_GPIOX_DIR);
+ return reg & 0x000f;
+}
+
+void eve_gpio_set_dir(uint8_t dir) {
+ uint16_t reg = eve_read16(REG_GPIOX_DIR);
+ reg &= 0xfff0;
+ reg |= dir & 0x0f;
+ eve_write16(REG_GPIOX_DIR, reg);
+}
+
+void eve_standby(void) {
+ uint16_t gpiox;
+
+ if (power_state != EVE_PSTATE_ACTIVE) return;
+
+ eve_command(EVE_STANDBY, 0);
+
+ power_state = EVE_PSTATE_STANDBY;
+}
+
+void eve_sleep(void) {
+ uint16_t gpiox;
+
+ if (power_state != EVE_PSTATE_ACTIVE) return;
+
+ eve_stop();
+
+ eve_command(EVE_SLEEP, 0);
+
+ power_state = EVE_PSTATE_SLEEP;
+}
+
+void eve_active(void) {
+ uint16_t gpiox;
+
+ eve_command(EVE_ACTIVE, 0);
+
+ if (power_state == EVE_PSTATE_SLEEP) {
+ eve_time_sleep(40);
+ eve_start(0);
+ }
+
+ power_state = EVE_PSTATE_ACTIVE;
+}
+
+void eve_brightness(uint8_t b) {
+ eve_write8(REG_PWM_DUTY, b);
+}