diff options
Diffstat (limited to 'fw/fe310/test/modem.c')
-rw-r--r-- | fw/fe310/test/modem.c | 54 |
1 files changed, 29 insertions, 25 deletions
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 = ¶m->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(¶m->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, ¶m->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); } |