Skip to content

Commit

Permalink
fix card emulator default card
Browse files Browse the repository at this point in the history
  • Loading branch information
solosky committed Aug 25, 2024
1 parent 00a6adc commit ed61ce8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 4 additions & 1 deletion fw/application/src/app/chameleon/app_chameleon.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ void app_chameleon_on_kill(mini_app_inst_t *p_app_inst) {
p_retain->cycle_mode_index = chameleon_view_get_index(p_app_handle->p_chameleon_view);

settings_data_t *settings = settings_get_data();
if (tag_helper_valid_default_slot()) {
if (tag_helper_valid_default_slot() &&
tag_emulation_slot_is_enabled(settings->chameleon_default_slot_index, TAG_SENSE_HF)) {
tag_emulation_change_slot(settings->chameleon_default_slot_index, false);
} else {
settings->chameleon_default_slot_index = INVALID_SLOT_INDEX;
}

tag_emulation_save();
Expand Down
3 changes: 1 addition & 2 deletions fw/application/src/app/chameleon/port/tag_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,5 @@ bool tag_helper_is_defult_slot() {

bool tag_helper_valid_default_slot(){
settings_data_t *settings = settings_get_data();
return settings->chameleon_default_slot_index != INVALID_SLOT_INDEX
&& tag_emulation_slot_is_enabled(settings->chameleon_default_slot_index, TAG_SENSE_HF);
return settings->chameleon_default_slot_index != INVALID_SLOT_INDEX;
}
27 changes: 18 additions & 9 deletions fw/application/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
#include "hal_spi_bus.h"
#include "hal_spi_flash.h"

#include "tag_helper.h"

#include "cache.h"
#include "i18n/language.h"
#include "settings.h"
Expand Down Expand Up @@ -195,11 +197,23 @@ static uint32_t check_wakeup_src(void) {
uint32_t rr = nrf_power_resetreas_get();
NRF_LOG_INFO("nrf_power_resetreas_get: 0x%04x", rr);

if (cache_valid()) {
cache_data_t *p_cache = cache_get_data();
ntag_emu_set_tag(&(p_cache->ntag));
// 如果卡模拟器设置了默认卡,这里就不开启模拟NTAG
if (tag_helper_valid_default_slot() && (rr & NRF_POWER_RESETREAS_NFC_MASK)) {
tag_emulation_init();
hal_nfc_set_nrfx_irq_enable(true);
tag_emulation_sense_run();
} else {
cache_clean();

extern const ntag_t default_ntag215;
ret_code_t err_code = ntag_emu_init(&default_ntag215);
APP_ERROR_CHECK(err_code);

if (cache_valid()) {
cache_data_t *p_cache = cache_get_data();
ntag_emu_set_tag(&(p_cache->ntag));
} else {
cache_clean();
}
}

if (rr == 0) {
Expand Down Expand Up @@ -255,12 +269,7 @@ int main(void) {
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);

extern const ntag_t default_ntag215;
err_code = ntag_emu_init(&default_ntag215);
APP_ERROR_CHECK(err_code);

// cache_clean(); //FOR TESTING


err_code = settings_init();
// we ignore error here, cause flash may not be presented or settings.bin did not exist
Expand Down

0 comments on commit ed61ce8

Please sign in to comment.