channel port refacrtored
This commit is contained in:
parent
d4def49a30
commit
7e86211c93
115
firmware/main.c
115
firmware/main.c
|
@ -32,7 +32,9 @@
|
|||
#include "ir_nec.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <avr/eeprom.h> /* EEPROM handling */
|
||||
volatile uint8_t* PORTS[CHANNELS_1+CHANNELS_2] = {&PORTC,&PORTC,&PORTC,&PORTC,&PORTC,&PORTD,&PORTD,&PORTD,&PORTD,&PORTD};
|
||||
volatile uint8_t* DDRS[CHANNELS_1+CHANNELS_2] = {&DDRC,&DDRC,&DDRC,&DDRC,&DDRC,&DDRD,&DDRD,&DDRD,&DDRD,&DDRD};
|
||||
const uint8_t BITS[CHANNELS_1+CHANNELS_2] = {PC0,PC1,PC2,PC3,PC4};
|
||||
|
||||
/* global variables */
|
||||
#define INPUT_MAX 255 /* max length for user input string */
|
||||
|
@ -181,10 +183,10 @@ void ioinit(void)
|
|||
TIMSK1 |= (1<<OCIE1A); /* enable timer 1 compare interrupt */
|
||||
|
||||
/* configure channels (used for powering LEDs using an nMOS) */
|
||||
DDRC |= (1<<CH1_1)|(1<<CH1_2)|(1<<CH1_3)|(1<<CH1_4)|(1<<CH1_5); /* CH1_x is output */
|
||||
PORTC &= ~((1<<CH1_1)|(1<<CH1_2)|(1<<CH1_3)|(1<<CH1_4)|(1<<CH1_5)); /* switch off CH1_x */
|
||||
DDRD |= (1<<CH2_1)|(1<<CH2_2)|(1<<CH2_3)|(1<<CH2_4)|(1<<CH2_5); /* CH2_x is output */
|
||||
PORTD &= ~((1<<CH2_1)|(1<<CH2_2)|(1<<CH2_3)|(1<<CH2_4)|(1<<CH2_5)); /* switch off CH2_x */
|
||||
for (uint8_t i=0; i<CHANNELS_1+CHANNELS_2; i++) {
|
||||
*(DDRS[i]) |= (1<<BITS[i]);
|
||||
*(PORTS[i]) &= ~(1<<BITS[i]);
|
||||
}
|
||||
|
||||
/* use timer 0 as source for the channel PWM */
|
||||
/* use CTC mode */
|
||||
|
@ -223,24 +225,18 @@ int main(void)
|
|||
channel_flag = true; /* calculate above values later */
|
||||
|
||||
puts("LED dimmer up & running");
|
||||
uint8_t p = 0;
|
||||
eeprom_update_byte((uint8_t*)&p,0x42);
|
||||
printf("eeprom: %02x\n",eeprom_read_byte((uint8_t*)&p));
|
||||
if (verify_settings()) {
|
||||
puts("settings ok");
|
||||
} else {
|
||||
puts("settings corrupted");
|
||||
puts("initializing settings");
|
||||
|
||||
/* load settings */
|
||||
if (!verify_settings()) {
|
||||
initialize_settings();
|
||||
puts("saving settings");
|
||||
save_settings();
|
||||
if (verify_settings()) {
|
||||
puts("settings saved");
|
||||
} else {
|
||||
puts("settings not saved");
|
||||
if (!verify_settings()) {
|
||||
puts("can't store setting");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
load_settings();
|
||||
|
||||
while (true) {
|
||||
/* calculated PWM values */
|
||||
while (channel_flag) {
|
||||
|
@ -355,87 +351,6 @@ void uart_action(char c)
|
|||
//ch_1[0] = (ch_1[0]+1)%(LEVELS+1);
|
||||
channel_flag = true;
|
||||
break;
|
||||
case '2':
|
||||
PINC |= (1<<CH1_2);
|
||||
printf("CH1_2: ");
|
||||
if (PINC&(1<<CH1_2)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
PINC |= (1<<CH1_3);
|
||||
printf("CH1_3: ");
|
||||
if (PINC&(1<<CH1_3)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
PINC |= (1<<CH1_4);
|
||||
printf("CH1_4: ");
|
||||
if (PINC&(1<<CH1_4)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '5':
|
||||
PINC |= (1<<CH1_5);
|
||||
printf("CH1_5: ");
|
||||
if (PINC&(1<<CH1_5)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '6':
|
||||
PIND |= (1<<CH2_1);
|
||||
printf("CH2_1: ");
|
||||
if (PIND&(1<<CH2_1)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '7':
|
||||
PIND |= (1<<CH2_2);
|
||||
printf("CH2_2: ");
|
||||
if (PIND&(1<<CH2_2)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '8':
|
||||
PIND |= (1<<CH2_3);
|
||||
printf("CH2_3: ");
|
||||
if (PIND&(1<<CH2_3)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '9':
|
||||
PIND |= (1<<CH2_4);
|
||||
printf("CH2_4: ");
|
||||
if (PIND&(1<<CH2_4)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
PIND |= (1<<CH2_5);
|
||||
printf("CH2_5: ");
|
||||
if (PIND&(1<<CH2_5)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
if (OCR0A>0) {
|
||||
OCR0A--;
|
||||
|
|
|
@ -16,23 +16,19 @@
|
|||
* It handles all peripherals (power, fan, channels, IR, serial)
|
||||
*/
|
||||
|
||||
/* ports */
|
||||
/* peripheral I/O */
|
||||
#define LED PD6 /* status LED */
|
||||
#define IR PB0 /* IR receiver */
|
||||
#define FAN PC5 /* FAN output */
|
||||
#define PWR_OK PB1 /* ATX power OK */
|
||||
#define nPS_ON PB2 /* ATX power supply ON switch */
|
||||
/* LEDs */
|
||||
#define CH1_1 PC0
|
||||
#define CH1_2 PC1
|
||||
#define CH1_3 PC2
|
||||
#define CH1_4 PC3
|
||||
#define CH1_5 PC4
|
||||
#define CH2_1 PD2
|
||||
#define CH2_2 PD3
|
||||
#define CH2_3 PD4
|
||||
#define CH2_4 PD5
|
||||
#define CH2_5 PD7
|
||||
|
||||
/* 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 volatile uint8_t* DDRS[CHANNELS_1+CHANNELS_2]; /* channel I/O configuration registers */
|
||||
extern const uint8_t BITS[CHANNELS_1+CHANNELS_2]; /* channel bits */
|
||||
|
||||
void ioinit(void);
|
||||
void uart_action(char c);
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
#include <stdbool.h> /* Boolean */
|
||||
#include <avr/eeprom.h> /* EEPROM handling */
|
||||
|
||||
#include "main.h"
|
||||
#include "settings.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 brightness[MODES][CHANNELS_1+CHANNELS_2];
|
||||
uint8_t mode;
|
||||
uint8_t ir_keys[IR_ACTION_END][2];
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
#include <avr/io.h> /* 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
|
||||
|
|
Loading…
Reference in New Issue