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