save color when going to sleep
This commit is contained in:
parent
ad3b844978
commit
9696a136f2
18
main.c
18
main.c
|
@ -490,7 +490,25 @@ void main(void)
|
|||
led_red(0); // ensure LED is off
|
||||
led_green(0); // ensure LED is off
|
||||
led_blue(0); // ensure LED is off
|
||||
// save color
|
||||
if (rgb[0] != *(uint8_t*)(EEPROM_ADDR + 0) || rgb[1] != *(uint8_t*)(EEPROM_ADDR + 1) || rgb[2] != *(uint8_t*)(EEPROM_ADDR + 2)) {
|
||||
// disable DATA (e.g. EEPROM) write protection
|
||||
if (0 == (FLASH_IAPSR & FLASH_IAPSR_DUL)) {
|
||||
FLASH_DUKR = FLASH_DUKR_KEY1;
|
||||
FLASH_DUKR = FLASH_DUKR_KEY2;
|
||||
}
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
*(uint8_t*)(EEPROM_ADDR + i) = rgb[i];
|
||||
while (!(FLASH_IAPSR & FLASH_IAPSR_EOP)); // wait until programming is complete
|
||||
}
|
||||
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
|
||||
}
|
||||
puts("rest\r\n\n");
|
||||
halt();
|
||||
IRM_ON_PORT->ODR.reg |= IRM_ON_PIN; // switch IR demodulator on
|
||||
led_rgb(rgb); // set color
|
||||
time_shake = 0; // reset stay awake time
|
||||
time_count = 0; // reset counter
|
||||
}
|
||||
if (uart_c) { // data received over UART
|
||||
putc(uart_c); // echo back
|
||||
|
|
Loading…
Reference in New Issue