diff --git a/apps/beats-time/app.c b/apps/beats-time/app.c index 3a8c2dac..ef27ffef 100644 --- a/apps/beats-time/app.c +++ b/apps/beats-time/app.c @@ -3,7 +3,7 @@ #include #include "watch.h" -const uint8_t UTC_OFFSET = 4; // set to your current UTC offset to see correct beats time +const int8_t UTC_OFFSET = 4; // set to your current UTC offset to see correct beats time const uint8_t BEAT_REFRESH_FREQUENCY = 8; typedef enum ApplicationMode { @@ -160,7 +160,7 @@ float clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, int16_t ut float beats = seconds + ((float)application_state.subsecond / (float)BEAT_REFRESH_FREQUENCY); beats += 60 * minutes; beats += (float)hours * 60 * 60; - beats += (utc_offset + 1) * 60 * 60; // offset from utc + 1 since beats in in UTC+1 + beats += (1 - utc_offset) * 60 * 60; // offset from utc + 1 since beats in in UTC+1 beats /= 86.4; // convert to beats while(beats > 1000) beats -= 1000; // beats %= 1000 but for a float diff --git a/make.mk b/make.mk index 1b688ae5..94d0bd82 100644 --- a/make.mk +++ b/make.mk @@ -9,17 +9,18 @@ endif ############################################################################## .PHONY: all directory clean size -CC = arm-none-eabi-gcc -OBJCOPY = arm-none-eabi-objcopy -SIZE = arm-none-eabi-size -UF2 = python $(TOP)/utils/uf2conv.py - ifeq ($(OS), Windows_NT) MKDIR = gmkdir else MKDIR = mkdir endif +ifndef EMSCRIPTEN +CC = arm-none-eabi-gcc +OBJCOPY = arm-none-eabi-objcopy +SIZE = arm-none-eabi-size +UF2 = python $(TOP)/utils/uf2conv.py + CFLAGS += -W -Wall -Wextra -Wmissing-prototypes -Wmissing-declarations CFLAGS += --std=gnu99 -Os CFLAGS += -fno-diagnostics-show-caret @@ -30,40 +31,41 @@ CFLAGS += -MD -MP -MT $(BUILD)/$(*F).o -MF $(BUILD)/$(@F).d LDFLAGS += -mcpu=cortex-m0plus -mthumb LDFLAGS += -Wl,--gc-sections -LDFLAGS += -Wl,--script=$(TOP)//watch-library/linker/saml22j18.ld +LDFLAGS += -Wl,--script=$(TOP)/watch-library/hardware/linker/saml22j18.ld LIBS += -lm INCLUDES += \ -I$(TOP)/tinyusb/src \ -I$(TOP)/boards/$(BOARD) \ - -I$(TOP)/watch-library/include \ - -I$(TOP)/watch-library/hal/ \ - -I$(TOP)/watch-library/hal/documentation/ \ - -I$(TOP)/watch-library/hal/include/ \ - -I$(TOP)/watch-library/hal/src/ \ - -I$(TOP)/watch-library/hal/utils/ \ - -I$(TOP)/watch-library/hal/utils/include/ \ - -I$(TOP)/watch-library/hal/utils/src/ \ - -I$(TOP)/watch-library/hpl/ \ - -I$(TOP)/watch-library/hpl/core/ \ - -I$(TOP)/watch-library/hpl/dmac/ \ - -I$(TOP)/watch-library/hpl/eic/ \ - -I$(TOP)/watch-library/hpl/gclk/ \ - -I$(TOP)/watch-library/hpl/mclk/ \ - -I$(TOP)/watch-library/hpl/osc32kctrl/ \ - -I$(TOP)/watch-library/hpl/oscctrl/ \ - -I$(TOP)/watch-library/hpl/pm/ \ - -I$(TOP)/watch-library/hpl/port/ \ - -I$(TOP)/watch-library/hpl/sercom/ \ - -I$(TOP)/watch-library/hpl/slcd/ \ - -I$(TOP)/watch-library/hpl/systick/ \ - -I$(TOP)/watch-library/hri/ \ - -I$(TOP)/watch-library/config/ \ - -I$(TOP)/watch-library/hw/ \ - -I$(TOP)/watch-library/watch/ \ - -I$(TOP)/watch-library/driver/ \ - -I$(TOP)/watch-library + -I$(TOP)/watch-library/shared/config/ \ + -I$(TOP)/watch-library/shared/driver/ \ + -I$(TOP)/watch-library/shared/watch/ \ + -I$(TOP)/watch-library/hardware/include \ + -I$(TOP)/watch-library/hardware/hal/ \ + -I$(TOP)/watch-library/hardware/hal/documentation/ \ + -I$(TOP)/watch-library/hardware/hal/include/ \ + -I$(TOP)/watch-library/hardware/hal/src/ \ + -I$(TOP)/watch-library/hardware/hal/utils/ \ + -I$(TOP)/watch-library/hardware/hal/utils/include/ \ + -I$(TOP)/watch-library/hardware/hal/utils/src/ \ + -I$(TOP)/watch-library/hardware/hpl/ \ + -I$(TOP)/watch-library/hardware/hpl/core/ \ + -I$(TOP)/watch-library/hardware/hpl/dmac/ \ + -I$(TOP)/watch-library/hardware/hpl/eic/ \ + -I$(TOP)/watch-library/hardware/hpl/gclk/ \ + -I$(TOP)/watch-library/hardware/hpl/mclk/ \ + -I$(TOP)/watch-library/hardware/hpl/osc32kctrl/ \ + -I$(TOP)/watch-library/hardware/hpl/oscctrl/ \ + -I$(TOP)/watch-library/hardware/hpl/pm/ \ + -I$(TOP)/watch-library/hardware/hpl/port/ \ + -I$(TOP)/watch-library/hardware/hpl/sercom/ \ + -I$(TOP)/watch-library/hardware/hpl/slcd/ \ + -I$(TOP)/watch-library/hardware/hpl/systick/ \ + -I$(TOP)/watch-library/hardware/hri/ \ + -I$(TOP)/watch-library/hardware/hw/ \ + -I$(TOP)/watch-library/hardware/watch/ \ + -I$(TOP)/watch-library/hardware \ SRCS += \ $(TOP)/tinyusb/src/tusb.c \ @@ -72,55 +74,92 @@ SRCS += \ $(TOP)/tinyusb/src/device/usbd.c \ $(TOP)/tinyusb/src/device/usbd_control.c \ $(TOP)/tinyusb/src/portable/microchip/samd/dcd_samd.c \ - $(TOP)/watch-library/main.c \ - $(TOP)/watch-library/startup_saml22.c \ - $(TOP)/watch-library/hw/driver_init.c \ - $(TOP)/watch-library/watch/watch_rtc.c \ - $(TOP)/watch-library/watch/watch_slcd.c \ - $(TOP)/watch-library/watch/watch_extint.c \ - $(TOP)/watch-library/watch/watch_led.c \ - $(TOP)/watch-library/watch/watch_buzzer.c \ - $(TOP)/watch-library/watch/watch_adc.c \ - $(TOP)/watch-library/watch/watch_gpio.c \ - $(TOP)/watch-library/watch/watch_i2c.c \ - $(TOP)/watch-library/watch/watch_uart.c \ - $(TOP)/watch-library/watch/watch_deepsleep.c \ - $(TOP)/watch-library/watch/watch_utility.c \ - $(TOP)/watch-library/watch/watch_private.c \ - $(TOP)/watch-library/watch/watch.c \ - $(TOP)/watch-library/hal/src/hal_atomic.c \ - $(TOP)/watch-library/hal/src/hal_delay.c \ - $(TOP)/watch-library/hal/src/hal_ext_irq.c \ - $(TOP)/watch-library/hal/src/hal_gpio.c \ - $(TOP)/watch-library/hal/src/hal_i2c_m_sync.c \ - $(TOP)/watch-library/hal/src/hal_spi_m_sync.c \ - $(TOP)/watch-library/hal/src/hal_init.c \ - $(TOP)/watch-library/hal/src/hal_io.c \ - $(TOP)/watch-library/hal/src/hal_slcd_sync.c \ - $(TOP)/watch-library/hal/src/hal_sleep.c \ - $(TOP)/watch-library/hal/utils/src/utils_assert.c \ - $(TOP)/watch-library/hal/utils/src/utils_event.c \ - $(TOP)/watch-library/hal/utils/src/utils_list.c \ - $(TOP)/watch-library/hal/utils/src/utils_syscalls.c \ - $(TOP)/watch-library/hpl/core/hpl_core_m0plus_base.c \ - $(TOP)/watch-library/hpl/core/hpl_init.c \ - $(TOP)/watch-library/hpl/dmac/hpl_dmac.c \ - $(TOP)/watch-library/hpl/eic/hpl_eic.c \ - $(TOP)/watch-library/hpl/gclk/hpl_gclk.c \ - $(TOP)/watch-library/hpl/mclk/hpl_mclk.c \ - $(TOP)/watch-library/hpl/osc32kctrl/hpl_osc32kctrl.c \ - $(TOP)/watch-library/hpl/oscctrl/hpl_oscctrl.c \ - $(TOP)/watch-library/hpl/pm/hpl_pm.c \ - $(TOP)/watch-library/hpl/sercom/hpl_sercom.c \ - $(TOP)/watch-library/hpl/slcd/hpl_slcd.c \ - $(TOP)/watch-library/hpl/systick/hpl_systick.c \ - $(TOP)/watch-library/driver/lis2dh.c \ - $(TOP)/watch-library/driver/lis2dw.c \ + $(TOP)/watch-library/hardware/main.c \ + $(TOP)/watch-library/hardware/startup_saml22.c \ + $(TOP)/watch-library/hardware/hw/driver_init.c \ + $(TOP)/watch-library/hardware/watch/watch_rtc.c \ + $(TOP)/watch-library/hardware/watch/watch_slcd.c \ + $(TOP)/watch-library/hardware/watch/watch_extint.c \ + $(TOP)/watch-library/hardware/watch/watch_led.c \ + $(TOP)/watch-library/hardware/watch/watch_buzzer.c \ + $(TOP)/watch-library/hardware/watch/watch_adc.c \ + $(TOP)/watch-library/hardware/watch/watch_gpio.c \ + $(TOP)/watch-library/hardware/watch/watch_i2c.c \ + $(TOP)/watch-library/hardware/watch/watch_uart.c \ + $(TOP)/watch-library/hardware/watch/watch_deepsleep.c \ + $(TOP)/watch-library/hardware/watch/watch_private.c \ + $(TOP)/watch-library/hardware/watch/watch.c \ + $(TOP)/watch-library/hardware/hal/src/hal_atomic.c \ + $(TOP)/watch-library/hardware/hal/src/hal_delay.c \ + $(TOP)/watch-library/hardware/hal/src/hal_ext_irq.c \ + $(TOP)/watch-library/hardware/hal/src/hal_gpio.c \ + $(TOP)/watch-library/hardware/hal/src/hal_i2c_m_sync.c \ + $(TOP)/watch-library/hardware/hal/src/hal_spi_m_sync.c \ + $(TOP)/watch-library/hardware/hal/src/hal_init.c \ + $(TOP)/watch-library/hardware/hal/src/hal_io.c \ + $(TOP)/watch-library/hardware/hal/src/hal_slcd_sync.c \ + $(TOP)/watch-library/hardware/hal/src/hal_sleep.c \ + $(TOP)/watch-library/hardware/hal/utils/src/utils_assert.c \ + $(TOP)/watch-library/hardware/hal/utils/src/utils_event.c \ + $(TOP)/watch-library/hardware/hal/utils/src/utils_list.c \ + $(TOP)/watch-library/hardware/hal/utils/src/utils_syscalls.c \ + $(TOP)/watch-library/hardware/hpl/core/hpl_core_m0plus_base.c \ + $(TOP)/watch-library/hardware/hpl/core/hpl_init.c \ + $(TOP)/watch-library/hardware/hpl/dmac/hpl_dmac.c \ + $(TOP)/watch-library/hardware/hpl/eic/hpl_eic.c \ + $(TOP)/watch-library/hardware/hpl/gclk/hpl_gclk.c \ + $(TOP)/watch-library/hardware/hpl/mclk/hpl_mclk.c \ + $(TOP)/watch-library/hardware/hpl/osc32kctrl/hpl_osc32kctrl.c \ + $(TOP)/watch-library/hardware/hpl/oscctrl/hpl_oscctrl.c \ + $(TOP)/watch-library/hardware/hpl/pm/hpl_pm.c \ + $(TOP)/watch-library/hardware/hpl/sercom/hpl_sercom.c \ + $(TOP)/watch-library/hardware/hpl/slcd/hpl_slcd.c \ + $(TOP)/watch-library/hardware/hpl/systick/hpl_systick.c \ + $(TOP)/watch-library/shared/driver/lis2dh.c \ + $(TOP)/watch-library/shared/driver/lis2dw.c \ + $(TOP)/watch-library/shared/watch/watch_private_display.c \ + $(TOP)/watch-library/shared/watch/watch_utility.c \ DEFINES += \ -D__SAML22J18A__ \ -DDONT_USE_CMSIS_INIT +else + +CFLAGS += -W -Wall -Wextra -Wmissing-prototypes -Wmissing-declarations +CFLAGS += -Wno-format -Wno-unused-parameter + +INCLUDES += \ + -I$(TOP)/boards/$(BOARD) \ + -I$(TOP)/watch-library/shared/driver/ \ + -I$(TOP)/watch-library/shared/config/ \ + -I$(TOP)/watch-library/shared/watch/ \ + -I$(TOP)/watch-library/simulator/hpl/port/ \ + -I$(TOP)/watch-library/hardware/include/component \ + -I$(TOP)/watch-library/hardware/hal/include/ \ + -I$(TOP)/watch-library/hardware/hal/utils/include/ \ + -I$(TOP)/watch-library/hardware/hpl/slcd/ \ + -I$(TOP)/watch-library/hardware/hw/ \ + +SRCS += \ + $(TOP)/watch-library/simulator/main.c \ + $(TOP)/watch-library/simulator/watch/watch_rtc.c \ + $(TOP)/watch-library/simulator/watch/watch_slcd.c \ + $(TOP)/watch-library/simulator/watch/watch_extint.c \ + $(TOP)/watch-library/simulator/watch/watch_led.c \ + $(TOP)/watch-library/simulator/watch/watch_buzzer.c \ + $(TOP)/watch-library/simulator/watch/watch_adc.c \ + $(TOP)/watch-library/simulator/watch/watch_gpio.c \ + $(TOP)/watch-library/simulator/watch/watch_i2c.c \ + $(TOP)/watch-library/simulator/watch/watch_uart.c \ + $(TOP)/watch-library/simulator/watch/watch_deepsleep.c \ + $(TOP)/watch-library/simulator/watch/watch_private.c \ + $(TOP)/watch-library/simulator/watch/watch.c \ + $(TOP)/watch-library/shared/watch/watch_private_display.c \ + $(TOP)/watch-library/shared/watch/watch_utility.c \ + +endif + ifeq ($(LED), BLUE) CFLAGS += -DWATCH_SWAP_LED_PINS endif diff --git a/movement/README.md b/movement/README.md index 0e1c3b40..5d5b0e2f 100644 --- a/movement/README.md +++ b/movement/README.md @@ -22,13 +22,13 @@ A fifth optional function, `watch_face_wants_background_task`, will be added to To create a new watch face, you should create a new C header and source file in the watch-faces folder (i.e. for a watch face that displays moon phases: `moon_phase_face.h`, `moon_phase_face.c`), and implement these functions with your own unique prefix (i.e. `moon_phase_face_setup`). Then declare your watch face in your header file as follows: ```c -static const watch_face_t moon_phase_face = { - moon_phase_face_setup, - moon_phase_face_activate, - moon_phase_face_loop, - moon_phase_face_resign, - NULL // or moon_phase_face_wants_background_task, if you implemented this function -}; +#define moon_phase_face ((const watch_face_t){ \ + moon_phase_face_setup, \ + moon_phase_face_activate, \ + moon_phase_face_loop, \ + moon_phase_face_resign, \ + NULL, /* or moon_phase_face_wants_background_task, if you implemented this function */ \ +}) ``` This section will go over how each function works. The section headings use the watch_face prefix, but know that you should implement each function with your own prefix as described above. @@ -96,13 +96,13 @@ void pulsometer_face_activate(movement_settings_t *settings, void *context); bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void pulsometer_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t pulsometer_face = { - pulsometer_face_setup, - pulsometer_face_activate, - pulsometer_face_loop, - pulsometer_face_resign, - NULL -}; +#define pulsometer_face ((const watch_face_t){ \ + pulsometer_face_setup, \ + pulsometer_face_activate, \ + pulsometer_face_loop, \ + pulsometer_face_resign, \ + NULL, \ +}) ``` ### pulsometer_face.c diff --git a/movement/lib/TOTP-MCU/TOTP.c b/movement/lib/TOTP-MCU/TOTP.c index d977d06e..02858611 100644 --- a/movement/lib/TOTP-MCU/TOTP.c +++ b/movement/lib/TOTP-MCU/TOTP.c @@ -17,7 +17,7 @@ void setTimezone(uint8_t timezone){ _timeZoneOffset = timezone; } -uint32_t TimeStruct2Timestamp(struct tm time){ +static uint32_t TimeStruct2Timestamp(struct tm time){ //time.tm_mon -= 1; //time.tm_year -= 1900; return mktime(&(time)) - (_timeZoneOffset * 3600) - 2208988800; diff --git a/movement/lib/TOTP-MCU/sha1.c b/movement/lib/TOTP-MCU/sha1.c index 3ac14856..21a24fa5 100644 --- a/movement/lib/TOTP-MCU/sha1.c +++ b/movement/lib/TOTP-MCU/sha1.c @@ -34,11 +34,11 @@ void init(void) { bufferOffset = 0; } -uint32_t rol32(uint32_t number, uint8_t bits) { +static uint32_t rol32(uint32_t number, uint8_t bits) { return ((number << bits) | (uint32_t)(number >> (32-bits))); } -void hashBlock(void) { +static void hashBlock(void) { uint8_t i; uint32_t a,b,c,d,e,t; @@ -75,7 +75,7 @@ void hashBlock(void) { state.w[4] += e; } -void addUncounted(uint8_t data) { +static void addUncounted(uint8_t data) { buffer.b[bufferOffset ^ 3] = data; bufferOffset++; if (bufferOffset == BLOCK_LENGTH) { @@ -97,7 +97,7 @@ void writeArray(uint8_t *buffer, uint8_t size){ } } -void pad(void) { +static void pad(void) { // Implement SHA-1 padding (fips180-2 ��5.1.1) // Pad with 0x80 followed by 0x00 until the end of the block diff --git a/movement/movement.c b/movement/movement.c index 3dc1c060..d15c349f 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -29,6 +29,10 @@ #include "movement.h" #include "movement_config.h" +#if __EMSCRIPTEN__ +#include +#endif + movement_state_t movement_state; void * watch_face_contexts[MOVEMENT_NUM_FACES]; watch_date_time scheduled_tasks[MOVEMENT_NUM_FACES]; @@ -149,7 +153,16 @@ static void _movement_handle_scheduled_tasks(void) { void movement_request_tick_frequency(uint8_t freq) { if (freq == 128) return; // Movement uses the 128 Hz tick internally - RTC->MODE2.INTENCLR.reg = 0xFE; // disable all callbacks except the 128 Hz one + + // disable all callbacks except the 128 Hz one +#if __EMSCRIPTEN__ + for (int i = 1; i < 128; i = i << 1) { + watch_rtc_disable_periodic_callback(i); + } +#else + RTC->MODE2.INTENCLR.reg = 0xFE; +#endif + movement_state.subsecond = 0; movement_state.tick_frequency = freq; if (freq) watch_rtc_register_periodic_callback(cb_tick, freq); @@ -215,6 +228,18 @@ void app_init(void) { movement_state.light_ticks = -1; movement_state.alarm_ticks = -1; _movement_reset_inactivity_countdown(); + +#if __EMSCRIPTEN__ + int32_t time_zone_offset = EM_ASM_INT({ + return -new Date().getTimezoneOffset(); + }); + for (int i = 0, count = sizeof(movement_timezone_offsets) / sizeof(movement_timezone_offsets[0]); i < count; i++) { + if (movement_timezone_offsets[i] == time_zone_offset) { + movement_state.settings.bit.time_zone = i; + break; + } + } +#endif } void app_wake_from_backup(void) { diff --git a/movement/watch_faces/clock/simple_clock_face.h b/movement/watch_faces/clock/simple_clock_face.h index 98f997bf..6e8665bf 100644 --- a/movement/watch_faces/clock/simple_clock_face.h +++ b/movement/watch_faces/clock/simple_clock_face.h @@ -39,12 +39,12 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting void simple_clock_face_resign(movement_settings_t *settings, void *context); bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context); -static const watch_face_t simple_clock_face = { - simple_clock_face_setup, - simple_clock_face_activate, - simple_clock_face_loop, - simple_clock_face_resign, - simple_clock_face_wants_background_task -}; +#define simple_clock_face ((const watch_face_t){ \ + simple_clock_face_setup, \ + simple_clock_face_activate, \ + simple_clock_face_loop, \ + simple_clock_face_resign, \ + simple_clock_face_wants_background_task, \ +}) #endif // SIMPLE_CLOCK_FACE_H_ diff --git a/movement/watch_faces/clock/world_clock_face.h b/movement/watch_faces/clock/world_clock_face.h index b519bc85..36960f53 100644 --- a/movement/watch_faces/clock/world_clock_face.h +++ b/movement/watch_faces/clock/world_clock_face.h @@ -46,12 +46,12 @@ void world_clock_face_resign(movement_settings_t *settings, void *context); uint8_t world_clock_face_get_weekday(uint16_t day, uint16_t month, uint16_t year); -static const watch_face_t world_clock_face = { - world_clock_face_setup, - world_clock_face_activate, - world_clock_face_loop, - world_clock_face_resign, - NULL -}; +#define world_clock_face ((const watch_face_t){ \ + world_clock_face_setup, \ + world_clock_face_activate, \ + world_clock_face_loop, \ + world_clock_face_resign, \ + NULL, \ +}) #endif // WORLD_CLOCK_FACE_H_ diff --git a/movement/watch_faces/complications/beats_face.c b/movement/watch_faces/complications/beats_face.c index d1466b33..df31ad1c 100644 --- a/movement/watch_faces/complications/beats_face.c +++ b/movement/watch_faces/complications/beats_face.c @@ -45,7 +45,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void state->next_subsecond_update = (event.subsecond + 1 + (BEAT_REFRESH_FREQUENCY * 2 / 3)) % BEAT_REFRESH_FREQUENCY; state->last_centibeat_displayed = centibeats; } - sprintf(buf, "bt %6ld", centibeats); + sprintf(buf, "bt %6lu", centibeats); watch_display_string(buf, 0); break; @@ -53,7 +53,7 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void if (!watch_tick_animation_is_running()) watch_start_tick_animation(432); date_time = watch_rtc_get_date_time(); centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]); - sprintf(buf, "bt %4ld ", centibeats / 100); + sprintf(buf, "bt %4lu ", centibeats / 100); watch_display_string(buf, 0); break; diff --git a/movement/watch_faces/complications/beats_face.h b/movement/watch_faces/complications/beats_face.h index f11126d1..2bbbc26d 100644 --- a/movement/watch_faces/complications/beats_face.h +++ b/movement/watch_faces/complications/beats_face.h @@ -14,12 +14,12 @@ void beats_face_activate(movement_settings_t *settings, void *context); bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void beats_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t beats_face = { - beats_face_setup, - beats_face_activate, - beats_face_loop, - beats_face_resign, - NULL -}; +#define beats_face ((const watch_face_t){ \ + beats_face_setup, \ + beats_face_activate, \ + beats_face_loop, \ + beats_face_resign, \ + NULL, \ +}) #endif // BEATS_FACE_H_ \ No newline at end of file diff --git a/movement/watch_faces/complications/blinky_face.h b/movement/watch_faces/complications/blinky_face.h index 14f0e143..e966ab1d 100644 --- a/movement/watch_faces/complications/blinky_face.h +++ b/movement/watch_faces/complications/blinky_face.h @@ -38,12 +38,12 @@ void blinky_face_activate(movement_settings_t *settings, void *context); bool blinky_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void blinky_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t blinky_face = { - blinky_face_setup, - blinky_face_activate, - blinky_face_loop, - blinky_face_resign, - NULL -}; +#define blinky_face ((const watch_face_t){ \ + blinky_face_setup, \ + blinky_face_activate, \ + blinky_face_loop, \ + blinky_face_resign, \ + NULL, \ +}) -#endif // BLINKY_FACE_H_ \ No newline at end of file +#endif // BLINKY_FACE_H_ diff --git a/movement/watch_faces/complications/countdown_face.h b/movement/watch_faces/complications/countdown_face.h index 1a5d2c78..657c6377 100644 --- a/movement/watch_faces/complications/countdown_face.h +++ b/movement/watch_faces/complications/countdown_face.h @@ -58,12 +58,12 @@ void countdown_face_activate(movement_settings_t *settings, void *context); bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void countdown_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t countdown_face = { - countdown_face_setup, - countdown_face_activate, - countdown_face_loop, - countdown_face_resign, - NULL -}; +#define countdown_face ((const watch_face_t){ \ + countdown_face_setup, \ + countdown_face_activate, \ + countdown_face_loop, \ + countdown_face_resign, \ + NULL, \ +}) #endif // COUNTDOWN_FACE_H_ diff --git a/movement/watch_faces/complications/day_one_face.c b/movement/watch_faces/complications/day_one_face.c index 18d02d4d..99433990 100644 --- a/movement/watch_faces/complications/day_one_face.c +++ b/movement/watch_faces/complications/day_one_face.c @@ -37,7 +37,7 @@ static void _day_one_face_update(day_one_state_t state) { watch_date_time date_time = watch_rtc_get_date_time(); uint32_t julian_date = _day_one_face_juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day); uint32_t julian_birthdate = _day_one_face_juliandaynum(state.birth_year, state.birth_month, state.birth_day); - sprintf(buf, "DA %6ld", julian_date - julian_birthdate); + sprintf(buf, "DA %6lu", julian_date - julian_birthdate); watch_display_string(buf, 0); } diff --git a/movement/watch_faces/complications/day_one_face.h b/movement/watch_faces/complications/day_one_face.h index f39c7927..ab8372bf 100644 --- a/movement/watch_faces/complications/day_one_face.h +++ b/movement/watch_faces/complications/day_one_face.h @@ -44,12 +44,12 @@ void day_one_face_activate(movement_settings_t *settings, void *context); bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void day_one_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t day_one_face = { - day_one_face_setup, - day_one_face_activate, - day_one_face_loop, - day_one_face_resign, - NULL -}; +#define day_one_face ((const watch_face_t){ \ + day_one_face_setup, \ + day_one_face_activate, \ + day_one_face_loop, \ + day_one_face_resign, \ + NULL, \ +}) #endif // DAY_ONE_FACE_H_ diff --git a/movement/watch_faces/complications/pulsometer_face.h b/movement/watch_faces/complications/pulsometer_face.h index 65188604..600201e9 100644 --- a/movement/watch_faces/complications/pulsometer_face.h +++ b/movement/watch_faces/complications/pulsometer_face.h @@ -38,12 +38,12 @@ void pulsometer_face_activate(movement_settings_t *settings, void *context); bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void pulsometer_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t pulsometer_face = { - pulsometer_face_setup, - pulsometer_face_activate, - pulsometer_face_loop, - pulsometer_face_resign, - NULL -}; +#define pulsometer_face ((const watch_face_t){ \ + pulsometer_face_setup, \ + pulsometer_face_activate, \ + pulsometer_face_loop, \ + pulsometer_face_resign, \ + NULL, \ +}) -#endif // PULSOMETER_FACE_H_ \ No newline at end of file +#endif // PULSOMETER_FACE_H_ diff --git a/movement/watch_faces/complications/stopwatch_face.h b/movement/watch_faces/complications/stopwatch_face.h index ff0c1796..c6e3aadb 100644 --- a/movement/watch_faces/complications/stopwatch_face.h +++ b/movement/watch_faces/complications/stopwatch_face.h @@ -15,12 +15,12 @@ void stopwatch_face_activate(movement_settings_t *settings, void *context); bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void stopwatch_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t stopwatch_face = { - stopwatch_face_setup, - stopwatch_face_activate, - stopwatch_face_loop, - stopwatch_face_resign, - NULL -}; +#define stopwatch_face ((const watch_face_t){ \ + stopwatch_face_setup, \ + stopwatch_face_activate, \ + stopwatch_face_loop, \ + stopwatch_face_resign, \ + NULL, \ +}) -#endif // STOPWATCH_FACE_H_ \ No newline at end of file +#endif // STOPWATCH_FACE_H_ diff --git a/movement/watch_faces/complications/sunrise_sunset_face.h b/movement/watch_faces/complications/sunrise_sunset_face.h index 196b9db0..826d5e95 100644 --- a/movement/watch_faces/complications/sunrise_sunset_face.h +++ b/movement/watch_faces/complications/sunrise_sunset_face.h @@ -52,12 +52,12 @@ void sunrise_sunset_face_activate(movement_settings_t *settings, void *context); bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void sunrise_sunset_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t sunrise_sunset_face = { - sunrise_sunset_face_setup, - sunrise_sunset_face_activate, - sunrise_sunset_face_loop, - sunrise_sunset_face_resign, - NULL -}; +#define sunrise_sunset_face ((const watch_face_t){ \ + sunrise_sunset_face_setup, \ + sunrise_sunset_face_activate, \ + sunrise_sunset_face_loop, \ + sunrise_sunset_face_resign, \ + NULL, \ +}) #endif // SUNRISE_SUNSET_FACE_H_ diff --git a/movement/watch_faces/complications/totp_face.h b/movement/watch_faces/complications/totp_face.h index 1e2c5c02..dfa4a6d0 100644 --- a/movement/watch_faces/complications/totp_face.h +++ b/movement/watch_faces/complications/totp_face.h @@ -15,12 +15,12 @@ void totp_face_activate(movement_settings_t *settings, void *context); bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void totp_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t totp_face = { - totp_face_setup, - totp_face_activate, - totp_face_loop, - totp_face_resign, - NULL -}; +#define totp_face ((const watch_face_t){ \ + totp_face_setup, \ + totp_face_activate, \ + totp_face_loop, \ + totp_face_resign, \ + NULL, \ +}) #endif // TOTP_FACE_H_ diff --git a/movement/watch_faces/demos/character_set_face.h b/movement/watch_faces/demos/character_set_face.h index a6c8e17d..82627aed 100644 --- a/movement/watch_faces/demos/character_set_face.h +++ b/movement/watch_faces/demos/character_set_face.h @@ -32,12 +32,12 @@ void character_set_face_activate(movement_settings_t *settings, void *context); bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void character_set_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t character_set_face = { - character_set_face_setup, - character_set_face_activate, - character_set_face_loop, - character_set_face_resign, - NULL -}; +#define character_set_face ((const watch_face_t){ \ + character_set_face_setup, \ + character_set_face_activate, \ + character_set_face_loop, \ + character_set_face_resign, \ + NULL, \ +}) -#endif // CHARACTER_SET_FACE_H_ \ No newline at end of file +#endif // CHARACTER_SET_FACE_H_ diff --git a/movement/watch_faces/demos/demo_face.h b/movement/watch_faces/demos/demo_face.h index 6eb4298d..026e0d10 100644 --- a/movement/watch_faces/demos/demo_face.h +++ b/movement/watch_faces/demos/demo_face.h @@ -32,12 +32,12 @@ void demo_face_activate(movement_settings_t *settings, void *context); bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void demo_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t demo_face = { - demo_face_setup, - demo_face_activate, - demo_face_loop, - demo_face_resign, - NULL -}; +#define demo_face ((const watch_face_t){ \ + demo_face_setup, \ + demo_face_activate, \ + demo_face_loop, \ + demo_face_resign, \ + NULL, \ +}) -#endif // DEMO_FACE_H_ \ No newline at end of file +#endif // DEMO_FACE_H_ diff --git a/movement/watch_faces/demos/hello_there_face.h b/movement/watch_faces/demos/hello_there_face.h index c444e016..1140bb20 100644 --- a/movement/watch_faces/demos/hello_there_face.h +++ b/movement/watch_faces/demos/hello_there_face.h @@ -37,12 +37,12 @@ void hello_there_face_activate(movement_settings_t *settings, void *context); bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void hello_there_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t hello_there_face = { - hello_there_face_setup, - hello_there_face_activate, - hello_there_face_loop, - hello_there_face_resign, - NULL -}; +#define hello_there_face ((const watch_face_t){ \ + hello_there_face_setup, \ + hello_there_face_activate, \ + hello_there_face_loop, \ + hello_there_face_resign, \ + NULL, \ +}) #endif // HELLO_THERE_FACE_H_ diff --git a/movement/watch_faces/demos/lis2dh_logging_face.c b/movement/watch_faces/demos/lis2dh_logging_face.c index 08b265b6..31d1cad7 100644 --- a/movement/watch_faces/demos/lis2dh_logging_face.c +++ b/movement/watch_faces/demos/lis2dh_logging_face.c @@ -36,10 +36,11 @@ // Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last // 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode) -static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state, watch_date_time date_time) { +static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state) { char buf[14]; char time_indication_character; int8_t pos; + watch_date_time date_time; if (logger_state->log_ticks) { pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DH_LOGGING_NUM_DATA_POINTS; @@ -58,16 +59,16 @@ static void _lis2dh_logging_face_update_display(movement_settings_t *settings, l } switch (logger_state->axis_index) { case 0: - sprintf(buf, "3A%2d%02d%4ld", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts + logger_state->data[pos].y_interrupts + logger_state->data[pos].z_interrupts); + sprintf(buf, "3A%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts + logger_state->data[pos].y_interrupts + logger_state->data[pos].z_interrupts); break; case 1: - sprintf(buf, "XA%2d%02d%4ld", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts); + sprintf(buf, "XA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts); break; case 2: - sprintf(buf, "YA%2d%02d%4ld", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].y_interrupts); + sprintf(buf, "YA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].y_interrupts); break; case 3: - sprintf(buf, "ZA%2d%02d%4ld", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].z_interrupts); + sprintf(buf, "ZA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].z_interrupts); break; } } @@ -145,7 +146,6 @@ void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context; lis2dh_interrupt_state interrupt_state = 0; - watch_date_time date_time; switch (event.event_type) { case EVENT_MODE_BUTTON_UP: @@ -157,13 +157,13 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti case EVENT_LIGHT_BUTTON_DOWN: logger_state->axis_index = (logger_state->axis_index + 1) % 4; logger_state->log_ticks = 255; - _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state, date_time); + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); break; case EVENT_ALARM_BUTTON_UP: if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DH_LOGGING_NUM_DATA_POINTS; logger_state->log_ticks = 255; logger_state->axis_index = 0; - _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state, date_time); + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); break; case EVENT_ACTIVATE: case EVENT_TICK: @@ -182,7 +182,7 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti } else { watch_clear_indicator(WATCH_INDICATOR_SIGNAL); } - _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state, date_time); + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); break; case EVENT_BACKGROUND_TASK: _lis2dh_logging_face_log_data(logger_state); diff --git a/movement/watch_faces/demos/lis2dh_logging_face.h b/movement/watch_faces/demos/lis2dh_logging_face.h index 22ecd2d9..49366542 100644 --- a/movement/watch_faces/demos/lis2dh_logging_face.h +++ b/movement/watch_faces/demos/lis2dh_logging_face.h @@ -55,12 +55,12 @@ bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *setti void lis2dh_logging_face_resign(movement_settings_t *settings, void *context); bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context); -static const watch_face_t lis2dh_logging_face = { - lis2dh_logging_face_setup, - lis2dh_logging_face_activate, - lis2dh_logging_face_loop, - lis2dh_logging_face_resign, - lis2dh_logging_face_wants_background_task -}; +#define lis2dh_logging_face ((const watch_face_t){ \ + lis2dh_logging_face_setup, \ + lis2dh_logging_face_activate, \ + lis2dh_logging_face_loop, \ + lis2dh_logging_face_resign, \ + lis2dh_logging_face_wants_background_task, \ +}) #endif // LIS2DH_LOGGING_FACE_H_ diff --git a/movement/watch_faces/demos/voltage_face.c b/movement/watch_faces/demos/voltage_face.c index 4e5fecc1..24346aa3 100644 --- a/movement/watch_faces/demos/voltage_face.c +++ b/movement/watch_faces/demos/voltage_face.c @@ -86,6 +86,6 @@ void voltage_face_resign(movement_settings_t *settings, void *context) { (void) settings; (void) context; // make sure to restore the default in the end. - watch_set_analog_reference_voltage(ADC_REFCTRL_REFSEL_INTVCC2_Val); + watch_set_analog_reference_voltage(ADC_REFERENCE_VCC); watch_disable_adc(); } diff --git a/movement/watch_faces/demos/voltage_face.h b/movement/watch_faces/demos/voltage_face.h index 07d9e473..dc5e631b 100644 --- a/movement/watch_faces/demos/voltage_face.h +++ b/movement/watch_faces/demos/voltage_face.h @@ -32,12 +32,12 @@ void voltage_face_activate(movement_settings_t *settings, void *context); bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void voltage_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t voltage_face = { - voltage_face_setup, - voltage_face_activate, - voltage_face_loop, - voltage_face_resign, - NULL -}; +#define voltage_face ((const watch_face_t){ \ + voltage_face_setup, \ + voltage_face_activate, \ + voltage_face_loop, \ + voltage_face_resign, \ + NULL, \ +}) -#endif // VOLTAGE_FACE_H_ \ No newline at end of file +#endif // VOLTAGE_FACE_H_ diff --git a/movement/watch_faces/settings/preferences_face.h b/movement/watch_faces/settings/preferences_face.h index 11f9dc43..b178bfd2 100644 --- a/movement/watch_faces/settings/preferences_face.h +++ b/movement/watch_faces/settings/preferences_face.h @@ -32,12 +32,12 @@ void preferences_face_activate(movement_settings_t *settings, void *context); bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void preferences_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t preferences_face = { - preferences_face_setup, - preferences_face_activate, - preferences_face_loop, - preferences_face_resign, - NULL -}; +#define preferences_face ((const watch_face_t){ \ + preferences_face_setup, \ + preferences_face_activate, \ + preferences_face_loop, \ + preferences_face_resign, \ + NULL, \ +}) -#endif // PREFERENCES_FACE_H_ \ No newline at end of file +#endif // PREFERENCES_FACE_H_ diff --git a/movement/watch_faces/settings/set_time_face.h b/movement/watch_faces/settings/set_time_face.h index ebc3d8d4..c86b6376 100644 --- a/movement/watch_faces/settings/set_time_face.h +++ b/movement/watch_faces/settings/set_time_face.h @@ -32,12 +32,12 @@ void set_time_face_activate(movement_settings_t *settings, void *context); bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void set_time_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t set_time_face = { - set_time_face_setup, - set_time_face_activate, - set_time_face_loop, - set_time_face_resign, - NULL -}; +#define set_time_face ((const watch_face_t){ \ + set_time_face_setup, \ + set_time_face_activate, \ + set_time_face_loop, \ + set_time_face_resign, \ + NULL, \ +}) #endif // SET_TIME_FACE_H_ diff --git a/movement/watch_faces/thermistor/thermistor_logging_face.h b/movement/watch_faces/thermistor/thermistor_logging_face.h index effb8822..4ba593ec 100644 --- a/movement/watch_faces/thermistor/thermistor_logging_face.h +++ b/movement/watch_faces/thermistor/thermistor_logging_face.h @@ -48,12 +48,12 @@ bool thermistor_logging_face_loop(movement_event_t event, movement_settings_t *s void thermistor_logging_face_resign(movement_settings_t *settings, void *context); bool thermistor_logging_face_wants_background_task(movement_settings_t *settings, void *context); -static const watch_face_t thermistor_logging_face = { - thermistor_logging_face_setup, - thermistor_logging_face_activate, - thermistor_logging_face_loop, - thermistor_logging_face_resign, - thermistor_logging_face_wants_background_task -}; +#define thermistor_logging_face ((const watch_face_t){ \ + thermistor_logging_face_setup, \ + thermistor_logging_face_activate, \ + thermistor_logging_face_loop, \ + thermistor_logging_face_resign, \ + thermistor_logging_face_wants_background_task, \ +}) #endif // THERMISTOR_LOGGING_FACE_H_ diff --git a/movement/watch_faces/thermistor/thermistor_readout_face.h b/movement/watch_faces/thermistor/thermistor_readout_face.h index 5b14fc5b..7361164e 100644 --- a/movement/watch_faces/thermistor/thermistor_readout_face.h +++ b/movement/watch_faces/thermistor/thermistor_readout_face.h @@ -32,12 +32,12 @@ void thermistor_readout_face_activate(movement_settings_t *settings, void *conte bool thermistor_readout_face_loop(movement_event_t event, movement_settings_t *settings, void *context); void thermistor_readout_face_resign(movement_settings_t *settings, void *context); -static const watch_face_t thermistor_readout_face = { - thermistor_readout_face_setup, - thermistor_readout_face_activate, - thermistor_readout_face_loop, - thermistor_readout_face_resign, - NULL -}; +#define thermistor_readout_face ((const watch_face_t){ \ + thermistor_readout_face_setup, \ + thermistor_readout_face_activate, \ + thermistor_readout_face_loop, \ + thermistor_readout_face_resign, \ + NULL, \ +}) #endif // THERMISTOR_READOUT_FACE_H_ diff --git a/rules.mk b/rules.mk index f0979f3f..cd42a433 100644 --- a/rules.mk +++ b/rules.mk @@ -4,7 +4,17 @@ OBJS = $(addprefix $(BUILD)/, $(notdir %/$(subst .c,.o, $(SRCS)))) SUBMODULES = tinyusb +ifndef EMSCRIPTEN all: directory $(SUBMODULES) $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size +else +all: directory $(SUBMODULES) $(BUILD)/$(BIN).html +endif + +$(BUILD)/$(BIN).html: $(OBJS) + @echo HTML $@ + @$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ \ + -s EXPORTED_FUNCTIONS=_main \ + --shell-file=$(TOP)/watch-library/simulator/shell.html $(BUILD)/$(BIN).elf: $(OBJS) @echo LD $@ diff --git a/watch-library/hal/documentation/ext_irq.rst b/watch-library/hardware/hal/documentation/ext_irq.rst similarity index 100% rename from watch-library/hal/documentation/ext_irq.rst rename to watch-library/hardware/hal/documentation/ext_irq.rst diff --git a/watch-library/hal/documentation/flash.rst b/watch-library/hardware/hal/documentation/flash.rst similarity index 100% rename from watch-library/hal/documentation/flash.rst rename to watch-library/hardware/hal/documentation/flash.rst diff --git a/watch-library/hal/documentation/i2c_master_sync.rst b/watch-library/hardware/hal/documentation/i2c_master_sync.rst similarity index 100% rename from watch-library/hal/documentation/i2c_master_sync.rst rename to watch-library/hardware/hal/documentation/i2c_master_sync.rst diff --git a/watch-library/hal/documentation/rand_sync.rst b/watch-library/hardware/hal/documentation/rand_sync.rst similarity index 100% rename from watch-library/hal/documentation/rand_sync.rst rename to watch-library/hardware/hal/documentation/rand_sync.rst diff --git a/watch-library/hal/documentation/slcd_sync.rst b/watch-library/hardware/hal/documentation/slcd_sync.rst similarity index 100% rename from watch-library/hal/documentation/slcd_sync.rst rename to watch-library/hardware/hal/documentation/slcd_sync.rst diff --git a/watch-library/hal/documentation/spi_master_sync.rst b/watch-library/hardware/hal/documentation/spi_master_sync.rst similarity index 100% rename from watch-library/hal/documentation/spi_master_sync.rst rename to watch-library/hardware/hal/documentation/spi_master_sync.rst diff --git a/watch-library/hal/documentation/usart_sync.rst b/watch-library/hardware/hal/documentation/usart_sync.rst similarity index 100% rename from watch-library/hal/documentation/usart_sync.rst rename to watch-library/hardware/hal/documentation/usart_sync.rst diff --git a/watch-library/hal/include/hal_atomic.h b/watch-library/hardware/hal/include/hal_atomic.h similarity index 100% rename from watch-library/hal/include/hal_atomic.h rename to watch-library/hardware/hal/include/hal_atomic.h diff --git a/watch-library/hal/include/hal_calendar.h b/watch-library/hardware/hal/include/hal_calendar.h similarity index 100% rename from watch-library/hal/include/hal_calendar.h rename to watch-library/hardware/hal/include/hal_calendar.h diff --git a/watch-library/hal/include/hal_delay.h b/watch-library/hardware/hal/include/hal_delay.h similarity index 100% rename from watch-library/hal/include/hal_delay.h rename to watch-library/hardware/hal/include/hal_delay.h diff --git a/watch-library/hal/include/hal_ext_irq.h b/watch-library/hardware/hal/include/hal_ext_irq.h similarity index 100% rename from watch-library/hal/include/hal_ext_irq.h rename to watch-library/hardware/hal/include/hal_ext_irq.h diff --git a/watch-library/hal/include/hal_flash.h b/watch-library/hardware/hal/include/hal_flash.h similarity index 100% rename from watch-library/hal/include/hal_flash.h rename to watch-library/hardware/hal/include/hal_flash.h diff --git a/watch-library/hal/include/hal_gpio.h b/watch-library/hardware/hal/include/hal_gpio.h similarity index 100% rename from watch-library/hal/include/hal_gpio.h rename to watch-library/hardware/hal/include/hal_gpio.h diff --git a/watch-library/hal/include/hal_i2c_m_sync.h b/watch-library/hardware/hal/include/hal_i2c_m_sync.h similarity index 100% rename from watch-library/hal/include/hal_i2c_m_sync.h rename to watch-library/hardware/hal/include/hal_i2c_m_sync.h diff --git a/watch-library/hal/include/hal_init.h b/watch-library/hardware/hal/include/hal_init.h similarity index 100% rename from watch-library/hal/include/hal_init.h rename to watch-library/hardware/hal/include/hal_init.h diff --git a/watch-library/hal/include/hal_io.h b/watch-library/hardware/hal/include/hal_io.h similarity index 100% rename from watch-library/hal/include/hal_io.h rename to watch-library/hardware/hal/include/hal_io.h diff --git a/watch-library/hal/include/hal_rand_sync.h b/watch-library/hardware/hal/include/hal_rand_sync.h similarity index 100% rename from watch-library/hal/include/hal_rand_sync.h rename to watch-library/hardware/hal/include/hal_rand_sync.h diff --git a/watch-library/hal/include/hal_slcd_sync.h b/watch-library/hardware/hal/include/hal_slcd_sync.h similarity index 100% rename from watch-library/hal/include/hal_slcd_sync.h rename to watch-library/hardware/hal/include/hal_slcd_sync.h diff --git a/watch-library/hal/include/hal_sleep.h b/watch-library/hardware/hal/include/hal_sleep.h similarity index 100% rename from watch-library/hal/include/hal_sleep.h rename to watch-library/hardware/hal/include/hal_sleep.h diff --git a/watch-library/hal/include/hal_spi_m_sync.h b/watch-library/hardware/hal/include/hal_spi_m_sync.h similarity index 100% rename from watch-library/hal/include/hal_spi_m_sync.h rename to watch-library/hardware/hal/include/hal_spi_m_sync.h diff --git a/watch-library/hal/include/hal_usart_sync.h b/watch-library/hardware/hal/include/hal_usart_sync.h similarity index 100% rename from watch-library/hal/include/hal_usart_sync.h rename to watch-library/hardware/hal/include/hal_usart_sync.h diff --git a/watch-library/hal/include/hpl_calendar.h b/watch-library/hardware/hal/include/hpl_calendar.h similarity index 100% rename from watch-library/hal/include/hpl_calendar.h rename to watch-library/hardware/hal/include/hpl_calendar.h diff --git a/watch-library/hal/include/hpl_core.h b/watch-library/hardware/hal/include/hpl_core.h similarity index 100% rename from watch-library/hal/include/hpl_core.h rename to watch-library/hardware/hal/include/hpl_core.h diff --git a/watch-library/hal/include/hpl_delay.h b/watch-library/hardware/hal/include/hpl_delay.h similarity index 100% rename from watch-library/hal/include/hpl_delay.h rename to watch-library/hardware/hal/include/hpl_delay.h diff --git a/watch-library/hal/include/hpl_dma.h b/watch-library/hardware/hal/include/hpl_dma.h similarity index 100% rename from watch-library/hal/include/hpl_dma.h rename to watch-library/hardware/hal/include/hpl_dma.h diff --git a/watch-library/hal/include/hpl_ext_irq.h b/watch-library/hardware/hal/include/hpl_ext_irq.h similarity index 100% rename from watch-library/hal/include/hpl_ext_irq.h rename to watch-library/hardware/hal/include/hpl_ext_irq.h diff --git a/watch-library/hal/include/hpl_flash.h b/watch-library/hardware/hal/include/hpl_flash.h similarity index 100% rename from watch-library/hal/include/hpl_flash.h rename to watch-library/hardware/hal/include/hpl_flash.h diff --git a/watch-library/hal/include/hpl_gpio.h b/watch-library/hardware/hal/include/hpl_gpio.h similarity index 100% rename from watch-library/hal/include/hpl_gpio.h rename to watch-library/hardware/hal/include/hpl_gpio.h diff --git a/watch-library/hal/include/hpl_i2c_m_async.h b/watch-library/hardware/hal/include/hpl_i2c_m_async.h similarity index 100% rename from watch-library/hal/include/hpl_i2c_m_async.h rename to watch-library/hardware/hal/include/hpl_i2c_m_async.h diff --git a/watch-library/hal/include/hpl_i2c_m_sync.h b/watch-library/hardware/hal/include/hpl_i2c_m_sync.h similarity index 100% rename from watch-library/hal/include/hpl_i2c_m_sync.h rename to watch-library/hardware/hal/include/hpl_i2c_m_sync.h diff --git a/watch-library/hal/include/hpl_i2c_s_async.h b/watch-library/hardware/hal/include/hpl_i2c_s_async.h similarity index 100% rename from watch-library/hal/include/hpl_i2c_s_async.h rename to watch-library/hardware/hal/include/hpl_i2c_s_async.h diff --git a/watch-library/hal/include/hpl_i2c_s_sync.h b/watch-library/hardware/hal/include/hpl_i2c_s_sync.h similarity index 100% rename from watch-library/hal/include/hpl_i2c_s_sync.h rename to watch-library/hardware/hal/include/hpl_i2c_s_sync.h diff --git a/watch-library/hal/include/hpl_init.h b/watch-library/hardware/hal/include/hpl_init.h similarity index 100% rename from watch-library/hal/include/hpl_init.h rename to watch-library/hardware/hal/include/hpl_init.h diff --git a/watch-library/hal/include/hpl_irq.h b/watch-library/hardware/hal/include/hpl_irq.h similarity index 100% rename from watch-library/hal/include/hpl_irq.h rename to watch-library/hardware/hal/include/hpl_irq.h diff --git a/watch-library/hal/include/hpl_missing_features.h b/watch-library/hardware/hal/include/hpl_missing_features.h similarity index 100% rename from watch-library/hal/include/hpl_missing_features.h rename to watch-library/hardware/hal/include/hpl_missing_features.h diff --git a/watch-library/hal/include/hpl_rand_sync.h b/watch-library/hardware/hal/include/hpl_rand_sync.h similarity index 100% rename from watch-library/hal/include/hpl_rand_sync.h rename to watch-library/hardware/hal/include/hpl_rand_sync.h diff --git a/watch-library/hal/include/hpl_reset.h b/watch-library/hardware/hal/include/hpl_reset.h similarity index 100% rename from watch-library/hal/include/hpl_reset.h rename to watch-library/hardware/hal/include/hpl_reset.h diff --git a/watch-library/hal/include/hpl_slcd.h b/watch-library/hardware/hal/include/hpl_slcd.h similarity index 100% rename from watch-library/hal/include/hpl_slcd.h rename to watch-library/hardware/hal/include/hpl_slcd.h diff --git a/watch-library/hal/include/hpl_slcd_sync.h b/watch-library/hardware/hal/include/hpl_slcd_sync.h similarity index 100% rename from watch-library/hal/include/hpl_slcd_sync.h rename to watch-library/hardware/hal/include/hpl_slcd_sync.h diff --git a/watch-library/hal/include/hpl_sleep.h b/watch-library/hardware/hal/include/hpl_sleep.h similarity index 100% rename from watch-library/hal/include/hpl_sleep.h rename to watch-library/hardware/hal/include/hpl_sleep.h diff --git a/watch-library/hal/include/hpl_spi.h b/watch-library/hardware/hal/include/hpl_spi.h similarity index 100% rename from watch-library/hal/include/hpl_spi.h rename to watch-library/hardware/hal/include/hpl_spi.h diff --git a/watch-library/hal/include/hpl_spi_async.h b/watch-library/hardware/hal/include/hpl_spi_async.h similarity index 100% rename from watch-library/hal/include/hpl_spi_async.h rename to watch-library/hardware/hal/include/hpl_spi_async.h diff --git a/watch-library/hal/include/hpl_spi_dma.h b/watch-library/hardware/hal/include/hpl_spi_dma.h similarity index 100% rename from watch-library/hal/include/hpl_spi_dma.h rename to watch-library/hardware/hal/include/hpl_spi_dma.h diff --git a/watch-library/hal/include/hpl_spi_m_async.h b/watch-library/hardware/hal/include/hpl_spi_m_async.h similarity index 100% rename from watch-library/hal/include/hpl_spi_m_async.h rename to watch-library/hardware/hal/include/hpl_spi_m_async.h diff --git a/watch-library/hal/include/hpl_spi_m_dma.h b/watch-library/hardware/hal/include/hpl_spi_m_dma.h similarity index 100% rename from watch-library/hal/include/hpl_spi_m_dma.h rename to watch-library/hardware/hal/include/hpl_spi_m_dma.h diff --git a/watch-library/hal/include/hpl_spi_m_sync.h b/watch-library/hardware/hal/include/hpl_spi_m_sync.h similarity index 100% rename from watch-library/hal/include/hpl_spi_m_sync.h rename to watch-library/hardware/hal/include/hpl_spi_m_sync.h diff --git a/watch-library/hal/include/hpl_spi_s_async.h b/watch-library/hardware/hal/include/hpl_spi_s_async.h similarity index 100% rename from watch-library/hal/include/hpl_spi_s_async.h rename to watch-library/hardware/hal/include/hpl_spi_s_async.h diff --git a/watch-library/hal/include/hpl_spi_s_sync.h b/watch-library/hardware/hal/include/hpl_spi_s_sync.h similarity index 100% rename from watch-library/hal/include/hpl_spi_s_sync.h rename to watch-library/hardware/hal/include/hpl_spi_s_sync.h diff --git a/watch-library/hal/include/hpl_spi_sync.h b/watch-library/hardware/hal/include/hpl_spi_sync.h similarity index 100% rename from watch-library/hal/include/hpl_spi_sync.h rename to watch-library/hardware/hal/include/hpl_spi_sync.h diff --git a/watch-library/hal/include/hpl_time_measure.h b/watch-library/hardware/hal/include/hpl_time_measure.h similarity index 100% rename from watch-library/hal/include/hpl_time_measure.h rename to watch-library/hardware/hal/include/hpl_time_measure.h diff --git a/watch-library/hal/include/hpl_timer.h b/watch-library/hardware/hal/include/hpl_timer.h similarity index 100% rename from watch-library/hal/include/hpl_timer.h rename to watch-library/hardware/hal/include/hpl_timer.h diff --git a/watch-library/hal/include/hpl_usart.h b/watch-library/hardware/hal/include/hpl_usart.h similarity index 100% rename from watch-library/hal/include/hpl_usart.h rename to watch-library/hardware/hal/include/hpl_usart.h diff --git a/watch-library/hal/include/hpl_usart_async.h b/watch-library/hardware/hal/include/hpl_usart_async.h similarity index 100% rename from watch-library/hal/include/hpl_usart_async.h rename to watch-library/hardware/hal/include/hpl_usart_async.h diff --git a/watch-library/hal/include/hpl_usart_sync.h b/watch-library/hardware/hal/include/hpl_usart_sync.h similarity index 100% rename from watch-library/hal/include/hpl_usart_sync.h rename to watch-library/hardware/hal/include/hpl_usart_sync.h diff --git a/watch-library/hal/include/hpl_user_area.h b/watch-library/hardware/hal/include/hpl_user_area.h similarity index 100% rename from watch-library/hal/include/hpl_user_area.h rename to watch-library/hardware/hal/include/hpl_user_area.h diff --git a/watch-library/hal/src/hal_atomic.c b/watch-library/hardware/hal/src/hal_atomic.c similarity index 100% rename from watch-library/hal/src/hal_atomic.c rename to watch-library/hardware/hal/src/hal_atomic.c diff --git a/watch-library/hal/src/hal_calendar.c b/watch-library/hardware/hal/src/hal_calendar.c similarity index 100% rename from watch-library/hal/src/hal_calendar.c rename to watch-library/hardware/hal/src/hal_calendar.c diff --git a/watch-library/hal/src/hal_delay.c b/watch-library/hardware/hal/src/hal_delay.c similarity index 100% rename from watch-library/hal/src/hal_delay.c rename to watch-library/hardware/hal/src/hal_delay.c diff --git a/watch-library/hal/src/hal_ext_irq.c b/watch-library/hardware/hal/src/hal_ext_irq.c similarity index 100% rename from watch-library/hal/src/hal_ext_irq.c rename to watch-library/hardware/hal/src/hal_ext_irq.c diff --git a/watch-library/hal/src/hal_flash.c b/watch-library/hardware/hal/src/hal_flash.c similarity index 100% rename from watch-library/hal/src/hal_flash.c rename to watch-library/hardware/hal/src/hal_flash.c diff --git a/watch-library/hal/src/hal_gpio.c b/watch-library/hardware/hal/src/hal_gpio.c similarity index 100% rename from watch-library/hal/src/hal_gpio.c rename to watch-library/hardware/hal/src/hal_gpio.c diff --git a/watch-library/hal/src/hal_i2c_m_sync.c b/watch-library/hardware/hal/src/hal_i2c_m_sync.c similarity index 100% rename from watch-library/hal/src/hal_i2c_m_sync.c rename to watch-library/hardware/hal/src/hal_i2c_m_sync.c diff --git a/watch-library/hal/src/hal_init.c b/watch-library/hardware/hal/src/hal_init.c similarity index 100% rename from watch-library/hal/src/hal_init.c rename to watch-library/hardware/hal/src/hal_init.c diff --git a/watch-library/hal/src/hal_io.c b/watch-library/hardware/hal/src/hal_io.c similarity index 100% rename from watch-library/hal/src/hal_io.c rename to watch-library/hardware/hal/src/hal_io.c diff --git a/watch-library/hal/src/hal_rand_sync.c b/watch-library/hardware/hal/src/hal_rand_sync.c similarity index 100% rename from watch-library/hal/src/hal_rand_sync.c rename to watch-library/hardware/hal/src/hal_rand_sync.c diff --git a/watch-library/hal/src/hal_slcd_sync.c b/watch-library/hardware/hal/src/hal_slcd_sync.c similarity index 100% rename from watch-library/hal/src/hal_slcd_sync.c rename to watch-library/hardware/hal/src/hal_slcd_sync.c diff --git a/watch-library/hal/src/hal_sleep.c b/watch-library/hardware/hal/src/hal_sleep.c similarity index 100% rename from watch-library/hal/src/hal_sleep.c rename to watch-library/hardware/hal/src/hal_sleep.c diff --git a/watch-library/hal/src/hal_spi_m_sync.c b/watch-library/hardware/hal/src/hal_spi_m_sync.c similarity index 100% rename from watch-library/hal/src/hal_spi_m_sync.c rename to watch-library/hardware/hal/src/hal_spi_m_sync.c diff --git a/watch-library/hal/src/hal_usart_sync.c b/watch-library/hardware/hal/src/hal_usart_sync.c similarity index 100% rename from watch-library/hal/src/hal_usart_sync.c rename to watch-library/hardware/hal/src/hal_usart_sync.c diff --git a/watch-library/hal/utils/include/compiler.h b/watch-library/hardware/hal/utils/include/compiler.h similarity index 98% rename from watch-library/hal/utils/include/compiler.h rename to watch-library/hardware/hal/utils/include/compiler.h index f35db3df..010b2637 100644 --- a/watch-library/hal/utils/include/compiler.h +++ b/watch-library/hardware/hal/utils/include/compiler.h @@ -52,9 +52,11 @@ extern "C" { #include #include +#ifndef __EMSCRIPTEN__ #ifndef _UNIT_TEST_ #include "parts.h" #endif +#endif #include "err_codes.h" #ifdef __cplusplus diff --git a/watch-library/hal/utils/include/err_codes.h b/watch-library/hardware/hal/utils/include/err_codes.h similarity index 100% rename from watch-library/hal/utils/include/err_codes.h rename to watch-library/hardware/hal/utils/include/err_codes.h diff --git a/watch-library/hal/utils/include/events.h b/watch-library/hardware/hal/utils/include/events.h similarity index 100% rename from watch-library/hal/utils/include/events.h rename to watch-library/hardware/hal/utils/include/events.h diff --git a/watch-library/hal/utils/include/parts.h b/watch-library/hardware/hal/utils/include/parts.h similarity index 100% rename from watch-library/hal/utils/include/parts.h rename to watch-library/hardware/hal/utils/include/parts.h diff --git a/watch-library/hal/utils/include/utils.h b/watch-library/hardware/hal/utils/include/utils.h similarity index 100% rename from watch-library/hal/utils/include/utils.h rename to watch-library/hardware/hal/utils/include/utils.h diff --git a/watch-library/hal/utils/include/utils_assert.h b/watch-library/hardware/hal/utils/include/utils_assert.h similarity index 100% rename from watch-library/hal/utils/include/utils_assert.h rename to watch-library/hardware/hal/utils/include/utils_assert.h diff --git a/watch-library/hal/utils/include/utils_decrement_macro.h b/watch-library/hardware/hal/utils/include/utils_decrement_macro.h similarity index 100% rename from watch-library/hal/utils/include/utils_decrement_macro.h rename to watch-library/hardware/hal/utils/include/utils_decrement_macro.h diff --git a/watch-library/hal/utils/include/utils_event.h b/watch-library/hardware/hal/utils/include/utils_event.h similarity index 100% rename from watch-library/hal/utils/include/utils_event.h rename to watch-library/hardware/hal/utils/include/utils_event.h diff --git a/watch-library/hal/utils/include/utils_increment_macro.h b/watch-library/hardware/hal/utils/include/utils_increment_macro.h similarity index 100% rename from watch-library/hal/utils/include/utils_increment_macro.h rename to watch-library/hardware/hal/utils/include/utils_increment_macro.h diff --git a/watch-library/hal/utils/include/utils_list.h b/watch-library/hardware/hal/utils/include/utils_list.h similarity index 100% rename from watch-library/hal/utils/include/utils_list.h rename to watch-library/hardware/hal/utils/include/utils_list.h diff --git a/watch-library/hal/utils/include/utils_recursion_macro.h b/watch-library/hardware/hal/utils/include/utils_recursion_macro.h similarity index 100% rename from watch-library/hal/utils/include/utils_recursion_macro.h rename to watch-library/hardware/hal/utils/include/utils_recursion_macro.h diff --git a/watch-library/hal/utils/include/utils_repeat_macro.h b/watch-library/hardware/hal/utils/include/utils_repeat_macro.h similarity index 100% rename from watch-library/hal/utils/include/utils_repeat_macro.h rename to watch-library/hardware/hal/utils/include/utils_repeat_macro.h diff --git a/watch-library/hal/utils/src/utils_assert.c b/watch-library/hardware/hal/utils/src/utils_assert.c similarity index 100% rename from watch-library/hal/utils/src/utils_assert.c rename to watch-library/hardware/hal/utils/src/utils_assert.c diff --git a/watch-library/hal/utils/src/utils_event.c b/watch-library/hardware/hal/utils/src/utils_event.c similarity index 100% rename from watch-library/hal/utils/src/utils_event.c rename to watch-library/hardware/hal/utils/src/utils_event.c diff --git a/watch-library/hal/utils/src/utils_list.c b/watch-library/hardware/hal/utils/src/utils_list.c similarity index 100% rename from watch-library/hal/utils/src/utils_list.c rename to watch-library/hardware/hal/utils/src/utils_list.c diff --git a/watch-library/hal/utils/src/utils_syscalls.c b/watch-library/hardware/hal/utils/src/utils_syscalls.c similarity index 100% rename from watch-library/hal/utils/src/utils_syscalls.c rename to watch-library/hardware/hal/utils/src/utils_syscalls.c diff --git a/watch-library/hpl/core/hpl_core_m0plus_base.c b/watch-library/hardware/hpl/core/hpl_core_m0plus_base.c similarity index 100% rename from watch-library/hpl/core/hpl_core_m0plus_base.c rename to watch-library/hardware/hpl/core/hpl_core_m0plus_base.c diff --git a/watch-library/hpl/core/hpl_core_port.h b/watch-library/hardware/hpl/core/hpl_core_port.h similarity index 100% rename from watch-library/hpl/core/hpl_core_port.h rename to watch-library/hardware/hpl/core/hpl_core_port.h diff --git a/watch-library/hpl/core/hpl_init.c b/watch-library/hardware/hpl/core/hpl_init.c similarity index 100% rename from watch-library/hpl/core/hpl_init.c rename to watch-library/hardware/hpl/core/hpl_init.c diff --git a/watch-library/hpl/dmac/hpl_dmac.c b/watch-library/hardware/hpl/dmac/hpl_dmac.c similarity index 100% rename from watch-library/hpl/dmac/hpl_dmac.c rename to watch-library/hardware/hpl/dmac/hpl_dmac.c diff --git a/watch-library/hpl/eic/hpl_eic.c b/watch-library/hardware/hpl/eic/hpl_eic.c similarity index 100% rename from watch-library/hpl/eic/hpl_eic.c rename to watch-library/hardware/hpl/eic/hpl_eic.c diff --git a/watch-library/hpl/gclk/hpl_gclk.c b/watch-library/hardware/hpl/gclk/hpl_gclk.c similarity index 100% rename from watch-library/hpl/gclk/hpl_gclk.c rename to watch-library/hardware/hpl/gclk/hpl_gclk.c diff --git a/watch-library/hpl/gclk/hpl_gclk_base.h b/watch-library/hardware/hpl/gclk/hpl_gclk_base.h similarity index 100% rename from watch-library/hpl/gclk/hpl_gclk_base.h rename to watch-library/hardware/hpl/gclk/hpl_gclk_base.h diff --git a/watch-library/hpl/mclk/hpl_mclk.c b/watch-library/hardware/hpl/mclk/hpl_mclk.c similarity index 100% rename from watch-library/hpl/mclk/hpl_mclk.c rename to watch-library/hardware/hpl/mclk/hpl_mclk.c diff --git a/watch-library/hpl/nvmctrl/hpl_nvmctrl.c b/watch-library/hardware/hpl/nvmctrl/hpl_nvmctrl.c similarity index 100% rename from watch-library/hpl/nvmctrl/hpl_nvmctrl.c rename to watch-library/hardware/hpl/nvmctrl/hpl_nvmctrl.c diff --git a/watch-library/hpl/osc32kctrl/hpl_osc32kctrl.c b/watch-library/hardware/hpl/osc32kctrl/hpl_osc32kctrl.c similarity index 100% rename from watch-library/hpl/osc32kctrl/hpl_osc32kctrl.c rename to watch-library/hardware/hpl/osc32kctrl/hpl_osc32kctrl.c diff --git a/watch-library/hpl/oscctrl/hpl_oscctrl.c b/watch-library/hardware/hpl/oscctrl/hpl_oscctrl.c similarity index 100% rename from watch-library/hpl/oscctrl/hpl_oscctrl.c rename to watch-library/hardware/hpl/oscctrl/hpl_oscctrl.c diff --git a/watch-library/hpl/pm/hpl_pm.c b/watch-library/hardware/hpl/pm/hpl_pm.c similarity index 100% rename from watch-library/hpl/pm/hpl_pm.c rename to watch-library/hardware/hpl/pm/hpl_pm.c diff --git a/watch-library/hpl/pm/hpl_pm_base.h b/watch-library/hardware/hpl/pm/hpl_pm_base.h similarity index 100% rename from watch-library/hpl/pm/hpl_pm_base.h rename to watch-library/hardware/hpl/pm/hpl_pm_base.h diff --git a/watch-library/hpl/port/hpl_gpio_base.h b/watch-library/hardware/hpl/port/hpl_gpio_base.h similarity index 100% rename from watch-library/hpl/port/hpl_gpio_base.h rename to watch-library/hardware/hpl/port/hpl_gpio_base.h diff --git a/watch-library/hpl/sercom/hpl_sercom.c b/watch-library/hardware/hpl/sercom/hpl_sercom.c similarity index 100% rename from watch-library/hpl/sercom/hpl_sercom.c rename to watch-library/hardware/hpl/sercom/hpl_sercom.c diff --git a/watch-library/hpl/slcd/hpl_slcd.c b/watch-library/hardware/hpl/slcd/hpl_slcd.c similarity index 100% rename from watch-library/hpl/slcd/hpl_slcd.c rename to watch-library/hardware/hpl/slcd/hpl_slcd.c diff --git a/watch-library/hpl/slcd/hpl_slcd_cm.h b/watch-library/hardware/hpl/slcd/hpl_slcd_cm.h similarity index 100% rename from watch-library/hpl/slcd/hpl_slcd_cm.h rename to watch-library/hardware/hpl/slcd/hpl_slcd_cm.h diff --git a/watch-library/hpl/systick/hpl_systick.c b/watch-library/hardware/hpl/systick/hpl_systick.c similarity index 100% rename from watch-library/hpl/systick/hpl_systick.c rename to watch-library/hardware/hpl/systick/hpl_systick.c diff --git a/watch-library/hpl/trng/hpl_trng.c b/watch-library/hardware/hpl/trng/hpl_trng.c similarity index 100% rename from watch-library/hpl/trng/hpl_trng.c rename to watch-library/hardware/hpl/trng/hpl_trng.c diff --git a/watch-library/hri/hri_ac_l22.h b/watch-library/hardware/hri/hri_ac_l22.h similarity index 100% rename from watch-library/hri/hri_ac_l22.h rename to watch-library/hardware/hri/hri_ac_l22.h diff --git a/watch-library/hri/hri_adc_l22.h b/watch-library/hardware/hri/hri_adc_l22.h similarity index 100% rename from watch-library/hri/hri_adc_l22.h rename to watch-library/hardware/hri/hri_adc_l22.h diff --git a/watch-library/hri/hri_aes_l22.h b/watch-library/hardware/hri/hri_aes_l22.h similarity index 100% rename from watch-library/hri/hri_aes_l22.h rename to watch-library/hardware/hri/hri_aes_l22.h diff --git a/watch-library/hri/hri_ccl_l22.h b/watch-library/hardware/hri/hri_ccl_l22.h similarity index 100% rename from watch-library/hri/hri_ccl_l22.h rename to watch-library/hardware/hri/hri_ccl_l22.h diff --git a/watch-library/hri/hri_dmac_l22.h b/watch-library/hardware/hri/hri_dmac_l22.h similarity index 100% rename from watch-library/hri/hri_dmac_l22.h rename to watch-library/hardware/hri/hri_dmac_l22.h diff --git a/watch-library/hri/hri_dsu_l22.h b/watch-library/hardware/hri/hri_dsu_l22.h similarity index 100% rename from watch-library/hri/hri_dsu_l22.h rename to watch-library/hardware/hri/hri_dsu_l22.h diff --git a/watch-library/hri/hri_eic_l22.h b/watch-library/hardware/hri/hri_eic_l22.h similarity index 100% rename from watch-library/hri/hri_eic_l22.h rename to watch-library/hardware/hri/hri_eic_l22.h diff --git a/watch-library/hri/hri_evsys_l22.h b/watch-library/hardware/hri/hri_evsys_l22.h similarity index 100% rename from watch-library/hri/hri_evsys_l22.h rename to watch-library/hardware/hri/hri_evsys_l22.h diff --git a/watch-library/hri/hri_freqm_l22.h b/watch-library/hardware/hri/hri_freqm_l22.h similarity index 100% rename from watch-library/hri/hri_freqm_l22.h rename to watch-library/hardware/hri/hri_freqm_l22.h diff --git a/watch-library/hri/hri_gclk_l22.h b/watch-library/hardware/hri/hri_gclk_l22.h similarity index 100% rename from watch-library/hri/hri_gclk_l22.h rename to watch-library/hardware/hri/hri_gclk_l22.h diff --git a/watch-library/hri/hri_l22.h b/watch-library/hardware/hri/hri_l22.h similarity index 100% rename from watch-library/hri/hri_l22.h rename to watch-library/hardware/hri/hri_l22.h diff --git a/watch-library/hri/hri_mclk_l22.h b/watch-library/hardware/hri/hri_mclk_l22.h similarity index 100% rename from watch-library/hri/hri_mclk_l22.h rename to watch-library/hardware/hri/hri_mclk_l22.h diff --git a/watch-library/hri/hri_mtb_l22.h b/watch-library/hardware/hri/hri_mtb_l22.h similarity index 100% rename from watch-library/hri/hri_mtb_l22.h rename to watch-library/hardware/hri/hri_mtb_l22.h diff --git a/watch-library/hri/hri_nvic_l22.h b/watch-library/hardware/hri/hri_nvic_l22.h similarity index 100% rename from watch-library/hri/hri_nvic_l22.h rename to watch-library/hardware/hri/hri_nvic_l22.h diff --git a/watch-library/hri/hri_nvmctrl_l22.h b/watch-library/hardware/hri/hri_nvmctrl_l22.h similarity index 100% rename from watch-library/hri/hri_nvmctrl_l22.h rename to watch-library/hardware/hri/hri_nvmctrl_l22.h diff --git a/watch-library/hri/hri_osc32kctrl_l22.h b/watch-library/hardware/hri/hri_osc32kctrl_l22.h similarity index 100% rename from watch-library/hri/hri_osc32kctrl_l22.h rename to watch-library/hardware/hri/hri_osc32kctrl_l22.h diff --git a/watch-library/hri/hri_oscctrl_l22.h b/watch-library/hardware/hri/hri_oscctrl_l22.h similarity index 100% rename from watch-library/hri/hri_oscctrl_l22.h rename to watch-library/hardware/hri/hri_oscctrl_l22.h diff --git a/watch-library/hri/hri_pac_l22.h b/watch-library/hardware/hri/hri_pac_l22.h similarity index 100% rename from watch-library/hri/hri_pac_l22.h rename to watch-library/hardware/hri/hri_pac_l22.h diff --git a/watch-library/hri/hri_pm_l22.h b/watch-library/hardware/hri/hri_pm_l22.h similarity index 100% rename from watch-library/hri/hri_pm_l22.h rename to watch-library/hardware/hri/hri_pm_l22.h diff --git a/watch-library/hri/hri_port_l22.h b/watch-library/hardware/hri/hri_port_l22.h similarity index 100% rename from watch-library/hri/hri_port_l22.h rename to watch-library/hardware/hri/hri_port_l22.h diff --git a/watch-library/hri/hri_rstc_l22.h b/watch-library/hardware/hri/hri_rstc_l22.h similarity index 100% rename from watch-library/hri/hri_rstc_l22.h rename to watch-library/hardware/hri/hri_rstc_l22.h diff --git a/watch-library/hri/hri_rtc_l22.h b/watch-library/hardware/hri/hri_rtc_l22.h similarity index 100% rename from watch-library/hri/hri_rtc_l22.h rename to watch-library/hardware/hri/hri_rtc_l22.h diff --git a/watch-library/hri/hri_sercom_l22.h b/watch-library/hardware/hri/hri_sercom_l22.h similarity index 100% rename from watch-library/hri/hri_sercom_l22.h rename to watch-library/hardware/hri/hri_sercom_l22.h diff --git a/watch-library/hri/hri_slcd_l22.h b/watch-library/hardware/hri/hri_slcd_l22.h similarity index 100% rename from watch-library/hri/hri_slcd_l22.h rename to watch-library/hardware/hri/hri_slcd_l22.h diff --git a/watch-library/hri/hri_supc_l22.h b/watch-library/hardware/hri/hri_supc_l22.h similarity index 100% rename from watch-library/hri/hri_supc_l22.h rename to watch-library/hardware/hri/hri_supc_l22.h diff --git a/watch-library/hri/hri_systemcontrol_l22.h b/watch-library/hardware/hri/hri_systemcontrol_l22.h similarity index 100% rename from watch-library/hri/hri_systemcontrol_l22.h rename to watch-library/hardware/hri/hri_systemcontrol_l22.h diff --git a/watch-library/hri/hri_systick_l22.h b/watch-library/hardware/hri/hri_systick_l22.h similarity index 100% rename from watch-library/hri/hri_systick_l22.h rename to watch-library/hardware/hri/hri_systick_l22.h diff --git a/watch-library/hri/hri_tc_l22.h b/watch-library/hardware/hri/hri_tc_l22.h similarity index 100% rename from watch-library/hri/hri_tc_l22.h rename to watch-library/hardware/hri/hri_tc_l22.h diff --git a/watch-library/hri/hri_tcc_l22.h b/watch-library/hardware/hri/hri_tcc_l22.h similarity index 100% rename from watch-library/hri/hri_tcc_l22.h rename to watch-library/hardware/hri/hri_tcc_l22.h diff --git a/watch-library/hri/hri_trng_l22.h b/watch-library/hardware/hri/hri_trng_l22.h similarity index 100% rename from watch-library/hri/hri_trng_l22.h rename to watch-library/hardware/hri/hri_trng_l22.h diff --git a/watch-library/hri/hri_usb_l22.h b/watch-library/hardware/hri/hri_usb_l22.h similarity index 100% rename from watch-library/hri/hri_usb_l22.h rename to watch-library/hardware/hri/hri_usb_l22.h diff --git a/watch-library/hri/hri_wdt_l22.h b/watch-library/hardware/hri/hri_wdt_l22.h similarity index 100% rename from watch-library/hri/hri_wdt_l22.h rename to watch-library/hardware/hri/hri_wdt_l22.h diff --git a/watch-library/hw/driver_init.c b/watch-library/hardware/hw/driver_init.c similarity index 100% rename from watch-library/hw/driver_init.c rename to watch-library/hardware/hw/driver_init.c diff --git a/watch-library/hw/driver_init.h b/watch-library/hardware/hw/driver_init.h similarity index 100% rename from watch-library/hw/driver_init.h rename to watch-library/hardware/hw/driver_init.h diff --git a/watch-library/include/component-version.h b/watch-library/hardware/include/component-version.h similarity index 100% rename from watch-library/include/component-version.h rename to watch-library/hardware/include/component-version.h diff --git a/watch-library/include/component/ac.h b/watch-library/hardware/include/component/ac.h similarity index 100% rename from watch-library/include/component/ac.h rename to watch-library/hardware/include/component/ac.h diff --git a/watch-library/include/component/adc.h b/watch-library/hardware/include/component/adc.h similarity index 100% rename from watch-library/include/component/adc.h rename to watch-library/hardware/include/component/adc.h diff --git a/watch-library/include/component/aes.h b/watch-library/hardware/include/component/aes.h similarity index 100% rename from watch-library/include/component/aes.h rename to watch-library/hardware/include/component/aes.h diff --git a/watch-library/include/component/ccl.h b/watch-library/hardware/include/component/ccl.h similarity index 100% rename from watch-library/include/component/ccl.h rename to watch-library/hardware/include/component/ccl.h diff --git a/watch-library/include/component/dmac.h b/watch-library/hardware/include/component/dmac.h similarity index 100% rename from watch-library/include/component/dmac.h rename to watch-library/hardware/include/component/dmac.h diff --git a/watch-library/include/component/dsu.h b/watch-library/hardware/include/component/dsu.h similarity index 100% rename from watch-library/include/component/dsu.h rename to watch-library/hardware/include/component/dsu.h diff --git a/watch-library/include/component/eic.h b/watch-library/hardware/include/component/eic.h similarity index 100% rename from watch-library/include/component/eic.h rename to watch-library/hardware/include/component/eic.h diff --git a/watch-library/include/component/evsys.h b/watch-library/hardware/include/component/evsys.h similarity index 100% rename from watch-library/include/component/evsys.h rename to watch-library/hardware/include/component/evsys.h diff --git a/watch-library/include/component/freqm.h b/watch-library/hardware/include/component/freqm.h similarity index 100% rename from watch-library/include/component/freqm.h rename to watch-library/hardware/include/component/freqm.h diff --git a/watch-library/include/component/gclk.h b/watch-library/hardware/include/component/gclk.h similarity index 100% rename from watch-library/include/component/gclk.h rename to watch-library/hardware/include/component/gclk.h diff --git a/watch-library/include/component/mclk.h b/watch-library/hardware/include/component/mclk.h similarity index 100% rename from watch-library/include/component/mclk.h rename to watch-library/hardware/include/component/mclk.h diff --git a/watch-library/include/component/mtb.h b/watch-library/hardware/include/component/mtb.h similarity index 100% rename from watch-library/include/component/mtb.h rename to watch-library/hardware/include/component/mtb.h diff --git a/watch-library/include/component/nvmctrl.h b/watch-library/hardware/include/component/nvmctrl.h similarity index 100% rename from watch-library/include/component/nvmctrl.h rename to watch-library/hardware/include/component/nvmctrl.h diff --git a/watch-library/include/component/osc32kctrl.h b/watch-library/hardware/include/component/osc32kctrl.h similarity index 100% rename from watch-library/include/component/osc32kctrl.h rename to watch-library/hardware/include/component/osc32kctrl.h diff --git a/watch-library/include/component/oscctrl.h b/watch-library/hardware/include/component/oscctrl.h similarity index 100% rename from watch-library/include/component/oscctrl.h rename to watch-library/hardware/include/component/oscctrl.h diff --git a/watch-library/include/component/pac.h b/watch-library/hardware/include/component/pac.h similarity index 100% rename from watch-library/include/component/pac.h rename to watch-library/hardware/include/component/pac.h diff --git a/watch-library/include/component/pm.h b/watch-library/hardware/include/component/pm.h similarity index 100% rename from watch-library/include/component/pm.h rename to watch-library/hardware/include/component/pm.h diff --git a/watch-library/include/component/port.h b/watch-library/hardware/include/component/port.h similarity index 100% rename from watch-library/include/component/port.h rename to watch-library/hardware/include/component/port.h diff --git a/watch-library/include/component/rstc.h b/watch-library/hardware/include/component/rstc.h similarity index 100% rename from watch-library/include/component/rstc.h rename to watch-library/hardware/include/component/rstc.h diff --git a/watch-library/include/component/rtc.h b/watch-library/hardware/include/component/rtc.h similarity index 100% rename from watch-library/include/component/rtc.h rename to watch-library/hardware/include/component/rtc.h diff --git a/watch-library/include/component/sercom.h b/watch-library/hardware/include/component/sercom.h similarity index 100% rename from watch-library/include/component/sercom.h rename to watch-library/hardware/include/component/sercom.h diff --git a/watch-library/include/component/slcd.h b/watch-library/hardware/include/component/slcd.h similarity index 100% rename from watch-library/include/component/slcd.h rename to watch-library/hardware/include/component/slcd.h diff --git a/watch-library/include/component/supc.h b/watch-library/hardware/include/component/supc.h similarity index 100% rename from watch-library/include/component/supc.h rename to watch-library/hardware/include/component/supc.h diff --git a/watch-library/include/component/tc.h b/watch-library/hardware/include/component/tc.h similarity index 100% rename from watch-library/include/component/tc.h rename to watch-library/hardware/include/component/tc.h diff --git a/watch-library/include/component/tcc.h b/watch-library/hardware/include/component/tcc.h similarity index 100% rename from watch-library/include/component/tcc.h rename to watch-library/hardware/include/component/tcc.h diff --git a/watch-library/include/component/trng.h b/watch-library/hardware/include/component/trng.h similarity index 100% rename from watch-library/include/component/trng.h rename to watch-library/hardware/include/component/trng.h diff --git a/watch-library/include/component/usb.h b/watch-library/hardware/include/component/usb.h similarity index 100% rename from watch-library/include/component/usb.h rename to watch-library/hardware/include/component/usb.h diff --git a/watch-library/include/component/wdt.h b/watch-library/hardware/include/component/wdt.h similarity index 100% rename from watch-library/include/component/wdt.h rename to watch-library/hardware/include/component/wdt.h diff --git a/watch-library/include/core_cm0plus.h b/watch-library/hardware/include/core_cm0plus.h similarity index 100% rename from watch-library/include/core_cm0plus.h rename to watch-library/hardware/include/core_cm0plus.h diff --git a/watch-library/include/core_cmFunc.h b/watch-library/hardware/include/core_cmFunc.h similarity index 100% rename from watch-library/include/core_cmFunc.h rename to watch-library/hardware/include/core_cmFunc.h diff --git a/watch-library/include/core_cmInstr.h b/watch-library/hardware/include/core_cmInstr.h similarity index 100% rename from watch-library/include/core_cmInstr.h rename to watch-library/hardware/include/core_cmInstr.h diff --git a/watch-library/include/instance/ac.h b/watch-library/hardware/include/instance/ac.h similarity index 100% rename from watch-library/include/instance/ac.h rename to watch-library/hardware/include/instance/ac.h diff --git a/watch-library/include/instance/adc.h b/watch-library/hardware/include/instance/adc.h similarity index 100% rename from watch-library/include/instance/adc.h rename to watch-library/hardware/include/instance/adc.h diff --git a/watch-library/include/instance/aes.h b/watch-library/hardware/include/instance/aes.h similarity index 100% rename from watch-library/include/instance/aes.h rename to watch-library/hardware/include/instance/aes.h diff --git a/watch-library/include/instance/ccl.h b/watch-library/hardware/include/instance/ccl.h similarity index 100% rename from watch-library/include/instance/ccl.h rename to watch-library/hardware/include/instance/ccl.h diff --git a/watch-library/include/instance/dmac.h b/watch-library/hardware/include/instance/dmac.h similarity index 100% rename from watch-library/include/instance/dmac.h rename to watch-library/hardware/include/instance/dmac.h diff --git a/watch-library/include/instance/dsu.h b/watch-library/hardware/include/instance/dsu.h similarity index 100% rename from watch-library/include/instance/dsu.h rename to watch-library/hardware/include/instance/dsu.h diff --git a/watch-library/include/instance/eic.h b/watch-library/hardware/include/instance/eic.h similarity index 100% rename from watch-library/include/instance/eic.h rename to watch-library/hardware/include/instance/eic.h diff --git a/watch-library/include/instance/evsys.h b/watch-library/hardware/include/instance/evsys.h similarity index 100% rename from watch-library/include/instance/evsys.h rename to watch-library/hardware/include/instance/evsys.h diff --git a/watch-library/include/instance/freqm.h b/watch-library/hardware/include/instance/freqm.h similarity index 100% rename from watch-library/include/instance/freqm.h rename to watch-library/hardware/include/instance/freqm.h diff --git a/watch-library/include/instance/gclk.h b/watch-library/hardware/include/instance/gclk.h similarity index 100% rename from watch-library/include/instance/gclk.h rename to watch-library/hardware/include/instance/gclk.h diff --git a/watch-library/include/instance/mclk.h b/watch-library/hardware/include/instance/mclk.h similarity index 100% rename from watch-library/include/instance/mclk.h rename to watch-library/hardware/include/instance/mclk.h diff --git a/watch-library/include/instance/mtb.h b/watch-library/hardware/include/instance/mtb.h similarity index 100% rename from watch-library/include/instance/mtb.h rename to watch-library/hardware/include/instance/mtb.h diff --git a/watch-library/include/instance/nvmctrl.h b/watch-library/hardware/include/instance/nvmctrl.h similarity index 100% rename from watch-library/include/instance/nvmctrl.h rename to watch-library/hardware/include/instance/nvmctrl.h diff --git a/watch-library/include/instance/osc32kctrl.h b/watch-library/hardware/include/instance/osc32kctrl.h similarity index 100% rename from watch-library/include/instance/osc32kctrl.h rename to watch-library/hardware/include/instance/osc32kctrl.h diff --git a/watch-library/include/instance/oscctrl.h b/watch-library/hardware/include/instance/oscctrl.h similarity index 100% rename from watch-library/include/instance/oscctrl.h rename to watch-library/hardware/include/instance/oscctrl.h diff --git a/watch-library/include/instance/pac.h b/watch-library/hardware/include/instance/pac.h similarity index 100% rename from watch-library/include/instance/pac.h rename to watch-library/hardware/include/instance/pac.h diff --git a/watch-library/include/instance/pm.h b/watch-library/hardware/include/instance/pm.h similarity index 100% rename from watch-library/include/instance/pm.h rename to watch-library/hardware/include/instance/pm.h diff --git a/watch-library/include/instance/port.h b/watch-library/hardware/include/instance/port.h similarity index 100% rename from watch-library/include/instance/port.h rename to watch-library/hardware/include/instance/port.h diff --git a/watch-library/include/instance/ptc.h b/watch-library/hardware/include/instance/ptc.h similarity index 100% rename from watch-library/include/instance/ptc.h rename to watch-library/hardware/include/instance/ptc.h diff --git a/watch-library/include/instance/rstc.h b/watch-library/hardware/include/instance/rstc.h similarity index 100% rename from watch-library/include/instance/rstc.h rename to watch-library/hardware/include/instance/rstc.h diff --git a/watch-library/include/instance/rtc.h b/watch-library/hardware/include/instance/rtc.h similarity index 100% rename from watch-library/include/instance/rtc.h rename to watch-library/hardware/include/instance/rtc.h diff --git a/watch-library/include/instance/sercom0.h b/watch-library/hardware/include/instance/sercom0.h similarity index 100% rename from watch-library/include/instance/sercom0.h rename to watch-library/hardware/include/instance/sercom0.h diff --git a/watch-library/include/instance/sercom1.h b/watch-library/hardware/include/instance/sercom1.h similarity index 100% rename from watch-library/include/instance/sercom1.h rename to watch-library/hardware/include/instance/sercom1.h diff --git a/watch-library/include/instance/sercom2.h b/watch-library/hardware/include/instance/sercom2.h similarity index 100% rename from watch-library/include/instance/sercom2.h rename to watch-library/hardware/include/instance/sercom2.h diff --git a/watch-library/include/instance/sercom3.h b/watch-library/hardware/include/instance/sercom3.h similarity index 100% rename from watch-library/include/instance/sercom3.h rename to watch-library/hardware/include/instance/sercom3.h diff --git a/watch-library/include/instance/sercom4.h b/watch-library/hardware/include/instance/sercom4.h similarity index 100% rename from watch-library/include/instance/sercom4.h rename to watch-library/hardware/include/instance/sercom4.h diff --git a/watch-library/include/instance/sercom5.h b/watch-library/hardware/include/instance/sercom5.h similarity index 100% rename from watch-library/include/instance/sercom5.h rename to watch-library/hardware/include/instance/sercom5.h diff --git a/watch-library/include/instance/slcd.h b/watch-library/hardware/include/instance/slcd.h similarity index 100% rename from watch-library/include/instance/slcd.h rename to watch-library/hardware/include/instance/slcd.h diff --git a/watch-library/include/instance/supc.h b/watch-library/hardware/include/instance/supc.h similarity index 100% rename from watch-library/include/instance/supc.h rename to watch-library/hardware/include/instance/supc.h diff --git a/watch-library/include/instance/tc0.h b/watch-library/hardware/include/instance/tc0.h similarity index 100% rename from watch-library/include/instance/tc0.h rename to watch-library/hardware/include/instance/tc0.h diff --git a/watch-library/include/instance/tc1.h b/watch-library/hardware/include/instance/tc1.h similarity index 100% rename from watch-library/include/instance/tc1.h rename to watch-library/hardware/include/instance/tc1.h diff --git a/watch-library/include/instance/tc2.h b/watch-library/hardware/include/instance/tc2.h similarity index 100% rename from watch-library/include/instance/tc2.h rename to watch-library/hardware/include/instance/tc2.h diff --git a/watch-library/include/instance/tc3.h b/watch-library/hardware/include/instance/tc3.h similarity index 100% rename from watch-library/include/instance/tc3.h rename to watch-library/hardware/include/instance/tc3.h diff --git a/watch-library/include/instance/tcc0.h b/watch-library/hardware/include/instance/tcc0.h similarity index 100% rename from watch-library/include/instance/tcc0.h rename to watch-library/hardware/include/instance/tcc0.h diff --git a/watch-library/include/instance/trng.h b/watch-library/hardware/include/instance/trng.h similarity index 100% rename from watch-library/include/instance/trng.h rename to watch-library/hardware/include/instance/trng.h diff --git a/watch-library/include/instance/usb.h b/watch-library/hardware/include/instance/usb.h similarity index 100% rename from watch-library/include/instance/usb.h rename to watch-library/hardware/include/instance/usb.h diff --git a/watch-library/include/instance/wdt.h b/watch-library/hardware/include/instance/wdt.h similarity index 100% rename from watch-library/include/instance/wdt.h rename to watch-library/hardware/include/instance/wdt.h diff --git a/watch-library/include/pio/saml22g16a.h b/watch-library/hardware/include/pio/saml22g16a.h similarity index 100% rename from watch-library/include/pio/saml22g16a.h rename to watch-library/hardware/include/pio/saml22g16a.h diff --git a/watch-library/include/pio/saml22g17a.h b/watch-library/hardware/include/pio/saml22g17a.h similarity index 100% rename from watch-library/include/pio/saml22g17a.h rename to watch-library/hardware/include/pio/saml22g17a.h diff --git a/watch-library/include/pio/saml22g18a.h b/watch-library/hardware/include/pio/saml22g18a.h similarity index 100% rename from watch-library/include/pio/saml22g18a.h rename to watch-library/hardware/include/pio/saml22g18a.h diff --git a/watch-library/include/pio/saml22j16a.h b/watch-library/hardware/include/pio/saml22j16a.h similarity index 100% rename from watch-library/include/pio/saml22j16a.h rename to watch-library/hardware/include/pio/saml22j16a.h diff --git a/watch-library/include/pio/saml22j17a.h b/watch-library/hardware/include/pio/saml22j17a.h similarity index 100% rename from watch-library/include/pio/saml22j17a.h rename to watch-library/hardware/include/pio/saml22j17a.h diff --git a/watch-library/include/pio/saml22j18a.h b/watch-library/hardware/include/pio/saml22j18a.h similarity index 100% rename from watch-library/include/pio/saml22j18a.h rename to watch-library/hardware/include/pio/saml22j18a.h diff --git a/watch-library/include/pio/saml22n16a.h b/watch-library/hardware/include/pio/saml22n16a.h similarity index 100% rename from watch-library/include/pio/saml22n16a.h rename to watch-library/hardware/include/pio/saml22n16a.h diff --git a/watch-library/include/pio/saml22n17a.h b/watch-library/hardware/include/pio/saml22n17a.h similarity index 100% rename from watch-library/include/pio/saml22n17a.h rename to watch-library/hardware/include/pio/saml22n17a.h diff --git a/watch-library/include/pio/saml22n18a.h b/watch-library/hardware/include/pio/saml22n18a.h similarity index 100% rename from watch-library/include/pio/saml22n18a.h rename to watch-library/hardware/include/pio/saml22n18a.h diff --git a/watch-library/include/sam.h b/watch-library/hardware/include/sam.h similarity index 100% rename from watch-library/include/sam.h rename to watch-library/hardware/include/sam.h diff --git a/watch-library/include/saml22.h b/watch-library/hardware/include/saml22.h similarity index 100% rename from watch-library/include/saml22.h rename to watch-library/hardware/include/saml22.h diff --git a/watch-library/include/saml22g16a.h b/watch-library/hardware/include/saml22g16a.h similarity index 100% rename from watch-library/include/saml22g16a.h rename to watch-library/hardware/include/saml22g16a.h diff --git a/watch-library/include/saml22g17a.h b/watch-library/hardware/include/saml22g17a.h similarity index 100% rename from watch-library/include/saml22g17a.h rename to watch-library/hardware/include/saml22g17a.h diff --git a/watch-library/include/saml22g18a.h b/watch-library/hardware/include/saml22g18a.h similarity index 100% rename from watch-library/include/saml22g18a.h rename to watch-library/hardware/include/saml22g18a.h diff --git a/watch-library/include/saml22j16a.h b/watch-library/hardware/include/saml22j16a.h similarity index 100% rename from watch-library/include/saml22j16a.h rename to watch-library/hardware/include/saml22j16a.h diff --git a/watch-library/include/saml22j17a.h b/watch-library/hardware/include/saml22j17a.h similarity index 100% rename from watch-library/include/saml22j17a.h rename to watch-library/hardware/include/saml22j17a.h diff --git a/watch-library/include/saml22j18a.h b/watch-library/hardware/include/saml22j18a.h similarity index 100% rename from watch-library/include/saml22j18a.h rename to watch-library/hardware/include/saml22j18a.h diff --git a/watch-library/include/saml22n16a.h b/watch-library/hardware/include/saml22n16a.h similarity index 100% rename from watch-library/include/saml22n16a.h rename to watch-library/hardware/include/saml22n16a.h diff --git a/watch-library/include/saml22n17a.h b/watch-library/hardware/include/saml22n17a.h similarity index 100% rename from watch-library/include/saml22n17a.h rename to watch-library/hardware/include/saml22n17a.h diff --git a/watch-library/include/saml22n18a.h b/watch-library/hardware/include/saml22n18a.h similarity index 100% rename from watch-library/include/saml22n18a.h rename to watch-library/hardware/include/saml22n18a.h diff --git a/watch-library/include/system_saml22.h b/watch-library/hardware/include/system_saml22.h similarity index 100% rename from watch-library/include/system_saml22.h rename to watch-library/hardware/include/system_saml22.h diff --git a/watch-library/linker/saml22j18.ld b/watch-library/hardware/linker/saml22j18.ld similarity index 100% rename from watch-library/linker/saml22j18.ld rename to watch-library/hardware/linker/saml22j18.ld diff --git a/watch-library/main.c b/watch-library/hardware/main.c similarity index 100% rename from watch-library/main.c rename to watch-library/hardware/main.c diff --git a/watch-library/startup_saml22.c b/watch-library/hardware/startup_saml22.c similarity index 100% rename from watch-library/startup_saml22.c rename to watch-library/hardware/startup_saml22.c diff --git a/watch-library/watch/tusb_config.h b/watch-library/hardware/watch/tusb_config.h similarity index 100% rename from watch-library/watch/tusb_config.h rename to watch-library/hardware/watch/tusb_config.h diff --git a/watch-library/watch/watch.c b/watch-library/hardware/watch/watch.c similarity index 100% rename from watch-library/watch/watch.c rename to watch-library/hardware/watch/watch.c diff --git a/watch-library/watch/watch_adc.c b/watch-library/hardware/watch/watch_adc.c similarity index 100% rename from watch-library/watch/watch_adc.c rename to watch-library/hardware/watch/watch_adc.c diff --git a/watch-library/watch/watch_buzzer.c b/watch-library/hardware/watch/watch_buzzer.c similarity index 100% rename from watch-library/watch/watch_buzzer.c rename to watch-library/hardware/watch/watch_buzzer.c diff --git a/watch-library/watch/watch_deepsleep.c b/watch-library/hardware/watch/watch_deepsleep.c similarity index 100% rename from watch-library/watch/watch_deepsleep.c rename to watch-library/hardware/watch/watch_deepsleep.c diff --git a/watch-library/watch/watch_extint.c b/watch-library/hardware/watch/watch_extint.c similarity index 100% rename from watch-library/watch/watch_extint.c rename to watch-library/hardware/watch/watch_extint.c diff --git a/watch-library/watch/watch_gpio.c b/watch-library/hardware/watch/watch_gpio.c similarity index 100% rename from watch-library/watch/watch_gpio.c rename to watch-library/hardware/watch/watch_gpio.c diff --git a/watch-library/watch/watch_i2c.c b/watch-library/hardware/watch/watch_i2c.c similarity index 100% rename from watch-library/watch/watch_i2c.c rename to watch-library/hardware/watch/watch_i2c.c diff --git a/watch-library/watch/watch_led.c b/watch-library/hardware/watch/watch_led.c similarity index 100% rename from watch-library/watch/watch_led.c rename to watch-library/hardware/watch/watch_led.c diff --git a/watch-library/watch/watch_private.c b/watch-library/hardware/watch/watch_private.c similarity index 100% rename from watch-library/watch/watch_private.c rename to watch-library/hardware/watch/watch_private.c diff --git a/watch-library/watch/watch_rtc.c b/watch-library/hardware/watch/watch_rtc.c similarity index 100% rename from watch-library/watch/watch_rtc.c rename to watch-library/hardware/watch/watch_rtc.c diff --git a/watch-library/hardware/watch/watch_slcd.c b/watch-library/hardware/watch/watch_slcd.c new file mode 100644 index 00000000..c3bacd0d --- /dev/null +++ b/watch-library/hardware/watch/watch_slcd.c @@ -0,0 +1,101 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_slcd.h" +#include "watch_private_display.h" +#include "hpl_slcd_config.h" + + ////////////////////////////////////////////////////////////////////////////////////////// +// Segmented Display + +static void _sync_slcd(void) { + while (SLCD->SYNCBUSY.reg); +} + +void watch_enable_display(void) { + SEGMENT_LCD_0_init(); + slcd_sync_enable(&SEGMENT_LCD_0); +} + +inline void watch_set_pixel(uint8_t com, uint8_t seg) { + slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); +} + +inline void watch_clear_pixel(uint8_t com, uint8_t seg) { + slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); +} + +void watch_clear_display(void) { + SLCD->SDATAL0.reg = 0; + SLCD->SDATAL1.reg = 0; + SLCD->SDATAL2.reg = 0; +} + +void watch_start_character_blink(char character, uint32_t duration) { + SLCD->CTRLD.bit.FC0EN = 0; + _sync_slcd(); + + if (duration <= SLCD_FC_BYPASS_MAX_MS) { + SLCD->FC0.reg = SLCD_FC0_PB | ((duration / (1000 / SLCD_FRAME_FREQUENCY)) - 1); + } else { + SLCD->FC0.reg = (((duration / (1000 / SLCD_FRAME_FREQUENCY)) / 8 - 1)); + } + SLCD->CTRLD.bit.FC0EN = 1; + + watch_display_character(character, 7); + watch_clear_pixel(2, 10); // clear segment B of position 7 since it can't blink + + SLCD->CTRLD.bit.BLINK = 0; + SLCD->CTRLA.bit.ENABLE = 0; + _sync_slcd(); + + SLCD->BCFG.bit.BSS0 = 0x07; + SLCD->BCFG.bit.BSS1 = 0x07; + + SLCD->CTRLD.bit.BLINK = 1; + _sync_slcd(); + SLCD->CTRLA.bit.ENABLE = 1; + _sync_slcd(); +} + +void watch_stop_blink(void) { + SLCD->CTRLD.bit.FC0EN = 0; + SLCD->CTRLD.bit.BLINK = 0; +} + +void watch_start_tick_animation(uint32_t duration) { + watch_display_character(' ', 8); + const uint32_t segs[] = { SLCD_SEGID(0, 2)}; + slcd_sync_start_animation(&SEGMENT_LCD_0, segs, 1, duration); +} + +bool watch_tick_animation_is_running(void) { + return hri_slcd_get_CTRLD_CSREN_bit(SLCD); +} + +void watch_stop_tick_animation(void) { + const uint32_t segs[] = { SLCD_SEGID(0, 2)}; + slcd_sync_stop_animation(&SEGMENT_LCD_0, segs, 1); + watch_display_character(' ', 8); +} diff --git a/watch-library/watch/watch_uart.c b/watch-library/hardware/watch/watch_uart.c similarity index 100% rename from watch-library/watch/watch_uart.c rename to watch-library/hardware/watch/watch_uart.c diff --git a/watch-library/config/RTE_Components.h b/watch-library/shared/config/RTE_Components.h similarity index 100% rename from watch-library/config/RTE_Components.h rename to watch-library/shared/config/RTE_Components.h diff --git a/watch-library/config/hpl_dmac_config.h b/watch-library/shared/config/hpl_dmac_config.h similarity index 100% rename from watch-library/config/hpl_dmac_config.h rename to watch-library/shared/config/hpl_dmac_config.h diff --git a/watch-library/config/hpl_eic_config.h b/watch-library/shared/config/hpl_eic_config.h similarity index 100% rename from watch-library/config/hpl_eic_config.h rename to watch-library/shared/config/hpl_eic_config.h diff --git a/watch-library/config/hpl_gclk_config.h b/watch-library/shared/config/hpl_gclk_config.h similarity index 100% rename from watch-library/config/hpl_gclk_config.h rename to watch-library/shared/config/hpl_gclk_config.h diff --git a/watch-library/config/hpl_mclk_config.h b/watch-library/shared/config/hpl_mclk_config.h similarity index 100% rename from watch-library/config/hpl_mclk_config.h rename to watch-library/shared/config/hpl_mclk_config.h diff --git a/watch-library/config/hpl_nvmctrl_config.h b/watch-library/shared/config/hpl_nvmctrl_config.h similarity index 100% rename from watch-library/config/hpl_nvmctrl_config.h rename to watch-library/shared/config/hpl_nvmctrl_config.h diff --git a/watch-library/config/hpl_osc32kctrl_config.h b/watch-library/shared/config/hpl_osc32kctrl_config.h similarity index 100% rename from watch-library/config/hpl_osc32kctrl_config.h rename to watch-library/shared/config/hpl_osc32kctrl_config.h diff --git a/watch-library/config/hpl_oscctrl_config.h b/watch-library/shared/config/hpl_oscctrl_config.h similarity index 100% rename from watch-library/config/hpl_oscctrl_config.h rename to watch-library/shared/config/hpl_oscctrl_config.h diff --git a/watch-library/config/hpl_port_config.h b/watch-library/shared/config/hpl_port_config.h similarity index 100% rename from watch-library/config/hpl_port_config.h rename to watch-library/shared/config/hpl_port_config.h diff --git a/watch-library/config/hpl_rtc_config.h b/watch-library/shared/config/hpl_rtc_config.h similarity index 100% rename from watch-library/config/hpl_rtc_config.h rename to watch-library/shared/config/hpl_rtc_config.h diff --git a/watch-library/config/hpl_sercom_config.h b/watch-library/shared/config/hpl_sercom_config.h similarity index 100% rename from watch-library/config/hpl_sercom_config.h rename to watch-library/shared/config/hpl_sercom_config.h diff --git a/watch-library/config/hpl_slcd_config.h b/watch-library/shared/config/hpl_slcd_config.h similarity index 100% rename from watch-library/config/hpl_slcd_config.h rename to watch-library/shared/config/hpl_slcd_config.h diff --git a/watch-library/config/hpl_systick_config.h b/watch-library/shared/config/hpl_systick_config.h similarity index 100% rename from watch-library/config/hpl_systick_config.h rename to watch-library/shared/config/hpl_systick_config.h diff --git a/watch-library/config/hpl_trng_config.h b/watch-library/shared/config/hpl_trng_config.h similarity index 100% rename from watch-library/config/hpl_trng_config.h rename to watch-library/shared/config/hpl_trng_config.h diff --git a/watch-library/config/nv_storage_config.h b/watch-library/shared/config/nv_storage_config.h similarity index 100% rename from watch-library/config/nv_storage_config.h rename to watch-library/shared/config/nv_storage_config.h diff --git a/watch-library/config/peripheral_clk_config.h b/watch-library/shared/config/peripheral_clk_config.h similarity index 100% rename from watch-library/config/peripheral_clk_config.h rename to watch-library/shared/config/peripheral_clk_config.h diff --git a/watch-library/driver/lis2dh.c b/watch-library/shared/driver/lis2dh.c similarity index 100% rename from watch-library/driver/lis2dh.c rename to watch-library/shared/driver/lis2dh.c diff --git a/watch-library/driver/lis2dh.h b/watch-library/shared/driver/lis2dh.h similarity index 100% rename from watch-library/driver/lis2dh.h rename to watch-library/shared/driver/lis2dh.h diff --git a/watch-library/driver/lis2dw.c b/watch-library/shared/driver/lis2dw.c similarity index 100% rename from watch-library/driver/lis2dw.c rename to watch-library/shared/driver/lis2dw.c diff --git a/watch-library/driver/lis2dw.h b/watch-library/shared/driver/lis2dw.h similarity index 100% rename from watch-library/driver/lis2dw.h rename to watch-library/shared/driver/lis2dw.h diff --git a/watch-library/watch/watch.h b/watch-library/shared/watch/watch.h similarity index 100% rename from watch-library/watch/watch.h rename to watch-library/shared/watch/watch.h diff --git a/watch-library/watch/watch_adc.h b/watch-library/shared/watch/watch_adc.h similarity index 96% rename from watch-library/watch/watch_adc.h rename to watch-library/shared/watch/watch_adc.h index aa7c801a..d4c8586d 100644 --- a/watch-library/watch/watch_adc.h +++ b/watch-library/shared/watch/watch_adc.h @@ -27,6 +27,23 @@ #include "watch.h" +// matches adc.h +#ifndef ADC_REFCTRL_REFSEL_INTREF_Val +#define ADC_REFCTRL_REFSEL_INTREF_Val 0x0 +#endif + +#ifndef ADC_REFCTRL_REFSEL_INTVCC0_Val +#define ADC_REFCTRL_REFSEL_INTVCC0_Val 0x1 +#endif + +#ifndef ADC_REFCTRL_REFSEL_INTVCC1_Val +#define ADC_REFCTRL_REFSEL_INTVCC1_Val 0x2 +#endif + +#ifndef ADC_REFCTRL_REFSEL_INTVCC2_Val +#define ADC_REFCTRL_REFSEL_INTVCC2_Val 0x5 +#endif + /** @addtogroup adc Analog Input * @brief This section covers functions related to the SAM L22's analog-to-digital converter, * as well as configuring and reading values from the five analog-capable pins on the diff --git a/watch-library/watch/watch_app.h b/watch-library/shared/watch/watch_app.h similarity index 100% rename from watch-library/watch/watch_app.h rename to watch-library/shared/watch/watch_app.h diff --git a/watch-library/watch/watch_buzzer.h b/watch-library/shared/watch/watch_buzzer.h similarity index 100% rename from watch-library/watch/watch_buzzer.h rename to watch-library/shared/watch/watch_buzzer.h diff --git a/watch-library/watch/watch_deepsleep.h b/watch-library/shared/watch/watch_deepsleep.h similarity index 100% rename from watch-library/watch/watch_deepsleep.h rename to watch-library/shared/watch/watch_deepsleep.h diff --git a/watch-library/watch/watch_extint.h b/watch-library/shared/watch/watch_extint.h similarity index 100% rename from watch-library/watch/watch_extint.h rename to watch-library/shared/watch/watch_extint.h diff --git a/watch-library/watch/watch_gpio.h b/watch-library/shared/watch/watch_gpio.h similarity index 100% rename from watch-library/watch/watch_gpio.h rename to watch-library/shared/watch/watch_gpio.h diff --git a/watch-library/watch/watch_i2c.h b/watch-library/shared/watch/watch_i2c.h similarity index 100% rename from watch-library/watch/watch_i2c.h rename to watch-library/shared/watch/watch_i2c.h diff --git a/watch-library/watch/watch_led.h b/watch-library/shared/watch/watch_led.h similarity index 100% rename from watch-library/watch/watch_led.h rename to watch-library/shared/watch/watch_led.h diff --git a/watch-library/watch/watch_private.h b/watch-library/shared/watch/watch_private.h similarity index 100% rename from watch-library/watch/watch_private.h rename to watch-library/shared/watch/watch_private.h diff --git a/watch-library/shared/watch/watch_private_display.c b/watch-library/shared/watch/watch_private_display.c new file mode 100644 index 00000000..87e3f1ae --- /dev/null +++ b/watch-library/shared/watch/watch_private_display.c @@ -0,0 +1,137 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_slcd.h" +#include "watch_private_display.h" + +static const uint32_t IndicatorSegments[] = { + SLCD_SEGID(0, 17), // WATCH_INDICATOR_SIGNAL + SLCD_SEGID(0, 16), // WATCH_INDICATOR_BELL + SLCD_SEGID(2, 17), // WATCH_INDICATOR_PM + SLCD_SEGID(2, 16), // WATCH_INDICATOR_24H + SLCD_SEGID(1, 10), // WATCH_INDICATOR_LAP +}; + +void watch_display_character(uint8_t character, uint8_t position) { + // special cases for positions 4 and 6 + if (position == 4 || position == 6) { + if (character == '7') character = '&'; // "lowercase" 7 + else if (character == 'A') character = 'a'; // A needs to be lowercase + else if (character == 'o') character = 'O'; // O needs to be uppercase + else if (character == 'L') character = '!'; // L needs to be in top half + else if (character == 'M' || character == 'm' || character == 'N') character = 'n'; // M and uppercase N need to be lowercase n + else if (character == 'c') character = 'C'; // C needs to be uppercase + else if (character == 'J') character = 'j'; // same + else if (character == 'v' || character == 'V' || character == 'U' || character == 'W' || character == 'w') character = 'u'; // bottom segment duplicated, so show in top half + } else { + if (character == 'u') character = 'v'; // we can use the bottom segment; move to lower half + else if (character == 'j') character = 'J'; // same but just display a normal J + } + if (position > 1) { + if (character == 'T') character = 't'; // uppercase T only works in positions 0 and 1 + } + if (position == 1) { + if (character == 'o') character = 'O'; // O needs to be uppercase + if (character == 'i') character = 'l'; // I needs to be uppercase (use an l, it looks the same) + if (character == 'n') character = 'N'; // N needs to be uppercase + if (character == 'r') character = 'R'; // R needs to be uppercase + if (character == 'd') character = 'D'; // D needs to be uppercase + if (character == 'v' || character == 'V' || character == 'u') character = 'U'; // side segments shared, make uppercase + if (character == 'b') character = 'B'; // B needs to be uppercase + if (character == 'c') character = 'C'; // C needs to be uppercase + } else { + if (character == 'R') character = 'r'; // R needs to be lowercase almost everywhere + } + if (position == 0) { + watch_clear_pixel(0, 15); // clear funky ninth segment + } else { + if (character == 'I') character = 'l'; // uppercase I only works in position 0 + } + + uint64_t segmap = Segment_Map[position]; + uint64_t segdata = Character_Set[character - 0x20]; + + for (int i = 0; i < 8; i++) { + uint8_t com = (segmap & 0xFF) >> 6; + if (com > 2) { + // COM3 means no segment exists; skip it. + segmap = segmap >> 8; + segdata = segdata >> 1; + continue; + } + uint8_t seg = segmap & 0x3F; + watch_clear_pixel(com, seg); + if (segdata & 1) watch_set_pixel(com, seg); + segmap = segmap >> 8; + segdata = segdata >> 1; + } + + if (character == 'T' && position == 1) watch_set_pixel(1, 12); // add descender + else if (position == 0 && (character == 'B' || character == 'D')) watch_set_pixel(0, 15); // add funky ninth segment + else if (position == 1 && (character == 'B' || character == 'D' || character == '@')) watch_set_pixel(0, 12); // add funky ninth segment +} + +void watch_display_string(char *string, uint8_t position) { + size_t i = 0; + while(string[i] != 0) { + watch_display_character(string[i], position + i); + i++; + if (position + i >= Num_Chars) break; + } + // uncomment this line to see screen output on terminal, i.e. + // FR 29 + // 11 50 23 + // note that for partial displays (positon > 0) it will only show the characters that were updated. + // printf("________\n %c%c %c%c\n%c%c %c%c %c%c\n--------\n", (position > 0) ? ' ' : string[0], (position > 1) ? ' ' : string[1 - position], (position > 2) ? ' ' : string[2 - position], (position > 3) ? ' ' : string[3 - position], (position > 4) ? ' ' : string[4 - position], (position > 5) ? ' ' : string[5 - position], (position > 6) ? ' ' : string[6 - position], (position > 7) ? ' ' : string[7 - position], (position > 8) ? ' ' : string[8 - position], (position > 9) ? ' ' : string[9 - position]); +} + +void watch_set_colon(void) { + watch_set_pixel(1, 16); +} + +void watch_clear_colon(void) { + watch_clear_pixel(1, 16); +} + +void watch_set_indicator(WatchIndicatorSegment indicator) { + uint32_t value = IndicatorSegments[indicator]; + uint8_t com = SLCD_COMNUM(value); + uint8_t seg = SLCD_SEGNUM(value); + watch_set_pixel(com, seg); +} + +void watch_clear_indicator(WatchIndicatorSegment indicator) { + uint32_t value = IndicatorSegments[indicator]; + uint8_t com = SLCD_COMNUM(value); + uint8_t seg = SLCD_SEGNUM(value); + watch_clear_pixel(com, seg); +} + +void watch_clear_all_indicators(void) { + watch_clear_pixel(2, 17); + watch_clear_pixel(2, 16); + watch_clear_pixel(0, 17); + watch_clear_pixel(0, 16); + watch_clear_pixel(1, 10); +} diff --git a/watch-library/shared/watch/watch_private_display.h b/watch-library/shared/watch/watch_private_display.h new file mode 100644 index 00000000..08597848 --- /dev/null +++ b/watch-library/shared/watch/watch_private_display.h @@ -0,0 +1,146 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _WATCH_PRIVATE_DISPLAY_H_INCLUDED +#define _WATCH_PRIVATE_DISPLAY_H_INCLUDED + +#include "hpl_slcd_config.h" +#include "driver_init.h" + +static const uint8_t Character_Set[] = +{ + 0b00000000, // + 0b01100000, // ! (L in the top half for positions 4 and 6) + 0b00100010, // " + 0b01100011, // # (degree symbol, hash mark doesn't fit) + 0b00000000, // $ (unused) + 0b00000000, // % (unused) + 0b01000100, // & ("lowercase 7" for positions 4 and 6) + 0b00100000, // ' + 0b00111001, // ( + 0b00001111, // ) + 0b00000000, // * (unused) + 0b11000000, // + (only works in position 0) + 0b00000100, // , + 0b01000000, // - + 0b01000000, // . (same as -, semantically most useful) + 0b00010010, // / + 0b00111111, // 0 + 0b00000110, // 1 + 0b01011011, // 2 + 0b01001111, // 3 + 0b01100110, // 4 + 0b01101101, // 5 + 0b01111101, // 6 + 0b00000111, // 7 + 0b01111111, // 8 + 0b01101111, // 9 + 0b00000000, // : (unused) + 0b00000000, // ; (unused) + 0b01011000, // < + 0b01001000, // = + 0b01001100, // > + 0b01010011, // ? + 0b11111111, // @ (all segments on) + 0b01110111, // A + 0b01111111, // B + 0b00111001, // C + 0b00111111, // D + 0b01111001, // E + 0b01110001, // F + 0b00111101, // G + 0b01110110, // H + 0b10001001, // I (only works in position 0) + 0b00001110, // J + 0b01110101, // K + 0b00111000, // L + 0b10110111, // M (only works in position 0) + 0b00110111, // N + 0b00111111, // O + 0b01110011, // P + 0b01100111, // Q + 0b11110111, // R (only works in position 1) + 0b01101101, // S + 0b10000001, // T (only works in position 0; set (1, 12) to make it work in position 1) + 0b00111110, // U + 0b00111110, // V + 0b10111110, // W (only works in position 0) + 0b01111110, // X + 0b01101110, // Y + 0b00011011, // Z + 0b00111001, // [ + 0b00100100, // backslash + 0b00001111, // ] + 0b00100011, // ^ + 0b00001000, // _ + 0b00000010, // ` + 0b01011111, // a + 0b01111100, // b + 0b01011000, // c + 0b01011110, // d + 0b01111011, // e + 0b01110001, // f + 0b01101111, // g + 0b01110100, // h + 0b00010000, // i + 0b01000010, // j (appears as superscript to work in more positions) + 0b01110101, // k + 0b00110000, // l + 0b10110111, // m (only works in position 0) + 0b01010100, // n + 0b01011100, // o + 0b01110011, // p + 0b01100111, // q + 0b01010000, // r + 0b01101101, // s + 0b01111000, // t + 0b01100010, // u (appears in (u)pper half to work in more positions) + 0b00011100, // v (looks like u but in the lower half) + 0b10111110, // w (only works in position 0) + 0b01111110, // x + 0b01101110, // y + 0b00011011, // z + 0b00111001, // { + 0b00110000, // | + 0b00001111, // } + 0b00000001, // ~ +}; + +static const uint64_t Segment_Map[] = { + 0x4e4f0e8e8f8d4d0d, // Position 0, mode + 0xc8c4c4c8b4b4b0b, // Position 1, mode (Segments B and C shared, as are segments E and F) + 0xc049c00a49890949, // Position 2, day of month (Segments A, D, G shared; missing segment F) + 0xc048088886874707, // Position 3, day of month + 0xc053921252139352, // Position 4, clock hours (Segments A and D shared) + 0xc054511415559594, // Position 5, clock hours + 0xc057965616179716, // Position 6, clock minutes (Segments A and D shared) + 0xc041804000018a81, // Position 7, clock minutes + 0xc043420203048382, // Position 8, clock seconds + 0xc045440506468584, // Position 9, clock seconds +}; + +static const uint8_t Num_Chars = 10; + +void watch_display_character(uint8_t character, uint8_t position); + +#endif diff --git a/watch-library/watch/watch_rtc.h b/watch-library/shared/watch/watch_rtc.h similarity index 100% rename from watch-library/watch/watch_rtc.h rename to watch-library/shared/watch/watch_rtc.h diff --git a/watch-library/watch/watch_slcd.h b/watch-library/shared/watch/watch_slcd.h similarity index 100% rename from watch-library/watch/watch_slcd.h rename to watch-library/shared/watch/watch_slcd.h diff --git a/watch-library/watch/watch_uart.h b/watch-library/shared/watch/watch_uart.h similarity index 100% rename from watch-library/watch/watch_uart.h rename to watch-library/shared/watch/watch_uart.h diff --git a/watch-library/watch/watch_utility.c b/watch-library/shared/watch/watch_utility.c similarity index 100% rename from watch-library/watch/watch_utility.c rename to watch-library/shared/watch/watch_utility.c diff --git a/watch-library/watch/watch_utility.h b/watch-library/shared/watch/watch_utility.h similarity index 100% rename from watch-library/watch/watch_utility.h rename to watch-library/shared/watch/watch_utility.h diff --git a/watch-library/simulator/hpl/port/hpl_gpio_base.h b/watch-library/simulator/hpl/port/hpl_gpio_base.h new file mode 100644 index 00000000..c8fd6e0e --- /dev/null +++ b/watch-library/simulator/hpl/port/hpl_gpio_base.h @@ -0,0 +1,87 @@ + +/** + * \file + * + * \brief SAM PORT. + * + * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries. + * + * \asf_license_start + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip + * software and any derivatives exclusively with Microchip products. + * It is your responsibility to comply with third party license terms applicable + * to your use of third party software (including open source software) that + * may accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, + * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, + * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, + * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE + * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL + * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE + * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE + * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT + * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY + * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, + * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. + * + * \asf_license_stop + * + */ +#include +#include +#include +#include + +/** + * \brief Set direction on port with mask + */ +static inline void _gpio_set_direction(const enum gpio_port port, const uint32_t mask, + const enum gpio_direction direction) +{ +} + +/** + * \brief Set output level on port with mask + */ +static inline void _gpio_set_level(const enum gpio_port port, const uint32_t mask, const bool level) +{ +} + +/** + * \brief Change output level to the opposite with mask + */ +static inline void _gpio_toggle_level(const enum gpio_port port, const uint32_t mask) +{ +} + +/** + * \brief Get input levels on all port pins + */ +static inline uint32_t _gpio_get_level(const enum gpio_port port) +{ + uint32_t tmp = 0; + return tmp; +} + +/** + * \brief Set pin pull mode + */ +static inline void _gpio_set_pin_pull_mode(const enum gpio_port port, const uint8_t pin, + const enum gpio_pull_mode pull_mode) +{ +} + +/** + * \brief Set gpio pin function + */ +static inline void _gpio_set_pin_function(const uint32_t gpio, const uint32_t function) +{ +} + +static inline void _port_event_init() +{ +} diff --git a/watch-library/simulator/main.c b/watch-library/simulator/main.c new file mode 100644 index 00000000..5596bf82 --- /dev/null +++ b/watch-library/simulator/main.c @@ -0,0 +1,70 @@ +/* + * MIT License + * + * Copyright (c) 2022 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "watch.h" + +#include +#include + +static bool sleeping = true; + +static EM_BOOL main_loop(double time, void *userData) { + if (sleeping) { + sleeping = false; + app_wake_from_standby(); + } + + bool can_sleep = app_loop(); + + if (can_sleep) { + app_prepare_for_standby(); + sleeping = true; + return EM_FALSE; + } + + return EM_TRUE; +} + +// make compiler happy +void resume_main_loop(void); + +EMSCRIPTEN_KEEPALIVE +void resume_main_loop(void) { + if (sleeping) { + emscripten_request_animation_frame_loop(main_loop, NULL); + } +} + +int main(void) { + printf("Hello, world!\n"); + + app_init(); + _watch_init(); + app_setup(); + + resume_main_loop(); + + return 0; +} diff --git a/watch-library/simulator/shell.html b/watch-library/simulator/shell.html new file mode 100644 index 00000000..1a4de984 --- /dev/null +++ b/watch-library/simulator/shell.html @@ -0,0 +1,368 @@ + + + + + Sensor Watch Emulator + + + + + + +
+

