diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-10-24 19:57:30 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-10-24 19:57:30 +0200 |
commit | a5a94dea7043fa6b65693cf0cc11d426d49c637d (patch) | |
tree | 97b73d5c42a581f1962f07db96313207f84e7a61 /fw | |
parent | d8d94a9c2f13b1a7c6d0c209f9757e3f1f122e0b (diff) |
added SMS app; fixed phone app
Diffstat (limited to 'fw')
-rw-r--r-- | fw/fe310/phone/Makefile | 6 | ||||
-rw-r--r-- | fw/fe310/phone/flash.c | 5 | ||||
-rw-r--r-- | fw/fe310/phone/main.c | 8 | ||||
-rw-r--r-- | fw/fe310/phone/phone.c | 118 | ||||
-rw-r--r-- | fw/fe310/phone/phone.h | 2 | ||||
-rw-r--r-- | fw/fe310/phone/sms.c | 109 | ||||
-rw-r--r-- | fw/fe310/phone/sms.h | 4 | ||||
-rw-r--r-- | fw/fe310/phone/test.c | 7 | ||||
-rw-r--r-- | fw/fe310/phone/timer.c | 5 |
9 files changed, 214 insertions, 50 deletions
diff --git a/fw/fe310/phone/Makefile b/fw/fe310/phone/Makefile index 9cdac9e..5c74fb9 100644 --- a/fw/fe310/phone/Makefile +++ b/fw/fe310/phone/Makefile @@ -1,10 +1,10 @@ include ../common.mk -DEPS = main.o mem.o wifi.o cell.o phone.o modem.o timer.o test.o flash.o +DEPS = main.o mem.o wifi.o cell.o sms.o phone.o modem.o timer.o test.o flash.o lib_eos = eve eos eos-soc eos-dev eos-net eos-ext eos-bsp -lib_ecp = +# lib_ecp = ecp ecpcr ecptm ecptr ecpvconn ecpdir -CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I.. +CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/libressl/include/ -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I.. LDFLAGS = app/*.o $(CFLAGS) -L.. -L$(ecp_dir)/build-fe310 -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc $(addprefix -l,$(lib_eos)) $(addprefix -l,$(lib_ecp)) -Wl,--end-group -T../bsp/default.lds TARGET = phone diff --git a/fw/fe310/phone/flash.c b/fw/fe310/phone/flash.c index e78576a..b0a2d6c 100644 --- a/fw/fe310/phone/flash.c +++ b/fw/fe310/phone/flash.c @@ -131,7 +131,10 @@ int flash_app(EVEWindow *window, EVEViewStack *stack) { APP_SPACERW(1,1), }; EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), flash_uievt, flash_close); - if (page == NULL) return EVE_ERR_NOMEM; + if (page == NULL) { + APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n"); + return EVE_ERR_NOMEM; + } return EVE_OK; } diff --git a/fw/fe310/phone/main.c b/fw/fe310/phone/main.c index 8696ebe..fd4d672 100644 --- a/fw/fe310/phone/main.c +++ b/fw/fe310/phone/main.c @@ -25,6 +25,7 @@ #include "wifi.h" #include "cell.h" +#include "sms.h" #include "phone.h" #include "modem.h" #include "timer.h" @@ -50,6 +51,12 @@ static int home_page(EVEWindow *window, EVEViewStack *stack) { { .widget.type = EVE_WIDGET_TYPE_PAGE, .widget.g.w = APP_SCREEN_W, + .widget.tspec.page.title = "SMS", + .widget.tspec.page.constructor = sms_app, + }, + { + .widget.type = EVE_WIDGET_TYPE_PAGE, + .widget.g.w = APP_SCREEN_W, .widget.tspec.page.title = "Phone", .widget.tspec.page.constructor = phone_app, }, @@ -99,6 +106,7 @@ int main() { wifi_init(); cell_init(); + sms_init(); phone_init(); app_init(home_page, 0x20); diff --git a/fw/fe310/phone/phone.c b/fw/fe310/phone/phone.c index a8d5a86..ca877e4 100644 --- a/fw/fe310/phone/phone.c +++ b/fw/fe310/phone/phone.c @@ -39,41 +39,68 @@ static void handle_mic(unsigned char type) { } static void handle_cell_voice(unsigned char type, unsigned char *buffer, uint16_t len) { + int rv; + switch (type) { case EOS_CELL_MTYPE_VOICE_RING: { - app_status_set_msg("RING"); + rv = EOS_OK; + if (len > EOS_CELL_MAX_DIAL_STR + 1) rv = EOS_ERR_SIZE; + if (rv) { + APP_LOG(APP_LOG_ERR, "RING ERROR:%d\n", rv); + break; + } + + buffer[len + 1] = '\0'; APP_LOG(APP_LOG_DEBUG, "RING:%s\n", buffer+1); - phone_state = PHONE_STATE_RING; + if ((phone_state == PHONE_STATE_IDLE) || (phone_state == PHONE_STATE_RING)) { + phone_state = PHONE_STATE_RING; + app_status_set_msg("RING"); + } + break; + } + + case EOS_CELL_MTYPE_VOICE_BUSY: { + APP_LOG(APP_LOG_DEBUG, "BUSY\n"); + if (phone_state == PHONE_STATE_DIAL) { + phone_state = PHONE_STATE_IDLE; + app_status_set_msg("BUSY"); + } break; } case EOS_CELL_MTYPE_VOICE_MISS: { - app_status_set_msg("MISS"); APP_LOG(APP_LOG_DEBUG, "MISS\n"); - phone_state = PHONE_STATE_IDLE; + if ((phone_state == PHONE_STATE_DIAL) || (phone_state == PHONE_STATE_RING)) { + phone_state = PHONE_STATE_IDLE; + app_status_set_msg("MISS"); + } break; } case EOS_CELL_MTYPE_VOICE_BEGIN: { - app_status_set_msg("CALL BEGIN"); APP_LOG(APP_LOG_DEBUG, "CALL BEGIN\n"); - phone_state = PHONE_STATE_CIP; - eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1); - eos_i2s_spk_init(spk_arr, ABUF_SIZE); - eos_i2s_mic_init(mic_arr, ABUF_SIZE); - eos_i2s_mic_set_wm(MIC_WM); - eos_i2s_mic_set_handler(handle_mic); - eos_i2s_mic_set_vol(4); - eos_i2s_start(8000); + if ((phone_state == PHONE_STATE_DIAL) || (phone_state == PHONE_STATE_RING)) { + phone_state = PHONE_STATE_CIP; + app_status_set_msg("CALL BEGIN"); + eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1); + eos_i2s_spk_init(spk_arr, ABUF_SIZE); + eos_i2s_mic_init(mic_arr, ABUF_SIZE); + eos_i2s_mic_set_wm(MIC_WM); + eos_i2s_mic_set_handler(handle_mic); + eos_i2s_mic_set_vol(4); + eos_i2s_start(8000); + } break; } case EOS_CELL_MTYPE_VOICE_END: { - app_status_set_msg("HUP"); - APP_LOG(APP_LOG_DEBUG, "HUP\n"); - phone_state = PHONE_STATE_IDLE; - eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 0); - eos_i2s_stop(); + APP_LOG(APP_LOG_DEBUG, "CALL END\n"); + if (phone_state == PHONE_STATE_CIP) { + phone_state = PHONE_STATE_IDLE; + app_status_set_msg("CALL END"); + eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 0); + eos_i2s_stop(); + } break; } @@ -107,6 +134,17 @@ static void widget_btn_draw(EVEFreeWidget *widget) { eve_cmd_dl(END()); } +static void call(char * num) { + int rv; + + if (strlen(num)) { + phone_state = PHONE_STATE_DIAL; + app_status_set_msg("DIAL"); + rv = eos_cell_voice_dial(num, NULL, 0); + if (rv) APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv); + } +} + static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt) { if (evt & EVE_TOUCH_ETYPE_TAG_UP) { uint8_t tagi; @@ -125,19 +163,19 @@ static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt case PHONE_STATE_IDLE: { EVEPage *page = widget->w.page; EVEStrWidget *strw = (EVEStrWidget *)eve_page_widget(page, 0); - char *num = strw->str; - if (strlen(num)) { - app_status_set_msg("DIAL"); - rv = eos_cell_voice_dial(num, NULL, 0); - if (rv) APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv); - } + call(strw->str); break; } } } else if (tagi == 1) { - rv = eos_cell_voice_hangup(NULL, 0); - if (rv) APP_LOG(APP_LOG_ERR, "HANGUP ERR:%d\n", rv); + if (phone_state != PHONE_STATE_IDLE) { + if (phone_state != PHONE_STATE_CIP) { + phone_state = PHONE_STATE_IDLE; + } + rv = eos_cell_voice_hangup(NULL, 0); + if (rv) APP_LOG(APP_LOG_ERR, "HANGUP ERR:%d\n", rv); + } } return 1; } @@ -145,13 +183,17 @@ static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt return 0; } +void phone_init(void) { + eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, handle_cell_voice); +} + int phone_app(EVEWindow *window, EVEViewStack *stack) { EVEFormSpec spec[] = { { .label.title = "Phone:", .widget.type = EVE_WIDGET_TYPE_STR, - .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR, + .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR + 1, }, APP_SPACERW(APP_SCREEN_W, 50), { @@ -164,7 +206,10 @@ int phone_app(EVEWindow *window, EVEViewStack *stack) { }; EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, phone_close); - if (page == NULL) return EVE_ERR_NOMEM; + if (page == NULL) { + APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n"); + return EVE_ERR_NOMEM; + } return EVE_OK; } @@ -176,17 +221,10 @@ int phone_uievt(EVEPage *page, uint16_t evt, void *param) { case EVE_UIEVT_WIDGET_FOCUS_OUT: { if (param == eve_page_widget(page, 0)) { EVEStrWidget *strw = param; - int rv; - rv = eos_cell_voice_dial((char *)strw->str, NULL, 0); - if (rv) { - APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv); - return ret; + if (phone_state == PHONE_STATE_IDLE) { + call(strw->str); } - app_status_set_msg("DIAL"); - APP_LOG(APP_LOG_DEBUG, "DIAL:%s\n", strw->str); - eos_cell_voice_dial(strw->str, NULL, 0); - phone_state = PHONE_STATE_DIAL; } break; } @@ -204,10 +242,6 @@ void phone_close(EVEPage *page) { eve_form_destroy(page); } -void phone_init(void) { - eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, handle_cell_voice); -} - -unsigned char app_phone_state_get(void) { +unsigned char phone_get_state(void) { return phone_state; } diff --git a/fw/fe310/phone/phone.h b/fw/fe310/phone/phone.h index c7f8a82..c7ab167 100644 --- a/fw/fe310/phone/phone.h +++ b/fw/fe310/phone/phone.h @@ -3,7 +3,7 @@ #define PHONE_STATE_RING 2 #define PHONE_STATE_CIP 3 +void phone_init(void); int phone_app(EVEWindow *window, EVEViewStack *stack); int phone_uievt(EVEPage *page, uint16_t evt, void *param); void phone_close(EVEPage *page); -void phone_init(void);
\ No newline at end of file diff --git a/fw/fe310/phone/sms.c b/fw/fe310/phone/sms.c new file mode 100644 index 0000000..d2819c9 --- /dev/null +++ b/fw/fe310/phone/sms.c @@ -0,0 +1,109 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include <eos.h> +#include <soc/i2s.h> +#include <dev/net.h> +#include <net/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 "app/app.h" +#include "app/status.h" + +#include "sms.h" + +static void handle_cell_sms(unsigned char type, unsigned char *buffer, uint16_t len) { + int rv; + + switch (type) { + case EOS_CELL_MTYPE_SMS_MSG: { + char num[EOS_CELL_MAX_DIAL_STR + 1], text[EOS_CELL_MAX_SMS_TEXT + 1]; + + rv = eos_cell_sms_recv(buffer, len, num, sizeof(num), text, sizeof(text)); + if (rv) { + APP_LOG(APP_LOG_ERR, "SMS PARSE ERR:%d\n", rv); + break; + } + APP_LOG(APP_LOG_DEBUG, "SMS From:%s\n%s\n", num, text); + break; + } + } + eos_net_free(buffer, 0); +} + +static void send(char *num, char *text) { + int rv; + + if (strlen(num)) { + app_status_set_msg("SMS SENT"); + rv = eos_cell_sms_send(num, text, NULL, 0); + if (rv) APP_LOG(APP_LOG_ERR, "SMS SEND ERR:%d\n", rv); + } + +} + +void sms_init(void) { + eos_cell_set_handler(EOS_CELL_MTYPE_SMS, handle_cell_sms); +} + +int sms_app(EVEWindow *window, EVEViewStack *stack) { + EVEFormSpec spec[] = { + { + .label.title = "Text:", + + .widget.type = EVE_WIDGET_TYPE_STR, + .widget.tspec.str.str_size = EOS_CELL_MAX_SMS_TEXT + 1, + }, + APP_SPACERW(APP_SCREEN_W, 50), + { + .label.title = "Phone:", + + .widget.type = EVE_WIDGET_TYPE_STR, + .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR + 1, + }, + }; + + EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, sms_close); + if (page == NULL) { + APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n"); + return EVE_ERR_NOMEM; + } + + return EVE_OK; +} + +int sms_uievt(EVEPage *page, uint16_t evt, void *param) { + int ret = 0; + + switch (evt) { + case EVE_UIEVT_WIDGET_FOCUS_OUT: { + if (param == eve_page_widget(page, 1)) { + EVEStrWidget *num = param; + EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(page, 0); + + send(num->str, text->str); + } + break; + } + + default: { + ret = eve_form_uievt(page, evt, param); + break; + } + } + + return ret; +} + +void sms_close(EVEPage *page) { + eve_form_destroy(page); +} diff --git a/fw/fe310/phone/sms.h b/fw/fe310/phone/sms.h new file mode 100644 index 0000000..75bdd57 --- /dev/null +++ b/fw/fe310/phone/sms.h @@ -0,0 +1,4 @@ +void sms_init(void); +int sms_app(EVEWindow *window, EVEViewStack *stack); +int sms_uievt(EVEPage *page, uint16_t evt, void *param); +void sms_close(EVEPage *page); diff --git a/fw/fe310/phone/test.c b/fw/fe310/phone/test.c index 72f575f..06f35c3 100644 --- a/fw/fe310/phone/test.c +++ b/fw/fe310/phone/test.c @@ -30,10 +30,13 @@ static int reg_write(uint8_t reg, uint8_t data) { int test_app(EVEWindow *window, EVEViewStack *stack) { EVEFormSpec spec[] = { - APP_SPACERW(1,1), + APP_SPACERW(APP_SCREEN_W,1), }; EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), test_uievt, test_close); - if (page == NULL) return EVE_ERR_NOMEM; + if (page == NULL) { + APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n"); + return EVE_ERR_NOMEM; + } app_status_set_msg("TEST!"); return EVE_OK; diff --git a/fw/fe310/phone/timer.c b/fw/fe310/phone/timer.c index 03593ff..cd66053 100644 --- a/fw/fe310/phone/timer.c +++ b/fw/fe310/phone/timer.c @@ -31,7 +31,10 @@ int timer_app(EVEWindow *window, EVEViewStack *stack) { APP_SPACERW(1,1), }; EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, timer_close); - if (page == NULL) return EVE_ERR_NOMEM; + if (page == NULL) { + APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n"); + return EVE_ERR_NOMEM; + } eos_timer_set_handler(EOS_TIMER_ETYPE_USR, timer); eos_timer_set(EOS_TIMER_ETYPE_USR, 500); eos_net_acquire_for_evt(EOS_EVT_TIMER | EOS_TIMER_ETYPE_USR, 1); |