2022-03-29 13:01:56 +00:00
|
|
|
#include "ibutton_worker_i.h"
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
#include <core/check.h>
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
#include <furi_hal_rfid.h>
|
|
|
|
#include <furi_hal_power.h>
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
#include "ibutton_protocols.h"
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
static void ibutton_worker_mode_idle_start(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_idle_tick(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_idle_stop(iButtonWorker* worker);
|
|
|
|
|
|
|
|
static void ibutton_worker_mode_emulate_start(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_emulate_tick(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_emulate_stop(iButtonWorker* worker);
|
|
|
|
|
|
|
|
static void ibutton_worker_mode_read_start(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_read_tick(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_read_stop(iButtonWorker* worker);
|
|
|
|
|
|
|
|
static void ibutton_worker_mode_write_common_start(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_write_blank_tick(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_write_copy_tick(iButtonWorker* worker);
|
|
|
|
static void ibutton_worker_mode_write_common_stop(iButtonWorker* worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
const iButtonWorkerModeType ibutton_worker_modes[] = {
|
|
|
|
{
|
2022-07-20 10:56:33 +00:00
|
|
|
.quant = FuriWaitForever,
|
2022-03-29 13:01:56 +00:00
|
|
|
.start = ibutton_worker_mode_idle_start,
|
|
|
|
.tick = ibutton_worker_mode_idle_tick,
|
|
|
|
.stop = ibutton_worker_mode_idle_stop,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.quant = 100,
|
|
|
|
.start = ibutton_worker_mode_read_start,
|
|
|
|
.tick = ibutton_worker_mode_read_tick,
|
|
|
|
.stop = ibutton_worker_mode_read_stop,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.quant = 1000,
|
2023-03-02 13:23:33 +00:00
|
|
|
.start = ibutton_worker_mode_write_common_start,
|
|
|
|
.tick = ibutton_worker_mode_write_blank_tick,
|
|
|
|
.stop = ibutton_worker_mode_write_common_stop,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.quant = 1000,
|
|
|
|
.start = ibutton_worker_mode_write_common_start,
|
|
|
|
.tick = ibutton_worker_mode_write_copy_tick,
|
|
|
|
.stop = ibutton_worker_mode_write_common_stop,
|
2022-03-29 13:01:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.quant = 1000,
|
|
|
|
.start = ibutton_worker_mode_emulate_start,
|
|
|
|
.tick = ibutton_worker_mode_emulate_tick,
|
|
|
|
.stop = ibutton_worker_mode_emulate_stop,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*********************** IDLE ***********************/
|
|
|
|
|
|
|
|
void ibutton_worker_mode_idle_start(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_idle_tick(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_idle_stop(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** READ ***********************/
|
|
|
|
|
|
|
|
void ibutton_worker_mode_read_start(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
furi_hal_power_enable_otg();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_read_tick(iButtonWorker* worker) {
|
2023-03-02 13:23:33 +00:00
|
|
|
if(ibutton_protocols_read(worker->protocols, worker->key)) {
|
2022-03-29 13:01:56 +00:00
|
|
|
if(worker->read_cb != NULL) {
|
|
|
|
worker->read_cb(worker->cb_ctx);
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
ibutton_worker_switch_mode(worker, iButtonWorkerModeIdle);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_read_stop(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
furi_hal_power_disable_otg();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** EMULATE ***********************/
|
|
|
|
|
|
|
|
void ibutton_worker_mode_emulate_start(iButtonWorker* worker) {
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_assert(worker->key);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
furi_hal_rfid_pins_reset();
|
|
|
|
furi_hal_rfid_pin_pull_pulldown();
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
ibutton_protocols_emulate_start(worker->protocols, worker->key);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_emulate_tick(iButtonWorker* worker) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_worker_mode_emulate_stop(iButtonWorker* worker) {
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_assert(worker->key);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
ibutton_protocols_emulate_stop(worker->protocols, worker->key);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_hal_rfid_pins_reset();
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** WRITE ***********************/
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_worker_mode_write_common_start(iButtonWorker* worker) { //-V524
|
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
furi_hal_power_enable_otg();
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_worker_mode_write_blank_tick(iButtonWorker* worker) {
|
|
|
|
furi_assert(worker->key);
|
|
|
|
|
|
|
|
const bool success = ibutton_protocols_write_blank(worker->protocols, worker->key);
|
2023-08-22 17:56:27 +00:00
|
|
|
// TODO FL-3527: pass a proper result to the callback
|
2023-03-02 13:23:33 +00:00
|
|
|
const iButtonWorkerWriteResult result = success ? iButtonWorkerWriteOK :
|
|
|
|
iButtonWorkerWriteNoDetect;
|
|
|
|
if(worker->write_cb != NULL) {
|
|
|
|
worker->write_cb(worker->cb_ctx, result);
|
2022-03-29 13:01:56 +00:00
|
|
|
}
|
2023-03-02 13:23:33 +00:00
|
|
|
}
|
2022-03-29 13:01:56 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_worker_mode_write_copy_tick(iButtonWorker* worker) {
|
|
|
|
furi_assert(worker->key);
|
|
|
|
|
|
|
|
const bool success = ibutton_protocols_write_copy(worker->protocols, worker->key);
|
2023-08-22 17:56:27 +00:00
|
|
|
// TODO FL-3527: pass a proper result to the callback
|
2023-03-02 13:23:33 +00:00
|
|
|
const iButtonWorkerWriteResult result = success ? iButtonWorkerWriteOK :
|
|
|
|
iButtonWorkerWriteNoDetect;
|
2022-03-29 13:01:56 +00:00
|
|
|
if(worker->write_cb != NULL) {
|
|
|
|
worker->write_cb(worker->cb_ctx, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
void ibutton_worker_mode_write_common_stop(iButtonWorker* worker) { //-V524
|
|
|
|
UNUSED(worker);
|
2022-03-29 13:01:56 +00:00
|
|
|
furi_hal_power_disable_otg();
|
2022-05-06 13:37:10 +00:00
|
|
|
}
|