summaryrefslogtreecommitdiff
path: root/fw/fe310/eos
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos')
-rw-r--r--fw/fe310/eos/Makefile12
-rw-r--r--fw/fe310/eos/board.h28
-rw-r--r--fw/fe310/eos/dev/Makefile12
-rw-r--r--fw/fe310/eos/dev/bq25895.c5
-rw-r--r--fw/fe310/eos/dev/cam.c10
-rw-r--r--fw/fe310/eos/dev/eve.c (renamed from fw/fe310/eos/eve_eos.c)69
-rw-r--r--fw/fe310/eos/dev/eve.h (renamed from fw/fe310/eos/eve_eos.h)4
-rw-r--r--fw/fe310/eos/dev/lcd.c546
-rw-r--r--fw/fe310/eos/dev/lcd.h12
-rw-r--r--fw/fe310/eos/dev/net.c (renamed from fw/fe310/eos/soc/net.c)18
-rw-r--r--fw/fe310/eos/dev/net.h (renamed from fw/fe310/eos/soc/net.h)2
-rw-r--r--fw/fe310/eos/dev/ov2640.c6
-rw-r--r--fw/fe310/eos/dev/sdc_crypto.h2
-rw-r--r--fw/fe310/eos/dev/sdcard.c4
-rw-r--r--fw/fe310/eos/dev/spi.c (renamed from fw/fe310/eos/soc/spi_dev.c)42
-rw-r--r--fw/fe310/eos/dev/spi.h (renamed from fw/fe310/eos/soc/spi_dev.h)2
-rw-r--r--fw/fe310/eos/dev/spi_cfg.h (renamed from fw/fe310/eos/soc/spi_cfg.h)21
-rw-r--r--fw/fe310/eos/eos.c75
-rw-r--r--fw/fe310/eos/eve/Makefile16
-rw-r--r--fw/fe310/eos/eve/eve.c7
-rw-r--r--fw/fe310/eos/eve/eve.h2
-rwxr-xr-xfw/fe310/eos/eve/eve_config.h16
-rw-r--r--fw/fe310/eos/eve/eve_phy.c15
-rw-r--r--fw/fe310/eos/eve/eve_phy.h2
-rw-r--r--fw/fe310/eos/eve/eve_platform.h6
-rw-r--r--fw/fe310/eos/eve/eve_touch.c24
-rw-r--r--fw/fe310/eos/eve/eve_touch.h1
-rw-r--r--fw/fe310/eos/eve/eve_touch_engine.c119
-rw-r--r--fw/fe310/eos/eve/eve_touch_engine.h17
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.c34
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.h12
-rw-r--r--fw/fe310/eos/eve/screen/form.c52
-rw-r--r--fw/fe310/eos/eve/screen/form.h16
-rw-r--r--fw/fe310/eos/eve/screen/page.c149
-rw-r--r--fw/fe310/eos/eve/screen/page.h17
-rw-r--r--fw/fe310/eos/eve/screen/uievt.h16
-rw-r--r--fw/fe310/eos/eve/screen/view.c9
-rw-r--r--fw/fe310/eos/eve/screen/view.h4
-rw-r--r--fw/fe310/eos/eve/widget/Makefile2
-rw-r--r--fw/fe310/eos/eve/widget/freew.c35
-rw-r--r--fw/fe310/eos/eve/widget/freew.h6
-rw-r--r--fw/fe310/eos/eve/widget/label.c7
-rw-r--r--fw/fe310/eos/eve/widget/label.h11
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c21
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h4
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c54
-rw-r--r--fw/fe310/eos/eve/widget/selectw.h14
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c16
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h11
-rw-r--r--fw/fe310/eos/eve/widget/strw.c41
-rw-r--r--fw/fe310/eos/eve/widget/strw.h7
-rw-r--r--fw/fe310/eos/eve/widget/textw.c57
-rw-r--r--fw/fe310/eos/eve/widget/textw.h6
-rw-r--r--fw/fe310/eos/eve/widget/togglew.c58
-rw-r--r--fw/fe310/eos/eve/widget/togglew.h21
-rw-r--r--fw/fe310/eos/eve/widget/widget.c63
-rw-r--r--fw/fe310/eos/eve/widget/widget.h32
-rw-r--r--fw/fe310/eos/eve/widget/widgets.c43
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h35
-rw-r--r--fw/fe310/eos/net/Makefile19
-rw-r--r--fw/fe310/eos/net/cell.c4
-rw-r--r--fw/fe310/eos/net/cell.h20
-rw-r--r--fw/fe310/eos/net/pwr.c69
-rw-r--r--fw/fe310/eos/net/pwr.h10
-rw-r--r--fw/fe310/eos/net/rng.c2
-rw-r--r--fw/fe310/eos/net/sock.c29
-rw-r--r--fw/fe310/eos/net/sock.h4
-rw-r--r--fw/fe310/eos/net/wifi.c113
-rw-r--r--fw/fe310/eos/net/wifi.h29
-rw-r--r--fw/fe310/eos/soc/Makefile20
-rw-r--r--fw/fe310/eos/soc/i2c.c12
-rw-r--r--fw/fe310/eos/soc/i2c.h6
-rw-r--r--fw/fe310/eos/soc/i2s.c217
-rw-r--r--fw/fe310/eos/soc/i2s.h4
-rw-r--r--fw/fe310/eos/soc/interrupt.h4
-rw-r--r--fw/fe310/eos/soc/pwr.c65
-rw-r--r--fw/fe310/eos/soc/pwr.h9
-rw-r--r--fw/fe310/eos/soc/spi.c48
-rw-r--r--fw/fe310/eos/soc/spi.h8
-rw-r--r--fw/fe310/eos/soc/spi_priv.h3
-rw-r--r--fw/fe310/eos/soc/trap_entry.S205
-rw-r--r--fw/fe310/eos/soc/uart.c31
-rw-r--r--fw/fe310/eos/soc/uart.h9
83 files changed, 1371 insertions, 1517 deletions
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index 7861810..e9c6421 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -1,7 +1,8 @@
include ../common.mk
-CFLAGS += -I. -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto
+CFLAGS += -I$(bsp_dir)/include
-obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o spi_dev.o lcd.o eve_eos.o sdcard.o sdc_crypto.o cam.o net.o rng.o wifi.o cell.o sock.o unicode.o
+obj = eos.o msgq.o event.o unicode.o
+lib = ../libeos.a
%.o: %.c %.h
@@ -10,7 +11,10 @@ obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o pwr.o i2s.o i2c.o ua
%.o: %.S
$(CC) $(CFLAGS) -c $<
-all: $(obj)
+all: $(lib)
+
+$(lib): $(obj)
+ $(AR) rcs $@ $(obj)
clean:
- rm -f *.o
+ rm -f *.o $(lib)
diff --git a/fw/fe310/eos/board.h b/fw/fe310/eos/board.h
index 99832a7..3891c61 100644
--- a/fw/fe310/eos/board.h
+++ b/fw/fe310/eos/board.h
@@ -5,30 +5,33 @@
#define SPI_CSID_NET 0
#define SPI_CSID_EVE 3
-#define SPI_CSID_SDC SPI_CSID_NONE
+#define SPI_CSID_SDC -1
#define SPI_CSID_CAM 2
-#define SPI_IOF_MASK ((1 << IOF_SPI1_SCK) | (1 << IOF_SPI1_MOSI) | (1 << IOF_SPI1_MISO) | (1 << IOF_SPI1_SS0) | (1 << IOF_SPI1_SS2) | (1 << IOF_SPI1_SS3))
-
-#define SPI_CSPIN_NET 2
-#define SPI_CSPIN_EVE 10
+#define SPI_CSPIN_NET -1
+#define SPI_CSPIN_EVE -1
#define SPI_CSPIN_SDC 0
-#define SPI_CSPIN_CAM 9
+#define SPI_CSPIN_CAM -1
+
+#define SPI_CSPIN_LCD 11
+
+#define SPI_IOF_MASK ((1 << IOF_SPI1_SCK) | (1 << IOF_SPI1_MOSI) | (1 << IOF_SPI1_MISO) | (1 << IOF_SPI1_SS0) | (1 << IOF_SPI1_SS2) | (1 << IOF_SPI1_SS3))
#define NET_PIN_RTS 20
#define NET_PIN_CTS 22
-#define LCD_PIN_CS 11
-
-#define EVE_PIN_INTR 23
+#define EVE_PIN_INTR 1
+//#define EVE_PIN_INTR 23
#define I2S_PIN_CK 1 /* PWM 0.1 */
#define I2S_PIN_CK_SW 21 /* PWM 1.2 */
#define I2S_PIN_CK_SR 18
#define I2S_PIN_WS_MIC 19 /* PWM 1.1 */
#define I2S_PIN_WS_SPK 11 /* PWM 2.1 */
-#define I2S_PIN_SD_IN 13
-#define I2S_PIN_SD_OUT 12
+#define I2S_PIN_SD_IN 17
+#define I2S_PIN_SD_OUT 16
+//#define I2S_PIN_SD_IN 13
+//#define I2S_PIN_SD_OUT 12
#define I2S_IRQ_WS_ID (INT_PWM2_BASE + 0)
#define I2S_IRQ_SD_ID (INT_PWM2_BASE + 3)
@@ -39,7 +42,8 @@
#define I2S_IDLE_CYCLES 1
-#define CTP_PIN_INT 1
+//#define CTP_PIN_INT 1
+#define CTP_PIN_INT 23
#define CTP_PIN_RST 19
#define EVE_GPIO_DIR 0xf
diff --git a/fw/fe310/eos/dev/Makefile b/fw/fe310/eos/dev/Makefile
index 83cb1f5..7407212 100644
--- a/fw/fe310/eos/dev/Makefile
+++ b/fw/fe310/eos/dev/Makefile
@@ -1,7 +1,8 @@
include ../../common.mk
-CFLAGS += -I$(bsp_dir)/include
+CFLAGS += -I$(bsp_dir)/include -I$(ext_dir)/crypto
-obj = bq25895.o ov2640.o gt911.o
+obj = spi.o net.o bq25895.o sdcard.o sdc_crypto.o eve.o ov2640.o cam.o
+lib = ../../libeos-dev.a
%.o: %.c %.h
@@ -10,7 +11,10 @@ obj = bq25895.o ov2640.o gt911.o
%.o: %.S
$(CC) $(CFLAGS) -c $<
-all: $(obj)
+all: $(lib)
+
+$(lib): $(obj)
+ $(AR) rcs $@ $(obj)
clean:
- rm -f *.o
+ rm -f *.o $(lib)
diff --git a/fw/fe310/eos/dev/bq25895.c b/fw/fe310/eos/dev/bq25895.c
index b290926..11323c7 100644
--- a/fw/fe310/eos/dev/bq25895.c
+++ b/fw/fe310/eos/dev/bq25895.c
@@ -3,8 +3,9 @@
#include <stdio.h>
#include "eos.h"
-#include "pwr.h"
-#include "i2c.h"
+#include "soc/pwr.h"
+#include "soc/i2c.h"
+
#include "bq25895.h"
static int reg_read(uint8_t reg, uint8_t *data) {
diff --git a/fw/fe310/eos/dev/cam.c b/fw/fe310/eos/dev/cam.c
index 43293af..50a0bdd 100644
--- a/fw/fe310/eos/dev/cam.c
+++ b/fw/fe310/eos/dev/cam.c
@@ -2,7 +2,9 @@
#include <stdint.h>
#include "eos.h"
-#include "spi.h"
+
+#include "soc/spi.h"
+
#include "cam.h"
const int _eos_cam_resolution[][2] = {
@@ -105,7 +107,7 @@ int eos_cam_capture_done(void) {
void eos_cam_capture_wait(void) {
int done = 0;
-
+
while (!done) {
done = eos_cam_capture_done();
}
@@ -113,7 +115,7 @@ void eos_cam_capture_wait(void) {
uint32_t eos_cam_fbuf_size(void) {
uint32_t ret;
-
+
ret = reg_read(CAM_REG_FIFO_SIZE1);
ret |= reg_read(CAM_REG_FIFO_SIZE2) << 8;
ret |= (reg_read(CAM_REG_FIFO_SIZE3) & 0x7f) << 16;
@@ -122,7 +124,7 @@ uint32_t eos_cam_fbuf_size(void) {
void eos_cam_fbuf_read(uint8_t *buffer, uint16_t sz, int first) {
int i;
-
+
eos_spi_cs_set();
eos_spi_xchg8(CAM_REG_READ_BURST, 0);
if (first) eos_spi_xchg8(0, 0);
diff --git a/fw/fe310/eos/eve_eos.c b/fw/fe310/eos/dev/eve.c
index 351cd79..0f98fed 100644
--- a/fw/fe310/eos/eve_eos.c
+++ b/fw/fe310/eos/dev/eve.c
@@ -4,35 +4,35 @@
#include "platform.h"
#include "eos.h"
-#include "interrupt.h"
#include "event.h"
-#include "pwr.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_eos.h"
-
-static int _run;
+#include "eve.h"
static void handle_time(unsigned char type) {
- if (_run) {
- eve_spi_start();
- eve_handle_time();
- eve_spi_stop();
- }
+ 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 (_run) {
- eve_spi_start();
- eve_handle_intr();
- eve_spi_stop();
+ if (!eos_eve_running()) return;
- GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
- }
+ eve_spi_start();
+ eve_handle_intr();
+ eve_spi_stop();
+
+ GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
}
static void handle_intr(void) {
@@ -41,38 +41,37 @@ static void handle_intr(void) {
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_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR);
-
GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR);
- _run = 1;
}
static void _stop(void) {
- _run = 0;
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, uint8_t gpio_dir, const uint32_t *touch_matrix) {
+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(gpio_dir);
- if (!rv) eve_touch_init_engine(touch_matrix);
+ rv = eve_init();
+ if (!rv) {
+ eve_gpio_set_dir(EVE_GPIO_DIR);
+ eve_touch_init_engine();
+ }
} else {
eve_activate();
}
@@ -91,7 +90,7 @@ int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, const uint32_t *touch_m
}
void eos_eve_calibrate(void) {
- uint32_t touch_matrix[6];
+ uint32_t matrix[6];
int r;
eve_spi_start();
@@ -114,17 +113,17 @@ void eos_eve_calibrate(void) {
eve_touch_set_extended(1);
eve_brightness(0);
- touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A);
- touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B);
- touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C);
- touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D);
- touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E);
- touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F);
-
+ 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", touch_matrix[0], touch_matrix[1], touch_matrix[2], touch_matrix[3], touch_matrix[4], touch_matrix[5]);
+ 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) {
@@ -147,3 +146,7 @@ void eos_eve_stop(void) {
_stop();
eve_spi_stop();
}
+
+int eos_eve_running(void) {
+ return !!(GPIO_REG(GPIO_INPUT_EN) & (1 << EVE_PIN_INTR));
+}
diff --git a/fw/fe310/eos/eve_eos.h b/fw/fe310/eos/dev/eve.h
index 47b326e..8eb982f 100644
--- a/fw/fe310/eos/eve_eos.h
+++ b/fw/fe310/eos/dev/eve.h
@@ -1,7 +1,9 @@
#include <stdint.h>
-int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, const uint32_t *touch_matrix);
+int eos_eve_init(uint8_t wakeup_cause);
void eos_eve_calibrate(void);
+void eos_eve_set_touch_matrix(const uint32_t *matrix);
int eos_eve_run(uint8_t wakeup_cause);
void eos_eve_start(void);
void eos_eve_stop(void);
+int eos_eve_running(void);
diff --git a/fw/fe310/eos/dev/lcd.c b/fw/fe310/eos/dev/lcd.c
deleted file mode 100644
index 3080a13..0000000
--- a/fw/fe310/eos/dev/lcd.c
+++ /dev/null
@@ -1,546 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "encoding.h"
-#include "platform.h"
-
-#include "eos.h"
-#include "timer.h"
-#include "i2s.h"
-#include "net.h"
-#include "spi_dev.h"
-#include "eve/eve.h"
-
-#include "board.h"
-
-#include "lcd.h"
-
-#define BIT_PUT(b, pin) if (b) GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << (pin)); else GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << (pin));
-#define BIT_GET(pin) ((GPIO_REG(GPIO_INPUT_VAL) & (1 << (pin))) >> (pin))
-
-#define SCK_UP { GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_SCK); }
-#define SCK_DN { GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << IOF_SPI1_SCK); }
-
-static inline void _sleep(int n) {
- volatile int x = n;
-
- while(x) x--;
-}
-
-int eos_lcd_select(void) {
- if (eos_i2s_running()) return EOS_ERR_BUSY;
- if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY;
-
- eos_net_stop();
-
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << LCD_PIN_CS);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << LCD_PIN_CS);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << LCD_PIN_CS);
-
- GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK;
-
- return EOS_OK;
-}
-
-void eos_lcd_deselect(void) {
- GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
- eos_net_start();
-}
-
-void eos_lcd_cs_set(void) {
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << LCD_PIN_CS);
-}
-
-void eos_lcd_cs_clear(void) {
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << LCD_PIN_CS);
-}
-
-/* sck frequency for r/w operations is 0.8Mhz */
-void eos_lcd_write(uint8_t dc, uint8_t data) {
- int i;
-
- BIT_PUT(dc, IOF_SPI1_MOSI);
- _sleep(10);
- SCK_UP;
- for (i=0; i<8; i++) {
- _sleep(10);
- SCK_DN;
- BIT_PUT(data & 0x80, IOF_SPI1_MOSI);
- _sleep(10);
- SCK_UP;
- data = data << 1;
- }
- _sleep(10);
- SCK_DN;
-}
-
-void eos_lcd_read(uint8_t *data) {
- int i;
-
- *data = 0;
- for (i=0; i<8; i++) {
- _sleep(10);
- *data = *data << 1;
- *data |= BIT_GET(IOF_SPI1_MISO);
- SCK_UP;
- _sleep(10);
- SCK_DN;
- }
-}
-
-static int _init(void) {
- int rv;
- uint8_t chip_id[3];
-
- rv = eos_lcd_select();
- if (rv) return rv;
- eos_lcd_cs_set();
-
- /* LCD Setting */
- eos_lcd_write(0, 0xFF); // change to Page 1 CMD
- eos_lcd_write(1, 0xFF);
- eos_lcd_write(1, 0x98);
- eos_lcd_write(1, 0x06);
- eos_lcd_write(1, 0x04);
- eos_lcd_write(1, 0x01);
-
- // eos_lcd_write(0, 0x08); // Output SDA
- // eos_lcd_write(1, 0x10);
-
- eos_lcd_write(0, 0xFE); // enable read
- eos_lcd_write(1, 0x81);
-
- eos_lcd_write(0, 0x00); // RDID4
- eos_lcd_read(&chip_id[0]);
-
- eos_lcd_write(0, 0x01);
- eos_lcd_read(&chip_id[1]);
-
- eos_lcd_write(0, 0x02);
- eos_lcd_read(&chip_id[2]);
-
- printf("LCD CHIP ID: %.2x%.2x%.2x\n", chip_id[0], chip_id[1], chip_id[2]);
-
- eos_lcd_write(0, 0xFE); // disable read
- eos_lcd_write(1, 0x00);
-
- if (memcmp(chip_id, "\x98\x06\x04", sizeof(chip_id))) {
- return EOS_ERR_ABSENT;
- }
-
- eos_lcd_write(0, 0x20); // set DE/VSYNC mode
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x21); // DE = 1 Active
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x30); // resolution setting 480 X 854
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x31); // inversion setting 2-dot
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x40); // BT AVDD,AVDD
- eos_lcd_write(1, 0x16);
-
- eos_lcd_write(0, 0x41);
- eos_lcd_write(1, 0x33); // 22
-
- eos_lcd_write(0, 0x42);
- eos_lcd_write(1, 0x03); // VGL=DDVDH+VCIP-DDVDL, VGH=2DDVDL-VCIP
-
- eos_lcd_write(0, 0x43);
- eos_lcd_write(1, 0x09); // set VGH clamp level
-
- eos_lcd_write(0, 0x44);
- eos_lcd_write(1, 0x06); // set VGL clamp level
-
- eos_lcd_write(0, 0x50); // VREG1
- eos_lcd_write(1, 0x88);
-
- eos_lcd_write(0, 0x51); // VREG2
- eos_lcd_write(1, 0x88);
-
- eos_lcd_write(0, 0x52); // flicker MSB
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x53); // flicker LSB
- eos_lcd_write(1, 0x49); // VCOM
-
- eos_lcd_write(0, 0x55); // flicker
- eos_lcd_write(1, 0x49);
-
- eos_lcd_write(0, 0x60);
- eos_lcd_write(1, 0x07);
-
- eos_lcd_write(0, 0x61);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x62);
- eos_lcd_write(1, 0x07);
-
- eos_lcd_write(0, 0x63);
- eos_lcd_write(1, 0x00);
-
- /* Gamma Setting */
- eos_lcd_write(0, 0xA0); // positive Gamma
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0xA1);
- eos_lcd_write(1, 0x09);
-
- eos_lcd_write(0, 0xA2);
- eos_lcd_write(1, 0x11);
-
- eos_lcd_write(0, 0xA3);
- eos_lcd_write(1, 0x0B);
-
- eos_lcd_write(0, 0xA4);
- eos_lcd_write(1, 0x05);
-
- eos_lcd_write(0, 0xA5);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0xA6);
- eos_lcd_write(1, 0x06);
-
- eos_lcd_write(0, 0xA7);
- eos_lcd_write(1, 0x04);
-
- eos_lcd_write(0, 0xA8);
- eos_lcd_write(1, 0x09);
-
- eos_lcd_write(0, 0xA9);
- eos_lcd_write(1, 0x0C);
-
- eos_lcd_write(0, 0xAA);
- eos_lcd_write(1, 0x15);
-
- eos_lcd_write(0, 0xAB);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0xAC);
- eos_lcd_write(1, 0x0F);
-
- eos_lcd_write(0, 0xAD);
- eos_lcd_write(1, 0x12);
-
- eos_lcd_write(0, 0xAE);
- eos_lcd_write(1, 0x09);
-
- eos_lcd_write(0, 0xAF);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0xC0); // negative Gamma
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0xC1);
- eos_lcd_write(1, 0x09);
-
- eos_lcd_write(0, 0xC2);
- eos_lcd_write(1, 0x10);
-
- eos_lcd_write(0, 0xC3);
- eos_lcd_write(1, 0x0C);
-
- eos_lcd_write(0, 0xC4);
- eos_lcd_write(1, 0x05);
-
- eos_lcd_write(0, 0xC5);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0xC6);
- eos_lcd_write(1, 0x06);
-
- eos_lcd_write(0, 0xC7);
- eos_lcd_write(1, 0x04);
-
- eos_lcd_write(0, 0xC8);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0xC9);
- eos_lcd_write(1, 0x0C);
-
- eos_lcd_write(0, 0xCA);
- eos_lcd_write(1, 0x14);
-
- eos_lcd_write(0, 0xCB);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0xCC);
- eos_lcd_write(1, 0x0F);
-
- eos_lcd_write(0, 0xCD);
- eos_lcd_write(1, 0x11);
-
- eos_lcd_write(0, 0xCE);
- eos_lcd_write(1, 0x09);
-
- eos_lcd_write(0, 0xCF);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0xFF); // change to Page 6 CMD for GIP timing
- eos_lcd_write(1, 0xFF);
- eos_lcd_write(1, 0x98);
- eos_lcd_write(1, 0x06);
- eos_lcd_write(1, 0x04);
- eos_lcd_write(1, 0x06);
-
- eos_lcd_write(0, 0x00);
- eos_lcd_write(1, 0x20);
-
- eos_lcd_write(0, 0x01);
- eos_lcd_write(1, 0x0A);
-
- eos_lcd_write(0, 0x02);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x03);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x04);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x05);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x06);
- eos_lcd_write(1, 0x98);
-
- eos_lcd_write(0, 0x07);
- eos_lcd_write(1, 0x06);
-
- eos_lcd_write(0, 0x08);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x09);
- eos_lcd_write(1, 0x80);
-
- eos_lcd_write(0, 0x0A);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x0B);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x0C);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x0D);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x0E);
- eos_lcd_write(1, 0x05);
-
- eos_lcd_write(0, 0x0F);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x10);
- eos_lcd_write(1, 0xF0);
-
- eos_lcd_write(0, 0x11);
- eos_lcd_write(1, 0xF4);
-
- eos_lcd_write(0, 0x12);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x13);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x14);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x15);
- eos_lcd_write(1, 0xC0);
-
- eos_lcd_write(0, 0x16);
- eos_lcd_write(1, 0x08);
-
- eos_lcd_write(0, 0x17);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x18);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x19);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x1A);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x1B);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x1C);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x1D);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x20);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x21);
- eos_lcd_write(1, 0x23);
-
- eos_lcd_write(0, 0x22);
- eos_lcd_write(1, 0x45);
-
- eos_lcd_write(0, 0x23);
- eos_lcd_write(1, 0x67);
-
- eos_lcd_write(0, 0x24);
- eos_lcd_write(1, 0x01);
-
- eos_lcd_write(0, 0x25);
- eos_lcd_write(1, 0x23);
-
- eos_lcd_write(0, 0x26);
- eos_lcd_write(1, 0x45);
-
- eos_lcd_write(0, 0x27);
- eos_lcd_write(1, 0x67);
-
- eos_lcd_write(0, 0x30);
- eos_lcd_write(1, 0x11);
-
- eos_lcd_write(0, 0x31);
- eos_lcd_write(1, 0x11);
-
- eos_lcd_write(0, 0x32);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x33);
- eos_lcd_write(1, 0xEE);
-
- eos_lcd_write(0, 0x34);
- eos_lcd_write(1, 0xFF);
-
- eos_lcd_write(0, 0x35);
- eos_lcd_write(1, 0xBB);
-
- eos_lcd_write(0, 0x36);
- eos_lcd_write(1, 0xAA);
-
- eos_lcd_write(0, 0x37);
- eos_lcd_write(1, 0xDD);
-
- eos_lcd_write(0, 0x38);
- eos_lcd_write(1, 0xCC);
-
- eos_lcd_write(0, 0x39);
- eos_lcd_write(1, 0x66);
-
- eos_lcd_write(0, 0x3A);
- eos_lcd_write(1, 0x77);
-
- eos_lcd_write(0, 0x3B);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x3C);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x3D);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x3E);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x3F);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x40);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0xFF); // change to Page 7 CMD for GIP timing
- eos_lcd_write(1, 0xFF);
- eos_lcd_write(1, 0x98);
- eos_lcd_write(1, 0x06);
- eos_lcd_write(1, 0x04);
- eos_lcd_write(1, 0x07);
-
- eos_lcd_write(0, 0x17);
- eos_lcd_write(1, 0x22);
-
- eos_lcd_write(0, 0x02);
- eos_lcd_write(1, 0x77);
-
- eos_lcd_write(0, 0x26);
- eos_lcd_write(1, 0xB2);
-
- eos_lcd_write(0, 0xFF); // change to Page 0 CMD for normal command
- eos_lcd_write(1, 0xFF);
- eos_lcd_write(1, 0x98);
- eos_lcd_write(1, 0x06);
- eos_lcd_write(1, 0x04);
- eos_lcd_write(1, 0x00);
-
- eos_lcd_write(0, 0x3A);
- eos_lcd_write(1, 0x70); // 24BIT
-
- eos_lcd_write(0, 0x11);
- eos_time_sleep(120);
- eos_lcd_write(0, 0x29);
- eos_time_sleep(25);
-
- eos_lcd_cs_clear();
- eos_lcd_deselect();
-
- return EOS_OK;
-}
-
-int eos_lcd_init(uint8_t wakeup_cause) {
- eos_spi_select(EOS_SPI_DEV_EVE);
- eve_gpio_set(EVE_GPIO_LCD_EN, 1);
- eos_spi_deselect();
- eos_time_sleep(200);
-
- return _init();
-}
-
-int eos_lcd_sleep(void) {
- int rv;
-
- rv = eos_lcd_select();
- if (rv) return rv;
-
- eos_lcd_cs_set();
-
- eos_lcd_write(0, 0x28);
- eos_time_sleep(10);
- eos_lcd_write(0, 0x10);
-
- eos_lcd_cs_clear();
- eos_lcd_deselect();
-
- eos_spi_select(EOS_SPI_DEV_EVE);
- eve_gpio_set(EVE_GPIO_LCD_EN, 0);
- eos_spi_deselect();
-
- return EOS_OK;
-}
-
-int eos_lcd_wake(void) {
- int rv;
-
- eos_spi_select(EOS_SPI_DEV_EVE);
- eve_gpio_set(EVE_GPIO_LCD_EN, 1);
- eos_spi_deselect();
- eos_time_sleep(200);
-
- rv = eos_lcd_select();
- if (rv) return rv;
-
- eos_lcd_cs_set();
-
- eos_lcd_write(0, 0x11);
- eos_time_sleep(120);
- eos_lcd_write(0, 0x29);
-
- eos_lcd_cs_clear();
- eos_lcd_deselect();
-
- return EOS_OK;
-}
diff --git a/fw/fe310/eos/dev/lcd.h b/fw/fe310/eos/dev/lcd.h
deleted file mode 100644
index 1bcb2cd..0000000
--- a/fw/fe310/eos/dev/lcd.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <stdint.h>
-
-int eos_lcd_init(uint8_t wakeup_cause);
-int eos_lcd_select(void);
-void eos_lcd_deselect(void);
-void eos_lcd_cs_set(void);
-void eos_lcd_cs_clear(void);
-void eos_lcd_write(uint8_t dc, uint8_t data);
-void eos_lcd_read(uint8_t *data);
-
-int eos_lcd_sleep(void);
-int eos_lcd_wake(void); \ No newline at end of file
diff --git a/fw/fe310/eos/soc/net.c b/fw/fe310/eos/dev/net.c
index 33b71c2..d287e5a 100644
--- a/fw/fe310/eos/soc/net.c
+++ b/fw/fe310/eos/dev/net.c
@@ -6,16 +6,17 @@
#include "eos.h"
#include "msgq.h"
-#include "interrupt.h"
#include "event.h"
-#include "timer.h"
-#include "pwr.h"
#include "board.h"
+#include "soc/interrupt.h"
+#include "soc/timer.h"
+#include "soc/pwr.h"
+#include "soc/spi.h"
+#include "soc/spi_priv.h"
+
#include "spi.h"
-#include "spi_priv.h"
-#include "spi_dev.h"
#include "net.h"
@@ -303,9 +304,8 @@ static void net_resume(void) {
}
static void net_start(void) {
+ eos_spi_dev_configure(EOS_SPI_DEV_NET);
eos_intr_set_handler(INT_SPI1_BASE, net_handle_xchg);
- SPI1_REG(SPI_REG_SCKDIV) = eos_spi_div(EOS_SPI_DEV_NET);
- SPI1_REG(SPI_REG_CSID) = eos_spi_csid(EOS_SPI_DEV_NET);
}
static void net_stop(void) {
@@ -328,14 +328,10 @@ int eos_net_init(uint8_t wakeup_cause) {
eos_evtq_set_handler(EOS_EVT_NET, net_handle_evt);
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_CTS);
- GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_CTS);
-
GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_CTS);
eos_intr_set(INT_GPIO_BASE + NET_PIN_CTS, IRQ_PRIORITY_NET_CTS, net_handle_cts);
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_RTS);
- GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_RTS);
-
GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_RTS);
GPIO_REG(GPIO_FALL_IE) |= (1 << NET_PIN_RTS);
eos_intr_set(INT_GPIO_BASE + NET_PIN_RTS, IRQ_PRIORITY_NET_RTS, net_handle_rts);
diff --git a/fw/fe310/eos/soc/net.h b/fw/fe310/eos/dev/net.h
index 79caf4b..2482a32 100644
--- a/fw/fe310/eos/soc/net.h
+++ b/fw/fe310/eos/dev/net.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#include "event.h"
+#include "../event.h"
/* common */
#define EOS_NET_MTU 1500
diff --git a/fw/fe310/eos/dev/ov2640.c b/fw/fe310/eos/dev/ov2640.c
index 6e54f10..e84a59b 100644
--- a/fw/fe310/eos/dev/ov2640.c
+++ b/fw/fe310/eos/dev/ov2640.c
@@ -3,10 +3,10 @@
#include <math.h>
#include "eos.h"
-#include "timer.h"
-#include "cam.h"
+#include "soc/timer.h"
+#include "soc/i2c.h"
-#include "i2c.h"
+#include "cam.h"
#include "ov2640_regs.h"
#include "ov2640.h"
diff --git a/fw/fe310/eos/dev/sdc_crypto.h b/fw/fe310/eos/dev/sdc_crypto.h
index 015bf8a..6442547 100644
--- a/fw/fe310/eos/dev/sdc_crypto.h
+++ b/fw/fe310/eos/dev/sdc_crypto.h
@@ -15,4 +15,4 @@ typedef struct EOSSDCCrypto {
void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eve_sdcc_init_t init, eve_sdcc_crypt_t enc, eve_sdcc_crypt_t dec, void *ctx_essiv, eve_sdcc_init_t init_essiv, eve_sdcc_essiv_t enc_essiv);
void eos_sdcc_encrypt(uint32_t sect, uint8_t *buffer);
-void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer); \ No newline at end of file
+void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer);
diff --git a/fw/fe310/eos/dev/sdcard.c b/fw/fe310/eos/dev/sdcard.c
index d081388..fa316c7 100644
--- a/fw/fe310/eos/dev/sdcard.c
+++ b/fw/fe310/eos/dev/sdcard.c
@@ -3,10 +3,10 @@
#include <stdio.h>
#include "eos.h"
-#include "timer.h"
+#include "soc/timer.h"
+#include "soc/spi.h"
#include "spi.h"
-#include "spi_dev.h"
#include "sdc_crypto.h"
#include "sdcard.h"
diff --git a/fw/fe310/eos/soc/spi_dev.c b/fw/fe310/eos/dev/spi.c
index c0c21b0..12549fc 100644
--- a/fw/fe310/eos/soc/spi_dev.c
+++ b/fw/fe310/eos/dev/spi.c
@@ -6,16 +6,17 @@
#include "eos.h"
#include "msgq.h"
-#include "interrupt.h"
#include "event.h"
#include "board.h"
+#include "soc/interrupt.h"
+#include "soc/spi.h"
+
#include "net.h"
+
#include "spi.h"
-#include "spi_priv.h"
#include "spi_cfg.h"
-#include "spi_dev.h"
static uint8_t spi_dev;
static uint8_t spi_lock;
@@ -26,10 +27,8 @@ int eos_spi_dev_init(uint8_t wakeup_cause) {
for (i=0; i<EOS_SPI_MAX_DEV; i++) {
spi_div[i] = spi_cfg[i].div;
- if (spi_cfg[i].cspin != SPI_CSPIN_NONE) {
+ if (!(spi_cfg[i].flags & SPI_DEV_FLAG_CSFLOAT) && (spi_cfg[i].cspin != -1)) {
GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << spi_cfg[i].cspin);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << spi_cfg[i].cspin);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << spi_cfg[i].cspin);
}
}
@@ -40,17 +39,26 @@ int eos_spi_dev_init(uint8_t wakeup_cause) {
int eos_spi_select(unsigned char dev) {
if (spi_lock) return EOS_ERR_BUSY;
- if (spi_dev == EOS_SPI_DEV_NET) {
- eos_net_stop();
+ if (spi_cfg[spi_dev].flags & SPI_DEV_FLAG_9BIT) {
+ eos_spi_enable();
} else {
- eos_spi_stop();
+ if (spi_dev == EOS_SPI_DEV_NET) {
+ eos_net_stop();
+ } else {
+ eos_spi_stop();
+ }
}
spi_dev = dev;
- if (dev == EOS_SPI_DEV_NET) {
- eos_net_start();
+ if (spi_cfg[dev].flags & SPI_DEV_FLAG_9BIT) {
+ eos_spi_configure(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt);
+ eos_spi_disable();
} else {
- eos_spi_start(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt);
+ if (dev == EOS_SPI_DEV_NET) {
+ eos_net_start();
+ } else {
+ eos_spi_start(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt);
+ }
}
return EOS_OK;
@@ -60,7 +68,11 @@ int eos_spi_deselect(void) {
if (spi_lock) return EOS_ERR_BUSY;
if (spi_dev == EOS_SPI_DEV_NET) return EOS_ERR;
- eos_spi_stop();
+ if (spi_cfg[spi_dev].flags & SPI_DEV_FLAG_9BIT) {
+ eos_spi_enable();
+ } else {
+ eos_spi_stop();
+ }
spi_dev = EOS_SPI_DEV_NET;
eos_net_start();
@@ -68,6 +80,10 @@ int eos_spi_deselect(void) {
return EOS_OK;
}
+void eos_spi_dev_configure(unsigned char dev) {
+ eos_spi_configure(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt);
+}
+
uint8_t eos_spi_dev(void) {
return spi_dev;
}
diff --git a/fw/fe310/eos/soc/spi_dev.h b/fw/fe310/eos/dev/spi.h
index e801f7e..c899e83 100644
--- a/fw/fe310/eos/soc/spi_dev.h
+++ b/fw/fe310/eos/dev/spi.h
@@ -4,10 +4,12 @@
#define EOS_SPI_DEV_EVE 1
#define EOS_SPI_DEV_SDC 2
#define EOS_SPI_DEV_CAM 3
+#define EOS_SPI_DEV_LCD 4
int eos_spi_dev_init(uint8_t wakeup_cause);
int eos_spi_select(unsigned char dev);
int eos_spi_deselect(void);
+void eos_spi_dev_configure(unsigned char dev);
uint8_t eos_spi_dev(void);
uint16_t eos_spi_div(unsigned char dev);
diff --git a/fw/fe310/eos/soc/spi_cfg.h b/fw/fe310/eos/dev/spi_cfg.h
index 84ab8bb..6a5d7b4 100644
--- a/fw/fe310/eos/soc/spi_cfg.h
+++ b/fw/fe310/eos/dev/spi_cfg.h
@@ -1,37 +1,52 @@
#include <stdint.h>
-#define EOS_SPI_MAX_DEV 4
+#define EOS_SPI_MAX_DEV 5
typedef struct {
uint16_t div;
- uint8_t csid;
- uint8_t cspin;
+ int8_t csid;
+ int8_t cspin;
+ uint8_t flags;
unsigned char evt;
} SPIConfig;
+#define SPI_DEV_FLAG_9BIT 0x1
+#define SPI_DEV_FLAG_CSFLOAT 0x2
+
static const SPIConfig spi_cfg[EOS_SPI_MAX_DEV] = {
{ // DEV_NET
.div = SPI_DIV_NET,
.csid = SPI_CSID_NET,
.cspin = SPI_CSPIN_NET,
+ .flags = 0,
.evt = 0, // Not SPI event
},
{ // DEV_EVE
.div = SPI_DIV_EVE,
.csid = SPI_CSID_EVE,
.cspin = SPI_CSPIN_EVE,
+ .flags = 0,
.evt = 0,
},
{ // DEV_SDC
.div = SPI_DIV_SDC,
.csid = SPI_CSID_SDC,
.cspin = SPI_CSPIN_SDC,
+ .flags = 0,
.evt = EOS_SPI_EVT_SDC,
},
{ // DEV_CAM
.div = SPI_DIV_CAM,
.csid = SPI_CSID_CAM,
.cspin = SPI_CSPIN_CAM,
+ .flags = 0,
.evt = EOS_SPI_EVT_CAM,
},
+ { // DEV_LCD 9bit spi
+ .div = 0,
+ .csid = -1,
+ .cspin = SPI_CSPIN_LCD,
+ .flags = SPI_DEV_FLAG_9BIT | SPI_DEV_FLAG_CSFLOAT,
+ .evt = 0,
+ },
};
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c
index 0260073..03609ae 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -1,30 +1,26 @@
#include <stdio.h>
#include "event.h"
-#include "interrupt.h"
-#include "timer.h"
-#include "pwr.h"
-#include "i2s.h"
-#include "i2c.h"
-#include "uart.h"
-#include "spi.h"
-#include "spi_dev.h"
-#include "lcd.h"
-#include "sdcard.h"
-#include "net.h"
-#include "wifi.h"
-#include "cell.h"
-#include "sock.h"
-#include "eve_eos.h"
-
-#include "eve/eve.h"
-#include "i2c/gt911.h"
-#include "i2c/bq25895.h"
-
-#include "board.h"
-#include "eos.h"
+#include "soc/interrupt.h"
+#include "soc/timer.h"
+#include "soc/pwr.h"
+#include "soc/i2s.h"
+#include "soc/i2c.h"
+#include "soc/uart.h"
+#include "soc/spi.h"
+
+#include "dev/spi.h"
+#include "dev/net.h"
+#include "dev/sdcard.h"
+#include "dev/bq25895.h"
+#include "dev/eve.h"
+
+#include "net/pwr.h"
+#include "net/wifi.h"
+#include "net/sock.h"
+#include "net/cell.h"
-extern const uint32_t _eos_touch_matrix[6];
+#include "eos.h"
void eos_init(void) {
uint8_t wakeup_cause = eos_pwr_wakeup_cause();
@@ -47,25 +43,18 @@ void eos_init(void) {
if (rv) printf("SPI INIT ERR:%d\n", rv);
rv = eos_spi_dev_init(wakeup_cause);
if (rv) printf("SPI DEV INIT ERR:%d\n", rv);
- rv = eos_sdc_init(wakeup_cause);
- if (rv) printf("SDC INIT ERR:%d\n", rv);
- rv = eos_net_init(wakeup_cause);
- if (rv) printf("NET INIT ERR:%d\n", rv);
- eos_i2c_start();
rv = eos_bq25895_init(wakeup_cause);
- eos_i2c_stop();
if (rv) printf("BQ25895 INIT ERR:%d\n", rv);
- rv = eos_eve_init(wakeup_cause, EVE_GPIO_DIR, _eos_touch_matrix);
- if (rv) printf("EVE INIT ERR:%d\n", rv);
+ rv = eos_net_init(wakeup_cause);
+ if (rv) printf("NET INIT ERR:%d\n", rv);
- rv = eos_lcd_init(wakeup_cause);
- if (rv == EOS_ERR_ABSENT) eve_lcd_absent();
- if (rv) printf("LCD INIT ERR:%d\n", rv);
+ rv = eos_sdc_init(wakeup_cause);
+ if (rv) printf("SDC INIT ERR:%d\n", rv);
- rv = eos_gt911_init(wakeup_cause);
- if (rv) printf("CTP INIT ERR:%d\n", rv);
+ rv = eos_eve_init(wakeup_cause);
+ if (rv) printf("EVE INIT ERR:%d\n", rv);
eos_run(wakeup_cause);
}
@@ -76,20 +65,14 @@ void eos_run(uint8_t wakeup_cause) {
rv = eos_eve_run(wakeup_cause);
if (rv) printf("EVE RUN ERR:%d\n", rv);
- eos_pwr_netinit();
- eos_wifi_netinit();
- eos_cell_netinit();
- eos_sock_netinit();
+ eos_pwr_net_init();
+ eos_wifi_init();
+ eos_sock_init();
+ eos_cell_init();
rv = eos_net_run(wakeup_cause);
if (rv) printf("NET RUN ERR:%d\n", rv);
}
void eos_run_once(void) {
- eos_i2c_start();
- eos_gt911_cfg_print();
- eos_gt911_set_threshold();
- eos_gt911_cfg_print();
- eos_i2c_stop();
-
eos_eve_calibrate();
}
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile
index 462891c..650bff8 100644
--- a/fw/fe310/eos/eve/Makefile
+++ b/fw/fe310/eos/eve/Makefile
@@ -1,7 +1,8 @@
include ../../common.mk
-CFLAGS += -I$(bsp_dir)/include
obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o
+subdirs = screen widget
+lib = ../../libeve.a
%.o: %.c %.h
@@ -10,7 +11,16 @@ obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o
%.o: %.S
$(CC) $(CFLAGS) -c $<
-all: $(obj)
+all: $(lib)
+
+$(lib): $(obj)
+ for i in $(subdirs); do \
+ (cd $$i && $(MAKE)) || exit; \
+ done
+ $(AR) rcs $@ $(obj) screen/*.o widget/*.o
clean:
- rm -f *.o
+ for i in $(subdirs); do \
+ (cd $$i && $(MAKE) clean) || exit; \
+ done
+ rm -f *.o $(lib)
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 02e0cae..5103e5f 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -311,7 +311,7 @@ void eve_handle_intr(void) {
if (intr_flags & (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)) eve_handle_touch(intr_flags);
}
-int eve_init(uint8_t gpio_dir) {
+int eve_init(void) {
uint8_t chipid = 0;
uint8_t reset = 0x07;
uint16_t timeout;
@@ -343,7 +343,7 @@ int eve_init(uint8_t gpio_dir) {
eve_write8(REG_PWM_DUTY, 0x00);
eve_write16(REG_GPIOX, 0x0000);
- eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f));
+ eve_write16(REG_GPIOX_DIR, 0x8000);
/* initialize display */
eve_write16(REG_HCYCLE, EVE_HCYCLE); /* total number of clocks per line, incl front/back porch */
@@ -363,7 +363,8 @@ int eve_init(uint8_t gpio_dir) {
/* do not set PCLK yet - wait for just after the first display list */
/* disable audio */
- eve_write16(REG_SOUND, 0x0000); /* set synthesizer to silence */
+ eve_write16(REG_SOUND, 0x0060); /* set synthesizer to mute */
+ eve_write8(REG_PLAY, 0x01);
eve_write8(REG_VOL_SOUND, 0x00); /* turn synthesizer volume off */
eve_write8(REG_VOL_PB, 0x00); /* turn recorded audio volume off */
diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h
index 6b31818..c1b91e4 100644
--- a/fw/fe310/eos/eve/eve.h
+++ b/fw/fe310/eos/eve/eve.h
@@ -58,7 +58,7 @@ void eve_cmd_burst_end(void);
void eve_handle_intr(void);
-int eve_init(uint8_t gpio_dir);
+int eve_init(void);
void eve_start(void);
void eve_stop(void);
void eve_start_clk(void);
diff --git a/fw/fe310/eos/eve/eve_config.h b/fw/fe310/eos/eve/eve_config.h
index b151c63..1126277 100755
--- a/fw/fe310/eos/eve/eve_config.h
+++ b/fw/fe310/eos/eve/eve_config.h
@@ -3,19 +3,20 @@
/* FocusLCDs E50RG84885LWAM520-CA */
-#define EVE_HLPW 20 /* horizontal low pulse width */
-#define EVE_HBP 60 /* horizontal back porch */
-#define EVE_HFP 40 /* horizontal front porch */
+#define EVE_HLPW 6 /* horizontal low pulse width */
+#define EVE_HBP 6 /* horizontal back porch */
+#define EVE_HFP 6 /* horizontal front porch */
#define EVE_HACT 480 /* horizontal active pixels */
#define EVE_HTOT (EVE_HLPW + EVE_HBP + EVE_HFP + EVE_HACT + 10)
-#define EVE_VLPW 26 /* vertical low pulse width */
-#define EVE_VBP 50 /* vertical back porch */
-#define EVE_VFP 30 /* vertical front porch */
+#define EVE_VLPW 6 /* vertical low pulse width */
+#define EVE_VBP 6 /* vertical back porch */
+#define EVE_VFP 6 /* vertical front porch */
#define EVE_VACT 854 /* vertical active pixels */
#define EVE_VTOT (EVE_VLPW + EVE_VBP + EVE_VFP + EVE_VACT + 10)
+
#define EVE_HCYCLE (EVE_HTOT) /* Th Total length of line (visible and non-visible) (in PCLKs) */
#define EVE_HSIZE (EVE_HACT) /* Length of visible part of line (in PCLKs) - display width */
#define EVE_HOFFSET (EVE_HFP + EVE_HLPW + EVE_HBP) /* Length of non-visible part of line (in PCLK cycles) */
@@ -32,7 +33,8 @@
#define EVE_SWIZZLE 0 /* Defines the arrangement of the RGB pins */
#define EVE_CSPREAD 0 /* helps with noise, when set to 1 fewer signals are changed simultaneously, reset-default: 1 */
-#define EVE_PCLK 2 /* 36 MHz */
+#define EVE_PCLK 1 /* Clock from EVE_PCLK_FREQ */
+#define EVE_PCLK_FREQ 27000000
#define EVE_GEN 4
diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c
index 09a86c6..cfddc80 100644
--- a/fw/fe310/eos/eve/eve_phy.c
+++ b/fw/fe310/eos/eve/eve_phy.c
@@ -9,14 +9,21 @@ void eve_phy_acc_init(EVEPhyAcc *param, int a) {
param->a = a;
}
-void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y) {
- double v0 = sqrt(v0x * v0x + v0y * v0y);
+int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y) {
+ double v0;
+ uint32_t dt = eve_get_tick() - t0;
+ v0 = sqrt(v0x * v0x + v0y * v0y);
+ param->k = 2 * v0 / param->a * EVE_RTC_FREQ;
+ if ((param->k < 0) && (dt >= -param->k / 2)) {
+ return 0;
+ }
param->x0 = x0;
param->y0 = y0;
param->v0x = v0x;
param->v0y = v0y;
- param->k = 2 * v0 / param->a * EVE_RTC_FREQ;
+
+ return 1;
}
int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y) {
@@ -60,6 +67,8 @@ void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint
int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0) {
param->x0 = x0;
param->y0 = y0;
+
+ return 1;
}
int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y) {
diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h
index 37d0221..e747b44 100644
--- a/fw/fe310/eos/eve/eve_phy.h
+++ b/fw/fe310/eos/eve/eve_phy.h
@@ -10,7 +10,7 @@ typedef struct EVEPhyAcc {
} EVEPhyAcc;
void eve_phy_acc_init(EVEPhyAcc *param, int a);
-void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y);
+int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y);
int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y);
typedef struct EVEPhyLHO {
diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h
index 9d472b5..29240d5 100644
--- a/fw/fe310/eos/eve/eve_platform.h
+++ b/fw/fe310/eos/eve/eve_platform.h
@@ -1,9 +1,9 @@
#include <stdint.h>
#include <stdlib.h>
-#include "timer.h"
-#include "spi.h"
-#include "spi_dev.h"
+#include "../soc/timer.h"
+#include "../soc/spi.h"
+#include "../dev/spi.h"
#define EVE_ETYPE_INTR 1
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index 0dc8b31..d17a509 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -128,10 +128,18 @@ void eve_handle_touch(uint16_t intr_flags) {
touch->tracker.tag = 0;
}
if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) {
- if (dx > EVE_TOUCH_THRESHOLD_X) {
- touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT;
+ int track_x = 0;
+
+ if ((dx > EVE_TOUCH_THRESHOLD_X) && (dx > EVE_TOUCH_THRESHOLD_Y) && ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY) == EVE_TOUCH_OPT_TRACK_XY)) {
+ if (dx > dy) {
+ track_x = 1;
+ }
+ } else if (dx > EVE_TOUCH_THRESHOLD_X) {
+ track_x = 1;
}
- if (dy > EVE_TOUCH_THRESHOLD_Y) {
+ if (track_x) {
+ touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT;
+ } else {
touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP;
}
touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
@@ -166,14 +174,18 @@ void eve_handle_touch(uint16_t intr_flags) {
eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS);
}
if (touch->tracker.tag && touch->tracker.track) {
+ int start = 0;
uint8_t opt = touch_tag_opt[touch->tracker.tag];
uint8_t track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) ||
((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y));
+
if (!eve_timer_get_evt(NULL) && track_ext) {
EVEVTrack *vtrack = eve_vtrack_get();
+ if (vtrack->start) start = vtrack->start(touch, vtrack->param);
+ }
+ if (start) {
eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK);
- if (vtrack->start) vtrack->start(touch, vtrack->param);
} else {
touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
}
@@ -372,6 +384,10 @@ void eve_timer_stop(void) {
if (touch_timer.touch == NULL) eve_timer_clear(NULL);
}
+int eve_timer_running(void) {
+ return (touch_timer.evt == EVE_TOUCH_ETYPE_TIMER);
+}
+
void eve_touch_clear_tag0(void) {
touch_tag0 = 0;
}
diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h
index e3e92b0..8ec6e0e 100644
--- a/fw/fe310/eos/eve/eve_touch.h
+++ b/fw/fe310/eos/eve/eve_touch.h
@@ -118,4 +118,5 @@ EVETouchTimer *eve_timer_get_obj(void);
void eve_timer_start(uint8_t tag0, uint32_t to);
void eve_timer_stop(void);
+int eve_timer_running(void);
void eve_touch_clear_tag0(void);
diff --git a/fw/fe310/eos/eve/eve_touch_engine.c b/fw/fe310/eos/eve/eve_touch_engine.c
new file mode 100644
index 0000000..2c75ca0
--- /dev/null
+++ b/fw/fe310/eos/eve/eve_touch_engine.c
@@ -0,0 +1,119 @@
+#include <stdlib.h>
+
+#include "eve.h"
+#include "eve_touch_engine.h"
+
+static const uint32_t _reg_touch[] = {
+ REG_CTOUCH_TOUCH0_XY,
+ REG_CTOUCH_TOUCH1_XY,
+ REG_CTOUCH_TOUCH2_XY,
+ REG_CTOUCH_TOUCH3_XY
+};
+
+static const uint32_t _reg_tag[] = {
+ REG_TOUCH_TAG,
+ REG_TOUCH_TAG1,
+ REG_TOUCH_TAG2,
+ REG_TOUCH_TAG3,
+ REG_TOUCH_TAG4
+};
+
+static const uint32_t _reg_track[] = {
+ REG_TRACKER,
+ REG_TRACKER_1,
+ REG_TRACKER_2,
+ REG_TRACKER_3,
+ REG_TRACKER_4
+};
+
+void eve_touch_init_engine(void) {
+ /* configure touch */
+ eve_write8(REG_CPURESET, 2); /* touch engine reset */
+ eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */
+ eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */
+ eve_write8(REG_CPURESET, 0); /* clear reset */
+
+ eve_touch_ehost_enter(0, 0x8000, 0x8000);
+ eve_touch_ehost_end();
+}
+
+void eve_touch_start(void) {
+ uint16_t intr_mask;
+
+ intr_mask = eve_read16(REG_INT_MASK);
+ eve_write16(REG_INT_MASK, intr_mask | (EVE_INT_CONVCOMPLETE | EVE_INT_TAG));
+
+ eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS);
+}
+
+void eve_touch_stop(void) {
+ uint16_t intr_mask;
+
+ intr_mask = eve_read16(REG_INT_MASK);
+ eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_CONVCOMPLETE | EVE_INT_TAG));
+ eve_timer_clear(NULL);
+
+ eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF);
+}
+
+void eve_touch_set_extended(int extended) {
+ eve_write8(REG_CPURESET, 2); /* touch engine reset */
+ eve_write8(REG_CTOUCH_EXTENDED, !extended); /* set / clear extended mode */
+ eve_write8(REG_CPURESET, 0); /* clear reset */
+}
+
+void eve_touch_get_matrix(uint32_t *touch_matrix) {
+ touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A);
+ touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B);
+ touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C);
+ touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D);
+ touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E);
+ touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F);
+}
+
+void eve_touch_set_matrix(const uint32_t *touch_matrix) {
+ eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]);
+ eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]);
+ eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]);
+ eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]);
+ eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]);
+ eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]);
+}
+
+uint32_t eve_touch_reg_xy(int i) {
+ uint32_t touch_xy;
+
+ touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y));
+ return touch_xy;
+}
+
+uint8_t eve_touch_reg_tag(int i) {
+ uint8_t touch_tag;
+
+ touch_tag = eve_read8(_reg_tag[i]);
+ return touch_tag;
+}
+
+uint32_t eve_touch_reg_track(int i) {
+ uint32_t touch_track;
+
+ touch_track = eve_read32(_reg_track[i]);
+ return touch_track;
+}
+
+int eve_touch_ehost_ready(void) {
+ uint8_t ack;
+
+ ack = eve_read8(REG_EHOST_TOUCH_ACK);
+ return (ack == 1);
+}
+
+void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y) {
+ eve_write16(REG_EHOST_TOUCH_X, x);
+ eve_write16(REG_EHOST_TOUCH_Y, y);
+ eve_write8(REG_EHOST_TOUCH_ID, id);
+}
+
+void eve_touch_ehost_end(void) {
+ eve_write8(REG_EHOST_TOUCH_ID, 0xf);
+}
diff --git a/fw/fe310/eos/eve/eve_touch_engine.h b/fw/fe310/eos/eve/eve_touch_engine.h
new file mode 100644
index 0000000..3a7508f
--- /dev/null
+++ b/fw/fe310/eos/eve/eve_touch_engine.h
@@ -0,0 +1,17 @@
+#include <stdint.h>
+
+void eve_touch_init_engine(void);
+void eve_touch_start(void);
+void eve_touch_stop(void);
+
+void eve_touch_set_extended(int extended);
+void eve_touch_get_matrix(uint32_t *touch_matrix);
+void eve_touch_set_matrix(const uint32_t *touch_matrix);
+
+int eve_touch_ehost_ready(void);
+void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y);
+void eve_touch_ehost_end(void);
+
+uint32_t eve_touch_reg_xy(int i);
+uint8_t eve_touch_reg_tag(int i);
+uint32_t eve_touch_reg_track(int i);
diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c
index bd9158b..a7619fb 100644
--- a/fw/fe310/eos/eve/eve_vtrack.c
+++ b/fw/fe310/eos/eve/eve_vtrack.c
@@ -26,9 +26,16 @@ void eve_vtrack_reset(void) {
eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &vtrack_acc);
}
-void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) {
- eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to);
- if (vtrack.start) vtrack.start(touch, vtrack.param);
+int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) {
+ if (vtrack.start) {
+ int start;
+
+ start = vtrack.start(touch, vtrack.param);
+ if (start) eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to);
+
+ return start;
+ }
+ return 0;
}
void eve_vtrack_stop(EVETouch *touch) {
@@ -36,9 +43,10 @@ void eve_vtrack_stop(EVETouch *touch) {
eve_vtrack_reset();
}
-void eve_vtrack_acc_start(EVETouch *touch, void *p) {
+int eve_vtrack_acc_start(EVETouch *touch, void *p) {
EVEPhyAcc *param = (EVEPhyAcc *)p;
- eve_phy_acc_start(param, touch->x, touch->y, touch->vx, touch->vy);
+
+ return eve_phy_acc_start(param, touch->x, touch->y, touch->t, touch->vx, touch->vy);
}
int eve_vtrack_acc_tick(EVETouch *touch, void *p) {
@@ -46,19 +54,3 @@ int eve_vtrack_acc_tick(EVETouch *touch, void *p) {
return eve_phy_acc_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y);
}
-
-void eve_vtrack_lho_start(EVETouch *touch, void *p) {
- EVEPhyLHO *param = (EVEPhyLHO *)p;
-
- eve_phy_lho_start(param, touch->x, touch->y);
-}
-
-int eve_vtrack_lho_tick(EVETouch *touch, void *p) {
- EVEPhyLHO *param = (EVEPhyLHO *)p;
-
- return eve_phy_lho_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y);
-}
-
-void eve_vtrack_lho_stop(EVETouch *touch, void *p) {
- eve_vtrack_reset();
-}
diff --git a/fw/fe310/eos/eve/eve_vtrack.h b/fw/fe310/eos/eve/eve_vtrack.h
index fa7e7b7..8455502 100644
--- a/fw/fe310/eos/eve/eve_vtrack.h
+++ b/fw/fe310/eos/eve/eve_vtrack.h
@@ -2,7 +2,7 @@
#define EVE_VTRACK_ACC_A 10000
-typedef void (*eve_vtrack_start_t) (EVETouch *, void *);
+typedef int (*eve_vtrack_start_t) (EVETouch *, void *);
typedef int (*eve_vtrack_tick_t) (EVETouch *, void *);
typedef void (*eve_vtrack_stop_t) (EVETouch *, void *);
@@ -17,12 +17,8 @@ void eve_vtrack_init(void);
EVEVTrack *eve_vtrack_get(void);
void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param);
void eve_vtrack_reset(void);
-void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to);
+int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to);
void eve_vtrack_stop(EVETouch *touch);
-void eve_vtrack_acc_start(EVETouch *touch, void *p);
-int eve_vtrack_acc_tick(EVETouch *touch, void *p);
-
-void eve_vtrack_lho_start(EVETouch *touch, void *p);
-int eve_vtrack_lho_tick(EVETouch *touch, void *p);
-void eve_vtrack_lho_stop(EVETouch *touch, void *p);
+int eve_vtrack_acc_start(EVETouch *touch, void *p);
+int eve_vtrack_acc_tick(EVETouch *touch, void *p); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c
index 8555158..13021a0 100644
--- a/fw/fe310/eos/eve/screen/form.c
+++ b/fw/fe310/eos/eve/screen/form.c
@@ -9,8 +9,6 @@
#include "page.h"
#include "form.h"
-#include "widget/widgets.h"
-
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -57,7 +55,7 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) {
}
}
-EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) {
+EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) {
EVEWidget *widgets;
EVEWidget *widget;
EVELabel *label;
@@ -65,17 +63,17 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s
int w_size = 0;
int i, r;
- for (i=0; i<spec_size; i++) {
- w_size += eve_widget_size(spec[i].widget.type);
- }
+ if (uievt == NULL) uievt = eve_form_uievt;
+ if (destructor == NULL) destructor = eve_form_destroy;
form = eve_malloc(sizeof(EVEForm));
if (form == NULL) {
return NULL;
}
- if (uievt == NULL) uievt = eve_form_uievt;
- if (destructor == NULL) destructor = eve_form_destroy;
eve_form_init(form, window, stack, NULL, 0, uievt, action, destructor);
+ for (i=0; i<spec_size; i++) {
+ w_size += eve_widget_size(spec[i].widget.type);
+ }
widgets = eve_malloc(w_size);
if (widgets == NULL) {
eve_free(form);
@@ -84,7 +82,7 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s
widget = widgets;
for (i=0; i<spec_size; i++) {
- r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, (EVEPage *)form, &spec[i].widget.spec);
+ r = eve_widget_create(widget, &spec[i].widget, (EVEPage *)form);
if (r) {
widgets_destroy(widgets, i);
eve_free(widgets);
@@ -92,7 +90,6 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s
return NULL;
}
if (spec[i].label.title) {
- EVEFont *font = spec[i].label.font ? spec[i].label.font : eve_window_font(window);
label = eve_malloc(sizeof(EVELabel));
if (label == NULL) {
eve_widget_destroy(widget);
@@ -101,15 +98,13 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s
eve_free(form);
return NULL;
}
- eve_label_init(label, &spec[i].label.g, font, spec[i].label.title);
+ eve_label_create(label, &spec[i].label, (EVEPage *)form);
eve_widget_set_label(widget, label);
- if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title);
}
- if (widget->label && (widget->label->g.w == 0)) eve_font_str_w(label->font, label->title) + EVE_FORM_LABEL_MARGIN;
if (widget->g.w == 0) widget->g.w = window->g.w - (widget->label ? widget->label->g.w : 0);
widget = eve_widget_next(widget);
}
- eve_form_update(form, widgets, spec_size);
+ eve_form_set_widget(form, widgets, spec_size);
return form;
}
@@ -118,11 +113,11 @@ void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWid
memset(form, 0, sizeof(EVEForm));
eve_page_init(&form->p, window, stack, NULL, 0, EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_BACK | EVE_PAGE_OPT_TRACK_EXT_Y, eve_page_draw, eve_page_touch, (eve_view_uievt_t)uievt, (eve_page_destructor_t)destructor);
form->action = action;
- eve_form_update(form, widget, widget_size);
+ eve_form_set_widget(form, widget, widget_size);
}
-void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size) {
- eve_page_update((EVEPage *)form, widget, widget_size);
+void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size) {
+ eve_page_set_widget((EVEPage *)form, widget, widget_size);
form_update_g(form, NULL);
}
@@ -138,25 +133,24 @@ int eve_form_uievt(EVEForm *form, uint16_t evt, void *param) {
form_update_g(form, (EVEWidget *)param);
break;
- case EVE_UIEVT_PAGE_SCROLL_START:
+ case EVE_UIEVT_GEST_SCROLL_START:
break;
- case EVE_UIEVT_PAGE_SCROLL_STOP:
+ case EVE_UIEVT_GEST_SCROLL_STOP:
break;
- case EVE_UIEVT_PAGE_TRACK_START:
+ case EVE_UIEVT_GEST_TRACK_START:
break;
- case EVE_UIEVT_PAGE_TRACK_STOP: {
+ case EVE_UIEVT_GEST_TRACK_STOP: {
EVEUIEvtTouch *touch_p = (EVEUIEvtTouch *)param;
- if (touch_p->evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) {
- eve_page_close((EVEPage *)form);
- return 1;
- }
- if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) {
- if (form->action) form->action(form);
- }
+
+ if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) {
+ eve_page_close((EVEPage *)form);
+ return 1;
+ }
+ if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) {
+ if (form->action) form->action(form);
}
break;
}
diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h
index 272b6ed..62e10f7 100644
--- a/fw/fe310/eos/eve/screen/form.h
+++ b/fw/fe310/eos/eve/screen/form.h
@@ -1,10 +1,10 @@
#include <stdint.h>
-#define EVE_FORM_LABEL_MARGIN 10
+#include "../widget/widget.h"
struct EVEWidget;
-struct EVEWidgetSpec;
struct EVEForm;
+struct EVEFormSpec;
typedef int (*eve_form_uievt_t) (struct EVEForm *, uint16_t, void *);
typedef void (*eve_form_action_t) (struct EVEForm *);
@@ -15,9 +15,15 @@ typedef struct EVEForm {
eve_form_action_t action;
} EVEForm;
-EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, struct EVEWidgetSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor);
-void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor);
-void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size);
+typedef struct EVEFormSpec {
+ EVELabelSpec label;
+ EVEWidgetSpec widget;
+} EVEFormSpec;
+
+EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor);
+void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor);
+void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size);
void eve_form_destroy(EVEForm *form);
int eve_form_uievt(EVEForm *form, uint16_t evt, void *param);
+
diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c
index 28526ca..64fc473 100644
--- a/fw/fe310/eos/eve/screen/page.c
+++ b/fw/fe310/eos/eve/screen/page.c
@@ -8,7 +8,6 @@
#include "window.h"
#include "page.h"
-#include "widget/label.h"
#include "widget/widget.h"
#define PAGE_TMODE_NONE 0
@@ -21,10 +20,22 @@ void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWid
page->stack = stack;
page->opt = opt;
page->destructor = destructor;
- eve_page_update(page, widget, widget_size);
+ eve_page_set_widget(page, widget, widget_size);
}
-void eve_page_update(EVEPage *page, EVEWidget *widget, uint16_t widget_size) {
+EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) {
+ EVEWidget *w = page->widget;
+ int i;
+
+ if (idx >= page->widget_size) return NULL;
+
+ for (i=0; i<idx; i++) {
+ w = eve_widget_next(w);
+ }
+ return w;
+}
+
+void eve_page_set_widget(EVEPage *page, EVEWidget *widget, uint16_t widget_size) {
page->widget = widget;
page->widget_size = widget_size;
}
@@ -45,16 +56,16 @@ void eve_page_close(EVEPage *page) {
if (stack->level <= 1) return;
- if (page->lho_t0) {
- page->lho_t0 = 0;
+ if (eve_timer_running()) {
eve_timer_stop();
}
if (eve_window_scroll(window->root, NULL) == window) {
eve_window_scroll_stop(window);
}
- if (destructor) destructor(page);
eve_window_kbd_detach(window);
+
+ if (destructor) destructor(page);
eve_view_destroy(window, stack);
}
@@ -93,30 +104,32 @@ int eve_page_rect_visible(EVEPage *page, EVERect *g) {
return 0;
}
-void eve_page_focus(EVEPage *page, EVERect *rect) {
- if (rect) {
- EVERect g;
+void eve_page_rect_set_visible(EVEPage *page, EVERect *rect) {
+ EVERect g;
- eve_window_visible_g(page->v.window, &g);
- g.x -= page->v.window->g.x;
- g.y -= page->v.window->g.y;
+ eve_window_visible_g(page->v.window, &g);
+ g.x -= page->v.window->g.x;
+ g.y -= page->v.window->g.y;
- if (rect->x < page->g.x + g.x) {
- page->g.x = rect->x - g.x;
- }
- if (rect->y < page->g.y + g.y) {
- page->g.y = rect->y - g.y;
- }
- if ((rect->x + rect->w) > (page->g.x + g.x + g.w)) {
- page->g.x = (rect->x + rect->w) - (g.x + g.w);
- }
- if ((rect->y + rect->h) > (page->g.y + g.y + g.h)) {
- page->g.y = (rect->y + rect->h) - (g.y + g.h);
- }
+ if (rect->x < page->g.x + g.x) {
+ page->g.x = rect->x - g.x;
+ }
+ if (rect->y < page->g.y + g.y) {
+ page->g.y = rect->y - g.y;
+ }
+ if ((rect->x + rect->w) > (page->g.x + g.x + g.w)) {
+ page->g.x = (rect->x + rect->w) - (g.x + g.w);
}
+ if ((rect->y + rect->h) > (page->g.y + g.y + g.h)) {
+ page->g.y = (rect->y + rect->h) - (g.y + g.h);
+ }
+}
+
+EVEWidget *eve_page_focus(EVEPage *page) {
+ return page->widget_f;
}
-void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) {
+void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *rect) {
if (page->widget_f != widget) {
EVEWindow *window = page->v.window;
EVEWidget *widget_f = page->widget_f;
@@ -131,67 +144,59 @@ void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) {
if (kbd) eve_kbd_set_handler(kbd, widget->putc, widget);
if (!(widget_f && widget_f->putc)) eve_window_kbd_attach(window);
}
+ if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_OUT, page->widget_f);
page->widget_f = widget;
+ if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_IN, page->widget_f);
}
- if (rect) eve_page_focus(page, rect);
+ if (rect) eve_page_rect_set_visible(page, rect);
}
-EVEWidget *eve_page_focus_widget_get(EVEPage *page) {
- return page->widget_f;
-}
-
-EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) {
- EVEWidget *w = page->widget;
- int i;
-
- if (idx >= page->widget_size) return NULL;
-
- for (i=0; i<idx; i++) {
- w = eve_widget_next(w);
- }
- return w;
-}
+#include <stdio.h>
static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0) {
EVEView *view = &page->v;
EVEWindow *window = view->window;
- int scroll, scroll_x, scroll_y;
+ int scroll_x = 0, scroll_y = 0, scroll;
int ret = 0;
- scroll_x = page->opt & (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_XY);
- if (scroll_x && touch) scroll_x = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_X);
-
- scroll_y = page->opt & (EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_XY);
- if (scroll_y && touch) scroll_y = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_Y);
+ if (touch) {
+ if ((page->opt & EVE_PAGE_OPT_SCROLL_XY) == EVE_PAGE_OPT_SCROLL_XY) {
+ scroll_x = scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY);
+ } else if (page->opt & EVE_PAGE_OPT_SCROLL_X) {
+ scroll_x = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X);
+ } else if (page->opt & EVE_PAGE_OPT_SCROLL_Y) {
+ scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y);
+ }
+ }
scroll = scroll_x || scroll_y;
if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) {
int _ret = 0;
- if (page->widget_f) eve_page_focus_widget(page, NULL, NULL);
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TOUCH, touch, evt, tag0);
+ if (page->widget_f) eve_page_set_focus(page, NULL, NULL);
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TOUCH, touch, evt, tag0);
if (_ret) return _ret;
ret = 1;
}
- /* Scroll start */
+ /* Scroll / track start */
if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && !(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) {
int _ret = 0;
if (scroll) {
page->track_mode = PAGE_TMODE_SCROLL;
eve_window_scroll_start(window, touch->tracker.tag);
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_START, touch, evt, tag0);
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_START, touch, evt, tag0);
} else {
page->track_mode = PAGE_TMODE_TRACK;
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TRACK_START, touch, evt, tag0);
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_START, touch, evt, tag0);
}
if (_ret) return _ret;
ret = 1;
}
- /* Scroll stop */
+ /* Scroll / track stop */
if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) ||
((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) {
if ((page->track_mode == PAGE_TMODE_SCROLL) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) {
@@ -211,23 +216,29 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
eve_window_scroll(window->root, &_tag);
- eve_phy_lho_init(lho, lho_x, lho_y, 1000, 0.5, 0);
- eve_phy_lho_start(lho, page->g.x, page->g.y);
page->lho_t0 = eve_get_tick();
+ eve_phy_lho_init(lho, lho_x, lho_y, 100, 0.5, 0);
+ eve_phy_lho_start(lho, page->g.x, page->g.y);
eve_timer_start(_tag, 20);
}
}
- if (!page->lho_t0) {
+ if (!eve_timer_running()) {
int _ret = 0;
- if (page->track_mode == PAGE_TMODE_SCROLL) {
- page->track_mode = PAGE_TMODE_NONE;
- eve_window_scroll_stop(window);
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0);
- } else if (!(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) {
- page->track_mode = PAGE_TMODE_NONE;
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TRACK_STOP, touch, evt, tag0);
+ switch (page->track_mode) {
+ case PAGE_TMODE_SCROLL: {
+ page->track_mode = PAGE_TMODE_NONE;
+ eve_window_scroll_stop(window);
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0);
+ break;
+ }
+
+ case PAGE_TMODE_TRACK: {
+ page->track_mode = PAGE_TMODE_NONE;
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_STOP, touch, evt, tag0);
+ break;
+ }
}
if (_ret) return _ret;
ret = 1;
@@ -254,26 +265,26 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0
}
if ((evt & EVE_TOUCH_ETYPE_TIMER) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) {
EVEPhyLHO *lho = &page->lho;
+ int scroll_x = page->opt & EVE_PAGE_OPT_SCROLL_X;
+ int scroll_y = page->opt & EVE_PAGE_OPT_SCROLL_Y;
int x, y, more;
more = eve_phy_lho_tick(lho, eve_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL);
if (scroll_x) page->g.x = x;
if (scroll_y) page->g.y = y;
+ printf("TIMER: %d\n", y);
if (!more) {
int _ret = 0;
- page->lho_t0 = 0;
- eve_timer_stop();
+ printf("TIMER STOP!\n");
page->track_mode = PAGE_TMODE_NONE;
+ eve_timer_stop();
eve_window_scroll_stop(window);
- _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0);
+ _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0);
if (_ret) return _ret;
}
ret = 1;
}
- if (evt & EVE_TOUCH_EETYPE_TIMER_ABORT) {
- page->lho_t0 = 0;
- }
}
return ret;
diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h
index 0fc9809..7aa8c1d 100644
--- a/fw/fe310/eos/eve/screen/page.h
+++ b/fw/fe310/eos/eve/screen/page.h
@@ -5,10 +5,11 @@
#define EVE_PAGE_OPT_SCROLL_X 0x01
#define EVE_PAGE_OPT_SCROLL_Y 0x02
#define EVE_PAGE_OPT_SCROLL_BACK 0x04
-#define EVE_PAGE_OPT_SCROLL_XY 0x08
#define EVE_PAGE_OPT_TRACK_EXT_X 0x10
#define EVE_PAGE_OPT_TRACK_EXT_Y 0x20
-#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y)
+
+#define EVE_PAGE_OPT_SCROLL_XY (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_Y)
+#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y)
struct EVEWidget;
struct EVEPage;
@@ -32,7 +33,10 @@ typedef struct EVEPage {
} EVEPage;
void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, uint8_t opt,eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor);
-void eve_page_update(EVEPage *page, struct EVEWidget *widget, uint16_t widget_size);
+
+struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx);
+void eve_page_set_widget(EVEPage *page, struct EVEWidget *widget, uint16_t widget_size);
+
void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor);
void eve_page_close(EVEPage *page);
@@ -46,11 +50,10 @@ int16_t eve_page_win_y(EVEPage *page, int16_t y);
int16_t eve_page_scr_x(EVEPage *page, int16_t x);
int16_t eve_page_scr_y(EVEPage *page, int16_t y);
int eve_page_rect_visible(EVEPage *page, EVERect *g);
+void eve_page_rect_set_visible(EVEPage *page, EVERect *rect);
-void eve_page_focus(EVEPage *page, EVERect *rect);
-void eve_page_focus_widget(EVEPage *page, struct EVEWidget *widget, EVERect *rect);
-struct EVEWidget *eve_page_focus_widget_get(EVEPage *page);
-struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx);
+struct EVEWidget *eve_page_focus(EVEPage *page);
+void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *rect);
uint8_t eve_page_draw(EVEView *view, uint8_t tag0);
int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/screen/uievt.h b/fw/fe310/eos/eve/screen/uievt.h
index 98f0d95..8e1e682 100644
--- a/fw/fe310/eos/eve/screen/uievt.h
+++ b/fw/fe310/eos/eve/screen/uievt.h
@@ -1,11 +1,13 @@
-#define EVE_UIEVT_WIN_UPDATE_G 1
-#define EVE_UIEVT_PAGE_UPDATE_G 2
-#define EVE_UIEVT_PAGE_TOUCH 3
-#define EVE_UIEVT_PAGE_SCROLL_START 4
-#define EVE_UIEVT_PAGE_SCROLL_STOP 5
-#define EVE_UIEVT_PAGE_TRACK_START 6
-#define EVE_UIEVT_PAGE_TRACK_STOP 7
+#define EVE_UIEVT_GEST_TOUCH 1
+#define EVE_UIEVT_GEST_SCROLL_START 2
+#define EVE_UIEVT_GEST_SCROLL_STOP 3
+#define EVE_UIEVT_GEST_TRACK_START 4
+#define EVE_UIEVT_GEST_TRACK_STOP 5
+#define EVE_UIEVT_WIN_UPDATE_G 6
+#define EVE_UIEVT_PAGE_UPDATE_G 7
#define EVE_UIEVT_WIDGET_UPDATE_G 8
+#define EVE_UIEVT_WIDGET_FOCUS_IN 9
+#define EVE_UIEVT_WIDGET_FOCUS_OUT 10
typedef struct EVEUIEvtTouch {
EVETouch *touch;
diff --git a/fw/fe310/eos/eve/screen/view.c b/fw/fe310/eos/eve/screen/view.c
index ac9aef4..466644d 100644
--- a/fw/fe310/eos/eve/screen/view.c
+++ b/fw/fe310/eos/eve/screen/view.c
@@ -77,18 +77,19 @@ void eve_view_destroy(EVEWindow *window, EVEViewStack *stack) {
}
}
-void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) {
- if (view->uievt) view->uievt(view, evt, param);
+int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) {
+ if (view->uievt) return view->uievt(view, evt, param);
+ return 0;
}
-int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) {
+int eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) {
if (view->uievt) {
EVEUIEvtTouch param;
param.touch = touch;
param.evt = t_evt;
param.tag0 = tag0;
- view->uievt(view, evt, &param);
+ return view->uievt(view, evt, &param);
}
return 0;
}
diff --git a/fw/fe310/eos/eve/screen/view.h b/fw/fe310/eos/eve/screen/view.h
index 65999d7..c8be33a 100644
--- a/fw/fe310/eos/eve/screen/view.h
+++ b/fw/fe310/eos/eve/screen/view.h
@@ -38,5 +38,5 @@ void eve_view_stack_init(EVEViewStack *stack);
void eve_view_create(struct EVEWindow *window, EVEViewStack *stack, eve_view_constructor_t constructor);
void eve_view_destroy(struct EVEWindow *window, EVEViewStack *stack);
-void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param);
-int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0);
+int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param);
+int eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile
index 31349a8..0bb1533 100644
--- a/fw/fe310/eos/eve/widget/Makefile
+++ b/fw/fe310/eos/eve/widget/Makefile
@@ -1,7 +1,7 @@
include ../../../common.mk
CFLAGS += -I..
-obj = label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o
+obj = label.o widget.o widgets.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o togglew.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
index 86c2686..e7591da 100644
--- a/fw/fe310/eos/eve/widget/freew.c
+++ b/fw/fe310/eos/eve/widget/freew.c
@@ -8,15 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "freew.h"
-
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec) {
- eve_freew_init(widget, g, page, spec->draw, spec->touch, spec->putc);
-
- return EVE_OK;
-}
void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) {
EVEWidget *_widget = &widget->w;
@@ -25,16 +17,15 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_
eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc);
widget->_draw = draw;
widget->_touch = touch;
- widget->w.putc = putc;
}
-void eve_freew_tag(EVEFreeWidget *widget) {
- EVEWidget *_widget = &widget->w;
+int eve_freew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ EVEFreeSpec *tspec = &spec->tspec.free;
- if (_widget->tagN != EVE_NOTAG) {
- eve_cmd_dl(TAG(_widget->tagN));
- _widget->tagN++;
- }
+ eve_freew_init(widget, &spec->g, page, tspec->draw, tspec->touch, tspec->putc);
+
+ return EVE_OK;
}
uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
@@ -49,6 +40,18 @@ uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
+ int ret;
+
+ ret = widget->_touch(widget, touch, evt);
+ if (ret) eve_widget_set_focus(_widget, NULL);
+ return ret;
+}
- return widget->_touch(widget, touch, evt);
+void eve_freew_tag(EVEFreeWidget *widget) {
+ EVEWidget *_widget = &widget->w;
+
+ if (_widget->tagN != EVE_NOTAG) {
+ eve_cmd_dl(TAG(_widget->tagN));
+ _widget->tagN++;
+ }
}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
index 7eda8c1..324e98d 100644
--- a/fw/fe310/eos/eve/widget/freew.h
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -1,6 +1,7 @@
#include <stdint.h>
struct EVEFreeWidget;
+struct EVEWidgetSpec;
typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *);
typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVETouch *, uint16_t);
@@ -17,9 +18,10 @@ typedef struct EVEFreeSpec {
eve_kbd_input_handler_t putc;
} EVEFreeSpec;
-int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec);
void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc);
-void eve_freew_tag(EVEFreeWidget *widget);
+int eve_freew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0);
int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
+
+void eve_freew_tag(EVEFreeWidget *widget);
diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c
index f2d2e8e..43d555d 100644
--- a/fw/fe310/eos/eve/widget/label.c
+++ b/fw/fe310/eos/eve/widget/label.c
@@ -16,6 +16,13 @@ void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
label->font = font;
label->title = title;
if (label->g.h == 0) label->g.h = eve_font_h(font);
+ if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title) + EVE_LABEL_MARGIN;
+}
+
+void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page) {
+ EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
+
+ eve_label_init(label, &spec->g, font, spec->title);
}
void eve_label_draw(EVELabel *label) {
diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h
index 659c057..9992f8c 100644
--- a/fw/fe310/eos/eve/widget/label.h
+++ b/fw/fe310/eos/eve/widget/label.h
@@ -1,10 +1,21 @@
#include <stdint.h>
+#define EVE_LABEL_MARGIN 10
+
typedef struct EVELabel {
EVERect g;
EVEFont *font;
char *title;
} EVELabel;
+typedef struct EVELabelSpec {
+ EVERect g;
+ EVEFont *font;
+ char *title;
+ int16_t margin;
+} EVELabelSpec;
+
void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title);
+
+void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page);
void eve_label_draw(EVELabel *label); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index bd7819f..c926892 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.c
@@ -8,17 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "pagew.h"
-
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
-
- eve_pagew_init(widget, g, page, font, spec->title, spec->constructor);
-
- return EVE_OK;
-}
void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor) {
EVEWidget *_widget = &widget->w;
@@ -31,6 +21,16 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *f
if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
}
+int eve_pagew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEPageWidget *widget = (EVEPageWidget *)_widget;
+ EVEPageSpec *tspec = &spec->tspec.page;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+
+ eve_pagew_init(widget, &spec->g, page, font, tspec->title, tspec->constructor);
+
+ return EVE_OK;
+}
+
uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
@@ -51,6 +51,7 @@ int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ eve_widget_set_focus(_widget, NULL);
eve_page_open(parent, widget->constructor);
return 1;
}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 76ac0d2..b1a91b2 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVEPageWidget {
EVEWidget w;
EVEFont *font;
@@ -13,8 +15,8 @@ typedef struct EVEPageSpec {
eve_view_constructor_t constructor;
} EVEPageSpec;
-int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec);
void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor);
+int eve_pagew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0);
int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c
index 46ed3d1..5acf998 100644
--- a/fw/fe310/eos/eve/widget/selectw.c
+++ b/fw/fe310/eos/eve/widget/selectw.c
@@ -8,9 +8,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "selectw.h"
#define SELECTW_NOSELECT 0xffffffff
@@ -59,21 +57,6 @@ static void selectw_update_sz(EVESelectWidget *widget, int uievt) {
if (uievt) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE_G, _widget);
}
-int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
- utf8_t *option;
-
- option = eve_malloc(spec->option_size);
- if (option == NULL) {
- return EVE_ERR_NOMEM;
- }
- memset(option, 0, spec->option_size);
-
- eve_selectw_init(widget, g, page, font, option, spec->option_size, spec->multi);
-
- return EVE_OK;
-}
-
void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) {
EVEWidget *_widget = &widget->w;
int rv;
@@ -92,13 +75,32 @@ void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFon
widget->select = widget->multi ? 0 : SELECTW_NOSELECT;
}
-void eve_selectw_destroy(EVESelectWidget *widget) {
+int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVESelectWidget *widget = (EVESelectWidget *)_widget;
+ EVESelectSpec *tspec = &spec->tspec.select;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *option;
+
+ option = eve_malloc(tspec->option_size);
+ if (option == NULL) {
+ return EVE_ERR_NOMEM;
+ }
+ memset(option, 0, tspec->option_size);
+
+ eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi);
+
+ return EVE_OK;
+}
+
+void eve_selectw_destroy(EVEWidget *_widget) {
+ EVESelectWidget *widget = (EVESelectWidget *)_widget;
+
eve_free(widget->option);
}
uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) {
- EVEPage *page = _widget->page;
EVESelectWidget *widget = (EVESelectWidget *)_widget;
+ EVEPage *page = _widget->page;
int o_len;
int o_curr;
int i, s;
@@ -161,6 +163,7 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
int i = touch->tag0 - _widget->tag0 + widget->line0;
+
if (widget->multi) {
uint32_t f = (0x1 << i);
@@ -176,12 +179,15 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->select = i;
}
}
+
+ eve_widget_set_focus(_widget, NULL);
return 1;
}
+
return 0;
}
-utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
+utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx) {
int o_len;
int o_curr;
int i;
@@ -199,11 +205,11 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
return NULL;
}
-utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) {
- return eve_selectw_option_get(widget, widget->select);
+utf8_t *eve_selectw_option_selected(EVESelectWidget *widget) {
+ return eve_selectw_option(widget, widget->select);
}
-int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
+int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) {
int o_len;
int o_curr;
int rv, i;
@@ -231,7 +237,7 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) {
return EVE_OK;
}
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
+int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) {
int rv, i;
rv = selectw_verify(option, option_size);
diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h
index 939e362..f1b7071 100644
--- a/fw/fe310/eos/eve/widget/selectw.h
+++ b/fw/fe310/eos/eve/widget/selectw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVESelectWidget {
EVEWidget w;
EVEFont *font;
@@ -17,14 +19,14 @@ typedef struct EVESelectSpec {
uint8_t multi;
} EVESelectSpec;
-int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec);
void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi);
-void eve_selectw_destroy(EVESelectWidget *widget);
+int eve_selectw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_selectw_destroy(EVEWidget *_widget);
uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
-utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx);
-utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget);
-int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option);
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size);
+utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx);
+utf8_t *eve_selectw_option_selected(EVESelectWidget *widget);
+int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option);
+int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size);
diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
index d9f9104..aa5bec1 100644
--- a/fw/fe310/eos/eve/widget/spacerw.c
+++ b/fw/fe310/eos/eve/widget/spacerw.c
@@ -8,21 +8,17 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "spacerw.h"
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec) {
- eve_spacerw_init(widget, g, page);
-
- return EVE_OK;
+void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page) {
+ memset(widget, 0, sizeof(EVEWidget));
+ eve_widget_init(widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL);
}
-void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page) {
- EVEWidget *_widget = &widget->w;
+int eve_spacerw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ eve_spacerw_init(_widget, &spec->g, page);
- memset(widget, 0, sizeof(EVESpacerWidget));
- eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL);
+ return EVE_OK;
}
uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0) {
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
index 9dafa8b..621b45b 100644
--- a/fw/fe310/eos/eve/widget/spacerw.h
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -1,14 +1,9 @@
#include <stdint.h>
-typedef struct EVESpacerWidget {
- EVEWidget w;
-} EVESpacerWidget;
+struct EVEWidgetSpec;
-typedef struct EVESpacerSpec {
-} EVESpacerSpec;
-
-int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec);
-void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page);
+void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page);
+int eve_spacerw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_spacerw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index 55eeca4..ae9ccab 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -10,9 +10,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "strw.h"
#define STRW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_LPRESS
@@ -29,20 +27,6 @@
#define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f))
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
- utf8_t *str;
- uint16_t *line;
-
- str = eve_malloc(spec->str_size);
- if (str == NULL) return EVE_ERR_NOMEM;
- str[0] = '\0';
-
- eve_strw_init(widget, g, page, font, str, spec->str_size);
-
- return EVE_OK;
-}
-
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size) {
EVEWidget *_widget = &widget->w;
int rv, str_len;
@@ -75,7 +59,25 @@ int eve_strw_update(EVEStrWidget *widget) {
return (rv == UTF_OK) ? EVE_OK : EVE_ERR;
}
-void eve_strw_destroy(EVEStrWidget *widget) {
+int eve_strw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEStrWidget *widget = (EVEStrWidget *)_widget;
+ EVEStrSpec *tspec = &spec->tspec.str;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *str;
+ uint16_t *line;
+
+ str = eve_malloc(tspec->str_size);
+ if (str == NULL) return EVE_ERR_NOMEM;
+ str[0] = '\0';
+
+ eve_strw_init(widget, &spec->g, page, font, str, tspec->str_size);
+
+ return EVE_OK;
+}
+
+void eve_strw_destroy(EVEWidget *_widget) {
+ EVEStrWidget *widget = (EVEStrWidget *)_widget;
+
eve_free(widget->str);
}
@@ -87,7 +89,7 @@ static void set_focus(EVEStrWidget *widget) {
focus.y = _widget->g.y;
focus.w = _widget->g.w;
focus.h = 2 * widget->font->h;
- eve_widget_focus(_widget, &focus);
+ eve_widget_set_focus(_widget, &focus);
}
static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVETouch *touch, short *dx) {
@@ -216,8 +218,8 @@ uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) {
}
int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
- EVEPage *page = _widget->page;
EVEStrWidget *widget = (EVEStrWidget *)_widget;
+ EVEPage *page = _widget->page;
EVEStrCursor *t_cursor = NULL;
short dx;
int ret = 0;
@@ -291,6 +293,7 @@ int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->track.dx = 0;
}
+ if (ret) eve_widget_set_focus(_widget, NULL);
return ret;
}
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index 44e5e2d..acfd74b 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVEStrCursor {
char on;
uint16_t x;
@@ -31,13 +33,14 @@ typedef struct EVEStrSpec {
uint16_t str_size;
} EVEStrSpec;
-int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec);
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size);
-void eve_strw_destroy(EVEStrWidget *widget);
int eve_strw_update(EVEStrWidget *widget);
+int eve_strw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_strw_destroy(EVEWidget *_widget);
uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
+
void eve_strw_putc(void *_page, int c);
void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x);
void eve_strw_cursor_clear(EVEStrWidget *widget, EVEStrCursor *cursor); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index e994c0e..70a1e06 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -10,9 +10,7 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "label.h"
#include "widget.h"
-#include "textw.h"
#define TEXTW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_XY | EVE_TOUCH_OPT_LPRESS
@@ -32,27 +30,6 @@
#define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0))
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec) {
- EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);
- utf8_t *text;
- uint16_t *line;
-
- text = eve_malloc(spec->text_size);
- if (text == NULL) {
- return EVE_ERR_NOMEM;
- }
- text[0] = '\0';
- line = eve_malloc(sizeof(uint16_t) * spec->line_size);
- if (line == NULL) {
- free(text);
- return EVE_ERR_NOMEM;
- }
-
- eve_textw_init(widget, g, page, font, text, spec->text_size, line, spec->line_size);
-
- return EVE_OK;
-}
-
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) {
EVEWidget *_widget = &widget->w;
int rv, text_len;
@@ -74,7 +51,32 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f
eve_textw_text_update(widget, 0, 0);
}
-void eve_textw_destroy(EVETextWidget *widget) {
+int eve_textw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVETextSpec *tspec = &spec->tspec.text;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+ utf8_t *text;
+ uint16_t *line;
+
+ text = eve_malloc(tspec->text_size);
+ if (text == NULL) {
+ return EVE_ERR_NOMEM;
+ }
+ text[0] = '\0';
+ line = eve_malloc(sizeof(uint16_t) * tspec->line_size);
+ if (line == NULL) {
+ free(text);
+ return EVE_ERR_NOMEM;
+ }
+
+ eve_textw_init(widget, &spec->g, page, font, text, tspec->text_size, line, tspec->line_size);
+
+ return EVE_OK;
+}
+
+void eve_textw_destroy(EVEWidget *_widget) {
+ EVETextWidget *widget = (EVETextWidget *)_widget;
+
eve_free(widget->line);
eve_free(widget->text);
}
@@ -87,7 +89,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor) {
focus.y = _widget->g.y + cursor->line * widget->font->h;
focus.w = _widget->g.w;
focus.h = 2 * widget->font->h;
- eve_widget_focus(_widget, &focus);
+ eve_widget_set_focus(_widget, &focus);
}
static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVETouch *touch, short *dx, short *dl) {
@@ -144,8 +146,8 @@ static void draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) {
}
uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
- EVEPage *page = _widget->page;
EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVEPage *page = _widget->page;
int line0, lineN;
int _line0, _lineN;
char lineNvisible;
@@ -237,8 +239,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) {
}
int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
- EVEPage *page = _widget->page;
EVETextWidget *widget = (EVETextWidget *)_widget;
+ EVEPage *page = _widget->page;
EVETextCursor *t_cursor = NULL;
short dx, dl;
int ret = 0;
@@ -289,6 +291,7 @@ int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
widget->track.dl = 0;
}
+ if (ret) eve_widget_set_focus(_widget, NULL);
return ret;
}
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index 570bba8..1c33733 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+struct EVEWidgetSpec;
+
typedef struct EVETextCursor {
char on;
uint16_t x;
@@ -32,10 +34,10 @@ typedef struct EVETextSpec {
uint16_t line_size;
} EVETextSpec;
-int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec);
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
-void eve_textw_destroy(EVETextWidget *widget);
+int eve_textw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+void eve_textw_destroy(EVEWidget *_widget);
uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0);
int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
void eve_textw_putc(void *_w, int c);
diff --git a/fw/fe310/eos/eve/widget/togglew.c b/fw/fe310/eos/eve/widget/togglew.c
new file mode 100644
index 0000000..fbebacb
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/togglew.c
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "eve_font.h"
+
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "widget.h"
+
+void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels) {
+ EVEWidget *_widget = &widget->w;
+
+ memset(widget, 0, sizeof(EVEPageWidget));
+ eve_widget_init(_widget, EVE_WIDGET_TYPE_TOGGLE, g, page, eve_togglew_draw, eve_togglew_touch, NULL);
+ widget->font = font;
+ widget->labels = labels;
+ if (_widget->g.w == 0) _widget->g.w = 3 * eve_font_h(widget->font);
+ if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font);
+}
+
+int eve_togglew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+ EVEToggleSpec *tspec = &spec->tspec.toggle;
+ EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window);
+
+ eve_togglew_init(widget, &spec->g, page, font, tspec->labels);
+
+ return EVE_OK;
+}
+
+uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+
+ _widget->tag0 = tag0;
+ if (tag0 != EVE_NOTAG) {
+ eve_cmd_dl(TAG(tag0));
+ tag0++;
+ }
+ _widget->tagN = tag0;
+
+ eve_cmd(CMD_TOGGLE, "hhhhhhs", _widget->g.x, _widget->g.y, _widget->g.w, widget->font->id, 0, widget->state ? 65535 : 0, widget->labels);
+
+ return _widget->tagN;
+}
+
+int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
+ EVEToggleWidget *widget = (EVEToggleWidget *)_widget;
+
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ widget->state = !widget->state;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/fw/fe310/eos/eve/widget/togglew.h b/fw/fe310/eos/eve/widget/togglew.h
new file mode 100644
index 0000000..26ff77c
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/togglew.h
@@ -0,0 +1,21 @@
+#include <stdint.h>
+
+struct EVEWidgetSpec;
+
+typedef struct EVEToggleWidget {
+ EVEWidget w;
+ EVEFont *font;
+ char *labels;
+ uint8_t state;
+} EVEToggleWidget;
+
+typedef struct EVEToggleSpec {
+ EVEFont *font;
+ char *labels;
+} EVEToggleSpec;
+
+void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels);
+
+int eve_togglew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page);
+uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0);
+int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index 96d2ddf..a157301 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.c
@@ -8,37 +8,11 @@
#include "screen/window.h"
#include "screen/page.h"
-#include "widgets.h"
-
-static const size_t _widget_size[] = {
- 0,
- sizeof(EVEFreeWidget),
- sizeof(EVESpacerWidget),
- sizeof(EVEPageWidget),
- sizeof(EVEStrWidget),
- sizeof(EVETextWidget),
- sizeof(EVESelectWidget),
-};
-
-static const eve_widget_create_t _widget_create[] = {
- NULL,
- (eve_widget_create_t)eve_freew_create,
- (eve_widget_create_t)eve_spacerw_create,
- (eve_widget_create_t)eve_pagew_create,
- (eve_widget_create_t)eve_strw_create,
- (eve_widget_create_t)eve_textw_create,
- (eve_widget_create_t)eve_selectw_create,
-};
-
-static const eve_widget_destroy_t _widget_destroy[] = {
- NULL,
- NULL,
- NULL,
- NULL,
- (eve_widget_destroy_t)eve_strw_destroy,
- (eve_widget_destroy_t)eve_textw_destroy,
- (eve_widget_destroy_t)eve_selectw_destroy,
-};
+#include "widget.h"
+
+extern const size_t _eve_widget_size[];
+extern const eve_widget_create_t _eve_widget_create[];
+extern const eve_widget_destroy_t _eve_widget_destroy[];
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc) {
if (g) widget->g = *g;
@@ -50,7 +24,7 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page,
}
size_t eve_widget_size(uint8_t type) {
- return _widget_size[type];
+ return _eve_widget_size[type];
}
void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
@@ -59,19 +33,32 @@ void eve_widget_set_label(EVEWidget *widget, EVELabel *label) {
EVEWidget *eve_widget_next(EVEWidget *widget) {
char *_w = (char *)widget;
- return (EVEWidget *)(_w + _widget_size[widget->type]);
+ return (EVEWidget *)(_w + _eve_widget_size[widget->type]);
}
-int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec) {
- return _widget_create[type](widget, g, page, spec);
+int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page) {
+ int rv;
+
+ rv = _eve_widget_create[spec->type](widget, spec, page);
+ if (!rv) eve_widget_set_flags(widget, spec->flags);
+
+ return rv;
}
void eve_widget_destroy(EVEWidget *widget) {
- if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget);
+ if (_eve_widget_destroy[widget->type]) _eve_widget_destroy[widget->type](widget);
}
-void eve_widget_focus(EVEWidget *widget, EVERect *rect) {
+void eve_widget_set_focus(EVEWidget *widget, EVERect *rect) {
EVEPage *page = widget->page;
- eve_page_focus_widget(page, widget, rect);
+ eve_page_set_focus(page, widget, rect);
+}
+
+void eve_widget_set_flags(EVEWidget *widget, uint8_t flags) {
+ widget->flags |= flags;
+}
+
+void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags) {
+ widget->flags &= ~flags;
}
diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h
index f081b4c..0bef06e 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -1,11 +1,10 @@
#include <stdint.h>
-#define EVE_WIDGET_TYPE_FREE 1
-#define EVE_WIDGET_TYPE_SPACER 2
-#define EVE_WIDGET_TYPE_PAGE 3
-#define EVE_WIDGET_TYPE_STR 4
-#define EVE_WIDGET_TYPE_TEXT 5
-#define EVE_WIDGET_TYPE_SELECT 6
+#include "label.h"
+
+#define EVEP_WIDGET_FLAG_RO 0x01
+#define EVEP_WIDGET_FLAG_HIDDEN 0x02
+#define EVEP_WIDGET_FLAG_BUSY 0x04
struct EVEWidget;
@@ -20,12 +19,31 @@ typedef struct EVEWidget {
eve_kbd_input_handler_t putc;
EVELabel *label;
uint8_t type;
+ uint8_t flags;
uint8_t tag0;
uint8_t tagN;
} EVEWidget;
+#include "widgets.h"
+
+typedef struct EVEWidgetSpec {
+ EVERect g;
+ EVEWidgetSpecT tspec;
+ uint8_t type;
+ uint8_t flags;
+} EVEWidgetSpec;
+
+typedef int (*eve_widget_create_t) (EVEWidget *, EVEWidgetSpec *, EVEPage *);
+typedef void (*eve_widget_destroy_t) (EVEWidget *);
+
+int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page);
+void eve_widget_destroy(EVEWidget *widget);
+
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc);
size_t eve_widget_size(uint8_t type);
void eve_widget_set_label(EVEWidget *widget, EVELabel *label);
EVEWidget *eve_widget_next(EVEWidget *widget);
-void eve_widget_focus(EVEWidget *widget, EVERect *rect); \ No newline at end of file
+
+void eve_widget_set_focus(EVEWidget *widget, EVERect *rect);
+void eve_widget_set_flags(EVEWidget *widget, uint8_t flags);
+void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/widget/widgets.c b/fw/fe310/eos/eve/widget/widgets.c
new file mode 100644
index 0000000..ec422c1
--- /dev/null
+++ b/fw/fe310/eos/eve/widget/widgets.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+
+#include "eve.h"
+#include "eve_kbd.h"
+#include "eve_font.h"
+
+#include "screen/window.h"
+#include "screen/page.h"
+
+#include "widget.h"
+
+const size_t _eve_widget_size[] = {
+ 0,
+ sizeof(EVEFreeWidget),
+ sizeof(EVEWidget),
+ sizeof(EVEPageWidget),
+ sizeof(EVEToggleWidget),
+ sizeof(EVEStrWidget),
+ sizeof(EVETextWidget),
+ sizeof(EVESelectWidget),
+};
+
+const eve_widget_create_t _eve_widget_create[] = {
+ NULL,
+ eve_freew_create,
+ eve_spacerw_create,
+ eve_pagew_create,
+ eve_togglew_create,
+ eve_strw_create,
+ eve_textw_create,
+ eve_selectw_create,
+};
+
+const eve_widget_destroy_t _eve_widget_destroy[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ eve_strw_destroy,
+ eve_textw_destroy,
+ eve_selectw_destroy,
+};
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
index 2f8d3ca..9c96d8c 100644
--- a/fw/fe310/eos/eve/widget/widgets.h
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -1,39 +1,24 @@
-#include "label.h"
-#include "widget.h"
-
#include "freew.h"
#include "spacerw.h"
#include "pagew.h"
#include "strw.h"
#include "textw.h"
#include "selectw.h"
+#include "togglew.h"
+
+#define EVE_WIDGET_TYPE_FREE 1
+#define EVE_WIDGET_TYPE_SPACER 2
+#define EVE_WIDGET_TYPE_PAGE 3
+#define EVE_WIDGET_TYPE_TOGGLE 4
+#define EVE_WIDGET_TYPE_STR 5
+#define EVE_WIDGET_TYPE_TEXT 6
+#define EVE_WIDGET_TYPE_SELECT 7
typedef union EVEWidgetSpecT {
EVEFreeSpec free;
- EVESpacerSpec spacer;
EVEPageSpec page;
+ EVEToggleSpec toggle;
EVEStrSpec str;
EVETextSpec text;
EVESelectSpec select;
} EVEWidgetSpecT;
-
-typedef struct EVELabelSpec {
- EVERect g;
- EVEFont *font;
- char *title;
-} APPLabelSpec;
-
-typedef struct EVEWidgetSpec {
- APPLabelSpec label;
- struct {
- EVERect g;
- EVEWidgetSpecT spec;
- uint8_t type;
- } widget;
-} EVEWidgetSpec;
-
-typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *, EVEPage *, EVEWidgetSpecT *);
-typedef void (*eve_widget_destroy_t) (EVEWidget *);
-
-int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec);
-void eve_widget_destroy(EVEWidget *widget);
diff --git a/fw/fe310/eos/net/Makefile b/fw/fe310/eos/net/Makefile
new file mode 100644
index 0000000..fc65454
--- /dev/null
+++ b/fw/fe310/eos/net/Makefile
@@ -0,0 +1,19 @@
+include ../../common.mk
+
+obj = rng.o pwr.o wifi.o sock.o cell.o
+lib = ../../libeos-net.a
+
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) -c $<
+
+all: $(lib)
+
+$(lib): $(obj)
+ $(AR) rcs $@ $(obj)
+
+clean:
+ rm -f *.o $(lib)
diff --git a/fw/fe310/eos/net/cell.c b/fw/fe310/eos/net/cell.c
index 20a9f42..4bfbb35 100644
--- a/fw/fe310/eos/net/cell.c
+++ b/fw/fe310/eos/net/cell.c
@@ -4,7 +4,7 @@
#include "eos.h"
#include "event.h"
-#include "net.h"
+#include "dev/net.h"
#include "cell.h"
@@ -28,7 +28,7 @@ static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_cell_netinit(void) {
+void eos_cell_init(void) {
int i;
for (i=0; i<EOS_CELL_MAX_MTYPE; i++) {
diff --git a/fw/fe310/eos/net/cell.h b/fw/fe310/eos/net/cell.h
index b01d4cf..f04eef2 100644
--- a/fw/fe310/eos/net/cell.h
+++ b/fw/fe310/eos/net/cell.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#include "event.h"
+#include "../event.h"
#define EOS_CELL_MTYPE_DEV 0x10
#define EOS_CELL_MTYPE_VOICE 0x20
@@ -38,14 +38,24 @@
#define EOS_CELL_MTYPE_USSD_REPLY 2
#define EOS_CELL_MTYPE_USSD_CANCEL 3
-#define EOS_CELL_MTYPE_PDP_CONFIG 1
-#define EOS_CELL_MTYPE_PDP_CONNECT 2
-#define EOS_CELL_MTYPE_PDP_DISCONNECT 3
+#define EOS_CELL_MTYPE_PDP_GET_APN 1
+#define EOS_CELL_MTYPE_PDP_GET_USR 2
+#define EOS_CELL_MTYPE_PDP_GET_PWD 3
+#define EOS_CELL_MTYPE_PDP_SET_APN 4
+#define EOS_CELL_MTYPE_PDP_SET_USR 5
+#define EOS_CELL_MTYPE_PDP_SET_PWD 6
+#define EOS_CELL_MTYPE_PDP_CONNECT 7
+#define EOS_CELL_MTYPE_PDP_DISCONNECT 8
#define EOS_CELL_SMS_ADDRTYPE_INTL 1
#define EOS_CELL_SMS_ADDRTYPE_ALPHA 2
#define EOS_CELL_SMS_ADDRTYPE_OTHER 3
-void eos_cell_netinit(void);
+#define EOS_CELL_PDP_SIZE_APN 64
+#define EOS_CELL_PDP_SIZE_USR 64
+#define EOS_CELL_PDP_SIZE_PWD 64
+#define EOS_CELL_PDP_SIZE_ARG 64
+
+void eos_cell_init(void);
void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler);
eos_evt_handler_t eos_cell_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/net/pwr.c b/fw/fe310/eos/net/pwr.c
new file mode 100644
index 0000000..734e3cd
--- /dev/null
+++ b/fw/fe310/eos/net/pwr.c
@@ -0,0 +1,69 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "eos.h"
+#include "event.h"
+#include "dev/net.h"
+
+#include "soc/pwr.h"
+#include "soc/spi.h"
+#include "dev/spi.h"
+#include "eve/eve.h"
+
+#include "pwr.h"
+
+static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE];
+static unsigned char power_btn_down;
+
+static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
+ unsigned char mtype;
+
+ if ((buffer == NULL) || (len < 1)) {
+ eos_net_bad_handler(type, buffer, len);
+ return;
+ }
+
+ mtype = buffer[0];
+ if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) {
+ evt_handler[mtype](mtype, buffer, len);
+ } else {
+ eos_net_bad_handler(type, buffer, len);
+ }
+}
+
+static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) {
+ int rv;
+ unsigned char level = buffer[1];
+
+ eos_net_free(buffer, 0);
+ if (!level) {
+ power_btn_down = 1;
+ return;
+ }
+ if (!power_btn_down) return;
+
+ eos_spi_select(EOS_SPI_DEV_EVE);
+ eve_pwr_sleep();
+ eos_spi_deselect();
+
+ rv = eos_pwr_sleep();
+}
+
+void eos_pwr_net_init(void) {
+ int i;
+
+ for (i=0; i<EOS_PWR_MAX_MTYPE; i++) {
+ evt_handler[i] = NULL;
+ }
+ eos_net_set_handler(EOS_NET_MTYPE_POWER, pwr_handle_msg);
+ eos_pwr_set_handler(EOS_PWR_MTYPE_BUTTON, pwr_handle_btn);
+}
+
+void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
+ if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler;
+}
+
+eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype) {
+ if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype];
+ return NULL;
+}
diff --git a/fw/fe310/eos/net/pwr.h b/fw/fe310/eos/net/pwr.h
new file mode 100644
index 0000000..b82a96b
--- /dev/null
+++ b/fw/fe310/eos/net/pwr.h
@@ -0,0 +1,10 @@
+#include <stdint.h>
+#include "../event.h"
+
+#define EOS_PWR_MTYPE_BUTTON 1
+
+#define EOS_PWR_MAX_MTYPE 2
+
+void eos_pwr_net_init(void);
+void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler);
+eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype);
diff --git a/fw/fe310/eos/net/rng.c b/fw/fe310/eos/net/rng.c
index 317941d..7d05a81 100644
--- a/fw/fe310/eos/net/rng.c
+++ b/fw/fe310/eos/net/rng.c
@@ -2,7 +2,7 @@
#include <stdint.h>
#include <string.h>
-#include "net.h"
+#include "dev/net.h"
int getentropy(unsigned char *b, size_t sz) {
unsigned char type;
diff --git a/fw/fe310/eos/net/sock.c b/fw/fe310/eos/net/sock.c
index 7365c97..1db0cd9 100644
--- a/fw/fe310/eos/net/sock.c
+++ b/fw/fe310/eos/net/sock.c
@@ -4,7 +4,7 @@
#include "eos.h"
#include "event.h"
-#include "net.h"
+#include "dev/net.h"
#include "sock.h"
@@ -34,7 +34,7 @@ static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_sock_netinit(void) {
+void eos_sock_init(void) {
int i;
for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
@@ -69,20 +69,29 @@ int eos_sock_open_udp(eos_evt_handler_t handler, unsigned char *buffer) {
buffer[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
rv = eos_net_xchg(&type, buffer, &len);
- if (rv) return rv;
+ if (rv) goto sock_open_udp_fin;
- if (type != EOS_NET_MTYPE_SOCK) return EOS_ERR_NET;
- if (len < 2) return EOS_ERR_SIZE;
+ if (type != EOS_NET_MTYPE_SOCK) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
+ }
+ if (len < 2) {
+ rv = EOS_ERR_SIZE;
+ goto sock_open_udp_fin;
+ }
sock = buffer[1];
- if (sock == 0) return EOS_ERR_NET;
-
- if (do_release) {
- eos_net_free(buffer, 1);
+ if (sock == 0) {
+ rv = EOS_ERR_NET;
+ goto sock_open_udp_fin;
}
+
+ rv = sock;
eos_sock_set_handler(sock, handler);
- return sock;
+sock_open_udp_fin:
+ if (do_release) eos_net_free(buffer, 1);
+ return rv;
}
void eos_sock_close(unsigned char sock, unsigned char *buffer) {
diff --git a/fw/fe310/eos/net/sock.h b/fw/fe310/eos/net/sock.h
index 5ef42e3..e2f8637 100644
--- a/fw/fe310/eos/net/sock.h
+++ b/fw/fe310/eos/net/sock.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#include "event.h"
+#include "../event.h"
#define EOS_SOCK_MTYPE_PKT 0
#define EOS_SOCK_MTYPE_OPEN_DGRAM 1
@@ -16,7 +16,7 @@ typedef struct EOSNetAddr {
uint16_t port;
} EOSNetAddr;
-void eos_sock_netinit(void);
+void eos_sock_init(void);
void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler);
eos_evt_handler_t eos_sock_get_handler(unsigned char sock);
diff --git a/fw/fe310/eos/net/wifi.c b/fw/fe310/eos/net/wifi.c
index 0663582..4db49f8 100644
--- a/fw/fe310/eos/net/wifi.c
+++ b/fw/fe310/eos/net/wifi.c
@@ -4,10 +4,13 @@
#include "eos.h"
#include "event.h"
-#include "net.h"
+#include "dev/net.h"
#include "wifi.h"
+#define WIFI_SIZE_SSID 33
+#define WIFI_SIZE_PWD 64
+
static eos_evt_handler_t evt_handler[EOS_WIFI_MAX_MTYPE];
static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
@@ -26,7 +29,7 @@ static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_wifi_netinit(void) {
+void eos_wifi_init(void) {
int i;
for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
@@ -44,7 +47,64 @@ eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) {
return NULL;
}
-int eos_wifi_scan(unsigned char *buffer) {
+int eos_wifi_status(unsigned char *buffer, uint8_t *status, uint8_t ip_addr[], char *ssid) {
+ unsigned char *buf;
+ unsigned char type;
+ uint16_t len;
+ int do_release;
+ int rv;
+
+ do_release = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ do_release = 1;
+ }
+
+ type = EOS_NET_MTYPE_WIFI;
+ len = 1;
+ buffer[0] = EOS_WIFI_MTYPE_STATUS;
+
+ rv = eos_net_xchg(&type, buffer, &len);
+ if (rv) goto wifi_status_fin;
+
+ if (type != EOS_NET_MTYPE_WIFI) {
+ rv = EOS_ERR_NET;
+ goto wifi_status_fin;
+ }
+ if (len < 2) {
+ rv = EOS_ERR_SIZE;
+ goto wifi_status_fin;
+ }
+
+ *status = buffer[1];
+ buf = buffer + 2;
+ len -= 2;
+
+ switch (*status) {
+ case EOS_WIFI_STATUS_GOT_IP:
+ if (len < sizeof(uint32_t)) {
+ rv = EOS_ERR_SIZE;
+ goto wifi_status_fin;
+ }
+ if (ip_addr) memcpy(ip_addr, buf, sizeof(uint32_t));
+ buf += sizeof(uint32_t);
+ len -= sizeof(uint32_t);
+ case EOS_WIFI_STATUS_CONNECTED:
+ if ((len == 0) || (len > WIFI_SIZE_SSID)) {
+ rv = EOS_ERR_SIZE;
+ goto wifi_status_fin;
+ }
+ buf[len - 1] = '\0';
+ if (ssid) strcpy(ssid, buf);
+ break;
+ }
+
+wifi_status_fin:
+ if (do_release) eos_net_free(buffer, 1);
+ return rv;
+}
+
+int eos_wifi_start(unsigned char *buffer) {
int async;
async = 0;
@@ -52,13 +112,11 @@ int eos_wifi_scan(unsigned char *buffer) {
buffer = eos_net_alloc();
async = 1;
}
- buffer[0] = EOS_WIFI_MTYPE_SCAN;
+ buffer[0] = EOS_WIFI_MTYPE_START;
return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
}
-int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer) {
- unsigned char *buf;
- size_t ssid_len, pass_len;
+int eos_wifi_stop(unsigned char *buffer) {
int async;
async = 0;
@@ -66,30 +124,45 @@ int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer) {
buffer = eos_net_alloc();
async = 1;
}
- ssid_len = strlen(ssid) + 1;
- pass_len = strlen(pass) + 1;
- if ((1 + ssid_len + pass_len) > EOS_NET_MTU) return EOS_ERR_SIZE;
+ buffer[0] = EOS_WIFI_MTYPE_STOP;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
- buf = buffer;
- buf[0] = EOS_WIFI_MTYPE_AUTH;
- buf++;
- strcpy(buf, ssid);
- buf += ssid_len;
- strcpy(buf, pass);
- buf += pass_len;
+int eos_wifi_scan(unsigned char *buffer) {
+ int async;
- return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1 + ssid_len + pass_len, async, 1);
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_SCAN;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
}
-int eos_wifi_connect(unsigned char *buffer) {
+int eos_wifi_connect(const char *ssid, const char *pwd, unsigned char *buffer) {
+ unsigned char *buf;
+ size_t ssid_len, pwd_len;
int async;
+ ssid_len = strlen(ssid);
+ pwd_len = strlen(pwd);
+ if (ssid_len > WIFI_SIZE_SSID - 1) return EOS_ERR_SIZE;
+ if (pwd_len > WIFI_SIZE_PWD - 1) return EOS_ERR_SIZE;
+
async = 0;
if (buffer == NULL) {
buffer = eos_net_alloc();
async = 1;
}
- buffer[0] = EOS_WIFI_MTYPE_CONNECT;
+ buf = buffer;
+ buf[0] = EOS_WIFI_MTYPE_CONNECT;
+ buf++;
+ strcpy(buf, ssid);
+ buf += ssid_len + 1;
+ strcpy(buf, pwd);
+ buf += pwd_len + 1;
+
return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
}
diff --git a/fw/fe310/eos/net/wifi.h b/fw/fe310/eos/net/wifi.h
index 4a49518..2100144 100644
--- a/fw/fe310/eos/net/wifi.h
+++ b/fw/fe310/eos/net/wifi.h
@@ -1,18 +1,27 @@
#include <stdint.h>
-#include "event.h"
+#include "../event.h"
-#define EOS_WIFI_MTYPE_SCAN 1
-#define EOS_WIFI_MTYPE_AUTH 2
-#define EOS_WIFI_MTYPE_CONNECT 3
-#define EOS_WIFI_MTYPE_DISCONNECT 4
+#define EOS_WIFI_MTYPE_STATUS 0
+#define EOS_WIFI_MTYPE_SCAN 1
+#define EOS_WIFI_MTYPE_START 2
+#define EOS_WIFI_MTYPE_STOP 3
+#define EOS_WIFI_MTYPE_CONNECT 4
+#define EOS_WIFI_MTYPE_DISCONNECT 5
-#define EOS_WIFI_MAX_MTYPE 5
+#define EOS_WIFI_MAX_MTYPE 2
-void eos_wifi_netinit(void);
+#define EOS_WIFI_STATUS_OFF 0
+#define EOS_WIFI_STATUS_DISCONNECTED 1
+#define EOS_WIFI_STATUS_CONNECTED 2
+#define EOS_WIFI_STATUS_GOT_IP 3
+
+void eos_wifi_init(void);
void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler);
eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype);
+int eos_wifi_status(unsigned char *buffer, uint8_t *status, uint8_t ip_addr[], char *ssid);
+int eos_wifi_start(unsigned char *buffer);
+int eos_wifi_stop(unsigned char *buffer);
int eos_wifi_scan(unsigned char *buffer);
-int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer);
-int eos_wifi_connect(unsigned char *buffer);
-int eos_wifi_disconnect(unsigned char *buffer);
+int eos_wifi_connect(const char *ssid, const char *pwd, unsigned char *buffer);
+int eos_wifi_disconnect(unsigned char *buffer); \ No newline at end of file
diff --git a/fw/fe310/eos/soc/Makefile b/fw/fe310/eos/soc/Makefile
new file mode 100644
index 0000000..1404c81
--- /dev/null
+++ b/fw/fe310/eos/soc/Makefile
@@ -0,0 +1,20 @@
+include ../../common.mk
+CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers
+
+obj = trap_entry.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o
+lib = ../../libeos-soc.a
+
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) -c $<
+
+all: $(lib)
+
+$(lib): $(obj)
+ $(AR) rcs $@ $(obj)
+
+clean:
+ rm -f *.o $(lib)
diff --git a/fw/fe310/eos/soc/i2c.c b/fw/fe310/eos/soc/i2c.c
index a507af1..553a9bf 100644
--- a/fw/fe310/eos/soc/i2c.c
+++ b/fw/fe310/eos/soc/i2c.c
@@ -11,22 +11,28 @@
int eos_i2c_init(uint8_t wakeup_cause) {
eos_i2c_speed(EOS_I2C_SPEED);
- // eos_i2c_start();
+ eos_i2c_enable();
return EOS_OK;
}
-void eos_i2c_start(void) {
+void eos_i2c_enable(void) {
I2C0_REGB(I2C_CONTROL) |= I2C_CONTROL_EN;
+
GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_I2C0_MASK;
GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK;
}
-void eos_i2c_stop(void) {
+void eos_i2c_disable(void) {
GPIO_REG(GPIO_IOF_EN) &= ~IOF0_I2C0_MASK;
+
I2C0_REGB(I2C_CONTROL) &= ~I2C_CONTROL_EN;
}
+int eos_i2c_enabled(void) {
+ return !!(GPIO_REG(GPIO_IOF_EN) & IOF0_I2C0_MASK);
+}
+
void eos_i2c_speed(uint32_t baud_rate) {
unsigned long clock_rate = PRCI_get_cpu_freq();
uint16_t prescaler = (clock_rate / (baud_rate * 5)) - 1;
diff --git a/fw/fe310/eos/soc/i2c.h b/fw/fe310/eos/soc/i2c.h
index 20d3dc7..5032988 100644
--- a/fw/fe310/eos/soc/i2c.h
+++ b/fw/fe310/eos/soc/i2c.h
@@ -3,9 +3,9 @@
#define EOS_I2C_SPEED 100000
int eos_i2c_init(uint8_t wakeup_cause);
-int eos_i2c_run(uint8_t wakeup_cause);
-void eos_i2c_start(void);
-void eos_i2c_stop(void);
+void eos_i2c_enable(void);
+void eos_i2c_disable(void);
+int eos_i2c_enabled(void);
void eos_i2c_speed(uint32_t baud_rate);
int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t len);
int eos_i2c_read16(uint8_t addr, uint16_t reg, uint8_t *buffer, uint16_t len);
diff --git a/fw/fe310/eos/soc/i2s.c b/fw/fe310/eos/soc/i2s.c
index 9cc9d9c..5e5eaa7 100644
--- a/fw/fe310/eos/soc/i2s.c
+++ b/fw/fe310/eos/soc/i2s.c
@@ -25,41 +25,20 @@
#define EOS_ABUF_IDX_MASK(IDX, SIZE) ((IDX) & ((SIZE) - 1))
-EOSABuf i2s_mic_buf;
-EOSABuf i2s_spk_buf;
+EOSABuf _eos_i2s_mic_buf;
+EOSABuf _eos_i2s_spk_buf;
+uint32_t _eos_i2s_fmt = 0;
+uint32_t _eos_i2s_mic_wm = 0;
+uint32_t _eos_i2s_spk_wm = 0;
+uint32_t _eos_i2s_mic_evt_enable = 0;
+uint32_t _eos_i2s_spk_evt_enable = 0;
-static eos_i2s_handler_t i2s_mic_handler = NULL;
static eos_i2s_handler_t i2s_spk_handler = NULL;
+static eos_i2s_handler_t i2s_mic_handler = NULL;
static uint32_t i2s_clk_period;
static uint8_t i2s_mic_volume = 0; /* 0 - 8 */
static uint8_t i2s_spk_volume = 16; /* 0 - 16 */
-uint32_t _eos_i2s_drvr[] = {
- 0, /* I2S_MIC_BUF */
- 0, /* I2S_SPK_BUF */
- EOS_I2S_FMT_PCM16, /* I2S_FMT */
- EOS_I2S_MODE_STEREO, /* I2S_MODE */
- 0, /* I2S_MIC_WM */
- 0, /* I2S_SPK_WM */
- 0, /* I2S_MIC_EVT */
- 0, /* I2S_SPK_EVT */
- 0, /* I2S_MIC_CMP2 */
- 0, /* I2S_MIC_CMP3 */
- 0, /* I2S_SAMPLE */
-};
-
-#define I2S_MIC_BUF 0
-#define I2S_SPK_BUF 1
-#define I2S_FMT 2
-#define I2S_MODE 3
-#define I2S_MIC_WM 4
-#define I2S_SPK_WM 5
-#define I2S_MIC_EVT 6
-#define I2S_SPK_EVT 7
-#define I2S_MIC_CMP2 8
-#define I2S_MIC_CMP3 9
-#define I2S_SAMPLE 10
-
static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) {
buf->idx_r = 0;
buf->idx_w = 0;
@@ -105,6 +84,7 @@ static int _abuf_pop16(EOSABuf *buf, uint16_t *sample) {
}
}
+
static void _abuf_flush(EOSABuf *buf) {
buf->idx_r = 0;
buf->idx_w = 0;
@@ -117,63 +97,42 @@ static uint16_t _abuf_len(EOSABuf *buf) {
static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
switch(type & ~EOS_EVT_MASK) {
case EOS_I2S_ETYPE_MIC:
- if (i2s_mic_handler) {
- i2s_mic_handler(type);
- clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_drvr[I2S_MIC_EVT] = 1;
- set_csr(mstatus, MSTATUS_MIE);
- }
+ if (i2s_mic_handler) i2s_mic_handler(type);
+ clear_csr(mstatus, MSTATUS_MIE);
+ _eos_i2s_mic_evt_enable = 1;
+ set_csr(mstatus, MSTATUS_MIE);
break;
-
case EOS_I2S_ETYPE_SPK:
- if (i2s_spk_handler) {
- i2s_spk_handler(type);
- clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_drvr[I2S_SPK_EVT] = 1;
- set_csr(mstatus, MSTATUS_MIE);
- }
+ if (i2s_spk_handler) i2s_spk_handler(type);
+ clear_csr(mstatus, MSTATUS_MIE);
+ _eos_i2s_spk_evt_enable = 1;
+ set_csr(mstatus, MSTATUS_MIE);
break;
-
default:
eos_evtq_bad_handler(type, buffer, len);
break;
}
}
-#define PLIC_PRIORITY 0x0C000000
-
-static void i2s_cmp_set(void) {
- int c = 7; /* interrupt will trigger c i2s clocks before spk ws */
- int spk_ws_offset = i2s_spk_volume - 16 + i2s_mic_volume;
- volatile uint32_t *p = (uint32_t *)PLIC_PRIORITY+I2S_IRQ_SD_ID;
-
- /* interrupt trigger - will start with left channel */
- if (spk_ws_offset - c < 0) {
- I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (64 + spk_ws_offset - c);
- } else {
- I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (spk_ws_offset - c);
- }
-
- /* disable interrupt for this cycle */
- *p = 0;
+static void _mic_vol_set(uint8_t vol) {
+ I2S_REG_WS_MIC(PWM_CMP2) = i2s_clk_period * (vol + 1);
+ I2S_REG_WS_MIC(PWM_CMP3) = I2S_REG_WS_MIC(PWM_CMP2) + i2s_clk_period * 16;
+}
- /* empty buffers */
- // i2s_mic_buf.idx_r = i2s_mic_buf.idx_w;
- // i2s_spk_buf.idx_w = i2s_spk_buf.idx_r;
+static void _spk_vol_set(uint8_t vol) {
+ int spk_cmp = vol + i2s_mic_volume - 16;
- /* adjust spk ws relative to mic ws */
- if (spk_ws_offset <= 0) {
- spk_ws_offset += 32;
+ if (spk_cmp <= 0) {
+ I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * (32 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (64 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * 33;
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
} else {
- GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << I2S_PIN_WS_SPK);
+ I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_cmp;
+ I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_cmp);
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (33 + spk_cmp);
+ GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << I2S_PIN_WS_SPK);
}
- I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_ws_offset;
- I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_ws_offset);
-
- /* mic cmp2 relative to interrupt trigger */
- _eos_i2s_drvr[I2S_MIC_CMP2] = (17 + c - i2s_spk_volume) * i2s_clk_period; /* (17 + c - i2s_spk_volume) == (1 + i2s_mic_volume) - (spk_ws_offset - c) */
- _eos_i2s_drvr[I2S_MIC_CMP3] = 16 * i2s_clk_period;
}
extern void _eos_i2s_start_pwm(void);
@@ -181,10 +140,6 @@ extern void _eos_i2s_start_pwm(void);
int eos_i2s_init(uint8_t wakeup_cause) {
eos_evtq_set_handler(EOS_EVT_I2S, i2s_handle_evt);
- I2S_REG_CK(PWM_CFG) = 0;
- I2S_REG_WS_MIC(PWM_CFG) = 0;
- I2S_REG_WS_SPK(PWM_CFG) = 0;
-
eos_i2s_init_mux();
GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
@@ -218,7 +173,7 @@ void eos_i2s_init_mux(void) {
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
}
-void eos_i2s_start(uint32_t sample_rate) {
+void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
i2s_clk_period = ((PRCI_get_cpu_freq() / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK) + 1;
GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN);
@@ -234,33 +189,23 @@ void eos_i2s_start(uint32_t sample_rate) {
I2S_REG_WS_MIC(PWM_CMP0) = i2s_clk_period * 64 - 1;
I2S_REG_WS_MIC(PWM_CMP1) = i2s_clk_period * 32;
+ _mic_vol_set(i2s_mic_volume);
I2S_REG_WS_SPK(PWM_CMP0) = i2s_clk_period * 64 - 1;
- i2s_cmp_set();
+ _spk_vol_set(i2s_spk_volume);
I2S_REG_CK(PWM_COUNT) = 0;
I2S_REG_WS_MIC(PWM_COUNT) = 0;
I2S_REG_WS_SPK(PWM_COUNT) = i2s_clk_period / 2;
- if (i2s_mic_buf.array && i2s_mic_buf.size) {
- _eos_i2s_drvr[I2S_MIC_BUF] = (uint32_t)&i2s_mic_buf;
- if (_eos_i2s_drvr[I2S_MIC_WM] == 0) {
- _eos_i2s_drvr[I2S_MIC_WM] = i2s_mic_buf.size / 2;
- }
- }
- if (i2s_spk_buf.array && i2s_spk_buf.size) {
- _eos_i2s_drvr[I2S_SPK_BUF] = (uint32_t)&i2s_spk_buf;
- if (_eos_i2s_drvr[I2S_SPK_WM] == 0) {
- _eos_i2s_drvr[I2S_SPK_WM] = i2s_spk_buf.size / 2;
- }
- }
- if (i2s_mic_handler) _eos_i2s_drvr[I2S_MIC_EVT] = 1;
- if (i2s_spk_handler) _eos_i2s_drvr[I2S_SPK_EVT] = 1;
+ _eos_i2s_fmt = fmt;
+ _eos_i2s_mic_evt_enable = 1;
+ _eos_i2s_spk_evt_enable = 1;
- eos_intr_set_priority(I2S_IRQ_SD_ID, IRQ_PRIORITY_I2S_SD);
eos_intr_set_priority(I2S_IRQ_WS_ID, IRQ_PRIORITY_I2S_WS);
- eos_intr_enable(I2S_IRQ_SD_ID);
+ eos_intr_set_priority(I2S_IRQ_SD_ID, 0);
eos_intr_enable(I2S_IRQ_WS_ID);
+ eos_intr_enable(I2S_IRQ_SD_ID);
_eos_i2s_start_pwm();
/*
@@ -269,13 +214,9 @@ void eos_i2s_start(uint32_t sample_rate) {
I2S_REG_WS_SPK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG;
*/
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_MIC);
-
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM;
- GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM;
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM;
+ GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM;
}
void eos_i2s_stop(void) {
@@ -286,14 +227,10 @@ void eos_i2s_stop(void) {
I2S_REG_WS_MIC(PWM_COUNT) = 0;
I2S_REG_WS_SPK(PWM_COUNT) = 0;
- _eos_i2s_drvr[I2S_MIC_BUF] = 0;
- _eos_i2s_drvr[I2S_MIC_EVT] = 0;
- _eos_i2s_drvr[I2S_MIC_WM] = 0;
-
- _eos_i2s_drvr[I2S_SPK_BUF] = 0;
- _eos_i2s_drvr[I2S_SPK_EVT] = 0;
- _eos_i2s_drvr[I2S_SPK_WM] = 0;
-
+ _eos_i2s_mic_evt_enable = 0;
+ _eos_i2s_spk_evt_enable = 0;
+ eos_intr_set_priority(I2S_IRQ_WS_ID, 0);
+ eos_intr_set_priority(I2S_IRQ_SD_ID, 0);
eos_intr_disable(I2S_IRQ_WS_ID);
eos_intr_disable(I2S_IRQ_SD_ID);
@@ -302,26 +239,15 @@ void eos_i2s_stop(void) {
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM;
-
- eos_i2s_mic_set_wm(0);
- eos_i2s_spk_set_wm(0);
}
int eos_i2s_running(void) {
- return !!(GPIO_REG(GPIO_IOF_EN) & (1 << I2S_PIN_CK));
-}
-
-void eos_i2s_set_fmt(unsigned char fmt) {
- _eos_i2s_drvr[I2S_FMT] = fmt;
-}
-
-void eos_i2s_set_mode(unsigned char mode) {
- _eos_i2s_drvr[I2S_MODE] = mode;
+ return !!(GPIO_REG(GPIO_IOF_EN) & I2S_PIN_PWM);
}
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size) {
clear_csr(mstatus, MSTATUS_MIE);
- _abuf_init(&i2s_mic_buf, mic_arr, mic_arr_size);
+ _abuf_init(&_eos_i2s_mic_buf, mic_arr, mic_arr_size);
set_csr(mstatus, MSTATUS_MIE);
}
@@ -333,14 +259,14 @@ void eos_i2s_mic_set_handler(eos_i2s_handler_t wm_handler) {
void eos_i2s_mic_set_wm(uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_drvr[I2S_MIC_WM] = wm;
+ _eos_i2s_mic_wm = wm;
set_csr(mstatus, MSTATUS_MIE);
}
uint16_t eos_i2s_mic_len(void) {
clear_csr(mstatus, MSTATUS_MIE);
- uint16_t ret = _abuf_len(&i2s_mic_buf);
+ uint16_t ret = _abuf_len(&_eos_i2s_mic_buf);
set_csr(mstatus, MSTATUS_MIE);
return ret;
}
@@ -350,37 +276,31 @@ uint16_t eos_i2s_mic_read(uint8_t *sample, uint16_t ssize) {
uint16_t _ssize = 0;
clear_csr(mstatus, MSTATUS_MIE);
- _ssize = MIN(ssize, _abuf_len(&i2s_mic_buf));
+ _ssize = MIN(ssize, _abuf_len(&_eos_i2s_mic_buf));
set_csr(mstatus, MSTATUS_MIE);
for (i=0; i<_ssize; i++) {
- sample[i] = i2s_mic_buf.array[EOS_ABUF_IDX_MASK(i2s_mic_buf.idx_r + i, i2s_mic_buf.size)];
+ sample[i] = _eos_i2s_mic_buf.array[EOS_ABUF_IDX_MASK(_eos_i2s_mic_buf.idx_r + i, _eos_i2s_mic_buf.size)];
}
clear_csr(mstatus, MSTATUS_MIE);
- i2s_mic_buf.idx_r += _ssize;
+ _eos_i2s_mic_buf.idx_r += _ssize;
set_csr(mstatus, MSTATUS_MIE);
return _ssize;
}
int eos_i2s_mic_pop8(uint8_t *sample) {
- int ret;
-
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_pop8(&i2s_mic_buf, sample);
+ int ret = _abuf_pop8(&_eos_i2s_mic_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
-
return ret;
}
int eos_i2s_mic_pop16(uint16_t *sample) {
- int ret;
-
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_pop16(&i2s_mic_buf, sample);
+ int ret = _abuf_pop16(&_eos_i2s_mic_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
-
return ret;
}
@@ -394,13 +314,14 @@ void eos_i2s_mic_vol_set(int vol) {
i2s_mic_volume = vol;
clear_csr(mstatus, MSTATUS_MIE);
- i2s_cmp_set();
+ _mic_vol_set(vol);
+ _spk_vol_set(i2s_spk_volume);
set_csr(mstatus, MSTATUS_MIE);
}
void eos_i2s_spk_init(uint8_t *spk_arr, uint16_t spk_arr_size) {
clear_csr(mstatus, MSTATUS_MIE);
- _abuf_init(&i2s_spk_buf, spk_arr, spk_arr_size);
+ _abuf_init(&_eos_i2s_spk_buf, spk_arr, spk_arr_size);
set_csr(mstatus, MSTATUS_MIE);
}
@@ -412,13 +333,13 @@ void eos_i2s_spk_set_handler(eos_i2s_handler_t wm_handler) {
void eos_i2s_spk_set_wm(uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_drvr[I2S_SPK_WM] = wm;
+ _eos_i2s_spk_wm = wm;
set_csr(mstatus, MSTATUS_MIE);
}
uint16_t eos_i2s_spk_len(void) {
clear_csr(mstatus, MSTATUS_MIE);
- uint16_t ret = _abuf_len(&i2s_spk_buf);
+ uint16_t ret = _abuf_len(&_eos_i2s_spk_buf);
set_csr(mstatus, MSTATUS_MIE);
return ret;
}
@@ -428,37 +349,31 @@ uint16_t eos_i2s_spk_write(uint8_t *sample, uint16_t ssize) {
uint16_t _ssize = 0;
clear_csr(mstatus, MSTATUS_MIE);
- _ssize = MIN(ssize, i2s_spk_buf.size - _abuf_len(&i2s_spk_buf));
+ _ssize = MIN(ssize, _eos_i2s_spk_buf.size - _abuf_len(&_eos_i2s_spk_buf));
set_csr(mstatus, MSTATUS_MIE);
for (i=0; i<_ssize; i++) {
- i2s_spk_buf.array[EOS_ABUF_IDX_MASK(i2s_spk_buf.idx_w + i, i2s_spk_buf.size)] = sample[i];
+ _eos_i2s_spk_buf.array[EOS_ABUF_IDX_MASK(_eos_i2s_spk_buf.idx_w + i, _eos_i2s_spk_buf.size)] = sample[i];
}
clear_csr(mstatus, MSTATUS_MIE);
- i2s_spk_buf.idx_w += _ssize;
+ _eos_i2s_spk_buf.idx_w += _ssize;
set_csr(mstatus, MSTATUS_MIE);
return _ssize;
}
int eos_i2s_spk_push8(uint8_t sample) {
- int ret;
-
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_push8(&i2s_spk_buf, sample);
+ int ret = _abuf_push8(&_eos_i2s_spk_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
-
return ret;
}
int eos_i2s_spk_push16(uint16_t sample) {
- int ret;
-
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_push16(&i2s_spk_buf, sample);
+ int ret = _abuf_push16(&_eos_i2s_spk_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
-
return ret;
}
@@ -472,6 +387,6 @@ void eos_i2s_spk_vol_set(int vol) {
i2s_spk_volume = vol;
clear_csr(mstatus, MSTATUS_MIE);
- i2s_cmp_set();
+ _spk_vol_set(vol);
set_csr(mstatus, MSTATUS_MIE);
}
diff --git a/fw/fe310/eos/soc/i2s.h b/fw/fe310/eos/soc/i2s.h
index 81b4ade..f53e183 100644
--- a/fw/fe310/eos/soc/i2s.h
+++ b/fw/fe310/eos/soc/i2s.h
@@ -13,11 +13,9 @@ typedef void (*eos_i2s_handler_t) (unsigned char);
int eos_i2s_init(uint8_t wakeup_cause);
void eos_i2s_init_mux(void);
-void eos_i2s_start(uint32_t sample_rate);
+void eos_i2s_start(uint32_t sample_rate, unsigned char fmt);
void eos_i2s_stop(void);
int eos_i2s_running(void);
-void eos_i2s_set_fmt(unsigned char fmt);
-void eos_i2s_set_mode(unsigned char mode);
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size);
void eos_i2s_mic_set_handler(eos_i2s_handler_t wm_handler);
void eos_i2s_mic_set_wm(uint16_t wm);
diff --git a/fw/fe310/eos/soc/interrupt.h b/fw/fe310/eos/soc/interrupt.h
index a239934..c6252b5 100644
--- a/fw/fe310/eos/soc/interrupt.h
+++ b/fw/fe310/eos/soc/interrupt.h
@@ -1,6 +1,6 @@
#include <stdint.h>
-#include "irq_def.h"
+#include "../irq_def.h"
typedef void (*eos_intr_handler_t) (void);
@@ -10,4 +10,4 @@ void eos_intr_set_handler(uint8_t int_num, eos_intr_handler_t handler);
void eos_intr_set_priority(uint8_t int_num, uint8_t priority);
void eos_intr_enable(uint8_t int_num);
void eos_intr_disable(uint8_t int_num);
-void eos_intr_mask(uint8_t priority); \ No newline at end of file
+void eos_intr_mask(uint8_t priority);
diff --git a/fw/fe310/eos/soc/pwr.c b/fw/fe310/eos/soc/pwr.c
index 802e593..a2adfd4 100644
--- a/fw/fe310/eos/soc/pwr.c
+++ b/fw/fe310/eos/soc/pwr.c
@@ -5,22 +5,14 @@
#include "platform.h"
#include "eos.h"
-#include "event.h"
#include "timer.h"
-#include "spi.h"
-#include "spi_dev.h"
-#include "net.h"
-#include "lcd.h"
-#include "eve/eve.h"
+#include "dev/net.h"
#include "pwr.h"
#define PWR_RTC_SCALE 15
#define PWR_RTC_SFREQ (EOS_TIMER_RTC_FREQ >> PWR_RTC_SCALE)
-static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE];
-static unsigned char power_btn_down;
-
int eos_pwr_init(uint8_t wakeup_cause) {
AON_REG(AON_PMUKEY) = 0x51F15E;
AON_REG(AON_PMUIE) = 0x5;
@@ -44,13 +36,6 @@ uint8_t eos_pwr_reset_cause(void) {
int eos_pwr_sleep(void) {
int rv;
- rv = eos_lcd_sleep();
- if (rv) return rv;
-
- eos_spi_select(EOS_SPI_DEV_EVE);
- eve_pwr_sleep();
- eos_spi_deselect();
-
rv = eos_net_sleep(1000);
if (rv) return rv;
@@ -83,51 +68,3 @@ void eos_pwr_wake_disable(void) {
AON_REG(AON_PMUKEY) = 0x51F15E;
AON_REG(AON_PMUIE) = pmuie;
}
-
-static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char mtype;
-
- if ((buffer == NULL) || (len < 1)) {
- eos_net_bad_handler(type, buffer, len);
- return;
- }
-
- mtype = buffer[0];
- if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) {
- evt_handler[mtype](mtype, buffer, len);
- } else {
- eos_net_bad_handler(type, buffer, len);
- }
-}
-
-static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char level = buffer[1];
-
- eos_net_free(buffer, 0);
- if (!level) {
- power_btn_down = 1;
- return;
- }
- if (!power_btn_down) return;
-
- eos_pwr_sleep();
-}
-
-void eos_pwr_netinit(void) {
- int i;
-
- for (i=0; i<EOS_PWR_MAX_MTYPE; i++) {
- evt_handler[i] = NULL;
- }
- eos_net_set_handler(EOS_NET_MTYPE_POWER, pwr_handle_msg);
- eos_pwr_set_handler(EOS_PWR_MTYPE_BUTTON, pwr_handle_btn);
-}
-
-void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
- if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler;
-}
-
-eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype) {
- if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype];
- return NULL;
-}
diff --git a/fw/fe310/eos/soc/pwr.h b/fw/fe310/eos/soc/pwr.h
index 264436b..1a0d17a 100644
--- a/fw/fe310/eos/soc/pwr.h
+++ b/fw/fe310/eos/soc/pwr.h
@@ -1,9 +1,4 @@
#include <stdint.h>
-#include "event.h"
-
-#define EOS_PWR_MTYPE_BUTTON 1
-
-#define EOS_PWR_MAX_MTYPE 2
#define EOS_PWR_WAKE_RST 0
#define EOS_PWR_WAKE_RTC 1
@@ -19,7 +14,3 @@ uint8_t eos_pwr_reset_cause(void);
int eos_pwr_sleep(void);
void eos_pwr_wake_at(uint32_t msec);
void eos_pwr_wake_disable(void);
-
-void eos_pwr_netinit(void);
-void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler);
-eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/soc/spi.c b/fw/fe310/eos/soc/spi.c
index 05c9448..2c36109 100644
--- a/fw/fe310/eos/soc/spi.c
+++ b/fw/fe310/eos/soc/spi.c
@@ -21,6 +21,8 @@
#define SPI_FLAG_XCHG 0x10
+#define SPI_CSID_NONE 1
+
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
@@ -52,19 +54,7 @@ int eos_spi_init(uint8_t wakeup_cause) {
evt_handler[i] = eos_evtq_bad_handler;
}
eos_evtq_set_handler(EOS_EVT_SPI, spi_handle_evt);
- eos_intr_set(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG, NULL);
-
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << IOF_SPI1_SCK);
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << IOF_SPI1_SCK);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_SCK);
-
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << IOF_SPI1_MOSI);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_MOSI);
-
- GPIO_REG(GPIO_INPUT_EN) |= (1 << IOF_SPI1_MISO);
- GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << IOF_SPI1_MISO);
+ eos_intr_set_priority(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG);
SPI1_REG(SPI_REG_SCKMODE) = SPI_MODE0;
SPI1_REG(SPI_REG_FMT) = SPI_FMT_PROTO(SPI_PROTO_S) |
@@ -72,25 +62,34 @@ int eos_spi_init(uint8_t wakeup_cause) {
SPI_FMT_DIR(SPI_DIR_RX) |
SPI_FMT_LEN(8);
- GPIO_REG(GPIO_IOF_SEL) &= ~SPI_IOF_MASK;
- GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
+ /* for spi 9bit protocol */
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_SCK);
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_MOSI);
+ GPIO_REG(GPIO_INPUT_EN) |= (1 << IOF_SPI1_MISO);
+
+ eos_spi_enable();
// There is no way here to change the CS polarity.
// SPI1_REG(SPI_REG_CSDEF) = 0xFFFF;
return EOS_OK;
}
-void eos_spi_start(uint16_t div, uint8_t csid, uint8_t cspin, unsigned char evt) {
+void eos_spi_configure(uint16_t div, int8_t csid, int8_t cspin, unsigned char evt) {
spi_state_flags = 0;
spi_evt = evt;
SPI1_REG(SPI_REG_SCKDIV) = div;
- SPI1_REG(SPI_REG_CSID) = csid;
- if (csid != SPI_CSID_NONE) {
+ if (csid != -1) {
+ SPI1_REG(SPI_REG_CSID) = csid;
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO;
} else {
spi_cspin = cspin;
+ SPI1_REG(SPI_REG_CSID) = SPI_CSID_NONE;
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_OFF;
}
+}
+
+void eos_spi_start(uint16_t div, int8_t csid, int8_t cspin, unsigned char evt) {
+ eos_spi_configure(div, csid, cspin, evt);
eos_intr_set_handler(INT_SPI1_BASE, eos_spi_handle_xchg);
}
@@ -100,6 +99,19 @@ void eos_spi_stop(void) {
spi_evt = 0;
}
+void eos_spi_enable(void) {
+ eos_intr_enable(INT_SPI1_BASE);
+
+ GPIO_REG(GPIO_IOF_SEL) &= ~SPI_IOF_MASK;
+ GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
+}
+
+void eos_spi_disable(void) {
+ GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK;
+
+ eos_intr_disable(INT_SPI1_BASE);
+}
+
void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler) {
if (handler == NULL) handler = eos_evtq_bad_handler;
if (evt && (evt <= EOS_SPI_MAX_EVT)) evt_handler[evt - 1] = handler;
diff --git a/fw/fe310/eos/soc/spi.h b/fw/fe310/eos/soc/spi.h
index a23a235..0c2de4b 100644
--- a/fw/fe310/eos/soc/spi.h
+++ b/fw/fe310/eos/soc/spi.h
@@ -1,5 +1,5 @@
#include <stdint.h>
-#include "event.h"
+#include "../event.h"
#define EOS_SPI_FLAG_TX 0x01
#define EOS_SPI_FLAG_MORE 0x02
@@ -11,8 +11,12 @@
#define EOS_SPI_MAX_EVT 2
int eos_spi_init(uint8_t wakeup_cause);
-void eos_spi_start(uint16_t div, uint8_t csid, uint8_t cspin, unsigned char evt);
+void eos_spi_configure(uint16_t div, int8_t csid, int8_t cspin, unsigned char evt);
+void eos_spi_start(uint16_t div, int8_t csid, int8_t cspin, unsigned char evt);
void eos_spi_stop(void);
+void eos_spi_enable(void);
+void eos_spi_disable(void);
+
void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler);
void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags);
diff --git a/fw/fe310/eos/soc/spi_priv.h b/fw/fe310/eos/soc/spi_priv.h
index 72c2dae..17081a3 100644
--- a/fw/fe310/eos/soc/spi_priv.h
+++ b/fw/fe310/eos/soc/spi_priv.h
@@ -1,8 +1,5 @@
#include <stdint.h>
-#define SPI_CSID_NONE 1
-#define SPI_CSPIN_NONE 0xff
-
/* DO NOT TOUCH THEESE */
#define SPI_SIZE_CHUNK 4
#define SPI_SIZE_WM 2
diff --git a/fw/fe310/eos/soc/trap_entry.S b/fw/fe310/eos/soc/trap_entry.S
index fb2b121..96024cb 100644
--- a/fw/fe310/eos/soc/trap_entry.S
+++ b/fw/fe310/eos/soc/trap_entry.S
@@ -25,18 +25,6 @@
#define INT_PWM1_BASE 44
#define INT_PWM2_BASE 48
-#define I2S_MIC_BUF (0*4)
-#define I2S_SPK_BUF (1*4)
-#define I2S_FMT (2*4)
-#define I2S_MODE (3*4)
-#define I2S_MIC_WM (4*4)
-#define I2S_SPK_WM (5*4)
-#define I2S_MIC_EVT (6*4)
-#define I2S_SPK_EVT (7*4)
-#define I2S_MIC_CMP2 (8*4)
-#define I2S_MIC_CMP3 (9*4)
-#define I2S_SAMPLE (10*4)
-
#include "board.h"
#include "irq_def.h"
#include "evt_def.h"
@@ -49,7 +37,7 @@
.global eos_trap_entry
eos_trap_entry:
- addi sp, sp, -12*REGBYTES
+ addi sp, sp, -8*REGBYTES
STORE x8, 0*REGBYTES(sp)
STORE x9, 1*REGBYTES(sp)
STORE x18, 2*REGBYTES(sp)
@@ -58,10 +46,6 @@ eos_trap_entry:
STORE x21, 5*REGBYTES(sp)
STORE x22, 6*REGBYTES(sp)
STORE x23, 7*REGBYTES(sp)
- STORE x24, 8*REGBYTES(sp) # format: 0 - PCM16; 1 - ALAW
- STORE x25, 9*REGBYTES(sp) # mode: 0 - stereo; 1 - mono
- STORE x26, 10*REGBYTES(sp) # channel: 0 - left; 1 - right
- STORE x27, 11*REGBYTES(sp) # _eos_event_q addr
csrr x8, mcause
li x18, MCAUSE_EXT
@@ -100,68 +84,34 @@ evtq_push:
jalr x0, x21
i2s_handle_sd:
- li x8, I2S_CTRL_ADDR_WS_SPK
- lw x18, PWM_COUNT(x8)
- lw x19, PWM_CMP3(x8)
-
# exit if too early
- bltu x18, x19, i2s_sd_exit
-
- la x27, _eos_i2s_drvr
-
- # move CMPs for next channel and store channel bit to x26
- lw x20, I2S_MIC_CMP2(x27)
- lw x21, I2S_MIC_CMP3(x27) # 16-bit period
-
- add x23, x19, x20
- add x24, x23, x21
- slli x20, x21, 1 # 32-bit period
- slli x21, x20, 1 # 64-bit period
- bltu x24, x21, 0f
- neg x21, x21
- add x23, x23, x21
- add x24, x24, x21
-0:
- li x26, 0
- bltu x23, x20, 0f
- li x26, 1
-0:
- bltu x19, x20, 0f
- neg x20, x20
+ li x18, I2S_CTRL_ADDR_WS_SPK
+ lw x8, PWM_COUNT(x18)
+ lw x9, PWM_CMP3(x18)
+ bltu x8, x9, i2s_handle_sd_exit
+
+ # disable sd irq
li x18, PLIC_PRIORITY
sw x0, 4*I2S_IRQ_SD_ID(x18)
-0:
- add x19, x19, x20
- li x9, I2S_CTRL_ADDR_WS_MIC
- sw x19, PWM_CMP3(x8)
- sw x23, PWM_CMP2(x9)
- sw x24, PWM_CMP3(x9)
-
- lw x24, I2S_FMT(x27)
- lw x25, I2S_MODE(x27)
+ la x9, _eos_i2s_fmt
+ lw x23, 0(x9)
i2s_abuf_pop:
- and x8, x25, x26
- beqz x8, 0f
-
- lw x8, I2S_SAMPLE(x27)
- j i2s_sd_xchg
-0:
# pop from spk buf -> x8
- lw x9, I2S_SPK_BUF(x27)
- beqz x9, i2s_sd_xchg
+ mv x8, x0
+ la x9, _eos_i2s_spk_buf
lhu x18, I2S_ABUF_OFF_IDXR(x9)
lhu x19, I2S_ABUF_OFF_IDXW(x9)
lhu x20, I2S_ABUF_OFF_SIZE(x9)
- beq x18, x19, 2f
+ beq x18, x19, i2s_handle_sd_xchg
addi x20, x20, -1
and x20, x20, x18
lw x21, I2S_ABUF_OFF_ARRAY(x9)
add x21, x21, x20
- beqz x24, 0f
+ beqz x23, 0f
lbu x8, 0(x21)
addi x18, x18, 1
j 1f
@@ -174,18 +124,20 @@ i2s_abuf_pop:
1:
sh x18, I2S_ABUF_OFF_IDXR(x9)
-2:
li x21, 0xffff
sub x18, x19, x18
and x18, x18, x21
# check for push to event queue
- lw x9, I2S_SPK_WM(x27)
- bgtu x18, x9, i2s_decode
+ la x9, _eos_i2s_spk_wm
+ lw x20, 0(x9)
+ beqz x20, i2s_decode
+ bgtu x18, x20, i2s_decode
- lw x9, I2S_SPK_EVT(x27)
- beqz x9, i2s_decode
- sw x0, I2S_SPK_EVT(x27)
+ la x9, _eos_i2s_spk_evt_enable
+ lw x18, 0(x9)
+ beqz x18, i2s_decode
+ sw x0, 0(x9)
# push to event queue
jal x22, evtq_push
@@ -194,7 +146,7 @@ i2s_abuf_pop:
sb x18, MSGQ_ITEM_OFF_TYPE(x21)
i2s_decode:
- beqz x24, 3f
+ beqz x23, i2s_handle_sd_xchg
# aLaw decode -> x8
xori x8, x8, 0x55
andi x9, x8, 0x80
@@ -229,13 +181,10 @@ i2s_decode:
slli x8, x8, 1
ori x8, x8, 1
2:
- beqz x9, 3f
+ beqz x9, i2s_handle_sd_xchg
mul x8, x8, x9
-3:
- beqz x25, i2s_sd_xchg
- sw x8, I2S_SAMPLE(x27)
-i2s_sd_xchg:
+i2s_handle_sd_xchg:
# read/write shift reg: x8 -> sr -> x8
li x18, GPIO_CTRL_ADDR
li x19, (0x1 << I2S_PIN_SD_IN)
@@ -285,15 +234,17 @@ i2s_sd_xchg:
xor x22, x22, x21
sw x22, GPIO_OUTPUT_VAL(x18)
- addi x23, x23, -1
- bnez x23, 0b
-
# idle
li x9, I2S_IDLE_CYCLES
1:
addi x9, x9, -1
bnez x9, 1b
+ addi x23, x23, -1
+ beqz x23, 2f
+ j 0b
+
+2:
# 74HC595 ck low (I2S_PIN_CK_SR high)
xor x22, x22, x21
sw x22, GPIO_OUTPUT_VAL(x18)
@@ -305,8 +256,11 @@ i2s_sd_xchg:
slli x8, x8, 16
srai x8, x8, 16
+ la x9, _eos_i2s_fmt
+ lw x23, 0(x9)
+
i2s_encode:
- beqz x24, i2s_abuf_push
+ beqz x23, i2s_abuf_push
# aLaw encode -> x8
li x18, 0x800
li x19, 7
@@ -338,12 +292,8 @@ i2s_encode:
andi x8, x8, 0xff
i2s_abuf_push:
- # check channel
- # bnez x26, i2s_sd_exit
-
# push to mic buf
- lw x9, I2S_MIC_BUF(x27)
- beqz x9, i2s_sd_exit
+ la x9, _eos_i2s_mic_buf
lhu x18, I2S_ABUF_OFF_IDXR(x9)
lhu x19, I2S_ABUF_OFF_IDXW(x9)
lhu x20, I2S_ABUF_OFF_SIZE(x9)
@@ -351,13 +301,13 @@ i2s_abuf_push:
sub x18, x19, x18
and x18, x18, x21
- beq x18, x20, 2f
+ beq x18, x20, i2s_handle_sd_exit
addi x20, x20, -1
and x20, x20, x19
lw x21, I2S_ABUF_OFF_ARRAY(x9)
add x21, x21, x20
- beqz x24, 0f
+ beqz x23, 0f
sb x8, 0(x21)
addi x19, x19, 1
addi x18, x18, 1
@@ -371,22 +321,24 @@ i2s_abuf_push:
1:
sh x19, I2S_ABUF_OFF_IDXW(x9)
-2:
# check for push to event queue
- lw x9, I2S_MIC_WM(x27)
- bltu x18, x9, i2s_sd_exit
+ la x9, _eos_i2s_mic_wm
+ lw x20, 0(x9)
+ beqz x20, i2s_handle_sd_exit
+ bltu x18, x20, i2s_handle_sd_exit
- lw x9, I2S_MIC_EVT(x27)
- beqz x9, i2s_sd_exit
- sw x0, I2S_MIC_EVT(x27)
+ la x9, _eos_i2s_mic_evt_enable
+ lw x18, 0(x9)
+ beqz x18, i2s_handle_sd_exit
+ sw x0, 0(x9)
# push to event queue
jal x22, evtq_push
- beqz x21, i2s_sd_exit
+ beqz x21, i2s_handle_sd_exit
li x18, (EOS_EVT_I2S | EOS_I2S_ETYPE_MIC)
sb x18, MSGQ_ITEM_OFF_TYPE(x21)
-i2s_sd_exit:
+i2s_handle_sd_exit:
# complete
li x18, I2S_IRQ_SD_ID
li x19, PLIC_CLAIM
@@ -443,6 +395,16 @@ _eos_i2s_start_pwm:
ret
+.global _eos_flash_set
+_eos_flash_set:
+ li a3, SPI0_CTRL_ADDR
+ sw x0, SPI_REG_FCTRL(a3)
+ sw a0, SPI_REG_SCKDIV(a3)
+ sw a1, SPI_REG_FFMT(a3)
+ li a0, 1
+ sw a0, SPI_REG_FCTRL(a3)
+ ret
+
trap_exit_data:
# Remain in M-mode after mret
li x18, MSTATUS_MPP
@@ -456,11 +418,7 @@ trap_exit_data:
LOAD x21, 5*REGBYTES(sp)
LOAD x22, 6*REGBYTES(sp)
LOAD x23, 7*REGBYTES(sp)
- LOAD x24, 8*REGBYTES(sp)
- LOAD x25, 9*REGBYTES(sp)
- LOAD x26, 10*REGBYTES(sp)
- LOAD x27, 11*REGBYTES(sp)
- addi sp, sp, 12*REGBYTES
+ addi sp, sp, 8*REGBYTES
mret
@@ -473,7 +431,7 @@ handle_intr:
.align 4
trap_entry_text:
- addi sp, sp, -20*REGBYTES
+ addi sp, sp, -24*REGBYTES
STORE x1, 0*REGBYTES(sp)
STORE x2, 1*REGBYTES(sp)
@@ -490,10 +448,14 @@ trap_entry_text:
STORE x15, 12*REGBYTES(sp)
STORE x16, 13*REGBYTES(sp)
STORE x17, 14*REGBYTES(sp)
- STORE x28, 15*REGBYTES(sp)
- STORE x29, 16*REGBYTES(sp)
- STORE x30, 17*REGBYTES(sp)
- STORE x31, 18*REGBYTES(sp)
+ STORE x24, 15*REGBYTES(sp)
+ STORE x25, 16*REGBYTES(sp)
+ STORE x26, 17*REGBYTES(sp)
+ STORE x27, 18*REGBYTES(sp)
+ STORE x28, 19*REGBYTES(sp)
+ STORE x29, 20*REGBYTES(sp)
+ STORE x30, 21*REGBYTES(sp)
+ STORE x31, 22*REGBYTES(sp)
li x18, MCAUSE_TIMER
beq x8, x18, handle_timer
@@ -511,6 +473,7 @@ handle_ext:
call eos_intr_handle
li x18, PLIC_CLAIM
sw a0, 0(x18)
+ j trap_exit_text
trap_exit_text:
# Remain in M-mode after mret
@@ -532,23 +495,23 @@ trap_exit_text:
LOAD x15, 12*REGBYTES(sp)
LOAD x16, 13*REGBYTES(sp)
LOAD x17, 14*REGBYTES(sp)
- LOAD x28, 15*REGBYTES(sp)
- LOAD x29, 16*REGBYTES(sp)
- LOAD x30, 17*REGBYTES(sp)
- LOAD x31, 18*REGBYTES(sp)
-
- LOAD x8, 20*REGBYTES(sp)
- LOAD x9, 21*REGBYTES(sp)
- LOAD x18, 22*REGBYTES(sp)
- LOAD x19, 23*REGBYTES(sp)
- LOAD x20, 24*REGBYTES(sp)
- LOAD x21, 25*REGBYTES(sp)
- LOAD x22, 26*REGBYTES(sp)
- LOAD x23, 27*REGBYTES(sp)
- LOAD x24, 28*REGBYTES(sp)
- LOAD x25, 29*REGBYTES(sp)
- LOAD x26, 30*REGBYTES(sp)
- LOAD x27, 31*REGBYTES(sp)
+ LOAD x24, 15*REGBYTES(sp)
+ LOAD x25, 16*REGBYTES(sp)
+ LOAD x26, 17*REGBYTES(sp)
+ LOAD x27, 18*REGBYTES(sp)
+ LOAD x28, 19*REGBYTES(sp)
+ LOAD x29, 20*REGBYTES(sp)
+ LOAD x30, 21*REGBYTES(sp)
+ LOAD x31, 22*REGBYTES(sp)
+
+ LOAD x8, 24*REGBYTES(sp)
+ LOAD x9, 25*REGBYTES(sp)
+ LOAD x18, 26*REGBYTES(sp)
+ LOAD x19, 27*REGBYTES(sp)
+ LOAD x20, 28*REGBYTES(sp)
+ LOAD x21, 29*REGBYTES(sp)
+ LOAD x22, 30*REGBYTES(sp)
+ LOAD x23, 31*REGBYTES(sp)
addi sp, sp, 32*REGBYTES
mret
diff --git a/fw/fe310/eos/soc/uart.c b/fw/fe310/eos/soc/uart.c
index 30f76d9..589832a 100644
--- a/fw/fe310/eos/soc/uart.c
+++ b/fw/fe310/eos/soc/uart.c
@@ -9,6 +9,7 @@
#include "eos.h"
#include "interrupt.h"
#include "event.h"
+#include "i2s.h"
#include "uart.h"
@@ -44,22 +45,30 @@ int eos_uart_init(uint8_t wakeup_cause) {
eos_evtq_set_handler(EOS_EVT_UART, uart_handle_evt);
eos_intr_set(INT_UART0_BASE, IRQ_PRIORITY_UART, uart_handle_intr);
- UART0_REG(UART_REG_TXCTRL) |= UART_TXEN;
- UART0_REG(UART_REG_RXCTRL) |= UART_RXEN;
-
eos_uart_speed(EOS_UART_SPEED);
- eos_uart_start();
+
+ eos_uart_enable();
return EOS_OK;
}
-void eos_uart_start(void) {
+void eos_uart_enable(void) {
+ UART0_REG(UART_REG_TXCTRL) |= UART_TXEN;
+ UART0_REG(UART_REG_RXCTRL) |= UART_RXEN;
+
GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK;
GPIO_REG(GPIO_IOF_EN) |= IOF0_UART0_MASK;
}
-void eos_uart_stop(void) {
+void eos_uart_disable(void) {
GPIO_REG(GPIO_IOF_EN) &= ~IOF0_UART0_MASK;
+
+ UART0_REG(UART_REG_TXCTRL) &= ~UART_TXEN;
+ UART0_REG(UART_REG_RXCTRL) &= ~UART_RXEN;
+}
+
+int eos_uart_enabled(void) {
+ return !!(GPIO_REG(GPIO_IOF_EN) & IOF0_UART0_MASK);
}
void eos_uart_speed(uint32_t baud_rate) {
@@ -90,8 +99,8 @@ void eos_uart_rxwm_clear(void) {
UART0_REG(UART_REG_IE) &= ~UART_IP_RXWM;
}
-int eos_uart_putc(int c, char b) {
- if (b) {
+int eos_uart_putc(int c, int block) {
+ if (block) {
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000);
UART0_REG(UART_REG_TXFIFO) = c & 0xff;
} else {
@@ -101,14 +110,14 @@ int eos_uart_putc(int c, char b) {
return EOS_OK;
}
-int eos_uart_getc(char b) {
+int eos_uart_getc(int block) {
volatile uint32_t r;
- if (b) {
+ if (block) {
while ((r = UART0_REG(UART_REG_RXFIFO)) & 0x80000000);
} else {
r = UART0_REG(UART_REG_RXFIFO);
if (r & 0x80000000) return EOS_ERR_EMPTY;
}
return r & 0xff;
-} \ No newline at end of file
+}
diff --git a/fw/fe310/eos/soc/uart.h b/fw/fe310/eos/soc/uart.h
index 94999e6..caaf6c6 100644
--- a/fw/fe310/eos/soc/uart.h
+++ b/fw/fe310/eos/soc/uart.h
@@ -10,8 +10,9 @@
typedef void (*eos_uart_handler_t) (unsigned char);
int eos_uart_init(uint8_t wakeup_cause);
-void eos_uart_start(void);
-void eos_uart_stop(void);
+void eos_uart_enable(void);
+void eos_uart_disable(void);
+int eos_uart_enabled(void);
void eos_uart_speed(uint32_t baud_rate);
void eos_uart_set_handler(unsigned char type, eos_uart_handler_t handler);
@@ -20,5 +21,5 @@ void eos_uart_txwm_set(uint8_t wm);
void eos_uart_txwm_clear(void);
void eos_uart_rxwm_set(uint8_t wm);
void eos_uart_rxwm_clear(void);
-int eos_uart_putc(int c, char b);
-int eos_uart_getc(char b); \ No newline at end of file
+int eos_uart_putc(int c, int block);
+int eos_uart_getc(int block); \ No newline at end of file