From: Sebastien Bourdeauducq Date: Mon, 13 May 2013 13:45:28 +0000 (+0200) Subject: software/videomixer: connect crossfade and blackout pots X-Git-Tag: 24jan2021_ls180~2927 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f81afb844c5d7607ed941ac9f686561e97193e5;p=litex.git software/videomixer: connect crossfade and blackout pots --- diff --git a/software/videomixer/Makefile b/software/videomixer/Makefile index 6bc3493e..41b1fcfa 100644 --- a/software/videomixer/Makefile +++ b/software/videomixer/Makefile @@ -1,7 +1,7 @@ M2DIR=../.. include $(M2DIR)/software/common.mak -OBJECTS=crt0.o isr.o dvisampler0.o dvisampler1.o main.o +OBJECTS=crt0.o isr.o time.o dvisampler0.o dvisampler1.o main.o all: videomixer.bin diff --git a/software/videomixer/dvisamplerX.c b/software/videomixer/dvisamplerX.c index df046fa7..d1cec368 100644 --- a/software/videomixer/dvisamplerX.c +++ b/software/videomixer/dvisamplerX.c @@ -6,6 +6,7 @@ #include #include +#include "time.h" #include "dvisamplerX.h" #define FRAMEBUFFER_COUNT 4 @@ -152,22 +153,7 @@ int dvisamplerX_init_phase(void) } static int dvisamplerX_locked; - -static int elapsed(int period) -{ - static int last_event; - int t, dt; - - t = timer0_reload_read() - timer0_value_read(); // TODO: atomic read - dt = t - last_event; - if(dt < 0) - dt += timer0_reload_read(); - if((dt > period) || (dt < 0)) { - last_event = t; - return 1; - } else - return 0; -} +static int dvisamplerX_last_event; void dvisamplerX_service(void) { @@ -175,7 +161,7 @@ void dvisamplerX_service(void) if(dvisamplerX_locked) { if(dvisamplerX_clocking_locked_read()) { - if(elapsed(identifier_frequency_read())) { + if(elapsed(&dvisamplerX_last_event, identifier_frequency_read())) { dvisamplerX_adjust_phase(); dvisamplerX_print_status(); } @@ -196,9 +182,9 @@ void dvisamplerX_service(void) dvisamplerX_print_status(); dvisamplerX_locked = 1; } else { - if(elapsed(identifier_frequency_read()/4)) { + if(elapsed(&dvisamplerX_last_event, identifier_frequency_read()/4)) { dvisamplerX_clocking_pll_reset_write(1); - while(!elapsed(identifier_frequency_read()/16)); + while(!elapsed(&dvisamplerX_last_event, identifier_frequency_read()/16)); dvisamplerX_clocking_pll_reset_write(0); } } diff --git a/software/videomixer/main.c b/software/videomixer/main.c index de3c9791..83af200f 100644 --- a/software/videomixer/main.c +++ b/software/videomixer/main.c @@ -7,40 +7,75 @@ #include #include +#include "time.h" #include "dvisampler0.h" #include "dvisampler1.h" -int main(void) +static int scale_pot(int raw, int range) +{ + int pot_min = 54000; + int pot_max = 105400; + int scaled; + + scaled = range*(raw - pot_min)/(pot_max - pot_min); + if(scaled < 0) + scaled = 0; + if(scaled > range) + scaled = range; + return scaled; +} + +static void pots_service(void) +{ + static int last_event; + int blackout; + int crossfade; + + if(elapsed(&last_event, identifier_frequency_read()/32)) { + pots_start_busy_write(1); + while(pots_start_busy_read()); + blackout = scale_pot(pots_res0_read(), 256); + crossfade = scale_pot(pots_res1_read(), 255); + + fb_blender_f0_write(crossfade*blackout >> 8); + fb_blender_f1_write((255-crossfade)*blackout >> 8); + } +} + +static void fb_service(void) { int c; + if(readchar_nonblock()) { + c = readchar(); + if(c == '1') { + fb_enable_write(1); + printf("Framebuffer is ON\n"); + } else if(c == '0') { + fb_enable_write(0); + printf("Framebuffer is OFF\n"); + } + } +} + +int main(void) +{ irq_setmask(0); irq_setie(1); uart_init(); puts("Minimal video mixer software built "__DATE__" "__TIME__"\n"); - timer0_reload_write(2*identifier_frequency_read()); - timer0_en_write(1); - + time_init(); dvisampler0_init_video(); dvisampler1_init_video(); fb_enable_write(1); - fb_blender_f0_write(127); - fb_blender_f1_write(127); + while(1) { dvisampler0_service(); dvisampler1_service(); - if(readchar_nonblock()) { - c = readchar(); - if(c == '1') { - fb_enable_write(1); - printf("Framebuffer is ON\n"); - } else if(c == '0') { - fb_enable_write(0); - printf("Framebuffer is OFF\n"); - } - } + pots_service(); + fb_service(); } return 0; diff --git a/software/videomixer/time.c b/software/videomixer/time.c new file mode 100644 index 00000000..4f53219c --- /dev/null +++ b/software/videomixer/time.c @@ -0,0 +1,24 @@ +#include + +#include "time.h" + +void time_init(void) +{ + timer0_reload_write(2*identifier_frequency_read()); + timer0_en_write(1); +} + +int elapsed(int *last_event, int period) +{ + int t, dt; + + t = timer0_reload_read() - timer0_value_read(); // TODO: atomic read + dt = t - *last_event; + if(dt < 0) + dt += timer0_reload_read(); + if((dt > period) || (dt < 0)) { + *last_event = t; + return 1; + } else + return 0; +} diff --git a/software/videomixer/time.h b/software/videomixer/time.h new file mode 100644 index 00000000..a8ebe23f --- /dev/null +++ b/software/videomixer/time.h @@ -0,0 +1,7 @@ +#ifndef __TIME_H +#define __TIME_H + +void time_init(void); +int elapsed(int *last_event, int period); + +#endif /* __TIME_H */