Skip to content

Commit

Permalink
colors
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Sep 24, 2023
1 parent f5b50aa commit e23ad69
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
4 changes: 2 additions & 2 deletions firmware/application/src/app_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/src/rfid/nfctag/hf/nfc_14a.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/src/rfid/nfctag/lf/lf_tag_em.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/src/rfid/reader/hf/mf1_toolbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
11 changes: 8 additions & 3 deletions firmware/application/src/rgb_marquee.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions firmware/common/hw_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
12 changes: 11 additions & 1 deletion firmware/common/hw_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit e23ad69

Please sign in to comment.