summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-24 19:50:20 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-24 19:50:20 +0100
commit3050565531af2b3a09f2213893f10c64cf9fe43f (patch)
tree689d10ca064dba4480a85b6ec14a4eb8305d5c89 /fw/fe310
parentd0a0fee0571be63f023f8f6a49a0b76b89871e56 (diff)
added test app with voice, wifi/cellular data connectivity examples
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/bsp/include/platform.h81
-rw-r--r--fw/fe310/bsp/include/sifive/devices/aon.h1
-rw-r--r--fw/fe310/bsp/include/sifive/devices/clint.h12
-rw-r--r--fw/fe310/bsp/include/sifive/devices/gpio.h2
-rw-r--r--fw/fe310/bsp/include/sifive/devices/i2c.h34
-rw-r--r--fw/fe310/bsp/include/sifive/devices/prci.h8
-rw-r--r--fw/fe310/eos/Makefile2
-rw-r--r--fw/fe310/eos/app/root.c7
-rw-r--r--fw/fe310/eos/app/root.h2
-rw-r--r--fw/fe310/eos/cell.c17
-rw-r--r--fw/fe310/eos/cell.h33
-rw-r--r--fw/fe310/eos/eve/eve.h4
-rw-r--r--fw/fe310/eos/eve/eve_kbd.c26
-rw-r--r--fw/fe310/eos/eve/eve_kbd.h1
-rw-r--r--fw/fe310/eos/eve/eve_platform.c13
-rw-r--r--fw/fe310/eos/eve/eve_platform.h9
-rw-r--r--fw/fe310/eos/eve/eve_text.c2
-rw-r--r--fw/fe310/eos/eve/eve_touch.c7
-rw-r--r--fw/fe310/eos/eve/eve_touch.h10
-rw-r--r--fw/fe310/eos/eve/screen/form.c84
-rw-r--r--fw/fe310/eos/eve/screen/form.h13
-rw-r--r--fw/fe310/eos/eve/screen/page.c39
-rw-r--r--fw/fe310/eos/eve/screen/page.h10
-rw-r--r--fw/fe310/eos/eve/screen/screen.c12
-rw-r--r--fw/fe310/eos/eve/widget/Makefile2
-rw-r--r--fw/fe310/eos/eve/widget/freew.c29
-rw-r--r--fw/fe310/eos/eve/widget/freew.h6
-rw-r--r--fw/fe310/eos/eve/widget/pagew.c28
-rw-r--r--fw/fe310/eos/eve/widget/pagew.h3
-rw-r--r--fw/fe310/eos/eve/widget/selectw.c24
-rw-r--r--fw/fe310/eos/eve/widget/selectw.h6
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.c6
-rw-r--r--fw/fe310/eos/eve/widget/spacerw.h2
-rw-r--r--fw/fe310/eos/eve/widget/strw.c132
-rw-r--r--fw/fe310/eos/eve/widget/strw.h3
-rw-r--r--fw/fe310/eos/eve/widget/textw.c159
-rw-r--r--fw/fe310/eos/eve/widget/textw.h7
-rw-r--r--fw/fe310/eos/eve/widget/widget.c3
-rw-r--r--fw/fe310/eos/eve/widget/widget.h5
-rw-r--r--fw/fe310/eos/eve/widget/widgets.h2
-rw-r--r--fw/fe310/eos/net.c14
-rw-r--r--fw/fe310/eos/power.c9
-rw-r--r--fw/fe310/eos/power.h5
-rw-r--r--fw/fe310/eos/sock.c9
-rw-r--r--fw/fe310/eos/sock.h1
-rw-r--r--fw/fe310/eos/wifi.c15
-rw-r--r--fw/fe310/eos/wifi.h10
-rw-r--r--fw/fe310/test/Makefile8
-rw-r--r--fw/fe310/test/cell_data.c115
-rw-r--r--fw/fe310/test/cell_data.h4
-rw-r--r--fw/fe310/test/main.c83
-rw-r--r--fw/fe310/test/modem.c54
-rw-r--r--fw/fe310/test/modem.h2
-rw-r--r--fw/fe310/test/phone.c142
-rw-r--r--fw/fe310/test/phone.h9
-rw-r--r--fw/fe310/test/status.c93
-rw-r--r--fw/fe310/test/status.h2
-rw-r--r--fw/fe310/test/wifi.c108
-rw-r--r--fw/fe310/test/wifi.h4
59 files changed, 1095 insertions, 438 deletions
diff --git a/fw/fe310/bsp/include/platform.h b/fw/fe310/bsp/include/platform.h
index 5178d86..46ce61c 100644
--- a/fw/fe310/bsp/include/platform.h
+++ b/fw/fe310/bsp/include/platform.h
@@ -18,6 +18,7 @@
#include "sifive/devices/prci.h"
#include "sifive/devices/pwm.h"
#include "sifive/devices/spi.h"
+#include "sifive/devices/i2c.h"
#include "sifive/devices/uart.h"
/****************************************************************************
@@ -37,6 +38,7 @@
#define UART0_CTRL_ADDR _AC(0x10013000,UL)
#define SPI0_CTRL_ADDR _AC(0x10014000,UL)
#define PWM0_CTRL_ADDR _AC(0x10015000,UL)
+#define I2C0_CTRL_ADDR _AC(0x10016000,UL)
#define UART1_CTRL_ADDR _AC(0x10023000,UL)
#define SPI1_CTRL_ADDR _AC(0x10024000,UL)
#define PWM1_CTRL_ADDR _AC(0x10025000,UL)
@@ -47,43 +49,45 @@
// IOF masks
#define IOF0_SPI1_MASK _AC(0x000007FC,UL)
-#define SPI11_NUM_SS (4)
-#define IOF_SPI1_SS0 (2u)
-#define IOF_SPI1_SS1 (8u)
-#define IOF_SPI1_SS2 (9u)
-#define IOF_SPI1_SS3 (10u)
-#define IOF_SPI1_MOSI (3u)
-#define IOF_SPI1_MISO (4u)
-#define IOF_SPI1_SCK (5u)
-#define IOF_SPI1_DQ0 (3u)
-#define IOF_SPI1_DQ1 (4u)
-#define IOF_SPI1_DQ2 (6u)
-#define IOF_SPI1_DQ3 (7u)
+#define SPI11_NUM_SS (4)
+#define IOF_SPI1_SS0 (2u)
+#define IOF_SPI1_SS1 (8u)
+#define IOF_SPI1_SS2 (9u)
+#define IOF_SPI1_SS3 (10u)
+#define IOF_SPI1_MOSI (3u)
+#define IOF_SPI1_MISO (4u)
+#define IOF_SPI1_SCK (5u)
+#define IOF_SPI1_DQ0 (3u)
+#define IOF_SPI1_DQ1 (4u)
+#define IOF_SPI1_DQ2 (6u)
+#define IOF_SPI1_DQ3 (7u)
#define IOF0_SPI2_MASK _AC(0xFC000000,UL)
-#define SPI2_NUM_SS (1)
-#define IOF_SPI2_SS0 (26u)
-#define IOF_SPI2_MOSI (27u)
-#define IOF_SPI2_MISO (28u)
-#define IOF_SPI2_SCK (29u)
-#define IOF_SPI2_DQ0 (27u)
-#define IOF_SPI2_DQ1 (28u)
-#define IOF_SPI2_DQ2 (30u)
-#define IOF_SPI2_DQ3 (31u)
-
-//#define IOF0_I2C_MASK _AC(0x00003000,UL)
-
-#define IOF0_UART0_MASK _AC(0x00030000, UL)
-#define IOF_UART0_RX (16u)
-#define IOF_UART0_TX (17u)
-
-#define IOF0_UART1_MASK _AC(0x03000000, UL)
-#define IOF_UART1_RX (24u)
-#define IOF_UART1_TX (25u)
-
-#define IOF1_PWM0_MASK _AC(0x0000000F, UL)
-#define IOF1_PWM1_MASK _AC(0x00780000, UL)
-#define IOF1_PWM2_MASK _AC(0x00003C00, UL)
+#define SPI2_NUM_SS (1)
+#define IOF_SPI2_SS0 (26u)
+#define IOF_SPI2_MOSI (27u)
+#define IOF_SPI2_MISO (28u)
+#define IOF_SPI2_SCK (29u)
+#define IOF_SPI2_DQ0 (27u)
+#define IOF_SPI2_DQ1 (28u)
+#define IOF_SPI2_DQ2 (30u)
+#define IOF_SPI2_DQ3 (31u)
+
+#define IOF0_I2C0_MASK _AC(0x00003000,UL)
+#define IOF_I2C0_SCL (13u)
+#define IOF_I2C0_SDA (12u)
+
+#define IOF0_UART0_MASK _AC(0x00030000,UL)
+#define IOF_UART0_RX (16u)
+#define IOF_UART0_TX (17u)
+
+#define IOF0_UART1_MASK _AC(0x00840000,UL)
+#define IOF_UART1_RX (23u)
+#define IOF_UART1_TX (18u)
+
+#define IOF1_PWM0_MASK _AC(0x0000000F,UL)
+#define IOF1_PWM1_MASK _AC(0x00780000,UL)
+#define IOF1_PWM2_MASK _AC(0x00003C00,UL)
// Interrupt numbers
#define INT_RESERVED 0
@@ -98,9 +102,14 @@
#define INT_PWM0_BASE 40
#define INT_PWM1_BASE 44
#define INT_PWM2_BASE 48
+#define INT_I2C0_BASE 52
// Helper functions
+#define _REG8(p, i) (*(volatile uint8_t *) ((p) + (i)))
+#define _REG16(p, i) (*(volatile uint16_t *) ((p) + (i)))
#define _REG32(p, i) (*(volatile uint32_t *) ((p) + (i)))
+#define _REG8P(p, i) ((volatile uint8_t *) ((p) + (i)))
+#define _REG16P(p, i) ((volatile uint16_t *) ((p) + (i)))
#define _REG32P(p, i) ((volatile uint32_t *) ((p) + (i)))
#define AON_REG(offset) _REG32(AON_CTRL_ADDR, offset)
#define CLINT_REG(offset) _REG32(CLINT_CTRL_ADDR, offset)
@@ -114,6 +123,8 @@
#define SPI0_REG(offset) _REG32(SPI0_CTRL_ADDR, offset)
#define SPI1_REG(offset) _REG32(SPI1_CTRL_ADDR, offset)
#define SPI2_REG(offset) _REG32(SPI2_CTRL_ADDR, offset)
+#define I2C0_REG(offset) _REG32(I2C0_CTRL_ADDR, offset)
+#define I2C0_REGB(offset) _REG8(I2C0_CTRL_ADDR, offset)
#define UART0_REG(offset) _REG32(UART0_CTRL_ADDR, offset)
#define UART1_REG(offset) _REG32(UART1_CTRL_ADDR, offset)
diff --git a/fw/fe310/bsp/include/sifive/devices/aon.h b/fw/fe310/bsp/include/sifive/devices/aon.h
index 63f1db3..4a3332c 100644
--- a/fw/fe310/bsp/include/sifive/devices/aon.h
+++ b/fw/fe310/bsp/include/sifive/devices/aon.h
@@ -57,6 +57,7 @@
#define AON_PMUKEY 0x14C
#define AON_LFROSC 0x070
+
/* Constants */
#define AON_WDOGKEY_VALUE 0x51F15E
diff --git a/fw/fe310/bsp/include/sifive/devices/clint.h b/fw/fe310/bsp/include/sifive/devices/clint.h
index cd3e0c7..617b657 100644
--- a/fw/fe310/bsp/include/sifive/devices/clint.h
+++ b/fw/fe310/bsp/include/sifive/devices/clint.h
@@ -4,11 +4,11 @@
#define _SIFIVE_CLINT_H
-#define CLINT_MSIP 0x0000
-#define CLINT_MSIP_size 0x4
-#define CLINT_MTIMECMP 0x4000
+#define CLINT_MSIP 0x0000
+#define CLINT_MSIP_size 0x4
+#define CLINT_MTIMECMP 0x4000
#define CLINT_MTIMECMP_size 0x8
-#define CLINT_MTIME 0xBFF8
-#define CLINT_MTIME_size 0x8
+#define CLINT_MTIME 0xBFF8
+#define CLINT_MTIME_size 0x8
-#endif /* _SIFIVE_CLINT_H */
+#endif /* _SIFIVE_CLINT_H */
diff --git a/fw/fe310/bsp/include/sifive/devices/gpio.h b/fw/fe310/bsp/include/sifive/devices/gpio.h
index f7f0acb..835ac83 100644
--- a/fw/fe310/bsp/include/sifive/devices/gpio.h
+++ b/fw/fe310/bsp/include/sifive/devices/gpio.h
@@ -19,6 +19,6 @@
#define GPIO_LOW_IP (0x34)
#define GPIO_IOF_EN (0x38)
#define GPIO_IOF_SEL (0x3C)
-#define GPIO_OUTPUT_XOR (0x40)
+#define GPIO_OUTPUT_XOR (0x40)
#endif /* _SIFIVE_GPIO_H */
diff --git a/fw/fe310/bsp/include/sifive/devices/i2c.h b/fw/fe310/bsp/include/sifive/devices/i2c.h
new file mode 100644
index 0000000..900e238
--- /dev/null
+++ b/fw/fe310/bsp/include/sifive/devices/i2c.h
@@ -0,0 +1,34 @@
+// See LICENSE for license details.
+
+#ifndef _SIFIVE_I2C_H
+#define _SIFIVE_I2C_H
+
+/* Register offsets */
+
+#define I2C_PRESCALE_LOW 0x00
+#define I2C_PRESCALE_HIGH 0x04
+#define I2C_CONTROL 0x08
+#define I2C_TRANSMIT 0x0c
+#define I2C_RECEIVE 0x0c
+#define I2C_COMMAND 0x10
+#define I2C_STATUS 0x10
+
+/* Constants */
+
+#define I2C_CONTROL_EN (1UL << 7)
+#define I2C_CONTROL_IE (1UL << 6)
+#define I2C_WRITE (0UL << 0)
+#define I2C_READ (1UL << 0)
+#define I2C_CMD_START (1UL << 7)
+#define I2C_CMD_STOP (1UL << 6)
+#define I2C_CMD_READ (1UL << 5)
+#define I2C_CMD_WRITE (1UL << 4)
+#define I2C_CMD_ACK (1UL << 3)
+#define I2C_CMD_IACK (1UL << 0)
+#define I2C_STATUS_RXACK (1UL << 7)
+#define I2C_STATUS_BUSY (1UL << 6)
+#define I2C_STATUS_AL (1UL << 5)
+#define I2C_STATUS_TIP (1UL << 1)
+#define I2C_STATUS_IP (1UL << 0)
+
+#endif /* _SIFIVE_I2C_H */
diff --git a/fw/fe310/bsp/include/sifive/devices/prci.h b/fw/fe310/bsp/include/sifive/devices/prci.h
index 1a3de58..d46da08 100644
--- a/fw/fe310/bsp/include/sifive/devices/prci.h
+++ b/fw/fe310/bsp/include/sifive/devices/prci.h
@@ -12,13 +12,13 @@
#define PRCI_PROCMONCFG (0x00F0)
/* Fields */
-#define ROSC_DIV(x) (((x) & 0x2F) << 0 )
+#define ROSC_DIV(x) (((x) & 0x2F) << 0 )
#define ROSC_TRIM(x) (((x) & 0x1F) << 16)
-#define ROSC_EN(x) (((x) & 0x1 ) << 30)
+#define ROSC_EN(x) (((x) & 0x1 ) << 30)
#define ROSC_RDY(x) (((x) & 0x1 ) << 31)
-#define XOSC_EN(x) (((x) & 0x1) << 30)
-#define XOSC_RDY(x) (((x) & 0x1) << 31)
+#define XOSC_EN(x) (((x) & 0x1) << 30)
+#define XOSC_RDY(x) (((x) & 0x1) << 31)
#define PLL_R(x) (((x) & 0x7) << 0)
// single reserved bit for F LSB.
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index ef08fd1..0b3d6fe 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -2,7 +2,7 @@ include ../common.mk
CFLAGS += -I. -I../bsp/include -I../bsp/drivers
-obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o uart.o spi.o spi_dev.o net.o wifi.o cell.o sock.o unicode.o
+obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.o i2s.o i2c.o uart.o spi.o spi_dev.o net.o wifi.o cell.o sock.o unicode.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c
index 6eb3fa6..a86b291 100644
--- a/fw/fe310/eos/app/root.c
+++ b/fw/fe310/eos/app/root.c
@@ -97,10 +97,11 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) {
for (i=0; i<widget_size; i++) {
if (widget->label) eve_free(widget->label);
eve_widget_destroy(widget);
+ widget = eve_widget_next(widget);
}
}
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor) {
+EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor) {
EVEWidget *widgets;
EVEWidget *widget;
EVELabel *label;
@@ -146,8 +147,8 @@ EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec s
widget = eve_widget_next(widget);
}
- if (destructor == NULL) destructor = (eve_page_destructor_t)app_form_destroy;
- eve_form_init(form, window, stack, widgets, spec_size, destructor);
+ if (destructor == NULL) destructor = app_form_destroy;
+ eve_form_init(form, window, stack, widgets, spec_size, action, destructor);
return form;
}
diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h
index 1885515..2b6fc63 100644
--- a/fw/fe310/eos/app/root.h
+++ b/fw/fe310/eos/app/root.h
@@ -24,5 +24,5 @@ typedef struct APPWidgetSpec {
EVEScreen *app_screen(void);
void app_root_init(eve_view_constructor_t home_page);
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor);
+EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor);
void app_form_destroy(EVEForm *form);
diff --git a/fw/fe310/eos/cell.c b/fw/fe310/eos/cell.c
index 452fb47..2886041 100644
--- a/fw/fe310/eos/cell.c
+++ b/fw/fe310/eos/cell.c
@@ -10,7 +10,7 @@
static eos_evt_handler_t evt_handler[EOS_CELL_MAX_MTYPE];
-static void cell_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char mtype;
unsigned char idx;
@@ -28,19 +28,13 @@ static void cell_handle_evt(unsigned char type, unsigned char *buffer, uint16_t
}
}
-static void cell_handle_rdy(unsigned char type, unsigned char *buffer, uint16_t len) {
- // Do nothing
- eos_net_free(buffer, 0);
-}
-
void eos_cell_init(void) {
int i;
for (i=0; i<EOS_CELL_MAX_MTYPE; i++) {
evt_handler[i] = NULL;
}
- eos_net_set_handler(EOS_NET_MTYPE_CELL, cell_handle_evt);
- eos_cell_set_handler(EOS_CELL_MTYPE_READY, cell_handle_rdy);
+ eos_net_set_handler(EOS_NET_MTYPE_CELL, cell_handle_msg);
}
void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
@@ -48,3 +42,10 @@ void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
if (idx < EOS_CELL_MAX_MTYPE) evt_handler[idx] = handler;
}
+
+eos_evt_handler_t eos_cell_get_handler(unsigned char mtype) {
+ unsigned char idx = (mtype & EOS_CELL_MTYPE_MASK) >> 4;
+
+ if (idx < EOS_CELL_MAX_MTYPE) return evt_handler[idx];
+ return NULL;
+}
diff --git a/fw/fe310/eos/cell.h b/fw/fe310/eos/cell.h
index 371f7ba..90bb349 100644
--- a/fw/fe310/eos/cell.h
+++ b/fw/fe310/eos/cell.h
@@ -1,23 +1,25 @@
#include <stdint.h>
#include "event.h"
-#define EOS_CELL_MTYPE_DEV 0x00
-#define EOS_CELL_MTYPE_VOICE 0x10
-#define EOS_CELL_MTYPE_SMS 0x20
-#define EOS_CELL_MTYPE_CBS 0x30
-#define EOS_CELL_MTYPE_USSD 0x40
+#define EOS_CELL_MTYPE_DEV 0x10
+#define EOS_CELL_MTYPE_VOICE 0x20
+#define EOS_CELL_MTYPE_SMS 0x30
+#define EOS_CELL_MTYPE_CBS 0x40
+#define EOS_CELL_MTYPE_USSD 0x50
#define EOS_CELL_MTYPE_DATA 0x70
#define EOS_CELL_MTYPE_MASK 0xf0
#define EOS_CELL_MAX_MTYPE 8
-#define EOS_CELL_MTYPE_READY 0
-#define EOS_CELL_MTYPE_UART_DATA 1
-#define EOS_CELL_MTYPE_UART_TAKE 2
-#define EOS_CELL_MTYPE_UART_GIVE 3
-#define EOS_CELL_MTYPE_PCM_DATA 4
-#define EOS_CELL_MTYPE_PCM_START 5
-#define EOS_CELL_MTYPE_PCM_STOP 6
+/* EOS_CELL_MTYPE_DEV subtypes */
+#define EOS_CELL_MTYPE_READY 1
+#define EOS_CELL_MTYPE_UART_DATA 2
+#define EOS_CELL_MTYPE_UART_TAKE 3
+#define EOS_CELL_MTYPE_UART_GIVE 4
+#define EOS_CELL_MTYPE_PCM_DATA 5
+#define EOS_CELL_MTYPE_PCM_START 6
+#define EOS_CELL_MTYPE_PCM_STOP 7
+#define EOS_CELL_MTYPE_RESET 8
#define EOS_CELL_MTYPE_VOICE_DIAL 1
#define EOS_CELL_MTYPE_VOICE_RING 2
@@ -25,7 +27,9 @@
#define EOS_CELL_MTYPE_VOICE_HANGUP 4
#define EOS_CELL_MTYPE_VOICE_BEGIN 5
#define EOS_CELL_MTYPE_VOICE_END 6
-#define EOS_CELL_MTYPE_VOICE_MISSED 7
+#define EOS_CELL_MTYPE_VOICE_MISS 7
+#define EOS_CELL_MTYPE_VOICE_BUSY 8
+#define EOS_CELL_MTYPE_VOICE_ERR 9
#define EOS_CELL_MTYPE_SMS_LIST 1
#define EOS_CELL_MTYPE_SMS_SEND 2
@@ -45,4 +49,5 @@
#define EOS_CELL_SMS_ADDRTYPE_OTHER 3
void eos_cell_init(void);
-void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler); \ No newline at end of file
+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/eve/eve.h b/fw/fe310/eos/eve/eve.h
index e204158..e0583f0 100644
--- a/fw/fe310/eos/eve/eve.h
+++ b/fw/fe310/eos/eve/eve.h
@@ -7,6 +7,10 @@
#define EVE_OK 0
#define EVE_ERR -1
+
+#define EVE_ERR_FULL -10
+#define EVE_ERR_EMPTY -11
+
#define EVE_ERR_NOMEM -100
#define EVE_PSTATE_ACTIVE 0
diff --git a/fw/fe310/eos/eve/eve_kbd.c b/fw/fe310/eos/eve/eve_kbd.c
index 99210ce..5dd4d5a 100644
--- a/fw/fe310/eos/eve/eve_kbd.c
+++ b/fw/fe310/eos/eve/eve_kbd.c
@@ -38,24 +38,36 @@ void eve_kbd_init(EVEKbd *kbd, EVERect *g, uint32_t mem_addr, uint32_t *mem_next
}
kbd->mem_addr = mem_addr;
kbd->key_modifier = 0;
+ kbd->key_modifier_sticky = 0;
+ kbd->key_modifier_lock = 0;
kbd->key_count = 0;
kbd->key_down = 0;
kbd->putc = NULL;
kbd->param = NULL;
- kbd->active = 1;
+ kbd->key_down = 0xff;
eve_write16(REG_CMD_DL, 0);
eve_kbd_draw(kbd);
eve_cmd_exec(1);
mem_size = eve_read16(REG_CMD_DL);
eve_cmd(CMD_MEMCPY, "www", mem_addr, EVE_RAM_DL, mem_size);
eve_cmd_exec(1);
- kbd->active = 0;
+ kbd->key_down = 0;
kbd->mem_size = mem_size;
*mem_next = kbd->mem_addr + kbd->mem_size;
}
+void eve_kbd_close(EVEKbd *kbd) {
+ kbd->key_modifier = 0;
+ kbd->key_modifier_sticky = 0;
+ kbd->key_modifier_lock = 0;
+ kbd->key_count = 0;
+ kbd->key_down = 0;
+ kbd->putc = NULL;
+ kbd->param = NULL;
+}
+
void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc, void *param) {
kbd->putc = putc;
kbd->param = param;
@@ -64,9 +76,12 @@ void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc, void *param)
int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx) {
EVETouch *t;
uint16_t evt;
+ int ret;
t = eve_touch_evt(tag0, touch_idx, 1, 126, &evt);
if (t && evt) {
+ ret = 1;
+
if (evt & EVE_TOUCH_ETYPE_TAG) {
uint8_t _tag = t->tag;
@@ -117,16 +132,15 @@ int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx) {
}
}
}
- kbd->active = 1;
} else {
- kbd->active = 0;
+ ret = 0;
}
- return kbd->active;
+ return ret;
}
uint8_t eve_kbd_draw(EVEKbd *kbd) {
- if (kbd->active) {
+ if (kbd->key_down || kbd->key_modifier) {
int x = kbd->g.x;
int y = kbd->g.y;
int w = kbd->g.w;
diff --git a/fw/fe310/eos/eve/eve_kbd.h b/fw/fe310/eos/eve/eve_kbd.h
index b27f54d..7746472 100644
--- a/fw/fe310/eos/eve/eve_kbd.h
+++ b/fw/fe310/eos/eve/eve_kbd.h
@@ -17,6 +17,7 @@ typedef struct EVEKbd {
} EVEKbd;
void eve_kbd_init(EVEKbd *kbd, EVERect *g, uint32_t mem_addr, uint32_t *mem_next);
+void eve_kbd_close(EVEKbd *kbd);
void eve_kbd_set_handler(EVEKbd *kbd, eve_kbd_input_handler_t putc, void *param);
int eve_kbd_touch(EVEKbd *kbd, uint8_t tag0, int touch_idx);
uint8_t eve_kbd_draw(EVEKbd *kbd);
diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c
index e64d326..7f1b775 100644
--- a/fw/fe310/eos/eve/eve_platform.c
+++ b/fw/fe310/eos/eve/eve_platform.c
@@ -61,3 +61,16 @@ void eve_platform_init(void) {
eos_spi_dev_set_div(EOS_DEV_DISP, 4);
}
+
+#include <stdio.h>
+
+void *eve_malloc(size_t size) {
+ void *p = malloc(size);
+ printf("MALLOC:%p %d\n", p, size);
+ return p;
+}
+
+void eve_free(void *p) {
+ printf("FREE:%p\n", p);
+ free(p);
+}
diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h
index 514c4ee..7d085db 100644
--- a/fw/fe310/eos/eve/eve_platform.h
+++ b/fw/fe310/eos/eve/eve_platform.h
@@ -19,12 +19,15 @@
#define eve_spi_xchg24 eos_spi_xchg24
#define eve_spi_xchg32 eos_spi_xchg32
-#define eve_malloc malloc
-#define eve_free free
-
void eve_time_sleep(uint32_t ms);
void eve_timer_set(uint32_t ms);
void eve_timer_clear(void);
uint64_t eve_time_get_tick(void);
void eve_platform_init(void);
+
+//#define eve_malloc malloc
+//#define eve_free free
+
+void *eve_malloc(size_t);
+void eve_free(void *); \ No newline at end of file
diff --git a/fw/fe310/eos/eve/eve_text.c b/fw/fe310/eos/eve/eve_text.c
index 7a42a24..d23d012 100644
--- a/fw/fe310/eos/eve/eve_text.c
+++ b/fw/fe310/eos/eve/eve_text.c
@@ -151,7 +151,7 @@ uint8_t eve_text_draw(EVEText *box, uint8_t tag) {
box->tag = tag;
if (tag != EVE_TAG_NOTAG) {
eve_cmd_dl(TAG(tag));
- eve_touch_set_opt(tag, EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_EXT);
+ eve_touch_set_opt(tag, EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_EXT_Y);
tag++;
}
eve_cmd(CMD_APPEND, "ww", box->mem_addr + box->w * 2 * box->line_size, box->dl_size * 4);
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index a6db581..e3dae58 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -111,7 +111,7 @@ void eve_handle_touch(void) {
}
_touch_timer_clear();
}
- touch->evt = EVE_TOUCH_ETYPE_POINT | _eevt;
+ touch->evt = EVE_TOUCH_ETYPE_POINT | _evt;
touch->eevt = _eevt;
touch->tag0 = 0;
touch->tag = 0;
@@ -149,7 +149,10 @@ void eve_handle_touch(void) {
if (!_touch_timer.evt) _touch_timer_clear();
}
if (touch->tracker.tag && touch->tracker.track) {
- if (!_touch_timer.tag && (_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_EXT)) {
+ uint8_t opt = _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 (!_touch_timer.tag && track_ext) {
_touch_timer_set(touch->tracker.tag, i, EVE_TOUCH_ETYPE_TRACK, touch->x, touch->y, EVE_TIMEOUT_TRACK);
if (_ext_tracker.init) _ext_tracker.init(&_touch_timer, touch);
} else {
diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h
index 9f935bc..454dcc7 100644
--- a/fw/fe310/eos/eve/eve_touch.h
+++ b/fw/fe310/eos/eve/eve_touch.h
@@ -37,13 +37,15 @@
#define EVE_TOUCH_OPT_TRACK_REG EVE_TOUCH_ETYPE_TRACK_REG
#define EVE_TOUCH_OPT_TRACK_X 0x04
#define EVE_TOUCH_OPT_TRACK_Y 0x08
-#define EVE_TOUCH_OPT_TRACK_EXT 0x10
+#define EVE_TOUCH_OPT_TRACK_EXT_X 0x10
+#define EVE_TOUCH_OPT_TRACK_EXT_Y 0x20
#define EVE_TOUCH_OPT_LPRESS 0x40
#define EVE_TOUCH_OPT_DTAP 0x80
-#define EVE_TOUCH_OPT_TRACK_XY (EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_Y)
-#define EVE_TOUCH_OPT_TRACK_MASK (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)
-#define EVE_TOUCH_OPT_TIMER_MASK (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_DTAP)
+#define EVE_TOUCH_OPT_TRACK_XY (EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_Y)
+#define EVE_TOUCH_OPT_TRACK_EXT_XY (EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_TRACK_EXT_Y)
+#define EVE_TOUCH_OPT_TRACK_MASK (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)
+#define EVE_TOUCH_OPT_TIMER_MASK (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_DTAP)
typedef void (*eve_touch_handler_t) (void *, uint8_t, int);
diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c
index fe1bd0d..cf5653b 100644
--- a/fw/fe310/eos/eve/screen/form.c
+++ b/fw/fe310/eos/eve/screen/form.c
@@ -18,39 +18,45 @@
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
-int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor) {
+int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor) {
memset(form, 0, sizeof(EVEForm));
- eve_page_init(&form->p, window, stack, eve_form_touch, eve_form_draw, eve_form_handle_evt, eve_form_update_g, destructor);
+ eve_page_init(&form->p, window, stack, eve_form_touch, eve_form_draw, (eve_page_destructor_t)destructor);
+
form->widget = widget;
form->widget_size = widget_size;
- eve_form_update_g(&form->p, NULL);
+ form->action = action;
+ eve_form_update_g(form, NULL);
}
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx) {
EVEForm *form = (EVEForm *)v;
EVEWidget *widget = form->widget;
+ EVETouch *t;
+ uint16_t evt;
int i, ret = 0;
- if (touch_idx == 0) {
- EVETouch *t;
- uint16_t evt;
+ if (touch_idx > 0) return 0;
- t = eve_touch_evt(tag0, touch_idx, form->p.v.window->tag, 1, &evt);
- if (t && evt) {
- eve_form_handle_evt(&form->p, NULL, t, evt, tag0, touch_idx);
- if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (t->eevt == 0)) eve_page_set_focus(&form->p, NULL, NULL);
- ret = 1;
- }
+ t = eve_touch_evt(tag0, touch_idx, form->p.v.window->tag, 1, &evt);
+ if (t && evt) {
+ ret = eve_form_handle_evt(form, NULL, t, evt);
+ if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (t->eevt == 0)) eve_page_set_focus(&form->p, NULL, NULL);
+ if (ret) return 1;
}
for (i=0; i<form->widget_size; i++) {
if (eve_page_rect_visible(&form->p, &widget->g)) {
- int r = widget->touch(widget, &form->p, tag0, touch_idx);
- ret = ret || r;
+ t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
+ if (t && evt) {
+ ret = widget->touch(widget, &form->p, t, evt);
+ if (ret) return 1;
+ ret = eve_form_handle_evt(form, widget, t, evt);
+ if (ret) return 1;
+ }
}
widget = eve_widget_next(widget);
}
- return ret;
+ return 0;
}
uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
@@ -58,6 +64,7 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
EVEWidget *widget = form->widget;
int i;
uint8_t tagN = tag0;
+ uint8_t tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_Y;
eve_cmd_dl(SAVE_CONTEXT());
eve_cmd_dl(VERTEX_FORMAT(0));
@@ -70,32 +77,25 @@ uint8_t eve_form_draw(EVEView *v, uint8_t tag0) {
eve_label_draw(widget->label);
eve_cmd_dl(TAG_MASK(1));
}
- if (eve_page_rect_visible(&form->p, &widget->g)) tagN = widget->draw(widget, &form->p, tagN);
+ if (eve_page_rect_visible(&form->p, &widget->g)) {
+ uint16_t h = widget->g.h;
+ tagN = widget->draw(widget, &form->p, tagN);
+ if (h != widget->g.h) eve_form_update_g(form, widget);
+ }
widget = eve_widget_next(widget);
}
eve_cmd_dl(RESTORE_CONTEXT());
for (i=tag0; i<tagN; i++) {
- eve_touch_set_opt(i, eve_touch_get_opt(i) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT);
+ eve_touch_set_opt(i, eve_touch_get_opt(i) | tag_opt);
}
- if (v->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(v->window->tag, eve_touch_get_opt(v->window->tag) | EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT);
+ if (v->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(v->window->tag, eve_touch_get_opt(v->window->tag) | tag_opt);
return tagN;
}
-int eve_form_handle_evt(EVEPage *page, EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx) {
- /*
- if (evt & EVE_TOUCH_ETYPE_TRACK_Y) {
- // do scroll
- } else {
- // go back / forward
- }
- */
-}
-
-void eve_form_update_g(EVEPage *page, EVEWidget *_widget) {
- EVEForm *form = (EVEForm *)page;
+void eve_form_update_g(EVEForm *form, EVEWidget *_widget) {
EVEWidget *widget = form->widget;
int i;
uint16_t w = 0;
@@ -125,10 +125,34 @@ void eve_form_update_g(EVEPage *page, EVEWidget *_widget) {
}
}
+int eve_form_handle_evt(EVEForm *form, EVEWidget *widget, EVETouch *touch, uint16_t evt) {
+ static int16_t start;
+
+ if ((evt & EVE_TOUCH_ETYPE_TRACK) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)) {
+ if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ start = form->p.win_y;
+ }
+ form->p.win_y = start + touch->y0 - touch->y;
+ return 1;
+ }
+ if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT)) {
+ eve_page_close((EVEPage *)form);
+ return 1;
+ }
+ if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) && form->action) {
+ form->action(form);
+ return 1;
+ }
+
+ return 0;
+}
+
EVEWidget *eve_form_widget(EVEForm *form, uint16_t idx) {
EVEWidget *w = form->widget;
int i;
+ if (idx >= form->widget_size) return NULL;
+
for (i=0; i<idx; i++) {
w = eve_widget_next(w);
}
diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h
index cab10b9..426a655 100644
--- a/fw/fe310/eos/eve/screen/form.h
+++ b/fw/fe310/eos/eve/screen/form.h
@@ -1,16 +1,23 @@
#include <stdint.h>
struct EVEWidget;
+struct EVEForm;
+
+typedef void (*eve_form_action_t) (struct EVEForm *);
+typedef void (*eve_form_destructor_t) (struct EVEForm *);
typedef struct EVEForm {
EVEPage p;
struct EVEWidget *widget;
uint16_t widget_size;
+ eve_form_action_t action;
} EVEForm;
-int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_page_destructor_t destructor);
+int eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_action_t action, eve_form_destructor_t destructor);
+
int eve_form_touch(EVEView *v, uint8_t tag0, int touch_idx);
uint8_t eve_form_draw(EVEView *v, uint8_t tag0);
-int eve_form_handle_evt(EVEPage *page, struct EVEWidget *widget, EVETouch *touch, uint16_t evt, uint8_t tag0, int touch_idx);
-void eve_form_update_g(EVEPage *page, struct EVEWidget *widget);
+
+void eve_form_update_g(EVEForm *form, struct EVEWidget *widget);
+int eve_form_handle_evt(EVEForm *form, struct EVEWidget *widget, EVETouch *touch, uint16_t evt);
struct EVEWidget *eve_form_widget(EVEForm *form, uint16_t idx);
diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c
index 9568ce6..980cf33 100644
--- a/fw/fe310/eos/eve/screen/page.c
+++ b/fw/fe310/eos/eve/screen/page.c
@@ -16,11 +16,9 @@
#define CH_EOF 0x1a
-void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor) {
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_destructor_t destructor) {
memset(page, 0, sizeof(EVEPage));
eve_view_init(&page->v, window, touch, draw, NULL);
- page->handle_evt = handle_evt;
- page->update_g = update_g;
page->destructor = destructor;
page->stack = stack;
page->widget_f = NULL;
@@ -37,11 +35,15 @@ void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor) {
void eve_page_close(EVEPage *page) {
EVEWindow *window = page->v.window;
+ EVEScreen *screen = window->screen;
EVEViewStack *stack = page->stack;
eve_page_destructor_t destructor = page->destructor;
- if (destructor) destructor(page);
- eve_view_destroy(window, stack);
+ if (stack->level > 1) {
+ if (destructor) destructor(page);
+ eve_screen_hide_kbd(screen);
+ eve_view_destroy(window, stack);
+ }
}
int16_t eve_page_x(EVEPage *page, int16_t x) {
@@ -62,21 +64,18 @@ int16_t eve_page_scr_y(EVEPage *page, int16_t y) {
void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *f) {
if (page->widget_f != widget) {
- EVEKbd *kbd = eve_screen_get_kbd(page->v.window->screen);
-
- if (kbd) {
- EVEWidget *widget_f = page->widget_f;
-
- if (widget_f && widget_f->putc) {
- eve_screen_hide_kbd(page->v.window->screen);
- widget_f->putc(page, CH_EOF);
- }
- if (widget && widget->putc) {
- eve_kbd_set_handler(kbd, widget->putc, page);
- eve_screen_show_kbd(page->v.window->screen);
- } else {
- eve_kbd_set_handler(kbd, NULL, NULL);
- }
+ EVEScreen *screen = page->v.window->screen;
+ EVEWidget *widget_f = page->widget_f;
+
+ if (widget_f && widget_f->putc) {
+ eve_screen_hide_kbd(screen);
+ widget_f->putc(page, CH_EOF);
+ }
+ if (widget && widget->putc) {
+ EVEKbd *kbd = eve_screen_get_kbd(screen);
+
+ if (kbd) eve_kbd_set_handler(kbd, widget->putc, page);
+ eve_screen_show_kbd(screen);
}
page->widget_f = widget;
}
diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h
index 168a017..ed558ba 100644
--- a/fw/fe310/eos/eve/screen/page.h
+++ b/fw/fe310/eos/eve/screen/page.h
@@ -1,24 +1,20 @@
#include <stdint.h>
-struct EVEPage;
struct EVEWidget;
+struct EVEPage;
-typedef int (*eve_page_evt_handler_t) (struct EVEPage *, struct EVEWidget *, EVETouch *, uint16_t, uint8_t, int);
-typedef void (*eve_page_g_updater_t) (struct EVEPage *, struct EVEWidget *);
typedef void (*eve_page_destructor_t) (struct EVEPage *);
typedef struct EVEPage {
EVEView v;
int16_t win_x;
int16_t win_y;
- eve_page_evt_handler_t handle_evt;
- eve_page_g_updater_t update_g;
eve_page_destructor_t destructor;
- struct EVEViewStack *stack;
+ EVEViewStack *stack;
struct EVEWidget *widget_f;
} EVEPage;
-void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_evt_handler_t handle_evt, eve_page_g_updater_t update_g, eve_page_destructor_t destructor);
+void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, eve_view_touch_t touch, eve_view_draw_t draw, eve_page_destructor_t destructor);
void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor);
void eve_page_close(EVEPage *page);
diff --git a/fw/fe310/eos/eve/screen/screen.c b/fw/fe310/eos/eve/screen/screen.c
index af5a91f..fa4a0aa 100644
--- a/fw/fe310/eos/eve/screen/screen.c
+++ b/fw/fe310/eos/eve/screen/screen.c
@@ -28,13 +28,17 @@ void eve_screen_show_kbd(EVEScreen *screen) {
EVEWindow *win = screen->win_tail;
EVEKbd *kbd = eve_screen_get_kbd(screen);
- if (win) win->g.y = screen->h - kbd->g.h;
+ if (win && kbd) win->g.y = screen->h - kbd->g.h;
}
void eve_screen_hide_kbd(EVEScreen *screen) {
EVEWindow *win = screen->win_tail;
+ EVEKbd *kbd = eve_screen_get_kbd(screen);
- if (win) win->g.y = screen->h;
+ if (win && kbd) {
+ win->g.y = screen->h;
+ eve_kbd_close(kbd);
+ }
}
void eve_screen_draw(EVEScreen *screen) {
@@ -87,6 +91,7 @@ void eve_screen_draw(EVEScreen *screen) {
void eve_screen_handle_touch(void *s, uint8_t tag0, int touch_idx) {
EVEScreen *screen = s;
EVEWindow *win;
+ int h;
eve_touch_clear_opt();
@@ -94,7 +99,8 @@ void eve_screen_handle_touch(void *s, uint8_t tag0, int touch_idx) {
win = screen->win_tail;
while (win) {
if (eve_window_visible(win)) {
- int a = win->view->touch(win->view, tag0, touch_idx);
+ h = win->view->touch(win->view, tag0, touch_idx);
+ if (h) break;
}
win = win->prev;
}
diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile
index 720029e..fa5b41c 100644
--- a/fw/fe310/eos/eve/widget/Makefile
+++ b/fw/fe310/eos/eve/widget/Makefile
@@ -2,7 +2,7 @@ include ../../../common.mk
CFLAGS += -I.. -I../..
-obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o
+obj = clipb.o font.o label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c
index eaf982c..8fcc2f6 100644
--- a/fw/fe310/eos/eve/widget/freew.c
+++ b/fw/fe310/eos/eve/widget/freew.c
@@ -36,35 +36,26 @@ void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_
}
void eve_freew_tag(EVEFreeWidget *widget) {
- if (widget->tagN != EVE_TAG_NOTAG) {
- eve_cmd_dl(TAG(widget->tagN));
- widget->tagN++;
+ EVEWidget *_widget = &widget->w;
+
+ if (_widget->tagN != EVE_TAG_NOTAG) {
+ eve_cmd_dl(TAG(_widget->tagN));
+ _widget->tagN++;
}
}
-int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
- EVETouch *t;
- uint16_t evt;
- int ret = 0;
-
- if (touch_idx > 0) return 0;
-
- t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
- if (t && evt) {
- ret = widget->_touch(widget, page, t, evt, tag0, touch_idx);
- if (!ret && page && page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
- }
- return ret;
+ return widget->_touch(widget, page, t, evt);
}
uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
- widget->tag0 = tag0;
- widget->tagN = tag0;
+ _widget->tag0 = tag0;
+ _widget->tagN = tag0;
widget->_draw(widget, page);
- return widget->tagN;
+ return _widget->tagN;
}
diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h
index 3347e68..c7d8076 100644
--- a/fw/fe310/eos/eve/widget/freew.h
+++ b/fw/fe310/eos/eve/widget/freew.h
@@ -2,15 +2,13 @@
struct EVEFreeWidget;
-typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t, uint8_t, int);
+typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVEPage *, EVETouch *, uint16_t);
typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *, EVEPage *);
typedef struct EVEFreeWidget {
EVEWidget w;
eve_freew_touch_t _touch;
eve_freew_draw_t _draw;
- uint8_t tag0;
- uint8_t tagN;
} EVEFreeWidget;
typedef struct EVEFreeSpec {
@@ -24,5 +22,5 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, eve_freew_touch_t touch,
void eve_freew_update(EVEFreeWidget *widget, eve_freew_touch_t touch, eve_freew_draw_t draw, eve_kbd_input_handler_t putc);
void eve_freew_tag(EVEFreeWidget *widget);
-int eve_freew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+int eve_freew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_freew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c
index 319e207..2142cb9 100644
--- a/fw/fe310/eos/eve/widget/pagew.c
+++ b/fw/fe310/eos/eve/widget/pagew.c
@@ -39,36 +39,28 @@ void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_vie
if (_widget->g.h == 0) _widget->g.h = eve_font_h(font);
}
-int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
- EVETouch *t;
- uint16_t evt;
- int ret = 0;
-
- if (touch_idx > 0) return 0;
-
- t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt);
- if (t && evt) {
- if (evt & EVE_TOUCH_ETYPE_TRACK_MASK) {
- if (page->handle_evt) ret = page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
- } else if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
- eve_page_open(page, widget->constructor);
- ret = 1;
- }
+
+ if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
+ eve_page_open(page, widget->constructor);
+ return 1;
}
- return ret;
+ return 0;
}
uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
EVEPageWidget *widget = (EVEPageWidget *)_widget;
- widget->tag = tag0;
+ _widget->tag0 = tag0;
if (tag0 != EVE_TAG_NOTAG) {
eve_cmd_dl(TAG(tag0));
tag0++;
}
+ _widget->tagN = tag0;
+
eve_cmd(CMD_TEXT, "hhhhs", _widget->g.x, _widget->g.y, widget->font->id, 0, widget->title);
- return tag0;
+ return _widget->tagN;
}
diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h
index 67b1199..6560654 100644
--- a/fw/fe310/eos/eve/widget/pagew.h
+++ b/fw/fe310/eos/eve/widget/pagew.h
@@ -5,7 +5,6 @@ typedef struct EVEPageWidget {
char *title;
EVEFont *font;
eve_view_constructor_t constructor;
- uint8_t tag;
} EVEPageWidget;
typedef struct EVEPageSpec {
@@ -18,5 +17,5 @@ int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPageSpec *spec);
void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEFont *font, char *title, eve_view_constructor_t constructor);
void eve_pagew_update(EVEPageWidget *widget, EVEFont *font, char *title, eve_view_constructor_t constructor);
-int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+int eve_pagew_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_pagew_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c
index 48f7f6d..eeb956f 100644
--- a/fw/fe310/eos/eve/widget/selectw.c
+++ b/fw/fe310/eos/eve/widget/selectw.c
@@ -50,11 +50,11 @@ void eve_selectw_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option,
if (option) {
widget->option = option;
widget->option_size = option_size;
+ widget->select = SELECTW_NOSELECT;
}
- widget->select = SELECTW_NOSELECT;
}
-int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt, uint8_t tag0, int touch_idx) {
+int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
EVESelectWidget *widget = (EVESelectWidget *)_widget;
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
@@ -111,11 +111,7 @@ uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
} while (o_len);
- new_h = i * widget->font->h;
- if (_widget->g.h != new_h) {
- _widget->g.h = new_h;
- if (page && page->update_g) page->update_g(page, _widget);
- }
+ _widget->g.h = i * widget->font->h;
return _widget->tagN;
}
@@ -138,10 +134,8 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) {
return NULL;
}
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size) {
- if (size > widget->option_size) return EVE_ERR_FULL;
- memcpy(widget->option, opt, size);
- memset(widget->option + size, 0, widget->option_size - size);
+utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) {
+ return eve_selectw_option_get(widget, widget->select);
}
int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt) {
@@ -162,6 +156,10 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt) {
return EVE_OK;
}
-utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) {
- return eve_selectw_option_get(widget, widget->select);
+int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size) {
+ if (size > widget->option_size) return EVE_ERR_FULL;
+ memcpy(widget->option, opt, size);
+ memset(widget->option + size, 0, widget->option_size - size);
+
+ return EVE_OK;
}
diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h
index 6e2c203..953ba4a 100644
--- a/fw/fe310/eos/eve/widget/selectw.h
+++ b/fw/fe310/eos/eve/widget/selectw.h
@@ -18,10 +18,10 @@ void eve_selectw_destroy(EVESelectWidget *widget);
void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEFont *font, utf8_t *option, uint16_t option_size);
void eve_selectw_update(EVESelectWidget *widget, EVEFont *font, utf8_t *option, uint16_t option_size);
-int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt, uint8_t tag0, int touch_idx);
+int eve_selectw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_selectw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx);
-int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size);
-int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt);
utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget);
+int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *opt);
+int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *opt, uint16_t size);
diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c
index e53c9c1..3a0216f 100644
--- a/fw/fe310/eos/eve/widget/spacerw.c
+++ b/fw/fe310/eos/eve/widget/spacerw.c
@@ -28,10 +28,12 @@ void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g) {
eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, eve_spacerw_touch, eve_spacerw_draw, NULL);
}
-int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
return 0;
}
uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
- return tag0;
+ _widget->tag0 = tag0;
+ _widget->tagN = tag0;
+ return _widget->tagN;
}
diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h
index cbde4e8..073f134 100644
--- a/fw/fe310/eos/eve/widget/spacerw.h
+++ b/fw/fe310/eos/eve/widget/spacerw.h
@@ -10,5 +10,5 @@ typedef struct EVESpacerSpec {
int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVESpacerSpec *spec);
void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g);
-int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+int eve_spacerw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_spacerw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c
index 0e1c97f..fe71b89 100644
--- a/fw/fe310/eos/eve/widget/strw.c
+++ b/fw/fe310/eos/eve/widget/strw.c
@@ -24,9 +24,9 @@
#define CH_CTRLC 0x03
#define CH_CTRLV 0x16
-#define STRW_TMODE_CURSOR 1
-#define STRW_TMODE_SCROLL_X 2
-#define STRW_TMODE_SCROLL_Y 3
+#define STRW_TRACK_NONE 0
+#define STRW_TRACK_CRSR 1
+#define STRW_TRACK_TXT 2
#define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f))
@@ -97,93 +97,76 @@ static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVE
return NULL;
}
-int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
EVEStrWidget *widget = (EVEStrWidget *)_widget;
- EVETouch *t;
- uint16_t evt;
+ EVEStrCursor *t_cursor = NULL;
+ short dx;
+ int ret = 0;
- if (touch_idx > 0) return 0;
-
- t = eve_touch_evt(tag0, touch_idx, widget->tag, 1, &evt);
- if (t && evt) {
- EVEStrCursor *t_cursor = NULL;
- short dx;
-
- if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
- if (widget->cursor2.on) {
- t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx);
- }
- if ((t_cursor == NULL) && widget->cursor1.on) {
- t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx);
- }
- if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
+ if (widget->cursor2.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx);
+ }
+ if ((t_cursor == NULL) && widget->cursor1.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx);
+ }
+ if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
+ if (t_cursor) {
+ widget->track.mode = STRW_TRACK_CRSR;
widget->track.cursor = t_cursor;
- if (t_cursor) {
- widget->track.mode = STRW_TMODE_CURSOR;
- widget->track.dx = dx;
- } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_X) {
- widget->track.mode = STRW_TMODE_SCROLL_X;
- } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_Y) {
- widget->track.mode = STRW_TMODE_SCROLL_Y;
- }
+ widget->track.dx = dx;
+ } else if (t->eevt & EVE_TOUCH_EETYPE_TRACK_X) {
+ widget->track.mode = STRW_TRACK_TXT;
}
}
+ }
- switch (widget->track.mode) {
- case STRW_TMODE_SCROLL_Y:
- if (page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
- break;
+ if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.mode) {
+ int x, w1;
- case STRW_TMODE_SCROLL_X:
+ switch (widget->track.mode) {
+ case STRW_TRACK_TXT:
if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
widget->str_g.x0 = widget->str_g.x;
}
- if (evt & EVE_TOUCH_ETYPE_TRACK) {
- int x = widget->str_g.x0 + t->x0 - t->x;
- int w1 = widget->w.g.w - widget->font->w;
-
- if (x > widget->str_g.w - w1) x = widget->str_g.w - w1;
- if (x < 0) x = 0;
- widget->str_g.x = x;
- }
- break;
-
- case STRW_TMODE_CURSOR:
- if (evt & EVE_TOUCH_ETYPE_TRACK) eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, t->x) + widget->track.dx);
+ x = widget->str_g.x0 + t->x0 - t->x;
+ w1 = widget->w.g.w - widget->font->w;
+ if (x > widget->str_g.w - w1) x = widget->str_g.w - w1;
+ if (x < 0) x = 0;
+ widget->str_g.x = x;
break;
- default:
- if (evt & EVE_TOUCH_ETYPE_LPRESS) {
- if (widget->cursor2.on) {
- // copy
- } else if (widget->cursor1.on) {
- if (t_cursor) {
- // paste
- } else {
- eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, t->x));
- }
- } else {
- // select
- }
- }
- if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
- eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, t->x0));
- if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2);
- set_focus(widget, page);
- }
+ case STRW_TRACK_CRSR:
+ eve_strw_cursor_set(widget, widget->track.cursor, eve_page_x(page, t->x) + widget->track.dx);
break;
}
-
- if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- widget->track.mode = 0;
- widget->track.cursor = NULL;
- widget->track.dx = 0;
+ ret = 1;
+ } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
+ if (widget->cursor2.on) {
+ // copy
+ } else if (widget->cursor1.on) {
+ if (t_cursor) {
+ // paste
+ } else {
+ eve_strw_cursor_set(widget, &widget->cursor2, eve_page_x(page, t->x));
+ }
+ } else {
+ // select
}
+ ret = 1;
+ } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
+ eve_strw_cursor_set(widget, &widget->cursor1, eve_page_x(page, t->x0));
+ if (widget->cursor2.on) eve_strw_cursor_clear(widget, &widget->cursor2);
+ set_focus(widget, page);
+ }
- return 1;
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ widget->track.mode = STRW_TRACK_NONE;
+ widget->track.cursor = NULL;
+ widget->track.dx = 0;
}
- return 0;
+ return ret;
}
static void _draw_str(EVEStrWidget *widget, EVEWindow *window, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
@@ -227,12 +210,13 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
EVEStrWidget *widget = (EVEStrWidget *)_widget;
char cut = widget->str_g.x || (widget->str_g.w > _widget->g.w);
- widget->tag = tag0;
+ _widget->tag0 = tag0;
if (tag0 != EVE_TAG_NOTAG) {
eve_cmd_dl(TAG(tag0));
eve_touch_set_opt(tag0, EVE_TOUCH_OPT_LPRESS);
tag0++;
}
+ _widget->tagN = tag0;
if (cut) {
EVEWindow *window = page->v.window;
@@ -293,7 +277,7 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
eve_cmd_dl(RESTORE_CONTEXT());
}
- return tag0;
+ return _widget->tagN;
}
void eve_strw_putc(void *_page, int c) {
diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h
index 9456603..dcb34c1 100644
--- a/fw/fe310/eos/eve/widget/strw.h
+++ b/fw/fe310/eos/eve/widget/strw.h
@@ -19,7 +19,6 @@ typedef struct EVEStrWidget {
} str_g;
EVEStrCursor cursor1;
EVEStrCursor cursor2;
- uint8_t tag;
struct {
EVEStrCursor *cursor;
short dx;
@@ -37,7 +36,7 @@ void eve_strw_destroy(EVEStrWidget *widget);
void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEFont *font, utf8_t *str, uint16_t str_size);
void eve_strw_update(EVEStrWidget *widget, EVEFont *font, utf8_t *str, uint16_t str_size);
-int eve_strw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+int eve_strw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
void eve_strw_putc(void *_page, int c);
void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x);
diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c
index c81031a..62cbeff 100644
--- a/fw/fe310/eos/eve/widget/textw.c
+++ b/fw/fe310/eos/eve/widget/textw.c
@@ -24,9 +24,6 @@
#define CH_CTRLC 0x03
#define CH_CTRLV 0x16
-#define TEXTW_TMODE_CURSOR 1
-#define TEXTW_TMODE_SCROLL 2
-
#define LINE_LEN(w,l) ((l) ? (w->line[l] ? w->line[l] - w->line[(l) - 1] - 1 : 0) : w->line[l])
#define LINE_START(w,l) ((l) ? w->line[(l) - 1] + 1 : 0)
#define LINE_END(w,l) (w->line[l])
@@ -88,7 +85,7 @@ void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16
widget->line_size = line_size;
}
memset(widget->line, 0xff, line_size * sizeof(uint16_t));
- eve_textw_text_update(widget, NULL, 0);
+ eve_textw_text_update(widget, 0);
}
static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page) {
@@ -105,7 +102,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *pag
static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVEPage *page, EVETouch *t, short *dx, short *dl) {
EVEWidget *_widget = &widget->w;
int x = eve_page_x(page, t->x0) - _widget->g.x;
- int l = (int)t->tag0 - widget->tag0 + widget->line0;
+ int l = (int)t->tag0 - _widget->tag0 + widget->line0;
int _dx, _dl;
*dx = cursor->x - x;
@@ -118,81 +115,55 @@ static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor,
return NULL;
}
-int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx) {
+int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt) {
EVETextWidget *widget = (EVETextWidget *)_widget;
- EVETouch *t;
- uint16_t evt;
-
- if (touch_idx > 0) return 0;
+ EVETextCursor *t_cursor = NULL;
+ short dx, dl;
+ int ret = 0;
- t = eve_touch_evt(tag0, touch_idx, widget->tag0, widget->tagN - widget->tag0, &evt);
- if (t && evt) {
- EVETextCursor *t_cursor = NULL;
- short dx, dl;
-
- if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
- if (widget->cursor2.on) {
- t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl);
- }
- if ((t_cursor == NULL) && widget->cursor1.on) {
- t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx, &dl);
- }
- if (evt & EVE_TOUCH_ETYPE_TRACK_START) {
- widget->track.cursor = t_cursor;
- if (t_cursor) {
- widget->track.mode = TEXTW_TMODE_CURSOR;
- widget->track.dx = dx;
- widget->track.dl = dl;
- } else {
- widget->track.mode = TEXTW_TMODE_SCROLL;
- }
- }
+ if (evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TRACK_START)) {
+ if (widget->cursor2.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor2, page, t, &dx, &dl);
}
-
- switch (widget->track.mode) {
- case TEXTW_TMODE_SCROLL:
- if (page->handle_evt) page->handle_evt(page, _widget, t, evt, tag0, touch_idx);
- break;
-
- case TEXTW_TMODE_CURSOR:
- if (evt & EVE_TOUCH_ETYPE_TRACK) {
- eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
- }
- break;
-
- default:
- if (evt & EVE_TOUCH_ETYPE_LPRESS) {
- if (widget->cursor2.on) {
- // copy
- } else if (widget->cursor1.on) {
- if (t_cursor && (dl == 0)) {
- // paste
- } else {
- eve_textw_cursor_set(widget, &widget->cursor2, t->tag, eve_page_x(page, t->x));
- }
- } else {
- // select
- }
- }
- if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
- eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, eve_page_x(page, t->x0));
- if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2);
- set_focus(widget, &widget->cursor1, page);
- }
- break;
+ if ((t_cursor == NULL) && widget->cursor1.on) {
+ t_cursor = cursor_prox(widget, &widget->cursor1, page, t, &dx, &dl);
}
+ if (t_cursor && (evt & EVE_TOUCH_ETYPE_TRACK_START)) {
+ widget->track.cursor = t_cursor;
+ widget->track.dx = dx;
+ widget->track.dl = dl;
+ }
+ }
- if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
- widget->track.mode = 0;
- widget->track.cursor = NULL;
- widget->track.dx = 0;
- widget->track.dl = 0;
+ if ((evt & EVE_TOUCH_ETYPE_TRACK) && widget->track.cursor) {
+ eve_textw_cursor_set(widget, widget->track.cursor, t->tag + widget->track.dl, eve_page_x(page, t->x) + widget->track.dx);
+ ret = 1;
+ } else if (evt & EVE_TOUCH_ETYPE_LPRESS) {
+ if (widget->cursor2.on) {
+ // copy
+ } else if (widget->cursor1.on) {
+ if (t_cursor && (dl == 0)) {
+ // paste
+ } else {
+ eve_textw_cursor_set(widget, &widget->cursor2, t->tag, eve_page_x(page, t->x));
+ }
+ } else {
+ // select
}
+ ret = 1;
+ } else if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(t->eevt & EVE_TOUCH_EETYPE_LPRESS)) {
+ eve_textw_cursor_set(widget, &widget->cursor1, t->tag_up, eve_page_x(page, t->x0));
+ if (widget->cursor2.on) eve_textw_cursor_clear(widget, &widget->cursor2);
+ set_focus(widget, &widget->cursor1, page);
+ }
- return 1;
+ if (evt & EVE_TOUCH_ETYPE_TRACK_STOP) {
+ widget->track.cursor = NULL;
+ widget->track.dx = 0;
+ widget->track.dl = 0;
}
- return 0;
+ return ret;
}
static void _draw_line(EVETextWidget *widget, EVEWindow *window, uint16_t l, uint16_t ch, uint16_t len, uint16_t x1, uint16_t x2, char s) {
@@ -250,8 +221,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
EVETextCursor *c1, *c2;
widget->line0 = line0;
- widget->tag0 = tag0;
- widget->tagN = tag0;
+ _widget->tag0 = tag0;
+ _widget->tagN = tag0;
if (widget->cursor2.on) {
if (widget->cursor1.ch <= widget->cursor2.ch) {
@@ -267,10 +238,10 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
for (i=line0; i<lineN; i++) {
- if (widget->tagN != EVE_TAG_NOTAG) {
- eve_cmd_dl(TAG(widget->tagN));
- eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_LPRESS);
- widget->tagN++;
+ if (_widget->tagN != EVE_TAG_NOTAG) {
+ eve_cmd_dl(TAG(_widget->tagN));
+ eve_touch_set_opt(_widget->tagN, EVE_TOUCH_OPT_LPRESS);
+ _widget->tagN++;
}
if (!s && c1 && (c1->line == i)) {
int l1, l2, l3;
@@ -306,22 +277,22 @@ uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) {
}
}
if (lineNvisible) {
- if (widget->tagN != EVE_TAG_NOTAG) {
- eve_cmd_dl(TAG(widget->tagN));
- eve_touch_set_opt(widget->tagN, EVE_TOUCH_OPT_LPRESS);
- widget->tagN++;
+ if (_widget->tagN != EVE_TAG_NOTAG) {
+ eve_cmd_dl(TAG(_widget->tagN));
+ eve_touch_set_opt(_widget->tagN, EVE_TOUCH_OPT_LPRESS);
+ _widget->tagN++;
}
_draw_line(widget, page->v.window, lineN, 0, 0, 0, _widget->g.w, 0);
}
-
- return widget->tagN;
} else {
widget->line0 = 0;
- widget->tag0 = EVE_TAG_NOTAG;
- widget->tagN = EVE_TAG_NOTAG;
-
- return tag0;
+ _widget->tag0 = EVE_TAG_NOTAG;
+ _widget->tagN = EVE_TAG_NOTAG;
}
+
+ _widget->g.h = (widget->line_len + 1) * widget->font->h;
+
+ return _widget->tagN;
}
void eve_textw_putc(void *_page, int c) {
@@ -428,8 +399,8 @@ void eve_textw_putc(void *_page, int c) {
}
r = cursor1->line;
- if (cursor1->line) r = eve_textw_text_update(widget, page, cursor1->line - 1);
- if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, page, cursor1->line);
+ if (cursor1->line) r = eve_textw_text_update(widget, cursor1->line - 1);
+ if ((cursor1->line == 0) || (r == cursor1->line - 1)) r = eve_textw_text_update(widget, cursor1->line);
if (cursor1->line && (cursor1->ch < LINE_START(widget, cursor1->line))) {
cursor1->line--;
@@ -444,7 +415,7 @@ void eve_textw_putc(void *_page, int c) {
}
}
-uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
+uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line) {
int i;
utf32_t ch;
uint8_t ch_w;
@@ -501,16 +472,10 @@ uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t li
}
widget->line_len = line;
- new_h = (line + 1) * widget->font->h;
for (i=line; i<widget->line_size; i++) {
widget->line[i] = LINE_EMPTY;
}
- if (_widget->g.h != new_h) {
- _widget->g.h = new_h;
- if (page && page->update_g) page->update_g(page, _widget);
- }
-
return line;
}
@@ -537,7 +502,7 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t
uint8_t ch_l;
EVEWidget *_widget = &widget->w;
- if ((tag >= widget->tag0) && ((widget->tagN == EVE_TAG_NOTAG) || (tag < widget->tagN))) c_line = tag - widget->tag0 + widget->line0;
+ if ((tag >= _widget->tag0) && ((_widget->tagN == EVE_TAG_NOTAG) || (tag < _widget->tagN))) c_line = tag - _widget->tag0 + widget->line0;
if (c_line < widget->line_len) {
cursor->line = c_line;
} else if (c_line == widget->line_len) {
diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h
index 36ab466..95f0091 100644
--- a/fw/fe310/eos/eve/widget/textw.h
+++ b/fw/fe310/eos/eve/widget/textw.h
@@ -19,13 +19,10 @@ typedef struct EVETextWidget {
EVETextCursor cursor1;
EVETextCursor cursor2;
uint16_t line0;
- uint8_t tag0;
- uint8_t tagN;
struct {
EVETextCursor *cursor;
short dx;
short dl;
- char mode;
} track;
} EVETextWidget;
@@ -40,10 +37,10 @@ void eve_textw_destroy(EVETextWidget *widget);
void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
void eve_textw_update(EVETextWidget *widget, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size);
-int eve_textw_touch(EVEWidget *_widget, EVEPage *page, uint8_t tag0, int touch_idx);
+int eve_textw_touch(EVEWidget *_widget, EVEPage *page, EVETouch *t, uint16_t evt);
uint8_t eve_textw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0);
void eve_textw_putc(void *_w, int c);
-uint16_t eve_textw_text_update(EVETextWidget *widget, EVEPage *page, uint16_t line);
+uint16_t eve_textw_text_update(EVETextWidget *widget, uint16_t line);
void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor);
void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t tag, int16_t x);
void eve_textw_cursor_clear(EVETextWidget *widget, EVETextCursor *cursor);
diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c
index 1d610bf..a223169 100644
--- a/fw/fe310/eos/eve/widget/widget.c
+++ b/fw/fe310/eos/eve/widget/widget.c
@@ -19,6 +19,7 @@ static const size_t _widget_size[] = {
sizeof(EVEPageWidget),
sizeof(EVEStrWidget),
sizeof(EVETextWidget),
+ sizeof(EVESelectWidget),
};
static const eve_widget_create_t _widget_create[] = {
@@ -28,6 +29,7 @@ static const eve_widget_create_t _widget_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[] = {
@@ -37,6 +39,7 @@ static const eve_widget_destroy_t _widget_destroy[] = {
NULL,
(eve_widget_destroy_t)eve_strw_destroy,
(eve_widget_destroy_t)eve_textw_destroy,
+ (eve_widget_destroy_t)eve_selectw_destroy,
};
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc) {
diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h
index cff5c1d..3e04f3e 100644
--- a/fw/fe310/eos/eve/widget/widget.h
+++ b/fw/fe310/eos/eve/widget/widget.h
@@ -5,10 +5,11 @@
#define EVE_WIDGET_TYPE_PAGE 3
#define EVE_WIDGET_TYPE_STR 4
#define EVE_WIDGET_TYPE_TEXT 5
+#define EVE_WIDGET_TYPE_SELECT 6
struct EVEWidget;
-typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, uint8_t, int);
+typedef int (*eve_widget_touch_t) (struct EVEWidget *, EVEPage *, EVETouch *, uint16_t);
typedef uint8_t (*eve_widget_draw_t) (struct EVEWidget *, EVEPage *, uint8_t);
typedef struct EVEWidget {
@@ -18,6 +19,8 @@ typedef struct EVEWidget {
eve_kbd_input_handler_t putc;
EVELabel *label;
uint8_t type;
+ uint8_t tag0;
+ uint8_t tagN;
} EVEWidget;
void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, eve_widget_touch_t touch, eve_widget_draw_t draw, eve_kbd_input_handler_t putc);
diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h
index 4206894..542b350 100644
--- a/fw/fe310/eos/eve/widget/widgets.h
+++ b/fw/fe310/eos/eve/widget/widgets.h
@@ -7,6 +7,7 @@
#include "pagew.h"
#include "strw.h"
#include "textw.h"
+#include "selectw.h"
typedef union EVEWidgetSpec {
EVEFreeSpec free;
@@ -14,6 +15,7 @@ typedef union EVEWidgetSpec {
EVEPageSpec page;
EVEStrSpec str;
EVETextSpec text;
+ EVESelectSpec select;
} EVEWidgetSpec;
typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *g, EVEWidgetSpec *);
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c
index 297e8f0..46700e8 100644
--- a/fw/fe310/eos/net.c
+++ b/fw/fe310/eos/net.c
@@ -456,10 +456,16 @@ void eos_net_release(void) {
unsigned char *eos_net_alloc(void) {
unsigned char *ret = NULL;
- clear_csr(mstatus, MSTATUS_MIE);
- ret = net_state_next_buf;
- net_state_next_buf = NULL;
- set_csr(mstatus, MSTATUS_MIE);
+ while (!ret) {
+ clear_csr(mstatus, MSTATUS_MIE);
+ if (net_state_next_buf) {
+ ret = net_state_next_buf;
+ net_state_next_buf = NULL;
+ } else {
+ asm volatile ("wfi");
+ }
+ set_csr(mstatus, MSTATUS_MIE);
+ }
return ret;
}
diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c
index 2b13c9f..8717553 100644
--- a/fw/fe310/eos/power.c
+++ b/fw/fe310/eos/power.c
@@ -18,7 +18,7 @@
static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE];
static unsigned char power_btn_down;
-static void power_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+static void power_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char mtype;
if ((buffer == NULL) || (len < 1)) {
@@ -53,7 +53,7 @@ void eos_power_init(void) {
for (i=0; i<EOS_PWR_MAX_MTYPE; i++) {
evt_handler[i] = NULL;
}
- eos_net_set_handler(EOS_NET_MTYPE_POWER, power_handle_evt);
+ eos_net_set_handler(EOS_NET_MTYPE_POWER, power_handle_msg);
eos_power_set_handler(EOS_PWR_MTYPE_BUTTON, power_handle_btn);
AON_REG(AON_PMUKEY) = 0x51F15E;
@@ -110,3 +110,8 @@ void eos_power_wake_disable(void) {
void eos_power_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_power_get_handler(unsigned char mtype) {
+ if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype];
+ return NULL;
+}
diff --git a/fw/fe310/eos/power.h b/fw/fe310/eos/power.h
index 466573f..3eee817 100644
--- a/fw/fe310/eos/power.h
+++ b/fw/fe310/eos/power.h
@@ -1,7 +1,7 @@
#include <stdint.h>
#include "event.h"
-#define EOS_PWR_MTYPE_BUTTON 0
+#define EOS_PWR_MTYPE_BUTTON 1
#define EOS_PWR_MAX_MTYPE 2
@@ -19,4 +19,5 @@ uint8_t eos_power_reset_cause(void);
void eos_power_sleep(void);
void eos_power_wake_at(uint32_t msec);
void eos_power_wake_disable(void);
-void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler); \ No newline at end of file
+void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler);
+eos_evt_handler_t eos_power_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/sock.c
index 9abb9e8..a2e30e3 100644
--- a/fw/fe310/eos/sock.c
+++ b/fw/fe310/eos/sock.c
@@ -10,7 +10,7 @@
static eos_evt_handler_t evt_handler[EOS_SOCK_MAX_SOCK];
-static void sock_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char sock;
if ((buffer == NULL) || (len < 2)) {
@@ -40,13 +40,18 @@ void eos_sock_init(void) {
for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
evt_handler[i] = NULL;
}
- eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handle_evt);
+ eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handle_msg);
}
void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler) {
if (sock && (sock <= EOS_SOCK_MAX_SOCK)) evt_handler[sock - 1] = handler;
}
+eos_evt_handler_t eos_sock_get_handler(unsigned char sock) {
+ if (sock && (sock <= EOS_SOCK_MAX_SOCK)) return evt_handler[sock - 1];
+ return NULL;
+}
+
int eos_sock_open_udp(eos_evt_handler_t handler) {
unsigned char type = EOS_SOCK_MTYPE_OPEN_DGRAM;
unsigned char *buffer = eos_net_alloc();
diff --git a/fw/fe310/eos/sock.h b/fw/fe310/eos/sock.h
index cec8aae..7461473 100644
--- a/fw/fe310/eos/sock.h
+++ b/fw/fe310/eos/sock.h
@@ -18,6 +18,7 @@ typedef struct EOSNetAddr {
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);
int eos_sock_open_udp(eos_evt_handler_t handler);
void eos_sock_close(unsigned char sock);
diff --git a/fw/fe310/eos/wifi.c b/fw/fe310/eos/wifi.c
index 6d39332..c3449e8 100644
--- a/fw/fe310/eos/wifi.c
+++ b/fw/fe310/eos/wifi.c
@@ -10,7 +10,7 @@
static eos_evt_handler_t evt_handler[EOS_WIFI_MAX_MTYPE];
-static void wifi_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char mtype;
if ((buffer == NULL) || (len < 1)) {
@@ -32,13 +32,24 @@ void eos_wifi_init(void) {
for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
evt_handler[i] = NULL;
}
- eos_net_set_handler(EOS_NET_MTYPE_WIFI, wifi_handle_evt);
+ 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;
+}
+
+void eos_wifi_scan(void) {
+ unsigned char *buffer = eos_net_alloc();
+ buffer[0] = EOS_WIFI_MTYPE_SCAN;
+ eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
+}
+
void eos_wifi_connect(const char *ssid, const char *pass) {
int ssid_len = strlen(ssid);
int pass_len = strlen(pass);
diff --git a/fw/fe310/eos/wifi.h b/fw/fe310/eos/wifi.h
index 732a7a9..57048af 100644
--- a/fw/fe310/eos/wifi.h
+++ b/fw/fe310/eos/wifi.h
@@ -1,14 +1,16 @@
#include <stdint.h>
#include "event.h"
-#define EOS_WIFI_MTYPE_SCAN 0
-#define EOS_WIFI_MTYPE_CONNECT 1
-#define EOS_WIFI_MTYPE_DISCONNECT 2
+#define EOS_WIFI_MTYPE_SCAN 1
+#define EOS_WIFI_MTYPE_CONNECT 2
+#define EOS_WIFI_MTYPE_DISCONNECT 3
-#define EOS_WIFI_MAX_MTYPE 3
+#define EOS_WIFI_MAX_MTYPE 4
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);
+void eos_wifi_scan(void);
void eos_wifi_connect(const char *ssid, const char *pass);
void eos_wifi_disconnect(void);
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
index 24efa2f..53e6f2d 100644
--- a/fw/fe310/test/Makefile
+++ b/fw/fe310/test/Makefile
@@ -3,18 +3,20 @@ include ../common.mk
CFLAGS += -I../eos -I../bsp/include -I../bsp/drivers
LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds
-TARGET = modem
+DEPS = main.o status.o phone.o wifi.o cell_data.o modem.o
+TARGET = phone
all: $(TARGET)
%.o: %.c
$(CC) $(CFLAGS) -c $<
-$(TARGET): $(TARGET).o
- $(CC) $< $(LDFLAGS) -o $@
+$(TARGET): $(DEPS)
+ $(CC) $(DEPS) $(LDFLAGS) -o $@
clean:
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/cell_data.c b/fw/fe310/test/cell_data.c
new file mode 100644
index 0000000..007fa0b
--- /dev/null
+++ b/fw/fe310/test/cell_data.c
@@ -0,0 +1,115 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <event.h>
+#include <spi.h>
+#include <uart.h>
+#include <net.h>
+#include <cell.h>
+
+#include <unicode.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+
+#include <eve/screen/screen.h>
+#include <eve/screen/window.h>
+#include <eve/screen/view.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/root.h>
+
+#include "status.h"
+#include "cell_data.h"
+
+extern EVEFont *_app_font_default;
+
+static void cell_data_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ switch (type) {
+ case EOS_CELL_MTYPE_DATA_CONNECT:
+ app_status_msg_set("Cell data connected", 1);
+ break;
+
+ case EOS_CELL_MTYPE_DATA_DISCONNECT:
+ app_status_msg_set("Cell data disconnected", 1);
+ break;
+
+ default:
+ break;
+ }
+ eos_net_free(buffer, 0);
+}
+
+void app_cell_data(EVEWindow *window, EVEViewStack *stack) {
+ APPWidgetSpec spec[] = {
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.font = _app_font_default,
+ .label.title = "APN:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.g.w = APP_SCREEN_W - APP_SCREEN_W / 3,
+ .widget.spec.str.font = _app_font_default,
+ .widget.spec.str.str_size = 128,
+ },
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.font = _app_font_default,
+ .label.title = "User:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.g.w = APP_SCREEN_W - APP_SCREEN_W / 3,
+ .widget.spec.str.font = _app_font_default,
+ .widget.spec.str.str_size = 128,
+ },
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.font = _app_font_default,
+ .label.title = "Pass:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.g.w = APP_SCREEN_W - APP_SCREEN_W / 3,
+ .widget.spec.str.font = _app_font_default,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = app_form_create(window, stack, spec, 3, app_cell_data_action, app_cell_data_close);
+}
+
+void app_cell_data_action(EVEForm *form) {
+ unsigned char *buf = eos_net_alloc();
+ unsigned char *p;
+ EVEStrWidget *apn = (EVEStrWidget *)eve_form_widget(form, 0);
+ EVEStrWidget *user = (EVEStrWidget *)eve_form_widget(form, 1);
+ EVEStrWidget *pass = (EVEStrWidget *)eve_form_widget(form, 2);
+
+ buf[0] = EOS_CELL_MTYPE_DATA | EOS_CELL_MTYPE_DATA_CONFIGURE;
+ p = buf + 1;
+ strcpy(p, apn->str);
+ p += strlen(apn->str) + 1;
+ strcpy(p, user->str);
+ p += strlen(user->str) + 1;
+ strcpy(p, pass->str);
+ p += strlen(pass->str) + 1;
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, p - buf, 1);
+
+ eos_net_acquire();
+ buf = eos_net_alloc();
+ buf[0] = EOS_CELL_MTYPE_DATA | EOS_CELL_MTYPE_DATA_CONNECT;
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+}
+
+void app_cell_data_close(EVEForm *form) {
+ app_form_destroy(form);
+}
+
+void app_cell_data_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_DATA, cell_data_handler);
+}
diff --git a/fw/fe310/test/cell_data.h b/fw/fe310/test/cell_data.h
new file mode 100644
index 0000000..69ae2ef
--- /dev/null
+++ b/fw/fe310/test/cell_data.h
@@ -0,0 +1,4 @@
+void app_cell_data(EVEWindow *window, EVEViewStack *stack);
+void app_cell_data_action(EVEForm *form);
+void app_cell_data_close(EVEForm *form);
+void app_cell_data_init(void); \ No newline at end of file
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
new file mode 100644
index 0000000..095746d
--- /dev/null
+++ b/fw/fe310/test/main.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <event.h>
+#include <spi.h>
+#include <i2s.h>
+#include <net.h>
+#include <cell.h>
+
+#include <unicode.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+
+#include <eve/screen/screen.h>
+#include <eve/screen/window.h>
+#include <eve/screen/view.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/root.h>
+
+#include "status.h"
+#include "phone.h"
+#include "wifi.h"
+#include "cell_data.h"
+#include "modem.h"
+
+extern EVEFont *_app_font_default;
+
+void app_home_page(EVEWindow *window, EVEViewStack *stack) {
+ APPWidgetSpec spec[] = {
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.font = _app_font_default,
+ .widget.spec.page.title = "Phone",
+ .widget.spec.page.constructor = app_phone
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.font = _app_font_default,
+ .widget.spec.page.title = "WiFi",
+ .widget.spec.page.constructor = app_wifi
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.font = _app_font_default,
+ .widget.spec.page.title = "Cellular data",
+ .widget.spec.page.constructor = app_cell_data
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.font = _app_font_default,
+ .widget.spec.page.title = "Modem",
+ .widget.spec.page.constructor = app_modem
+ },
+ };
+
+ EVEForm *form = app_form_create(window, stack, spec, 4, NULL, NULL);
+}
+
+int main() {
+ printf("\nREADY.\n");
+
+ eos_init();
+
+ app_root_init(app_home_page);
+ app_status_init();
+ app_phone_init();
+ app_wifi_init();
+ app_cell_data_init();
+
+ eos_evtq_loop();
+}
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
index 5fa17cc..6453b24 100644
--- a/fw/fe310/test/modem.c
+++ b/fw/fe310/test/modem.c
@@ -26,18 +26,27 @@
#include <app/root.h>
+#include "modem.h"
+
typedef struct {
uint32_t mem;
EVEViewStack *stack;
+ eos_evt_handler_t cell_dev_handler;
EVEText text;
} VParam;
static void key_down(void *p, int c) {
- EVEText *text = p;
- unsigned char *buf = eos_net_alloc();
+ EVEView *view = p;
+ EVEText *text = &((VParam *)view->param)->text;
+ unsigned char *buf;
int i = 2;
- buf[0] = EOS_CELL_MTYPE_UART_DATA;
+ if (c == 0x11) {
+ app_modem_close(view);
+ return;
+ }
+ buf = eos_net_alloc();
+ buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_UART_DATA;
if (c == '\n') {
buf[1] = '\r';
buf[2] = '\n';
@@ -59,7 +68,7 @@ static void handle_uart(unsigned char type) {
if (c == EOS_ERR_EMPTY) return;
buf = eos_net_alloc();
- buf[0] = EOS_CELL_MTYPE_UART_DATA;
+ buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_UART_DATA;
buf[1] = c;
i = 2;
while ((c = eos_uart_getc(0)) != EOS_ERR_EMPTY) {
@@ -72,10 +81,11 @@ static void handle_uart(unsigned char type) {
}
static void handle_cell_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
+ EVEScreen *screen = app_screen();
+ EVEWindow *window = eve_window_get(screen, "main");
+ VParam *param = window->view->param;
+
if (type == EOS_CELL_MTYPE_UART_DATA) {
- EVEScreen *screen = app_screen();
- EVEWindow *window = eve_window_get(screen, "main");
- VParam *param = window->view->param;
EVEText *text = &param->text;
int i;
@@ -88,9 +98,10 @@ static void handle_cell_msg(unsigned char type, unsigned char *buffer, uint16_t
eve_screen_draw(window->screen);
}
eos_spi_dev_stop();
-
+ eos_net_free(buffer, 0);
+ } else {
+ param->cell_dev_handler(type, buffer, len);
}
- eos_net_free(buffer, 0);
}
static int modem_touch(EVEView *view, uint8_t tag0, int touch_idx) {
@@ -107,7 +118,7 @@ static uint8_t modem_draw(EVEView *view, uint8_t tag) {
return eve_text_draw(text, tag);
}
-void app_modem_create(EVEWindow *window, EVEViewStack *stack) {
+void app_modem(EVEWindow *window, EVEViewStack *stack) {
unsigned char *buf;
EVEScreen *screen = window->screen;
EVEKbd *kbd = eve_screen_get_kbd(screen);
@@ -119,10 +130,11 @@ void app_modem_create(EVEWindow *window, EVEViewStack *stack) {
param = eve_malloc(sizeof(VParam));
param->mem = screen->mem_next;
param->stack = stack;
+ param->cell_dev_handler = eos_cell_get_handler(EOS_CELL_MTYPE_DEV);
eve_text_init(&param->text, &g, 30, 16, 200, screen->mem_next, &screen->mem_next);
eve_view_init(view, window, modem_touch, modem_draw, param);
- eve_kbd_set_handler(kbd, key_down, &param->text);
+ eve_kbd_set_handler(kbd, key_down, view);
eve_screen_show_kbd(screen);
eos_uart_set_handler(EOS_UART_ETYPE_RX, handle_uart);
@@ -130,37 +142,29 @@ void app_modem_create(EVEWindow *window, EVEViewStack *stack) {
eos_net_acquire_for_evt(EOS_EVT_UART | EOS_UART_ETYPE_RX, 1);
buf = eos_net_alloc();
- buf[0] = EOS_CELL_MTYPE_UART_TAKE;
+ buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_UART_TAKE;
eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
eos_uart_rxwm_set(0);
}
-void app_modem_destroy(EVEView *view) {
+void app_modem_close(EVEView *view) {
unsigned char *buf = eos_net_alloc();
VParam *param = view->param;
EVEWindow *window = view->window;
EVEScreen *screen = window->screen;
- EVEKbd *kbd = eve_screen_get_kbd(screen);
EVEViewStack *stack = param->stack;
- buf[0] = EOS_CELL_MTYPE_UART_GIVE;
+ buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_RESET;
eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
eos_uart_rxwm_clear();
eos_uart_set_handler(EOS_UART_ETYPE_RX, NULL);
- eos_cell_set_handler(EOS_CELL_MTYPE_DEV, NULL);
+ eos_cell_set_handler(EOS_CELL_MTYPE_DEV, param->cell_dev_handler);
eos_net_acquire_for_evt(EOS_EVT_UART | EOS_UART_ETYPE_RX, 0);
- eve_screen_hide_kbd(screen);
- eve_kbd_set_handler(kbd, NULL, NULL);
-
screen->mem_next = param->mem;
eve_free(param);
eve_free(view);
- eve_view_destroy(window, stack);
-}
-int main() {
- eos_init();
- app_root_init(app_modem_create);
- eos_evtq_loop();
+ eve_screen_hide_kbd(screen);
+ eve_view_destroy(window, stack);
}
diff --git a/fw/fe310/test/modem.h b/fw/fe310/test/modem.h
new file mode 100644
index 0000000..3a6bc35
--- /dev/null
+++ b/fw/fe310/test/modem.h
@@ -0,0 +1,2 @@
+void app_modem(EVEWindow *window, EVEViewStack *stack);
+void app_modem_close(EVEView *view);
diff --git a/fw/fe310/test/phone.c b/fw/fe310/test/phone.c
new file mode 100644
index 0000000..6f88698
--- /dev/null
+++ b/fw/fe310/test/phone.c
@@ -0,0 +1,142 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <event.h>
+#include <spi.h>
+#include <i2s.h>
+#include <net.h>
+#include <cell.h>
+
+#include <unicode.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+
+#include <eve/screen/screen.h>
+#include <eve/screen/window.h>
+#include <eve/screen/view.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/root.h>
+
+#include "status.h"
+#include "phone.h"
+
+extern EVEFont *_app_font_default;
+
+#define ABUF_SIZE 512
+#define MIC_WM 128
+
+static uint8_t mic_arr[ABUF_SIZE];
+static uint8_t spk_arr[ABUF_SIZE];
+
+#define VOICE_STATE_IDLE 0
+#define VOICE_STATE_DIAL 1
+#define VOICE_STATE_RING 2
+#define VOICE_STATE_CIP 3
+
+static unsigned char voice_state = 0;
+
+static void cell_dev_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
+ switch (type) {
+ case EOS_CELL_MTYPE_READY:
+ app_status_msg_set("Modem ready", 1);
+ break;
+
+ case EOS_CELL_MTYPE_PCM_DATA:
+ if (voice_state == VOICE_STATE_CIP) {
+ eos_i2s_spk_write(buffer+1, len-1);
+ }
+ break;
+ }
+ eos_net_free(buffer, 0);
+}
+
+static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
+ char msg[128];
+
+ printf("VOICE: %d\n", type);
+ msg[0] = 0;
+ switch (type) {
+ case EOS_CELL_MTYPE_VOICE_RING:
+ voice_state = VOICE_STATE_RING;
+ sprintf(msg, "RING:%s", buffer+1);
+ break;
+ case EOS_CELL_MTYPE_VOICE_MISS:
+ voice_state = VOICE_STATE_IDLE;
+ break;
+ case EOS_CELL_MTYPE_VOICE_BEGIN:
+ voice_state = VOICE_STATE_CIP;
+ eos_i2s_start(8000, EOS_I2S_FMT_PCM16);
+ break;
+ case EOS_CELL_MTYPE_VOICE_END:
+ voice_state = VOICE_STATE_IDLE;
+ eos_i2s_stop();
+ break;
+ }
+ app_status_msg_set(msg, 1);
+ eos_net_free(buffer, 0);
+}
+
+static void handle_mic(unsigned char type) {
+ uint16_t size;
+ unsigned char *buf = eos_net_alloc();
+
+ buf[0] = EOS_CELL_MTYPE_PCM_DATA;
+ size = eos_i2s_mic_read(buf+1, MIC_WM);
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0);
+}
+
+void app_phone(EVEWindow *window, EVEViewStack *stack) {
+ char *title = "Phone:";
+ uint16_t w = eve_font_str_w(_app_font_default, title) + 10;
+ APPWidgetSpec spec[] = {
+ {
+ .label.g.w = w,
+ .label.font = _app_font_default,
+ .label.title = title,
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.g.w = APP_SCREEN_W - w,
+ .widget.spec.str.font = _app_font_default,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = app_form_create(window, stack, spec, 1, app_phone_action, NULL);
+}
+
+void app_phone_action(EVEForm *form) {
+ char msg[128];
+ EVEStrWidget *w = (EVEStrWidget *)eve_form_widget(form, 0);
+ unsigned char *buf = eos_net_alloc();
+
+ buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_DIAL;
+ strcpy(buf + 1, w->str);
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, 1 + strlen(w->str), 0);
+
+ voice_state = VOICE_STATE_DIAL;
+ sprintf(msg, "DIAL:%s", w->str);
+ app_status_msg_set(msg, 0);
+}
+
+void app_phone_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_DEV, cell_dev_handler);
+ eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, cell_voice_handler);
+
+ eos_i2s_mic_init(mic_arr, ABUF_SIZE);
+ eos_i2s_mic_set_wm(MIC_WM);
+ eos_i2s_mic_set_handler(handle_mic);
+ eos_i2s_spk_init(spk_arr, ABUF_SIZE);
+ eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1);
+}
+
+unsigned char app_phone_state_get(void) {
+ return voice_state;
+}
diff --git a/fw/fe310/test/phone.h b/fw/fe310/test/phone.h
new file mode 100644
index 0000000..f346a38
--- /dev/null
+++ b/fw/fe310/test/phone.h
@@ -0,0 +1,9 @@
+#define VOICE_STATE_IDLE 0
+#define VOICE_STATE_DIAL 1
+#define VOICE_STATE_RING 2
+#define VOICE_STATE_CIP 3
+
+void app_phone(EVEWindow *window, EVEViewStack *stack);
+void app_phone_action(EVEForm *form);
+void app_phone_init(void);
+unsigned char app_phone_state_get(void);
diff --git a/fw/fe310/test/status.c b/fw/fe310/test/status.c
new file mode 100644
index 0000000..489bf78
--- /dev/null
+++ b/fw/fe310/test/status.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <event.h>
+#include <spi.h>
+#include <i2s.h>
+#include <net.h>
+#include <cell.h>
+
+#include <unicode.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+
+#include <eve/screen/screen.h>
+#include <eve/screen/window.h>
+#include <eve/screen/view.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/root.h>
+
+#include "phone.h"
+#include "status.h"
+
+extern EVEFont *_app_font_default;
+
+static char status_msg[128];
+
+static int status_touch(EVEView *v, uint8_t tag0, int touch_idx) {
+ if (touch_idx == 0) {
+ EVETouch *t;
+ uint16_t evt;
+ unsigned char state = app_phone_state_get();
+
+ t = eve_touch_evt(tag0, touch_idx, v->window->tag, 2, &evt);
+ if (t && (evt & EVE_TOUCH_ETYPE_POINT_UP)) {
+ if ((state == VOICE_STATE_RING) && (t->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT)) {
+ unsigned char *buf = eos_net_alloc();
+
+ buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_ANSWER;
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ status_msg[0] = '\0';
+ }
+ if ((state != VOICE_STATE_IDLE) && (t->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT)) {
+ unsigned char *buf = eos_net_alloc();
+
+ buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_HANGUP;
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ status_msg[0] = '\0';
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static uint8_t status_draw(EVEView *v, uint8_t tag0) {
+ uint8_t tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY;
+ if (v->window->tag != EVE_TAG_NOTAG) eve_touch_set_opt(v->window->tag, eve_touch_get_opt(v->window->tag) | tag_opt);
+
+ if (tag0 != EVE_TAG_NOTAG) {
+ eve_touch_set_opt(tag0, eve_touch_get_opt(tag0) | tag_opt);
+ eve_cmd_dl(TAG(tag0));
+ tag0++;
+ }
+
+ eve_cmd(CMD_TEXT, "hhhhs", 0, 0, 31, 0, status_msg);
+
+ return tag0;
+}
+
+void app_status_msg_set(char *msg, int refresh) {
+ strcpy(status_msg, msg);
+
+ if (refresh) {
+ eos_spi_dev_start(EOS_DEV_DISP);
+ eve_screen_draw(app_screen());
+ eos_spi_dev_stop();
+ }
+}
+
+void app_status_init(void) {
+ EVEScreen *screen = app_screen();
+ EVEWindow *status = eve_window_get(screen, "status");
+ status->view->touch = status_touch;
+ status->view->draw = status_draw;
+}
diff --git a/fw/fe310/test/status.h b/fw/fe310/test/status.h
new file mode 100644
index 0000000..c891b7d
--- /dev/null
+++ b/fw/fe310/test/status.h
@@ -0,0 +1,2 @@
+void app_status_msg_set(char *msg, int refresh);
+void app_status_init(void);
diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c
new file mode 100644
index 0000000..595a87c
--- /dev/null
+++ b/fw/fe310/test/wifi.c
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <event.h>
+#include <spi.h>
+#include <uart.h>
+#include <net.h>
+#include <wifi.h>
+
+#include <unicode.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+
+#include <eve/screen/screen.h>
+#include <eve/screen/window.h>
+#include <eve/screen/view.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/root.h>
+
+#include "status.h"
+#include "wifi.h"
+
+extern EVEFont *_app_font_default;
+
+void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ EVEScreen *screen = app_screen();
+ EVEWindow *window = eve_window_get(screen, "main");
+ EVEForm *form = (EVEForm *)window->view;
+ EVESelectWidget *select = (EVESelectWidget *)eve_form_widget(form, 0);
+
+ eve_selectw_option_set(select, buffer + 1, size - 1);
+ eos_net_free(buffer, 0);
+
+ eos_spi_dev_start(EOS_DEV_DISP);
+ eve_screen_draw(app_screen());
+ eos_spi_dev_stop();
+}
+
+static void wifi_connect_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ app_status_msg_set("WiFi connected", 1);
+ eos_net_free(buffer, 0);
+}
+
+static void wifi_disconnect_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ app_status_msg_set("WiFi disconnected", 1);
+ eos_net_free(buffer, 0);
+}
+
+void app_wifi(EVEWindow *window, EVEViewStack *stack) {
+ char *title = "Password:";
+ uint16_t w = eve_font_str_w(_app_font_default, title) + 10;
+ APPWidgetSpec spec[] = {
+ {
+ .label.g.w = APP_SCREEN_W,
+ .label.font = _app_font_default,
+ .label.title = "Select network:",
+
+ .widget.type = EVE_WIDGET_TYPE_SELECT,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.select.font = _app_font_default,
+ .widget.spec.select.option_size = 1500,
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_SPACER,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.g.h = 50,
+ },
+ {
+ .label.g.w = w,
+ .label.font = _app_font_default,
+ .label.title = title,
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.g.w = APP_SCREEN_W - w,
+ .widget.spec.str.font = _app_font_default,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = app_form_create(window, stack, spec, 3, app_wifi_action, app_wifi_close);
+ eos_wifi_scan();
+}
+
+void app_wifi_action(EVEForm *form) {
+ EVESelectWidget *sel = (EVESelectWidget *)eve_form_widget(form, 0);
+ EVEStrWidget *str = (EVEStrWidget *)eve_form_widget(form, 2);
+ char *ssid = eve_selectw_option_get_select(sel);
+
+ eos_wifi_connect(ssid, str->str);
+}
+
+void app_wifi_close(EVEForm *form) {
+ app_form_destroy(form);
+}
+
+void app_wifi_init(void) {
+ eos_wifi_set_handler(EOS_WIFI_MTYPE_SCAN, wifi_scan_handler);
+ eos_wifi_set_handler(EOS_WIFI_MTYPE_CONNECT, wifi_connect_handler);
+ eos_wifi_set_handler(EOS_WIFI_MTYPE_DISCONNECT, wifi_disconnect_handler);
+}
diff --git a/fw/fe310/test/wifi.h b/fw/fe310/test/wifi.h
new file mode 100644
index 0000000..5adaebd
--- /dev/null
+++ b/fw/fe310/test/wifi.h
@@ -0,0 +1,4 @@
+void app_wifi(EVEWindow *window, EVEViewStack *stack);
+void app_wifi_action(EVEForm *form);
+void app_wifi_close(EVEForm *form);
+void app_wifi_init(void); \ No newline at end of file