summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/Makefile19
-rw-r--r--fw/fe310/eos/Makefile12
-rw-r--r--fw/fe310/eos/board.h28
-rw-r--r--fw/fe310/eos/dev/Makefile20
-rw-r--r--fw/fe310/eos/dev/bq25895.c (renamed from fw/fe310/eos/i2c/bq25895.c)7
-rw-r--r--fw/fe310/eos/dev/bq25895.h (renamed from fw/fe310/eos/i2c/bq25895.h)0
-rw-r--r--fw/fe310/eos/dev/cam.c (renamed from fw/fe310/eos/cam.c)10
-rw-r--r--fw/fe310/eos/dev/cam.h (renamed from fw/fe310/eos/cam.h)0
-rw-r--r--fw/fe310/eos/dev/drv2605.h (renamed from fw/fe310/eos/i2c/drv2605.h)0
-rw-r--r--fw/fe310/eos/dev/eve.c152
-rw-r--r--fw/fe310/eos/dev/eve.h9
-rw-r--r--fw/fe310/eos/dev/lsm9ds1.h (renamed from fw/fe310/eos/i2c/lsm9ds1.h)0
-rw-r--r--fw/fe310/eos/dev/net.c (renamed from fw/fe310/eos/net.c)19
-rw-r--r--fw/fe310/eos/dev/net.h (renamed from fw/fe310/eos/net.h)2
-rw-r--r--fw/fe310/eos/dev/ov2640.c (renamed from fw/fe310/eos/i2c/ov2640.c)6
-rw-r--r--fw/fe310/eos/dev/ov2640.h (renamed from fw/fe310/eos/i2c/ov2640.h)0
-rw-r--r--fw/fe310/eos/dev/ov2640_regs.h (renamed from fw/fe310/eos/i2c/ov2640_regs.h)0
-rw-r--r--fw/fe310/eos/dev/sdc_crypto.c (renamed from fw/fe310/eos/sdc_crypto.c)2
-rw-r--r--fw/fe310/eos/dev/sdc_crypto.h (renamed from fw/fe310/eos/sdc_crypto.h)2
-rw-r--r--fw/fe310/eos/dev/sdcard.c (renamed from fw/fe310/eos/sdcard.c)30
-rw-r--r--fw/fe310/eos/dev/sdcard.h (renamed from fw/fe310/eos/sdcard.h)0
-rw-r--r--fw/fe310/eos/dev/spi.c (renamed from fw/fe310/eos/spi_dev.c)42
-rw-r--r--fw/fe310/eos/dev/spi.h (renamed from fw/fe310/eos/spi_dev.h)2
-rw-r--r--fw/fe310/eos/dev/spi_cfg.h (renamed from fw/fe310/eos/spi_cfg.h)21
-rw-r--r--fw/fe310/eos/eos.c71
-rw-r--r--fw/fe310/eos/eos.h4
-rw-r--r--fw/fe310/eos/eve/Makefile18
-rw-r--r--fw/fe310/eos/eve/eve.c47
-rw-r--r--fw/fe310/eos/eve/eve.h12
-rwxr-xr-xfw/fe310/eos/eve/eve_def.h4
-rw-r--r--fw/fe310/eos/eve/eve_eos.c104
-rw-r--r--fw/fe310/eos/eve/eve_eos.h6
-rw-r--r--fw/fe310/eos/eve/eve_phy.c30
-rw-r--r--fw/fe310/eos/eve/eve_phy.h6
-rw-r--r--fw/fe310/eos/eve/eve_platform.c14
-rw-r--r--fw/fe310/eos/eve/eve_platform.h14
-rw-r--r--fw/fe310/eos/eve/eve_touch.c497
-rw-r--r--fw/fe310/eos/eve/eve_touch.h26
-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.c39
-rw-r--r--fw/fe310/eos/eve/eve_vtrack.h14
-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.c155
-rw-r--r--fw/fe310/eos/eve/screen/page.h19
-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.c43
-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/event.c28
-rw-r--r--fw/fe310/eos/event.h1
-rw-r--r--fw/fe310/eos/evt_def.h3
-rw-r--r--fw/fe310/eos/i2c/Makefile15
-rw-r--r--fw/fe310/eos/irq_def.h3
-rw-r--r--fw/fe310/eos/lcd.c522
-rw-r--r--fw/fe310/eos/lcd.h12
-rw-r--r--fw/fe310/eos/net/Makefile19
-rw-r--r--fw/fe310/eos/net/cell.c (renamed from fw/fe310/eos/cell.c)4
-rw-r--r--fw/fe310/eos/net/cell.h (renamed from fw/fe310/eos/cell.h)20
-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.c (renamed from fw/fe310/eos/rng.c)2
-rw-r--r--fw/fe310/eos/net/rng.h (renamed from fw/fe310/eos/rng.h)0
-rw-r--r--fw/fe310/eos/net/sock.c (renamed from fw/fe310/eos/sock.c)29
-rw-r--r--fw/fe310/eos/net/sock.h (renamed from fw/fe310/eos/sock.h)4
-rw-r--r--fw/fe310/eos/net/wifi.c179
-rw-r--r--fw/fe310/eos/net/wifi.h27
-rw-r--r--fw/fe310/eos/pwr.c133
-rw-r--r--fw/fe310/eos/soc/Makefile20
-rw-r--r--fw/fe310/eos/soc/i2c.c (renamed from fw/fe310/eos/i2c.c)12
-rw-r--r--fw/fe310/eos/soc/i2c.h (renamed from fw/fe310/eos/i2c.h)6
-rw-r--r--fw/fe310/eos/soc/i2s.c (renamed from fw/fe310/eos/i2s.c)217
-rw-r--r--fw/fe310/eos/soc/i2s.h (renamed from fw/fe310/eos/i2s.h)4
-rw-r--r--fw/fe310/eos/soc/i2s_def.h (renamed from fw/fe310/eos/i2s_def.h)0
-rw-r--r--fw/fe310/eos/soc/i2s_priv.h (renamed from fw/fe310/eos/i2s_priv.h)0
-rw-r--r--fw/fe310/eos/soc/interrupt.c (renamed from fw/fe310/eos/interrupt.c)0
-rw-r--r--fw/fe310/eos/soc/interrupt.h (renamed from fw/fe310/eos/interrupt.h)4
-rw-r--r--fw/fe310/eos/soc/pwr.c70
-rw-r--r--fw/fe310/eos/soc/pwr.h (renamed from fw/fe310/eos/pwr.h)9
-rw-r--r--fw/fe310/eos/soc/spi.c (renamed from fw/fe310/eos/spi.c)48
-rw-r--r--fw/fe310/eos/soc/spi.h (renamed from fw/fe310/eos/spi.h)8
-rw-r--r--fw/fe310/eos/soc/spi_priv.h (renamed from fw/fe310/eos/spi_priv.h)3
-rw-r--r--fw/fe310/eos/soc/timer.c (renamed from fw/fe310/eos/timer.c)19
-rw-r--r--fw/fe310/eos/soc/timer.h (renamed from fw/fe310/eos/timer.h)6
-rw-r--r--fw/fe310/eos/soc/trap_entry.S (renamed from fw/fe310/eos/trap_entry.S)205
-rw-r--r--fw/fe310/eos/soc/uart.c (renamed from fw/fe310/eos/uart.c)31
-rw-r--r--fw/fe310/eos/soc/uart.h (renamed from fw/fe310/eos/uart.h)9
-rw-r--r--fw/fe310/eos/wifi.c106
-rw-r--r--fw/fe310/eos/wifi.h18
-rw-r--r--fw/fe310/test/Makefile30
-rw-r--r--fw/fe310/test/app/app_root.c4
-rw-r--r--fw/fe310/test/app/app_root.h2
-rw-r--r--fw/fe310/test/fs.c25
-rw-r--r--fw/fe310/test/main.c22
115 files changed, 2037 insertions, 2163 deletions
diff --git a/fw/fe310/Makefile b/fw/fe310/Makefile
index f9da883..70bacff 100644
--- a/fw/fe310/Makefile
+++ b/fw/fe310/Makefile
@@ -5,25 +5,24 @@ MAKEFLAGS += -I$(fe310_dir)
include $(crypto_dir)/crypto_obj.mk
obj_crypto = $(addprefix $(crypto_dir)/,$(obj_dep))
-subdirs = bsp/drivers bsp/gloss bsp/metal eos eos/i2c eos/eve eos/eve/screen eos/eve/widget $(ext_dir)/fsfat
+subdirs_bsp = bsp/drivers bsp/gloss bsp/metal
+subdirs_ext = $(crypto_dir) $(ext_dir)/fsfat
+subdirs = eos eos/soc eos/dev eos/net eos/eve $(subdirs_bsp) $(subdirs_ext)
-all: libeos.a
%.o: %.c
$(CC) $(CFLAGS) -c $<
-libeos.a:
- for i in $(subdirs) $(crypto_dir); do \
- (cd $$i && $(MAKE)) || exit; \
- done
- rm -f $@
+all:
+ rm -f *.a
for i in $(subdirs); do \
- $(AR) rcs $@ $$i/*.o; \
+ (cd $$i && $(MAKE)) || exit; \
done
- $(AR) rcs $@ $(obj_crypto)
+ $(AR) rcs libeos-bsp.a $(addsuffix /*.o,$(subdirs_bsp))
+ $(AR) rcs libeos-ext.a $(obj_crypto) $(ext_dir)/fsfat/*.o
clean:
- for i in $(subdirs) $(crypto_dir); do \
+ for i in $(subdirs); do \
(cd $$i && $(MAKE) clean) || exit; \
done
rm -f *.o *.a
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index a52b5db..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 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
new file mode 100644
index 0000000..7407212
--- /dev/null
+++ b/fw/fe310/eos/dev/Makefile
@@ -0,0 +1,20 @@
+include ../../common.mk
+CFLAGS += -I$(bsp_dir)/include -I$(ext_dir)/crypto
+
+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
+ $(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/i2c/bq25895.c b/fw/fe310/eos/dev/bq25895.c
index 570e9a0..11323c7 100644
--- a/fw/fe310/eos/i2c/bq25895.c
+++ b/fw/fe310/eos/dev/bq25895.c
@@ -3,9 +3,10 @@
#include <stdio.h>
#include "eos.h"
-#include "pwr.h"
-#include "i2c.h"
-#include "i2c/bq25895.h"
+#include "soc/pwr.h"
+#include "soc/i2c.h"
+
+#include "bq25895.h"
static int reg_read(uint8_t reg, uint8_t *data) {
return eos_i2c_read8(BQ25895_ADDR, reg, data, 1);
diff --git a/fw/fe310/eos/i2c/bq25895.h b/fw/fe310/eos/dev/bq25895.h
index cbef36e..cbef36e 100644
--- a/fw/fe310/eos/i2c/bq25895.h
+++ b/fw/fe310/eos/dev/bq25895.h
diff --git a/fw/fe310/eos/cam.c b/fw/fe310/eos/dev/cam.c
index 43293af..50a0bdd 100644
--- a/fw/fe310/eos/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/cam.h b/fw/fe310/eos/dev/cam.h
index f61757b..f61757b 100644
--- a/fw/fe310/eos/cam.h
+++ b/fw/fe310/eos/dev/cam.h
diff --git a/fw/fe310/eos/i2c/drv2605.h b/fw/fe310/eos/dev/drv2605.h
index fe90a9b..fe90a9b 100644
--- a/fw/fe310/eos/i2c/drv2605.h
+++ b/fw/fe310/eos/dev/drv2605.h
diff --git a/fw/fe310/eos/dev/eve.c b/fw/fe310/eos/dev/eve.c
new file mode 100644
index 0000000..0f98fed
--- /dev/null
+++ b/fw/fe310/eos/dev/eve.c
@@ -0,0 +1,152 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "platform.h"
+
+#include "eos.h"
+#include "event.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.h"
+
+static void handle_time(unsigned char type) {
+ 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 (!eos_eve_running()) return;
+
+ eve_spi_start();
+ eve_handle_intr();
+ eve_spi_stop();
+
+ GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
+}
+
+static void handle_intr(void) {
+ GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
+ GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR);
+ 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_LOW_IE) |= (1 << EVE_PIN_INTR);
+
+ eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR);
+}
+
+static void _stop(void) {
+ 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) {
+ int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
+ int rv = EVE_OK;
+
+ eve_spi_start();
+ if (rst) {
+ rv = eve_init();
+ if (!rv) {
+ eve_gpio_set_dir(EVE_GPIO_DIR);
+ eve_touch_init_engine();
+ }
+ } else {
+ eve_activate();
+ }
+ eve_spi_stop();
+
+ if (rv) return EOS_ERR;
+
+ eve_touch_init();
+
+ eos_evtq_set_handler(EOS_EVT_EVE, handle_evt);
+ eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time);
+ eos_intr_set_handler(INT_GPIO_BASE + EVE_PIN_INTR, handle_intr);
+ eos_intr_set_priority(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_EVE);
+
+ return EOS_OK;
+}
+
+void eos_eve_calibrate(void) {
+ uint32_t matrix[6];
+ int r;
+
+ eve_spi_start();
+
+ eve_brightness(0x40);
+ eve_touch_set_extended(0);
+
+ eve_cmd(CMD_TEXT, "hhhhs", EVE_HSIZE/2, EVE_VSIZE/2, 27, EVE_OPT_CENTER, "Please tap on the dot.");
+ eve_cmd(CMD_CALIBRATE, "w", 0);
+ eve_cmd_exec(0);
+
+ do {
+ r = eve_cmd_done();
+ if (r < 0) break;
+ eve_spi_stop();
+ eos_evtq_exec();
+ eve_spi_start();
+ } while (!r);
+
+ eve_touch_set_extended(1);
+ eve_brightness(0);
+
+ 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", 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) {
+ eve_spi_start();
+ _start();
+ eve_start_clk();
+ eve_spi_stop();
+
+ return EOS_OK;
+}
+
+void eos_eve_start(void) {
+ eve_spi_start();
+ _start();
+ eve_spi_stop();
+}
+
+void eos_eve_stop(void) {
+ eve_spi_start();
+ _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/dev/eve.h b/fw/fe310/eos/dev/eve.h
new file mode 100644
index 0000000..8eb982f
--- /dev/null
+++ b/fw/fe310/eos/dev/eve.h
@@ -0,0 +1,9 @@
+#include <stdint.h>
+
+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/i2c/lsm9ds1.h b/fw/fe310/eos/dev/lsm9ds1.h
index 92220e7..92220e7 100644
--- a/fw/fe310/eos/i2c/lsm9ds1.h
+++ b/fw/fe310/eos/dev/lsm9ds1.h
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/dev/net.c
index e10414c..d287e5a 100644
--- a/fw/fe310/eos/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"
@@ -213,6 +214,7 @@ static void net_handle_cts(void) {
static void net_handle_rts(void) {
uint32_t rts_offset = (1 << NET_PIN_RTS);
+
if (GPIO_REG(GPIO_RISE_IP) & rts_offset) {
GPIO_REG(GPIO_RISE_IP) = rts_offset;
net_state_flags |= NET_STATE_FLAG_RTS;
@@ -302,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) {
@@ -327,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/net.h b/fw/fe310/eos/dev/net.h
index 79caf4b..2482a32 100644
--- a/fw/fe310/eos/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/i2c/ov2640.c b/fw/fe310/eos/dev/ov2640.c
index 6e54f10..e84a59b 100644
--- a/fw/fe310/eos/i2c/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/i2c/ov2640.h b/fw/fe310/eos/dev/ov2640.h
index 3d08c2a..3d08c2a 100644
--- a/fw/fe310/eos/i2c/ov2640.h
+++ b/fw/fe310/eos/dev/ov2640.h
diff --git a/fw/fe310/eos/i2c/ov2640_regs.h b/fw/fe310/eos/dev/ov2640_regs.h
index deb7521..deb7521 100644
--- a/fw/fe310/eos/i2c/ov2640_regs.h
+++ b/fw/fe310/eos/dev/ov2640_regs.h
diff --git a/fw/fe310/eos/sdc_crypto.c b/fw/fe310/eos/dev/sdc_crypto.c
index c094468..f0e935d 100644
--- a/fw/fe310/eos/sdc_crypto.c
+++ b/fw/fe310/eos/dev/sdc_crypto.c
@@ -48,4 +48,4 @@ void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer) {
memcpy(iv, &sect, sizeof(sect));
sdc_crypto->enc_essiv(sdc_crypto->ctx_essiv, iv);
sdc_crypto->dec(sdc_crypto->ctx, iv, buffer, 512);
-} \ No newline at end of file
+}
diff --git a/fw/fe310/eos/sdc_crypto.h b/fw/fe310/eos/dev/sdc_crypto.h
index 015bf8a..6442547 100644
--- a/fw/fe310/eos/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/sdcard.c b/fw/fe310/eos/dev/sdcard.c
index 6f5488d..fa316c7 100644
--- a/fw/fe310/eos/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"
@@ -94,8 +94,8 @@ static uint16_t sdc_crc16(uint16_t crc, uint8_t b) {
return crc;
}
-static uint32_t sdc_nto(uint64_t start, uint32_t timeout) {
- uint32_t d = eos_time_since(start);
+static uint32_t sdc_nto(uint32_t start, uint32_t timeout) {
+ uint32_t d = eos_time_delta_ms(start);
return (d > timeout) ? 0 : timeout - d;
}
@@ -167,12 +167,12 @@ static int sdc_xchg_cmd(uint8_t cmd, uint32_t arg, uint8_t flags) {
static int sdc_ready(uint32_t timeout) {
uint8_t d = 0;
- uint64_t start;
+ uint32_t start;
if (timeout == 0) return EOS_ERR_BUSY;
start = eos_time_get_tick();
do {
- if (eos_time_since(start) > timeout) break;
+ if (eos_time_delta_ms(start) > timeout) break;
d = sdc_xchg8(0xff);
} while (d != 0xff);
if (d != 0xff) return EOS_ERR_BUSY;
@@ -182,12 +182,12 @@ static int sdc_ready(uint32_t timeout) {
static int sdc_block_read(uint8_t *buffer, uint16_t len, uint32_t timeout) {
uint8_t token = 0xff;
- uint64_t start;
+ uint32_t start;
if (timeout == 0) return EOS_ERR_BUSY;
start = eos_time_get_tick();
do {
- if (eos_time_since(start) > timeout) break;
+ if (eos_time_delta_ms(start) > timeout) break;
token = sdc_xchg8(0xff);
} while (token == 0xff);
if (token == 0xff) return EOS_ERR_BUSY;
@@ -236,7 +236,7 @@ static int sdc_cmd(uint8_t cmd, uint32_t arg, uint8_t flags, uint32_t timeout) {
static int sdc_acmd(uint8_t cmd, uint32_t arg, uint8_t flags, uint32_t timeout) {
int rv;
- uint64_t start;
+ uint32_t start;
start = eos_time_get_tick();
rv = sdc_cmd(APP_CMD, 0, flags, timeout);
@@ -253,7 +253,7 @@ static int sdc_init(uint32_t timeout) {
int rv, i;
uint8_t _type;
uint8_t ocr[4];
- uint64_t start;
+ uint32_t start;
start = eos_time_get_tick();
eos_time_sleep(100);
@@ -378,7 +378,7 @@ uint8_t eos_sdc_cap(void) {
int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors) {
int rv;
uint8_t csd[16];
- uint64_t start = eos_time_get_tick();
+ uint32_t start = eos_time_get_tick();
sdc_select();
rv = sdc_cmd(SEND_CSD, 0, SDC_CMD_FLAG_NOCS, timeout);
@@ -404,7 +404,7 @@ int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors) {
int eos_sdc_get_blk_size(uint32_t timeout, uint32_t *size) {
int rv;
uint8_t rbl[64]; /* SD Status or CSD register */
- uint64_t start = eos_time_get_tick();
+ uint32_t start = eos_time_get_tick();
sdc_select();
if (sdc_type & EOS_SDC_TYPE_SDC2) {
@@ -444,7 +444,7 @@ int eos_sdc_sync(uint32_t timeout) {
int eos_sdc_erase(uint32_t blk_start, uint32_t blk_end, uint32_t timeout) {
int rv;
- uint64_t start;
+ uint32_t start;
if (!(sdc_type & EOS_SDC_TYPE_SDC)) return EOS_ERR;
if (!(sdc_type & EOS_SDC_CAP_ERASE_EN)) return EOS_ERR;
@@ -468,11 +468,9 @@ int eos_sdc_erase(uint32_t blk_start, uint32_t blk_end, uint32_t timeout) {
int eos_sdc_sect_read(uint32_t sect, unsigned int count, uint8_t *buffer) {
int rv;
- uint64_t start;
uint8_t cmd = ((count == 1) ? READ_SINGLE_BLOCK : READ_MULTIPLE_BLOCK);
if (!(sdc_type & EOS_SDC_CAP_BLK)) sect *= 512;
- start = eos_time_get_tick();
sdc_select();
rv = sdc_cmd(cmd, sect, SDC_CMD_FLAG_NOCS, SDC_TIMEOUT_CMD);
@@ -498,10 +496,8 @@ int eos_sdc_sect_read(uint32_t sect, unsigned int count, uint8_t *buffer) {
int eos_sdc_sect_write(uint32_t sect, unsigned int count, uint8_t *buffer) {
int rv;
- uint64_t start;
if (!(sdc_type & EOS_SDC_CAP_BLK)) sect *= 512;
- start = eos_time_get_tick();
if (count == 1) {
sdc_select();
diff --git a/fw/fe310/eos/sdcard.h b/fw/fe310/eos/dev/sdcard.h
index 910a6e0..910a6e0 100644
--- a/fw/fe310/eos/sdcard.h
+++ b/fw/fe310/eos/dev/sdcard.h
diff --git a/fw/fe310/eos/spi_dev.c b/fw/fe310/eos/dev/spi.c
index c0c21b0..12549fc 100644
--- a/fw/fe310/eos/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/spi_dev.h b/fw/fe310/eos/dev/spi.h
index e801f7e..c899e83 100644
--- a/fw/fe310/eos/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/spi_cfg.h b/fw/fe310/eos/dev/spi_cfg.h
index 84ab8bb..6a5d7b4 100644
--- a/fw/fe310/eos/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 b52ed93..03609ae 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -1,31 +1,29 @@
#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 "i2c/bq25895.h"
-#include "eve/eve_eos.h"
-
-#include "board.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"
#include "eos.h"
void eos_init(void) {
uint8_t wakeup_cause = eos_pwr_wakeup_cause();
- uint32_t touch_matrix[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0};
- int touch_calibrate = 0;
int rv;
eos_evtq_init(wakeup_cause);
@@ -45,26 +43,19 @@ 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, touch_calibrate, 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) printf("LCD INIT ERR:%d\n", rv);
+ rv = eos_sdc_init(wakeup_cause);
+ if (rv) printf("SDC INIT ERR:%d\n", rv);
+
+ rv = eos_eve_init(wakeup_cause);
+ if (rv) printf("EVE INIT ERR:%d\n", rv);
- if (touch_calibrate) {
- 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]);
- }
eos_run(wakeup_cause);
}
@@ -74,10 +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_eve_calibrate();
+}
diff --git a/fw/fe310/eos/eos.h b/fw/fe310/eos/eos.h
index 87a7e27..f3caf6b 100644
--- a/fw/fe310/eos/eos.h
+++ b/fw/fe310/eos/eos.h
@@ -9,8 +9,10 @@
#define EOS_ERR_FULL -11
#define EOS_ERR_EMPTY -12
#define EOS_ERR_NOTFOUND -13
+#define EOS_ERR_ABSENT -14
#define EOS_ERR_NET -20
void eos_init(void);
-void eos_run(uint8_t wakeup_cause); \ No newline at end of file
+void eos_run(uint8_t wakeup_cause);
+void eos_run_once(void); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile
index 323a132..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_eos.o eve_platform.o eve_touch.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o
+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_eos.o eve_platform.o eve_touch.o eve_phy.o eve_vtrack.o eve_font
%.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 e1191fc..5103e5f 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -13,6 +13,7 @@ static char dl_burst;
static uint32_t dl_addr;
static uint8_t power_state;
+static int lcd_absent = 0;
void eve_command(uint8_t command, uint8_t parameter) {
eve_spi_cs_set();
@@ -289,6 +290,7 @@ int eve_cmd_exec(int w) {
void eve_cmd_burst_start(void) {
uint32_t addr = EVE_RAM_CMD + cmd_offset;
+
eve_spi_lock();
eve_spi_cs_set();
eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX);
@@ -306,10 +308,10 @@ void eve_handle_intr(void) {
uint16_t intr_flags;
intr_flags = eve_read16(REG_INT_FLAGS);
- eve_handle_touch(intr_flags);
+ if (intr_flags & (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)) eve_handle_touch(intr_flags);
}
-int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
+int eve_init(void) {
uint8_t chipid = 0;
uint8_t reset = 0x07;
uint16_t timeout;
@@ -319,11 +321,11 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
eve_command(EVE_CLKEXT, 0);
eve_command(EVE_CLKSEL, 0x46); /* set clock to 72 MHz */
eve_command(EVE_ACTIVE, 0); /* start EVE */
- eve_time_sleep(4);
+ eve_sleep(4);
timeout = 0;
while (chipid != 0x7c) { /* if chipid is not 0x7c, continue to read it until it is, EVE needs a moment for it's power on self-test and configuration */
- eve_time_sleep(1);
+ eve_sleep(1);
chipid = eve_read8(REG_ID);
timeout++;
if (timeout > 400) return EVE_ERR;
@@ -331,7 +333,7 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
timeout = 0;
while (reset != 0x00) { /* check if EVE is in working status */
- eve_time_sleep(1);
+ eve_sleep(1);
reset = eve_read8(REG_CPURESET) & 0x07;
timeout++;
if(timeout > 50) return EVE_ERR;
@@ -341,7 +343,7 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
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 */
@@ -361,7 +363,8 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
/* 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 */
@@ -381,21 +384,16 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
#endif
/* nothing is being displayed yet... the pixel clock is still 0x00 */
- eve_touch_init(touch_calibrate, touch_matrix);
return EVE_OK;
}
void eve_start(void) {
- eve_touch_start();
-
/* enable interrupts */
eve_write8(REG_INT_EN, 0x01);
while(eve_read8(REG_INT_FLAGS));
}
void eve_stop(void) {
- eve_touch_stop();
-
/* disable interrupts */
eve_write8(REG_INT_EN, 0x00);
while(eve_read8(REG_INT_FLAGS));
@@ -417,12 +415,12 @@ void eve_stop_clk(void) {
eve_write8(REG_PCLK, 0);
}
-void eve_active(void) {
+void eve_activate(void) {
eve_command(EVE_ACTIVE, 0);
- eve_time_sleep(40);
+ eve_sleep(40);
}
-void eve_standby(void) {
+void eve_pwr_standby(void) {
if (power_state != EVE_PSTATE_ACTIVE) return;
eve_command(EVE_STANDBY, 0);
@@ -430,7 +428,7 @@ void eve_standby(void) {
power_state = EVE_PSTATE_STANDBY;
}
-void eve_sleep(void) {
+void eve_pwr_sleep(void) {
if (power_state != EVE_PSTATE_ACTIVE) return;
eve_stop_clk();
@@ -441,8 +439,8 @@ void eve_sleep(void) {
power_state = EVE_PSTATE_SLEEP;
}
-void eve_wake(void) {
- eve_active();
+void eve_pwr_wake(void) {
+ eve_activate();
if (power_state == EVE_PSTATE_SLEEP) {
eve_start();
@@ -452,10 +450,6 @@ void eve_wake(void) {
power_state = EVE_PSTATE_ACTIVE;
}
-void eve_brightness(uint8_t b) {
- eve_write8(REG_PWM_DUTY, b);
-}
-
int eve_gpio_get(int gpio) {
uint16_t reg = eve_read16(REG_GPIOX);
@@ -483,3 +477,12 @@ void eve_gpio_set_dir(uint8_t dir) {
reg |= dir & 0x0f;
eve_write16(REG_GPIOX_DIR, reg);
}
+
+void eve_brightness(uint8_t b) {
+ if (lcd_absent) b = 0;
+ eve_write8(REG_PWM_DUTY, b);
+}
+
+void eve_lcd_absent(void) {
+ lcd_absent = 1;
+}
diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h
index 02fa697..c1b91e4 100644
--- a/fw/fe310/eos/eve/eve.h
+++ b/fw/fe310/eos/eve/eve.h
@@ -58,19 +58,21 @@ void eve_cmd_burst_end(void);
void eve_handle_intr(void);
-int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix);
+int eve_init(void);
void eve_start(void);
void eve_stop(void);
void eve_start_clk(void);
void eve_stop_clk(void);
-void eve_active(void);
-void eve_standby(void);
-void eve_sleep(void);
-void eve_wake(void);
+void eve_activate(void);
+void eve_pwr_standby(void);
+void eve_pwr_sleep(void);
+void eve_pwr_wake(void);
int eve_gpio_get(int gpio);
void eve_gpio_set(int gpio, int val);
uint8_t eve_gpio_get_dir(void);
void eve_gpio_set_dir(uint8_t dir);
+
void eve_brightness(uint8_t b);
+void eve_lcd_absent(void); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/eve_def.h b/fw/fe310/eos/eve/eve_def.h
index 2f7e0b7..b7110b9 100755
--- a/fw/fe310/eos/eve/eve_def.h
+++ b/fw/fe310/eos/eve/eve_def.h
@@ -697,6 +697,10 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#define REG_PLAY_CONTROL 0x30914eUL
#define REG_COPRO_PATCH_PTR 0x309162UL
+#define REG_EHOST_TOUCH_X 0x30210cUL
+#define REG_EHOST_TOUCH_Y 0x302118UL
+#define REG_EHOST_TOUCH_ID 0x302114UL
+#define REG_EHOST_TOUCH_ACK 0x302170UL
/* BT81x graphics engine specific macros */
#define BITMAP_EXT_FORMAT(format) ((46UL<<24)|(((format)&65535UL)<<0))
diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c
deleted file mode 100644
index 2e13cd2..0000000
--- a/fw/fe310/eos/eve/eve_eos.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include <stdlib.h>
-
-#include "platform.h"
-
-#include "eos.h"
-#include "interrupt.h"
-#include "event.h"
-#include "pwr.h"
-
-#include "board.h"
-
-#include "eve.h"
-#include "eve_eos.h"
-
-static int _run;
-
-static void handle_time(unsigned char type) {
- if (_run) {
- 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();
-
- GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
- }
-}
-
-static void handle_intr(void) {
- GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
- GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR);
- eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INTR, NULL, 0);
-}
-
-
-static void _start(void) {
- 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);
-
- eve_stop();
-}
-
-int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
- int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
- int rv = EVE_OK;
-
- eve_spi_start();
- if (rst) {
- rv = eve_init(gpio_dir, touch_calibrate, touch_matrix);
- } else {
- eve_active();
- }
- eve_spi_stop();
-
- if (rv) return EOS_ERR;
-
- eos_evtq_set_handler(EOS_EVT_UI, handle_evt);
- eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time);
- eos_intr_set(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_UI, handle_intr);
- eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR);
-
- return EOS_OK;
-}
-
-int eos_eve_run(uint8_t wakeup_cause) {
- eve_spi_start();
- _start();
- eve_start_clk();
- eve_spi_stop();
-
- return EOS_OK;
-}
-
-void eos_eve_start(void) {
- eve_spi_start();
- _start();
- eve_spi_stop();
-}
-
-void eos_eve_stop(void) {
- eve_spi_start();
- _stop();
- eve_spi_stop();
-}
diff --git a/fw/fe310/eos/eve/eve_eos.h b/fw/fe310/eos/eve/eve_eos.h
deleted file mode 100644
index 80eea86..0000000
--- a/fw/fe310/eos/eve/eve_eos.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <stdint.h>
-
-int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix);
-int eos_eve_run(uint8_t wakeup_cause);
-void eos_eve_start(void);
-void eos_eve_stop(void);
diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c
index 1e255fe..cfddc80 100644
--- a/fw/fe310/eos/eve/eve_phy.c
+++ b/fw/fe310/eos/eve/eve_phy.c
@@ -9,30 +9,44 @@ 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, int dt, int *x, int *y) {
+int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y) {
int k = param->k;
int x0 = param->x0;
int y0 = param->y0;
int v0x = param->v0x;
int v0y = param->v0y;
+ int _dt = dt;
int more = 1;
+ if (k == 0) {
+ if (x) *x = x0;
+ if (y) *y = y0;
+ return 0;
+ }
+
if ((k < 0) && (dt >= -k / 2)) {
dt = -k / 2;
more = 0;
}
- if (x) *x = x0 + (v0x * dt + v0x * dt / k * dt) / (int)(EVE_RTC_FREQ);
- if (y) *y = y0 + (v0y * dt + v0y * dt / k * dt) / (int)(EVE_RTC_FREQ);
+ if (x) *x = x0 + (v0x * _dt + v0x * _dt / k * _dt) / EVE_RTC_FREQ;
+ if (y) *y = y0 + (v0y * _dt + v0y * _dt / k * _dt) / EVE_RTC_FREQ;
return more;
}
@@ -53,9 +67,11 @@ 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, int dt, int *x, int *y) {
+int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y) {
int ax = param->x0 - param->x;
int ay = param->y0 - param->y;
int more = 1;
diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h
index 1be5fd0..e747b44 100644
--- a/fw/fe310/eos/eve/eve_phy.h
+++ b/fw/fe310/eos/eve/eve_phy.h
@@ -10,8 +10,8 @@ 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_tick(EVEPhyAcc *param, int dt, int *x, int *y);
+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 {
int x;
@@ -25,4 +25,4 @@ typedef struct EVEPhyLHO {
void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint32_t t_max);
int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0);
-int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y); \ No newline at end of file
+int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c
index 4450412..f0fc399 100644
--- a/fw/fe310/eos/eve/eve_platform.c
+++ b/fw/fe310/eos/eve/eve_platform.c
@@ -17,19 +17,19 @@ void eve_free(void *p) {
free(p);
}
-void eve_timer_set(uint32_t ms) {
- eos_timer_set(ms, EOS_TIMER_ETYPE_UI);
+void eve_sleep(uint32_t ms) {
+ eos_time_sleep(ms);
}
-void eve_time_sleep(uint32_t ms) {
- eos_time_sleep(ms);
+uint32_t eve_get_tick(void) {
+ return (uint32_t)eos_time_get_tick();
}
-uint64_t eve_time_get_tick(void) {
- return eos_time_get_tick();
+void eve_sys_timer_set(uint32_t ms) {
+ eos_timer_set(EOS_TIMER_ETYPE_UI, ms);
}
-void eve_timer_clear(void) {
+void eve_sys_timer_clear(void) {
eos_timer_clear(EOS_TIMER_ETYPE_UI);
}
diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h
index 77afffc..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
@@ -31,7 +31,7 @@ void eve_spi_stop(void);
#define eve_spi_lock eos_spi_lock
#define eve_spi_unlock eos_spi_unlock
-void eve_time_sleep(uint32_t ms);
-uint64_t eve_time_get_tick(void);
-void eve_timer_set(uint32_t ms);
-void eve_timer_clear(void);
+void eve_sleep(uint32_t ms);
+uint32_t eve_get_tick(void);
+void eve_sys_timer_set(uint32_t ms);
+void eve_sys_timer_clear(void);
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index 7c06f81..d17a509 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -1,10 +1,9 @@
#include <stdlib.h>
#include <string.h>
-#include <math.h>
#include "eve.h"
+#include "eve_touch_engine.h"
-static int touch_multi;
static uint8_t touch_tag0;
static EVETouch touch_obj[EVE_MAX_TOUCH];
@@ -14,235 +13,222 @@ static eve_touch_handler_t touch_handler;
static void *touch_handler_param;
static uint8_t touch_tag_opt[256];
-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(void) {
+ int i;
+
+ touch_tag0 = 0;
+ memset(&touch_timer, 0, sizeof(touch_timer));
+ for (i=0; i<EVE_MAX_TOUCH; i++) {
+ EVETouch *touch = &touch_obj[i];
+
+ memset(&touch_obj[i], 0, sizeof(EVETouch));
+ touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
+ }
+ eve_vtrack_init();
+}
void eve_handle_touch(uint16_t intr_flags) {
int i;
- char touch_ex = 0;
- char int_ccomplete = 0;
- uint16_t intr_mask;
-
- intr_mask = eve_read16(REG_INT_MASK);
- if (!touch_multi && (intr_flags & EVE_INT_TOUCH)) touch_multi = 1;
for (i=0; i<EVE_MAX_TOUCH; i++) {
- uint8_t touch_tag;
- uint32_t touch_xy;
- uint64_t now = 0;
+ uint32_t now = 0;
uint16_t touch_evt = 0;
EVETouch *touch = &touch_obj[i];
- touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y));
-
- if (touch_xy != EVE_NOTOUCH) {
- int16_t touch_x = touch_xy >> 16;
- int16_t touch_y = touch_xy & 0xffff;
- now = eve_time_get_tick();
- if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) {
- uint16_t _evt = 0;
- uint16_t _eevt = 0;
- uint16_t _ttevt = eve_touch_timer_get_evt(touch);
-
- if (_ttevt) {
- touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH;
+ now = eve_get_tick();
+
+ if (intr_flags & EVE_INT_CONVCOMPLETE) {
+ uint32_t touch_xy = eve_touch_reg_xy(i);
+ uint16_t timer_evt;
+
+ if (touch_xy != EVE_NOTOUCH) {
+ int16_t touch_x = touch_xy >> 16;
+ int16_t touch_y = touch_xy & 0xffff;
+ int check_track, check_timer;
+
+ if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) {
+ uint16_t _evt = 0;
+ uint16_t _eevt = 0;
+
+ timer_evt = eve_timer_get_evt(touch);
+ if (timer_evt) {
+ uint16_t _touch_evt = 0;
+
+ touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH;
+ if (timer_evt & EVE_TOUCH_ETYPE_TAP2) {
+ int dx = touch_x - touch->x0;
+ int dy = touch_y - touch->y0;
+
+ dx = dx < 0 ? -dx : dx;
+ dy = dy < 0 ? -dy : dy;
+ if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) {
+ _touch_evt |= EVE_TOUCH_ETYPE_TAP1;
+ } else {
+ _evt |= EVE_TOUCH_ETYPE_TAP2;
+ _eevt |= EVE_TOUCH_EETYPE_TAP2;
+ }
+ }
+ if (timer_evt & EVE_TOUCH_ETYPE_TRACK) {
+ EVEVTrack *vtrack = eve_vtrack_get();
- if (_ttevt & EVE_TOUCH_ETYPE_TAP2) {
- int dx = touch_x - touch->x0;
- int dy = touch_y - touch->y0;
+ _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT;
+ _touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT);
+ if (vtrack->stop) vtrack->stop(touch, vtrack->param);
+ }
+ if (timer_evt & EVE_TOUCH_ETYPE_TIMER) {
+ _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT;
+ _touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT;
+ }
- dx = dx < 0 ? -dx : dx;
- dy = dy < 0 ? -dy : dy;
- if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) {
- touch_evt |= EVE_TOUCH_ETYPE_TAP1;
- } else {
- _evt |= EVE_TOUCH_ETYPE_TAP2;
- _eevt |= EVE_TOUCH_EETYPE_TAP2;
+ eve_timer_clear(touch);
+ if (touch_handler && _touch_evt) {
+ touch_handler(touch_timer.touch, _touch_evt, touch_timer.tag0, touch_handler_param);
}
}
- if (_ttevt & EVE_TOUCH_ETYPE_TRACK) {
- EVEVTrack *vtrack = eve_vtrack_get();
-
- _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT;
- touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT);
- if (vtrack->stop) vtrack->stop(touch, vtrack->param);
+ touch_evt |= EVE_TOUCH_ETYPE_POINT | _evt;
+ touch->eevt = _eevt;
+ touch->tag0 = 0;
+ touch->tag = 0;
+ touch->tag_up = 0;
+ touch->tracker.tag = 0;
+ touch->tracker.track = 0;
+ touch->tracker.val = 0;
+ touch->t = 0;
+ touch->vx = 0;
+ touch->vy = 0;
+ touch->x0 = touch_x;
+ touch->y0 = touch_y;
+ } else if (touch->tracker.track) {
+ uint32_t dt = now - touch->t;
+ int vx = ((int)touch_x - touch->x) * EVE_RTC_FREQ / (int)dt;
+ int vy = ((int)touch_y - touch->y) * EVE_RTC_FREQ / (int)dt;
+
+ touch->vx = vx;
+ touch->vy = vy;
+ touch->t = now;
+ }
+ touch->x = touch_x;
+ touch->y = touch_y;
+
+ timer_evt = eve_timer_get_evt(touch);
+ check_track = touch->tracker.tag && !touch->tracker.track;
+ check_timer = timer_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2);
+
+ if (check_track || check_timer) {
+ int dx = touch->x - touch->x0;
+ int dy = touch->y - touch->y0;
+
+ dx = dx < 0 ? -dx : dx;
+ dy = dy < 0 ? -dy : dy;
+ if (check_track) {
+ if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
+ touch->tracker.tag = 0;
+ }
+ if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
+ touch->tracker.tag = 0;
+ }
+ if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) {
+ 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 (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;
+ touch->tracker.track = 1;
+ touch->t = now;
+ }
}
- if (_ttevt & EVE_TOUCH_ETYPE_TIMER) {
- _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT;
- touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT;
+ if (check_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) {
+ eve_timer_set_evt(touch, timer_evt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2));
}
-
- eve_touch_timer_clear(touch);
- if (touch_handler && touch_evt) {
- touch_handler(touch_timer.touch, touch_evt, touch_timer.tag0, touch_handler_param);
- }
- }
- touch_evt = EVE_TOUCH_ETYPE_POINT | _evt;
- touch->eevt = _eevt;
- touch->tag0 = 0;
- touch->tag = 0;
- touch->tag_up = 0;
- touch->tracker.tag = 0;
- touch->tracker.track = 0;
- touch->tracker.val = 0;
- touch->t = 0;
- touch->vx = 0;
- touch->vy = 0;
- touch->x0 = touch_x;
- touch->y0 = touch_y;
- } else if (touch->t) {
- int dt = now - touch->t;
- int vx = ((int)touch_x - touch->x) * (int)(EVE_RTC_FREQ) / dt;
- int vy = ((int)touch_y - touch->y) * (int)(EVE_RTC_FREQ) / dt;
- touch->vx = touch->vx ? (vx + touch->vx * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vx;
- touch->vy = touch->vy ? (vy + touch->vy * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vy;
- touch->t = now;
- }
- touch->x = touch_x;
- touch->y = touch_y;
- if (touch_multi || (intr_flags & EVE_INT_TAG)) {
- touch_tag = eve_read8(_reg_tag[i]);
- } else {
- touch_tag = touch->tag;
- }
- touch_ex = 1;
- } else {
- touch_tag = 0;
- if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) {
- uint16_t _ttevt = eve_touch_timer_get_evt(touch);
-
- touch_evt = EVE_TOUCH_ETYPE_POINT_UP;
- touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
- if (_ttevt & EVE_TOUCH_ETYPE_LPRESS) {
- eve_touch_timer_set_evt(touch, _ttevt & ~EVE_TOUCH_ETYPE_LPRESS);
}
if (touch->tracker.tag && touch->tracker.track) {
- uint8_t opt = touch_tag_opt[touch->tracker.tag];
- char 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_touch_timer_get_evt(NULL) && track_ext) {
- EVEVTrack *vtrack = eve_vtrack_get();
-
- eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK);
- if (vtrack->start) vtrack->start(touch, vtrack->param);
+ if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK;
+ if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG;
+ }
+ if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) {
+ uint32_t touch_track = eve_touch_reg_track(i);
+
+ if (touch->tracker.tag == (touch_track & 0xff)) {
+ touch->tracker.val = touch_track >> 16;
} else {
- touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG;
}
}
- }
- }
- if (touch_tag != touch->tag) {
- if (touch_tag) {
- if (!touch_tag0) touch_tag0 = touch_tag;
- if (!touch->tag0) {
- touch->tag0 = touch_tag;
- if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) {
- touch->tracker.tag = touch_tag;
- }
- if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) {
- touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
- touch->tracker.track = 1;
- touch->t = now;
+ } else {
+ if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) {
+ touch_evt |= EVE_TOUCH_ETYPE_POINT_UP;
+ touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
+
+ timer_evt = eve_timer_get_evt(touch);
+ if (timer_evt & EVE_TOUCH_ETYPE_LPRESS) {
+ eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS);
}
- if (!eve_touch_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) {
- uint16_t _evt = 0;
+ 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 (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS;
- if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2;
- eve_touch_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP);
+ 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);
+ } else {
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP;
+ }
}
}
}
- touch->tag_up = touch->tag;
- if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP;
- touch->tag = touch_tag;
- if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG;
}
- if (touch_xy != EVE_NOTOUCH) {
- uint16_t _ttevt = eve_touch_timer_get_evt(touch);
- int _track = touch->tracker.tag && !touch->tracker.track;
- int _timer = _ttevt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2);
- if (_track || _timer) {
- int dx = touch->x - touch->x0;
- int dy = touch->y - touch->y0;
- dx = dx < 0 ? -dx : dx;
- dy = dy < 0 ? -dy : dy;
- if (_track) {
- if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) {
- touch->tracker.tag = 0;
- }
- if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) {
- 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;
+
+ if (intr_flags & EVE_INT_TAG) {
+ uint8_t touch_tag = eve_touch_reg_tag(i);
+
+ if (touch_tag != touch->tag) {
+ if (touch_tag) {
+ if (!touch_tag0) touch_tag0 = touch_tag;
+ if (!touch->tag0) {
+ touch->tag0 = touch_tag;
+ if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) {
+ touch->tracker.tag = touch_tag;
}
- if (dy > EVE_TOUCH_THRESHOLD_Y) {
- touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP;
+ if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) {
+ touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
+ touch->tracker.track = 1;
+ touch->t = now;
+ }
+ if (!eve_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) {
+ uint16_t _evt = 0;
+
+ if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS;
+ if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2;
+ eve_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP);
}
- touch_evt |= EVE_TOUCH_ETYPE_TRACK_START;
- touch->tracker.track = 1;
- touch->t = now;
}
}
- if (_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) {
- eve_touch_timer_set_evt(touch, _ttevt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2));
- _timer = 0;
- }
+ touch->tag_up = touch->tag;
+ if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP;
+ touch->tag = touch_tag;
+ if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG;
}
- if (touch->tracker.tag && touch->tracker.track) {
- if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK;
- if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG;
- }
- if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) {
- uint32_t touch_track = eve_read32(_reg_track[i]);
- if (touch->tracker.tag == (touch_track & 0xff)) {
- touch->tracker.val = touch_track >> 16;
- } else {
- touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG;
- }
- }
- if (touch->tracker.tag || _timer) int_ccomplete = 1;
}
+
if (touch_handler && touch_evt) {
touch_handler(touch, touch_evt, touch_tag0, touch_handler_param);
}
- if (!touch_multi) break;
- }
-
- if (!touch_ex) {
- touch_tag0 = 0;
- touch_multi = 0;
- }
-
- if (touch_multi) int_ccomplete = 1;
-
- if (int_ccomplete && !(intr_mask & EVE_INT_CONVCOMPLETE)) {
- eve_write16(REG_INT_MASK, intr_mask | EVE_INT_CONVCOMPLETE);
- }
- if (!int_ccomplete && (intr_mask & EVE_INT_CONVCOMPLETE)) {
- eve_write16(REG_INT_MASK, intr_mask & ~EVE_INT_CONVCOMPLETE);
}
}
@@ -278,7 +264,7 @@ void eve_handle_time(void) {
}
if (more) {
- eve_timer_set(touch_timer.to);
+ eve_sys_timer_set(touch_timer.to);
} else {
touch_timer.evt = 0;
}
@@ -289,74 +275,12 @@ void eve_handle_time(void) {
}
}
-void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix) {
- /* configure touch */
- eve_write8(REG_CPURESET, 2); /* touch engine reset */
- eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */
- eve_write8(REG_CPURESET, 0); /* clear reset */
-
- if (touch_calibrate) {
- eve_write8(REG_PWM_DUTY, 0x40);
- eve_cmd(CMD_TEXT, "hhhhs", EVE_HSIZE/2, EVE_VSIZE/2, 27, EVE_OPT_CENTER, "Please tap on the dot.");
- eve_cmd(CMD_CALIBRATE, "w", 0);
- eve_cmd_exec(1);
- eve_write8(REG_PWM_DUTY, 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);
- } else {
- 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]);
- }
-
- eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */
-}
-
-void eve_touch_start(void) {
- uint16_t intr_mask;
- int i;
-
- touch_multi = 0;
- touch_tag0 = 0;
- memset(&touch_timer, 0, sizeof(touch_timer));
- for (i=0; i<EVE_MAX_TOUCH; i++) {
- EVETouch *touch = &touch_obj[i];
-
- memset(&touch_obj[i], 0, sizeof(EVETouch));
- touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH;
- }
- eve_vtrack_init();
-
- intr_mask = eve_read16(REG_INT_MASK);
- eve_write16(REG_INT_MASK, intr_mask | EVE_INT_TAG | EVE_INT_TOUCH);
-
- 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_TAG | EVE_INT_TOUCH | EVE_INT_CONVCOMPLETE));
- eve_touch_timer_clear(touch_timer.touch);
-
- eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF);
-}
-
void eve_touch_set_handler(eve_touch_handler_t handler, void *param) {
touch_handler = handler;
touch_handler_param = param;
}
-EVETouch *eve_touch_get(int i) {
+EVETouch *eve_touch_get_obj(int i) {
return &touch_obj[i];
}
@@ -411,46 +335,59 @@ void eve_touch_clear_opt(void) {
memset(touch_tag_opt, 0, sizeof(touch_tag_opt));
}
-void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) {
+void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) {
touch_timer.touch = touch;
touch_timer.evt = evt;
touch_timer.tag0 = tag0;
touch_timer.to = to;
- eve_timer_set(to);
+ eve_sys_timer_set(to);
+}
+
+void eve_timer_clear(EVETouch *touch) {
+ eve_timer_set_evt(touch, 0);
}
-void eve_touch_timer_clear(EVETouch *touch) {
- eve_touch_timer_set_evt(touch, 0);
+void eve_timer_set_evt(EVETouch *touch, uint16_t evt) {
+ if ((touch == NULL) || (touch == touch_timer.touch)) {
+ touch_timer.evt = evt;
+ } else if (touch_timer.touch == NULL) {
+ touch_timer.evt = evt;
+ }
+ if (!touch_timer.evt) {
+ eve_sys_timer_clear();
+ touch_timer.touch = NULL;
+ touch_timer.tag0 = 0;
+ touch_timer.to = 0;
+ }
}
-uint16_t eve_touch_timer_get_evt(EVETouch *touch) {
+uint16_t eve_timer_get_evt(EVETouch *touch) {
uint16_t ret = 0;
if ((touch == NULL) || (touch_timer.touch == touch)) {
ret = touch_timer.evt;
} else if (touch_timer.touch == NULL) {
- ret = touch_timer.evt & EVE_TOUCH_ETYPE_TIMER;
+ ret = touch_timer.evt;
}
return ret;
}
-void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt) {
- if (touch == touch_timer.touch) {
- touch_timer.evt = evt;
- } else if (touch_timer.touch == NULL) {
- touch_timer.evt = evt & EVE_TOUCH_ETYPE_TIMER;
- }
- if (!touch_timer.evt) eve_timer_clear();
+EVETouchTimer *eve_timer_get_obj(void) {
+ return &touch_timer;
}
-void eve_touch_timer_start(uint8_t tag0, uint32_t to) {
- eve_touch_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to);
+void eve_timer_start(uint8_t tag0, uint32_t to) {
+ if (!touch_timer.evt) eve_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to);
}
-void eve_touch_timer_stop(void) {
- eve_touch_timer_clear(NULL);
+void eve_timer_stop(void) {
+ if (touch_timer.touch == NULL) eve_timer_clear(NULL);
}
-EVETouchTimer *eve_touch_timer_get(void) {
- return &touch_timer;
+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 b10fde2..8ec6e0e 100644
--- a/fw/fe310/eos/eve/eve_touch.h
+++ b/fw/fe310/eos/eve/eve_touch.h
@@ -5,7 +5,6 @@
#define EVE_TOUCH_THRESHOLD_X 5
#define EVE_TOUCH_THRESHOLD_Y 5
-#define EVE_TOUCH_TRAVG 3
#define EVE_NOTAG 0
#define EVE_NOTOUCH 0x80008000
@@ -77,7 +76,7 @@ typedef struct EVETouch {
int vy;
int x0;
int y0;
- uint64_t t;
+ uint32_t t;
uint16_t eevt;
uint8_t tag0;
uint8_t tag;
@@ -98,15 +97,12 @@ typedef struct EVETouchTimer {
typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *);
+void eve_touch_init(void);
void eve_handle_touch(uint16_t intr_flags);
void eve_handle_time(void);
-void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix);
-void eve_touch_start(void);
-void eve_touch_stop(void);
-
void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param);
-EVETouch *eve_touch_get(int i);
+EVETouch *eve_touch_get_obj(int i);
int8_t eve_touch_get_idx(EVETouch *touch);
uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n);
@@ -114,11 +110,13 @@ void eve_touch_set_opt(uint8_t tag, uint8_t opt);
uint8_t eve_touch_get_opt(uint8_t tag);
void eve_touch_clear_opt(void);
-void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to);
-void eve_touch_timer_clear(EVETouch *touch);
-uint16_t eve_touch_timer_get_evt(EVETouch *touch);
-void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt);
-void eve_touch_timer_start(uint8_t tag0, uint32_t to);
-void eve_touch_timer_stop(void);
+void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to);
+void eve_timer_clear(EVETouch *touch);
+void eve_timer_set_evt(EVETouch *touch, uint16_t evt);
+uint16_t eve_timer_get_evt(EVETouch *touch);
+EVETouchTimer *eve_timer_get_obj(void);
-EVETouchTimer *eve_touch_timer_get(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 b9f28af..a7619fb 100644
--- a/fw/fe310/eos/eve/eve_vtrack.c
+++ b/fw/fe310/eos/eve/eve_vtrack.c
@@ -26,40 +26,31 @@ 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_touch_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) {
- eve_touch_timer_clear(touch);
+ eve_timer_clear(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) {
EVEPhyAcc *param = (EVEPhyAcc *)p;
- return eve_phy_acc_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y);
+ 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_time_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 b75f673..8455502 100644
--- a/fw/fe310/eos/eve/eve_vtrack.h
+++ b/fw/fe310/eos/eve/eve_vtrack.h
@@ -1,8 +1,8 @@
#include <stdint.h>
-#define EVE_VTRACK_ACC_A 1000
+#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 65dd534..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;
- eve_touch_timer_stop();
+ 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);
+ 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);
- page->lho_t0 = eve_time_get_tick();
- eve_touch_timer_start(_tag, 20);
+ 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_time_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL);
+ 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_touch_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 26c33c5..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;
@@ -26,13 +27,16 @@ typedef struct EVEPage {
uint16_t widget_size;
struct EVEWidget *widget_f;
EVEPhyLHO lho;
- uint64_t lho_t0;
+ uint32_t lho_t0;
uint8_t track_mode;
uint8_t opt;
} 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 e78cf46..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;
@@ -71,10 +55,29 @@ int eve_strw_update(EVEStrWidget *widget) {
widget->str[str_len] = '\0';
}
widget->str_len = str_len;
+ widget->str_g.w = eve_font_str_w(widget->font, widget->str);
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);
}
@@ -86,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) {
@@ -215,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;
@@ -290,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;
}
@@ -305,7 +309,6 @@ void eve_strw_putc(void *w, int c) {
int ins_c = 0, del_c = 0;
int ins_w = 0, del_w = 0;
-
if (c == EVE_PAGE_KBDCH_CLOSE) {
if (cursor1->on) eve_strw_cursor_clear(widget, cursor1);
if (cursor2->on) eve_strw_cursor_clear(widget, cursor2);
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/event.c b/fw/fe310/eos/event.c
index 753cdb4..f76384a 100644
--- a/fw/fe310/eos/event.c
+++ b/fw/fe310/eos/event.c
@@ -121,22 +121,28 @@ void eos_evtq_flush_isr(void) {
}
void eos_evtq_loop(void) {
+ int foo = 1;
+
+ while(foo) {
+ eos_evtq_exec();
+ }
+}
+
+void eos_evtq_exec(void) {
unsigned char type;
unsigned char *buffer;
uint16_t len;
- int foo = 1;
- while(foo) {
- clear_csr(mstatus, MSTATUS_MIE);
- eos_msgq_pop(&_eos_event_q, &type, &buffer, &len);
- if (type) {
- set_csr(mstatus, MSTATUS_MIE);
- evt_handler[0](type, buffer, len);
- } else {
- asm volatile ("wfi");
- set_csr(mstatus, MSTATUS_MIE);
- }
+ clear_csr(mstatus, MSTATUS_MIE);
+ eos_msgq_pop(&_eos_event_q, &type, &buffer, &len);
+ if (type) {
+ set_csr(mstatus, MSTATUS_MIE);
+ evt_handler[0](type, buffer, len);
+ } else {
+ asm volatile ("wfi");
+ set_csr(mstatus, MSTATUS_MIE);
}
+
}
void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
diff --git a/fw/fe310/eos/event.h b/fw/fe310/eos/event.h
index 82043f4..9501a15 100644
--- a/fw/fe310/eos/event.h
+++ b/fw/fe310/eos/event.h
@@ -15,6 +15,7 @@ void eos_evtq_wait(unsigned char type, unsigned char *selector, uint16_t sel_len
void eos_evtq_flush(void);
void eos_evtq_flush_isr(void);
void eos_evtq_loop(void);
+void eos_evtq_exec(void);
void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len);
void eos_evtq_set_handler(unsigned char type, eos_evt_handler_t handler);
diff --git a/fw/fe310/eos/evt_def.h b/fw/fe310/eos/evt_def.h
index 16c4255..e34b2d2 100644
--- a/fw/fe310/eos/evt_def.h
+++ b/fw/fe310/eos/evt_def.h
@@ -3,7 +3,8 @@
#define EOS_EVT_NET 0x30
#define EOS_EVT_SPI 0x40
#define EOS_EVT_UART 0x50
-#define EOS_EVT_UI 0x60
+#define EOS_EVT_EVE 0x60
+#define EOS_EVT_CTP 0x70
#define EOS_EVT_USER 0x80
#define EOS_EVT_MAX_EVT 8
diff --git a/fw/fe310/eos/i2c/Makefile b/fw/fe310/eos/i2c/Makefile
deleted file mode 100644
index 97e4f12..0000000
--- a/fw/fe310/eos/i2c/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-include ../../common.mk
-
-obj = bq25895.o ov2640.o
-
-
-%.o: %.c %.h
- $(CC) $(CFLAGS) -c $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c $<
-
-all: $(obj)
-
-clean:
- rm -f *.o
diff --git a/fw/fe310/eos/irq_def.h b/fw/fe310/eos/irq_def.h
index 5d9fb1e..ea3e7a8 100644
--- a/fw/fe310/eos/irq_def.h
+++ b/fw/fe310/eos/irq_def.h
@@ -8,4 +8,5 @@
#define IRQ_PRIORITY_UART 1
-#define IRQ_PRIORITY_UI 5
+#define IRQ_PRIORITY_EVE 5
+#define IRQ_PRIORITY_CTP 5
diff --git a/fw/fe310/eos/lcd.c b/fw/fe310/eos/lcd.c
deleted file mode 100644
index cf09018..0000000
--- a/fw/fe310/eos/lcd.c
+++ /dev/null
@@ -1,522 +0,0 @@
-#include <stdlib.h>
-#include <stdint.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;
-
- 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, 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/lcd.h b/fw/fe310/eos/lcd.h
deleted file mode 100644
index 1bcb2cd..0000000
--- a/fw/fe310/eos/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/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/cell.c b/fw/fe310/eos/net/cell.c
index 20a9f42..4bfbb35 100644
--- a/fw/fe310/eos/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/cell.h b/fw/fe310/eos/net/cell.h
index b01d4cf..f04eef2 100644
--- a/fw/fe310/eos/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/rng.c b/fw/fe310/eos/net/rng.c
index 317941d..7d05a81 100644
--- a/fw/fe310/eos/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/rng.h b/fw/fe310/eos/net/rng.h
index 27bbf74..27bbf74 100644
--- a/fw/fe310/eos/rng.h
+++ b/fw/fe310/eos/net/rng.h
diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/net/sock.c
index 7365c97..1db0cd9 100644
--- a/fw/fe310/eos/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/sock.h b/fw/fe310/eos/net/sock.h
index 5ef42e3..e2f8637 100644
--- a/fw/fe310/eos/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
new file mode 100644
index 0000000..4db49f8
--- /dev/null
+++ b/fw/fe310/eos/net/wifi.c
@@ -0,0 +1,179 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "eos.h"
+#include "event.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) {
+ unsigned char mtype;
+
+ if ((buffer == NULL) || (len < 1)) {
+ eos_net_bad_handler(type, buffer, len);
+ return;
+ }
+
+ mtype = buffer[0];
+ if ((mtype < EOS_WIFI_MAX_MTYPE) && evt_handler[mtype]) {
+ evt_handler[mtype](mtype, buffer, len);
+ } else {
+ eos_net_bad_handler(type, buffer, len);
+ }
+}
+
+void eos_wifi_init(void) {
+ int i;
+
+ for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
+ evt_handler[i] = NULL;
+ }
+ eos_net_set_handler(EOS_NET_MTYPE_WIFI, wifi_handle_msg);
+}
+
+void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
+ if (mtype < EOS_WIFI_MAX_MTYPE) evt_handler[mtype] = handler;
+}
+
+eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) {
+ if (mtype < EOS_WIFI_MAX_MTYPE) return evt_handler[mtype];
+ return NULL;
+}
+
+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;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_START;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
+
+int eos_wifi_stop(unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_STOP;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
+
+int eos_wifi_scan(unsigned char *buffer) {
+ int async;
+
+ 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(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;
+ }
+ 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);
+}
+
+int eos_wifi_disconnect(unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
+ 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
new file mode 100644
index 0000000..2100144
--- /dev/null
+++ b/fw/fe310/eos/net/wifi.h
@@ -0,0 +1,27 @@
+#include <stdint.h>
+#include "../event.h"
+
+#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 2
+
+#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_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/pwr.c b/fw/fe310/eos/pwr.c
deleted file mode 100644
index f42249d..0000000
--- a/fw/fe310/eos/pwr.c
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "encoding.h"
-#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 "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;
-
- AON_REG(AON_RTCCMP) = 0xFFFFFFFF;
- AON_REG(AON_RTCCFG) = PWR_RTC_SCALE;
- AON_REG(AON_RTCHI) = 0;
- AON_REG(AON_RTCLO) = 0;
-
- return EOS_OK;
-}
-
-uint8_t eos_pwr_wakeup_cause(void) {
- return AON_REG(AON_PMUCAUSE) & 0xff;
-}
-
-uint8_t eos_pwr_reset_cause(void) {
- return (AON_REG(AON_PMUCAUSE) >> 8) & 0xff;
-}
-
-int eos_pwr_sleep(void) {
- int rv;
-
- rv = eos_lcd_sleep();
- if (rv) return rv;
-
- eos_spi_select(EOS_SPI_DEV_EVE);
- eve_sleep();
- eos_spi_deselect();
-
- rv = eos_net_sleep(1000);
- if (rv) return rv;
-
- AON_REG(AON_PMUKEY) = 0x51F15E;
- AON_REG(AON_PMUSLEEP) = 1;
-
- return EOS_OK;
-}
-
-void eos_pwr_wake_at(uint32_t msec) {
- uint32_t pmuie;
-
- AON_REG(AON_RTCCFG) |= AON_RTCCFG_ENALWAYS;
- AON_REG(AON_RTCCMP) = msec * PWR_RTC_SFREQ / 1000;
-
- pmuie = AON_REG(AON_PMUIE) | 0x2;
- AON_REG(AON_PMUKEY) = 0x51F15E;
- AON_REG(AON_PMUIE) = pmuie;
-}
-
-void eos_pwr_wake_disable(void) {
- uint32_t pmuie;
-
- AON_REG(AON_RTCCMP) = 0xFFFFFFFF;
- AON_REG(AON_RTCCFG) &= ~AON_RTCCFG_ENALWAYS;
- AON_REG(AON_RTCHI) = 0;
- AON_REG(AON_RTCLO) = 0;
-
- pmuie = AON_REG(AON_PMUIE) & ~0x2;
- 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/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/i2c.c b/fw/fe310/eos/soc/i2c.c
index a507af1..553a9bf 100644
--- a/fw/fe310/eos/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/i2c.h b/fw/fe310/eos/soc/i2c.h
index 20d3dc7..5032988 100644
--- a/fw/fe310/eos/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/i2s.c b/fw/fe310/eos/soc/i2s.c
index 9cc9d9c..5e5eaa7 100644
--- a/fw/fe310/eos/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/i2s.h b/fw/fe310/eos/soc/i2s.h
index 81b4ade..f53e183 100644
--- a/fw/fe310/eos/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/i2s_def.h b/fw/fe310/eos/soc/i2s_def.h
index 3529be1..3529be1 100644
--- a/fw/fe310/eos/i2s_def.h
+++ b/fw/fe310/eos/soc/i2s_def.h
diff --git a/fw/fe310/eos/i2s_priv.h b/fw/fe310/eos/soc/i2s_priv.h
index 25237c3..25237c3 100644
--- a/fw/fe310/eos/i2s_priv.h
+++ b/fw/fe310/eos/soc/i2s_priv.h
diff --git a/fw/fe310/eos/interrupt.c b/fw/fe310/eos/soc/interrupt.c
index dab6fab..dab6fab 100644
--- a/fw/fe310/eos/interrupt.c
+++ b/fw/fe310/eos/soc/interrupt.c
diff --git a/fw/fe310/eos/interrupt.h b/fw/fe310/eos/soc/interrupt.h
index a239934..c6252b5 100644
--- a/fw/fe310/eos/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
new file mode 100644
index 0000000..a2adfd4
--- /dev/null
+++ b/fw/fe310/eos/soc/pwr.c
@@ -0,0 +1,70 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "encoding.h"
+#include "platform.h"
+
+#include "eos.h"
+#include "timer.h"
+#include "dev/net.h"
+
+#include "pwr.h"
+
+#define PWR_RTC_SCALE 15
+#define PWR_RTC_SFREQ (EOS_TIMER_RTC_FREQ >> PWR_RTC_SCALE)
+
+int eos_pwr_init(uint8_t wakeup_cause) {
+ AON_REG(AON_PMUKEY) = 0x51F15E;
+ AON_REG(AON_PMUIE) = 0x5;
+
+ AON_REG(AON_RTCCMP) = 0xFFFFFFFF;
+ AON_REG(AON_RTCCFG) = PWR_RTC_SCALE;
+ AON_REG(AON_RTCHI) = 0;
+ AON_REG(AON_RTCLO) = 0;
+
+ return EOS_OK;
+}
+
+uint8_t eos_pwr_wakeup_cause(void) {
+ return AON_REG(AON_PMUCAUSE) & 0xff;
+}
+
+uint8_t eos_pwr_reset_cause(void) {
+ return (AON_REG(AON_PMUCAUSE) >> 8) & 0xff;
+}
+
+int eos_pwr_sleep(void) {
+ int rv;
+
+ rv = eos_net_sleep(1000);
+ if (rv) return rv;
+
+ AON_REG(AON_PMUKEY) = 0x51F15E;
+ AON_REG(AON_PMUSLEEP) = 1;
+
+ return EOS_OK;
+}
+
+void eos_pwr_wake_at(uint32_t msec) {
+ uint32_t pmuie;
+
+ AON_REG(AON_RTCCFG) |= AON_RTCCFG_ENALWAYS;
+ AON_REG(AON_RTCCMP) = msec * PWR_RTC_SFREQ / 1000;
+
+ pmuie = AON_REG(AON_PMUIE) | 0x2;
+ AON_REG(AON_PMUKEY) = 0x51F15E;
+ AON_REG(AON_PMUIE) = pmuie;
+}
+
+void eos_pwr_wake_disable(void) {
+ uint32_t pmuie;
+
+ AON_REG(AON_RTCCMP) = 0xFFFFFFFF;
+ AON_REG(AON_RTCCFG) &= ~AON_RTCCFG_ENALWAYS;
+ AON_REG(AON_RTCHI) = 0;
+ AON_REG(AON_RTCLO) = 0;
+
+ pmuie = AON_REG(AON_PMUIE) & ~0x2;
+ AON_REG(AON_PMUKEY) = 0x51F15E;
+ AON_REG(AON_PMUIE) = pmuie;
+}
diff --git a/fw/fe310/eos/pwr.h b/fw/fe310/eos/soc/pwr.h
index 264436b..1a0d17a 100644
--- a/fw/fe310/eos/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/spi.c b/fw/fe310/eos/soc/spi.c
index 05c9448..2c36109 100644
--- a/fw/fe310/eos/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/spi.h b/fw/fe310/eos/soc/spi.h
index a23a235..0c2de4b 100644
--- a/fw/fe310/eos/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/spi_priv.h b/fw/fe310/eos/soc/spi_priv.h
index 72c2dae..17081a3 100644
--- a/fw/fe310/eos/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/timer.c b/fw/fe310/eos/soc/timer.c
index 5ae58da..91861a3 100644
--- a/fw/fe310/eos/timer.c
+++ b/fw/fe310/eos/soc/timer.c
@@ -32,7 +32,7 @@ void _eos_timer_handle(void) {
uint64_t now = *mtime;
uint64_t next = 0;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
if (timer_next[i] && (timer_next[i] <= now)) {
timer_next[i] = 0;
if (i == 0) {
@@ -88,7 +88,7 @@ uint32_t eos_timer_get(unsigned char evt) {
return ret;
}
-void eos_timer_set(uint32_t msec, unsigned char evt) {
+void eos_timer_set(unsigned char evt, uint32_t msec) {
int i;
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
@@ -97,7 +97,7 @@ void eos_timer_set(uint32_t msec, unsigned char evt) {
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
timer_next[evt] = tick;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]);
}
*mtimecmp = next;
@@ -112,7 +112,7 @@ void eos_timer_clear(unsigned char evt) {
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
if (timer_next[evt]) {
timer_next[evt] = 0;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]);
}
*mtimecmp = next;
@@ -120,12 +120,11 @@ void eos_timer_clear(unsigned char evt) {
if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
}
-
void eos_time_sleep(uint32_t msec) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
- uint64_t now_ms = *mtime * 1000 / EOS_TIMER_RTC_FREQ;
+ uint64_t mtime0 = *mtime;
- while (*mtime * 1000 / EOS_TIMER_RTC_FREQ < now_ms + msec);
+ while ((*mtime - mtime0) < (msec * EOS_TIMER_RTC_FREQ / 1000 + 1));
}
uint64_t eos_time_get_tick(void) {
@@ -133,6 +132,6 @@ uint64_t eos_time_get_tick(void) {
return *mtime;
}
-uint32_t eos_time_since(uint32_t start) {
- return (eos_time_get_tick() - start) * 1000 / EOS_TIMER_RTC_FREQ;
- }
+uint32_t eos_time_delta_ms(uint32_t tick) {
+ return ((uint32_t)eos_time_get_tick() - tick) * 1000 / EOS_TIMER_RTC_FREQ;
+}
diff --git a/fw/fe310/eos/timer.h b/fw/fe310/eos/soc/timer.h
index e479483..0309454 100644
--- a/fw/fe310/eos/timer.h
+++ b/fw/fe310/eos/soc/timer.h
@@ -6,7 +6,7 @@
#define EOS_TIMER_MAX_ETYPE 4
-#define EOS_TIMER_NONE 0xffffffff
+#define EOS_TIMER_NONE -1
#define EOS_TIMER_RTC_FREQ 32768
typedef void (*eos_timer_handler_t) (unsigned char);
@@ -15,9 +15,9 @@ int eos_timer_init(uint8_t wakeup_cause);
void eos_timer_set_handler(unsigned char evt, eos_timer_handler_t handler);
uint32_t eos_timer_get(unsigned char evt);
-void eos_timer_set(uint32_t msec, unsigned char evt);
+void eos_timer_set(unsigned char evt, uint32_t msec);
void eos_timer_clear(unsigned char evt);
void eos_time_sleep(uint32_t msec);
uint64_t eos_time_get_tick(void);
-uint32_t eos_time_since(uint32_t start);
+uint32_t eos_time_delta_ms(uint32_t tick);
diff --git a/fw/fe310/eos/trap_entry.S b/fw/fe310/eos/soc/trap_entry.S
index fb2b121..96024cb 100644
--- a/fw/fe310/eos/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/uart.c b/fw/fe310/eos/soc/uart.c
index 30f76d9..589832a 100644
--- a/fw/fe310/eos/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/uart.h b/fw/fe310/eos/soc/uart.h
index 94999e6..caaf6c6 100644
--- a/fw/fe310/eos/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
diff --git a/fw/fe310/eos/wifi.c b/fw/fe310/eos/wifi.c
deleted file mode 100644
index 0663582..0000000
--- a/fw/fe310/eos/wifi.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
-#include "eos.h"
-#include "event.h"
-#include "net.h"
-
-#include "wifi.h"
-
-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) {
- unsigned char mtype;
-
- if ((buffer == NULL) || (len < 1)) {
- eos_net_bad_handler(type, buffer, len);
- return;
- }
-
- mtype = buffer[0];
- if ((mtype < EOS_WIFI_MAX_MTYPE) && evt_handler[mtype]) {
- evt_handler[mtype](mtype, buffer, len);
- } else {
- eos_net_bad_handler(type, buffer, len);
- }
-}
-
-void eos_wifi_netinit(void) {
- int i;
-
- for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
- evt_handler[i] = NULL;
- }
- eos_net_set_handler(EOS_NET_MTYPE_WIFI, wifi_handle_msg);
-}
-
-void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
- if (mtype < EOS_WIFI_MAX_MTYPE) evt_handler[mtype] = handler;
-}
-
-eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) {
- if (mtype < EOS_WIFI_MAX_MTYPE) return evt_handler[mtype];
- return NULL;
-}
-
-int eos_wifi_scan(unsigned char *buffer) {
- int async;
-
- 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_auth(const char *ssid, const char *pass, unsigned char *buffer) {
- unsigned char *buf;
- size_t ssid_len, pass_len;
- int async;
-
- async = 0;
- if (buffer == NULL) {
- 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;
-
- buf = buffer;
- buf[0] = EOS_WIFI_MTYPE_AUTH;
- buf++;
- strcpy(buf, ssid);
- buf += ssid_len;
- strcpy(buf, pass);
- buf += pass_len;
-
- return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1 + ssid_len + pass_len, async, 1);
-}
-
-int eos_wifi_connect(unsigned char *buffer) {
- int async;
-
- async = 0;
- if (buffer == NULL) {
- buffer = eos_net_alloc();
- async = 1;
- }
- buffer[0] = EOS_WIFI_MTYPE_CONNECT;
- return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
-}
-
-int eos_wifi_disconnect(unsigned char *buffer) {
- int async;
-
- async = 0;
- if (buffer == NULL) {
- buffer = eos_net_alloc();
- async = 1;
- }
- buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
- return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
-}
diff --git a/fw/fe310/eos/wifi.h b/fw/fe310/eos/wifi.h
deleted file mode 100644
index 4a49518..0000000
--- a/fw/fe310/eos/wifi.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdint.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_MAX_MTYPE 5
-
-void eos_wifi_netinit(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_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);
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
deleted file mode 100644
index dde518c..0000000
--- a/fw/fe310/test/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-include ../common.mk
-DEPS = main.o mem.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o fs.o test.o
-LIBS_ECP =
-
-# LIBS_ECP += -lecp -lecpcr -lecptr -lecptm -lecpdir -lecpvconn
-# DEPS += ecp.o ecp_init.o audio.o
-
-CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I..
-LDFLAGS = app/*.o $(CFLAGS) -L.. -L$(ecp_dir)/build-fe310 -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos $(LIBS_ECP) -Wl,--end-group -T../bsp/default.lds
-TARGET = phone
-
-
-all: $(TARGET)
-
-app_:
- (cd app && $(MAKE)) || exit;
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $<
-
-$(TARGET): app_ $(DEPS)
- $(CC) $(DEPS) $(LDFLAGS) -o $@
-
-clean:
- (cd app && $(MAKE) clean) || exit;
- rm -f *.o *.a $(TARGET)
-
-upload: $(TARGET)
- ../bsp/upload --elf ./$(TARGET) --openocd $(RISCV_OPENOCD_HOME)/bin/openocd --gdb $(RISCV_HOME)/bin/riscv64-unknown-elf-gdb --openocd-config ../bsp/openocd.cfg
-
diff --git a/fw/fe310/test/app/app_root.c b/fw/fe310/test/app/app_root.c
index 7dda3c7..e6de2d1 100644
--- a/fw/fe310/test/app/app_root.c
+++ b/fw/fe310/test/app/app_root.c
@@ -16,7 +16,7 @@
#include "app_root.h"
#define KBD_X 0
-#define KBD_Y 575
+#define KBD_Y 629
#define KBD_W 480
#define KBD_H 225
@@ -84,5 +84,5 @@ void app_root_init(eve_view_constructor_t home_page, int b) {
eve_spi_stop();
- eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1);
+ eos_net_acquire_for_evt(EOS_EVT_EVE | EVE_ETYPE_INTR, 1);
}
diff --git a/fw/fe310/test/app/app_root.h b/fw/fe310/test/app/app_root.h
index b085344..35f889f 100644
--- a/fw/fe310/test/app/app_root.h
+++ b/fw/fe310/test/app/app_root.h
@@ -1,7 +1,7 @@
#include <stdint.h>
#define APP_SCREEN_W 480
-#define APP_SCREEN_H 800
+#define APP_SCREEN_H 854
#define APP_STATUS_H 60
#define APP_FONT_HANDLE 31
diff --git a/fw/fe310/test/fs.c b/fw/fe310/test/fs.c
index 222833b..1dce3af 100644
--- a/fw/fe310/test/fs.c
+++ b/fw/fe310/test/fs.c
@@ -100,5 +100,30 @@ void app_fs_init(void) {
rv = f_mount(&fs, "", 1);
printf("f_mount:%d\n", rv);
}
+
+ if (rv == FR_OK) {
+ FIL f;
+ UINT w;
+ char *msg = "PERA JE CAR!";
+
+ rv = f_open(&f, TEXT_FN, FA_READ);
+ printf("f_open:%d\n", rv);
+ if (!rv) {
+ UINT r;
+ char _msg[TEXT_SIZE];
+
+ memset(_msg, 0, sizeof(_msg));
+ rv = f_read(&f, _msg, sizeof(_msg), &r);
+ printf("f_read:%d %u %s\n", rv, r, _msg);
+ f_close(&f);
+ } else {
+ rv = f_open(&f, TEXT_FN, FA_WRITE | FA_CREATE_ALWAYS);
+ printf("f_open:%d\n", rv);
+ rv = f_write(&f, msg, strlen(msg), &w);
+ printf("f_write:%d\n", rv);
+ }
+ f_close(&f);
+
+ }
eos_spi_deselect();
} \ No newline at end of file
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
index ec57b99..2fc1a04 100644
--- a/fw/fe310/test/main.c
+++ b/fw/fe310/test/main.c
@@ -30,6 +30,8 @@
#include "fs.h"
#include "test.h"
+const uint32_t _eos_touch_matrix[6] = {0xf7ac,0x440,0x3e704,0xfffff718,0x108a3,0xfff76d42};
+
void app_home_page(EVEWindow *window, EVEViewStack *stack) {
EVEWidgetSpec spec[] = {
/*
@@ -63,13 +65,13 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) {
.widget.spec.page.title = "Camera",
.widget.spec.page.constructor = app_cam
},
+ */
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
.widget.spec.page.title = "File system",
.widget.spec.page.constructor = app_fs
},
- */
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
@@ -78,22 +80,26 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) {
},
};
- EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, NULL);
+ EVEForm *form = eve_form_create(window, stack, spec, 2, NULL, NULL, NULL);
}
void print_mem(void);
int main() {
eos_init();
+ // eos_run_once();
+
printf("FREQ:%lu\n", PRCI_get_cpu_freq());
printf("\nREADY.\n");
- app_root_init(app_home_page, 0x20);
- // app_phone_init();
- // app_wifi_init();
- // app_cell_dev_init();
- // app_cell_pdp_init();
- // app_fs_init();
+ app_root_init(app_home_page, 0x10);
+ app_phone_init();
+ app_wifi_init();
+ app_cell_dev_init();
+ app_cell_pdp_init();
+ app_fs_init();
+ // audio_start();
+ // app_ecp_init();
eos_evtq_loop();
}