2022-03-29 13:01:56 +00:00
|
|
|
/**
|
|
|
|
* @file one_wire_slave.h
|
|
|
|
*
|
2023-03-02 13:23:33 +00:00
|
|
|
* 1-Wire slave library.
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2023-03-02 13:23:33 +00:00
|
|
|
#include <stddef.h>
|
2022-03-29 13:01:56 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2023-03-02 13:23:33 +00:00
|
|
|
|
2022-03-29 13:01:56 +00:00
|
|
|
#include <furi_hal_gpio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct OneWireDevice OneWireDevice;
|
|
|
|
typedef struct OneWireSlave OneWireSlave;
|
2023-03-02 13:23:33 +00:00
|
|
|
|
2023-03-22 14:54:06 +00:00
|
|
|
typedef bool (*OneWireSlaveResetCallback)(bool is_short, void* context);
|
2023-03-02 13:23:33 +00:00
|
|
|
typedef bool (*OneWireSlaveCommandCallback)(uint8_t command, void* context);
|
2023-03-22 14:54:06 +00:00
|
|
|
typedef void (*OneWireSlaveResultCallback)(void* context);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* Allocate OneWireSlave instance
|
|
|
|
* @param [in] gpio_pin connection pin
|
|
|
|
* @return pointer to OneWireSlave instance
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
2023-02-08 05:40:44 +00:00
|
|
|
OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* Destroy OneWireSlave instance, free resources
|
|
|
|
* @param [in] bus pointer to OneWireSlave instance
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_free(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start working with the bus
|
2023-03-22 14:54:06 +00:00
|
|
|
* @param [in] bus pointer to OneWireSlave instance
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_start(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop working with the bus
|
2023-03-22 14:54:06 +00:00
|
|
|
* @param [in] bus pointer to OneWireSlave instance
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_stop(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* Receive one bit
|
|
|
|
* @param [in] bus pointer to OneWireSlave instance
|
|
|
|
* @return received bit value
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
2023-03-02 13:23:33 +00:00
|
|
|
bool onewire_slave_receive_bit(OneWireSlave* bus);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* Send one bit
|
|
|
|
* @param [in] bus pointer to OneWireSlave instance
|
|
|
|
* @param [in] value bit value to send
|
|
|
|
* @return true on success, false on failure
|
2023-03-02 13:23:33 +00:00
|
|
|
*/
|
|
|
|
bool onewire_slave_send_bit(OneWireSlave* bus, bool value);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* 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
|
2023-03-02 13:23:33 +00:00
|
|
|
*/
|
|
|
|
bool onewire_slave_send(OneWireSlave* bus, const uint8_t* data, size_t data_size);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* 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
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
2023-03-02 13:23:33 +00:00
|
|
|
bool onewire_slave_receive(OneWireSlave* bus, uint8_t* data, size_t data_size);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* 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
|
2023-03-02 13:23:33 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_set_reset_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveResetCallback callback,
|
|
|
|
void* context);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 14:54:06 +00:00
|
|
|
* 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
|
2023-03-02 13:23:33 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_set_command_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveCommandCallback callback,
|
|
|
|
void* context);
|
2022-03-29 13:01:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback to report emulation success
|
2023-03-22 14:54:06 +00:00
|
|
|
* @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
|
2022-03-29 13:01:56 +00:00
|
|
|
*/
|
|
|
|
void onewire_slave_set_result_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveResultCallback result_cb,
|
|
|
|
void* context);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|