Loading projects/step-up/Makefile +1 −1 Original line number Diff line number Diff line PROGRAM=lights SRC=main.c logging.c pwm.c adc.c pwmled.c pattern.c buttons.c control.c \ battery.c battery.c wdt.c OBJ=$(SRC:.c=.o) Loading projects/step-up/adc.c +1 −22 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ #define NUM_ADCS 2 volatile static unsigned char current_adc;; static unsigned char need_battery_adc; volatile unsigned char need_battery_adc; static uint16_t adc_sum, read_zero, drop_count, read_count, n_reads_log; volatile uint16_t jiffies; Loading Loading @@ -126,30 +126,9 @@ void susp_adc() DIDR0 = 0; } static void inline adc_based_timer() { static unsigned char count; if (++count < 40) // about 100 Hz jiffies return; count = 0; ++jiffies; if ((jiffies & 0x007F) == 1) { // about every 1s need_battery_adc = 1; } if ((jiffies & 0x0007) == 0) { patterns_next_tick(); } timer_check_buttons(); } ISR(ADC_vect) { // IRQ handler uint16_t adcval = ADCW; adc_based_timer(); if (read_zero) { setup_mux(current_adc); read_zero = 0; Loading projects/step-up/buttons.c +4 −4 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ #include "lights.h" #define WAKEUP_LIMIT 5 // times 100 ms #define SHORT_PRESS_MIN 10 // in jiffies (100 Hz ticks) #define SHORT_PRESS_MAX 50 #define LONG_PRESS_MIN 100 #define SHORT_PRESS_MIN 2 // in jiffies (16 Hz ticks) #define SHORT_PRESS_MAX 5 #define LONG_PRESS_MIN 10 static uint16_t button_start; static unsigned char prev_state; Loading Loading @@ -67,7 +67,7 @@ void timer_check_buttons() } else if (!cur && prev) { // --- just released --- uint16_t duration = jiffies - button_start; if (duration > SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) { if (duration >= SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) { short_press(); } else if (duration > LONG_PRESS_MIN) { // set_status_led(button, NULL); Loading projects/step-up/lights.h +8 −1 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ void inline log_word(uint16_t word) { } /* adc.c */ #define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */ extern volatile uint16_t jiffies; extern volatile unsigned char need_battery_adc; extern volatile unsigned char adc_running; void init_adc(); void susp_adc(); /* pwm.c */ #define PWM_MAX 0xFF extern volatile unsigned char pwm_running; void init_pwm(); void susp_pwm(); void pwm_off(); Loading Loading @@ -75,6 +77,11 @@ pattern_t *status_led_pattern_select(); #define ERR_PWMLED 2 void set_error(unsigned char err); /* wdt.c */ extern volatile uint16_t jiffies; void init_wdt(); void susp_wdt(); /* main.c */ void power_down(); Loading projects/step-up/main.c +15 −5 Original line number Diff line number Diff line Loading @@ -11,11 +11,10 @@ static void hw_setup() { power_all_disable(); wdt_enable(WDTO_1S); init_battery(); init_pwm(); init_adc(); init_wdt(); init_buttons(); Loading @@ -30,9 +29,10 @@ static void hw_suspend() { susp_pwm(); susp_adc(); susp_wdt(); susp_buttons(); wdt_disable(); power_all_disable(); } Loading Loading @@ -71,8 +71,18 @@ int main(void) sei(); #if 1 while (1) { wdt_reset(); sleep_mode(); cli(); if (pwm_running) { set_sleep_mode(SLEEP_MODE_IDLE); } else if (adc_running) { set_sleep_mode(SLEEP_MODE_ADC); } else { set_sleep_mode(SLEEP_MODE_PWR_DOWN); } // keep BOD active, no sleep_bod_disable(); sei(); sleep_cpu(); sleep_disable(); } #endif Loading Loading
projects/step-up/Makefile +1 −1 Original line number Diff line number Diff line PROGRAM=lights SRC=main.c logging.c pwm.c adc.c pwmled.c pattern.c buttons.c control.c \ battery.c battery.c wdt.c OBJ=$(SRC:.c=.o) Loading
projects/step-up/adc.c +1 −22 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ #define NUM_ADCS 2 volatile static unsigned char current_adc;; static unsigned char need_battery_adc; volatile unsigned char need_battery_adc; static uint16_t adc_sum, read_zero, drop_count, read_count, n_reads_log; volatile uint16_t jiffies; Loading Loading @@ -126,30 +126,9 @@ void susp_adc() DIDR0 = 0; } static void inline adc_based_timer() { static unsigned char count; if (++count < 40) // about 100 Hz jiffies return; count = 0; ++jiffies; if ((jiffies & 0x007F) == 1) { // about every 1s need_battery_adc = 1; } if ((jiffies & 0x0007) == 0) { patterns_next_tick(); } timer_check_buttons(); } ISR(ADC_vect) { // IRQ handler uint16_t adcval = ADCW; adc_based_timer(); if (read_zero) { setup_mux(current_adc); read_zero = 0; Loading
projects/step-up/buttons.c +4 −4 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ #include "lights.h" #define WAKEUP_LIMIT 5 // times 100 ms #define SHORT_PRESS_MIN 10 // in jiffies (100 Hz ticks) #define SHORT_PRESS_MAX 50 #define LONG_PRESS_MIN 100 #define SHORT_PRESS_MIN 2 // in jiffies (16 Hz ticks) #define SHORT_PRESS_MAX 5 #define LONG_PRESS_MIN 10 static uint16_t button_start; static unsigned char prev_state; Loading Loading @@ -67,7 +67,7 @@ void timer_check_buttons() } else if (!cur && prev) { // --- just released --- uint16_t duration = jiffies - button_start; if (duration > SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) { if (duration >= SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) { short_press(); } else if (duration > LONG_PRESS_MIN) { // set_status_led(button, NULL); Loading
projects/step-up/lights.h +8 −1 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ void inline log_word(uint16_t word) { } /* adc.c */ #define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */ extern volatile uint16_t jiffies; extern volatile unsigned char need_battery_adc; extern volatile unsigned char adc_running; void init_adc(); void susp_adc(); /* pwm.c */ #define PWM_MAX 0xFF extern volatile unsigned char pwm_running; void init_pwm(); void susp_pwm(); void pwm_off(); Loading Loading @@ -75,6 +77,11 @@ pattern_t *status_led_pattern_select(); #define ERR_PWMLED 2 void set_error(unsigned char err); /* wdt.c */ extern volatile uint16_t jiffies; void init_wdt(); void susp_wdt(); /* main.c */ void power_down(); Loading
projects/step-up/main.c +15 −5 Original line number Diff line number Diff line Loading @@ -11,11 +11,10 @@ static void hw_setup() { power_all_disable(); wdt_enable(WDTO_1S); init_battery(); init_pwm(); init_adc(); init_wdt(); init_buttons(); Loading @@ -30,9 +29,10 @@ static void hw_suspend() { susp_pwm(); susp_adc(); susp_wdt(); susp_buttons(); wdt_disable(); power_all_disable(); } Loading Loading @@ -71,8 +71,18 @@ int main(void) sei(); #if 1 while (1) { wdt_reset(); sleep_mode(); cli(); if (pwm_running) { set_sleep_mode(SLEEP_MODE_IDLE); } else if (adc_running) { set_sleep_mode(SLEEP_MODE_ADC); } else { set_sleep_mode(SLEEP_MODE_PWR_DOWN); } // keep BOD active, no sleep_bod_disable(); sei(); sleep_cpu(); sleep_disable(); } #endif Loading