mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-29 02:08:10 -07:00
Temp fix of broken ibutton emulation
Reverted lib changes and added old api TODO: Find what causes that issue, issue also present in official dev branch
This commit is contained in:
@@ -234,13 +234,16 @@ void ibutton_worker_emulate_timer_cb(void* context) {
|
||||
furi_assert(context);
|
||||
iButtonWorker* worker = context;
|
||||
|
||||
const LevelDuration level_duration =
|
||||
LevelDuration level =
|
||||
protocol_dict_encoder_yield(worker->protocols, worker->protocol_to_encode);
|
||||
|
||||
const bool level = level_duration_get_level(level_duration);
|
||||
furi_hal_ibutton_emulate_set_next(level_duration_get_duration(level));
|
||||
|
||||
furi_hal_ibutton_emulate_set_next(level);
|
||||
furi_hal_ibutton_pin_write(level);
|
||||
if(level_duration_get_level(level)) {
|
||||
furi_hal_ibutton_pin_high();
|
||||
} else {
|
||||
furi_hal_ibutton_pin_low();
|
||||
}
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_timer_start(iButtonWorker* worker) {
|
||||
@@ -263,7 +266,7 @@ void ibutton_worker_emulate_timer_start(iButtonWorker* worker) {
|
||||
protocol_dict_set_data(worker->protocols, worker->protocol_to_encode, key_id, key_size);
|
||||
protocol_dict_encoder_start(worker->protocols, worker->protocol_to_encode);
|
||||
|
||||
furi_hal_ibutton_pin_configure();
|
||||
furi_hal_ibutton_start_drive();
|
||||
furi_hal_ibutton_emulate_start(0, ibutton_worker_emulate_timer_cb, worker);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include "one_wire_host.h"
|
||||
#include "one_wire_host_timing.h"
|
||||
|
||||
@@ -24,47 +24,49 @@ void onewire_host_free(OneWireHost* host) {
|
||||
}
|
||||
|
||||
bool onewire_host_reset(OneWireHost* host) {
|
||||
UNUSED(host);
|
||||
uint8_t r;
|
||||
uint8_t retries = 125;
|
||||
|
||||
// wait until the gpio is high
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
do {
|
||||
if(--retries == 0) return 0;
|
||||
furi_delay_us(2);
|
||||
} while(!furi_hal_gpio_read(host->gpio_pin));
|
||||
} while(!furi_hal_ibutton_pin_get_level());
|
||||
|
||||
// pre delay
|
||||
furi_delay_us(OWH_RESET_DELAY_PRE);
|
||||
|
||||
// drive low
|
||||
furi_hal_gpio_write(host->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_delay_us(OWH_RESET_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_delay_us(OWH_RESET_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
r = !furi_hal_gpio_read(host->gpio_pin);
|
||||
r = !furi_hal_ibutton_pin_get_level();
|
||||
furi_delay_us(OWH_RESET_DELAY_POST);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool onewire_host_read_bit(OneWireHost* host) {
|
||||
UNUSED(host);
|
||||
bool result;
|
||||
|
||||
// drive low
|
||||
furi_hal_gpio_write(host->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_delay_us(OWH_READ_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_delay_us(OWH_READ_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
result = furi_hal_gpio_read(host->gpio_pin);
|
||||
result = furi_hal_ibutton_pin_get_level();
|
||||
furi_delay_us(OWH_READ_DELAY_POST);
|
||||
|
||||
return result;
|
||||
@@ -89,21 +91,22 @@ void onewire_host_read_bytes(OneWireHost* host, uint8_t* buffer, uint16_t count)
|
||||
}
|
||||
|
||||
void onewire_host_write_bit(OneWireHost* host, bool value) {
|
||||
UNUSED(host);
|
||||
if(value) {
|
||||
// drive low
|
||||
furi_hal_gpio_write(host->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_delay_us(OWH_WRITE_1_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_delay_us(OWH_WRITE_1_RELEASE);
|
||||
} else {
|
||||
// drive low
|
||||
furi_hal_gpio_write(host->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_delay_us(OWH_WRITE_0_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_delay_us(OWH_WRITE_0_RELEASE);
|
||||
}
|
||||
}
|
||||
@@ -121,13 +124,13 @@ void onewire_host_skip(OneWireHost* host) {
|
||||
}
|
||||
|
||||
void onewire_host_start(OneWireHost* host) {
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_gpio_init(host->gpio_pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
UNUSED(host);
|
||||
furi_hal_ibutton_start_drive();
|
||||
}
|
||||
|
||||
void onewire_host_stop(OneWireHost* host) {
|
||||
furi_hal_gpio_write(host->gpio_pin, true);
|
||||
furi_hal_gpio_init(host->gpio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
UNUSED(host);
|
||||
furi_hal_ibutton_stop();
|
||||
}
|
||||
|
||||
void onewire_host_reset_search(OneWireHost* host) {
|
||||
@@ -148,7 +151,7 @@ void onewire_host_target_search(OneWireHost* host, uint8_t family_code) {
|
||||
host->last_device_flag = false;
|
||||
}
|
||||
|
||||
uint8_t onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode) {
|
||||
uint8_t onewire_host_search(OneWireHost* host, uint8_t* newAddr, OneWireHostSearchMode mode) {
|
||||
uint8_t id_bit_number;
|
||||
uint8_t last_zero, rom_byte_number, search_result;
|
||||
uint8_t id_bit, cmp_id_bit;
|
||||
@@ -257,7 +260,7 @@ uint8_t onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSea
|
||||
host->last_family_discrepancy = 0;
|
||||
search_result = false;
|
||||
} else {
|
||||
for(int i = 0; i < 8; i++) new_addr[i] = host->saved_rom[i];
|
||||
for(int i = 0; i < 8; i++) newAddr[i] = host->saved_rom[i];
|
||||
}
|
||||
|
||||
return search_result;
|
||||
|
||||
@@ -22,7 +22,7 @@ typedef struct OneWireHost OneWireHost;
|
||||
|
||||
/**
|
||||
* Allocate onewire host bus
|
||||
* @param pin
|
||||
* @param gpio
|
||||
* @return OneWireHost*
|
||||
*/
|
||||
OneWireHost* onewire_host_alloc(const GpioPin* gpio_pin);
|
||||
@@ -114,7 +114,7 @@ void onewire_host_target_search(OneWireHost* host, uint8_t family_code);
|
||||
* @param mode
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode);
|
||||
uint8_t onewire_host_search(OneWireHost* host, uint8_t* newAddr, OneWireHostSearchMode mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -36,15 +36,15 @@ struct OneWireSlave {
|
||||
|
||||
/*********************** PRIVATE ***********************/
|
||||
|
||||
static uint32_t
|
||||
onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, const bool pin_value) {
|
||||
uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, const bool pin_value) {
|
||||
UNUSED(bus);
|
||||
uint32_t start = DWT->CYCCNT;
|
||||
uint32_t time_ticks = time * furi_hal_cortex_instructions_per_microsecond();
|
||||
uint32_t time_captured;
|
||||
|
||||
do { //-V1044
|
||||
time_captured = DWT->CYCCNT;
|
||||
if(furi_hal_gpio_read(bus->gpio_pin) != pin_value) {
|
||||
if(furi_hal_ibutton_pin_get_level() != pin_value) {
|
||||
uint32_t remaining_time = time_ticks - (time_captured - start);
|
||||
remaining_time /= furi_hal_cortex_instructions_per_microsecond();
|
||||
return remaining_time;
|
||||
@@ -54,14 +54,14 @@ static uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool onewire_slave_show_presence(OneWireSlave* bus) {
|
||||
bool onewire_slave_show_presence(OneWireSlave* bus) {
|
||||
// wait while master delay presence check
|
||||
onewire_slave_wait_while_gpio_is(bus, OWS_PRESENCE_TIMEOUT, true);
|
||||
|
||||
// show presence
|
||||
furi_hal_gpio_write(bus->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_delay_us(OWS_PRESENCE_MIN);
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
// somebody also can show presence
|
||||
const uint32_t wait_low_time = OWS_PRESENCE_MAX - OWS_PRESENCE_MIN;
|
||||
@@ -75,7 +75,7 @@ static bool onewire_slave_show_presence(OneWireSlave* bus) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool onewire_slave_receive_bit(OneWireSlave* bus) {
|
||||
bool onewire_slave_receive_bit(OneWireSlave* bus) {
|
||||
// wait while bus is low
|
||||
uint32_t time = OWS_SLOT_MAX;
|
||||
time = onewire_slave_wait_while_gpio_is(bus, time, false);
|
||||
@@ -99,7 +99,7 @@ static bool onewire_slave_receive_bit(OneWireSlave* bus) {
|
||||
return (time > 0);
|
||||
}
|
||||
|
||||
static bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
const bool write_zero = !value;
|
||||
|
||||
// wait while bus is low
|
||||
@@ -120,7 +120,7 @@ static bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
|
||||
// choose write time
|
||||
if(write_zero) {
|
||||
furi_hal_gpio_write(bus->gpio_pin, false);
|
||||
furi_hal_ibutton_pin_low();
|
||||
time = OWS_WRITE_ZERO;
|
||||
} else {
|
||||
time = OWS_READ_MAX;
|
||||
@@ -128,12 +128,12 @@ static bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
|
||||
// hold line for ZERO or ONE time
|
||||
furi_delay_us(time);
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void onewire_slave_cmd_search_rom(OneWireSlave* bus) {
|
||||
void onewire_slave_cmd_search_rom(OneWireSlave* bus) {
|
||||
const uint8_t key_bytes = 8;
|
||||
uint8_t* key = onewire_device_get_id_p(bus->device);
|
||||
|
||||
@@ -152,7 +152,7 @@ static void onewire_slave_cmd_search_rom(OneWireSlave* bus) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) {
|
||||
bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) {
|
||||
uint8_t cmd;
|
||||
onewire_slave_receive(bus, &cmd, 1);
|
||||
|
||||
@@ -179,14 +179,14 @@ static bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool onewire_slave_bus_start(OneWireSlave* bus) {
|
||||
bool onewire_slave_bus_start(OneWireSlave* bus) {
|
||||
bool result = true;
|
||||
|
||||
if(bus->device == NULL) {
|
||||
result = false;
|
||||
} else {
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_ibutton_start_drive_in_isr();
|
||||
bus->error = NO_ERROR;
|
||||
|
||||
if(onewire_slave_show_presence(bus)) {
|
||||
@@ -198,7 +198,7 @@ static bool onewire_slave_bus_start(OneWireSlave* bus) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_ibutton_start_interrupt_in_isr();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ static bool onewire_slave_bus_start(OneWireSlave* bus) {
|
||||
static void exti_cb(void* context) {
|
||||
OneWireSlave* bus = context;
|
||||
|
||||
volatile bool input_state = furi_hal_gpio_read(bus->gpio_pin);
|
||||
volatile bool input_state = furi_hal_ibutton_pin_get_level();
|
||||
static uint32_t pulse_start = 0;
|
||||
|
||||
if(input_state) {
|
||||
@@ -251,15 +251,14 @@ void onewire_slave_free(OneWireSlave* bus) {
|
||||
}
|
||||
|
||||
void onewire_slave_start(OneWireSlave* bus) {
|
||||
furi_hal_gpio_add_int_callback(bus->gpio_pin, exti_cb, bus);
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_ibutton_add_interrupt(exti_cb, bus);
|
||||
furi_hal_ibutton_start_interrupt();
|
||||
}
|
||||
|
||||
void onewire_slave_stop(OneWireSlave* bus) {
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_gpio_init(bus->gpio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_remove_int_callback(bus->gpio_pin);
|
||||
UNUSED(bus);
|
||||
furi_hal_ibutton_stop();
|
||||
furi_hal_ibutton_remove_interrupt();
|
||||
}
|
||||
|
||||
void onewire_slave_attach(OneWireSlave* bus, OneWireDevice* device) {
|
||||
@@ -285,7 +284,7 @@ void onewire_slave_set_result_callback(
|
||||
bool onewire_slave_send(OneWireSlave* bus, const uint8_t* address, const uint8_t data_length) {
|
||||
uint8_t bytes_sent = 0;
|
||||
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
// bytes loop
|
||||
for(; bytes_sent < data_length; ++bytes_sent) {
|
||||
@@ -307,7 +306,7 @@ bool onewire_slave_send(OneWireSlave* bus, const uint8_t* address, const uint8_t
|
||||
bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, const uint8_t data_length) {
|
||||
uint8_t bytes_received = 0;
|
||||
|
||||
furi_hal_gpio_write(bus->gpio_pin, true);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
for(; bytes_received < data_length; ++bytes_received) {
|
||||
uint8_t value = 0;
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef void (*OneWireSlaveResultCallback)(void* context);
|
||||
|
||||
/**
|
||||
* Allocate onewire slave
|
||||
* @param gpio_pin
|
||||
* @param pin
|
||||
* @return OneWireSlave*
|
||||
*/
|
||||
OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin);
|
||||
|
||||
Reference in New Issue
Block a user