mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-27 15:00:46 +00:00
Merge branch 'dev' into filebrowser
This commit is contained in:
commit
b8deb931c2
10 changed files with 178 additions and 71 deletions
|
@ -120,7 +120,10 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
furi_hal_subghz_rx();
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz.cc1101_g0_pin,
|
||||
GpioModeOutputPushPull,
|
||||
GpioPullNo,
|
||||
GpioSpeedLow);
|
||||
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, true);
|
||||
if(!furi_hal_subghz_tx()) {
|
||||
furi_hal_gpio_init(
|
||||
|
|
|
@ -1146,13 +1146,23 @@ Function,+,furi_hal_i2c_tx,_Bool,"FuriHalI2cBusHandle*, const uint8_t, const uin
|
|||
Function,+,furi_hal_i2c_write_mem,_Bool,"FuriHalI2cBusHandle*, uint8_t, uint8_t, uint8_t*, uint8_t, uint32_t"
|
||||
Function,+,furi_hal_i2c_write_reg_16,_Bool,"FuriHalI2cBusHandle*, uint8_t, uint8_t, uint16_t, uint32_t"
|
||||
Function,+,furi_hal_i2c_write_reg_8,_Bool,"FuriHalI2cBusHandle*, uint8_t, uint8_t, uint8_t, uint32_t"
|
||||
Function,+,furi_hal_ibutton_add_interrupt,void,"GpioExtiCallback, void*"
|
||||
Function,+,furi_hal_ibutton_emulate_set_next,void,uint32_t
|
||||
Function,+,furi_hal_ibutton_emulate_start,void,"uint32_t, FuriHalIbuttonEmulateCallback, void*"
|
||||
Function,+,furi_hal_ibutton_emulate_stop,void,
|
||||
Function,-,furi_hal_ibutton_init,void,
|
||||
Function,+,furi_hal_ibutton_pin_configure,void,
|
||||
Function,+,furi_hal_ibutton_pin_get_level,_Bool,
|
||||
Function,+,furi_hal_ibutton_pin_high,void,
|
||||
Function,+,furi_hal_ibutton_pin_low,void,
|
||||
Function,+,furi_hal_ibutton_pin_reset,void,
|
||||
Function,+,furi_hal_ibutton_pin_write,void,const _Bool
|
||||
Function,+,furi_hal_ibutton_remove_interrupt,void,
|
||||
Function,+,furi_hal_ibutton_start_drive,void,
|
||||
Function,+,furi_hal_ibutton_start_drive_in_isr,void,
|
||||
Function,+,furi_hal_ibutton_start_interrupt,void,
|
||||
Function,+,furi_hal_ibutton_start_interrupt_in_isr,void,
|
||||
Function,+,furi_hal_ibutton_stop,void,
|
||||
Function,+,furi_hal_info_get,void,"PropertyValueCallback, char, void*"
|
||||
Function,+,furi_hal_infrared_async_rx_set_capture_isr_callback,void,"FuriHalInfraredRxCaptureCallback, void*"
|
||||
Function,+,furi_hal_infrared_async_rx_set_timeout,void,uint32_t
|
||||
|
|
|
|
@ -89,6 +89,51 @@ void furi_hal_ibutton_emulate_stop() {
|
|||
}
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_start_drive() {
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_start_drive_in_isr() {
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_start_interrupt() {
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_start_interrupt_in_isr() {
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_stop() {
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_add_interrupt(GpioExtiCallback cb, void* context) {
|
||||
furi_hal_gpio_add_int_callback(&ibutton_gpio, cb, context);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_remove_interrupt() {
|
||||
furi_hal_gpio_remove_int_callback(&ibutton_gpio);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_pin_low() {
|
||||
furi_hal_gpio_write(&ibutton_gpio, false);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_pin_high() {
|
||||
furi_hal_gpio_write(&ibutton_gpio, true);
|
||||
}
|
||||
|
||||
bool furi_hal_ibutton_pin_get_level() {
|
||||
return furi_hal_gpio_read(&ibutton_gpio);
|
||||
}
|
||||
|
||||
void furi_hal_ibutton_pin_configure() {
|
||||
furi_hal_gpio_write(&ibutton_gpio, true);
|
||||
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -17,28 +18,71 @@ typedef void (*FuriHalIbuttonEmulateCallback)(void* context);
|
|||
/** Initialize */
|
||||
void furi_hal_ibutton_init();
|
||||
|
||||
/**
|
||||
* Start emulation timer
|
||||
* @param period timer period
|
||||
* @param callback timer callback
|
||||
* @param context callback context
|
||||
*/
|
||||
void furi_hal_ibutton_emulate_start(
|
||||
uint32_t period,
|
||||
FuriHalIbuttonEmulateCallback callback,
|
||||
void* context);
|
||||
|
||||
/**
|
||||
* Update emulation timer period
|
||||
* @param period new timer period
|
||||
*/
|
||||
void furi_hal_ibutton_emulate_set_next(uint32_t period);
|
||||
|
||||
/**
|
||||
* Stop emulation timer
|
||||
*/
|
||||
void furi_hal_ibutton_emulate_stop();
|
||||
|
||||
/**
|
||||
* Sets the pin to normal mode (open collector), and sets it to float
|
||||
*/
|
||||
void furi_hal_ibutton_start_drive();
|
||||
|
||||
/**
|
||||
* Sets the pin to normal mode (open collector), and clears pin EXTI interrupt.
|
||||
* Used in EXTI interrupt context.
|
||||
*/
|
||||
void furi_hal_ibutton_start_drive_in_isr();
|
||||
|
||||
/**
|
||||
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and sets it to float
|
||||
*/
|
||||
void furi_hal_ibutton_start_interrupt();
|
||||
|
||||
/**
|
||||
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and clears pin EXTI interrupt.
|
||||
* Used in EXTI interrupt context.
|
||||
*/
|
||||
void furi_hal_ibutton_start_interrupt_in_isr();
|
||||
|
||||
/**
|
||||
* Sets the pin to analog mode, and sets it to float
|
||||
*/
|
||||
void furi_hal_ibutton_stop();
|
||||
|
||||
/**
|
||||
* Attach interrupt callback to iButton pin
|
||||
* @param cb callback
|
||||
* @param context context
|
||||
*/
|
||||
void furi_hal_ibutton_add_interrupt(GpioExtiCallback cb, void* context);
|
||||
|
||||
/**
|
||||
* Remove interrupt callback from iButton pin
|
||||
*/
|
||||
void furi_hal_ibutton_remove_interrupt();
|
||||
|
||||
/**
|
||||
* Sets the pin to low
|
||||
*/
|
||||
void furi_hal_ibutton_pin_low();
|
||||
|
||||
/**
|
||||
* Sets the pin to high (float in iButton pin modes)
|
||||
*/
|
||||
void furi_hal_ibutton_pin_high();
|
||||
|
||||
/**
|
||||
* Get pin level
|
||||
* @return true if level is high
|
||||
* @return false if level is low
|
||||
*/
|
||||
bool furi_hal_ibutton_pin_get_level();
|
||||
|
||||
/**
|
||||
* Set the pin to normal mode (open collector), and sets it to float
|
||||
*/
|
||||
|
|
|
@ -77,7 +77,7 @@ void furi_hal_rfid_init() {
|
|||
|
||||
void furi_hal_rfid_pins_reset() {
|
||||
// ibutton bus disable
|
||||
furi_hal_ibutton_pin_reset();
|
||||
furi_hal_ibutton_stop();
|
||||
|
||||
// pulldown rfid antenna
|
||||
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
@ -94,8 +94,8 @@ void furi_hal_rfid_pins_reset() {
|
|||
|
||||
void furi_hal_rfid_pins_emulate() {
|
||||
// ibutton low
|
||||
furi_hal_ibutton_pin_configure();
|
||||
furi_hal_ibutton_pin_write(false);
|
||||
furi_hal_ibutton_start_drive();
|
||||
furi_hal_ibutton_pin_low();
|
||||
|
||||
// pull pin to timer out
|
||||
furi_hal_gpio_init_ex(
|
||||
|
@ -115,8 +115,8 @@ void furi_hal_rfid_pins_emulate() {
|
|||
|
||||
void furi_hal_rfid_pins_read() {
|
||||
// ibutton low
|
||||
furi_hal_ibutton_pin_configure();
|
||||
furi_hal_ibutton_pin_write(false);
|
||||
furi_hal_ibutton_start_drive();
|
||||
furi_hal_ibutton_pin_low();
|
||||
|
||||
// dont pull rfid antenna
|
||||
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue