NFC: Add API to enforce ISO15693 mode (#225)

* Add API to enforce ISO15693 mode
See https://github.com/flipperdevices/flipperzero-firmware/pull/3885

* Revert symbols version

* Format

* Update changelog

---------

Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
This commit is contained in:
Aaron Tulino
2024-09-17 14:32:03 -07:00
committed by GitHub
parent 12f9bd73b7
commit 5afc01a4c3
8 changed files with 124 additions and 4 deletions

View File

@@ -26,6 +26,7 @@ typedef enum {
struct Iso15693Parser {
Iso15693ParserState state;
Iso15693ParserMode mode;
bool detect_mode;
SignalReader* signal_reader;
@@ -62,6 +63,7 @@ typedef Iso15693ParserCommand (*Iso15693ParserStateHandler)(Iso15693Parser* inst
Iso15693Parser* iso15693_parser_alloc(const GpioPin* pin, size_t max_frame_size) {
Iso15693Parser* instance = malloc(sizeof(Iso15693Parser));
instance->detect_mode = true;
instance->parsed_frame = bit_buffer_alloc(max_frame_size);
instance->signal_reader = signal_reader_alloc(pin, ISO15693_PARSER_SIGNAL_READER_BUFF_SIZE);
@@ -86,7 +88,7 @@ void iso15693_parser_reset(Iso15693Parser* instance) {
furi_assert(instance);
instance->state = Iso15693ParserStateParseSoF;
instance->mode = Iso15693ParserMode1OutOf4;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf4;
memset(instance->bitstream_buff, 0x00, sizeof(instance->bitstream_buff));
instance->bitstream_idx = 0;
@@ -122,10 +124,10 @@ static void signal_reader_callback(SignalReaderEvent event, void* context) {
if(instance->state == Iso15693ParserStateParseSoF) {
if(event.data->data[0] == sof_1_out_of_4) {
instance->mode = Iso15693ParserMode1OutOf4;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf4;
instance->state = Iso15693ParserStateParseFrame;
} else if(event.data->data[0] == sof_1_out_of_256) {
instance->mode = Iso15693ParserMode1OutOf256;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf256;
instance->state = Iso15693ParserStateParseFrame;
} else if(event.data->data[0] == eof_single) {
instance->eof_received = true;
@@ -298,3 +300,23 @@ void iso15693_parser_get_data(
bit_buffer_write_bytes(instance->parsed_frame, buff, buff_size);
*data_bits = bit_buffer_get_size(instance->parsed_frame);
}
void iso15693_parser_detect_mode(Iso15693Parser* instance) {
furi_assert(instance);
instance->detect_mode = true;
}
void iso15693_parser_force_1outof4(Iso15693Parser* instance) {
furi_assert(instance);
instance->detect_mode = false;
instance->mode = Iso15693ParserMode1OutOf4;
}
void iso15693_parser_force_1outof256(Iso15693Parser* instance) {
furi_assert(instance);
instance->detect_mode = false;
instance->mode = Iso15693ParserMode1OutOf256;
}

View File

@@ -37,6 +37,10 @@ void iso15693_parser_get_data(
size_t buff_size,
size_t* data_bits);
void iso15693_parser_detect_mode(Iso15693Parser* instance);
void iso15693_parser_force_1outof4(Iso15693Parser* instance);
void iso15693_parser_force_1outof256(Iso15693Parser* instance);
#ifdef __cplusplus
}
#endif