[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:
Georgii Surkov
2023-03-22 17:54:06 +03:00
committed by GitHub
parent 1f236ede0e
commit 8b224ecb15
16 changed files with 397 additions and 227 deletions

View File

@@ -18,68 +18,85 @@ extern "C" {
typedef struct OneWireDevice OneWireDevice;
typedef struct OneWireSlave OneWireSlave;
typedef void (*OneWireSlaveResetCallback)(void* context);
typedef void (*OneWireSlaveResultCallback)(void* context);
typedef bool (*OneWireSlaveResetCallback)(bool is_short, void* context);
typedef bool (*OneWireSlaveCommandCallback)(uint8_t command, void* context);
typedef void (*OneWireSlaveResultCallback)(void* context);
/**
* Allocate onewire slave
* @param gpio_pin
* @return OneWireSlave*
* Allocate OneWireSlave instance
* @param [in] gpio_pin connection pin
* @return pointer to OneWireSlave instance
*/
OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin);
/**
* Free onewire slave
* @param bus
* Destroy OneWireSlave instance, free resources
* @param [in] bus pointer to OneWireSlave instance
*/
void onewire_slave_free(OneWireSlave* bus);
/**
* Start working with the bus
* @param bus
* @param [in] bus pointer to OneWireSlave instance
*/
void onewire_slave_start(OneWireSlave* bus);
/**
* Stop working with the bus
* @param bus
* @param [in] bus pointer to OneWireSlave instance
*/
void onewire_slave_stop(OneWireSlave* bus);
/**
* TODO: description comment
* Receive one bit
* @param [in] bus pointer to OneWireSlave instance
* @return received bit value
*/
bool onewire_slave_receive_bit(OneWireSlave* bus);
/**
* TODO: description comment
* Send one bit
* @param [in] bus pointer to OneWireSlave instance
* @param [in] value bit value to send
* @return true on success, false on failure
*/
bool onewire_slave_send_bit(OneWireSlave* bus, bool value);
/**
* Send data
* @param bus
* @param data
* @param data_size
* @return bool
* Send one or more bytes of data
* @param [in] bus pointer to OneWireSlave instance
* @param [in] data pointer to the data to send
* @param [in] data_size size of the data to send
* @return true on success, false on failure
*/
bool onewire_slave_send(OneWireSlave* bus, const uint8_t* data, size_t data_size);
/**
* Receive data
* @param bus
* @param data
* @param data_size
* @return bool
* Receive one or more bytes of data
* @param [in] bus pointer to OneWireSlave instance
* @param [out] data pointer to the receive buffer
* @param [in] data_size number of bytes to receive
* @return true on success, false on failure
*/
bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, size_t data_size);
/**
* Set a callback to be called on each reset
* @param bus
* @param callback
* @param context
* Enable overdrive mode
* @param [in] bus pointer to OneWireSlave instance
* @param [in] set true to turn overdrive on, false to turn it off
*/
void onewire_slave_set_overdrive(OneWireSlave* bus, bool set);
/**
* Set a callback function to be called on each reset.
* The return value of the callback determines whether the emulated device
* supports the short reset (passed as the is_short parameter).
* In most applications, it should also call onewire_slave_set_overdrive()
* to set the appropriate speed mode.
*
* @param [in] bus pointer to OneWireSlave instance
* @param [in] callback pointer to a callback function
* @param [in] context additional parameter to be passed to the callback
*/
void onewire_slave_set_reset_callback(
OneWireSlave* bus,
@@ -87,10 +104,13 @@ void onewire_slave_set_reset_callback(
void* context);
/**
* Set a callback to be called on each command
* @param bus
* @param callback
* @param context
* Set a callback function to be called on each command.
* The return value of the callback determines whether further operation
* is possible. As a rule of thumb, return true unless a critical error happened.
*
* @param [in] bus pointer to OneWireSlave instance
* @param [in] callback pointer to a callback function
* @param [in] context additional parameter to be passed to the callback
*/
void onewire_slave_set_command_callback(
OneWireSlave* bus,
@@ -99,9 +119,9 @@ void onewire_slave_set_command_callback(
/**
* Set a callback to report emulation success
* @param bus
* @param result_cb
* @param context
* @param [in] bus pointer to OneWireSlave instance
* @param [in] result_cb pointer to a callback function
* @param [in] context additional parameter to be passed to the callback
*/
void onewire_slave_set_result_callback(
OneWireSlave* bus,