[FL-3179] 1-Wire Overdrive Mode (#2522)
* Separate ibutton to its own module, add one_wire to f18 * Move onewire cli to a separate app * Add definitions for normal and overdrive timings * Update api definitions * Add rough overdrive timings definition for onewire emulation * Remove one_wire_host_timing.h * Add rough overdrive timings for onewire host * Improve overdrive mode * Working overdrive mode from flipper to flipper * Update thermometer example app * Turn on otg power when running thermometer example app * Implement reset overdrive switching * Always exit out of overdrive mode * Improve overdrive timings * Fix typos * Fix reset behaviour * Use overdrive mode everywhere in DS1996 * Improve comments * Bump API version Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -63,24 +63,54 @@ const iButtonProtocolDallasBase ibutton_protocol_ds1996 = {
|
||||
|
||||
bool dallas_ds1996_read(OneWireHost* host, iButtonProtocolData* protocol_data) {
|
||||
DS1996ProtocolData* data = protocol_data;
|
||||
return onewire_host_reset(host) && dallas_common_read_rom(host, &data->rom_data) &&
|
||||
dallas_common_read_mem(host, 0, data->sram_data, DS1996_SRAM_DATA_SIZE);
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!onewire_host_reset(host)) break;
|
||||
if(!dallas_common_read_rom(host, &data->rom_data)) break;
|
||||
if(!onewire_host_reset(host)) break;
|
||||
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM);
|
||||
onewire_host_set_overdrive(host, true);
|
||||
|
||||
if(!dallas_common_read_mem(host, 0, data->sram_data, DS1996_SRAM_DATA_SIZE)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
onewire_host_set_overdrive(host, false);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool dallas_ds1996_write_copy(OneWireHost* host, iButtonProtocolData* protocol_data) {
|
||||
DS1996ProtocolData* data = protocol_data;
|
||||
return dallas_common_write_mem(
|
||||
host,
|
||||
DS1996_COPY_SCRATCH_TIMEOUT_US,
|
||||
DS1996_SRAM_PAGE_SIZE,
|
||||
data->sram_data,
|
||||
DS1996_SRAM_DATA_SIZE);
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!onewire_host_reset(host)) break;
|
||||
|
||||
onewire_host_write(host, DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM);
|
||||
onewire_host_set_overdrive(host, true);
|
||||
|
||||
if(!dallas_common_write_mem(
|
||||
host,
|
||||
DS1996_COPY_SCRATCH_TIMEOUT_US,
|
||||
DS1996_SRAM_PAGE_SIZE,
|
||||
data->sram_data,
|
||||
DS1996_SRAM_DATA_SIZE))
|
||||
break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
onewire_host_set_overdrive(host, false);
|
||||
return success;
|
||||
}
|
||||
|
||||
static void dallas_ds1996_reset_callback(void* context) {
|
||||
static bool dallas_ds1996_reset_callback(bool is_short, void* context) {
|
||||
furi_assert(context);
|
||||
DS1996ProtocolData* data = context;
|
||||
data->state.command_state = DallasCommonCommandStateIdle;
|
||||
onewire_slave_set_overdrive(data->state.bus, is_short);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dallas_ds1996_command_callback(uint8_t command, void* context) {
|
||||
@@ -96,8 +126,7 @@ static bool dallas_ds1996_command_callback(uint8_t command, void* context) {
|
||||
|
||||
} else if(data->state.command_state == DallasCommonCommandStateRomCmd) {
|
||||
data->state.command_state = DallasCommonCommandStateMemCmd;
|
||||
dallas_common_emulate_read_mem(bus, data->sram_data, DS1996_SRAM_DATA_SIZE);
|
||||
return false;
|
||||
return dallas_common_emulate_read_mem(bus, data->sram_data, DS1996_SRAM_DATA_SIZE);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
@@ -120,8 +149,17 @@ static bool dallas_ds1996_command_callback(uint8_t command, void* context) {
|
||||
}
|
||||
|
||||
case DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM:
|
||||
if(data->state.command_state == DallasCommonCommandStateIdle) {
|
||||
data->state.command_state = DallasCommonCommandStateRomCmd;
|
||||
onewire_slave_set_overdrive(bus, true);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
case DALLAS_COMMON_CMD_MATCH_ROM:
|
||||
case DALLAS_COMMON_CMD_OVERDRIVE_MATCH_ROM:
|
||||
/* TODO: Overdrive mode support */
|
||||
/* TODO: Match ROM command support */
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user