Add static and const declarations and spaces

Add `static` keyword for consistency and `const` where it makes
sense. Also add spaces when declaring enums.
This commit is contained in:
finga 2021-09-12 15:37:01 +02:00
parent a5d88e879c
commit f9f131a6da

View file

@ -16,8 +16,8 @@
#define ENC_A (PINB & (1 << PB6))
#define ENC_B (PINB & (1 << PB7))
uint8_t EEMEM eeprom_contrast = 8;
uint8_t EEMEM eeprom_backlight = 1;
static uint8_t EEMEM eeprom_contrast = 8;
static uint8_t EEMEM eeprom_backlight = 1;
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,
@ -93,37 +93,37 @@ static const struct symbol sym_colon = { 2, { 0x30, 0x30,
static const struct symbol sym_setup = { 19, { 0xF8, 0x98, 0xB8, 0x00, 0xF8, 0x98, 0x18, 0x00, 0x18, 0xF8, 0x18, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0xF8, 0x98, 0xF8,
0x1D, 0x19, 0x1F, 0x00, 0x1F, 0x19, 0x18, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x00, 0x1F, 0x01, 0x01 } };
enum input {cw, ccw, click, hold};
enum input { cw, ccw, click, hold };
static volatile enum state {home, ch1, ch2, ch3, setup} current_state = home;
static volatile enum state { home, ch1, ch2, ch3, setup } current_state = home;
static volatile enum state home_state = ch1;
static volatile enum setup_state {contrast, backlight, back, change_contrast, change_backlight} setup_state = contrast;
static volatile enum setup_state { contrast, backlight, back, change_contrast, change_backlight } setup_state = contrast;
static volatile uint8_t enc = 0;
static volatile uint8_t value_contrast;
static volatile uint8_t value_backlight;
void spi_init(void) {
static void spi_init(void) {
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
SPI_PORT |= (1 << SPI_SS);
SPCR = (1 << SPE) | (1 << MSTR);
SPSR = (1 << SPI2X);
}
uint8_t spi_byte(uint8_t data) {
static uint8_t spi_byte(const uint8_t data) {
SPDR = data;
while(!(SPSR & (1 << SPIF)));
return SPDR;
}
void lcd_write(uint8_t data) {
static void lcd_write(const uint8_t data) {
SPI_PORT &= ~(1 << SPI_SS);
spi_byte(data);
SPI_PORT |= (1 << SPI_SS);
}
void lcd_init(void) {
static void lcd_init(void) {
SPI_DDR |= (1 << LCD_CD) | (1 << LCD_RST);
_delay_ms(1);
SPI_PORT |= (1 << LCD_RST);
@ -141,14 +141,14 @@ void lcd_init(void) {
lcd_write(0xAF); // (12) Set Display Enable: Display on
}
void lcd_update_contrast(void) {
static 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) {
static void lcd_update_backlight(void) {
switch (value_backlight) {
case 0:
DDRD &= (0 << PD5);
@ -160,7 +160,7 @@ void lcd_update_backlight(void) {
}
}
void lcd_fill(uint8_t data) {
static void lcd_fill(const uint8_t data) {
for (uint8_t i = 0; i < 8; i++) {
SPI_PORT &= ~(1 << LCD_CD);
lcd_write(0x00);
@ -183,8 +183,8 @@ static void lcd_write_kerning(const uint8_t length,
}
static void lcd_write_symbol_page(const struct symbol* sym,
uint8_t page,
bool invert) {
const uint8_t page,
const bool invert) {
for (uint8_t i = 0; i < sym->length; i++)
if (invert)
lcd_write(~sym->symbol[page * sym->length + i]);
@ -192,8 +192,9 @@ 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) {
static void lcd_write_digit_page(const uint8_t digit,
const uint8_t page,
const bool invert) {
switch (digit) {
case 0:
lcd_write_symbol_page(&sym_0, page, invert);
@ -228,8 +229,10 @@ static void lcd_write_digit_page(uint8_t digit, uint8_t page,
}
}
static void lcd_write_integer_page(uint8_t integer, uint8_t digits,
uint8_t page, bool invert) {
static void lcd_write_integer_page(const uint8_t integer,
const uint8_t digits,
const uint8_t page,
const bool invert) {
if (digits != 0 || integer != 0) {
uint8_t input_digits = 0;
uint16_t comperator = 1;
@ -248,7 +251,7 @@ static void lcd_write_integer_page(uint8_t integer, uint8_t digits,
}
}
void lcd_splash(void) {
static void lcd_splash(void) {
lcd_fill(0x00);
for (uint8_t i = 0; i < 5; i++) {
@ -483,7 +486,7 @@ static void lcd_setup(void) {
}
}
static void change_state(enum state new_state) {
static void change_state(const enum state new_state) {
switch (new_state) {
case home:
lcd_home();
@ -503,7 +506,7 @@ static void change_state(enum state new_state) {
}
}
static void update_home(enum input event) {
static void update_home(const enum input event) {
switch (event) {
case cw:
home_state++;
@ -525,7 +528,7 @@ static void update_home(enum input event) {
}
}
static void update_setup(enum input event) {
static void update_setup(const enum input event) {
switch (event) {
case cw:
switch (setup_state) {
@ -624,7 +627,7 @@ static void update_setup(enum input event) {
}
}
static void update_state(enum input event) {
static void update_state(const enum input event) {
switch (current_state) {
case home:
update_home(event);