Compare commits

..

No commits in common. "a5d88e879c5e9298b29d25f5a5795b56bf4f15ae" and "05c9888a7514181d9a88d6e668d4640a9b59c3d3" have entirely different histories.

View file

@ -16,8 +16,8 @@
#define ENC_A (PINB & (1 << PB6)) #define ENC_A (PINB & (1 << PB6))
#define ENC_B (PINB & (1 << PB7)) #define ENC_B (PINB & (1 << PB7))
uint8_t EEMEM eeprom_contrast = 8; uint8_t EEMEM eeprom_contrast = 0;
uint8_t EEMEM eeprom_backlight = 1; uint8_t EEMEM eeprom_backlight = 0;
static const uint8_t sacred_chao[200] = { 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, static const uint8_t sacred_chao[200] = { 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x80, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0xC3, 0xE3, 0x73, 0x37, 0x17, 0x07, 0x0F, 0x1E, 0x3C, 0xF0, 0x80, 0x80, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0xC3, 0xE3, 0x73, 0x37, 0x17, 0x07, 0x0F, 0x1E, 0x3C, 0xF0, 0x80,
@ -137,29 +137,10 @@ void lcd_init(void) {
lcd_write(0x2F); // (5) Set Power Control: Booster, Regulator and Follower on lcd_write(0x2F); // (5) Set Power Control: Booster, Regulator and Follower on
lcd_write(0x27); // (8) Set VLCD Resistor Ratio: Set Contrast lcd_write(0x27); // (8) Set VLCD Resistor Ratio: Set Contrast
lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast
lcd_write(value_contrast); // (9) Set Electronic Volume: Set Contrast lcd_write(0x10); // (9) Set Electronic Volume: Set Contrast
lcd_write(0xAF); // (12) Set Display Enable: Display on lcd_write(0xAF); // (12) Set Display Enable: Display on
} }
void lcd_update_contrast(void) {
SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast
lcd_write(value_contrast); // (9) Set Electronic Volume: Set Contrast
SPI_PORT |= (1 << LCD_CD);
}
void lcd_update_backlight(void) {
switch (value_backlight) {
case 0:
DDRD &= (0 << PD5);
break;
default:
DDRD |= (1 << PD5);
OCR0B = value_backlight - 1;
break;
}
}
void lcd_fill(uint8_t data) { void lcd_fill(uint8_t data) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
SPI_PORT &= ~(1 << LCD_CD); SPI_PORT &= ~(1 << LCD_CD);
@ -426,19 +407,18 @@ static void lcd_setup(void) {
lcd_write_kerning(2, contrast_selected); lcd_write_kerning(2, contrast_selected);
lcd_write_symbol_page(&sym_colon, i, contrast_selected); lcd_write_symbol_page(&sym_colon, i, contrast_selected);
lcd_write_kerning(2, contrast_selected); lcd_write_kerning(2, contrast_selected);
lcd_write_kerning(16, false); lcd_write_kerning(9, false);
lcd_write_integer_page(value_contrast, 2, i, change_contrast_selected); lcd_write_integer_page(value_contrast, 3, i, change_contrast_selected);
lcd_write_kerning(2, change_contrast_selected); lcd_write_kerning(2, change_contrast_selected);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
SPI_PORT &= ~(1 << LCD_CD); SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x00); lcd_write(0x02);
lcd_write(0x10); lcd_write(0x10);
lcd_write(0xB4 + i); lcd_write(0xB4 + i);
SPI_PORT |= (1 << LCD_CD); SPI_PORT |= (1 << LCD_CD);
lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_b, i, backlight_selected); lcd_write_symbol_page(&sym_b, i, backlight_selected);
lcd_write_kerning(2, backlight_selected); lcd_write_kerning(2, backlight_selected);
lcd_write_symbol_page(&sym_a, i, backlight_selected); lcd_write_symbol_page(&sym_a, i, backlight_selected);
@ -537,16 +517,10 @@ static void update_setup(enum input event) {
setup_state = contrast; setup_state = contrast;
break; break;
case change_contrast: case change_contrast:
if (value_contrast < 63) { value_contrast++;
value_contrast++;
lcd_update_contrast();
}
break; break;
case change_backlight: case change_backlight:
if (value_backlight < 100) { value_backlight++;
value_backlight++;
lcd_update_backlight();
}
break; break;
} }
lcd_setup(); lcd_setup();
@ -561,16 +535,10 @@ static void update_setup(enum input event) {
setup_state = back; setup_state = back;
break; break;
case change_contrast: case change_contrast:
if (value_contrast > 0) { value_contrast--;
value_contrast--;
lcd_update_contrast();
}
break; break;
case change_backlight: case change_backlight:
if (value_backlight > 0) { value_backlight--;
value_backlight--;
lcd_update_backlight();
}
break; break;
} }
lcd_setup(); lcd_setup();
@ -610,13 +578,11 @@ static void update_setup(enum input event) {
case change_contrast: case change_contrast:
setup_state = contrast; setup_state = contrast;
value_contrast = eeprom_read_byte(&eeprom_contrast); value_contrast = eeprom_read_byte(&eeprom_contrast);
lcd_update_contrast();
lcd_setup(); lcd_setup();
break; break;
case change_backlight: case change_backlight:
setup_state = backlight; setup_state = backlight;
value_backlight = eeprom_read_byte(&eeprom_backlight); value_backlight = eeprom_read_byte(&eeprom_backlight);
lcd_update_backlight();
lcd_setup(); lcd_setup();
break; break;
} }
@ -695,8 +661,9 @@ ISR(PCINT1_vect) {
TCNT1 = 0; TCNT1 = 0;
} }
} else { // press } else { // press
if (!(TCCR1B & (1 << CS10))) if (!(TCCR1B & (1 << CS10))) {
TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1 TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1
}
} }
// TODO: proper debouncing // TODO: proper debouncing
@ -705,7 +672,7 @@ ISR(PCINT1_vect) {
sei(); sei();
} }
// Timer/Counter1 compare match A for back event // Timer/Counter1 compare match A
ISR(TIMER1_COMPA_vect) { ISR(TIMER1_COMPA_vect) {
cli(); cli();
@ -721,12 +688,13 @@ int main(void) {
value_contrast = eeprom_read_byte(&eeprom_contrast); value_contrast = eeprom_read_byte(&eeprom_contrast);
value_backlight = eeprom_read_byte(&eeprom_backlight); value_backlight = eeprom_read_byte(&eeprom_backlight);
// Init backlight: FastPWM: 1.25kHz // FastPWM: 1.25kHz
// TODO: Try to get the backlit even more dim // TODO: Try to get the backlit even more dim
TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1); TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
TCCR0B |= (1 << CS01) | (1 << WGM02); // prescaler = 8; TCCR0B = (1 << CS01) | (1 << WGM02); // prescaler = 8;
OCR0A = 100; OCR0A = 100;
lcd_update_backlight(); OCR0B = 0;
DDRD |= (1 << PD5);
// SPI setup // SPI setup
spi_init(); spi_init();