diff options
Diffstat (limited to 'fw/fe310/eos/eve')
44 files changed, 966 insertions, 818 deletions
diff --git a/fw/fe310/eos/eve/Makefile b/fw/fe310/eos/eve/Makefile index 323a132..650bff8 100644 --- a/fw/fe310/eos/eve/Makefile +++ b/fw/fe310/eos/eve/Makefile @@ -1,7 +1,8 @@ include ../../common.mk -CFLAGS += -I$(bsp_dir)/include -obj = eve.o eve_eos.o eve_platform.o eve_touch.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o +obj = eve.o eve_platform.o eve_touch.o eve_touch_engine.o eve_phy.o eve_vtrack.o eve_font.o eve_kbd.o eve_text.o clipb.o +subdirs = screen widget +lib = ../../libeve.a %.o: %.c %.h @@ -10,7 +11,16 @@ obj = eve.o eve_eos.o eve_platform.o eve_touch.o eve_phy.o eve_vtrack.o eve_font %.o: %.S $(CC) $(CFLAGS) -c $< -all: $(obj) +all: $(lib) + +$(lib): $(obj) + for i in $(subdirs); do \ + (cd $$i && $(MAKE)) || exit; \ + done + $(AR) rcs $@ $(obj) screen/*.o widget/*.o clean: - rm -f *.o + for i in $(subdirs); do \ + (cd $$i && $(MAKE) clean) || exit; \ + done + rm -f *.o $(lib) diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index e1191fc..5103e5f 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -13,6 +13,7 @@ static char dl_burst; static uint32_t dl_addr; static uint8_t power_state; +static int lcd_absent = 0; void eve_command(uint8_t command, uint8_t parameter) { eve_spi_cs_set(); @@ -289,6 +290,7 @@ int eve_cmd_exec(int w) { void eve_cmd_burst_start(void) { uint32_t addr = EVE_RAM_CMD + cmd_offset; + eve_spi_lock(); eve_spi_cs_set(); eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX); @@ -306,10 +308,10 @@ void eve_handle_intr(void) { uint16_t intr_flags; intr_flags = eve_read16(REG_INT_FLAGS); - eve_handle_touch(intr_flags); + if (intr_flags & (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)) eve_handle_touch(intr_flags); } -int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { +int eve_init(void) { uint8_t chipid = 0; uint8_t reset = 0x07; uint16_t timeout; @@ -319,11 +321,11 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { eve_command(EVE_CLKEXT, 0); eve_command(EVE_CLKSEL, 0x46); /* set clock to 72 MHz */ eve_command(EVE_ACTIVE, 0); /* start EVE */ - eve_time_sleep(4); + eve_sleep(4); timeout = 0; while (chipid != 0x7c) { /* if chipid is not 0x7c, continue to read it until it is, EVE needs a moment for it's power on self-test and configuration */ - eve_time_sleep(1); + eve_sleep(1); chipid = eve_read8(REG_ID); timeout++; if (timeout > 400) return EVE_ERR; @@ -331,7 +333,7 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { timeout = 0; while (reset != 0x00) { /* check if EVE is in working status */ - eve_time_sleep(1); + eve_sleep(1); reset = eve_read8(REG_CPURESET) & 0x07; timeout++; if(timeout > 50) return EVE_ERR; @@ -341,7 +343,7 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { eve_write8(REG_PWM_DUTY, 0x00); eve_write16(REG_GPIOX, 0x0000); - eve_write16(REG_GPIOX_DIR, 0x8000 | (gpio_dir & 0x0f)); + eve_write16(REG_GPIOX_DIR, 0x8000); /* initialize display */ eve_write16(REG_HCYCLE, EVE_HCYCLE); /* total number of clocks per line, incl front/back porch */ @@ -361,7 +363,8 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { /* do not set PCLK yet - wait for just after the first display list */ /* disable audio */ - eve_write16(REG_SOUND, 0x0000); /* set synthesizer to silence */ + eve_write16(REG_SOUND, 0x0060); /* set synthesizer to mute */ + eve_write8(REG_PLAY, 0x01); eve_write8(REG_VOL_SOUND, 0x00); /* turn synthesizer volume off */ eve_write8(REG_VOL_PB, 0x00); /* turn recorded audio volume off */ @@ -381,21 +384,16 @@ int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { #endif /* nothing is being displayed yet... the pixel clock is still 0x00 */ - eve_touch_init(touch_calibrate, touch_matrix); return EVE_OK; } void eve_start(void) { - eve_touch_start(); - /* enable interrupts */ eve_write8(REG_INT_EN, 0x01); while(eve_read8(REG_INT_FLAGS)); } void eve_stop(void) { - eve_touch_stop(); - /* disable interrupts */ eve_write8(REG_INT_EN, 0x00); while(eve_read8(REG_INT_FLAGS)); @@ -417,12 +415,12 @@ void eve_stop_clk(void) { eve_write8(REG_PCLK, 0); } -void eve_active(void) { +void eve_activate(void) { eve_command(EVE_ACTIVE, 0); - eve_time_sleep(40); + eve_sleep(40); } -void eve_standby(void) { +void eve_pwr_standby(void) { if (power_state != EVE_PSTATE_ACTIVE) return; eve_command(EVE_STANDBY, 0); @@ -430,7 +428,7 @@ void eve_standby(void) { power_state = EVE_PSTATE_STANDBY; } -void eve_sleep(void) { +void eve_pwr_sleep(void) { if (power_state != EVE_PSTATE_ACTIVE) return; eve_stop_clk(); @@ -441,8 +439,8 @@ void eve_sleep(void) { power_state = EVE_PSTATE_SLEEP; } -void eve_wake(void) { - eve_active(); +void eve_pwr_wake(void) { + eve_activate(); if (power_state == EVE_PSTATE_SLEEP) { eve_start(); @@ -452,10 +450,6 @@ void eve_wake(void) { power_state = EVE_PSTATE_ACTIVE; } -void eve_brightness(uint8_t b) { - eve_write8(REG_PWM_DUTY, b); -} - int eve_gpio_get(int gpio) { uint16_t reg = eve_read16(REG_GPIOX); @@ -483,3 +477,12 @@ void eve_gpio_set_dir(uint8_t dir) { reg |= dir & 0x0f; eve_write16(REG_GPIOX_DIR, reg); } + +void eve_brightness(uint8_t b) { + if (lcd_absent) b = 0; + eve_write8(REG_PWM_DUTY, b); +} + +void eve_lcd_absent(void) { + lcd_absent = 1; +} diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index 02fa697..c1b91e4 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -58,19 +58,21 @@ void eve_cmd_burst_end(void); void eve_handle_intr(void); -int eve_init(uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix); +int eve_init(void); void eve_start(void); void eve_stop(void); void eve_start_clk(void); void eve_stop_clk(void); -void eve_active(void); -void eve_standby(void); -void eve_sleep(void); -void eve_wake(void); +void eve_activate(void); +void eve_pwr_standby(void); +void eve_pwr_sleep(void); +void eve_pwr_wake(void); int eve_gpio_get(int gpio); void eve_gpio_set(int gpio, int val); uint8_t eve_gpio_get_dir(void); void eve_gpio_set_dir(uint8_t dir); + void eve_brightness(uint8_t b); +void eve_lcd_absent(void);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/eve_def.h b/fw/fe310/eos/eve/eve_def.h index 2f7e0b7..b7110b9 100755 --- a/fw/fe310/eos/eve/eve_def.h +++ b/fw/fe310/eos/eve/eve_def.h @@ -697,6 +697,10 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #define REG_PLAY_CONTROL 0x30914eUL
#define REG_COPRO_PATCH_PTR 0x309162UL
+#define REG_EHOST_TOUCH_X 0x30210cUL
+#define REG_EHOST_TOUCH_Y 0x302118UL
+#define REG_EHOST_TOUCH_ID 0x302114UL
+#define REG_EHOST_TOUCH_ACK 0x302170UL
/* BT81x graphics engine specific macros */
#define BITMAP_EXT_FORMAT(format) ((46UL<<24)|(((format)&65535UL)<<0))
diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c deleted file mode 100644 index 2e13cd2..0000000 --- a/fw/fe310/eos/eve/eve_eos.c +++ /dev/null @@ -1,104 +0,0 @@ -#include <stdlib.h> - -#include "platform.h" - -#include "eos.h" -#include "interrupt.h" -#include "event.h" -#include "pwr.h" - -#include "board.h" - -#include "eve.h" -#include "eve_eos.h" - -static int _run; - -static void handle_time(unsigned char type) { - if (_run) { - eve_spi_start(); - eve_handle_time(); - eve_spi_stop(); - } -} - -static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { - if (_run) { - eve_spi_start(); - eve_handle_intr(); - eve_spi_stop(); - - GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); - } -} - -static void handle_intr(void) { - GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); - GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR); - eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INTR, NULL, 0); -} - - -static void _start(void) { - eve_start(); - - GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR); - GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR); - - GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR); - - eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR); - _run = 1; -} - -static void _stop(void) { - _run = 0; - eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR); - - GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR); - - eve_stop(); -} - -int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) { - int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - int rv = EVE_OK; - - eve_spi_start(); - if (rst) { - rv = eve_init(gpio_dir, touch_calibrate, touch_matrix); - } else { - eve_active(); - } - eve_spi_stop(); - - if (rv) return EOS_ERR; - - eos_evtq_set_handler(EOS_EVT_UI, handle_evt); - eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time); - eos_intr_set(INT_GPIO_BASE + EVE_PIN_INTR, IRQ_PRIORITY_UI, handle_intr); - eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR); - - return EOS_OK; -} - -int eos_eve_run(uint8_t wakeup_cause) { - eve_spi_start(); - _start(); - eve_start_clk(); - eve_spi_stop(); - - return EOS_OK; -} - -void eos_eve_start(void) { - eve_spi_start(); - _start(); - eve_spi_stop(); -} - -void eos_eve_stop(void) { - eve_spi_start(); - _stop(); - eve_spi_stop(); -} diff --git a/fw/fe310/eos/eve/eve_eos.h b/fw/fe310/eos/eve/eve_eos.h deleted file mode 100644 index 80eea86..0000000 --- a/fw/fe310/eos/eve/eve_eos.h +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdint.h> - -int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix); -int eos_eve_run(uint8_t wakeup_cause); -void eos_eve_start(void); -void eos_eve_stop(void); diff --git a/fw/fe310/eos/eve/eve_phy.c b/fw/fe310/eos/eve/eve_phy.c index 1e255fe..cfddc80 100644 --- a/fw/fe310/eos/eve/eve_phy.c +++ b/fw/fe310/eos/eve/eve_phy.c @@ -9,30 +9,44 @@ void eve_phy_acc_init(EVEPhyAcc *param, int a) { param->a = a; } -void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y) { - double v0 = sqrt(v0x * v0x + v0y * v0y); +int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y) { + double v0; + uint32_t dt = eve_get_tick() - t0; + v0 = sqrt(v0x * v0x + v0y * v0y); + param->k = 2 * v0 / param->a * EVE_RTC_FREQ; + if ((param->k < 0) && (dt >= -param->k / 2)) { + return 0; + } param->x0 = x0; param->y0 = y0; param->v0x = v0x; param->v0y = v0y; - param->k = 2 * v0 / param->a * EVE_RTC_FREQ; + + return 1; } -int eve_phy_acc_tick(EVEPhyAcc *param, int dt, int *x, int *y) { +int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y) { int k = param->k; int x0 = param->x0; int y0 = param->y0; int v0x = param->v0x; int v0y = param->v0y; + int _dt = dt; int more = 1; + if (k == 0) { + if (x) *x = x0; + if (y) *y = y0; + return 0; + } + if ((k < 0) && (dt >= -k / 2)) { dt = -k / 2; more = 0; } - if (x) *x = x0 + (v0x * dt + v0x * dt / k * dt) / (int)(EVE_RTC_FREQ); - if (y) *y = y0 + (v0y * dt + v0y * dt / k * dt) / (int)(EVE_RTC_FREQ); + if (x) *x = x0 + (v0x * _dt + v0x * _dt / k * _dt) / EVE_RTC_FREQ; + if (y) *y = y0 + (v0y * _dt + v0y * _dt / k * _dt) / EVE_RTC_FREQ; return more; } @@ -53,9 +67,11 @@ void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0) { param->x0 = x0; param->y0 = y0; + + return 1; } -int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y) { +int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y) { int ax = param->x0 - param->x; int ay = param->y0 - param->y; int more = 1; diff --git a/fw/fe310/eos/eve/eve_phy.h b/fw/fe310/eos/eve/eve_phy.h index 1be5fd0..e747b44 100644 --- a/fw/fe310/eos/eve/eve_phy.h +++ b/fw/fe310/eos/eve/eve_phy.h @@ -10,8 +10,8 @@ typedef struct EVEPhyAcc { } EVEPhyAcc; void eve_phy_acc_init(EVEPhyAcc *param, int a); -void eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, int v0x, int v0y); -int eve_phy_acc_tick(EVEPhyAcc *param, int dt, int *x, int *y); +int eve_phy_acc_start(EVEPhyAcc *param, int x0, int y0, uint32_t t0, int v0x, int v0y); +int eve_phy_acc_tick(EVEPhyAcc *param, uint32_t dt, int *x, int *y); typedef struct EVEPhyLHO { int x; @@ -25,4 +25,4 @@ typedef struct EVEPhyLHO { void eve_phy_lho_init(EVEPhyLHO *param, int x, int y, uint32_t T, double d, uint32_t t_max); int eve_phy_lho_start(EVEPhyLHO *param, int x0, int y0); -int eve_phy_lho_tick(EVEPhyLHO *param, int dt, int *x, int *y);
\ No newline at end of file +int eve_phy_lho_tick(EVEPhyLHO *param, uint32_t dt, int *x, int *y);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c index 4450412..f0fc399 100644 --- a/fw/fe310/eos/eve/eve_platform.c +++ b/fw/fe310/eos/eve/eve_platform.c @@ -17,19 +17,19 @@ void eve_free(void *p) { free(p); } -void eve_timer_set(uint32_t ms) { - eos_timer_set(ms, EOS_TIMER_ETYPE_UI); +void eve_sleep(uint32_t ms) { + eos_time_sleep(ms); } -void eve_time_sleep(uint32_t ms) { - eos_time_sleep(ms); +uint32_t eve_get_tick(void) { + return (uint32_t)eos_time_get_tick(); } -uint64_t eve_time_get_tick(void) { - return eos_time_get_tick(); +void eve_sys_timer_set(uint32_t ms) { + eos_timer_set(EOS_TIMER_ETYPE_UI, ms); } -void eve_timer_clear(void) { +void eve_sys_timer_clear(void) { eos_timer_clear(EOS_TIMER_ETYPE_UI); } diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h index 77afffc..29240d5 100644 --- a/fw/fe310/eos/eve/eve_platform.h +++ b/fw/fe310/eos/eve/eve_platform.h @@ -1,9 +1,9 @@ #include <stdint.h> #include <stdlib.h> -#include "timer.h" -#include "spi.h" -#include "spi_dev.h" +#include "../soc/timer.h" +#include "../soc/spi.h" +#include "../dev/spi.h" #define EVE_ETYPE_INTR 1 @@ -31,7 +31,7 @@ void eve_spi_stop(void); #define eve_spi_lock eos_spi_lock #define eve_spi_unlock eos_spi_unlock -void eve_time_sleep(uint32_t ms); -uint64_t eve_time_get_tick(void); -void eve_timer_set(uint32_t ms); -void eve_timer_clear(void); +void eve_sleep(uint32_t ms); +uint32_t eve_get_tick(void); +void eve_sys_timer_set(uint32_t ms); +void eve_sys_timer_clear(void); diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index 7c06f81..d17a509 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -1,10 +1,9 @@ #include <stdlib.h> #include <string.h> -#include <math.h> #include "eve.h" +#include "eve_touch_engine.h" -static int touch_multi; static uint8_t touch_tag0; static EVETouch touch_obj[EVE_MAX_TOUCH]; @@ -14,235 +13,222 @@ static eve_touch_handler_t touch_handler; static void *touch_handler_param; static uint8_t touch_tag_opt[256]; -static const uint32_t _reg_touch[] = { - REG_CTOUCH_TOUCH0_XY, - REG_CTOUCH_TOUCH1_XY, - REG_CTOUCH_TOUCH2_XY, - REG_CTOUCH_TOUCH3_XY -}; - -static const uint32_t _reg_tag[] = { - REG_TOUCH_TAG, - REG_TOUCH_TAG1, - REG_TOUCH_TAG2, - REG_TOUCH_TAG3, - REG_TOUCH_TAG4 -}; - -static const uint32_t _reg_track[] = { - REG_TRACKER, - REG_TRACKER_1, - REG_TRACKER_2, - REG_TRACKER_3, - REG_TRACKER_4 -}; +void eve_touch_init(void) { + int i; + + touch_tag0 = 0; + memset(&touch_timer, 0, sizeof(touch_timer)); + for (i=0; i<EVE_MAX_TOUCH; i++) { + EVETouch *touch = &touch_obj[i]; + + memset(&touch_obj[i], 0, sizeof(EVETouch)); + touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; + } + eve_vtrack_init(); +} void eve_handle_touch(uint16_t intr_flags) { int i; - char touch_ex = 0; - char int_ccomplete = 0; - uint16_t intr_mask; - - intr_mask = eve_read16(REG_INT_MASK); - if (!touch_multi && (intr_flags & EVE_INT_TOUCH)) touch_multi = 1; for (i=0; i<EVE_MAX_TOUCH; i++) { - uint8_t touch_tag; - uint32_t touch_xy; - uint64_t now = 0; + uint32_t now = 0; uint16_t touch_evt = 0; EVETouch *touch = &touch_obj[i]; - touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y)); - - if (touch_xy != EVE_NOTOUCH) { - int16_t touch_x = touch_xy >> 16; - int16_t touch_y = touch_xy & 0xffff; - now = eve_time_get_tick(); - if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) { - uint16_t _evt = 0; - uint16_t _eevt = 0; - uint16_t _ttevt = eve_touch_timer_get_evt(touch); - - if (_ttevt) { - touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH; + now = eve_get_tick(); + + if (intr_flags & EVE_INT_CONVCOMPLETE) { + uint32_t touch_xy = eve_touch_reg_xy(i); + uint16_t timer_evt; + + if (touch_xy != EVE_NOTOUCH) { + int16_t touch_x = touch_xy >> 16; + int16_t touch_y = touch_xy & 0xffff; + int check_track, check_timer; + + if (touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH) { + uint16_t _evt = 0; + uint16_t _eevt = 0; + + timer_evt = eve_timer_get_evt(touch); + if (timer_evt) { + uint16_t _touch_evt = 0; + + touch->eevt &= ~EVE_TOUCH_EETYPE_NOTOUCH; + if (timer_evt & EVE_TOUCH_ETYPE_TAP2) { + int dx = touch_x - touch->x0; + int dy = touch_y - touch->y0; + + dx = dx < 0 ? -dx : dx; + dy = dy < 0 ? -dy : dy; + if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) { + _touch_evt |= EVE_TOUCH_ETYPE_TAP1; + } else { + _evt |= EVE_TOUCH_ETYPE_TAP2; + _eevt |= EVE_TOUCH_EETYPE_TAP2; + } + } + if (timer_evt & EVE_TOUCH_ETYPE_TRACK) { + EVEVTrack *vtrack = eve_vtrack_get(); - if (_ttevt & EVE_TOUCH_ETYPE_TAP2) { - int dx = touch_x - touch->x0; - int dy = touch_y - touch->y0; + _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT; + _touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT); + if (vtrack->stop) vtrack->stop(touch, vtrack->param); + } + if (timer_evt & EVE_TOUCH_ETYPE_TIMER) { + _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT; + _touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT; + } - dx = dx < 0 ? -dx : dx; - dy = dy < 0 ? -dy : dy; - if ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y)) { - touch_evt |= EVE_TOUCH_ETYPE_TAP1; - } else { - _evt |= EVE_TOUCH_ETYPE_TAP2; - _eevt |= EVE_TOUCH_EETYPE_TAP2; + eve_timer_clear(touch); + if (touch_handler && _touch_evt) { + touch_handler(touch_timer.touch, _touch_evt, touch_timer.tag0, touch_handler_param); } } - if (_ttevt & EVE_TOUCH_ETYPE_TRACK) { - EVEVTrack *vtrack = eve_vtrack_get(); - - _eevt |= EVE_TOUCH_EETYPE_TRACK_ABORT; - touch_evt |= (EVE_TOUCH_ETYPE_TRACK_STOP | EVE_TOUCH_ETYPE_TRACK_ABORT); - if (vtrack->stop) vtrack->stop(touch, vtrack->param); + touch_evt |= EVE_TOUCH_ETYPE_POINT | _evt; + touch->eevt = _eevt; + touch->tag0 = 0; + touch->tag = 0; + touch->tag_up = 0; + touch->tracker.tag = 0; + touch->tracker.track = 0; + touch->tracker.val = 0; + touch->t = 0; + touch->vx = 0; + touch->vy = 0; + touch->x0 = touch_x; + touch->y0 = touch_y; + } else if (touch->tracker.track) { + uint32_t dt = now - touch->t; + int vx = ((int)touch_x - touch->x) * EVE_RTC_FREQ / (int)dt; + int vy = ((int)touch_y - touch->y) * EVE_RTC_FREQ / (int)dt; + + touch->vx = vx; + touch->vy = vy; + touch->t = now; + } + touch->x = touch_x; + touch->y = touch_y; + + timer_evt = eve_timer_get_evt(touch); + check_track = touch->tracker.tag && !touch->tracker.track; + check_timer = timer_evt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2); + + if (check_track || check_timer) { + int dx = touch->x - touch->x0; + int dy = touch->y - touch->y0; + + dx = dx < 0 ? -dx : dx; + dy = dy < 0 ? -dy : dy; + if (check_track) { + if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) { + touch->tracker.tag = 0; + } + if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) { + touch->tracker.tag = 0; + } + if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { + int track_x = 0; + + if ((dx > EVE_TOUCH_THRESHOLD_X) && (dx > EVE_TOUCH_THRESHOLD_Y) && ((touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY) == EVE_TOUCH_OPT_TRACK_XY)) { + if (dx > dy) { + track_x = 1; + } + } else if (dx > EVE_TOUCH_THRESHOLD_X) { + track_x = 1; + } + if (track_x) { + touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + } else { + touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; + } + touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->tracker.track = 1; + touch->t = now; + } } - if (_ttevt & EVE_TOUCH_ETYPE_TIMER) { - _eevt |= EVE_TOUCH_EETYPE_TIMER_ABORT; - touch_evt |= EVE_TOUCH_ETYPE_TIMER_ABORT; + if (check_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { + eve_timer_set_evt(touch, timer_evt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2)); } - - eve_touch_timer_clear(touch); - if (touch_handler && touch_evt) { - touch_handler(touch_timer.touch, touch_evt, touch_timer.tag0, touch_handler_param); - } - } - touch_evt = EVE_TOUCH_ETYPE_POINT | _evt; - touch->eevt = _eevt; - touch->tag0 = 0; - touch->tag = 0; - touch->tag_up = 0; - touch->tracker.tag = 0; - touch->tracker.track = 0; - touch->tracker.val = 0; - touch->t = 0; - touch->vx = 0; - touch->vy = 0; - touch->x0 = touch_x; - touch->y0 = touch_y; - } else if (touch->t) { - int dt = now - touch->t; - int vx = ((int)touch_x - touch->x) * (int)(EVE_RTC_FREQ) / dt; - int vy = ((int)touch_y - touch->y) * (int)(EVE_RTC_FREQ) / dt; - touch->vx = touch->vx ? (vx + touch->vx * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vx; - touch->vy = touch->vy ? (vy + touch->vy * EVE_TOUCH_TRAVG) / (EVE_TOUCH_TRAVG + 1) : vy; - touch->t = now; - } - touch->x = touch_x; - touch->y = touch_y; - if (touch_multi || (intr_flags & EVE_INT_TAG)) { - touch_tag = eve_read8(_reg_tag[i]); - } else { - touch_tag = touch->tag; - } - touch_ex = 1; - } else { - touch_tag = 0; - if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) { - uint16_t _ttevt = eve_touch_timer_get_evt(touch); - - touch_evt = EVE_TOUCH_ETYPE_POINT_UP; - touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; - if (_ttevt & EVE_TOUCH_ETYPE_LPRESS) { - eve_touch_timer_set_evt(touch, _ttevt & ~EVE_TOUCH_ETYPE_LPRESS); } if (touch->tracker.tag && touch->tracker.track) { - uint8_t opt = touch_tag_opt[touch->tracker.tag]; - char track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) || - ((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)); - if (!eve_touch_timer_get_evt(NULL) && track_ext) { - EVEVTrack *vtrack = eve_vtrack_get(); - - eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); - if (vtrack->start) vtrack->start(touch, vtrack->param); + if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK; + if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG; + } + if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) { + uint32_t touch_track = eve_touch_reg_track(i); + + if (touch->tracker.tag == (touch_track & 0xff)) { + touch->tracker.val = touch_track >> 16; } else { - touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; + touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG; } } - } - } - if (touch_tag != touch->tag) { - if (touch_tag) { - if (!touch_tag0) touch_tag0 = touch_tag; - if (!touch->tag0) { - touch->tag0 = touch_tag; - if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) { - touch->tracker.tag = touch_tag; - } - if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { - touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->tracker.track = 1; - touch->t = now; + } else { + if (!(touch->eevt & EVE_TOUCH_EETYPE_NOTOUCH)) { + touch_evt |= EVE_TOUCH_ETYPE_POINT_UP; + touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; + + timer_evt = eve_timer_get_evt(touch); + if (timer_evt & EVE_TOUCH_ETYPE_LPRESS) { + eve_timer_set_evt(touch, timer_evt & ~EVE_TOUCH_ETYPE_LPRESS); } - if (!eve_touch_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) { - uint16_t _evt = 0; + if (touch->tracker.tag && touch->tracker.track) { + int start = 0; + uint8_t opt = touch_tag_opt[touch->tracker.tag]; + uint8_t track_ext = ((opt & EVE_TOUCH_OPT_TRACK_EXT_X) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X)) || + ((opt & EVE_TOUCH_OPT_TRACK_EXT_Y) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y)); + + if (!eve_timer_get_evt(NULL) && track_ext) { + EVEVTrack *vtrack = eve_vtrack_get(); - if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; - if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2; - eve_touch_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP); + if (vtrack->start) start = vtrack->start(touch, vtrack->param); + } + if (start) { + eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, touch_tag0, EVE_TOUCH_TIMEOUT_TRACK); + } else { + touch_evt |= EVE_TOUCH_ETYPE_TRACK_STOP; + } } } } - touch->tag_up = touch->tag; - if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP; - touch->tag = touch_tag; - if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG; } - if (touch_xy != EVE_NOTOUCH) { - uint16_t _ttevt = eve_touch_timer_get_evt(touch); - int _track = touch->tracker.tag && !touch->tracker.track; - int _timer = _ttevt & (EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2); - if (_track || _timer) { - int dx = touch->x - touch->x0; - int dy = touch->y - touch->y0; - dx = dx < 0 ? -dx : dx; - dy = dy < 0 ? -dy : dy; - if (_track) { - if ((dx > EVE_TOUCH_THRESHOLD_X) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_X)) { - touch->tracker.tag = 0; - } - if ((dy > EVE_TOUCH_THRESHOLD_Y) && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_Y)) { - touch->tracker.tag = 0; - } - if (touch->tracker.tag && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - if (dx > EVE_TOUCH_THRESHOLD_X) { - touch->eevt |= touch->x > touch->x0 ? EVE_TOUCH_EETYPE_TRACK_RIGHT : EVE_TOUCH_EETYPE_TRACK_LEFT; + + if (intr_flags & EVE_INT_TAG) { + uint8_t touch_tag = eve_touch_reg_tag(i); + + if (touch_tag != touch->tag) { + if (touch_tag) { + if (!touch_tag0) touch_tag0 = touch_tag; + if (!touch->tag0) { + touch->tag0 = touch_tag; + if (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_REG)) { + touch->tracker.tag = touch_tag; } - if (dy > EVE_TOUCH_THRESHOLD_Y) { - touch->eevt |= touch->y > touch->y0 ? EVE_TOUCH_EETYPE_TRACK_DOWN : EVE_TOUCH_EETYPE_TRACK_UP; + if (touch->tracker.tag && !(touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_XY)) { + touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; + touch->tracker.track = 1; + touch->t = now; + } + if (!eve_timer_get_evt(NULL) && (touch_tag_opt[touch_tag] & (EVE_TOUCH_OPT_LPRESS | EVE_TOUCH_OPT_TAP2))) { + uint16_t _evt = 0; + + if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_LPRESS) _evt |= EVE_TOUCH_ETYPE_LPRESS; + if (touch_tag_opt[touch_tag] & EVE_TOUCH_OPT_TAP2) _evt |= EVE_TOUCH_ETYPE_TAP2; + eve_timer_set(touch, _evt, touch_tag0, EVE_TOUCH_TIMEOUT_TAP); } - touch_evt |= EVE_TOUCH_ETYPE_TRACK_START; - touch->tracker.track = 1; - touch->t = now; } } - if (_timer && ((dx > EVE_TOUCH_THRESHOLD_X) || (dy > EVE_TOUCH_THRESHOLD_Y))) { - eve_touch_timer_set_evt(touch, _ttevt & ~(EVE_TOUCH_ETYPE_LPRESS | EVE_TOUCH_ETYPE_TAP2)); - _timer = 0; - } + touch->tag_up = touch->tag; + if (touch->tag_up) touch_evt |= EVE_TOUCH_ETYPE_TAG_UP; + touch->tag = touch_tag; + if (touch->tag) touch_evt |= EVE_TOUCH_ETYPE_TAG; } - if (touch->tracker.tag && touch->tracker.track) { - if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK) touch_evt |= EVE_TOUCH_ETYPE_TRACK; - if (touch_tag_opt[touch->tracker.tag] & EVE_TOUCH_OPT_TRACK_REG) touch_evt |= EVE_TOUCH_ETYPE_TRACK_REG; - } - if (touch_evt & EVE_TOUCH_ETYPE_TRACK_REG) { - uint32_t touch_track = eve_read32(_reg_track[i]); - if (touch->tracker.tag == (touch_track & 0xff)) { - touch->tracker.val = touch_track >> 16; - } else { - touch_evt &= ~EVE_TOUCH_ETYPE_TRACK_REG; - } - } - if (touch->tracker.tag || _timer) int_ccomplete = 1; } + if (touch_handler && touch_evt) { touch_handler(touch, touch_evt, touch_tag0, touch_handler_param); } - if (!touch_multi) break; - } - - if (!touch_ex) { - touch_tag0 = 0; - touch_multi = 0; - } - - if (touch_multi) int_ccomplete = 1; - - if (int_ccomplete && !(intr_mask & EVE_INT_CONVCOMPLETE)) { - eve_write16(REG_INT_MASK, intr_mask | EVE_INT_CONVCOMPLETE); - } - if (!int_ccomplete && (intr_mask & EVE_INT_CONVCOMPLETE)) { - eve_write16(REG_INT_MASK, intr_mask & ~EVE_INT_CONVCOMPLETE); } } @@ -278,7 +264,7 @@ void eve_handle_time(void) { } if (more) { - eve_timer_set(touch_timer.to); + eve_sys_timer_set(touch_timer.to); } else { touch_timer.evt = 0; } @@ -289,74 +275,12 @@ void eve_handle_time(void) { } } -void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix) { - /* configure touch */ - eve_write8(REG_CPURESET, 2); /* touch engine reset */ - eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */ - eve_write8(REG_CPURESET, 0); /* clear reset */ - - if (touch_calibrate) { - eve_write8(REG_PWM_DUTY, 0x40); - eve_cmd(CMD_TEXT, "hhhhs", EVE_HSIZE/2, EVE_VSIZE/2, 27, EVE_OPT_CENTER, "Please tap on the dot."); - eve_cmd(CMD_CALIBRATE, "w", 0); - eve_cmd_exec(1); - eve_write8(REG_PWM_DUTY, 0); - - touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); - touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); - touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); - touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); - touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); - touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); - } else { - eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]); - eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]); - eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]); - eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]); - eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]); - eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); - } - - eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ -} - -void eve_touch_start(void) { - uint16_t intr_mask; - int i; - - touch_multi = 0; - touch_tag0 = 0; - memset(&touch_timer, 0, sizeof(touch_timer)); - for (i=0; i<EVE_MAX_TOUCH; i++) { - EVETouch *touch = &touch_obj[i]; - - memset(&touch_obj[i], 0, sizeof(EVETouch)); - touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; - } - eve_vtrack_init(); - - intr_mask = eve_read16(REG_INT_MASK); - eve_write16(REG_INT_MASK, intr_mask | EVE_INT_TAG | EVE_INT_TOUCH); - - eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); -} - -void eve_touch_stop(void) { - uint16_t intr_mask; - - intr_mask = eve_read16(REG_INT_MASK); - eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_TAG | EVE_INT_TOUCH | EVE_INT_CONVCOMPLETE)); - eve_touch_timer_clear(touch_timer.touch); - - eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); -} - void eve_touch_set_handler(eve_touch_handler_t handler, void *param) { touch_handler = handler; touch_handler_param = param; } -EVETouch *eve_touch_get(int i) { +EVETouch *eve_touch_get_obj(int i) { return &touch_obj[i]; } @@ -411,46 +335,59 @@ void eve_touch_clear_opt(void) { memset(touch_tag_opt, 0, sizeof(touch_tag_opt)); } -void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) { +void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to) { touch_timer.touch = touch; touch_timer.evt = evt; touch_timer.tag0 = tag0; touch_timer.to = to; - eve_timer_set(to); + eve_sys_timer_set(to); +} + +void eve_timer_clear(EVETouch *touch) { + eve_timer_set_evt(touch, 0); } -void eve_touch_timer_clear(EVETouch *touch) { - eve_touch_timer_set_evt(touch, 0); +void eve_timer_set_evt(EVETouch *touch, uint16_t evt) { + if ((touch == NULL) || (touch == touch_timer.touch)) { + touch_timer.evt = evt; + } else if (touch_timer.touch == NULL) { + touch_timer.evt = evt; + } + if (!touch_timer.evt) { + eve_sys_timer_clear(); + touch_timer.touch = NULL; + touch_timer.tag0 = 0; + touch_timer.to = 0; + } } -uint16_t eve_touch_timer_get_evt(EVETouch *touch) { +uint16_t eve_timer_get_evt(EVETouch *touch) { uint16_t ret = 0; if ((touch == NULL) || (touch_timer.touch == touch)) { ret = touch_timer.evt; } else if (touch_timer.touch == NULL) { - ret = touch_timer.evt & EVE_TOUCH_ETYPE_TIMER; + ret = touch_timer.evt; } return ret; } -void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt) { - if (touch == touch_timer.touch) { - touch_timer.evt = evt; - } else if (touch_timer.touch == NULL) { - touch_timer.evt = evt & EVE_TOUCH_ETYPE_TIMER; - } - if (!touch_timer.evt) eve_timer_clear(); +EVETouchTimer *eve_timer_get_obj(void) { + return &touch_timer; } -void eve_touch_timer_start(uint8_t tag0, uint32_t to) { - eve_touch_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to); +void eve_timer_start(uint8_t tag0, uint32_t to) { + if (!touch_timer.evt) eve_timer_set(NULL, EVE_TOUCH_ETYPE_TIMER, tag0, to); } -void eve_touch_timer_stop(void) { - eve_touch_timer_clear(NULL); +void eve_timer_stop(void) { + if (touch_timer.touch == NULL) eve_timer_clear(NULL); } -EVETouchTimer *eve_touch_timer_get(void) { - return &touch_timer; +int eve_timer_running(void) { + return (touch_timer.evt == EVE_TOUCH_ETYPE_TIMER); +} + +void eve_touch_clear_tag0(void) { + touch_tag0 = 0; } diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h index b10fde2..8ec6e0e 100644 --- a/fw/fe310/eos/eve/eve_touch.h +++ b/fw/fe310/eos/eve/eve_touch.h @@ -5,7 +5,6 @@ #define EVE_TOUCH_THRESHOLD_X 5 #define EVE_TOUCH_THRESHOLD_Y 5 -#define EVE_TOUCH_TRAVG 3 #define EVE_NOTAG 0 #define EVE_NOTOUCH 0x80008000 @@ -77,7 +76,7 @@ typedef struct EVETouch { int vy; int x0; int y0; - uint64_t t; + uint32_t t; uint16_t eevt; uint8_t tag0; uint8_t tag; @@ -98,15 +97,12 @@ typedef struct EVETouchTimer { typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *); +void eve_touch_init(void); void eve_handle_touch(uint16_t intr_flags); void eve_handle_time(void); -void eve_touch_init(int touch_calibrate, uint32_t *touch_matrix); -void eve_touch_start(void); -void eve_touch_stop(void); - void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); -EVETouch *eve_touch_get(int i); +EVETouch *eve_touch_get_obj(int i); int8_t eve_touch_get_idx(EVETouch *touch); uint16_t eve_touch_evt(EVETouch *touch, uint16_t evt, uint8_t tag0, uint8_t tag_min, uint8_t tag_n); @@ -114,11 +110,13 @@ void eve_touch_set_opt(uint8_t tag, uint8_t opt); uint8_t eve_touch_get_opt(uint8_t tag); void eve_touch_clear_opt(void); -void eve_touch_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to); -void eve_touch_timer_clear(EVETouch *touch); -uint16_t eve_touch_timer_get_evt(EVETouch *touch); -void eve_touch_timer_set_evt(EVETouch *touch, uint16_t evt); -void eve_touch_timer_start(uint8_t tag0, uint32_t to); -void eve_touch_timer_stop(void); +void eve_timer_set(EVETouch *touch, uint16_t evt, uint8_t tag0, uint32_t to); +void eve_timer_clear(EVETouch *touch); +void eve_timer_set_evt(EVETouch *touch, uint16_t evt); +uint16_t eve_timer_get_evt(EVETouch *touch); +EVETouchTimer *eve_timer_get_obj(void); -EVETouchTimer *eve_touch_timer_get(void); +void eve_timer_start(uint8_t tag0, uint32_t to); +void eve_timer_stop(void); +int eve_timer_running(void); +void eve_touch_clear_tag0(void); diff --git a/fw/fe310/eos/eve/eve_touch_engine.c b/fw/fe310/eos/eve/eve_touch_engine.c new file mode 100644 index 0000000..2c75ca0 --- /dev/null +++ b/fw/fe310/eos/eve/eve_touch_engine.c @@ -0,0 +1,119 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_touch_engine.h" + +static const uint32_t _reg_touch[] = { + REG_CTOUCH_TOUCH0_XY, + REG_CTOUCH_TOUCH1_XY, + REG_CTOUCH_TOUCH2_XY, + REG_CTOUCH_TOUCH3_XY +}; + +static const uint32_t _reg_tag[] = { + REG_TOUCH_TAG, + REG_TOUCH_TAG1, + REG_TOUCH_TAG2, + REG_TOUCH_TAG3, + REG_TOUCH_TAG4 +}; + +static const uint32_t _reg_track[] = { + REG_TRACKER, + REG_TRACKER_1, + REG_TRACKER_2, + REG_TRACKER_3, + REG_TRACKER_4 +}; + +void eve_touch_init_engine(void) { + /* configure touch */ + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write16(REG_TOUCH_CONFIG, 0x4000); /* host mode multi touch */ + eve_write8(REG_CTOUCH_EXTENDED, 0x00); /* set extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ + + eve_touch_ehost_enter(0, 0x8000, 0x8000); + eve_touch_ehost_end(); +} + +void eve_touch_start(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask | (EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_CONTINUOUS); +} + +void eve_touch_stop(void) { + uint16_t intr_mask; + + intr_mask = eve_read16(REG_INT_MASK); + eve_write16(REG_INT_MASK, intr_mask & ~(EVE_INT_CONVCOMPLETE | EVE_INT_TAG)); + eve_timer_clear(NULL); + + eve_write8(REG_TOUCH_MODE, EVE_TMODE_OFF); +} + +void eve_touch_set_extended(int extended) { + eve_write8(REG_CPURESET, 2); /* touch engine reset */ + eve_write8(REG_CTOUCH_EXTENDED, !extended); /* set / clear extended mode */ + eve_write8(REG_CPURESET, 0); /* clear reset */ +} + +void eve_touch_get_matrix(uint32_t *touch_matrix) { + touch_matrix[0] = eve_read32(REG_TOUCH_TRANSFORM_A); + touch_matrix[1] = eve_read32(REG_TOUCH_TRANSFORM_B); + touch_matrix[2] = eve_read32(REG_TOUCH_TRANSFORM_C); + touch_matrix[3] = eve_read32(REG_TOUCH_TRANSFORM_D); + touch_matrix[4] = eve_read32(REG_TOUCH_TRANSFORM_E); + touch_matrix[5] = eve_read32(REG_TOUCH_TRANSFORM_F); +} + +void eve_touch_set_matrix(const uint32_t *touch_matrix) { + eve_write32(REG_TOUCH_TRANSFORM_A, touch_matrix[0]); + eve_write32(REG_TOUCH_TRANSFORM_B, touch_matrix[1]); + eve_write32(REG_TOUCH_TRANSFORM_C, touch_matrix[2]); + eve_write32(REG_TOUCH_TRANSFORM_D, touch_matrix[3]); + eve_write32(REG_TOUCH_TRANSFORM_E, touch_matrix[4]); + eve_write32(REG_TOUCH_TRANSFORM_F, touch_matrix[5]); +} + +uint32_t eve_touch_reg_xy(int i) { + uint32_t touch_xy; + + touch_xy = i < 4 ? eve_read32(_reg_touch[i]) : (((uint32_t)eve_read16(REG_CTOUCH_TOUCH4_X) << 16) | eve_read16(REG_CTOUCH_TOUCH4_Y)); + return touch_xy; +} + +uint8_t eve_touch_reg_tag(int i) { + uint8_t touch_tag; + + touch_tag = eve_read8(_reg_tag[i]); + return touch_tag; +} + +uint32_t eve_touch_reg_track(int i) { + uint32_t touch_track; + + touch_track = eve_read32(_reg_track[i]); + return touch_track; +} + +int eve_touch_ehost_ready(void) { + uint8_t ack; + + ack = eve_read8(REG_EHOST_TOUCH_ACK); + return (ack == 1); +} + +void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y) { + eve_write16(REG_EHOST_TOUCH_X, x); + eve_write16(REG_EHOST_TOUCH_Y, y); + eve_write8(REG_EHOST_TOUCH_ID, id); +} + +void eve_touch_ehost_end(void) { + eve_write8(REG_EHOST_TOUCH_ID, 0xf); +} diff --git a/fw/fe310/eos/eve/eve_touch_engine.h b/fw/fe310/eos/eve/eve_touch_engine.h new file mode 100644 index 0000000..3a7508f --- /dev/null +++ b/fw/fe310/eos/eve/eve_touch_engine.h @@ -0,0 +1,17 @@ +#include <stdint.h> + +void eve_touch_init_engine(void); +void eve_touch_start(void); +void eve_touch_stop(void); + +void eve_touch_set_extended(int extended); +void eve_touch_get_matrix(uint32_t *touch_matrix); +void eve_touch_set_matrix(const uint32_t *touch_matrix); + +int eve_touch_ehost_ready(void); +void eve_touch_ehost_enter(uint8_t id, uint16_t x, uint16_t y); +void eve_touch_ehost_end(void); + +uint32_t eve_touch_reg_xy(int i); +uint8_t eve_touch_reg_tag(int i); +uint32_t eve_touch_reg_track(int i); diff --git a/fw/fe310/eos/eve/eve_vtrack.c b/fw/fe310/eos/eve/eve_vtrack.c index b9f28af..a7619fb 100644 --- a/fw/fe310/eos/eve/eve_vtrack.c +++ b/fw/fe310/eos/eve/eve_vtrack.c @@ -26,40 +26,31 @@ void eve_vtrack_reset(void) { eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &vtrack_acc); } -void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) { - eve_touch_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); - if (vtrack.start) vtrack.start(touch, vtrack.param); +int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) { + if (vtrack.start) { + int start; + + start = vtrack.start(touch, vtrack.param); + if (start) eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to); + + return start; + } + return 0; } void eve_vtrack_stop(EVETouch *touch) { - eve_touch_timer_clear(touch); + eve_timer_clear(touch); eve_vtrack_reset(); } -void eve_vtrack_acc_start(EVETouch *touch, void *p) { +int eve_vtrack_acc_start(EVETouch *touch, void *p) { EVEPhyAcc *param = (EVEPhyAcc *)p; - eve_phy_acc_start(param, touch->x, touch->y, touch->vx, touch->vy); + + return eve_phy_acc_start(param, touch->x, touch->y, touch->t, touch->vx, touch->vy); } int eve_vtrack_acc_tick(EVETouch *touch, void *p) { EVEPhyAcc *param = (EVEPhyAcc *)p; - return eve_phy_acc_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y); + return eve_phy_acc_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y); } - -void eve_vtrack_lho_start(EVETouch *touch, void *p) { - EVEPhyLHO *param = (EVEPhyLHO *)p; - - eve_phy_lho_start(param, touch->x, touch->y); -} - -int eve_vtrack_lho_tick(EVETouch *touch, void *p) { - EVEPhyLHO *param = (EVEPhyLHO *)p; - - return eve_phy_lho_tick(param, eve_time_get_tick() - touch->t, &touch->x, &touch->y); -} - -void eve_vtrack_lho_stop(EVETouch *touch, void *p) { - eve_vtrack_reset(); -} - diff --git a/fw/fe310/eos/eve/eve_vtrack.h b/fw/fe310/eos/eve/eve_vtrack.h index b75f673..8455502 100644 --- a/fw/fe310/eos/eve/eve_vtrack.h +++ b/fw/fe310/eos/eve/eve_vtrack.h @@ -1,8 +1,8 @@ #include <stdint.h> -#define EVE_VTRACK_ACC_A 1000 +#define EVE_VTRACK_ACC_A 10000 -typedef void (*eve_vtrack_start_t) (EVETouch *, void *); +typedef int (*eve_vtrack_start_t) (EVETouch *, void *); typedef int (*eve_vtrack_tick_t) (EVETouch *, void *); typedef void (*eve_vtrack_stop_t) (EVETouch *, void *); @@ -17,12 +17,8 @@ void eve_vtrack_init(void); EVEVTrack *eve_vtrack_get(void); void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param); void eve_vtrack_reset(void); -void eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to); +int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to); void eve_vtrack_stop(EVETouch *touch); -void eve_vtrack_acc_start(EVETouch *touch, void *p); -int eve_vtrack_acc_tick(EVETouch *touch, void *p); - -void eve_vtrack_lho_start(EVETouch *touch, void *p); -int eve_vtrack_lho_tick(EVETouch *touch, void *p); -void eve_vtrack_lho_stop(EVETouch *touch, void *p); +int eve_vtrack_acc_start(EVETouch *touch, void *p); +int eve_vtrack_acc_tick(EVETouch *touch, void *p);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/screen/form.c b/fw/fe310/eos/eve/screen/form.c index 8555158..13021a0 100644 --- a/fw/fe310/eos/eve/screen/form.c +++ b/fw/fe310/eos/eve/screen/form.c @@ -9,8 +9,6 @@ #include "page.h" #include "form.h" -#include "widget/widgets.h" - #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) @@ -57,7 +55,7 @@ static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { } } -EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec spec[], uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor) { EVEWidget *widgets; EVEWidget *widget; EVELabel *label; @@ -65,17 +63,17 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s int w_size = 0; int i, r; - for (i=0; i<spec_size; i++) { - w_size += eve_widget_size(spec[i].widget.type); - } + if (uievt == NULL) uievt = eve_form_uievt; + if (destructor == NULL) destructor = eve_form_destroy; form = eve_malloc(sizeof(EVEForm)); if (form == NULL) { return NULL; } - if (uievt == NULL) uievt = eve_form_uievt; - if (destructor == NULL) destructor = eve_form_destroy; eve_form_init(form, window, stack, NULL, 0, uievt, action, destructor); + for (i=0; i<spec_size; i++) { + w_size += eve_widget_size(spec[i].widget.type); + } widgets = eve_malloc(w_size); if (widgets == NULL) { eve_free(form); @@ -84,7 +82,7 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s widget = widgets; for (i=0; i<spec_size; i++) { - r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, (EVEPage *)form, &spec[i].widget.spec); + r = eve_widget_create(widget, &spec[i].widget, (EVEPage *)form); if (r) { widgets_destroy(widgets, i); eve_free(widgets); @@ -92,7 +90,6 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s return NULL; } if (spec[i].label.title) { - EVEFont *font = spec[i].label.font ? spec[i].label.font : eve_window_font(window); label = eve_malloc(sizeof(EVELabel)); if (label == NULL) { eve_widget_destroy(widget); @@ -101,15 +98,13 @@ EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec s eve_free(form); return NULL; } - eve_label_init(label, &spec[i].label.g, font, spec[i].label.title); + eve_label_create(label, &spec[i].label, (EVEPage *)form); eve_widget_set_label(widget, label); - if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title); } - if (widget->label && (widget->label->g.w == 0)) eve_font_str_w(label->font, label->title) + EVE_FORM_LABEL_MARGIN; if (widget->g.w == 0) widget->g.w = window->g.w - (widget->label ? widget->label->g.w : 0); widget = eve_widget_next(widget); } - eve_form_update(form, widgets, spec_size); + eve_form_set_widget(form, widgets, spec_size); return form; } @@ -118,11 +113,11 @@ void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWid memset(form, 0, sizeof(EVEForm)); eve_page_init(&form->p, window, stack, NULL, 0, EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_BACK | EVE_PAGE_OPT_TRACK_EXT_Y, eve_page_draw, eve_page_touch, (eve_view_uievt_t)uievt, (eve_page_destructor_t)destructor); form->action = action; - eve_form_update(form, widget, widget_size); + eve_form_set_widget(form, widget, widget_size); } -void eve_form_update(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { - eve_page_update((EVEPage *)form, widget, widget_size); +void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size) { + eve_page_set_widget((EVEPage *)form, widget, widget_size); form_update_g(form, NULL); } @@ -138,25 +133,24 @@ int eve_form_uievt(EVEForm *form, uint16_t evt, void *param) { form_update_g(form, (EVEWidget *)param); break; - case EVE_UIEVT_PAGE_SCROLL_START: + case EVE_UIEVT_GEST_SCROLL_START: break; - case EVE_UIEVT_PAGE_SCROLL_STOP: + case EVE_UIEVT_GEST_SCROLL_STOP: break; - case EVE_UIEVT_PAGE_TRACK_START: + case EVE_UIEVT_GEST_TRACK_START: break; - case EVE_UIEVT_PAGE_TRACK_STOP: { + case EVE_UIEVT_GEST_TRACK_STOP: { EVEUIEvtTouch *touch_p = (EVEUIEvtTouch *)param; - if (touch_p->evt & EVE_TOUCH_ETYPE_TRACK_STOP) { - if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) { - eve_page_close((EVEPage *)form); - return 1; - } - if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) { - if (form->action) form->action(form); - } + + if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT) { + eve_page_close((EVEPage *)form); + return 1; + } + if (touch_p->touch->eevt & EVE_TOUCH_EETYPE_TRACK_LEFT) { + if (form->action) form->action(form); } break; } diff --git a/fw/fe310/eos/eve/screen/form.h b/fw/fe310/eos/eve/screen/form.h index 272b6ed..62e10f7 100644 --- a/fw/fe310/eos/eve/screen/form.h +++ b/fw/fe310/eos/eve/screen/form.h @@ -1,10 +1,10 @@ #include <stdint.h> -#define EVE_FORM_LABEL_MARGIN 10 +#include "../widget/widget.h" struct EVEWidget; -struct EVEWidgetSpec; struct EVEForm; +struct EVEFormSpec; typedef int (*eve_form_uievt_t) (struct EVEForm *, uint16_t, void *); typedef void (*eve_form_action_t) (struct EVEForm *); @@ -15,9 +15,15 @@ typedef struct EVEForm { eve_form_action_t action; } EVEForm; -EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, struct EVEWidgetSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); -void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); -void eve_form_update(EVEForm *form, struct EVEWidget *widget, uint16_t widget_size); +typedef struct EVEFormSpec { + EVELabelSpec label; + EVEWidgetSpec widget; +} EVEFormSpec; + +EVEForm *eve_form_create(EVEWindow *window, EVEViewStack *stack, EVEFormSpec *spec, uint16_t spec_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); +void eve_form_init(EVEForm *form, EVEWindow *window, EVEViewStack *stack, EVEWidget *widget, uint16_t widget_size, eve_form_uievt_t uievt, eve_form_action_t action, eve_form_destructor_t destructor); +void eve_form_set_widget(EVEForm *form, EVEWidget *widget, uint16_t widget_size); void eve_form_destroy(EVEForm *form); int eve_form_uievt(EVEForm *form, uint16_t evt, void *param); + diff --git a/fw/fe310/eos/eve/screen/page.c b/fw/fe310/eos/eve/screen/page.c index 65dd534..64fc473 100644 --- a/fw/fe310/eos/eve/screen/page.c +++ b/fw/fe310/eos/eve/screen/page.c @@ -8,7 +8,6 @@ #include "window.h" #include "page.h" -#include "widget/label.h" #include "widget/widget.h" #define PAGE_TMODE_NONE 0 @@ -21,10 +20,22 @@ void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, EVEWid page->stack = stack; page->opt = opt; page->destructor = destructor; - eve_page_update(page, widget, widget_size); + eve_page_set_widget(page, widget, widget_size); } -void eve_page_update(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { +EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) { + EVEWidget *w = page->widget; + int i; + + if (idx >= page->widget_size) return NULL; + + for (i=0; i<idx; i++) { + w = eve_widget_next(w); + } + return w; +} + +void eve_page_set_widget(EVEPage *page, EVEWidget *widget, uint16_t widget_size) { page->widget = widget; page->widget_size = widget_size; } @@ -45,16 +56,16 @@ void eve_page_close(EVEPage *page) { if (stack->level <= 1) return; - if (page->lho_t0) { - page->lho_t0 = 0; - eve_touch_timer_stop(); + if (eve_timer_running()) { + eve_timer_stop(); } if (eve_window_scroll(window->root, NULL) == window) { eve_window_scroll_stop(window); } - if (destructor) destructor(page); eve_window_kbd_detach(window); + + if (destructor) destructor(page); eve_view_destroy(window, stack); } @@ -93,30 +104,32 @@ int eve_page_rect_visible(EVEPage *page, EVERect *g) { return 0; } -void eve_page_focus(EVEPage *page, EVERect *rect) { - if (rect) { - EVERect g; +void eve_page_rect_set_visible(EVEPage *page, EVERect *rect) { + EVERect g; - eve_window_visible_g(page->v.window, &g); - g.x -= page->v.window->g.x; - g.y -= page->v.window->g.y; + eve_window_visible_g(page->v.window, &g); + g.x -= page->v.window->g.x; + g.y -= page->v.window->g.y; - if (rect->x < page->g.x + g.x) { - page->g.x = rect->x - g.x; - } - if (rect->y < page->g.y + g.y) { - page->g.y = rect->y - g.y; - } - if ((rect->x + rect->w) > (page->g.x + g.x + g.w)) { - page->g.x = (rect->x + rect->w) - (g.x + g.w); - } - if ((rect->y + rect->h) > (page->g.y + g.y + g.h)) { - page->g.y = (rect->y + rect->h) - (g.y + g.h); - } + if (rect->x < page->g.x + g.x) { + page->g.x = rect->x - g.x; } + if (rect->y < page->g.y + g.y) { + page->g.y = rect->y - g.y; + } + if ((rect->x + rect->w) > (page->g.x + g.x + g.w)) { + page->g.x = (rect->x + rect->w) - (g.x + g.w); + } + if ((rect->y + rect->h) > (page->g.y + g.y + g.h)) { + page->g.y = (rect->y + rect->h) - (g.y + g.h); + } +} + +EVEWidget *eve_page_focus(EVEPage *page) { + return page->widget_f; } -void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) { +void eve_page_set_focus(EVEPage *page, EVEWidget *widget, EVERect *rect) { if (page->widget_f != widget) { EVEWindow *window = page->v.window; EVEWidget *widget_f = page->widget_f; @@ -131,67 +144,59 @@ void eve_page_focus_widget(EVEPage *page, EVEWidget *widget, EVERect *rect) { if (kbd) eve_kbd_set_handler(kbd, widget->putc, widget); if (!(widget_f && widget_f->putc)) eve_window_kbd_attach(window); } + if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_OUT, page->widget_f); page->widget_f = widget; + if (page->widget_f) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_FOCUS_IN, page->widget_f); } - if (rect) eve_page_focus(page, rect); + if (rect) eve_page_rect_set_visible(page, rect); } -EVEWidget *eve_page_focus_widget_get(EVEPage *page) { - return page->widget_f; -} - -EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx) { - EVEWidget *w = page->widget; - int i; - - if (idx >= page->widget_size) return NULL; - - for (i=0; i<idx; i++) { - w = eve_widget_next(w); - } - return w; -} +#include <stdio.h> static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0) { EVEView *view = &page->v; EVEWindow *window = view->window; - int scroll, scroll_x, scroll_y; + int scroll_x = 0, scroll_y = 0, scroll; int ret = 0; - scroll_x = page->opt & (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_XY); - if (scroll_x && touch) scroll_x = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_X); - - scroll_y = page->opt & (EVE_PAGE_OPT_SCROLL_Y | EVE_PAGE_OPT_SCROLL_XY); - if (scroll_y && touch) scroll_y = touch->eevt & ((page->opt & EVE_PAGE_OPT_SCROLL_XY) ? EVE_TOUCH_EETYPE_TRACK_XY : EVE_TOUCH_EETYPE_TRACK_Y); + if (touch) { + if ((page->opt & EVE_PAGE_OPT_SCROLL_XY) == EVE_PAGE_OPT_SCROLL_XY) { + scroll_x = scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY); + } else if (page->opt & EVE_PAGE_OPT_SCROLL_X) { + scroll_x = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_X); + } else if (page->opt & EVE_PAGE_OPT_SCROLL_Y) { + scroll_y = (touch->eevt & EVE_TOUCH_EETYPE_TRACK_Y); + } + } scroll = scroll_x || scroll_y; if ((evt & EVE_TOUCH_ETYPE_POINT_UP) && !(touch->eevt & (EVE_TOUCH_EETYPE_TRACK_XY | EVE_TOUCH_EETYPE_ABORT))) { int _ret = 0; - if (page->widget_f) eve_page_focus_widget(page, NULL, NULL); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TOUCH, touch, evt, tag0); + if (page->widget_f) eve_page_set_focus(page, NULL, NULL); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TOUCH, touch, evt, tag0); if (_ret) return _ret; ret = 1; } - /* Scroll start */ + /* Scroll / track start */ if ((evt & EVE_TOUCH_ETYPE_TRACK_START) && !(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) { int _ret = 0; if (scroll) { page->track_mode = PAGE_TMODE_SCROLL; eve_window_scroll_start(window, touch->tracker.tag); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_START, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_START, touch, evt, tag0); } else { page->track_mode = PAGE_TMODE_TRACK; - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TRACK_START, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_START, touch, evt, tag0); } if (_ret) return _ret; ret = 1; } - /* Scroll stop */ + /* Scroll / track stop */ if (((evt & EVE_TOUCH_ETYPE_TRACK_STOP) && !(evt & EVE_TOUCH_ETYPE_TRACK_ABORT)) || ((evt & EVE_TOUCH_ETYPE_POINT_UP) && (touch->eevt & EVE_TOUCH_EETYPE_ABORT) && !(touch->eevt & EVE_TOUCH_EETYPE_TRACK_XY))) { if ((page->track_mode == PAGE_TMODE_SCROLL) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) { @@ -211,23 +216,29 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 eve_window_scroll(window->root, &_tag); - eve_phy_lho_init(lho, lho_x, lho_y, 1000, 0.5, 0); + page->lho_t0 = eve_get_tick(); + eve_phy_lho_init(lho, lho_x, lho_y, 100, 0.5, 0); eve_phy_lho_start(lho, page->g.x, page->g.y); - page->lho_t0 = eve_time_get_tick(); - eve_touch_timer_start(_tag, 20); + eve_timer_start(_tag, 20); } } - if (!page->lho_t0) { + if (!eve_timer_running()) { int _ret = 0; - if (page->track_mode == PAGE_TMODE_SCROLL) { - page->track_mode = PAGE_TMODE_NONE; - eve_window_scroll_stop(window); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); - } else if (!(touch->eevt & EVE_TOUCH_EETYPE_ABORT)) { - page->track_mode = PAGE_TMODE_NONE; - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_TRACK_STOP, touch, evt, tag0); + switch (page->track_mode) { + case PAGE_TMODE_SCROLL: { + page->track_mode = PAGE_TMODE_NONE; + eve_window_scroll_stop(window); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0); + break; + } + + case PAGE_TMODE_TRACK: { + page->track_mode = PAGE_TMODE_NONE; + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_TRACK_STOP, touch, evt, tag0); + break; + } } if (_ret) return _ret; ret = 1; @@ -254,26 +265,26 @@ static int page_touch(EVEPage *page, EVETouch *touch, uint16_t evt, uint8_t tag0 } if ((evt & EVE_TOUCH_ETYPE_TIMER) && (page->opt & EVE_PAGE_OPT_SCROLL_BACK)) { EVEPhyLHO *lho = &page->lho; + int scroll_x = page->opt & EVE_PAGE_OPT_SCROLL_X; + int scroll_y = page->opt & EVE_PAGE_OPT_SCROLL_Y; int x, y, more; - more = eve_phy_lho_tick(lho, eve_time_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL); + more = eve_phy_lho_tick(lho, eve_get_tick() - page->lho_t0, scroll_x ? &x : NULL, scroll_y ? &y : NULL); if (scroll_x) page->g.x = x; if (scroll_y) page->g.y = y; + printf("TIMER: %d\n", y); if (!more) { int _ret = 0; - page->lho_t0 = 0; - eve_touch_timer_stop(); + printf("TIMER STOP!\n"); page->track_mode = PAGE_TMODE_NONE; + eve_timer_stop(); eve_window_scroll_stop(window); - _ret = eve_view_uievt_pusht(view, EVE_UIEVT_PAGE_SCROLL_STOP, touch, evt, tag0); + _ret = eve_view_uievt_push_gest(view, EVE_UIEVT_GEST_SCROLL_STOP, touch, evt, tag0); if (_ret) return _ret; } ret = 1; } - if (evt & EVE_TOUCH_EETYPE_TIMER_ABORT) { - page->lho_t0 = 0; - } } return ret; diff --git a/fw/fe310/eos/eve/screen/page.h b/fw/fe310/eos/eve/screen/page.h index 26c33c5..7aa8c1d 100644 --- a/fw/fe310/eos/eve/screen/page.h +++ b/fw/fe310/eos/eve/screen/page.h @@ -5,10 +5,11 @@ #define EVE_PAGE_OPT_SCROLL_X 0x01 #define EVE_PAGE_OPT_SCROLL_Y 0x02 #define EVE_PAGE_OPT_SCROLL_BACK 0x04 -#define EVE_PAGE_OPT_SCROLL_XY 0x08 #define EVE_PAGE_OPT_TRACK_EXT_X 0x10 #define EVE_PAGE_OPT_TRACK_EXT_Y 0x20 -#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y) + +#define EVE_PAGE_OPT_SCROLL_XY (EVE_PAGE_OPT_SCROLL_X | EVE_PAGE_OPT_SCROLL_Y) +#define EVE_PAGE_OPT_TRACK_EXT_XY (EVE_PAGE_OPT_TRACK_EXT_X | EVE_PAGE_OPT_TRACK_EXT_Y) struct EVEWidget; struct EVEPage; @@ -26,13 +27,16 @@ typedef struct EVEPage { uint16_t widget_size; struct EVEWidget *widget_f; EVEPhyLHO lho; - uint64_t lho_t0; + uint32_t lho_t0; uint8_t track_mode; uint8_t opt; } EVEPage; void eve_page_init(EVEPage *page, EVEWindow *window, EVEViewStack *stack, struct EVEWidget *widget, uint16_t widget_size, uint8_t opt,eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, eve_page_destructor_t destructor); -void eve_page_update(EVEPage *page, struct EVEWidget *widget, uint16_t widget_size); + +struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx); +void eve_page_set_widget(EVEPage *page, struct EVEWidget *widget, uint16_t widget_size); + void eve_page_open(EVEPage *parent, eve_view_constructor_t constructor); void eve_page_close(EVEPage *page); @@ -46,11 +50,10 @@ int16_t eve_page_win_y(EVEPage *page, int16_t y); int16_t eve_page_scr_x(EVEPage *page, int16_t x); int16_t eve_page_scr_y(EVEPage *page, int16_t y); int eve_page_rect_visible(EVEPage *page, EVERect *g); +void eve_page_rect_set_visible(EVEPage *page, EVERect *rect); -void eve_page_focus(EVEPage *page, EVERect *rect); -void eve_page_focus_widget(EVEPage *page, struct EVEWidget *widget, EVERect *rect); -struct EVEWidget *eve_page_focus_widget_get(EVEPage *page); -struct EVEWidget *eve_page_widget(EVEPage *page, uint16_t idx); +struct EVEWidget *eve_page_focus(EVEPage *page); +void eve_page_set_focus(EVEPage *page, struct EVEWidget *widget, EVERect *rect); uint8_t eve_page_draw(EVEView *view, uint8_t tag0); int eve_page_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0); diff --git a/fw/fe310/eos/eve/screen/uievt.h b/fw/fe310/eos/eve/screen/uievt.h index 98f0d95..8e1e682 100644 --- a/fw/fe310/eos/eve/screen/uievt.h +++ b/fw/fe310/eos/eve/screen/uievt.h @@ -1,11 +1,13 @@ -#define EVE_UIEVT_WIN_UPDATE_G 1 -#define EVE_UIEVT_PAGE_UPDATE_G 2 -#define EVE_UIEVT_PAGE_TOUCH 3 -#define EVE_UIEVT_PAGE_SCROLL_START 4 -#define EVE_UIEVT_PAGE_SCROLL_STOP 5 -#define EVE_UIEVT_PAGE_TRACK_START 6 -#define EVE_UIEVT_PAGE_TRACK_STOP 7 +#define EVE_UIEVT_GEST_TOUCH 1 +#define EVE_UIEVT_GEST_SCROLL_START 2 +#define EVE_UIEVT_GEST_SCROLL_STOP 3 +#define EVE_UIEVT_GEST_TRACK_START 4 +#define EVE_UIEVT_GEST_TRACK_STOP 5 +#define EVE_UIEVT_WIN_UPDATE_G 6 +#define EVE_UIEVT_PAGE_UPDATE_G 7 #define EVE_UIEVT_WIDGET_UPDATE_G 8 +#define EVE_UIEVT_WIDGET_FOCUS_IN 9 +#define EVE_UIEVT_WIDGET_FOCUS_OUT 10 typedef struct EVEUIEvtTouch { EVETouch *touch; diff --git a/fw/fe310/eos/eve/screen/view.c b/fw/fe310/eos/eve/screen/view.c index ac9aef4..466644d 100644 --- a/fw/fe310/eos/eve/screen/view.c +++ b/fw/fe310/eos/eve/screen/view.c @@ -77,18 +77,19 @@ void eve_view_destroy(EVEWindow *window, EVEViewStack *stack) { } } -void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) { - if (view->uievt) view->uievt(view, evt, param); +int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) { + if (view->uievt) return view->uievt(view, evt, param); + return 0; } -int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) { +int eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0) { if (view->uievt) { EVEUIEvtTouch param; param.touch = touch; param.evt = t_evt; param.tag0 = tag0; - view->uievt(view, evt, ¶m); + return view->uievt(view, evt, ¶m); } return 0; } diff --git a/fw/fe310/eos/eve/screen/view.h b/fw/fe310/eos/eve/screen/view.h index 65999d7..c8be33a 100644 --- a/fw/fe310/eos/eve/screen/view.h +++ b/fw/fe310/eos/eve/screen/view.h @@ -38,5 +38,5 @@ void eve_view_stack_init(EVEViewStack *stack); void eve_view_create(struct EVEWindow *window, EVEViewStack *stack, eve_view_constructor_t constructor); void eve_view_destroy(struct EVEWindow *window, EVEViewStack *stack); -void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param); -int eve_view_uievt_pusht(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0); +int eve_view_uievt_push(EVEView *view, uint16_t evt, void *param); +int eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt, uint8_t tag0); diff --git a/fw/fe310/eos/eve/widget/Makefile b/fw/fe310/eos/eve/widget/Makefile index 31349a8..0bb1533 100644 --- a/fw/fe310/eos/eve/widget/Makefile +++ b/fw/fe310/eos/eve/widget/Makefile @@ -1,7 +1,7 @@ include ../../../common.mk CFLAGS += -I.. -obj = label.o widget.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o +obj = label.o widget.o widgets.o freew.o spacerw.o pagew.o strw.o textw.o selectw.o togglew.o %.o: %.c %.h diff --git a/fw/fe310/eos/eve/widget/freew.c b/fw/fe310/eos/eve/widget/freew.c index 86c2686..e7591da 100644 --- a/fw/fe310/eos/eve/widget/freew.c +++ b/fw/fe310/eos/eve/widget/freew.c @@ -8,15 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "freew.h" - -int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec) { - eve_freew_init(widget, g, page, spec->draw, spec->touch, spec->putc); - - return EVE_OK; -} void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) { EVEWidget *_widget = &widget->w; @@ -25,16 +17,15 @@ void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_ eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc); widget->_draw = draw; widget->_touch = touch; - widget->w.putc = putc; } -void eve_freew_tag(EVEFreeWidget *widget) { - EVEWidget *_widget = &widget->w; +int eve_freew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEFreeWidget *widget = (EVEFreeWidget *)_widget; + EVEFreeSpec *tspec = &spec->tspec.free; - if (_widget->tagN != EVE_NOTAG) { - eve_cmd_dl(TAG(_widget->tagN)); - _widget->tagN++; - } + eve_freew_init(widget, &spec->g, page, tspec->draw, tspec->touch, tspec->putc); + + return EVE_OK; } uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) { @@ -49,6 +40,18 @@ uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) { int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { EVEFreeWidget *widget = (EVEFreeWidget *)_widget; + int ret; + + ret = widget->_touch(widget, touch, evt); + if (ret) eve_widget_set_focus(_widget, NULL); + return ret; +} - return widget->_touch(widget, touch, evt); +void eve_freew_tag(EVEFreeWidget *widget) { + EVEWidget *_widget = &widget->w; + + if (_widget->tagN != EVE_NOTAG) { + eve_cmd_dl(TAG(_widget->tagN)); + _widget->tagN++; + } } diff --git a/fw/fe310/eos/eve/widget/freew.h b/fw/fe310/eos/eve/widget/freew.h index 7eda8c1..324e98d 100644 --- a/fw/fe310/eos/eve/widget/freew.h +++ b/fw/fe310/eos/eve/widget/freew.h @@ -1,6 +1,7 @@ #include <stdint.h> struct EVEFreeWidget; +struct EVEWidgetSpec; typedef void (*eve_freew_draw_t) (struct EVEFreeWidget *); typedef int (*eve_freew_touch_t) (struct EVEFreeWidget *, EVETouch *, uint16_t); @@ -17,9 +18,10 @@ typedef struct EVEFreeSpec { eve_kbd_input_handler_t putc; } EVEFreeSpec; -int eve_freew_create(EVEFreeWidget *widget, EVERect *g, EVEPage *page, EVEFreeSpec *spec); void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc); -void eve_freew_tag(EVEFreeWidget *widget); +int eve_freew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0); int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); + +void eve_freew_tag(EVEFreeWidget *widget); diff --git a/fw/fe310/eos/eve/widget/label.c b/fw/fe310/eos/eve/widget/label.c index f2d2e8e..43d555d 100644 --- a/fw/fe310/eos/eve/widget/label.c +++ b/fw/fe310/eos/eve/widget/label.c @@ -16,6 +16,13 @@ void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) { label->font = font; label->title = title; if (label->g.h == 0) label->g.h = eve_font_h(font); + if (label->g.w == 0) label->g.w = eve_font_str_w(font, label->title) + EVE_LABEL_MARGIN; +} + +void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page) { + EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); + + eve_label_init(label, &spec->g, font, spec->title); } void eve_label_draw(EVELabel *label) { diff --git a/fw/fe310/eos/eve/widget/label.h b/fw/fe310/eos/eve/widget/label.h index 659c057..9992f8c 100644 --- a/fw/fe310/eos/eve/widget/label.h +++ b/fw/fe310/eos/eve/widget/label.h @@ -1,10 +1,21 @@ #include <stdint.h> +#define EVE_LABEL_MARGIN 10 + typedef struct EVELabel { EVERect g; EVEFont *font; char *title; } EVELabel; +typedef struct EVELabelSpec { + EVERect g; + EVEFont *font; + char *title; + int16_t margin; +} EVELabelSpec; + void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title); + +void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page); void eve_label_draw(EVELabel *label);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/pagew.c b/fw/fe310/eos/eve/widget/pagew.c index bd7819f..c926892 100644 --- a/fw/fe310/eos/eve/widget/pagew.c +++ b/fw/fe310/eos/eve/widget/pagew.c @@ -8,17 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "pagew.h" - -int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - - eve_pagew_init(widget, g, page, font, spec->title, spec->constructor); - - return EVE_OK; -} void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor) { EVEWidget *_widget = &widget->w; @@ -31,6 +21,16 @@ void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *f if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font); } +int eve_pagew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEPageWidget *widget = (EVEPageWidget *)_widget; + EVEPageSpec *tspec = &spec->tspec.page; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + + eve_pagew_init(widget, &spec->g, page, font, tspec->title, tspec->constructor); + + return EVE_OK; +} + uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0) { EVEPageWidget *widget = (EVEPageWidget *)_widget; @@ -51,6 +51,7 @@ int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { EVEPageWidget *widget = (EVEPageWidget *)_widget; if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + eve_widget_set_focus(_widget, NULL); eve_page_open(parent, widget->constructor); return 1; } diff --git a/fw/fe310/eos/eve/widget/pagew.h b/fw/fe310/eos/eve/widget/pagew.h index 76ac0d2..b1a91b2 100644 --- a/fw/fe310/eos/eve/widget/pagew.h +++ b/fw/fe310/eos/eve/widget/pagew.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVEPageWidget { EVEWidget w; EVEFont *font; @@ -13,8 +15,8 @@ typedef struct EVEPageSpec { eve_view_constructor_t constructor; } EVEPageSpec; -int eve_pagew_create(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEPageSpec *spec); void eve_pagew_init(EVEPageWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *title, eve_view_constructor_t constructor); +int eve_pagew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_pagew_draw(EVEWidget *_widget, uint8_t tag0); int eve_pagew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/selectw.c b/fw/fe310/eos/eve/widget/selectw.c index 46ed3d1..5acf998 100644 --- a/fw/fe310/eos/eve/widget/selectw.c +++ b/fw/fe310/eos/eve/widget/selectw.c @@ -8,9 +8,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "selectw.h" #define SELECTW_NOSELECT 0xffffffff @@ -59,21 +57,6 @@ static void selectw_update_sz(EVESelectWidget *widget, int uievt) { if (uievt) eve_view_uievt_push(&page->v, EVE_UIEVT_WIDGET_UPDATE_G, _widget); } -int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *option; - - option = eve_malloc(spec->option_size); - if (option == NULL) { - return EVE_ERR_NOMEM; - } - memset(option, 0, spec->option_size); - - eve_selectw_init(widget, g, page, font, option, spec->option_size, spec->multi); - - return EVE_OK; -} - void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi) { EVEWidget *_widget = &widget->w; int rv; @@ -92,13 +75,32 @@ void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFon widget->select = widget->multi ? 0 : SELECTW_NOSELECT; } -void eve_selectw_destroy(EVESelectWidget *widget) { +int eve_selectw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVESelectWidget *widget = (EVESelectWidget *)_widget; + EVESelectSpec *tspec = &spec->tspec.select; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *option; + + option = eve_malloc(tspec->option_size); + if (option == NULL) { + return EVE_ERR_NOMEM; + } + memset(option, 0, tspec->option_size); + + eve_selectw_init(widget, &spec->g, page, font, option, tspec->option_size, tspec->multi); + + return EVE_OK; +} + +void eve_selectw_destroy(EVEWidget *_widget) { + EVESelectWidget *widget = (EVESelectWidget *)_widget; + eve_free(widget->option); } uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0) { - EVEPage *page = _widget->page; EVESelectWidget *widget = (EVESelectWidget *)_widget; + EVEPage *page = _widget->page; int o_len; int o_curr; int i, s; @@ -161,6 +163,7 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { if (evt & EVE_TOUCH_ETYPE_TAG_UP) { int i = touch->tag0 - _widget->tag0 + widget->line0; + if (widget->multi) { uint32_t f = (0x1 << i); @@ -176,12 +179,15 @@ int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->select = i; } } + + eve_widget_set_focus(_widget, NULL); return 1; } + return 0; } -utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) { +utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx) { int o_len; int o_curr; int i; @@ -199,11 +205,11 @@ utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx) { return NULL; } -utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget) { - return eve_selectw_option_get(widget, widget->select); +utf8_t *eve_selectw_option_selected(EVESelectWidget *widget) { + return eve_selectw_option(widget, widget->select); } -int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) { +int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option) { int o_len; int o_curr; int rv, i; @@ -231,7 +237,7 @@ int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option) { return EVE_OK; } -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { +int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size) { int rv, i; rv = selectw_verify(option, option_size); diff --git a/fw/fe310/eos/eve/widget/selectw.h b/fw/fe310/eos/eve/widget/selectw.h index 939e362..f1b7071 100644 --- a/fw/fe310/eos/eve/widget/selectw.h +++ b/fw/fe310/eos/eve/widget/selectw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVESelectWidget { EVEWidget w; EVEFont *font; @@ -17,14 +19,14 @@ typedef struct EVESelectSpec { uint8_t multi; } EVESelectSpec; -int eve_selectw_create(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVESelectSpec *spec); void eve_selectw_init(EVESelectWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *option, uint16_t option_size, uint8_t multi); -void eve_selectw_destroy(EVESelectWidget *widget); +int eve_selectw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_selectw_destroy(EVEWidget *_widget); uint8_t eve_selectw_draw(EVEWidget *_widget, uint8_t tag0); int eve_selectw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); -utf8_t *eve_selectw_option_get(EVESelectWidget *widget, int idx); -utf8_t *eve_selectw_option_get_select(EVESelectWidget *widget); -int eve_selectw_option_add(EVESelectWidget *widget, utf8_t *option); -int eve_selectw_option_set(EVESelectWidget *widget, utf8_t *option, uint16_t option_size); +utf8_t *eve_selectw_option(EVESelectWidget *widget, int idx); +utf8_t *eve_selectw_option_selected(EVESelectWidget *widget); +int eve_selectw_add_option(EVESelectWidget *widget, utf8_t *option); +int eve_selectw_set_option(EVESelectWidget *widget, utf8_t *option, uint16_t option_size); diff --git a/fw/fe310/eos/eve/widget/spacerw.c b/fw/fe310/eos/eve/widget/spacerw.c index d9f9104..aa5bec1 100644 --- a/fw/fe310/eos/eve/widget/spacerw.c +++ b/fw/fe310/eos/eve/widget/spacerw.c @@ -8,21 +8,17 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "spacerw.h" -int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec) { - eve_spacerw_init(widget, g, page); - - return EVE_OK; +void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page) { + memset(widget, 0, sizeof(EVEWidget)); + eve_widget_init(widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL); } -void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page) { - EVEWidget *_widget = &widget->w; +int eve_spacerw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + eve_spacerw_init(_widget, &spec->g, page); - memset(widget, 0, sizeof(EVESpacerWidget)); - eve_widget_init(_widget, EVE_WIDGET_TYPE_SPACER, g, page, eve_spacerw_draw, eve_spacerw_touch, NULL); + return EVE_OK; } uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0) { diff --git a/fw/fe310/eos/eve/widget/spacerw.h b/fw/fe310/eos/eve/widget/spacerw.h index 9dafa8b..621b45b 100644 --- a/fw/fe310/eos/eve/widget/spacerw.h +++ b/fw/fe310/eos/eve/widget/spacerw.h @@ -1,14 +1,9 @@ #include <stdint.h> -typedef struct EVESpacerWidget { - EVEWidget w; -} EVESpacerWidget; +struct EVEWidgetSpec; -typedef struct EVESpacerSpec { -} EVESpacerSpec; - -int eve_spacerw_create(EVESpacerWidget *widget, EVERect *g, EVEPage *page, EVESpacerSpec *spec); -void eve_spacerw_init(EVESpacerWidget *widget, EVERect *g, EVEPage *page); +void eve_spacerw_init(EVEWidget *widget, EVERect *g, EVEPage *page); +int eve_spacerw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); uint8_t eve_spacerw_draw(EVEWidget *_widget, uint8_t tag0); int eve_spacerw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/strw.c b/fw/fe310/eos/eve/widget/strw.c index e78cf46..ae9ccab 100644 --- a/fw/fe310/eos/eve/widget/strw.c +++ b/fw/fe310/eos/eve/widget/strw.c @@ -10,9 +10,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "strw.h" #define STRW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_X | EVE_TOUCH_OPT_TRACK_EXT_X | EVE_TOUCH_OPT_LPRESS @@ -29,20 +27,6 @@ #define CHAR_VALID_INPUT(c) ((c >= 0x20) && (c < 0x7f)) -int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *str; - uint16_t *line; - - str = eve_malloc(spec->str_size); - if (str == NULL) return EVE_ERR_NOMEM; - str[0] = '\0'; - - eve_strw_init(widget, g, page, font, str, spec->str_size); - - return EVE_OK; -} - void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size) { EVEWidget *_widget = &widget->w; int rv, str_len; @@ -71,10 +55,29 @@ int eve_strw_update(EVEStrWidget *widget) { widget->str[str_len] = '\0'; } widget->str_len = str_len; + widget->str_g.w = eve_font_str_w(widget->font, widget->str); return (rv == UTF_OK) ? EVE_OK : EVE_ERR; } -void eve_strw_destroy(EVEStrWidget *widget) { +int eve_strw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEStrWidget *widget = (EVEStrWidget *)_widget; + EVEStrSpec *tspec = &spec->tspec.str; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *str; + uint16_t *line; + + str = eve_malloc(tspec->str_size); + if (str == NULL) return EVE_ERR_NOMEM; + str[0] = '\0'; + + eve_strw_init(widget, &spec->g, page, font, str, tspec->str_size); + + return EVE_OK; +} + +void eve_strw_destroy(EVEWidget *_widget) { + EVEStrWidget *widget = (EVEStrWidget *)_widget; + eve_free(widget->str); } @@ -86,7 +89,7 @@ static void set_focus(EVEStrWidget *widget) { focus.y = _widget->g.y; focus.w = _widget->g.w; focus.h = 2 * widget->font->h; - eve_widget_focus(_widget, &focus); + eve_widget_set_focus(_widget, &focus); } static EVEStrCursor *cursor_prox(EVEStrWidget *widget, EVEStrCursor *cursor, EVETouch *touch, short *dx) { @@ -215,8 +218,8 @@ uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0) { } int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { - EVEPage *page = _widget->page; EVEStrWidget *widget = (EVEStrWidget *)_widget; + EVEPage *page = _widget->page; EVEStrCursor *t_cursor = NULL; short dx; int ret = 0; @@ -290,6 +293,7 @@ int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->track.dx = 0; } + if (ret) eve_widget_set_focus(_widget, NULL); return ret; } @@ -305,7 +309,6 @@ void eve_strw_putc(void *w, int c) { int ins_c = 0, del_c = 0; int ins_w = 0, del_w = 0; - if (c == EVE_PAGE_KBDCH_CLOSE) { if (cursor1->on) eve_strw_cursor_clear(widget, cursor1); if (cursor2->on) eve_strw_cursor_clear(widget, cursor2); diff --git a/fw/fe310/eos/eve/widget/strw.h b/fw/fe310/eos/eve/widget/strw.h index 44e5e2d..acfd74b 100644 --- a/fw/fe310/eos/eve/widget/strw.h +++ b/fw/fe310/eos/eve/widget/strw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVEStrCursor { char on; uint16_t x; @@ -31,13 +33,14 @@ typedef struct EVEStrSpec { uint16_t str_size; } EVEStrSpec; -int eve_strw_create(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEStrSpec *spec); void eve_strw_init(EVEStrWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *str, uint16_t str_size); -void eve_strw_destroy(EVEStrWidget *widget); int eve_strw_update(EVEStrWidget *widget); +int eve_strw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_strw_destroy(EVEWidget *_widget); uint8_t eve_strw_draw(EVEWidget *_widget, uint8_t tag0); int eve_strw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); + void eve_strw_putc(void *_page, int c); void eve_strw_cursor_set(EVEStrWidget *widget, EVEStrCursor *cursor, int16_t x); void eve_strw_cursor_clear(EVEStrWidget *widget, EVEStrCursor *cursor);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/textw.c b/fw/fe310/eos/eve/widget/textw.c index e994c0e..70a1e06 100644 --- a/fw/fe310/eos/eve/widget/textw.c +++ b/fw/fe310/eos/eve/widget/textw.c @@ -10,9 +10,7 @@ #include "screen/window.h" #include "screen/page.h" -#include "label.h" #include "widget.h" -#include "textw.h" #define TEXTW_TOUCH_OPT EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY | EVE_TOUCH_OPT_TRACK_EXT_XY | EVE_TOUCH_OPT_LPRESS @@ -32,27 +30,6 @@ #define DIVC(x,y) ((x) / (y) + ((x) % (y) != 0)) -int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec) { - EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window); - utf8_t *text; - uint16_t *line; - - text = eve_malloc(spec->text_size); - if (text == NULL) { - return EVE_ERR_NOMEM; - } - text[0] = '\0'; - line = eve_malloc(sizeof(uint16_t) * spec->line_size); - if (line == NULL) { - free(text); - return EVE_ERR_NOMEM; - } - - eve_textw_init(widget, g, page, font, text, spec->text_size, line, spec->line_size); - - return EVE_OK; -} - void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size) { EVEWidget *_widget = &widget->w; int rv, text_len; @@ -74,7 +51,32 @@ void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *f eve_textw_text_update(widget, 0, 0); } -void eve_textw_destroy(EVETextWidget *widget) { +int eve_textw_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVETextWidget *widget = (EVETextWidget *)_widget; + EVETextSpec *tspec = &spec->tspec.text; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + utf8_t *text; + uint16_t *line; + + text = eve_malloc(tspec->text_size); + if (text == NULL) { + return EVE_ERR_NOMEM; + } + text[0] = '\0'; + line = eve_malloc(sizeof(uint16_t) * tspec->line_size); + if (line == NULL) { + free(text); + return EVE_ERR_NOMEM; + } + + eve_textw_init(widget, &spec->g, page, font, text, tspec->text_size, line, tspec->line_size); + + return EVE_OK; +} + +void eve_textw_destroy(EVEWidget *_widget) { + EVETextWidget *widget = (EVETextWidget *)_widget; + eve_free(widget->line); eve_free(widget->text); } @@ -87,7 +89,7 @@ static void set_focus(EVETextWidget *widget, EVETextCursor *cursor) { focus.y = _widget->g.y + cursor->line * widget->font->h; focus.w = _widget->g.w; focus.h = 2 * widget->font->h; - eve_widget_focus(_widget, &focus); + eve_widget_set_focus(_widget, &focus); } static EVETextCursor *cursor_prox(EVETextWidget *widget, EVETextCursor *cursor, EVETouch *touch, short *dx, short *dl) { @@ -144,8 +146,8 @@ static void draw_cursor(EVETextWidget *widget, EVETextCursor *cursor) { } uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) { - EVEPage *page = _widget->page; EVETextWidget *widget = (EVETextWidget *)_widget; + EVEPage *page = _widget->page; int line0, lineN; int _line0, _lineN; char lineNvisible; @@ -237,8 +239,8 @@ uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0) { } int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { - EVEPage *page = _widget->page; EVETextWidget *widget = (EVETextWidget *)_widget; + EVEPage *page = _widget->page; EVETextCursor *t_cursor = NULL; short dx, dl; int ret = 0; @@ -289,6 +291,7 @@ int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { widget->track.dl = 0; } + if (ret) eve_widget_set_focus(_widget, NULL); return ret; } diff --git a/fw/fe310/eos/eve/widget/textw.h b/fw/fe310/eos/eve/widget/textw.h index 570bba8..1c33733 100644 --- a/fw/fe310/eos/eve/widget/textw.h +++ b/fw/fe310/eos/eve/widget/textw.h @@ -1,5 +1,7 @@ #include <stdint.h> +struct EVEWidgetSpec; + typedef struct EVETextCursor { char on; uint16_t x; @@ -32,10 +34,10 @@ typedef struct EVETextSpec { uint16_t line_size; } EVETextSpec; -int eve_textw_create(EVETextWidget *widget, EVERect *g, EVEPage *page, EVETextSpec *spec); void eve_textw_init(EVETextWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, utf8_t *text, uint16_t text_size, uint16_t *line, uint16_t line_size); -void eve_textw_destroy(EVETextWidget *widget); +int eve_textw_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +void eve_textw_destroy(EVEWidget *_widget); uint8_t eve_textw_draw(EVEWidget *_widget, uint8_t tag0); int eve_textw_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); void eve_textw_putc(void *_w, int c); diff --git a/fw/fe310/eos/eve/widget/togglew.c b/fw/fe310/eos/eve/widget/togglew.c new file mode 100644 index 0000000..fbebacb --- /dev/null +++ b/fw/fe310/eos/eve/widget/togglew.c @@ -0,0 +1,58 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" +#include "eve_font.h" + +#include "screen/window.h" +#include "screen/page.h" + +#include "widget.h" + +void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels) { + EVEWidget *_widget = &widget->w; + + memset(widget, 0, sizeof(EVEPageWidget)); + eve_widget_init(_widget, EVE_WIDGET_TYPE_TOGGLE, g, page, eve_togglew_draw, eve_togglew_touch, NULL); + widget->font = font; + widget->labels = labels; + if (_widget->g.w == 0) _widget->g.w = 3 * eve_font_h(widget->font); + if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font); +} + +int eve_togglew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + EVEToggleSpec *tspec = &spec->tspec.toggle; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + + eve_togglew_init(widget, &spec->g, page, font, tspec->labels); + + return EVE_OK; +} + +uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + _widget->tag0 = tag0; + if (tag0 != EVE_NOTAG) { + eve_cmd_dl(TAG(tag0)); + tag0++; + } + _widget->tagN = tag0; + + eve_cmd(CMD_TOGGLE, "hhhhhhs", _widget->g.x, _widget->g.y, _widget->g.w, widget->font->id, 0, widget->state ? 65535 : 0, widget->labels); + + return _widget->tagN; +} + +int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + widget->state = !widget->state; + return 1; + } + + return 0; +} diff --git a/fw/fe310/eos/eve/widget/togglew.h b/fw/fe310/eos/eve/widget/togglew.h new file mode 100644 index 0000000..26ff77c --- /dev/null +++ b/fw/fe310/eos/eve/widget/togglew.h @@ -0,0 +1,21 @@ +#include <stdint.h> + +struct EVEWidgetSpec; + +typedef struct EVEToggleWidget { + EVEWidget w; + EVEFont *font; + char *labels; + uint8_t state; +} EVEToggleWidget; + +typedef struct EVEToggleSpec { + EVEFont *font; + char *labels; +} EVEToggleSpec; + +void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels); + +int eve_togglew_create(EVEWidget *_widget, struct EVEWidgetSpec *spec, EVEPage *page); +uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0); +int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt); diff --git a/fw/fe310/eos/eve/widget/widget.c b/fw/fe310/eos/eve/widget/widget.c index 96d2ddf..a157301 100644 --- a/fw/fe310/eos/eve/widget/widget.c +++ b/fw/fe310/eos/eve/widget/widget.c @@ -8,37 +8,11 @@ #include "screen/window.h" #include "screen/page.h" -#include "widgets.h" - -static const size_t _widget_size[] = { - 0, - sizeof(EVEFreeWidget), - sizeof(EVESpacerWidget), - sizeof(EVEPageWidget), - sizeof(EVEStrWidget), - sizeof(EVETextWidget), - sizeof(EVESelectWidget), -}; - -static const eve_widget_create_t _widget_create[] = { - NULL, - (eve_widget_create_t)eve_freew_create, - (eve_widget_create_t)eve_spacerw_create, - (eve_widget_create_t)eve_pagew_create, - (eve_widget_create_t)eve_strw_create, - (eve_widget_create_t)eve_textw_create, - (eve_widget_create_t)eve_selectw_create, -}; - -static const eve_widget_destroy_t _widget_destroy[] = { - NULL, - NULL, - NULL, - NULL, - (eve_widget_destroy_t)eve_strw_destroy, - (eve_widget_destroy_t)eve_textw_destroy, - (eve_widget_destroy_t)eve_selectw_destroy, -}; +#include "widget.h" + +extern const size_t _eve_widget_size[]; +extern const eve_widget_create_t _eve_widget_create[]; +extern const eve_widget_destroy_t _eve_widget_destroy[]; void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc) { if (g) widget->g = *g; @@ -50,7 +24,7 @@ void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, } size_t eve_widget_size(uint8_t type) { - return _widget_size[type]; + return _eve_widget_size[type]; } void eve_widget_set_label(EVEWidget *widget, EVELabel *label) { @@ -59,19 +33,32 @@ void eve_widget_set_label(EVEWidget *widget, EVELabel *label) { EVEWidget *eve_widget_next(EVEWidget *widget) { char *_w = (char *)widget; - return (EVEWidget *)(_w + _widget_size[widget->type]); + return (EVEWidget *)(_w + _eve_widget_size[widget->type]); } -int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec) { - return _widget_create[type](widget, g, page, spec); +int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page) { + int rv; + + rv = _eve_widget_create[spec->type](widget, spec, page); + if (!rv) eve_widget_set_flags(widget, spec->flags); + + return rv; } void eve_widget_destroy(EVEWidget *widget) { - if (_widget_destroy[widget->type]) _widget_destroy[widget->type](widget); + if (_eve_widget_destroy[widget->type]) _eve_widget_destroy[widget->type](widget); } -void eve_widget_focus(EVEWidget *widget, EVERect *rect) { +void eve_widget_set_focus(EVEWidget *widget, EVERect *rect) { EVEPage *page = widget->page; - eve_page_focus_widget(page, widget, rect); + eve_page_set_focus(page, widget, rect); +} + +void eve_widget_set_flags(EVEWidget *widget, uint8_t flags) { + widget->flags |= flags; +} + +void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags) { + widget->flags &= ~flags; } diff --git a/fw/fe310/eos/eve/widget/widget.h b/fw/fe310/eos/eve/widget/widget.h index f081b4c..0bef06e 100644 --- a/fw/fe310/eos/eve/widget/widget.h +++ b/fw/fe310/eos/eve/widget/widget.h @@ -1,11 +1,10 @@ #include <stdint.h> -#define EVE_WIDGET_TYPE_FREE 1 -#define EVE_WIDGET_TYPE_SPACER 2 -#define EVE_WIDGET_TYPE_PAGE 3 -#define EVE_WIDGET_TYPE_STR 4 -#define EVE_WIDGET_TYPE_TEXT 5 -#define EVE_WIDGET_TYPE_SELECT 6 +#include "label.h" + +#define EVEP_WIDGET_FLAG_RO 0x01 +#define EVEP_WIDGET_FLAG_HIDDEN 0x02 +#define EVEP_WIDGET_FLAG_BUSY 0x04 struct EVEWidget; @@ -20,12 +19,31 @@ typedef struct EVEWidget { eve_kbd_input_handler_t putc; EVELabel *label; uint8_t type; + uint8_t flags; uint8_t tag0; uint8_t tagN; } EVEWidget; +#include "widgets.h" + +typedef struct EVEWidgetSpec { + EVERect g; + EVEWidgetSpecT tspec; + uint8_t type; + uint8_t flags; +} EVEWidgetSpec; + +typedef int (*eve_widget_create_t) (EVEWidget *, EVEWidgetSpec *, EVEPage *); +typedef void (*eve_widget_destroy_t) (EVEWidget *); + +int eve_widget_create(EVEWidget *widget, EVEWidgetSpec *spec, EVEPage *page); +void eve_widget_destroy(EVEWidget *widget); + void eve_widget_init(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, eve_widget_draw_t draw, eve_widget_touch_t touch, eve_kbd_input_handler_t putc); size_t eve_widget_size(uint8_t type); void eve_widget_set_label(EVEWidget *widget, EVELabel *label); EVEWidget *eve_widget_next(EVEWidget *widget); -void eve_widget_focus(EVEWidget *widget, EVERect *rect);
\ No newline at end of file + +void eve_widget_set_focus(EVEWidget *widget, EVERect *rect); +void eve_widget_set_flags(EVEWidget *widget, uint8_t flags); +void eve_widget_clr_flags(EVEWidget *widget, uint8_t flags);
\ No newline at end of file diff --git a/fw/fe310/eos/eve/widget/widgets.c b/fw/fe310/eos/eve/widget/widgets.c new file mode 100644 index 0000000..ec422c1 --- /dev/null +++ b/fw/fe310/eos/eve/widget/widgets.c @@ -0,0 +1,43 @@ +#include <stdlib.h> + +#include "eve.h" +#include "eve_kbd.h" +#include "eve_font.h" + +#include "screen/window.h" +#include "screen/page.h" + +#include "widget.h" + +const size_t _eve_widget_size[] = { + 0, + sizeof(EVEFreeWidget), + sizeof(EVEWidget), + sizeof(EVEPageWidget), + sizeof(EVEToggleWidget), + sizeof(EVEStrWidget), + sizeof(EVETextWidget), + sizeof(EVESelectWidget), +}; + +const eve_widget_create_t _eve_widget_create[] = { + NULL, + eve_freew_create, + eve_spacerw_create, + eve_pagew_create, + eve_togglew_create, + eve_strw_create, + eve_textw_create, + eve_selectw_create, +}; + +const eve_widget_destroy_t _eve_widget_destroy[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + eve_strw_destroy, + eve_textw_destroy, + eve_selectw_destroy, +}; diff --git a/fw/fe310/eos/eve/widget/widgets.h b/fw/fe310/eos/eve/widget/widgets.h index 2f8d3ca..9c96d8c 100644 --- a/fw/fe310/eos/eve/widget/widgets.h +++ b/fw/fe310/eos/eve/widget/widgets.h @@ -1,39 +1,24 @@ -#include "label.h" -#include "widget.h" - #include "freew.h" #include "spacerw.h" #include "pagew.h" #include "strw.h" #include "textw.h" #include "selectw.h" +#include "togglew.h" + +#define EVE_WIDGET_TYPE_FREE 1 +#define EVE_WIDGET_TYPE_SPACER 2 +#define EVE_WIDGET_TYPE_PAGE 3 +#define EVE_WIDGET_TYPE_TOGGLE 4 +#define EVE_WIDGET_TYPE_STR 5 +#define EVE_WIDGET_TYPE_TEXT 6 +#define EVE_WIDGET_TYPE_SELECT 7 typedef union EVEWidgetSpecT { EVEFreeSpec free; - EVESpacerSpec spacer; EVEPageSpec page; + EVEToggleSpec toggle; EVEStrSpec str; EVETextSpec text; EVESelectSpec select; } EVEWidgetSpecT; - -typedef struct EVELabelSpec { - EVERect g; - EVEFont *font; - char *title; -} APPLabelSpec; - -typedef struct EVEWidgetSpec { - APPLabelSpec label; - struct { - EVERect g; - EVEWidgetSpecT spec; - uint8_t type; - } widget; -} EVEWidgetSpec; - -typedef int (*eve_widget_create_t) (EVEWidget *, EVERect *, EVEPage *, EVEWidgetSpecT *); -typedef void (*eve_widget_destroy_t) (EVEWidget *); - -int eve_widget_create(EVEWidget *widget, uint8_t type, EVERect *g, EVEPage *page, EVEWidgetSpecT *spec); -void eve_widget_destroy(EVEWidget *widget); |