diff --git a/firmware/Makefile b/firmware/Makefile index 0292aac..95a998c 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -10,16 +10,12 @@ CFLAGS=-g -Wall -Werror -O3 -std=c99 # the target DEVICE=atmega328p F_CPU=18432000UL -# the port to flash -#PORT=/dev/ttyUSB0 # the flasher -#PROGRAMMER=buspirate PROGRAMMER=usbtiny # to flash -#AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER) FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER) # source files to compile -SRC = main.c uart.c ir_nec.c +SRC = main.c uart.c ir_nec.c settings.c # object files. OBJ = $(SRC:.c=.o) # listing files. diff --git a/firmware/ir_nec.c b/firmware/ir_nec.c index d9c185a..6746248 100644 --- a/firmware/ir_nec.c +++ b/firmware/ir_nec.c @@ -24,6 +24,9 @@ #include "ir_nec.h" +const uint16_t MARKS[2]={9000,560}; +const uint16_t SPACES[4]={4500,2250,1680,560}; + void time2nec(uint16_t* burst, uint8_t pulses) { diff --git a/firmware/ir_nec.h b/firmware/ir_nec.h index 983241f..7d86258 100644 --- a/firmware/ir_nec.h +++ b/firmware/ir_nec.h @@ -17,8 +17,8 @@ * More information at http://www.sbprojects.com/knowledge/ir/nec.php */ -static const uint16_t MARKS[2]={9000,560}; /* mark duration in us [start,bit] */ -static const uint16_t SPACES[4]={4500,2250,1680,560}; /* space duration in us [start,repeat,1,0] */ +extern const uint16_t MARKS[2]; /* mark duration in us [start,bit] */ +extern const uint16_t SPACES[4]; /* space duration in us [start,repeat,1,0] */ struct nec { bool valid; diff --git a/firmware/main.c b/firmware/main.c index daff9cc..0039e8a 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -30,6 +30,7 @@ #include "main.h" #include "uart.h" #include "ir_nec.h" +#include "settings.h" /* global variables */ #define INPUT_MAX 255 /* max length for user input string */ @@ -38,10 +39,10 @@ volatile uint8_t input_i = 0; /* user input index */ volatile uint8_t pwr_ok; /* is power ok */ volatile uint8_t fan; /* fan signal state, to measure tachometer */ volatile uint8_t timer2_ovf = 0; /* to measure fan speed using timer 2 */ -uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ +const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ volatile uint16_t tachometer = 0; /* the tachometer time (from timer) */ volatile uint8_t ir; /* IR signal state, to measure IR code */ -uint16_t TIMER1_PRESCALE[8] = {0,1,8,64,256,1024,0,0}; /* timer 1 CS1[2:0] values */ +const uint16_t TIMER1_PRESCALE[8] = {0,1,8,64,256,1024,0,0}; /* timer 1 CS1[2:0] values */ volatile uint16_t ir_tick; /* number of counter ticks per millisecond */ volatile uint8_t pulse = 0; /* pulse index within the burst */ #define PULSE_MAX 128 /* maximum number of pulses to save */ @@ -49,15 +50,7 @@ uint16_t burst[PULSE_MAX]; /* pulse times forming a burst (from timer) */ /* channel variables */ #define LEVELS 10 /* the number of PWM levels */ -uint8_t ch_tick = 0; /* the tick counter for the channel PWM */ -#define OUTPUTS_1 5 /* the number of outputs for channel 1 */ -#define OUTPUTS_2 5 /* the number of outputs for channel 2 */ -volatile uint8_t* PORTS_1[OUTPUTS_1] = {&PORTC,&PORTC,&PORTC,&PORTC,&PORTC}; /* channel 1 output ports */ -volatile uint8_t* PORTS_2[OUTPUTS_2] = {&PORTD,&PORTD,&PORTD,&PORTD,&PORTD}; /* channel 2 output ports */ -uint8_t BITS_1[OUTPUTS_1] = {PC0,PC1,PC2,PC3,PC4}; /* channel 1 output bits */ -uint8_t BITS_2[OUTPUTS_2] = {PD2,PD3,PD4,PD5,PD7}; /* channel 2 output bits */ -uint8_t ch_1[OUTPUTS_1]; /* the level value for the channel 1 outputs */ -uint8_t ch_2[OUTPUTS_2]; /* the level value for the channel 2 outputs */ +volatile uint8_t ch_tick = 0; /* the tick counter for the channel PWM */ /* flags, set in the interrupts and handled in the main program */ volatile bool uart_flag = false; /* an incoming activity on the UART */ @@ -132,7 +125,7 @@ ISR(TIMER0_COMPA_vect) { /* timer 0 OCR0A match interrupt vector */ pwm_flag = true; } -static void ioinit(void) +void ioinit(void) { /* configure power */ DDRB |= (1< /* Standard Integer Types */ +#include /* Standard IO facilities */ +#include /* General utilities */ +#include /* Boolean */ + +#include "settings.h" + +#include /* Strings */ +#include "uart.h" + +/* initialize variable */ +volatile uint8_t* PORTS[CHANNELS_1+CHANNELS_2] = {&PORTC,&PORTC,&PORTC,&PORTC,&PORTC,&PORTD,&PORTD,&PORTD,&PORTD,&PORTD}; +const uint8_t BITS[CHANNELS_1+CHANNELS_2] = {PC0,PC1,PC2,PC3,PC4}; +uint8_t mode = 0; +uint8_t brightness[MODES][CHANNELS_1+CHANNELS_2]; + +void verify_settings(void) +{ + uint8_t checksum = 0; + printf("brightness: %u\n",sizeof(brightness)); + printf("checksum: %u\n",checksum); +} diff --git a/firmware/settings.h b/firmware/settings.h new file mode 100644 index 0000000..f300318 --- /dev/null +++ b/firmware/settings.h @@ -0,0 +1,27 @@ +#include /* AVR device-specific IO definitions */ + +/* channel definitions */ +#define CHANNELS_1 5 /* the number of outputs for channel 1 */ +#define CHANNELS_2 5 /* the number of outputs for channel 2 */ +extern volatile uint8_t* PORTS[CHANNELS_1+CHANNELS_2]; /* channel ports */ +extern const uint8_t BITS[CHANNELS_1+CHANNELS_2]; /* channel bits */ + +/* mode settings */ +#define MODES 3 /* the number of modes */ +extern uint8_t mode; /* the current mode */ //TODO load the mode +extern uint8_t brightness[MODES][CHANNELS_1+CHANNELS_2]; /* the mode brightness settings for the channels */ + +/* IR settings */ +enum IR_ACTIONS { /* the actions for the infrared remote control */ + POWER = 0, + MODE, + BRIGHTNESS_UP, + BRIGHTNESS_DOWN, + CHANNEL_UP, + CHANNEL_DOWN, + IR_ACTION_END +}; +uint8_t ir_keys[IR_ACTION_END][2]; + +/* function to load/save the settings */ +void verify_settings(void);