summaryrefslogtreecommitdiff
path: root/fw/fe310/test
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/test')
-rw-r--r--fw/fe310/test/Makefile24
-rw-r--r--fw/fe310/test/cam.c166
-rw-r--r--fw/fe310/test/cam.h2
-rw-r--r--fw/fe310/test/cell_dev.c24
-rw-r--r--fw/fe310/test/cell_dev.h1
-rw-r--r--fw/fe310/test/cell_pdp.c108
-rw-r--r--fw/fe310/test/cell_pdp.h4
-rw-r--r--fw/fe310/test/fs.c104
-rw-r--r--fw/fe310/test/fs.h3
-rw-r--r--fw/fe310/test/main.c93
-rw-r--r--fw/fe310/test/modem.c168
-rw-r--r--fw/fe310/test/modem.h2
-rw-r--r--fw/fe310/test/phone.c122
-rw-r--r--fw/fe310/test/phone.h9
-rw-r--r--fw/fe310/test/status.c81
-rw-r--r--fw/fe310/test/status.h2
-rw-r--r--fw/fe310/test/test.c62
-rw-r--r--fw/fe310/test/test.h2
-rw-r--r--fw/fe310/test/wifi.c119
-rw-r--r--fw/fe310/test/wifi.h4
20 files changed, 1100 insertions, 0 deletions
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
new file mode 100644
index 0000000..8476db8
--- /dev/null
+++ b/fw/fe310/test/Makefile
@@ -0,0 +1,24 @@
+include ../common.mk
+
+CRYPTO_DIR = ../../../crypto
+
+CFLAGS += -I.. -I../eos -I../bsp/include -I../bsp/drivers -I$(CRYPTO_DIR)
+LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds
+
+DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o fs.o test.o
+TARGET = phone
+
+all: $(TARGET)
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $<
+
+$(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/cam.c b/fw/fe310/test/cam.c
new file mode 100644
index 0000000..caab2cc
--- /dev/null
+++ b/fw/fe310/test/cam.c
@@ -0,0 +1,166 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <cam.h>
+
+#include <i2c.h>
+#include <i2c/ov2640.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include <board.h>
+
+#include "cam.h"
+
+#include <stdio.h>
+
+static int cam_init = 0;
+static int cam_capture = 0;
+
+#define CHUNK_SIZE 512
+
+#define CAM_W 640
+#define CAM_H 480
+
+static void transfer_chunk(uint8_t *fbuf, size_t size, int first, int last, uint32_t addr) {
+ int rv;
+
+ eos_cam_fbuf_read(fbuf, size, first);
+ if (last) {
+ eos_cam_fbuf_done();
+ eos_cam_capture();
+ }
+
+ eos_spi_select(EOS_SPI_DEV_EVE);
+ eve_cmd_burst_start();
+ if (first) eve_cmd(CMD_LOADIMAGE, "ww+", addr, EVE_OPT_NODL);
+ eve_cmd_write(fbuf, size);
+ if (last) eve_cmd_end();
+ eve_cmd_burst_end();
+ rv = eve_cmd_exec(last);
+ if (rv) printf("CMD EXEC ERR\n");
+ if (!last) eos_spi_select(EOS_SPI_DEV_CAM);
+}
+
+static void transfer_img(uint32_t addr) {
+ int i;
+ uint32_t fb_size;
+ uint32_t fb_div;
+ uint32_t fb_mod;
+ uint8_t fbuf[CHUNK_SIZE];
+
+ cam_capture = 1;
+ fb_size = eos_cam_fbuf_size();
+
+ fb_div = fb_size / CHUNK_SIZE;
+ fb_mod = fb_size % CHUNK_SIZE;
+ for (i=0; i<fb_div; i++) {
+ transfer_chunk(fbuf, CHUNK_SIZE, i == 0, (fb_mod == 0) && (i + 1 == fb_div), addr);
+ }
+ if (fb_mod) {
+ transfer_chunk(fbuf, fb_mod, fb_size < CHUNK_SIZE, 1, addr);
+ }
+ printf("CAPTURE DONE. ADDR:%x SIZE:%d\n", addr, fb_size);
+}
+
+static void user_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ eos_spi_select(EOS_SPI_DEV_CAM);
+ if (eos_cam_capture_done()) {
+ EVEWindowRoot *root = app_root();
+ uint32_t addr = root->mem_next;
+
+ transfer_img(addr);
+ eve_window_root_draw(root);
+ }
+ eos_spi_deselect();
+ eos_evtq_push(EOS_EVT_USER, NULL, 0);
+}
+
+static void image_draw(EVEFreeWidget *widget) {
+ EVEWindowRoot *root = widget->w.page->v.window->root;
+ uint32_t addr = root->mem_next;
+
+ if (cam_capture) {
+ // eve_freew_tag(widget);
+ eve_cmd_dl(TAG_MASK(0));
+ eve_cmd_dl(BEGIN(EVE_BITMAPS));
+ // eve_cmd_dl(BITMAP_HANDLE(15));
+ eve_cmd_dl(BITMAP_SOURCE(addr));
+ eve_cmd_dl(BITMAP_LAYOUT(EVE_RGB565, CAM_W * 2, CAM_H));
+ eve_cmd_dl(BITMAP_LAYOUT_H(CAM_W * 2, CAM_H));
+ eve_cmd_dl(BITMAP_SIZE(EVE_NEAREST, EVE_BORDER, EVE_BORDER, CAM_H, CAM_W));
+ eve_cmd_dl(BITMAP_SIZE_H(CAM_H, CAM_W));
+ eve_cmd(CMD_LOADIDENTITY, "");
+ eve_cmd(CMD_TRANSLATE, "ww", CAM_H * 65536, 0);
+ eve_cmd(CMD_ROTATE, "w", 90 * 65536 / 360);
+ eve_cmd(CMD_SETMATRIX, "");
+ eve_cmd_dl(VERTEX2F(0, 0));
+ eve_cmd_dl(TAG_MASK(1));
+ }
+}
+
+static int image_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt) {
+ return 0;
+}
+
+void fbuf_print(uint8_t *fbuf, size_t size) {
+ int i;
+
+ for (i=0; i<size; i++) {
+ if (i % 128 == 0) printf("\n");
+ printf("%.2x", fbuf[i]);
+ }
+}
+
+void app_cam(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .widget.type = EVE_WIDGET_TYPE_FREE,
+ .widget.g.h = CAM_W,
+ .widget.spec.free.draw = image_draw,
+ .widget.spec.free.touch = image_touch,
+ },
+ };
+ EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, app_cam_close);
+ int rv = EOS_OK;
+
+ eve_gpio_set(EVE_GPIO_CAM, 1);
+ eos_time_sleep(100);
+ eos_i2c_start(100000);
+
+ rv = eos_ov2640_init();
+ if (!rv) rv = eos_ov2640_set_pixfmt(PIXFORMAT_JPEG);
+ if (!rv) rv = eos_ov2640_set_framesize(FRAMESIZE_VGA);
+ eos_i2c_stop();
+
+ if (!rv) {
+ printf("CAM INIT\n");
+ } else {
+ printf("CAM INIT ERR:%d\n", rv);
+ }
+ eos_evtq_set_handler(EOS_EVT_USER, user_handler);
+ eos_evtq_push(EOS_EVT_USER, NULL, 0);
+ eos_spi_select(EOS_SPI_DEV_CAM);
+ eos_cam_capture();
+ eos_spi_select(EOS_SPI_DEV_EVE);
+}
+
+void app_cam_close(EVEForm *form) {
+ eve_form_destroy(form);
+ eve_gpio_set(EVE_GPIO_CAM, 0);
+ eos_evtq_get(EOS_EVT_USER, NULL, NULL);
+ eos_evtq_set_handler(EOS_EVT_USER, NULL);
+}
diff --git a/fw/fe310/test/cam.h b/fw/fe310/test/cam.h
new file mode 100644
index 0000000..fdf07b8
--- /dev/null
+++ b/fw/fe310/test/cam.h
@@ -0,0 +1,2 @@
+void app_cam(EVEWindow *window, EVEViewStack *stack);
+void app_cam_close(EVEForm *form);
diff --git a/fw/fe310/test/cell_dev.c b/fw/fe310/test/cell_dev.c
new file mode 100644
index 0000000..40f2736
--- /dev/null
+++ b/fw/fe310/test/cell_dev.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <net.h>
+#include <cell.h>
+
+#include "status.h"
+#include "cell_dev.h"
+
+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;
+ }
+ eos_net_free(buffer, 0);
+}
+
+void app_cell_dev_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_DEV, cell_dev_handler);
+}
diff --git a/fw/fe310/test/cell_dev.h b/fw/fe310/test/cell_dev.h
new file mode 100644
index 0000000..19b7717
--- /dev/null
+++ b/fw/fe310/test/cell_dev.h
@@ -0,0 +1 @@
+void app_cell_dev_init(void); \ No newline at end of file
diff --git a/fw/fe310/test/cell_pdp.c b/fw/fe310/test/cell_pdp.c
new file mode 100644
index 0000000..9fc4a21
--- /dev/null
+++ b/fw/fe310/test/cell_pdp.c
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <net.h>
+#include <cell.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include "status.h"
+#include "cell_pdp.h"
+
+static void cell_pdp_connect(char *apn, char *user, char *pass) {
+ unsigned char *buffer, *p;
+
+ buffer = eos_net_alloc();
+ buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONFIG;
+ p = buffer + 1;
+ strcpy(p, user);
+ p += strlen(user) + 1;
+ strcpy(p, user);
+ p += strlen(user) + 1;
+ strcpy(p, pass);
+ p += strlen(pass) + 1;
+ eos_net_send(EOS_NET_MTYPE_CELL, buffer, p - buffer, 1);
+
+ buffer = eos_net_alloc();
+ buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONNECT;
+ eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0);
+}
+
+static void cell_pdp_disconnect(void) {
+ unsigned char *buffer = eos_net_alloc();
+ buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_DISCONNECT;
+ eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0);
+}
+
+static void cell_pdp_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ switch (type) {
+ case EOS_CELL_MTYPE_PDP_CONNECT:
+ app_status_msg_set("Cell data connected", 1);
+ break;
+
+ case EOS_CELL_MTYPE_PDP_DISCONNECT:
+ app_status_msg_set("Cell data disconnected", 1);
+ break;
+
+ default:
+ break;
+ }
+ eos_net_free(buffer, 0);
+}
+
+void app_cell_pdp(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.title = "APN:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = 128,
+ },
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.title = "User:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = 128,
+ },
+ {
+ .label.g.w = APP_SCREEN_W / 3,
+ .label.title = "Pass:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = eve_form_create(window, stack, spec, 3, NULL, app_cell_pdp_action, app_cell_pdp_close);
+}
+
+void app_cell_pdp_action(EVEForm *form) {
+ EVEStrWidget *apn = (EVEStrWidget *)eve_page_widget(&form->p, 0);
+ EVEStrWidget *user = (EVEStrWidget *)eve_page_widget(&form->p, 1);
+ EVEStrWidget *pass = (EVEStrWidget *)eve_page_widget(&form->p, 2);
+
+ cell_pdp_connect(apn->str, user->str, pass->str);
+}
+
+void app_cell_pdp_close(EVEForm *form) {
+ eve_form_destroy(form);
+}
+
+void app_cell_pdp_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_PDP, cell_pdp_handler);
+}
diff --git a/fw/fe310/test/cell_pdp.h b/fw/fe310/test/cell_pdp.h
new file mode 100644
index 0000000..3c28176
--- /dev/null
+++ b/fw/fe310/test/cell_pdp.h
@@ -0,0 +1,4 @@
+void app_cell_pdp(EVEWindow *window, EVEViewStack *stack);
+void app_cell_pdp_action(EVEForm *form);
+void app_cell_pdp_close(EVEForm *form);
+void app_cell_pdp_init(void); \ No newline at end of file
diff --git a/fw/fe310/test/fs.c b/fw/fe310/test/fs.c
new file mode 100644
index 0000000..e8b3587
--- /dev/null
+++ b/fw/fe310/test/fs.c
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <sdc_crypto.h>
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <aes/aes.h>
+#include <fsfat/ff.h>
+
+#include "fs.h"
+
+FATFS fs;
+
+#define TEXT_SIZE 128
+#define TEXT_FN "test.txt"
+#define KEY "passwordpassword"
+
+PARTITION VolToPart[FF_VOLUMES] = {
+ {0, 1} /* "0:" ==> 1st partition on the pd#0 */
+};
+
+static EOSSDCCrypto sdcc;
+static AESCtx ctx_crypt;
+static AESCtx ctx_essiv;
+
+void app_fs(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .label.title = "Text",
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = TEXT_SIZE,
+ },
+ };
+ EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, app_fs_close);
+ EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(&form->p, 0);
+ FIL f;
+ FRESULT rv;
+
+ eos_spi_select(EOS_SPI_DEV_SDC);
+ rv = f_open(&f, TEXT_FN, FA_READ);
+ printf("f_open:%d\n", rv);
+ if (!rv) {
+ UINT r;
+
+ rv = f_read(&f, text->str, TEXT_SIZE-1, &r);
+ printf("f_read:%d\n", rv);
+ if (rv != FR_OK) r = 0;
+ text->str[r] = '\0';
+ f_close(&f);
+ }
+ eos_spi_select(EOS_SPI_DEV_EVE);
+ eve_strw_update(text);
+}
+
+void app_fs_close(EVEForm *form) {
+ EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(&form->p, 0);
+ FIL f;
+ FRESULT rv;
+
+ eos_spi_select(EOS_SPI_DEV_SDC);
+ rv = f_open(&f, TEXT_FN, FA_WRITE | FA_CREATE_ALWAYS);
+ printf("f_open:%d\n", rv);
+ if (!rv) {
+ UINT w;
+
+ rv = f_write(&f, text->str, strlen(text->str), &w);
+ printf("f_write:%d\n", rv);
+ f_close(&f);
+ }
+ eos_spi_select(EOS_SPI_DEV_EVE);
+ eve_form_destroy(form);
+}
+
+void app_fs_init(void) {
+ FRESULT rv;
+
+ eos_sdcc_init(&sdcc, KEY, &ctx_crypt, (eve_sdcc_init_t)aes_init, (eve_sdcc_crypt_t)aes_cbc_encrypt, (eve_sdcc_crypt_t)aes_cbc_decrypt, &ctx_essiv, (eve_sdcc_init_t)aes_init, (eve_sdcc_essiv_t)aes_ecb_encrypt);
+ eos_spi_select(EOS_SPI_DEV_SDC);
+ rv = f_mount(&fs, "", 1);
+ printf("f_mount:%d\n", rv);
+ if (rv == FR_NO_FILESYSTEM) {
+ uint8_t w[FF_MAX_SS];
+ LBA_t plist[] = {100, 0};
+
+ rv = f_fdisk(0, plist, w);
+ printf("f_fdisk:%d\n", rv);
+ rv = f_mkfs("0:", 0, w, sizeof(w));
+ printf("f_mkfs:%d\n", rv);
+ rv = f_mount(&fs, "", 1);
+ printf("f_mount:%d\n", rv);
+ }
+ eos_spi_deselect();
+} \ No newline at end of file
diff --git a/fw/fe310/test/fs.h b/fw/fe310/test/fs.h
new file mode 100644
index 0000000..c525c5b
--- /dev/null
+++ b/fw/fe310/test/fs.h
@@ -0,0 +1,3 @@
+void app_fs(EVEWindow *window, EVEViewStack *stack);
+void app_fs_close(EVEForm *form);
+void app_fs_init(void);
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
new file mode 100644
index 0000000..844dedc
--- /dev/null
+++ b/fw/fe310/test/main.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include "status.h"
+#include "cell_dev.h"
+#include "cell_pdp.h"
+#include "phone.h"
+#include "modem.h"
+#include "wifi.h"
+#include "cam.h"
+#include "fs.h"
+#include "test.h"
+
+void app_home_page(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .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.title = "WiFi",
+ .widget.spec.page.constructor = app_wifi
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.title = "Cellular data",
+ .widget.spec.page.constructor = app_cell_pdp
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.page.title = "Modem",
+ .widget.spec.page.constructor = app_modem
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
+ .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,
+ .widget.spec.page.title = "Test",
+ .widget.spec.page.constructor = app_test
+ },
+ };
+
+ EVEForm *form = eve_form_create(window, stack, spec, 7, NULL, 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_dev_init();
+ app_cell_pdp_init();
+ app_fs_init();
+
+ eos_evtq_loop();
+}
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
new file mode 100644
index 0000000..b9fd1b1
--- /dev/null
+++ b/fw/fe310/test/modem.c
@@ -0,0 +1,168 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <uart.h>
+#include <net.h>
+#include <cell.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_text.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/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) {
+ EVEView *view = p;
+ EVEText *text = &((VParam *)view->param)->text;
+ unsigned char *buf;
+ int i = 2;
+
+ 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';
+ i++;
+ } else {
+ buf[1] = c;
+ }
+
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0);
+ eve_text_scroll0(text);
+}
+
+static void handle_uart(unsigned char type) {
+ int i = 0;
+ int c = 0;
+ unsigned char *buf = NULL;
+
+ c = eos_uart_getc(0);
+ if (c == EOS_ERR_EMPTY) return;
+
+ buf = eos_net_alloc();
+ 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) {
+ buf[i] = c;
+ i++;
+ if (i == EOS_NET_MTU) break;
+ }
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0);
+ eos_uart_rxwm_set(0);
+}
+
+static void handle_cell_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
+ EVEWindowRoot *root = app_root();
+ EVEWindow *window = eve_window_search(&root->w, "main");
+ VParam *param = window->view->param;
+
+ if (type == EOS_CELL_MTYPE_UART_DATA) {
+ EVEText *text = &param->text;
+ int i;
+
+ eve_spi_start();
+ for (i=1; i<len; i++) {
+ if (buffer[i] != '\r') eve_text_putc(text, buffer[i]);
+ }
+ if (text->dirty) {
+ text->dirty = 0;
+ eve_window_root_draw(root);
+ }
+ eve_spi_stop();
+ eos_net_free(buffer, 0);
+ } else {
+ param->cell_dev_handler(type, buffer, len);
+ }
+}
+
+static uint8_t modem_draw(EVEView *view, uint8_t tag0) {
+ VParam *param = view->param;
+ EVEText *text = &param->text;
+
+ tag0 = eve_view_clear(view, tag0, 0);
+ return eve_text_draw(text, tag0);
+}
+
+static int modem_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ VParam *param = view->param;
+ EVEText *text = &param->text;
+
+ return eve_text_touch(text, touch, evt, tag0);
+}
+
+void app_modem(EVEWindow *window, EVEViewStack *stack) {
+ unsigned char *buf;
+ EVEWindowRoot *root = window->root;
+ EVEKbd *kbd = eve_window_kbd(window);
+ EVERect g = {0, 60, 480, 512};
+ EVEView *view;
+ VParam *param;
+
+ view = eve_malloc(sizeof(EVEView));
+ param = eve_malloc(sizeof(VParam));
+ param->mem = root->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, root->mem_next, &root->mem_next);
+ eve_view_init(view, window, modem_draw, modem_touch, NULL, param);
+
+ eve_kbd_set_handler(kbd, key_down, view);
+ eve_window_kbd_attach(window);
+
+ eos_uart_set_handler(EOS_UART_ETYPE_RX, handle_uart);
+ eos_cell_set_handler(EOS_CELL_MTYPE_DEV, handle_cell_msg);
+ eos_net_acquire_for_evt(EOS_EVT_UART | EOS_UART_ETYPE_RX, 1);
+
+ buf = eos_net_alloc();
+ 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_close(EVEView *view) {
+ unsigned char *buf = eos_net_alloc();
+ VParam *param = view->param;
+ EVEWindow *window = view->window;
+ EVEWindowRoot *root = window->root;
+ EVEKbd *kbd = eve_window_kbd(window);
+ EVEViewStack *stack = param->stack;
+
+ 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, param->cell_dev_handler);
+ eos_net_acquire_for_evt(EOS_EVT_UART | EOS_UART_ETYPE_RX, 0);
+
+ root->mem_next = param->mem;
+ eve_window_kbd_detach(window);
+ eve_kbd_set_handler(kbd, NULL, NULL);
+
+ eve_free(param);
+ eve_free(view);
+ 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..78531b5
--- /dev/null
+++ b/fw/fe310/test/phone.c
@@ -0,0 +1,122 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <i2s.h>
+#include <net.h>
+#include <cell.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include "status.h"
+#include "phone.h"
+
+#define ABUF_SIZE 128
+#define MIC_WM 64
+
+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 handle_mic(unsigned char type) {
+ uint16_t size;
+ unsigned char *buf = eos_net_alloc();
+
+ buf[0] = EOS_CELL_MTYPE_VOICE_PCM;
+ size = eos_i2s_mic_read(buf+1, MIC_WM);
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0);
+}
+
+static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
+ char msg[128];
+
+ 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:
+ printf("VOICE BEGIN\n");
+ 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;
+
+ case EOS_CELL_MTYPE_VOICE_PCM:
+ if (voice_state == VOICE_STATE_CIP) {
+ eos_i2s_spk_write(buffer+1, len-1);
+ }
+ break;
+ }
+ app_status_msg_set(msg, 1);
+ eos_net_free(buffer, 0);
+}
+
+void app_phone(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .label.title = "Phone:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, app_phone_action, NULL);
+}
+
+void app_phone_action(EVEForm *form) {
+ char msg[128];
+ EVEStrWidget *w = (EVEStrWidget *)eve_page_widget(&form->p, 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_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..42d193a
--- /dev/null
+++ b/fw/fe310/test/status.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <net.h>
+#include <cell.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include "phone.h"
+#include "status.h"
+
+static char status_msg[128];
+
+static int status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ unsigned char state = app_phone_state_get();
+ int8_t touch_idx = eve_touch_get_idx(touch);
+
+ if (touch_idx != 0) return 0;
+
+ evt = eve_touch_evt(touch, evt, tag0, view->tag, 2);
+ if (touch && (evt & EVE_TOUCH_ETYPE_POINT_UP)) {
+ if ((state == VOICE_STATE_RING) && (touch->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) && (touch->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 *view, uint8_t tag0) {
+ uint8_t tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY;
+
+ tag0 = eve_view_clear(view, tag0, tag_opt);
+
+ if (tag0 != EVE_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) app_root_refresh();
+}
+
+void app_status_init(void) {
+ EVEWindowRoot *root = app_root();
+ EVEWindow *status = eve_window_search(&root->w, "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/test.c b/fw/fe310/test/test.c
new file mode 100644
index 0000000..9e5c790
--- /dev/null
+++ b/fw/fe310/test/test.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <i2c.h>
+#include <i2c/bq25895.h>
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include <board.h>
+
+#include "test.h"
+
+#include <stdio.h>
+
+int app_test_uievt(EVEForm *form, uint16_t evt, void *param) {
+ uint8_t data = 0;
+ int ret = 0, i;
+
+ switch (evt) {
+ case EVE_UIEVT_PAGE_TOUCH:
+ printf("PAGE TOUCH\n");
+ printf("BQ25895:\n");
+ eos_i2c_start(400000);
+ for (i=0; i<0x15; i++) {
+ ret = eos_i2c_read8(BQ25895_ADDR, i, &data);
+ if (!ret) printf("REG%02x: %02x\n", i, data);
+ }
+ eos_i2c_stop();
+ break;
+
+ default:
+ ret = eve_form_uievt(form, evt, param);
+ break;
+ }
+ return ret;
+}
+
+void app_test(EVEWindow *window, EVEViewStack *stack) {
+ EVEWidgetSpec spec[] = {
+ {
+ .widget.type = EVE_WIDGET_TYPE_SPACER,
+ .widget.g.h = 1,
+ },
+ };
+ EVEForm *form = eve_form_create(window, stack, spec, 1, app_test_uievt, NULL, app_test_close);
+}
+
+void app_test_close(EVEForm *form) {
+ eve_form_destroy(form);
+}
diff --git a/fw/fe310/test/test.h b/fw/fe310/test/test.h
new file mode 100644
index 0000000..daf1f1a
--- /dev/null
+++ b/fw/fe310/test/test.h
@@ -0,0 +1,2 @@
+void app_test(EVEWindow *window, EVEViewStack *stack);
+void app_test_close(EVEForm *form);
diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c
new file mode 100644
index 0000000..814d808
--- /dev/null
+++ b/fw/fe310/test/wifi.c
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <net.h>
+#include <wifi.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include <eve/widget/widgets.h>
+
+#include <app/app_root.h>
+
+#include "status.h"
+#include "wifi.h"
+
+static void 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);
+}
+
+static void wifi_connect(const char *ssid, const char *pass) {
+ unsigned char *buffer, *p;
+
+ buffer = eos_net_alloc();
+ buffer[0] = EOS_WIFI_MTYPE_CONFIG;
+ p = buffer + 1;
+ strcpy(p, ssid);
+ p += strlen(ssid) + 1;
+ strcpy(p, pass);
+ p += strlen(pass) + 1;
+ eos_net_send(EOS_NET_MTYPE_WIFI, buffer, p - buffer, 1);
+
+ buffer = eos_net_alloc();
+ buffer[0] = EOS_WIFI_MTYPE_CONNECT;
+ eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
+}
+
+static void wifi_disconnect(void) {
+ unsigned char *buffer = eos_net_alloc();
+ buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
+ eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
+}
+
+void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+ EVEWindowRoot *root = app_root();
+ EVEWindow *window = eve_window_search(&root->w, "main");
+ EVEForm *form = (EVEForm *)window->view;
+ EVESelectWidget *select = (EVESelectWidget *)eve_page_widget(&form->p, 0);
+
+ eve_selectw_option_set(select, buffer + 1, size - 1);
+ eos_net_free(buffer, 0);
+
+ app_root_refresh();
+}
+
+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) {
+ EVEWidgetSpec spec[] = {
+ {
+ .label.g.w = APP_SCREEN_W,
+ .label.title = "Select network:",
+
+ .widget.type = EVE_WIDGET_TYPE_SELECT,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.spec.select.option_size = 1500,
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_SPACER,
+ .widget.g.w = APP_SCREEN_W,
+ .widget.g.h = 50,
+ },
+ {
+ .label.title = "Password:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.spec.str.str_size = 128,
+ },
+ };
+
+ EVEForm *form = eve_form_create(window, stack, spec, 3, NULL, app_wifi_action, app_wifi_close);
+ wifi_scan();
+}
+
+void app_wifi_action(EVEForm *form) {
+ EVESelectWidget *sel = (EVESelectWidget *)eve_page_widget(&form->p, 0);
+ EVEStrWidget *str = (EVEStrWidget *)eve_page_widget(&form->p, 2);
+ char *ssid = eve_selectw_option_get_select(sel);
+
+ if (ssid) wifi_connect(ssid, str->str);
+}
+
+void app_wifi_close(EVEForm *form) {
+ eve_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