read color from EEPROM

This commit is contained in:
King Kévin 2022-10-13 16:02:33 +02:00
parent 7121f8b541
commit eaa3447fad
1 changed files with 22 additions and 13 deletions

35
main.c
View File

@ -12,6 +12,9 @@
// enable UART debug
#define DEBUG 1
// EEPROM start address
#define EEPROM_ADDR 0x4000
// pinout
// pin to power IR demodulator (source on)
#define IRM_ON_PIN PA3
@ -355,6 +358,13 @@ void main(void)
TIM2->EGR.fields.UG = 1; // transfer all registers
TIM2->CR1.fields.CEN = 1; // enable counter to start PWM
// load color
uint8_t rgb[3]; // eyes color
rgb[0] = *(uint8_t*)(EEPROM_ADDR + 0); // load red color
rgb[1] = *(uint8_t*)(EEPROM_ADDR + 1); // load green color
rgb[2] = *(uint8_t*)(EEPROM_ADDR + 2); // load blue color
led_rgb(rgb); // set color
// configure UV LED
LED_UV_PORT->ODR.reg &= ~LED_UV_PIN; // switch LED off
LED_UV_PORT->CR1.reg |= LED_UV_PIN; // use as push-pull
@ -399,7 +409,6 @@ void main(void)
rim(); // re-enable interrupts
bool action = false; // if an action has been performed
led_green(0x0100); // indicate we are ready
puts("\r\nready\r\n");
while (true) {
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
@ -417,24 +426,24 @@ void main(void)
puts("\r\n");
if (0x80 == nec_msg[0] && 0x7f == nec_msg[1]) { // radio remote
if (0x04 == nec_msg[2] && 0xfb == nec_msg[3]) { // 1
led_red(0x8000);
led_green(0);
led_blue(0);
rgb[0] = 0x80;
rgb[1] = 0;
rgb[2] = 0;
} else if (0x05 == nec_msg[2] && 0xfa == nec_msg[3]) { // 2
led_red(0);
led_green(0x8000);
led_blue(0);
rgb[0] = 0;
rgb[1] = 0x80;
rgb[2] = 0;
} else if (0x06 == nec_msg[2] && 0xf9 == nec_msg[3]) { // 3
led_red(0);
led_green(0);
led_blue(0x8000);
rgb[0] = 0;
rgb[1] = 0;
rgb[2] = 0x80;
} else if (0x01 == nec_msg[2] && 0xfe == nec_msg[3]) { // mute
LED_UV_PORT->ODR.reg |= LED_UV_PIN; // switch UV LED on
} else if (0x12 == nec_msg[2] && 0xed == nec_msg[3]) { // power
LED_UV_PORT->ODR.reg &= ~LED_UV_PIN; // switch UV LED off
led_red(0);
led_green(0);
led_blue(0);
rgb[0] = 0;
rgb[1] = 0;
rgb[2] = 0;
}
}
nec_flag = false; // clear flag