simplify: always use the TCC to drive the LEDs

This commit is contained in:
Joey Castillo 2021-08-31 19:38:06 -04:00
parent b22915431b
commit 637964ae4b
2 changed files with 37 additions and 53 deletions

View File

@ -22,26 +22,24 @@
* SOFTWARE. * SOFTWARE.
*/ */
void watch_enable_leds() {
void watch_enable_led(bool pwm) { if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
if (pwm) { _watch_enable_tcc();
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_disable_led(bool pwm) { void watch_disable_leds() {
if (pwm) { _watch_disable_tcc();
_watch_disable_tcc(); }
} else {
watch_disable_digital_output(RED); void watch_enable_led(bool unused) {
watch_disable_digital_output(GREEN); (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) { 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() { void watch_set_led_red() {
if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { watch_set_led_color(255, 0);
watch_set_led_color(255, 0);
} else {
watch_set_pin_level(RED, true);
watch_set_pin_level(GREEN, false);
}
} }
void watch_set_led_green() { void watch_set_led_green() {
if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { watch_set_led_color(0, 255);
watch_set_led_color(0, 255);
} else {
watch_set_pin_level(RED, false);
watch_set_pin_level(GREEN, true);
}
} }
void watch_set_led_yellow() { void watch_set_led_yellow() {
if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { watch_set_led_color(255, 255);
watch_set_led_color(255, 255);
} else {
watch_set_pin_level(RED, true);
watch_set_pin_level(GREEN, true);
}
} }
void watch_set_led_off() { void watch_set_led_off() {
if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) { watch_set_led_color(0, 0);
watch_set_led_color(0, 0);
} else {
watch_set_pin_level(RED, false);
watch_set_pin_level(GREEN, false);
}
} }

View File

@ -29,28 +29,28 @@
* hungry. The green LED, at full power, consumes more power than the whole chip in active mode, * 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 * 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. * 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. /** @brief Enables the bi-color LED.
* @param pwm if true, enables PWM output for brightness control (required to use @ref watch_set_led_color). * @note The TCC peripheral that drives the LEDs does not run in STANDBY mode but the outputs do! This
If false, configures the LED pins as digital outputs. * means that if you set either red, green or both LEDs to full power, they will shine even when
* @note The TC driver required for PWM mode does not run in STANDBY mode. You should keep your app awake * your app is asleep. If, however, you set a custom color using watch_set_led_color, the color will
while PWM'ing the LED's, and disable them before going to sleep. * 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. /** @brief Disables the LEDs.
* @param pwm if true, disables the PWM output. If false, disables the digital outputs. * @note This method will also disable the buzzer, since the buzzer and LED both make use of the same
* @note If pwm is true, this method will also disable the buzzer, since the buzzer and LED both make use of * peripheral to drive their PWM behavior.
* 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. /** @brief Sets the LED to a custom color by modulating each output's duty cycle.
* @param red The red value from 0-255. * @param red The red value from 0-255.
* @param green The green 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); 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. */ /** @brief Turns both the red and the green LEDs off. */
void watch_set_led_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);
/// @} /// @}