2022-03-29 16:01:56 +03:00
|
|
|
/**
|
|
|
|
* @file one_wire_slave.h
|
|
|
|
*
|
2023-03-02 16:23:33 +03:00
|
|
|
* 1-Wire slave library.
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2023-03-02 16:23:33 +03:00
|
|
|
#include <stddef.h>
|
2022-03-29 16:01:56 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2023-03-02 16:23:33 +03:00
|
|
|
|
2022-03-29 16:01:56 +03:00
|
|
|
#include <furi_hal_gpio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct OneWireDevice OneWireDevice;
|
|
|
|
typedef struct OneWireSlave OneWireSlave;
|
2023-03-02 16:23:33 +03:00
|
|
|
|
|
|
|
typedef void (*OneWireSlaveResetCallback)(void* context);
|
2022-03-29 16:01:56 +03:00
|
|
|
typedef void (*OneWireSlaveResultCallback)(void* context);
|
2023-03-02 16:23:33 +03:00
|
|
|
typedef bool (*OneWireSlaveCommandCallback)(uint8_t command, void* context);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate onewire slave
|
2023-02-08 08:40:44 +03:00
|
|
|
* @param gpio_pin
|
2022-03-29 16:01:56 +03:00
|
|
|
* @return OneWireSlave*
|
|
|
|
*/
|
2023-02-08 08:40:44 +03:00
|
|
|
OneWireSlave* onewire_slave_alloc(const GpioPin* gpio_pin);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free onewire slave
|
|
|
|
* @param bus
|
|
|
|
*/
|
|
|
|
void onewire_slave_free(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start working with the bus
|
|
|
|
* @param bus
|
|
|
|
*/
|
|
|
|
void onewire_slave_start(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop working with the bus
|
|
|
|
* @param bus
|
|
|
|
*/
|
|
|
|
void onewire_slave_stop(OneWireSlave* bus);
|
|
|
|
|
|
|
|
/**
|
2023-03-02 16:23:33 +03:00
|
|
|
* TODO: description comment
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
2023-03-02 16:23:33 +03:00
|
|
|
bool onewire_slave_receive_bit(OneWireSlave* bus);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
/**
|
2023-03-02 16:23:33 +03:00
|
|
|
* TODO: description comment
|
|
|
|
*/
|
|
|
|
bool onewire_slave_send_bit(OneWireSlave* bus, bool value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send data
|
|
|
|
* @param bus
|
|
|
|
* @param data
|
|
|
|
* @param data_size
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
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
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
2023-03-02 16:23:33 +03:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
void onewire_slave_set_reset_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveResetCallback callback,
|
|
|
|
void* context);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback to be called on each command
|
|
|
|
* @param bus
|
|
|
|
* @param callback
|
|
|
|
* @param context
|
|
|
|
*/
|
|
|
|
void onewire_slave_set_command_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveCommandCallback callback,
|
|
|
|
void* context);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback to report emulation success
|
|
|
|
* @param bus
|
|
|
|
* @param result_cb
|
|
|
|
* @param context
|
|
|
|
*/
|
|
|
|
void onewire_slave_set_result_callback(
|
|
|
|
OneWireSlave* bus,
|
|
|
|
OneWireSlaveResultCallback result_cb,
|
|
|
|
void* context);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|