2011-11-14 20:23:01 +01:00
|
|
|
/***************************************************************************
|
2012-01-07 19:57:34 +01:00
|
|
|
* 16ch RGB 8bit PWM controller *
|
2011-11-14 20:23:01 +01:00
|
|
|
* *
|
2012-02-11 14:00:34 +01:00
|
|
|
* Copyright (C) 2011 - 2012 by Olaf Rempel *
|
2011-11-14 20:23:01 +01:00
|
|
|
* razzor AT kopf MINUS tisch DOT de *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; version 2 of the License, *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-03-02 17:35:35 +01:00
|
|
|
#include "rgb16mpm.h"
|
|
|
|
|
2011-11-14 20:23:01 +01:00
|
|
|
/*
|
2012-01-07 19:57:34 +01:00
|
|
|
* using ATmega32 @8MHz:
|
|
|
|
* Fuse H: 0xD9 (no bootloader, jtag disabled)
|
|
|
|
* Fuse L: 0xD4 (int. 8MHz Osz, fast rising power, no BOD)
|
|
|
|
*
|
|
|
|
* PA0..7 -> COL1..8
|
|
|
|
* PC0..7 -> COL9..16
|
2012-02-20 21:34:22 +01:00
|
|
|
* PB0 / PD7(OC2) -> ROW2/GREEN (OC2 not used)
|
|
|
|
* PB1 / PD5(OC1A) -> ROW1/RED (OC1A not used)
|
|
|
|
* PB2 / PD4(OC1B) -> ROW4 (OC1B not used)
|
|
|
|
* PB3(OC0) / PD6 -> ROW3/BLUE (OC0 not used)
|
2012-01-07 19:57:34 +01:00
|
|
|
* PD0 -> RXD
|
|
|
|
* PD1 -> TXD
|
|
|
|
* PD2 -> /RX_TX
|
|
|
|
* PD3 -> /LED
|
2011-11-14 20:23:01 +01:00
|
|
|
*/
|
2012-01-07 19:57:34 +01:00
|
|
|
|
2012-02-11 14:00:34 +01:00
|
|
|
int main(void) __attribute__ ((noreturn));
|
2011-11-14 20:23:01 +01:00
|
|
|
int main(void)
|
|
|
|
{
|
2012-03-02 17:35:35 +01:00
|
|
|
DDRD = (1<<LED);
|
2012-02-11 14:00:34 +01:00
|
|
|
PORTD = (1<<LED);
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-03-02 17:35:35 +01:00
|
|
|
eeprom_read();
|
|
|
|
rgb_init();
|
|
|
|
mpm_init();
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-01-07 19:57:34 +01:00
|
|
|
sei();
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-01-07 19:57:34 +01:00
|
|
|
uint8_t x = 0;
|
|
|
|
uint8_t xdir = 1;
|
2012-02-07 20:45:45 +01:00
|
|
|
uint16_t ramp = 0;
|
2012-01-07 19:57:34 +01:00
|
|
|
uint8_t step = 0;
|
|
|
|
|
|
|
|
while (1) {
|
2012-03-02 17:35:35 +01:00
|
|
|
/* wait for complete update */
|
|
|
|
rgb_update(COLOR_MASK, 1);
|
2012-01-07 19:57:34 +01:00
|
|
|
|
2012-02-11 14:00:34 +01:00
|
|
|
#if 1
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-02-11 14:00:34 +01:00
|
|
|
// _delay_ms(100);
|
2012-01-07 19:57:34 +01:00
|
|
|
|
|
|
|
step++;
|
|
|
|
if (step == 16) {
|
|
|
|
step = 0;
|
|
|
|
|
|
|
|
if (xdir) {
|
|
|
|
x++;
|
|
|
|
if (x == 0x05)
|
|
|
|
x = 0x08;
|
|
|
|
else if (x == 0x0C)
|
|
|
|
xdir = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
x--;
|
|
|
|
if (x == 0x00)
|
|
|
|
xdir = 1;
|
|
|
|
else if (x == 0x07)
|
|
|
|
x = 0x04;
|
|
|
|
}
|
|
|
|
}
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-02-07 20:45:45 +01:00
|
|
|
uint8_t color[3];
|
|
|
|
|
|
|
|
ramp++;
|
|
|
|
switch (ramp >> 8) {
|
|
|
|
case 6:
|
|
|
|
ramp = 0x0000;
|
|
|
|
/* no break */
|
|
|
|
|
2012-01-07 19:57:34 +01:00
|
|
|
case 0: /* red: on, green: ramp up, blue: off */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = 0xFF;
|
|
|
|
color[1] = ramp & 0xFF;
|
|
|
|
color[2] = 0x00;
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* red: ramp down, green: on, blue:off */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = 0xFF - (ramp & 0xFF);
|
|
|
|
color[1] = 0xFF;
|
|
|
|
color[2] = 0x00;
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* red: off, green: on, blue: ramp up */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = 0x00;
|
|
|
|
color[1] = 0xFF;
|
|
|
|
color[2] = (ramp & 0xFF);
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* red: off, green: ramp down: blue: on */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = 0x00;
|
|
|
|
color[1] = 0xFF - (ramp & 0xFF);
|
|
|
|
color[2] = 0xFF;
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: /* red: ramp up, green: off, blue: on */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = (ramp & 0xFF);
|
|
|
|
color[1] = 0x00;
|
|
|
|
color[2] = 0xFF;
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: /* red: on, green: off, blue: ramp down */
|
2012-02-07 20:45:45 +01:00
|
|
|
color[0] = 0xFF;
|
|
|
|
color[1] = 0x00;
|
|
|
|
color[2] = 0xFF - (ramp & 0xFF);
|
2012-01-07 19:57:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-11-14 20:23:01 +01:00
|
|
|
|
2012-02-07 20:45:45 +01:00
|
|
|
uint8_t i, j;
|
2012-01-07 19:57:34 +01:00
|
|
|
for (i = 0; i < 16; i++) {
|
2012-02-07 20:45:45 +01:00
|
|
|
for (j = 0; j < 3; j++) {
|
2012-03-02 17:35:35 +01:00
|
|
|
#if 1
|
2012-02-07 20:45:45 +01:00
|
|
|
if (x == i) {
|
|
|
|
chan_value[j][i] = color[j];
|
2012-01-07 19:57:34 +01:00
|
|
|
|
2012-02-07 20:45:45 +01:00
|
|
|
} else if (chan_value[j][i] > 0) {
|
|
|
|
uint8_t tmp = (chan_value[j][i] >> 5);
|
|
|
|
chan_value[j][i] -= (tmp > 0) ? tmp : 1;
|
2012-01-07 19:57:34 +01:00
|
|
|
}
|
|
|
|
#else
|
2012-02-07 20:45:45 +01:00
|
|
|
chan_value[j][i] = color[j];
|
2012-01-07 19:57:34 +01:00
|
|
|
#endif
|
2012-02-07 20:45:45 +01:00
|
|
|
}
|
2012-01-07 19:57:34 +01:00
|
|
|
}
|
2012-02-11 14:00:34 +01:00
|
|
|
#endif
|
2012-01-07 19:57:34 +01:00
|
|
|
}
|
2011-11-14 20:23:01 +01:00
|
|
|
}
|