2013-03-21 05:42:31 -04:00
|
|
|
#include <stdio.h>
|
2013-03-23 19:46:23 -04:00
|
|
|
#include <stdlib.h>
|
2013-03-21 05:42:31 -04:00
|
|
|
|
|
|
|
#include <irq.h>
|
|
|
|
#include <uart.h>
|
2013-07-11 13:00:48 -04:00
|
|
|
#include <time.h>
|
2013-11-24 13:50:17 -05:00
|
|
|
#include <generated/csr.h>
|
2013-04-14 10:33:00 -04:00
|
|
|
#include <hw/flags.h>
|
2013-05-12 15:46:16 -04:00
|
|
|
#include <console.h>
|
2013-03-21 10:32:26 -04:00
|
|
|
|
2013-11-30 17:07:19 -05:00
|
|
|
#include "config.h"
|
2013-11-11 17:20:21 -05:00
|
|
|
#include "ci.h"
|
2013-11-11 11:52:07 -05:00
|
|
|
#include "processor.h"
|
2013-03-21 05:42:31 -04:00
|
|
|
|
2013-09-13 12:32:01 -04:00
|
|
|
#ifdef POTS_BASE
|
2013-05-13 09:45:28 -04:00
|
|
|
static int scale_pot(int raw, int range)
|
|
|
|
{
|
2013-05-16 11:43:56 -04:00
|
|
|
int pot_min = 64000;
|
|
|
|
int pot_max = 103000;
|
2013-05-13 09:45:28 -04:00
|
|
|
int scaled;
|
|
|
|
|
|
|
|
scaled = range*(raw - pot_min)/(pot_max - pot_min);
|
|
|
|
if(scaled < 0)
|
|
|
|
scaled = 0;
|
|
|
|
if(scaled > range)
|
|
|
|
scaled = range;
|
|
|
|
return scaled;
|
|
|
|
}
|
|
|
|
|
2013-05-16 11:44:49 -04:00
|
|
|
static void regular_blend(int p0, int p1)
|
2013-05-13 09:45:28 -04:00
|
|
|
{
|
|
|
|
int blackout;
|
|
|
|
int crossfade;
|
|
|
|
|
2013-05-16 11:44:49 -04:00
|
|
|
blackout = scale_pot(p0, 256);
|
|
|
|
crossfade = scale_pot(p1, 255);
|
|
|
|
|
|
|
|
fb_blender_f0_write(crossfade*blackout >> 8);
|
|
|
|
fb_blender_f1_write((255-crossfade)*blackout >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void additive_blend(int p0, int p1)
|
|
|
|
{
|
|
|
|
fb_blender_f0_write(scale_pot(p0, 255));
|
|
|
|
fb_blender_f1_write(scale_pot(p1, 255));
|
|
|
|
}
|
|
|
|
|
2013-09-13 12:32:01 -04:00
|
|
|
static void ui_service(void)
|
2013-05-16 11:44:49 -04:00
|
|
|
{
|
|
|
|
static int last_event;
|
|
|
|
static int additive_blend_enabled;
|
|
|
|
static int old_btn;
|
|
|
|
int btn;
|
|
|
|
int p0, p1;
|
|
|
|
|
2013-05-13 09:45:28 -04:00
|
|
|
if(elapsed(&last_event, identifier_frequency_read()/32)) {
|
2013-05-16 11:44:49 -04:00
|
|
|
btn = buttons_in_read() & 0x1;
|
|
|
|
if(btn && !old_btn) {
|
|
|
|
additive_blend_enabled = !additive_blend_enabled;
|
|
|
|
if(additive_blend_enabled)
|
|
|
|
leds_out_write(leds_out_read() | 0x1);
|
|
|
|
else
|
|
|
|
leds_out_write(leds_out_read() & ~0x1);
|
|
|
|
}
|
|
|
|
old_btn = btn;
|
|
|
|
|
2013-05-13 09:45:28 -04:00
|
|
|
pots_start_busy_write(1);
|
|
|
|
while(pots_start_busy_read());
|
2013-05-16 11:44:49 -04:00
|
|
|
p0 = pots_res0_read();
|
|
|
|
p1 = pots_res1_read();
|
|
|
|
if(!additive_blend_enabled)
|
|
|
|
regular_blend(p0, p1);
|
|
|
|
else
|
|
|
|
additive_blend(p0, p1);
|
2013-05-13 09:45:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 12:32:01 -04:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void ui_service(void)
|
|
|
|
{
|
|
|
|
fb_blender_f0_write(0xff);
|
|
|
|
fb_blender_f1_write(0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-05-13 09:45:28 -04:00
|
|
|
int main(void)
|
|
|
|
{
|
2013-03-21 05:42:31 -04:00
|
|
|
irq_setmask(0);
|
|
|
|
irq_setie(1);
|
|
|
|
uart_init();
|
|
|
|
|
2014-02-16 08:51:52 -05:00
|
|
|
printf("Mixxeo software rev. %08x built "__DATE__" "__TIME__"\n\n", MSC_GIT_ID);
|
2013-03-21 05:42:31 -04:00
|
|
|
|
2013-11-30 17:07:19 -05:00
|
|
|
config_init();
|
2013-05-13 09:45:28 -04:00
|
|
|
time_init();
|
2013-11-30 17:07:19 -05:00
|
|
|
processor_start(config_get(CONFIG_KEY_RESOLUTION));
|
2013-05-13 09:45:28 -04:00
|
|
|
|
2013-05-10 15:03:55 -04:00
|
|
|
while(1) {
|
2013-11-11 11:52:07 -05:00
|
|
|
processor_service();
|
2013-09-13 12:32:01 -04:00
|
|
|
ui_service();
|
2013-11-11 17:20:21 -05:00
|
|
|
ci_service();
|
2013-05-10 15:03:55 -04:00
|
|
|
}
|
2013-03-21 05:42:31 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|