From 71e411d8609b940ebd42b6aeaaad7d1ce106a424 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 31 Aug 2021 20:28:36 -0400 Subject: [PATCH] handle watch variant with red/blue LED --- make.mk | 4 ++++ watch-library/hw/atmel_start_pins.h | 11 ++++++++--- watch-library/watch/watch_led.c | 12 ++++++++++-- watch-library/watch/watch_led.h | 17 ++++++++++++----- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/make.mk b/make.mk index 38dcdf5..21ccc0f 100644 --- a/make.mk +++ b/make.mk @@ -111,3 +111,7 @@ SRCS += \ DEFINES += \ -D__SAML22J18A__ \ -DDONT_USE_CMSIS_INIT + +ifeq ($(LED), BLUE) +CFLAGS += -DWATCH_SWAP_LED_PINS +endif diff --git a/watch-library/hw/atmel_start_pins.h b/watch-library/hw/atmel_start_pins.h index 14df95e..4920e67 100644 --- a/watch-library/hw/atmel_start_pins.h +++ b/watch-library/hw/atmel_start_pins.h @@ -39,8 +39,14 @@ #define SEG19 GPIO(GPIO_PORTA, 17) #define SEG20 GPIO(GPIO_PORTA, 18) #define SEG21 GPIO(GPIO_PORTA, 19) -#define RED GPIO(GPIO_PORTA, 20) -#define GREEN GPIO(GPIO_PORTA, 21) +#ifdef WATCH_SWAP_LED_PINS + #define RED GPIO(GPIO_PORTA, 21) + #define GREEN GPIO(GPIO_PORTA, 20) +#else + #define RED GPIO(GPIO_PORTA, 20) + #define GREEN GPIO(GPIO_PORTA, 21) +#endif +#define BTN_ALARM GPIO(GPIO_PORTA, 2) #define BTN_LIGHT GPIO(GPIO_PORTA, 22) #define BTN_MODE GPIO(GPIO_PORTA, 23) #define BUZZER GPIO(GPIO_PORTA, 27) @@ -51,7 +57,6 @@ #define A4 GPIO(GPIO_PORTB, 0) #define D0 GPIO(GPIO_PORTB, 3) #define D1 GPIO(GPIO_PORTB, 0) -#define BTN_ALARM GPIO(GPIO_PORTA, 2) #define COM0 GPIO(GPIO_PORTB, 6) #define COM1 GPIO(GPIO_PORTB, 7) #define COM2 GPIO(GPIO_PORTB, 8) diff --git a/watch-library/watch/watch_led.c b/watch-library/watch/watch_led.c index 42bed56..f641973 100644 --- a/watch-library/watch/watch_led.c +++ b/watch-library/watch/watch_led.c @@ -22,6 +22,14 @@ * SOFTWARE. */ +#ifdef WATCH_SWAP_LED_PINS + #define WATCH_RED_CHANNEL 3 + #define WATCH_GREEN_CHANNEL 2 +#else + #define WATCH_RED_CHANNEL 2 + #define WATCH_GREEN_CHANNEL 3 +#endif + void watch_enable_leds() { if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { _watch_enable_tcc(); @@ -45,8 +53,8 @@ void watch_disable_led(bool unused) { void watch_set_led_color(uint8_t red, uint8_t green) { if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { uint32_t period = hri_tcc_get_PER_reg(TCC0, TCC_PER_MASK); - hri_tcc_write_CCBUF_reg(TCC0, 2, ((period * red * 1000ull) / 255000ull)); - hri_tcc_write_CCBUF_reg(TCC0, 3, ((period * green * 1000ull) / 255000ull)); + hri_tcc_write_CCBUF_reg(TCC0, WATCH_RED_CHANNEL, ((period * red * 1000ull) / 255000ull)); + hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_CHANNEL, ((period * green * 1000ull) / 255000ull)); } } diff --git a/watch-library/watch/watch_led.h b/watch-library/watch/watch_led.h index d711a05..0927e71 100644 --- a/watch-library/watch/watch_led.h +++ b/watch-library/watch/watch_led.h @@ -29,6 +29,11 @@ * hungry. The green LED, at full power, consumes more power than the whole chip in active mode, * and the red LED consumes about twelve times as much power! The LED's should thus be used only * sparingly in order to preserve battery life. + * @note Some watches use a red/blue LED instead of a red/green LED. You will be able to determine this + * easily when you double tap the reset button: if the pulsing bootloader LED is red, you have a + * red/green edition; if it is blue, you have a red/blue edition. For red/blue watches, build your + * project with the command `make LED=BLUE`, and the watch library will automatically swap the pins + * so that watch_set_led_red sets the red LED, and watch_set_led_green sets the blue one. */ /// @{ /** @brief Enables the bi-color LED. @@ -47,7 +52,7 @@ void watch_disable_leds(); /** @brief Sets the LED to a custom color by modulating each output's duty cycle. * @param red The red value from 0-255. - * @param green The green value from 0-255. + * @param green The green value from 0-255. If your watch has a red/blue LED, this will be the blue value. * @note If you are displaying a custom color, you will need to prevent your app from going to sleep * while the LED is on; otherwise, the color will not display correctly. You can do this by * returning false in your app_loop method. @@ -55,18 +60,20 @@ void watch_disable_leds(); void watch_set_led_color(uint8_t red, uint8_t green); /** @brief Sets the red LED to full brightness, and turns the green LED off. - * @note Of the two LED's in the RG bi-color LED, the red LED is the less power-efficient one (~4.5 mA). + * @details Of the two LED's in the RG bi-color LED, the red LED is the less power-efficient one (~4.5 mA). */ void watch_set_led_red(); /** @brief Sets the green LED to full brightness, and turns the red LED off. - * @note Of the two LED's in the RG bi-color LED, the green LED is the more power-efficient one (~0.44 mA). + * @details Of the two LED's in the RG bi-color LED, the green LED is the more power-efficient one (~0.44 mA). + * @note If your watch has a red/blue LED, this method will set the LED to blue. */ void watch_set_led_green(); /** @brief Sets both red and green LEDs to full brightness. - * @note The total current draw between the two LED's in this mode will be ~5 mA, which is more than the - * watch draws in any other mode. Take care not to drain the battery. + * @details The total current draw between the two LED's in this mode will be ~5 mA, which is more than the + * watch draws in any other mode. Take care not to drain the battery. + * @note If your watch has a red/blue LED, this method will set the LED to pink. */ void watch_set_led_yellow();