]> git.earman.xyz Git - sensor-watch.git/commitdiff
handle watch variant with red/blue LED
authorJoey Castillo <jose.castillo@gmail.com>
Wed, 1 Sep 2021 00:28:36 +0000 (20:28 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Wed, 1 Sep 2021 00:29:13 +0000 (20:29 -0400)
make.mk
watch-library/hw/atmel_start_pins.h
watch-library/watch/watch_led.c
watch-library/watch/watch_led.h

diff --git a/make.mk b/make.mk
index 38dcdf5714aaeffdec8fc74662c2207dcec50707..21ccc0f53810b7b4eb21f4ece38b03c4ebe4159f 100644 (file)
--- 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
index 14df95e1d84e9fc4a053edea103a0ff2da839965..4920e67eb778ce00af428367208d2a996d94f4bc 100644 (file)
 #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)
index 42bed56a16f7dc19798ea6ddae04f5e396501188..f6419737062280cb7bb7a64a05c9dd73aeb558b6 100644 (file)
  * 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));
     }
 }
 
index d711a0525a413911ad706593aa098c86744d8f5e..0927e716afaac378828b7106410e8f131911c11b 100644 (file)
   *          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();