2022-03-29 16:01:56 +03:00
|
|
|
/**
|
|
|
|
* @file one_wire_host.h
|
|
|
|
*
|
|
|
|
* 1-Wire host (master) library
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <furi_hal_gpio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
2023-03-02 16:23:33 +03:00
|
|
|
OneWireHostSearchModeConditional = 0, /**< Search for alarmed device */
|
2023-03-22 17:54:06 +03:00
|
|
|
OneWireHostSearchModeNormal = 1, /**< Search for all devices */
|
2022-03-29 16:01:56 +03:00
|
|
|
} OneWireHostSearchMode;
|
|
|
|
|
|
|
|
typedef struct OneWireHost OneWireHost;
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Allocate OneWireHost instance
|
|
|
|
* @param [in] gpio_pin connection pin
|
|
|
|
* @return pointer to OneWireHost instance
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
2023-02-08 08:40:44 +03:00
|
|
|
OneWireHost* onewire_host_alloc(const GpioPin* gpio_pin);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Destroy OneWireHost instance, free resources
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_free(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Reset the 1-Wire bus
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @return true if presence was detected, false otherwise
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
bool onewire_host_reset(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read one bit
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @return received bit value
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
bool onewire_host_read_bit(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read one byte
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @return received byte value
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
uint8_t onewire_host_read(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Read one or more bytes
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param [out] buffer received data buffer
|
|
|
|
* @param [in] count number of bytes to read
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_read_bytes(OneWireHost* host, uint8_t* buffer, uint16_t count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write one bit
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param value bit value to write
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_write_bit(OneWireHost* host, bool value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write one byte
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param value byte value to write
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_write(OneWireHost* host, uint8_t value);
|
|
|
|
|
2023-03-02 16:23:33 +03:00
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Write one or more bytes
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param [in] buffer pointer to the data to write
|
|
|
|
* @param [in] count size of the data to write
|
2023-03-02 16:23:33 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_write_bytes(OneWireHost* host, const uint8_t* buffer, uint16_t count);
|
|
|
|
|
2022-03-29 16:01:56 +03:00
|
|
|
/**
|
|
|
|
* Start working with the bus
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_start(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop working with the bus
|
2023-03-22 17:54:06 +03:00
|
|
|
* @param [in] host pointer to OneWireHost instance
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_stop(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Reset previous search results
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_reset_search(OneWireHost* host);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Set the family code to search for
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param [in] family_code device family code
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
|
|
|
void onewire_host_target_search(OneWireHost* host, uint8_t family_code);
|
|
|
|
|
|
|
|
/**
|
2023-03-22 17:54:06 +03:00
|
|
|
* Search for devices on the 1-Wire bus
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param [out] new_addr pointer to the buffer to contain the unique ROM of the found device
|
|
|
|
* @param [in] mode search mode
|
|
|
|
* @return true on success, false otherwise
|
|
|
|
*/
|
|
|
|
bool onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearchMode mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable overdrive mode
|
|
|
|
* @param [in] host pointer to OneWireHost instance
|
|
|
|
* @param [in] set true to turn overdrive on, false to turn it off
|
2022-03-29 16:01:56 +03:00
|
|
|
*/
|
2023-03-22 17:54:06 +03:00
|
|
|
void onewire_host_set_overdrive(OneWireHost* host, bool set);
|
2022-03-29 16:01:56 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2022-05-06 16:37:10 +03:00
|
|
|
#endif
|