Fixed compilation errors. Turned on optimization for size. Added gitignore

This commit is contained in:
nedko 2022-11-04 02:48:35 +02:00
parent 365d906890
commit ca40b8d0eb
3 changed files with 26 additions and 24 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
code/counter*

View File

@ -2,7 +2,7 @@ all:
make build make build
make program make program
build: build:
avr-gcc main.c i2c_master.c -o counter -mmcu=attiny84 -Wall -Wextra avr-gcc main.c i2c_master.c -o counter -mmcu=attiny84 -Wall -Wextra -Os
program: program:
avrdude -p attiny84 -c usbtiny -U flash:w:counter avrdude -p attiny84 -c usbtiny -U flash:w:counter

View File

@ -217,10 +217,10 @@ const uint8_t PROGMEM symbols[31 * CHAR_SIZE] =
const char PROGMEM menu_strings[(MENU_COUNT + 1) * MENU_STRLEN] = const char PROGMEM menu_strings[(MENU_COUNT + 1) * MENU_STRLEN] =
{ {
CHAR_A, CHAR_t, CHAR_t, CHAR_a, CHAR_c, CHAR_h, 0xFF, 0xFF, 0xFF, CHAR_A, CHAR_t, CHAR_t, CHAR_a, CHAR_c, CHAR_h, 0xFF, 0xFF,
CHAR_A, CHAR_d, CHAR_j, CHAR_u, CHAR_s, CHAR_t, 0xFF, 0xFF, 0xFF, CHAR_A, CHAR_d, CHAR_j, CHAR_u, CHAR_s, CHAR_t, 0xFF, 0xFF,
CHAR_B, CHAR_a, CHAR_t, CHAR_t, CHAR_e, CHAR_r, CHAR_y, 0xFF, 0xFF, CHAR_B, CHAR_a, CHAR_t, CHAR_t, CHAR_e, CHAR_r, CHAR_y, 0xFF,
CHAR_D, CHAR_e, CHAR_t, CHAR_a, CHAR_c, CHAR_h, 0xFF, 0xFF, 0xFF CHAR_D, CHAR_e, CHAR_t, CHAR_a, CHAR_c, CHAR_h, 0xFF, 0xFF
}; };
// 1 / (4 * ROT_PULSE_COUNT) * (2 * pi * ROT_WHEEL_RAD) // 1 / (4 * ROT_PULSE_COUNT) * (2 * pi * ROT_WHEEL_RAD)
@ -362,7 +362,7 @@ void set_adjust_spool();
void set_battery_state(); void set_battery_state();
// Updates the ms counter // Updates the ms counter
ISR(TIMER1_OVF_vect) ISR(TIM1_OVF_vect)
{ {
cli(); cli();
ms += 10; ms += 10;
@ -493,8 +493,6 @@ ISR(PCINT1_vect)
int main() int main()
{ {
uint8_t curr_event;
// Init Direct Hardware // Init Direct Hardware
simple_init(); simple_init();
@ -522,7 +520,7 @@ int main()
break; break;
case STATE_ADJUST: case STATE_ADJUST:
process_setting(); process_adjust();
break; break;
case STATE_BATTERY: case STATE_BATTERY:
@ -547,14 +545,14 @@ void simple_init()
{ {
// No Prescaler - 1 MHz // No Prescaler - 1 MHz
// Set Mode to CTC with ICR1 // Set Mode to CTC with ICR1
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 < CS10) TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
// 1 000 000 / 10 000 = 100 (Hz) // 1 000 000 / 10 000 = 100 (Hz)
// Interrupt every 10ms // Interrupt every 10ms
ICR1 = 10000; ICR1 = 10000;
// Enable Interrupt on overflow // Enable Interrupt on overflow
TIMSK = (1 << TOIE1); TIMSK1 = (1 << TOIE1);
// Interrupt on Up/Down/Click pins // Interrupt on Up/Down/Click pins
PCMSK0 = (1 << PCINT0) | (1 << PCINT1) | (1 << PCINT2) | (1 << PCINT3) | (1 << PCINT5); PCMSK0 = (1 << PCINT0) | (1 << PCINT1) | (1 << PCINT2) | (1 << PCINT3) | (1 << PCINT5);
@ -768,7 +766,7 @@ void print_symbol(uint8_t symbol_idx, uint8_t x, uint8_t y, uint8_t invert)
void print_mm() void print_mm()
{ {
static_uint8_t old_symbols[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; static uint8_t old_symbols[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static uint8_t old_highlight = 0xFF; static uint8_t old_highlight = 0xFF;
uint8_t x; uint8_t x;
uint8_t y; uint8_t y;
@ -866,7 +864,7 @@ void print_direction()
} }
// Print symbol on change or highlight change // Print symbol on change or highlight change
if ((old_is_A != is_A) || (old_highlight != dir_highlight)) if ((old_is_A != rot_dir_is_A) || (old_highlight != dir_highlight))
{ {
print_symbol(symbol, OLED_X_SIZE - (CHAR_SIZE + 1) * 2, 0, dir_highlight); print_symbol(symbol, OLED_X_SIZE - (CHAR_SIZE + 1) * 2, 0, dir_highlight);
} }
@ -913,7 +911,7 @@ void print_clear_menu_area()
while (i < count) while (i < count)
{ {
// If remaining bytes is smaller than buffer - send only required number // If remaining bytes is smaller than buffer - send only required number
bytes = count - i < sizeof(data) ? count - i, sizeof(data); bytes = (count - i) < sizeof(data) ? count - i : sizeof(data);
display_send_data(data, bytes); display_send_data(data, bytes);
i += bytes; i += bytes;
} }
@ -1061,12 +1059,13 @@ int16_t find_eeprom_idx()
uint8_t err; uint8_t err;
int16_t idx = 0; int16_t idx = 0;
uint8_t found = 0; uint8_t found = 0;
uint8_t dir;
uint32_t value = 0xFFFFFFFF; uint32_t value = 0xFFFFFFFF;
// FF is the erased byte value // FF is the erased byte value
for (idx = 0; idx < EEPROM_SIZE / EEPROM_IDX_SIZE; ++idx) for (idx = 0; idx < EEPROM_SIZE / EEPROM_IDX_SIZE; ++idx)
{ {
err = read_eeprom_val(idx, &value); err = read_eeprom_val(idx, &value, &dir);
if (0 != err) if (0 != err)
{ {
return -1; return -1;
@ -1136,7 +1135,7 @@ int8_t write_eeprom_val(int8_t idx, uint32_t value, uint8_t direction)
buf[0] = direction; buf[0] = direction;
err = i2c_write_buff(EEPROM_ADDRESS, idx * EEPROM_IDX_SIZE, buf, 4) err = i2c_write_buff(EEPROM_ADDRESS, idx * EEPROM_IDX_SIZE, buf, 4);
if (4 != err) if (4 != err)
{ {
return -1; return -1;
@ -1236,6 +1235,7 @@ int8_t read_battery(int16_t *mAh, int16_t *mV, int16_t *temp)
int8_t i2c_write_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t len) int8_t i2c_write_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t len)
{ {
uint8_t err; uint8_t err;
uint8_t i;
err = i2c_start(i2c_addr | I2C_WRITE); err = i2c_start(i2c_addr | I2C_WRITE);
if (0 != err) if (0 != err)
@ -1251,7 +1251,7 @@ int8_t i2c_write_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t
return -1; return -1;
} }
for (uint8_t i = 0; i < len; ++i) for (i = 0; i < len; ++i)
{ {
err = i2c_write(buf[i]); err = i2c_write(buf[i]);
if (0 != err) if (0 != err)
@ -1268,6 +1268,7 @@ int8_t i2c_write_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t
int8_t i2c_read_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t len) int8_t i2c_read_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t len)
{ {
uint8_t err; uint8_t err;
uint8_t i;
err = i2c_start(i2c_addr | I2C_WRITE); err = i2c_start(i2c_addr | I2C_WRITE);
if (0 != err) if (0 != err)
@ -1290,7 +1291,7 @@ int8_t i2c_read_buff(uint8_t i2c_addr, uint8_t data_addr, uint8_t *buf, uint8_t
return -1; return -1;
} }
for (uint8_t i = 0; i < len; ++i) for (i = 0; i < len; ++i)
{ {
buf[i] = i2c_read(i == len - 1); buf[i] = i2c_read(i == len - 1);
} }
@ -1406,7 +1407,7 @@ void spool_count(uint8_t event)
write_eeprom_val(eeprom_idx, 0xFFFFFFFF, 0xFF); write_eeprom_val(eeprom_idx, 0xFFFFFFFF, 0xFF);
++eeprom_idx; ++eeprom_idx;
eeprom_idx %= EEPROM_SIZE; eeprom_idx %= EEPROM_SIZE;
write_eeprom_val(eeprom_idx, (uint32_t) count_value_fine, move_dir); write_eeprom_val(eeprom_idx, (uint32_t) count_value_fine, rot_dir_is_A);
} }
count_value = (uint32_t) count_value_fine; count_value = (uint32_t) count_value_fine;
} }
@ -1628,7 +1629,7 @@ void process_battery()
// Button Clicked - Update Battery Info // Button Clicked - Update Battery Info
read_battery(&battery_mAh, &battery_mV, &battery_temp); read_battery(&battery_mAh, &battery_mV, &battery_temp);
print_battery_icon(); print_battery_icon();
print_battery_stat(); print_battery_stat(0);
} }
long_press_when_ms = 0xFFFFFFFF; long_press_when_ms = 0xFFFFFFFF;
break; break;
@ -1653,7 +1654,7 @@ void attach_detach_spool()
write_eeprom_val(eeprom_idx, 0xFFFFFFFF, 0xFF); write_eeprom_val(eeprom_idx, 0xFFFFFFFF, 0xFF);
++eeprom_idx; ++eeprom_idx;
eeprom_idx %= EEPROM_SIZE; eeprom_idx %= EEPROM_SIZE;
write_eeprom_val(eeprom_idx, (uint32_t) count_value_fine, move_dir); write_eeprom_val(eeprom_idx, (uint32_t) count_value_fine, rot_dir_is_A);
spool_counting = 0; spool_counting = 0;
spool_attached = 0; spool_attached = 0;
@ -1682,14 +1683,14 @@ void attach_detach_spool()
// New EEPROM // New EEPROM
if (0x00FFFFFF == count_value) if (0x00FFFFFF == count_value)
{ {
is_counting = 0; spool_counting = 0;
count_value = 0; count_value = 0;
count_value_fine = 0; count_value_fine = 0;
rot_dir_is_A = 1; rot_dir_is_A = 1;
} }
else else
{ {
is_counting = 1; spool_counting = 1;
count_value_fine = count_value; count_value_fine = count_value;
} }
spool_attached = 1; spool_attached = 1;