]> git.earman.xyz Git - sensor-watch.git/commitdiff
simplify: always use the TCC to drive the LEDs
authorJoey Castillo <jose.castillo@gmail.com>
Tue, 31 Aug 2021 23:38:06 +0000 (19:38 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Tue, 31 Aug 2021 23:38:06 +0000 (19:38 -0400)
watch-library/watch/watch_led.c
watch-library/watch/watch_led.h

index 4f9898d884b13a828590a18aace41c94cc5bba69..42bed56a16f7dc19798ea6ddae04f5e396501188 100644 (file)
  * SOFTWARE.
  */
 
-
-void watch_enable_led(bool pwm) {
-    if (pwm) {
-        if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
-            _watch_enable_tcc();
-        }
-    } else {
-        watch_enable_digital_output(RED);
-        watch_enable_digital_output(GREEN);
-        watch_set_led_off();
+void watch_enable_leds() {
+    if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
+        _watch_enable_tcc();
     }
 }
 
-void watch_disable_led(bool pwm) {
-    if (pwm) {
-        _watch_disable_tcc();
-    } else {
-        watch_disable_digital_output(RED);
-        watch_disable_digital_output(GREEN);
-    }
+void watch_disable_leds() {
+    _watch_disable_tcc();
+}
+
+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) {
@@ -53,37 +51,17 @@ void watch_set_led_color(uint8_t red, uint8_t green) {
 }
 
 void watch_set_led_red() {
-    if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
-        watch_set_led_color(255, 0);
-    } else {
-        watch_set_pin_level(RED, true);
-        watch_set_pin_level(GREEN, false);
-    }
+    watch_set_led_color(255, 0);
 }
 
 void watch_set_led_green() {
-    if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
-        watch_set_led_color(0, 255);
-    } else {
-        watch_set_pin_level(RED, false);
-        watch_set_pin_level(GREEN, true);
-    }
+    watch_set_led_color(0, 255);
 }
 
 void watch_set_led_yellow() {
-    if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
-        watch_set_led_color(255, 255);
-    } else {
-        watch_set_pin_level(RED, true);
-        watch_set_pin_level(GREEN, true);
-    }
+    watch_set_led_color(255, 255);
 }
 
 void watch_set_led_off() {
-    if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
-        watch_set_led_color(0, 0);
-    } else {
-        watch_set_pin_level(RED, false);
-        watch_set_pin_level(GREEN, false);
-    }
+    watch_set_led_color(0, 0);
 }
index 5dedadf3479565b7ea16fac7da18cec92e8893fc..d711a0525a413911ad706593aa098c86744d8f5e 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.
-  * @todo Explore running the TC3 PWM driver in standby mode; this would require that the user disable it
-  *       in app_prepare_for_sleep, but could allow for low power, low duty indicator LED usage.
   */
 /// @{
-/** @brief Enables the LED.
-  * @param pwm if true, enables PWM output for brightness control (required to use @ref watch_set_led_color).
-               If false, configures the LED pins as digital outputs.
-  * @note The TC driver required for PWM mode does not run in STANDBY mode. You should keep your app awake
-          while PWM'ing the LED's, and disable them before going to sleep.
+/** @brief Enables the bi-color LED.
+  * @note The TCC peripheral that drives the LEDs does not run in STANDBY mode — but the outputs do! This
+  *       means that if you set either red, green or both LEDs to full power, they will shine even when
+  *       your app is asleep. If, however, you set a custom color using watch_set_led_color, the color will
+  *       not display correctly in STANDBY mode. You will need to keep your app running while the LED is on.
   */
-void watch_enable_led(bool pwm);
+void watch_enable_leds();
 
 /** @brief Disables the LEDs.
-  * @param pwm if true, disables the PWM output. If false, disables the digital outputs.
-  * @note If pwm is true, this method will also disable the buzzer, since the buzzer and LED both make use of
-  *       the same peripheral to drive their PWM behavior.
+  * @note This method will also disable the buzzer, since the buzzer and LED both make use of the same
+  *       peripheral to drive their PWM behavior.
   */
-void watch_disable_led(bool pwm);
+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.
+  * @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.
   */
 void watch_set_led_color(uint8_t red, uint8_t green);
 
@@ -72,4 +72,10 @@ void watch_set_led_yellow();
 
 /** @brief Turns both the red and the green LEDs off. */
 void watch_set_led_off();
+
+__attribute__((deprecated("Use watch_enable_leds instead")))
+void watch_enable_led(bool unused);
+
+__attribute__((deprecated("Use watch_disable_leds instead")))
+void watch_disable_led(bool unused);
 /// @}