From e23ad695e6703f673469190861e6b8f12076a8ff Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 24 Sep 2023 23:21:59 +0200 Subject: [PATCH] colors --- firmware/application/src/app_cmd.c | 4 +-- firmware/application/src/app_main.c | 2 +- .../application/src/rfid/nfctag/hf/nfc_14a.c | 4 +-- .../src/rfid/nfctag/lf/lf_tag_em.c | 2 +- .../src/rfid/reader/hf/mf1_toolbox.c | 2 +- firmware/application/src/rgb_marquee.c | 11 +++++--- firmware/common/hw_connect.c | 26 +++++++++++++++---- firmware/common/hw_connect.h | 12 ++++++++- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index 42b0b67b..745b6b32 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -28,7 +28,7 @@ static void change_slot_auto(uint8_t slot) { device_mode_t mode = get_device_mode(); tag_emulation_change_slot(slot, mode != DEVICE_MODE_READER); light_up_by_slot(); - set_slot_light_color(0); + set_slot_light_color(RGB_RED); } @@ -557,7 +557,7 @@ static data_frame_tx_t *cmd_processor_set_slot_enable(uint16_t cmd, uint16_t sta uint8_t slot_prev = tag_emulation_slot_find_next(slot_now); NRF_LOG_INFO("slot_now = %d, slot_prev = %d", slot_now, slot_prev); if (slot_prev == slot_now) { - set_slot_light_color(3); + set_slot_light_color(RGB_MAGENTA); } else { change_slot_auto(slot_prev); } diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index 7380759c..a6eeab14 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -250,7 +250,7 @@ static void system_off_enter(void) { if (g_is_low_battery_shutdown) { // Don't create too complex animations, just blink LED1 three times. rgb_marquee_stop(); - set_slot_light_color(0); + set_slot_light_color(RGB_RED); for (uint8_t i = 0; i <= 3; i++) { nrf_gpio_pin_set(LED_1); bsp_delay_ms(100); diff --git a/firmware/application/src/rfid/nfctag/hf/nfc_14a.c b/firmware/application/src/rfid/nfctag/hf/nfc_14a.c index 40cc6439..6e01c9aa 100644 --- a/firmware/application/src/rfid/nfctag/hf/nfc_14a.c +++ b/firmware/application/src/rfid/nfctag/hf/nfc_14a.c @@ -617,7 +617,7 @@ void nfc_tag_14a_event_callback(nrfx_nfct_evt_t const *p_event) { g_is_tag_emulating = true; g_usb_led_marquee_enable = false; - set_slot_light_color(1); + set_slot_light_color(RGB_GREEN); TAG_FIELD_LED_ON() NRF_LOG_INFO("HF FIELD DETECTED"); @@ -661,7 +661,7 @@ void nfc_tag_14a_event_callback(nrfx_nfct_evt_t const *p_event) { break; } case NRFX_NFCT_EVT_RX_FRAMEEND: { - set_slot_light_color(1); + set_slot_light_color(RGB_GREEN); TAG_FIELD_LED_ON() // NRF_LOG_INFO("RX FRAMEEND.\n"); diff --git a/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c b/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c index ef90e7dd..9d480557 100644 --- a/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c +++ b/firmware/application/src/rfid/nfctag/lf/lf_tag_em.c @@ -299,7 +299,7 @@ static void lpcomp_event_handler(nrf_lpcomp_event_t event) { g_usb_led_marquee_enable = false; // LED status update - set_slot_light_color(2); + set_slot_light_color(RGB_BLUE); TAG_FIELD_LED_ON() //In any case, every time the state finds changes, you need to reset the BIT location of the sending diff --git a/firmware/application/src/rfid/reader/hf/mf1_toolbox.c b/firmware/application/src/rfid/reader/hf/mf1_toolbox.c index e8906345..98858b8f 100644 --- a/firmware/application/src/rfid/reader/hf/mf1_toolbox.c +++ b/firmware/application/src/rfid/reader/hf/mf1_toolbox.c @@ -382,7 +382,7 @@ uint8_t darkside_recover_key(uint8_t targetBlk, uint8_t targetTyp, // Verification instructions need to add CRC16 crc_14a_append(tag_auth, 2); rgb_marquee_stop(); - set_slot_light_color(1); + set_slot_light_color(RGB_GREEN); uint32_t *led_pins = hw_get_led_array(); for (uint8_t i = 0; i < RGB_LIST_NUM; i++) { nrf_gpio_pin_clear(led_pins[i]); diff --git a/firmware/application/src/rgb_marquee.c b/firmware/application/src/rgb_marquee.c index f4aece9a..3a5d259f 100644 --- a/firmware/application/src/rgb_marquee.c +++ b/firmware/application/src/rgb_marquee.c @@ -33,6 +33,7 @@ nrf_drv_pwm_config_t pwm_config = {//PWM configuration structure }; static autotimer *timer; static uint8_t ledblink6_step = 0; +static uint8_t ledblink6_color = RGB_RED; static uint8_t ledblink1_step = 0; extern bool g_usb_led_marquee_enable; @@ -392,7 +393,7 @@ void ledblink6(void) { } if (ledblink6_step == 0) { - set_slot_light_color(0); + set_slot_light_color(ledblink6_color); for (uint8_t i = 0; i < RGB_LIST_NUM; i++) { nrf_gpio_pin_clear(led_array[i]); } @@ -420,7 +421,7 @@ void ledblink6(void) { pwm_sequ_val.channel_2 = pwm_sequ_val.channel_0; pwm_sequ_val.channel_3 = pwm_sequ_val.channel_0; nrfx_pwm_uninit(&pwm0_ins); //Close PWM output - set_slot_light_color(1); + set_slot_light_color(ledblink6_color); nrf_drv_pwm_init(&pwm0_ins, &pwm_config, ledblink6_pwm_callback); nrf_drv_pwm_simple_playback(&pwm0_ins, &seq, 1, NRF_DRV_PWM_FLAG_LOOP); ledblink6_step = 3; @@ -457,7 +458,7 @@ void ledblink6(void) { pwm_sequ_val.channel_2 = pwm_sequ_val.channel_0; pwm_sequ_val.channel_3 = pwm_sequ_val.channel_0; nrfx_pwm_uninit(&pwm0_ins); //Close PWM output - set_slot_light_color(1); + set_slot_light_color(ledblink6_color); nrf_drv_pwm_init(&pwm0_ins, &pwm_config, ledblink6_pwm_callback); nrf_drv_pwm_simple_playback(&pwm0_ins, &seq, 1, NRF_DRV_PWM_FLAG_LOOP); ledblink6_step = 7; @@ -477,6 +478,10 @@ void ledblink6(void) { } } else { ledblink6_step = 0; + //if (++ledblink6_color == RGB_WHITE) ledblink6_color = RGB_RED; + uint8_t new_color=rand()%6; + for (; new_color == ledblink6_color; new_color=rand()%6); + ledblink6_color = new_color; } } } diff --git a/firmware/common/hw_connect.c b/firmware/common/hw_connect.c index 7d2d59e4..a4249c51 100644 --- a/firmware/common/hw_connect.c +++ b/firmware/common/hw_connect.c @@ -238,20 +238,36 @@ void init_leds(void) { * @brief Function for enter tag emulation mode * @param color: 0 means r, 1 means g, 2 means b */ -void set_slot_light_color(uint8_t color) { +void set_slot_light_color(chameleon_rgb_type_t color) { nrf_gpio_pin_set(LED_R); nrf_gpio_pin_set(LED_G); nrf_gpio_pin_set(LED_B); switch (color) { - case 0: + case RGB_RED: nrf_gpio_pin_clear(LED_R); break; - case 1: + case RGB_GREEN: nrf_gpio_pin_clear(LED_G); break; - case 2: + case RGB_BLUE: + nrf_gpio_pin_clear(LED_B); + break; + case RGB_MAGENTA: + nrf_gpio_pin_clear(LED_B); + nrf_gpio_pin_clear(LED_R); + break; + case RGB_YELLOW: + nrf_gpio_pin_clear(LED_R); + nrf_gpio_pin_clear(LED_G); + break; + case RGB_CYAN: + nrf_gpio_pin_clear(LED_G); + nrf_gpio_pin_clear(LED_B); + break; + case RGB_WHITE: + nrf_gpio_pin_clear(LED_R); + nrf_gpio_pin_clear(LED_G); nrf_gpio_pin_clear(LED_B); break; } - } diff --git a/firmware/common/hw_connect.h b/firmware/common/hw_connect.h index 92aa64b5..8e1b6b6f 100644 --- a/firmware/common/hw_connect.h +++ b/firmware/common/hw_connect.h @@ -13,6 +13,16 @@ typedef enum { CHAMELEON_LITE, } chameleon_device_type_t; +typedef enum { + RGB_RED, + RGB_GREEN, + RGB_BLUE, + RGB_MAGENTA, + RGB_YELLOW, + RGB_CYAN, + RGB_WHITE +} chameleon_rgb_type_t; + #define MAX_LED_NUM 8 #define MAX_RGB_NUM 3 @@ -97,7 +107,7 @@ uint32_t *hw_get_led_reversal_array(void); uint32_t *hw_get_rgb_array(void); chameleon_device_type_t hw_get_device_type(void); uint8_t hw_get_version_code(void); -void set_slot_light_color(uint8_t color); +void set_slot_light_color(chameleon_rgb_type_t color); #endif