Sensor Watch Emulator

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Original F-91W SVG is © 2020 Alexis Philip, and is used here under the terms of the MIT license.

+
+ + + + +{{{ SCRIPT }}} + + + diff --git a/watch-library/simulator/watch/watch.c b/watch-library/simulator/watch/watch.c new file mode 100644 index 00000000..2b14d0ab --- /dev/null +++ b/watch-library/simulator/watch/watch.c @@ -0,0 +1,9 @@ +#include "watch.h" + +bool watch_is_battery_low(void) { + return false; +} + +bool watch_is_buzzer_or_led_enabled(void) { + return false; +} diff --git a/watch-library/simulator/watch/watch_adc.c b/watch-library/simulator/watch/watch_adc.c new file mode 100644 index 00000000..364e2119 --- /dev/null +++ b/watch-library/simulator/watch/watch_adc.c @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_adc.h" + +void watch_enable_adc(void) {} + +void watch_enable_analog_input(const uint8_t pin) {} + +uint16_t watch_get_analog_pin_level(const uint8_t pin) { + return 0; +} + +void watch_set_analog_num_samples(uint16_t samples) {} + +void watch_set_analog_sampling_length(uint8_t cycles) {} + +void watch_set_analog_reference_voltage(watch_adc_reference_voltage reference) {} + +uint16_t watch_get_vcc_voltage(void) { + // TODO: (a2) hook to UI + return 3000; +} + +inline void watch_disable_analog_input(const uint8_t pin) {} + +inline void watch_disable_adc(void) {} diff --git a/watch-library/simulator/watch/watch_buzzer.c b/watch-library/simulator/watch/watch_buzzer.c new file mode 100644 index 00000000..f19e1928 --- /dev/null +++ b/watch-library/simulator/watch/watch_buzzer.c @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_buzzer.h" + +inline void watch_enable_buzzer(void) { + // TODO: (a2) hook to UI +} +inline void watch_set_buzzer_period(uint32_t period) { + // TODO: (a2) hook to UI +} + +void watch_disable_buzzer(void) { + _watch_disable_tcc(); +} + +inline void watch_set_buzzer_on(void) { + // TODO: (a2) hook to UI +} + +inline void watch_set_buzzer_off(void) { + // TODO: (a2) hook to UI +} + +// note: the buzzer uses a 1 MHz clock. these values were determined by dividing 1,000,000 by the target frequency. +// i.e. for a 440 Hz tone (A4 on the piano), 1MHz/440Hz = 2273 +const uint16_t NotePeriods[108] = {0}; + +void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms) { + if (note == BUZZER_NOTE_REST) { + watch_set_buzzer_off(); + } // else { + // hri_tcc_write_PERBUF_reg(TCC0, NotePeriods[note]); + // hri_tcc_write_CCBUF_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, NotePeriods[note] / 2); + // watch_set_buzzer_on(); + // } + // delay_ms(duration_ms); + // watch_set_buzzer_off(); +} diff --git a/watch-library/simulator/watch/watch_deepsleep.c b/watch-library/simulator/watch/watch_deepsleep.c new file mode 100644 index 00000000..9f409570 --- /dev/null +++ b/watch-library/simulator/watch/watch_deepsleep.c @@ -0,0 +1,99 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_extint.h" + +// this warning only appears when you `make BOARD=OSO-SWAT-A1-02`. it's annoying, +// but i'd rather have it warn us at build-time than fail silently at run-time. +// besides, no one but me really has any of these boards anyway. +#if BTN_ALARM != GPIO(GPIO_PORTA, 2) +#warning This board revision does not support external wake on BTN_ALARM, so watch_register_extwake_callback will not work with it. Use watch_register_interrupt_callback instead. +#endif + +static uint32_t watch_backup_data[8]; + +void watch_register_extwake_callback(uint8_t pin, ext_irq_cb_t callback, bool level) { + if (pin == BTN_ALARM) { + watch_register_interrupt_callback(pin, callback, level ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING); + } +} + +void watch_disable_extwake_interrupt(uint8_t pin) { + if (pin == BTN_ALARM) { + watch_register_interrupt_callback(pin, NULL, INTERRUPT_TRIGGER_NONE); + } +} + +void watch_store_backup_data(uint32_t data, uint8_t reg) { + if (reg < 8) { + watch_backup_data[reg] = data; + } +} + +uint32_t watch_get_backup_data(uint8_t reg) { + if (reg < 8) { + return watch_backup_data[reg]; + } + + return 0; +} + +void watch_enter_sleep_mode(void) { + // TODO: (a2) hook to UI + + // enter standby (4); we basically hang out here until an interrupt wakes us. + // sleep(4); + + // call app_setup so the app can re-enable everything we disabled. + app_setup(); + + // and call app_wake_from_standby (since main won't have a chance to do it) + app_wake_from_standby(); +} + +void watch_enter_deep_sleep_mode(void) { + // identical to sleep mode except we disable the LCD first. + // TODO: (a2) hook to UI + + watch_enter_sleep_mode(); +} + +void watch_enter_backup_mode(void) { + // TODO: (a2) hook to UI + + // go into backup sleep mode (5). when we exit, the reset controller will take over. + // sleep(5); +} + +// deprecated +void watch_enter_shallow_sleep(bool display_on) { + if (display_on) watch_enter_sleep_mode(); + else watch_enter_deep_sleep_mode(); +} + +// deprecated +void watch_enter_deep_sleep(void) { + watch_register_extwake_callback(BTN_ALARM, NULL, true); + watch_enter_backup_mode(); +} diff --git a/watch-library/simulator/watch/watch_extint.c b/watch-library/simulator/watch/watch_extint.c new file mode 100644 index 00000000..d37059bf --- /dev/null +++ b/watch-library/simulator/watch/watch_extint.c @@ -0,0 +1,191 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_extint.h" + +#include +#include + +static bool output_focused = false; +static bool external_interrupt_enabled = false; +static bool button_callbacks_installed = false; +static ext_irq_cb_t external_interrupt_mode_callback = NULL; +static watch_interrupt_trigger external_interrupt_mode_trigger = INTERRUPT_TRIGGER_NONE; +static ext_irq_cb_t external_interrupt_light_callback = NULL; +static watch_interrupt_trigger external_interrupt_light_trigger = INTERRUPT_TRIGGER_NONE; +static ext_irq_cb_t external_interrupt_alarm_callback = NULL; +static watch_interrupt_trigger external_interrupt_alarm_trigger = INTERRUPT_TRIGGER_NONE; + +#define BTN_ID_ALARM 3 +#define BTN_ID_LIGHT 1 +#define BTN_ID_MODE 2 +static const uint8_t BTN_IDS[] = { BTN_ID_ALARM, BTN_ID_LIGHT, BTN_ID_MODE }; +static void watch_invoke_interrupt_callback(const uint8_t button_id, watch_interrupt_trigger trigger); + +static EM_BOOL watch_invoke_key_callback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) { + if (output_focused || keyEvent->repeat) return EM_FALSE; + + const char *key = keyEvent->key; + if (key[1] != 0) return EM_FALSE; + + uint8_t button_id; + switch (key[0]) { + case 'A': + case 'a': + button_id = BTN_ID_ALARM; + break; + case 'L': + case 'l': + button_id = BTN_ID_LIGHT; + break; + case 'M': + case 'm': + button_id = BTN_ID_MODE; + break; + default: + return EM_FALSE; + } + + watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_KEYDOWN ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING; + watch_invoke_interrupt_callback(button_id, trigger); + return EM_TRUE; +} + +static EM_BOOL watch_invoke_mouse_callback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { + if (eventType == EMSCRIPTEN_EVENT_MOUSEOUT && mouseEvent->buttons == 0) return EM_FALSE; + uint8_t button_id = *(const char *)userData; + watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_MOUSEDOWN ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING; + watch_invoke_interrupt_callback(button_id, trigger); + return EM_TRUE; +} + +static EM_BOOL watch_invoke_touch_callback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData) { + uint8_t button_id = *(const char *)userData; + watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_TOUCHSTART ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING; + watch_invoke_interrupt_callback(button_id, trigger); + return EM_TRUE; +} + +static EM_BOOL watch_invoke_focus_callback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData) { + output_focused = eventType == EMSCRIPTEN_EVENT_FOCUS; + return EM_TRUE; +} + +static void watch_install_button_callbacks(void) { + emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, EM_FALSE, watch_invoke_key_callback); + emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, EM_FALSE, watch_invoke_key_callback); + + const char *target_output = "#output"; + emscripten_set_focus_callback(target_output, NULL, EM_FALSE, watch_invoke_focus_callback); + emscripten_set_blur_callback(target_output, NULL, EM_FALSE, watch_invoke_focus_callback); + + for (int i = 0, count = sizeof(BTN_IDS) / sizeof(BTN_IDS[0]); i < count; i++) { + char target[] = "#btn_"; + target[4] = BTN_IDS[i] + '0'; + + emscripten_set_mousedown_callback(target, (void *)&BTN_IDS[i], EM_FALSE, watch_invoke_mouse_callback); + emscripten_set_mouseup_callback(target, (void *)&BTN_IDS[i], EM_FALSE, watch_invoke_mouse_callback); + emscripten_set_mouseout_callback(target, (void *)&BTN_IDS[i], EM_FALSE, watch_invoke_mouse_callback); + + emscripten_set_touchstart_callback(target, (void *)&BTN_IDS[i], EM_FALSE, watch_invoke_touch_callback); + emscripten_set_touchend_callback(target, (void *)&BTN_IDS[i], EM_FALSE, watch_invoke_touch_callback); + } +} + +void watch_enable_external_interrupts(void) { + external_interrupt_enabled = true; + + if (!button_callbacks_installed) { + watch_install_button_callbacks(); + button_callbacks_installed = true; + } +} + +void watch_disable_external_interrupts(void) { + external_interrupt_enabled = false; +} + +static void watch_invoke_interrupt_callback(const uint8_t button_id, watch_interrupt_trigger event) { + if (!external_interrupt_enabled) return; + + ext_irq_cb_t callback; + watch_interrupt_trigger trigger; + uint8_t pin; + switch (button_id) { + case BTN_ID_MODE: + pin = BTN_MODE; + callback = external_interrupt_mode_callback; + trigger = external_interrupt_mode_trigger; + break; + case BTN_ID_LIGHT: + pin = BTN_LIGHT; + callback = external_interrupt_light_callback; + trigger = external_interrupt_light_trigger; + break; + case BTN_ID_ALARM: + pin = BTN_ALARM; + callback = external_interrupt_alarm_callback; + trigger = external_interrupt_alarm_trigger; + break; + default: + return; + } + + const bool level = (event & INTERRUPT_TRIGGER_RISING) != 0; + EM_ASM({ + const classList = document.querySelector('#btn' + $0).classList; + const highlight = 'highlight'; + $1 ? classList.add(highlight) : classList.remove(highlight); + }, button_id, level); + + watch_set_pin_level(pin, level); + + if (callback && (event & trigger) != 0) { + callback(); + + void resume_main_loop(void); + resume_main_loop(); + } +} + +void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback, watch_interrupt_trigger trigger) { + if (pin == BTN_MODE) { + external_interrupt_mode_callback = callback; + external_interrupt_mode_trigger = trigger; + } else if (pin == BTN_LIGHT) { + external_interrupt_light_callback = callback; + external_interrupt_light_trigger = trigger; + } else if (pin == BTN_ALARM) { + external_interrupt_alarm_callback = callback; + external_interrupt_alarm_trigger = trigger; + } +} + +void watch_register_button_callback(const uint8_t pin, ext_irq_cb_t callback) { + watch_register_interrupt_callback(pin, callback, INTERRUPT_TRIGGER_RISING); +} + +void watch_enable_buttons(void) { + watch_enable_external_interrupts(); +} diff --git a/watch-library/simulator/watch/watch_gpio.c b/watch-library/simulator/watch/watch_gpio.c new file mode 100644 index 00000000..4bea2c11 --- /dev/null +++ b/watch-library/simulator/watch/watch_gpio.c @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_gpio.h" + +static bool pin_levels[UINT8_MAX]; + +void watch_enable_digital_input(const uint8_t pin) {} + +void watch_disable_digital_input(const uint8_t pin) {} + +void watch_enable_pull_up(const uint8_t pin) {} + +void watch_enable_pull_down(const uint8_t pin) {} + +bool watch_get_pin_level(const uint8_t pin) { + return pin_levels[pin]; +} + +void watch_enable_digital_output(const uint8_t pin) {} + +void watch_disable_digital_output(const uint8_t pin) {} + +void watch_set_pin_level(const uint8_t pin, const bool level) { + pin_levels[pin] = level; +} diff --git a/watch-library/simulator/watch/watch_i2c.c b/watch-library/simulator/watch/watch_i2c.c new file mode 100644 index 00000000..09339888 --- /dev/null +++ b/watch-library/simulator/watch/watch_i2c.c @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_i2c.h" + +void watch_enable_i2c(void) {} + +void watch_disable_i2c(void) {} + +void watch_i2c_send(int16_t addr, uint8_t *buf, uint16_t length) {} + +void watch_i2c_receive(int16_t addr, uint8_t *buf, uint16_t length) {} + +void watch_i2c_write8(int16_t addr, uint8_t reg, uint8_t data) {} + +uint8_t watch_i2c_read8(int16_t addr, uint8_t reg) { + return 0; +} + +uint16_t watch_i2c_read16(int16_t addr, uint8_t reg) { + return 0; +} + +uint32_t watch_i2c_read24(int16_t addr, uint8_t reg) { + return 0; +} + +uint32_t watch_i2c_read32(int16_t addr, uint8_t reg) { + return 0; +} diff --git a/watch-library/simulator/watch/watch_led.c b/watch-library/simulator/watch/watch_led.c new file mode 100644 index 00000000..173f1b08 --- /dev/null +++ b/watch-library/simulator/watch/watch_led.c @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_led.h" + +#include + +void watch_enable_leds(void) {} + +void watch_disable_leds(void) {} + +void watch_enable_led(bool unused) { + (void)unused; + watch_enable_leds(); +} + +void watch_disable_led(bool unused) { + (void)unused; + watch_disable_leds(); +} + +void watch_set_led_color(uint8_t red, uint8_t green) { + EM_ASM({ + document.getElementById('light').style.opacity = $1 / 255; + }, red, green); +} + +void watch_set_led_red(void) { + watch_set_led_color(255, 0); +} + +void watch_set_led_green(void) { + watch_set_led_color(0, 255); +} + +void watch_set_led_yellow(void) { + watch_set_led_color(255, 255); +} + +void watch_set_led_off(void) { + watch_set_led_color(0, 0); +} diff --git a/watch-library/simulator/watch/watch_private.c b/watch-library/simulator/watch/watch_private.c new file mode 100644 index 00000000..b852893b --- /dev/null +++ b/watch-library/simulator/watch/watch_private.c @@ -0,0 +1,78 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_private.h" +#include "watch_utility.h" +#include + +void _watch_init(void) { + // External wake depends on RTC; calendar is a required module. + _watch_rtc_init(); +} + +// this function is called by arc4random to get entropy for random number generation. +// let's use the SAM L22's true random number generator to seed the PRNG! +int getentropy(void *buf, size_t buflen); +int getentropy(void *buf, size_t buflen) { + // TODO: (a2) hook to RNG + return 0; +} + +int _gettimeofday(struct timeval *tv, void *tzvp); +int _gettimeofday(struct timeval *tv, void *tzvp) { + (void)tzvp; + watch_date_time date_time = watch_rtc_get_date_time(); + + // FIXME: this assumes the system time is UTC! Will break for any other time zone. + tv->tv_sec = watch_utility_date_time_to_unix_time(date_time, 0); + tv->tv_usec = 0; + + return 0; +} + +void _watch_enable_tcc(void) {} + +void _watch_disable_tcc(void) {} + +void _watch_enable_usb(void) {} + +// this function ends up getting called by printf to log stuff to the USB console. +int _write(int file, char *ptr, int len) { + // TODO: (a2) hook to UI + return 0; +} + +// this method could be overridden to read stuff from the USB console? but no need rn. +int _read(void) { + return 0; +} + +// Alternate function that outputs to the debug UART. useful for debugging USB issues. +// int _write(int file, char *ptr, int len) { +// (void)file; +// int pos = 0; +// while(pos < len) watch_debug_putc(ptr[pos++]); + +// return 0; +// } diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c new file mode 100644 index 00000000..573c0ff2 --- /dev/null +++ b/watch-library/simulator/watch/watch_rtc.c @@ -0,0 +1,223 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_rtc.h" + +#include +#include + +static double time_offset = 0; +static long tick_callbacks[8]; + +static long alarm_interval_id; +static long alarm_timeout_id; +static double alarm_interval; +ext_irq_cb_t alarm_callback; +ext_irq_cb_t btn_alarm_callback; +ext_irq_cb_t a2_callback; +ext_irq_cb_t a4_callback; + +bool _watch_rtc_is_enabled(void) { + return true; +} + +void _watch_rtc_init(void) { +} + +void watch_rtc_set_date_time(watch_date_time date_time) { + time_offset = EM_ASM_DOUBLE({ + const year = 2020 + (($0 >> 26) & 0x3f); + const month = ($0 >> 22) & 0xf; + const day = ($0 >> 17) & 0x1f; + const hour = ($0 >> 12) & 0x1f; + const minute = ($0 >> 6) & 0x3f; + const second = $0 & 0x3f; + const date = new Date(year, month - 1, day, hour, minute, second); + return date - Date.now(); + }, date_time.reg); +} + +watch_date_time watch_rtc_get_date_time(void) { + watch_date_time retval; + retval.reg = EM_ASM_INT({ + const date = new Date(Date.now() + $0); + return date.getSeconds() | + (date.getMinutes() << 6) | + (date.getHours() << 12) | + (date.getDate() << 17) | + ((date.getMonth() + 1) << 22) | + ((date.getFullYear() - 2020) << 26); + }, time_offset); + return retval; +} + +void watch_rtc_register_tick_callback(ext_irq_cb_t callback) { + watch_rtc_register_periodic_callback(callback, 1); +} + +void watch_rtc_disable_tick_callback(void) { + watch_rtc_disable_periodic_callback(1); +} + +static void watch_invoke_periodic_callback(void *userData) { + ext_irq_cb_t callback = userData; + callback(); + + void resume_main_loop(void); + resume_main_loop(); +} + +void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequency) { + // we told them, it has to be a power of 2. + if (__builtin_popcount(frequency) != 1) return; + + // this left-justifies the period in a 32-bit integer. + uint32_t tmp = frequency << 24; + // now we can count the leading zeroes to get the value we need. + // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. + uint8_t per_n = __builtin_clz(tmp); + + // this also maps nicely to an index for our list of tick callbacks. + double interval = 1000 / frequency; // in msec + tick_callbacks[per_n] = emscripten_set_interval(watch_invoke_periodic_callback, interval, (void *)callback); +} + +void watch_rtc_disable_periodic_callback(uint8_t frequency) { + if (__builtin_popcount(frequency) != 1) return; + uint8_t per_n = __builtin_clz(frequency << 24); + emscripten_clear_interval(tick_callbacks[per_n]); + tick_callbacks[per_n] = 0; +} + +void watch_rtc_disable_all_periodic_callbacks(void) { + for (int i = 0; i < 8; i++) { + if (tick_callbacks[i] != 0) { + emscripten_clear_interval(tick_callbacks[i]); + tick_callbacks[i] = 0; + } + } +} + +static void watch_invoke_alarm_interval_callback(void *userData) { + (void)userData; + if (alarm_callback) alarm_callback(); +} + +static void watch_invoke_alarm_callback(void *userData) { + (void)userData; + if (alarm_callback) alarm_callback(); + alarm_interval_id = emscripten_set_interval(watch_invoke_alarm_interval_callback, alarm_interval, NULL); +} + +void watch_rtc_register_alarm_callback(ext_irq_cb_t callback, watch_date_time alarm_time, watch_rtc_alarm_match mask) { + watch_rtc_disable_alarm_callback(); + + switch (mask) { + case ALARM_MATCH_DISABLED: + return; + case ALARM_MATCH_SS: + alarm_interval = 60 * 1000; + break; + case ALARM_MATCH_MMSS: + alarm_interval = 60 * 60 * 1000; + break; + case ALARM_MATCH_HHMMSS: + alarm_interval = 60 * 60 * 60 * 1000; + break; + } + + double timeout = EM_ASM_DOUBLE({ + const now = Date.now(); + const date = new Date(now + $0); + + const hour = ($1 >> 12) & 0x1f; + const minute = ($1 >> 6) & 0x3f; + const second = $1 & 0x3f; + + if ($2 == 1) { // SS + if (second < date.getSeconds()) date.setMinutes(date.getMinutes() + 1); + date.setSeconds(second); + } else if ($2 == 2) { // MMSS + if (second < date.getSeconds()) date.setMinutes(date.getMinutes() + 1); + if (minute < date.getMinutes()) date.setHours(date.getHours() + 1); + date.setMinutes(minute, second); + } else if ($2 == 3) { // HHMMSS + if (second < date.getSeconds()) date.setMinutes(date.getMinutes() + 1); + if (minute < date.getMinutes()) date.setHours(date.getHours() + 1); + if (hour < date.getHours()) date.setDate(date.getDate() + 1); + date.setHours(hour, minute, second); + } else { + throw 'Invalid alarm match mask'; + } + + return date - now; + }, time_offset, alarm_time.reg, mask); + + alarm_callback = callback; + alarm_timeout_id = emscripten_set_timeout(watch_invoke_alarm_callback, timeout, NULL); +} + +void watch_rtc_disable_alarm_callback(void) { + alarm_callback = NULL; + alarm_interval = 0; + + if (alarm_timeout_id) { + emscripten_clear_timeout(alarm_timeout_id); + alarm_timeout_id = 0; + } + + if (alarm_interval_id) { + emscripten_clear_interval(alarm_interval_id); + alarm_interval_id = 0; + } +} + +/////////////////////// +// Deprecated functions + +void watch_set_date_time(struct calendar_date_time date_time) { + watch_date_time val; + val.unit.second = date_time.time.sec; + val.unit.minute = date_time.time.min; + val.unit.hour = date_time.time.hour; + val.unit.day = date_time.date.day; + val.unit.month = date_time.date.month; + val.unit.year = date_time.date.year - WATCH_RTC_REFERENCE_YEAR; + watch_rtc_set_date_time(val); +} + +void watch_get_date_time(struct calendar_date_time *date_time) { + if (date_time == NULL) return; + watch_date_time val = watch_rtc_get_date_time(); + date_time->time.sec = val.unit.second; + date_time->time.min = val.unit.minute; + date_time->time.hour = val.unit.hour; + date_time->date.day = val.unit.day; + date_time->date.month = val.unit.month; + date_time->date.year = val.unit.year + WATCH_RTC_REFERENCE_YEAR; +} + +void watch_register_tick_callback(ext_irq_cb_t callback) { + watch_rtc_register_tick_callback(callback); +} diff --git a/watch-library/simulator/watch/watch_slcd.c b/watch-library/simulator/watch/watch_slcd.c new file mode 100644 index 00000000..2af96847 --- /dev/null +++ b/watch-library/simulator/watch/watch_slcd.c @@ -0,0 +1,115 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_slcd.h" +#include "watch_private_display.h" +#include "hpl_slcd_config.h" + +#include +#include + +////////////////////////////////////////////////////////////////////////////////////////// +// Segmented Display + +static char blink_character; +static bool blink_state; +static long blink_interval_id; +static bool tick_state; +static long tick_interval_id; + +void watch_enable_display(void) { + watch_clear_display(); +} + +void watch_set_pixel(uint8_t com, uint8_t seg) { + EM_ASM({ + document.querySelectorAll("[data-com='" + $0 + "'][data-seg='" + $1 + "']") + .forEach((e) => e.style.opacity = 1); + }, com, seg); +} + +void watch_clear_pixel(uint8_t com, uint8_t seg) { + EM_ASM({ + document.querySelectorAll("[data-com='" + $0 + "'][data-seg='" + $1 + "']") + .forEach((e) => e.style.opacity = 0); + }, com, seg); +} + +void watch_clear_display(void) { + EM_ASM({ + document.querySelectorAll("[data-com][data-seg]") + .forEach((e) => e.style.opacity = 0); + }); +} + +static void watch_invoke_blink_callback(void *userData) { + blink_state = !blink_state; + watch_display_character(blink_state ? blink_character : ' ', 7); + watch_clear_pixel(2, 10); // clear segment B of position 7 since it can't blink +} + +void watch_start_character_blink(char character, uint32_t duration) { + watch_display_character(character, 7); + watch_clear_pixel(2, 10); // clear segment B of position 7 since it can't blink + + blink_state = true; + blink_character = character; + blink_interval_id = emscripten_set_interval(watch_invoke_blink_callback, (double)duration, NULL); +} + +void watch_stop_blink(void) { + emscripten_clear_timeout(blink_interval_id); + blink_interval_id = 0; + blink_state = false; +} + +static void watch_invoke_tick_callback(void *userData) { + tick_state = !tick_state; + if (tick_state) { + watch_clear_pixel(0, 2); + watch_set_pixel(0, 3); + } else { + watch_clear_pixel(0, 3); + watch_set_pixel(0, 2); + } +} + +void watch_start_tick_animation(uint32_t duration) { + watch_display_character(' ', 8); + + tick_state = true; + tick_interval_id = emscripten_set_interval(watch_invoke_tick_callback, (double)duration, NULL); +} + +bool watch_tick_animation_is_running(void) { + return tick_interval_id != 0; +} + +void watch_stop_tick_animation(void) { + emscripten_clear_timeout(tick_interval_id); + tick_interval_id = 0; + tick_state = false; + + watch_display_character(' ', 8); +} diff --git a/watch-library/simulator/watch/watch_uart.c b/watch-library/simulator/watch/watch_uart.c new file mode 100644 index 00000000..e37fabff --- /dev/null +++ b/watch-library/simulator/watch/watch_uart.c @@ -0,0 +1,65 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + /* + * UART methods are Copyright (c) 2014-2017, Alex Taradov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "watch_uart.h" +#include "peripheral_clk_config.h" + +void watch_enable_debug_uart(uint32_t baud) {} + +void watch_debug_putc(char c) {} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void watch_debug_puts(char *s) { + while (*s) watch_debug_putc(*s++); +} +#pragma GCC diagnostic pop diff --git a/watch-library/watch/watch_slcd.c b/watch-library/watch/watch_slcd.c deleted file mode 100644 index 1b1e53e4..00000000 --- a/watch-library/watch/watch_slcd.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020 Joey Castillo - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "watch_slcd.h" -#include "hpl_slcd_config.h" - - ////////////////////////////////////////////////////////////////////////////////////////// -// Segmented Display - -static const uint8_t Character_Set[] = -{ - 0b00000000, // - 0b01100000, // ! (L in the top half for positions 4 and 6) - 0b00100010, // " - 0b01100011, // # (degree symbol, hash mark doesn't fit) - 0b00000000, // $ (unused) - 0b00000000, // % (unused) - 0b01000100, // & ("lowercase 7" for positions 4 and 6) - 0b00100000, // ' - 0b00111001, // ( - 0b00001111, // ) - 0b00000000, // * (unused) - 0b11000000, // + (only works in position 0) - 0b00000100, // , - 0b01000000, // - - 0b01000000, // . (same as -, semantically most useful) - 0b00010010, // / - 0b00111111, // 0 - 0b00000110, // 1 - 0b01011011, // 2 - 0b01001111, // 3 - 0b01100110, // 4 - 0b01101101, // 5 - 0b01111101, // 6 - 0b00000111, // 7 - 0b01111111, // 8 - 0b01101111, // 9 - 0b00000000, // : (unused) - 0b00000000, // ; (unused) - 0b01011000, // < - 0b01001000, // = - 0b01001100, // > - 0b01010011, // ? - 0b11111111, // @ (all segments on) - 0b01110111, // A - 0b01111111, // B - 0b00111001, // C - 0b00111111, // D - 0b01111001, // E - 0b01110001, // F - 0b00111101, // G - 0b01110110, // H - 0b10001001, // I (only works in position 0) - 0b00001110, // J - 0b01110101, // K - 0b00111000, // L - 0b10110111, // M (only works in position 0) - 0b00110111, // N - 0b00111111, // O - 0b01110011, // P - 0b01100111, // Q - 0b11110111, // R (only works in position 1) - 0b01101101, // S - 0b10000001, // T (only works in position 0; set (1, 12) to make it work in position 1) - 0b00111110, // U - 0b00111110, // V - 0b10111110, // W (only works in position 0) - 0b01111110, // X - 0b01101110, // Y - 0b00011011, // Z - 0b00111001, // [ - 0b00100100, // backslash - 0b00001111, // ] - 0b00100011, // ^ - 0b00001000, // _ - 0b00000010, // ` - 0b01011111, // a - 0b01111100, // b - 0b01011000, // c - 0b01011110, // d - 0b01111011, // e - 0b01110001, // f - 0b01101111, // g - 0b01110100, // h - 0b00010000, // i - 0b01000010, // j (appears as superscript to work in more positions) - 0b01110101, // k - 0b00110000, // l - 0b10110111, // m (only works in position 0) - 0b01010100, // n - 0b01011100, // o - 0b01110011, // p - 0b01100111, // q - 0b01010000, // r - 0b01101101, // s - 0b01111000, // t - 0b01100010, // u (appears in (u)pper half to work in more positions) - 0b00011100, // v (looks like u but in the lower half) - 0b10111110, // w (only works in position 0) - 0b01111110, // x - 0b01101110, // y - 0b00011011, // z - 0b00111001, // { - 0b00110000, // | - 0b00001111, // } - 0b00000001, // ~ -}; - -static const uint64_t Segment_Map[] = { - 0x4e4f0e8e8f8d4d0d, // Position 0, mode - 0xc8c4c4c8b4b4b0b, // Position 1, mode (Segments B and C shared, as are segments E and F) - 0xc049c00a49890949, // Position 2, day of month (Segments A, D, G shared; missing segment F) - 0xc048088886874707, // Position 3, day of month - 0xc053921252139352, // Position 4, clock hours (Segments A and D shared) - 0xc054511415559594, // Position 5, clock hours - 0xc057965616179716, // Position 6, clock minutes (Segments A and D shared) - 0xc041804000018a81, // Position 7, clock minutes - 0xc043420203048382, // Position 8, clock seconds - 0xc045440506468584, // Position 9, clock seconds -}; - -static const uint8_t Num_Chars = 10; - -static const uint32_t IndicatorSegments[6] = { - SLCD_SEGID(0, 17), // WATCH_INDICATOR_SIGNAL - SLCD_SEGID(0, 16), // WATCH_INDICATOR_BELL - SLCD_SEGID(2, 17), // WATCH_INDICATOR_PM - SLCD_SEGID(2, 16), // WATCH_INDICATOR_24H - SLCD_SEGID(1, 10), // WATCH_INDICATOR_LAP -}; - -static void _sync_slcd(void) { - while (SLCD->SYNCBUSY.reg); -} - -void watch_enable_display(void) { - SEGMENT_LCD_0_init(); - slcd_sync_enable(&SEGMENT_LCD_0); -} - -inline void watch_set_pixel(uint8_t com, uint8_t seg) { - slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); -} - -inline void watch_clear_pixel(uint8_t com, uint8_t seg) { - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); -} - -void watch_clear_display(void) { - SLCD->SDATAL0.reg = 0; - SLCD->SDATAL1.reg = 0; - SLCD->SDATAL2.reg = 0; -} - -static void watch_display_character(uint8_t character, uint8_t position) { - // special cases for positions 4 and 6 - if (position == 4 || position == 6) { - if (character == '7') character = '&'; // "lowercase" 7 - else if (character == 'A') character = 'a'; // A needs to be lowercase - else if (character == 'o') character = 'O'; // O needs to be uppercase - else if (character == 'L') character = '!'; // L needs to be in top half - else if (character == 'M' || character == 'm' || character == 'N') character = 'n'; // M and uppercase N need to be lowercase n - else if (character == 'c') character = 'C'; // C needs to be uppercase - else if (character == 'J') character = 'j'; // same - else if (character == 'v' || character == 'V' || character == 'U' || character == 'W' || character == 'w') character = 'u'; // bottom segment duplicated, so show in top half - } else { - if (character == 'u') character = 'v'; // we can use the bottom segment; move to lower half - else if (character == 'j') character = 'J'; // same but just display a normal J - } - if (position > 1) { - if (character == 'T') character = 't'; // uppercase T only works in positions 0 and 1 - } - if (position == 1) { - if (character == 'o') character = 'O'; // O needs to be uppercase - if (character == 'i') character = 'l'; // I needs to be uppercase (use an l, it looks the same) - if (character == 'n') character = 'N'; // N needs to be uppercase - if (character == 'r') character = 'R'; // R needs to be uppercase - if (character == 'd') character = 'D'; // D needs to be uppercase - if (character == 'v' || character == 'V' || character == 'u') character = 'U'; // side segments shared, make uppercase - if (character == 'b') character = 'B'; // B needs to be uppercase - if (character == 'c') character = 'C'; // C needs to be uppercase - } else { - if (character == 'R') character = 'r'; // R needs to be lowercase almost everywhere - } - if (position == 0) { - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(0, 15)); // clear funky ninth segment - } else { - if (character == 'I') character = 'l'; // uppercase I only works in position 0 - } - - uint64_t segmap = Segment_Map[position]; - uint64_t segdata = Character_Set[character - 0x20]; - - for (int i = 0; i < 8; i++) { - uint8_t com = (segmap & 0xFF) >> 6; - if (com > 2) { - // COM3 means no segment exists; skip it. - segmap = segmap >> 8; - segdata = segdata >> 1; - continue; - } - uint8_t seg = segmap & 0x3F; - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); - if (segdata & 1) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); - segmap = segmap >> 8; - segdata = segdata >> 1; - } - if (character == 'T' && position == 1) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(1, 12)); // add descender - else if (position == 0 && (character == 'B' || character == 'D')) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(0, 15)); // add funky ninth segment - else if (position == 1 && (character == 'B' || character == 'D' || character == '@')) slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(0, 12)); // add funky ninth segment -} - -void watch_display_string(char *string, uint8_t position) { - size_t i = 0; - while(string[i] != 0) { - watch_display_character(string[i], position + i); - i++; - if (position + i >= Num_Chars) break; - } - // uncomment this line to see screen output on terminal, i.e. - // FR 29 - // 11 50 23 - // note that for partial displays (positon > 0) it will only show the characters that were updated. - // printf("________\n %c%c %c%c\n%c%c %c%c %c%c\n--------\n", (position > 0) ? ' ' : string[0], (position > 1) ? ' ' : string[1 - position], (position > 2) ? ' ' : string[2 - position], (position > 3) ? ' ' : string[3 - position], (position > 4) ? ' ' : string[4 - position], (position > 5) ? ' ' : string[5 - position], (position > 6) ? ' ' : string[6 - position], (position > 7) ? ' ' : string[7 - position], (position > 8) ? ' ' : string[8 - position], (position > 9) ? ' ' : string[9 - position]); -} - -inline void watch_set_colon(void) { - slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(1, 16)); -} - -inline void watch_clear_colon(void) { - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(1, 16)); -} - -inline void watch_set_indicator(WatchIndicatorSegment indicator) { - slcd_sync_seg_on(&SEGMENT_LCD_0, IndicatorSegments[indicator]); -} - -inline void watch_clear_indicator(WatchIndicatorSegment indicator) { - slcd_sync_seg_off(&SEGMENT_LCD_0, IndicatorSegments[indicator]); -} - -void watch_clear_all_indicators(void) { - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(2, 17)); - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(2, 16)); - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(0, 17)); - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(0, 16)); - slcd_sync_seg_off(&SEGMENT_LCD_0, SLCD_SEGID(1, 10)); -} - -void watch_start_character_blink(char character, uint32_t duration) { - SLCD->CTRLD.bit.FC0EN = 0; - _sync_slcd(); - - if (duration <= SLCD_FC_BYPASS_MAX_MS) { - SLCD->FC0.reg = SLCD_FC0_PB | ((duration / (1000 / SLCD_FRAME_FREQUENCY)) - 1); - } else { - SLCD->FC0.reg = (((duration / (1000 / SLCD_FRAME_FREQUENCY)) / 8 - 1)); - } - SLCD->CTRLD.bit.FC0EN = 1; - - watch_display_character(character, 7); - watch_clear_pixel(2, 10); // clear segment B of position 7 since it can't blink - - SLCD->CTRLD.bit.BLINK = 0; - SLCD->CTRLA.bit.ENABLE = 0; - _sync_slcd(); - - SLCD->BCFG.bit.BSS0 = 0x07; - SLCD->BCFG.bit.BSS1 = 0x07; - - SLCD->CTRLD.bit.BLINK = 1; - _sync_slcd(); - SLCD->CTRLA.bit.ENABLE = 1; - _sync_slcd(); -} - -void watch_stop_blink(void) { - SLCD->CTRLD.bit.FC0EN = 0; - SLCD->CTRLD.bit.BLINK = 0; -} - -void watch_start_tick_animation(uint32_t duration) { - watch_display_character(' ', 8); - const uint32_t segs[] = { SLCD_SEGID(0, 2)}; - slcd_sync_start_animation(&SEGMENT_LCD_0, segs, 1, duration); -} - -bool watch_tick_animation_is_running(void) { - return hri_slcd_get_CTRLD_CSREN_bit(SLCD); -} - -void watch_stop_tick_animation(void) { - const uint32_t segs[] = { SLCD_SEGID(0, 2)}; - slcd_sync_stop_animation(&SEGMENT_LCD_0, segs, 1); - watch_display_character(' ', 8); -}