Compare commits

...

2 commits

Author SHA1 Message Date
e2d30d7050 Fix indents and switch syntax
Fix indentions in `spi_byte()` and add missing space after `switch`
keywords.
2021-09-11 00:21:01 +02:00
6eb515e2d4 Display digits and integers
Display digits and integers, for the later displaying leading zeroes
is supported via parameter. Demo integers are displayed in the setup
screen.
2021-09-11 00:19:59 +02:00

View file

@ -104,10 +104,10 @@ void spi_init(void) {
}
uint8_t spi_byte(uint8_t data) {
SPDR = data;
while(!(SPSR & (1 << SPIF)));
return SPDR;
}
SPDR = data;
while(!(SPSR & (1 << SPIF)));
return SPDR;
}
void lcd_write(uint8_t data) {
SPI_PORT &= ~(1 << SPI_SS);
@ -165,6 +165,62 @@ static void lcd_write_symbol_page(const struct symbol* sym,
lcd_write(sym->symbol[page * sym->length + i]);
}
static void lcd_write_digit_page(uint8_t digit, uint8_t page,
bool invert) {
switch (digit) {
case 0:
lcd_write_symbol_page(&sym_0, page, invert);
break;
case 1:
lcd_write_symbol_page(&sym_1, page, invert);
break;
case 2:
lcd_write_symbol_page(&sym_2, page, invert);
break;
case 3:
lcd_write_symbol_page(&sym_3, page, invert);
break;
case 4:
lcd_write_symbol_page(&sym_4, page, invert);
break;
case 5:
lcd_write_symbol_page(&sym_5, page, invert);
break;
case 6:
lcd_write_symbol_page(&sym_6, page, invert);
break;
case 7:
lcd_write_symbol_page(&sym_7, page, invert);
break;
case 8:
lcd_write_symbol_page(&sym_8, page, invert);
break;
case 9:
lcd_write_symbol_page(&sym_9, page, invert);
break;
}
}
static void lcd_write_integer_page(uint8_t integer, uint8_t digits,
uint8_t page, bool invert) {
if (digits != 0 || integer != 0) {
uint8_t input_digits = 0;
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);
}
for (; comperator >= 10; comperator /= 10) {
lcd_write_kerning(2, invert);
lcd_write_digit_page((integer % comperator) / (comperator / 10),
page, invert);
}
}
}
void lcd_splash(void) {
lcd_fill(0x00);
@ -200,7 +256,7 @@ static void lcd_home(void) {
bool ch3_selected = false;
bool setup_selected = false;
switch(home_state) {
switch (home_state) {
case ch1:
ch1_selected = true;
break;
@ -317,7 +373,8 @@ static void lcd_setup(void) {
lcd_write_symbol_page(&sym_t, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_colon, i, false);
lcd_write_kerning(13, false);
lcd_write_kerning(11, false);
lcd_write_integer_page(123, 1, i, false);
}
for (uint8_t i = 0; i < 2; i++) {
@ -346,7 +403,8 @@ static void lcd_setup(void) {
lcd_write_symbol_page(&sym_t, i, false);
lcd_write_kerning(2, false);
lcd_write_symbol_page(&sym_colon, i, false);
lcd_write_kerning(9, false);
lcd_write_kerning(7, false);
lcd_write_integer_page(123, 3, i, false);
}
for (uint8_t i = 0; i < 2; i++) {
@ -367,7 +425,7 @@ static void lcd_setup(void) {
}
static void change_state(enum state new_state) {
switch(new_state) {
switch (new_state) {
case home:
lcd_home();
current_state = home;
@ -442,7 +500,7 @@ static void update_state(enum input event) {
ISR(PCINT0_vect) {
cli();
switch(enc) {
switch (enc) {
case 0:
if (ENC_A && !ENC_B)
enc = 1;