Implement LF RFID emulation (#208)

* migrate code from old repo, not work
* fix emulation
* disable irq handling while RFID emulating
* add testcase
This commit is contained in:
coreglitch
2020-10-28 14:38:04 +06:00
committed by GitHub
parent 665f6d7d9c
commit de968b13b4
6 changed files with 130 additions and 3 deletions

View File

@@ -44,10 +44,22 @@ static void input_callback(InputEvent* input_event, void* ctx) {
}
extern TIM_HandleTypeDef htim15;
void em4100_emulation(uint8_t* data, GpioPin* pin);
void prepare_data(uint32_t ID, uint32_t VENDOR, uint8_t* data);
void lf_rfid_workaround(void* p) {
osMessageQueueId_t event_queue = osMessageQueueNew(1, sizeof(AppEvent), NULL);
// create pin
GpioPin pull_pin = {.pin = GPIO_PIN_15, .port = GPIOB};
// TODO open record
GpioPin* pull_pin_record = &pull_pin;
gpio_init(pull_pin_record, GpioModeOutputPushPull);
uint8_t emulation_data[64];
prepare_data(4378151, 01, emulation_data);
State _state;
_state.freq_khz = 125;
_state.on = false;
@@ -73,7 +85,7 @@ void lf_rfid_workaround(void* p) {
AppEvent event;
while(1) {
osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 10000);
osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 100);
State* state = (State*)acquire_mutex_block(&state_mutex);
if(event_status == osOK) {
@@ -81,6 +93,7 @@ void lf_rfid_workaround(void* p) {
// press events
if(event.value.input.state && event.value.input.input == InputBack) {
hal_pwmn_stop(&htim15, TIM_CHANNEL_1); // TODO: move to furiac_onexit
gpio_init(pull_pin_record, GpioModeInput);
// TODO remove all widgets create by app
widget_enabled_set(widget, false);
furiac_exit(NULL);
@@ -111,6 +124,12 @@ void lf_rfid_workaround(void* p) {
hal_pwmn_set(
state->on ? 0.5 : 0.0, (float)(state->freq_khz * 1000), &htim15, TIM_CHANNEL_1);
if(!state->on) {
em4100_emulation(emulation_data, pull_pin_record);
} else {
gpio_write(pull_pin_record, false);
}
// common code, for example, force update UI
widget_update(widget);