work on pro LED, add rainbow test

This commit is contained in:
joeycastillo 2023-02-03 15:45:39 -06:00
parent 60e431d3d7
commit 4fcf33d175
6 changed files with 120 additions and 3 deletions

View File

@ -0,0 +1,64 @@
#include <stdio.h>
#include <string.h>
#include "watch.h"
void app_init(void) {
}
void app_wake_from_backup(void) {
}
void app_setup(void) {
watch_enable_leds();
}
void app_prepare_for_standby(void) {
}
void app_wake_from_standby(void) {
}
bool app_loop(void) {
static uint8_t red = 0;
static uint8_t green = 0;
static uint8_t blue = 255;
static uint8_t phase = 0;
switch (phase) {
case 0:
red++;
if (red == 255) phase = 1;
break;
case 1:
green++;
if (green == 255) phase = 2;
break;
case 2:
red--;
if (red == 0) phase = 3;
break;
case 3:
blue++;
if (blue == 255) phase = 4;
break;
case 4:
green--;
if (green == 0) phase = 5;
break;
case 5:
red++;
if (red == 255) phase = 6;
break;
case 6:
blue--;
if (blue == 0) {
phase = 1;
}
break;
}
watch_set_led_color_rgb(red, green, blue);
delay_ms(2);
return false;
}

View File

@ -0,0 +1,10 @@
TOP = ../../..
include $(TOP)/make.mk
INCLUDES += \
-I../
SRCS += \
../app.c
include $(TOP)/rules.mk

View File

@ -35,10 +35,24 @@ void watch_disable_leds(void) {
}
void watch_set_led_color(uint8_t red, uint8_t green) {
#ifdef WATCH_BLUE_TCC_CHANNEL
watch_set_led_color_rgb(red, green, 0);
#else
watch_set_led_color_rgb(red, green, green);
#endif
}
void watch_set_led_color_rgb(uint8_t red, uint8_t green, uint8_t blue) {
#ifndef WATCH_BLUE_TCC_CHANNEL
(void) blue; // silence warning
#endif
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, WATCH_RED_TCC_CHANNEL, ((period * red * 1000ull) / 255000ull));
hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, ((period * green * 1000ull) / 255000ull));
#ifdef WATCH_BLUE_TCC_CHANNEL
hri_tcc_write_CCBUF_reg(TCC0, WATCH_BLUE_TCC_CHANNEL, ((period * blue * 1000ull) / 255000ull));
#endif
}
}

View File

@ -140,11 +140,14 @@ void _watch_enable_tcc(void) {
// period (i.e. a square wave with a 50% duty cycle).
// * LEDs on CC[2] and CC[3] can be set to any value from 0 (off) to PER (fully on).
hri_tcc_write_WAVE_reg(TCC0, TCC_WAVE_WAVEGEN_NPWM);
#ifdef WATCH_INVERT_LED_POLARITY
// This is here for the dev board, which uses a common anode LED (instead of common cathode like the actual watch).
#ifdef WATCH_INVERT_LED_POLARITY
// This is here for the dev board and Pro, which use a common anode LED (instead of common cathode like the actual watch).
hri_tcc_set_WAVE_reg(TCC0, (1 << (TCC_WAVE_POL0_Pos + WATCH_RED_TCC_CHANNEL)) |
#ifdef WATCH_BLUE_TCC_CHANNEL
(1 << (TCC_WAVE_POL0_Pos + WATCH_BLUE_TCC_CHANNEL)) |
#endif // WATCH_BLUE_TCC_CHANNEL
(1 << (TCC_WAVE_POL0_Pos + WATCH_GREEN_TCC_CHANNEL)));
#endif
#endif // WATCH_INVERT_LED_POLARITY
// The buzzer will set the period depending on the tone it wants to play, but we have to set some period here to
// get the LED working. Almost any period will do, tho it should be below 20000 (i.e. 50 Hz) to avoid flickering.
hri_tcc_write_PER_reg(TCC0, 1024);
@ -152,6 +155,9 @@ void _watch_enable_tcc(void) {
hri_tcc_write_CC_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, 0);
hri_tcc_write_CC_reg(TCC0, WATCH_RED_TCC_CHANNEL, 0);
hri_tcc_write_CC_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, 0);
#ifdef WATCH_BLUE_TCC_CHANNEL
hri_tcc_write_CC_reg(TCC0, WATCH_BLUE_TCC_CHANNEL, 0);
#endif
// Enable the TCC
hri_tcc_set_CTRLA_ENABLE_bit(TCC0);
hri_tcc_wait_for_sync(TCC0, TCC_SYNCBUSY_ENABLE);
@ -161,6 +167,10 @@ void _watch_enable_tcc(void) {
gpio_set_pin_function(RED, WATCH_RED_TCC_PINMUX);
gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OUT);
gpio_set_pin_function(GREEN, WATCH_GREEN_TCC_PINMUX);
#ifdef WATCH_BLUE_TCC_CHANNEL
gpio_set_pin_direction(BLUE, GPIO_DIRECTION_OUT);
gpio_set_pin_function(BLUE, WATCH_BLUE_TCC_PINMUX);
#endif
}
void _watch_disable_tcc(void) {
@ -171,6 +181,10 @@ void _watch_disable_tcc(void) {
gpio_set_pin_function(RED, GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OFF);
gpio_set_pin_function(GREEN, GPIO_PIN_FUNCTION_OFF);
#ifdef WATCH_BLUE_TCC_CHANNEL
gpio_set_pin_direction(BLUE, GPIO_DIRECTION_OFF);
gpio_set_pin_function(BLUE, GPIO_PIN_FUNCTION_OFF);
#endif
// disable the TCC
hri_tcc_clear_CTRLA_ENABLE_bit(TCC0);

View File

@ -63,6 +63,16 @@ void watch_disable_leds(void);
*/
void watch_set_led_color(uint8_t red, uint8_t green);
/** @brief On boards with an RGB LED, 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 blue The blue 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_rgb(uint8_t red, uint8_t green, uint8_t blue);
/** @brief Sets the red LED to full brightness, and turns the green LED off.
* @details Of the two LED's in the RG bi-color LED, the red LED is the less power-efficient one (~4.5 mA).
*/

View File

@ -44,6 +44,11 @@ void watch_set_led_color(uint8_t red, uint8_t green) {
}, red, green);
}
void watch_set_led_color_rgb(uint8_t red, uint8_t green, uint8_t blue) {
(void) blue;
watch_set_led_color(red, green);
}
void watch_set_led_red(void) {
watch_set_led_color(255, 0);
}