diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-08-04 21:32:41 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-08-04 21:32:41 +0800 |
| commit | ea5ee8733396adf1443210a73911c6a42f5f162a (patch) | |
| tree | 1ac99bf128631c721543d373aca348dad5b2e467 | |
| parent | 26d04ee4de6c0306120c5ee1616c3e51f51328f6 (diff) | |
| download | fpm-door-lock-ea5ee8733396adf1443210a73911c6a42f5f162a.tar.gz | |
More fine-grained pwr controls.
| -rw-r--r-- | main.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -53,16 +53,30 @@ enum CTRL { static volatile enum CTRL cmd = NONE; +static inline void pwron(uint8_t port) +{ + PWR_PORT |= (1 << port); +} + +static inline void pwroff(uint8_t port) +{ + PWR_PORT &= ~(1 << port); +} + static inline void lock(void) { + pwron(PWR_SERVO); OCR1A = PWM_MID; _delay_ms(500); + pwroff(PWR_SERVO); } static inline void unlock(void) { + pwron(PWR_SERVO); OCR1A = PWM_MAX; _delay_ms(500); + pwroff(PWR_SERVO); } static inline void flash_led(void) @@ -75,16 +89,6 @@ static inline void flash_led(void) } } -static inline void pwr_fpm_servo_on(void) -{ - PWR_PORT |= (1 << PWR_FPM) | (1 << PWR_SERVO); -} - -static inline void pwr_fpm_servo_off(void) -{ - PWR_PORT &= ~((1 << PWR_FPM) | (1 << PWR_SERVO)); -} - int main(void) { uint16_t id; @@ -97,10 +101,9 @@ int main(void) WDTCSR = 0x00; uart_init(); - - /* power on the FPM and the servo */ PWR_DDR |= (1 << PWR_FPM) | (1 << PWR_SERVO); - pwr_fpm_servo_on(); + pwron(PWR_FPM); + fpm_init(); /* servo */ TCCR1A |= (1 << WGM11); @@ -171,15 +174,17 @@ int main(void) cmd = NONE; _delay_ms(500); - pwr_fpm_servo_off(); + pwroff(PWR_FPM); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sleep_bod_disable(); sei(); sleep_cpu(); + cli(); sleep_disable(); - pwr_fpm_servo_on(); + pwron(PWR_FPM); + fpm_init(); } return 0; |
