add gamma correction

This commit is contained in:
King Kévin 2016-03-28 16:39:11 +02:00
parent 3ea5f327b8
commit 3914df5590
1 changed files with 10 additions and 1 deletions

11
main.c
View File

@ -28,6 +28,7 @@
#include <unistd.h> // standard streams
#include <errno.h> // error number utilities
#include <string.h> // string utilities
#include <math.h> // mathematical utilities
/* STM32 (including CM3) libraries */
#include <libopencm3/stm32/rcc.h> // real-time control clock library
@ -92,6 +93,8 @@ volatile uint32_t current_time = 0;
char command[32] = {0};
/** user input command index */
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)
{
@ -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+1] = clock_leds[i*3+1]; // 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
#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
ws2812b_setup(); // setup WS2812b LEDs
clock_hours(); // show hour markers
@ -494,6 +502,7 @@ void BUTTON_ISR(void)
#endif
#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)
{
if (timer_get_flag(SQUARE_WAVE_TIMER, TIM_SR_UIF)) { // overflow even happened