add gamma correction
This commit is contained in:
parent
3ea5f327b8
commit
3914df5590
11
main.c
11
main.c
|
@ -28,6 +28,7 @@
|
||||||
#include <unistd.h> // standard streams
|
#include <unistd.h> // standard streams
|
||||||
#include <errno.h> // error number utilities
|
#include <errno.h> // error number utilities
|
||||||
#include <string.h> // string utilities
|
#include <string.h> // string utilities
|
||||||
|
#include <math.h> // mathematical utilities
|
||||||
|
|
||||||
/* STM32 (including CM3) libraries */
|
/* STM32 (including CM3) libraries */
|
||||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||||
|
@ -92,6 +93,8 @@ volatile uint32_t current_time = 0;
|
||||||
char command[32] = {0};
|
char command[32] = {0};
|
||||||
/** user input command index */
|
/** user input command index */
|
||||||
uint8_t command_i = 0;
|
uint8_t command_i = 0;
|
||||||
|
/** gamma correction lookup table (common for all colors) */
|
||||||
|
uint8_t gamma_correction_lut[256] = {0};
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len)
|
int _write(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
|
@ -248,7 +251,7 @@ static void clock_leds_set(void)
|
||||||
clock_leds_old[i*3+0] = clock_leds[i*3+0]; // memorise change
|
clock_leds_old[i*3+0] = clock_leds[i*3+0]; // memorise change
|
||||||
clock_leds_old[i*3+1] = clock_leds[i*3+1]; // memorise change
|
clock_leds_old[i*3+1] = clock_leds[i*3+1]; // memorise change
|
||||||
clock_leds_old[i*3+2] = clock_leds[i*3+2]; // memorise change
|
clock_leds_old[i*3+2] = clock_leds[i*3+2]; // memorise change
|
||||||
ws2812b_set_rgb(i,clock_leds[i*3+0],clock_leds[i*3+1],clock_leds[i*3+2]); // set new value (this costs time)
|
ws2812b_set_rgb(i,gamma_correction_lut[clock_leds[i*3+0]],gamma_correction_lut[clock_leds[i*3+1]],gamma_correction_lut[clock_leds[i*3+2]]); // set new value (this costs time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,6 +381,11 @@ int main(void)
|
||||||
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
|
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// generate gamma correction table (with fixed gamma value)
|
||||||
|
for (uint16_t i=0; i<LENGTH(gamma_correction_lut); i++) {
|
||||||
|
gamma_correction_lut[i] = powf((float)i / (float)LENGTH(gamma_correction_lut), 2.5)*LENGTH(gamma_correction_lut);
|
||||||
|
}
|
||||||
|
|
||||||
// setup WS2812b LEDs
|
// setup WS2812b LEDs
|
||||||
ws2812b_setup(); // setup WS2812b LEDs
|
ws2812b_setup(); // setup WS2812b LEDs
|
||||||
clock_hours(); // show hour markers
|
clock_hours(); // show hour markers
|
||||||
|
@ -494,6 +502,7 @@ void BUTTON_ISR(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SQUARE_WAVE_TIMER_IRQ) && defined(SQUARE_WAVE_TIMER_ISR)
|
#if defined(SQUARE_WAVE_TIMER_IRQ) && defined(SQUARE_WAVE_TIMER_ISR)
|
||||||
|
/** @brief timer interrupt when square wave output accumulated to a tick */
|
||||||
void SQUARE_WAVE_TIMER_ISR(void)
|
void SQUARE_WAVE_TIMER_ISR(void)
|
||||||
{
|
{
|
||||||
if (timer_get_flag(SQUARE_WAVE_TIMER, TIM_SR_UIF)) { // overflow even happened
|
if (timer_get_flag(SQUARE_WAVE_TIMER, TIM_SR_UIF)) { // overflow even happened
|
||||||
|
|
Loading…
Reference in New Issue