diff --git a/firmware/debounce.c b/firmware/debounce.c index deb269c..c8dda3f 100644 --- a/firmware/debounce.c +++ b/firmware/debounce.c @@ -15,27 +15,27 @@ void SuperDebounce(uint8_t * key_state, volatile uint8_t *KPIN, if( key_press && !*key_state ) { *key_state = debounce; - timers[TIM_DEBOUNCE] = 15; + tim_debounce = 15; } else if( *key_state ) { - if( key_press && debounce==*key_state && !timers[TIM_DEBOUNCE] ) { + if( key_press && debounce==*key_state && !tim_debounce ) { *key_state = 2; - timers[TIM_DEBOUNCE]=5; + tim_debounce=5; } else if( !key_press && *key_state>1 && *key_state<4 ) { if(push_proc) push_proc(); /* KEY_UP */ *key_state=idle; } else - if( key_press && go_rep==*key_state && !timers[TIM_DEBOUNCE] ) { + if( key_press && go_rep==*key_state && !tim_debounce ) { *key_state = wait_rep; - timers[TIM_DEBOUNCE]=rep_wait; + tim_debounce=rep_wait; } else - if( key_press && wait_rep==*key_state && !timers[TIM_DEBOUNCE] ) { + if( key_press && wait_rep==*key_state && !tim_debounce ) { *key_state = rep; } else - if( key_press && rep==*key_state && !timers[TIM_DEBOUNCE] ) { - timers[TIM_DEBOUNCE] = rep_time; + if( key_press && rep==*key_state && !tim_debounce ) { + tim_debounce = rep_time; if(rep_proc) rep_proc(); /* KEY_REP */ } } diff --git a/firmware/i2c.c b/firmware/i2c.c index 30cc81a..aa53448 100644 --- a/firmware/i2c.c +++ b/firmware/i2c.c @@ -3,9 +3,9 @@ void i2c_init(uint32_t bitrate) { - uint8_t prescaler_options[] = {1, 4, 16, 64}; - uint8_t prescaler_value = prescaler_options[TWSR & 0x03]; // 0x03 (hex) = 0b00000011 (bin) - TWBR = (uint8_t)((F_CPU / bitrate - 16) / (2 * prescaler_value)); + uint8_t prescaler_options[] = {1, 4, 16, 64}; + uint8_t prescaler_value = prescaler_options[TWSR & 0x03]; // 0x03 (hex) = 0b00000011 (bin) + TWBR = (uint8_t)((F_CPU / bitrate - 16) / (2 * prescaler_value)); } void i2c_start(void) @@ -41,7 +41,9 @@ void i2c_readbuf(uint8_t sla, uint8_t adr, uint8_t len, uint8_t* buf) i2c_write(adr); i2c_start(); i2c_write(sla + I2C_READ); + while(len--) *buf++ = i2c_read(len ? I2C_ACK : I2C_NACK); + i2c_stop(); } @@ -51,10 +53,7 @@ void i2c_writebuf(uint8_t sla, uint8_t adr, uint8_t len, uint8_t* buf) i2c_write(sla); i2c_write(adr); - while (len--) - { - i2c_write(*buf++); - } + while (len--) i2c_write(*buf++); i2c_stop(); } \ No newline at end of file diff --git a/firmware/keyboard.c b/firmware/keyboard.c index c4fcf3d..d8e6b3e 100644 --- a/firmware/keyboard.c +++ b/firmware/keyboard.c @@ -40,8 +40,8 @@ void keyboard_init(void) void keyboard_handle_input(void) { - SuperDebounce(&k_inc_hour, &KEYBOARD_PIN, KEY_INC_HOUR, 20, 500, &inc_hour, &inc_hour); - SuperDebounce(&k_inc_minute, &KEYBOARD_PIN, KEY_INC_MINUTE, 20, 500, &inc_minute, &inc_minute); - SuperDebounce(&k_inc_second, &KEYBOARD_PIN, KEY_INC_SECOND, 20, 500, &inc_second, &inc_second); - SuperDebounce(&k_inc_brightness, &KEYBOARD_PIN, KEY_INC_BRIGHTNESS, 20, 500, &inc_brightness, &inc_brightness); + SuperDebounce(&k_inc_hour, &KEYBOARD_PIN, KEY_INC_HOUR, 20, 0, &inc_hour, 0); + SuperDebounce(&k_inc_minute, &KEYBOARD_PIN, KEY_INC_MINUTE, 20, 0, &inc_minute, 0); + SuperDebounce(&k_inc_second, &KEYBOARD_PIN, KEY_INC_SECOND, 20, 0, &inc_second, 0); + SuperDebounce(&k_inc_brightness, &KEYBOARD_PIN, KEY_INC_BRIGHTNESS, 20, 0, &inc_brightness, 0); } \ No newline at end of file diff --git a/firmware/led.c b/firmware/led.c index 61427de..45cbe35 100644 --- a/firmware/led.c +++ b/firmware/led.c @@ -16,12 +16,12 @@ void led_init(void) // Clear LEDs ANODES_PORT = HOUR_ANODE | MINUTE_ANODE | SECOND_ANODE; LED_PORT |= 0x3F; // 0b00111111 - + TCCR0 |= (1<= pwm_counter ? ~HOUR_ANODE : 0xFF; - break; - case 2: - LED_PORT = ~led_minute; - ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~MINUTE_ANODE : 0xFF; - break; - case 4: - LED_PORT = ~led_second; - ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~SECOND_ANODE : 0xFF; - break; - } + { + case 1: + LED_PORT = ~led_hour; + ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~HOUR_ANODE : 0xFF; + break; + case 2: + LED_PORT = ~led_minute; + ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~MINUTE_ANODE : 0xFF; + break; + case 4: + LED_PORT = ~led_second; + ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~SECOND_ANODE : 0xFF; + break; + } + // 31.25 kHz / 250 = 125 Hz if(!counter) { curr_anode <<= 1; diff --git a/firmware/main.c b/firmware/main.c index abc99af..6e796ba 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -32,7 +32,7 @@ int main() ISR(INT0_vect) { - struct time curr_time = rtc_read_time(); + struct TIME curr_time = rtc_read_time(); led_hour = curr_time.hour; led_minute = curr_time.minute; led_second = curr_time.second; diff --git a/firmware/ptimer.c b/firmware/ptimer.c index f3b4e70..da76bae 100644 --- a/firmware/ptimer.c +++ b/firmware/ptimer.c @@ -2,22 +2,20 @@ #include #include "ptimer.h" -volatile uint16_t timers[TIMERS_COUNT]; +volatile uint16_t tim_debounce; void ptimer_init(void) { - for(uint8_t i=0; i> 4) & 0x0F) * 10) + ((bcd) & 0x0F)) -struct time +struct TIME { uint8_t hour; uint8_t minute; @@ -28,6 +28,6 @@ struct time void rtc_int0_init(void); void rtc_int1_init(void); void rtc_set_time(uint8_t part, uint8_t value); -struct time rtc_read_time(void); +struct TIME rtc_read_time(void); #endif \ No newline at end of file