diff --git a/firmware/src/Makefile b/firmware/src/Makefile index 1be6326..d1f4470 100644 --- a/firmware/src/Makefile +++ b/firmware/src/Makefile @@ -9,6 +9,7 @@ EEP := main.eep BIN := main.elf OBJ := main.o +LOW_FUSE := 0xE2 HIGH_FUSE := 0xD6 SHELL := sh @@ -42,7 +43,7 @@ eeprom: $(EEP) size $(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U eeprom:w:$<:a fuses: - $(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U hfuse:w:$(HIGH_FUSE):m + $(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U lfuse:w:$(LOW_FUSE):m -U hfuse:w:$(HIGH_FUSE):m clean: $(RM) $(TARGET) $(EEP) $(BIN) $(OBJ) diff --git a/firmware/src/main.c b/firmware/src/main.c index d76bf27..37d994f 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -194,10 +194,20 @@ static void lcd_update_backlight(void) { case 0: DDRD &= (0 << PD5); break; - default: + case 1: + case 2: + case 3: + case 4: + case 5: + TCCR0B = 0x0C; // prescaler = 256; DDRD |= (1 << PD5); OCR0B = value_backlight - 1; break; + default: + TCCR0B = 0x0B; // prescaler = 64; + DDRD |= (1 << PD5); + OCR0B = value_backlight - 4; + break; } } @@ -598,7 +608,7 @@ ISR(PCINT0_vect) { } // TODO: proper dechattering - _delay_us(100); + _delay_ms(3); sei(); } @@ -607,19 +617,19 @@ ISR(PCINT0_vect) { ISR(PCINT1_vect) { cli(); - if (PINC & (1 << PC0)) { // release - TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1 - if (TCNT1 != 0) { + if (PINC & (1 << PC0)) { // Release + if (TCCR1B & (1 << CS10)) // If release before hold update_state(click); // Switch to selected state - TCNT1 = 0; - } - } else { // press + + TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1 + } else { // Press + TCNT1 = 0; if (!(TCCR1B & (1 << CS10))) TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1 } - // TODO: proper debouncing - _delay_us(70); + // TODO: Proper debouncing + _delay_ms(3); sei(); } @@ -629,7 +639,6 @@ ISR(TIMER1_COMPA_vect) { cli(); TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1 - TCNT1 = 0; update_state(hold); sei(); @@ -643,8 +652,7 @@ int main(void) { // Init backlight: FastPWM: 1.25kHz // TODO: Try to get the backlit even more dim TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1); - TCCR0B |= (1 << CS01) | (1 << WGM02); // prescaler = 8; - OCR0A = 100; + OCR0A = 255; lcd_update_backlight(); // SPI setup @@ -661,13 +669,13 @@ int main(void) { PCICR |= (1 << PCIE1); PCMSK1 |= (1 << PCINT8); - // Timer1 setup to recognize held button - OCR1A = 8192; + // Timer/Counter1 setup to recognize held button + OCR1A = 65535; TIMSK1 |= (1 << OCIE1A); // Enable match compare A // Show splash screen and load the menu lcd_splash(); - _delay_ms(250); + _delay_ms(2000); change_state(current_state); // Enable interrupts