Furbish code and comments
Add `TODO` comment to optimize waiting times, fix capitalization in comments, add blank line and break up long lines. To improve code semantics `lcd_home()` and `lcd_setup()` were renamed to `draw_home()` and `draw_setup()` respectively. Improve ordering of function calls in `main()`.
This commit is contained in:
parent
2579ae3686
commit
3aa458c4bc
1 changed files with 31 additions and 26 deletions
|
@ -187,6 +187,7 @@ static void lcd_write(const uint8_t data) {
|
|||
}
|
||||
|
||||
static void lcd_init(void) {
|
||||
// TODO: Optimize waiting times
|
||||
SPI_DDR |= (1 << LCD_CD) | (1 << LCD_RST);
|
||||
_delay_ms(1);
|
||||
SPI_PORT |= (1 << LCD_RST);
|
||||
|
@ -221,12 +222,12 @@ static void lcd_update_backlight(void) {
|
|||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
TCCR0B = 0x0C; // prescaler = 256;
|
||||
TCCR0B = 0x0C; // Prescaler = 256;
|
||||
DDRD |= (1 << PD5);
|
||||
OCR0B = value_backlight - 1;
|
||||
break;
|
||||
default:
|
||||
TCCR0B = 0x0B; // prescaler = 64;
|
||||
TCCR0B = 0x0B; // Prescaler = 64;
|
||||
DDRD |= (1 << PD5);
|
||||
OCR0B = value_backlight - 4;
|
||||
break;
|
||||
|
@ -301,6 +302,7 @@ static void lcd_write_integer_page(const uint8_t integer,
|
|||
uint16_t comperator = 1;
|
||||
|
||||
for (; comperator <= integer; comperator *= 10, input_digits++);
|
||||
|
||||
for (int8_t i = digits - input_digits; i > 0; i--) {
|
||||
lcd_write_kerning(2, invert);
|
||||
lcd_write_digit_page(0, page, invert);
|
||||
|
@ -424,7 +426,7 @@ static void twi_write_register(const uint8_t address,
|
|||
twi_stop();
|
||||
}
|
||||
|
||||
static void lcd_home(void) {
|
||||
static void draw_home(void) {
|
||||
lcd_fill(0x00);
|
||||
|
||||
bool ch1_selected = false;
|
||||
|
@ -466,7 +468,7 @@ static void lcd_home(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void lcd_setup(void) {
|
||||
static void draw_setup(void) {
|
||||
lcd_fill(0x00);
|
||||
|
||||
bool contrast_selected = false;
|
||||
|
@ -505,7 +507,8 @@ static void lcd_setup(void) {
|
|||
lcd_write_string_page("CONTRAST:\0", i, contrast_selected);
|
||||
lcd_write_kerning(2, contrast_selected);
|
||||
lcd_write_kerning(16, false);
|
||||
lcd_write_integer_page(value_contrast, 2, i, change_contrast_selected);
|
||||
lcd_write_integer_page(value_contrast, 2, i,
|
||||
change_contrast_selected);
|
||||
lcd_write_kerning(2, change_contrast_selected);
|
||||
}
|
||||
|
||||
|
@ -514,7 +517,8 @@ static void lcd_setup(void) {
|
|||
lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected);
|
||||
lcd_write_kerning(2, backlight_selected);
|
||||
lcd_write_kerning(5, false);
|
||||
lcd_write_integer_page(value_backlight, 3, i, change_backlight_selected);
|
||||
lcd_write_integer_page(value_backlight, 3, i,
|
||||
change_backlight_selected);
|
||||
lcd_write_kerning(2, change_backlight_selected);
|
||||
}
|
||||
|
||||
|
@ -528,7 +532,7 @@ static void lcd_setup(void) {
|
|||
static void change_state(const enum state new_state) {
|
||||
switch (new_state) {
|
||||
case home:
|
||||
lcd_home();
|
||||
draw_home();
|
||||
current_state = home;
|
||||
break;
|
||||
case ch1:
|
||||
|
@ -539,7 +543,7 @@ static void change_state(const enum state new_state) {
|
|||
break;
|
||||
case setup:
|
||||
setup_state = contrast;
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
current_state = setup;
|
||||
break;
|
||||
}
|
||||
|
@ -551,13 +555,13 @@ static void update_home(const enum input event) {
|
|||
home_state++;
|
||||
if (home_state > setup)
|
||||
home_state = ch1;
|
||||
lcd_home();
|
||||
draw_home();
|
||||
break;
|
||||
case ccw:
|
||||
home_state--;
|
||||
if (home_state > setup)
|
||||
home_state = setup;
|
||||
lcd_home();
|
||||
draw_home();
|
||||
break;
|
||||
case click:
|
||||
change_state(home_state);
|
||||
|
@ -591,7 +595,7 @@ static void update_setup(const enum input event) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case ccw:
|
||||
switch (setup_state) {
|
||||
|
@ -615,17 +619,17 @@ static void update_setup(const enum input event) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case click:
|
||||
switch (setup_state) {
|
||||
case contrast:
|
||||
setup_state = change_contrast;
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case backlight:
|
||||
setup_state = change_backlight;
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case back:
|
||||
change_state(home);
|
||||
|
@ -633,12 +637,12 @@ static void update_setup(const enum input event) {
|
|||
case change_contrast:
|
||||
eeprom_update_byte(&eeprom_contrast, value_contrast);
|
||||
setup_state = contrast;
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case change_backlight:
|
||||
eeprom_update_byte(&eeprom_backlight, value_backlight);
|
||||
setup_state = backlight;
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -653,13 +657,13 @@ static void update_setup(const enum input event) {
|
|||
setup_state = contrast;
|
||||
value_contrast = eeprom_read_byte(&eeprom_contrast);
|
||||
lcd_update_contrast();
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
case change_backlight:
|
||||
setup_state = backlight;
|
||||
value_backlight = eeprom_read_byte(&eeprom_backlight);
|
||||
lcd_update_backlight();
|
||||
lcd_setup();
|
||||
draw_setup();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -726,7 +730,7 @@ ISR(PCINT0_vect) {
|
|||
sei();
|
||||
}
|
||||
|
||||
// encoder button interrupt
|
||||
// Encoder button interrupt
|
||||
ISR(PCINT1_vect) {
|
||||
cli();
|
||||
|
||||
|
@ -762,13 +766,12 @@ int main(void) {
|
|||
value_contrast = eeprom_read_byte(&eeprom_contrast);
|
||||
value_backlight = eeprom_read_byte(&eeprom_backlight);
|
||||
|
||||
// Init backlight: FastPWM: 1.25kHz
|
||||
// TODO: Try to get the backlit even more dim
|
||||
// Init backlight
|
||||
TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
||||
OCR0A = 255;
|
||||
lcd_update_backlight();
|
||||
|
||||
// SPI setup
|
||||
// SPI and LCD init
|
||||
spi_init();
|
||||
lcd_init();
|
||||
|
||||
|
@ -786,13 +789,12 @@ int main(void) {
|
|||
OCR1A = 65535;
|
||||
TIMSK1 |= (1 << OCIE1A); // Enable match compare A
|
||||
|
||||
// Show splash screen and load the menu
|
||||
// Show splash screen
|
||||
lcd_splash();
|
||||
_delay_ms(2000);
|
||||
change_state(current_state);
|
||||
|
||||
// Enable interrupts
|
||||
sei();
|
||||
// Load the menu
|
||||
change_state(current_state);
|
||||
|
||||
// Set TWI bit rate to 200kHz
|
||||
TWBR = 12;
|
||||
|
@ -800,6 +802,9 @@ int main(void) {
|
|||
(void) &twi_read_register;
|
||||
(void) &twi_write_register;
|
||||
|
||||
// Enable interrupts
|
||||
sei();
|
||||
|
||||
// Run...
|
||||
for (;;);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue