adaptions for HW V2.1

added PWM output for new discrete white LEDs
added 2 new SK6812 LEDs
added a default start mode
This commit is contained in:
Mario Hüttel 2021-05-09 14:30:39 +02:00
parent b9a01bcad9
commit d9769e7b34

View File

@ -3,18 +3,19 @@
#include <stdbool.h>
#include <ring-light/temp-adc.h>
#define RING_MAX_LED 30u
#define RING_MAX_LED 32u
enum ring_modes {
RING_MODE_ALL,
RING_MODE_RED,
RING_MODE_GREEN,
RING_MODE_BLUE,
RING_MODE_WHITE,
RING_MODE_ARC,
RING_MODE_QUARTER,
RING_MODE_IN_FARBE_UND_BUNT,
RING_MODE_MAX
RING_MODE_ALL, /*!< control all LEDs at once */
RING_MODE_RED, /*!< only red SK6812 */
RING_MODE_GREEN, /*!< only green SK6812 */
RING_MODE_BLUE, /*!< only blue SK6812 */
RING_MODE_WHITE, /*!< only white SK6812 */
RING_MODE_WHITE_DISCRETE, /*!< only discrete white LEDs */
RING_MODE_ARC, /*!< SK6812 closing ring */
RING_MODE_QUARTER, /*!< SK6812 walking quarter */
RING_MODE_IN_FARBE_UND_BUNT, /*!< SK6812 color mix */
RING_MODE_MAX /*!< end of list */
};
volatile int32_t temperature;
@ -33,12 +34,13 @@ int main(void)
{
uint32_t led_val = 0x00UL;
uint32_t led_calc_val[RING_MAX_LED] = {0x00UL};
uint8_t led_pwm_val = 0u;
bool button_pressed = false;
enum ring_modes mode = RING_MODE_ALL;
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN | RCC_APB1ENR_TIM14EN;
GPIOA->MODER |= (2<<7*2)|(2<<6*2)|(1<<3*2);
@ -47,6 +49,11 @@ int main(void)
/* enable TIM3 on encoder inputs */
GPIOA->AFR[0] |= (1<<7*4)|(1<<6*4);
/* enable PWM output for magic LED regulator */
GPIOB->MODER |= (2<<1*2);
GPIOB->AFR[0] &= ~(0<<1*4);
/*! -# init the TIM3 to read the encoder */
TIM3->ARR = 0xFFFF;
TIM3->CNT = 0;
TIM3->CR2 = 0;
@ -56,17 +63,38 @@ int main(void)
TIM3->PSC = 0;
TIM3->CR1 = TIM_CR1_CEN;
/*! -# init TIM14 for PWM control of the magic LED driver */
/*! -# count up to 255 (0 bit resolution) */
TIM14->ARR = 0x00FFu;
TIM14->CNT = 0u;
TIM14->CCR1 = 0u;
/*! -# set prescaler to 16 ==> ca. 11 KHz */
TIM14->PSC = 15u;
/*! -# PWM Mode 1 + prefetch */
TIM14->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE;
/*! -# enable Output compare 1 */
TIM14->CCER = TIM_CCER_CC1E;
/*! -# finally enable TIM14 */
TIM14->CR2 = 0;
TIM14->CR1 = TIM_CR1_CEN;
/*! -# set initial state to all 25% */
led_val = 64u;
mode = RING_MODE_ALL;
temperature_adc_init();
SysTick_Config(800000);
while(1) {
temperature = temperature_adc_get_temp();
led_pwm_val = 0u;
switch (mode)
{
case RING_MODE_ALL:
for(int i = 0; i < RING_MAX_LED; i ++) {
led_calc_val[i] = (led_val << 24) + (led_val << 16) + (led_val << 8) + led_val;
}
led_pwm_val = led_val;
break;
case RING_MODE_RED:
for(int i = 0; i < RING_MAX_LED; i ++) {
@ -88,6 +116,12 @@ int main(void)
led_calc_val[i] = led_val;
}
break;
case RING_MODE_WHITE_DISCRETE:
for(int i = 0; i < RING_MAX_LED; i ++) {
led_calc_val[i] = 0u;
}
led_pwm_val = led_val;
break;
case RING_MODE_ARC:
for(int i = 0; i < RING_MAX_LED; i ++) {
if(led_val > i*8) {
@ -133,6 +167,8 @@ int main(void)
}
break;
}
TIM14->CCR1 = led_pwm_val;
__disable_irq();
for(int i = 0; i < RING_MAX_LED; i ++) {
sk6812_send_led(led_calc_val[i]);