2021-11-28 21:28:19 +03:00
|
|
|
/**
|
2022-01-05 19:10:18 +03:00
|
|
|
* @file furi_hal_i2c.h
|
2021-11-28 21:28:19 +03:00
|
|
|
* I2C HAL API
|
|
|
|
*/
|
|
|
|
|
2021-05-18 12:23:14 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal_i2c_config.h>
|
2021-05-18 12:23:14 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-11-28 21:28:19 +03:00
|
|
|
/** Init I2C
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_i2c_init();
|
2021-05-18 12:23:14 +03:00
|
|
|
|
2021-11-28 21:28:19 +03:00
|
|
|
/** Acquire i2c bus handle
|
|
|
|
*
|
|
|
|
* @return Instance of FuriHalI2cBus
|
|
|
|
*/
|
|
|
|
void furi_hal_i2c_acquire(FuriHalI2cBusHandle* handle);
|
|
|
|
|
|
|
|
/** Release i2c bus handle
|
|
|
|
*
|
|
|
|
* @param bus instance of FuriHalI2cBus aquired in `furi_hal_i2c_acquire`
|
|
|
|
*/
|
|
|
|
void furi_hal_i2c_release(FuriHalI2cBusHandle* handle);
|
|
|
|
|
|
|
|
/** Perform I2C tx transfer
|
|
|
|
*
|
2021-12-01 01:07:17 +03:00
|
|
|
* @param handle pointer to FuriHalI2cBusHandle instance
|
|
|
|
* @param address I2C slave address
|
|
|
|
* @param data pointer to data buffer
|
|
|
|
* @param size size of data buffer
|
|
|
|
* @param timeout timeout in ticks
|
2021-11-28 21:28:19 +03:00
|
|
|
*
|
|
|
|
* @return true on successful transfer, false otherwise
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_i2c_tx(
|
2021-11-28 21:28:19 +03:00
|
|
|
FuriHalI2cBusHandle* handle,
|
2021-05-18 12:23:14 +03:00
|
|
|
const uint8_t address,
|
|
|
|
const uint8_t* data,
|
|
|
|
const uint8_t size,
|
|
|
|
uint32_t timeout);
|
|
|
|
|
2021-11-28 21:28:19 +03:00
|
|
|
/** Perform I2C rx transfer
|
|
|
|
*
|
2021-12-01 01:07:17 +03:00
|
|
|
* @param handle pointer to FuriHalI2cBusHandle instance
|
|
|
|
* @param address I2C slave address
|
|
|
|
* @param data pointer to data buffer
|
|
|
|
* @param size size of data buffer
|
|
|
|
* @param timeout timeout in ticks
|
2021-11-28 21:28:19 +03:00
|
|
|
*
|
|
|
|
* @return true on successful transfer, false otherwise
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_i2c_rx(
|
2021-11-28 21:28:19 +03:00
|
|
|
FuriHalI2cBusHandle* handle,
|
2021-05-18 12:23:14 +03:00
|
|
|
const uint8_t address,
|
|
|
|
uint8_t* data,
|
|
|
|
const uint8_t size,
|
|
|
|
uint32_t timeout);
|
|
|
|
|
2021-11-28 21:28:19 +03:00
|
|
|
/** Perform I2C tx and rx transfers
|
|
|
|
*
|
2021-12-01 01:07:17 +03:00
|
|
|
* @param handle pointer to FuriHalI2cBusHandle instance
|
|
|
|
* @param address I2C slave address
|
|
|
|
* @param tx_data pointer to tx data buffer
|
|
|
|
* @param tx_size size of tx data buffer
|
|
|
|
* @param rx_data pointer to rx data buffer
|
|
|
|
* @param rx_size size of rx data buffer
|
|
|
|
* @param timeout timeout in ticks
|
2021-11-28 21:28:19 +03:00
|
|
|
*
|
|
|
|
* @return true on successful transfer, false otherwise
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_i2c_trx(
|
2021-11-28 21:28:19 +03:00
|
|
|
FuriHalI2cBusHandle* handle,
|
2021-05-18 12:23:14 +03:00
|
|
|
const uint8_t address,
|
|
|
|
const uint8_t* tx_data,
|
|
|
|
const uint8_t tx_size,
|
|
|
|
uint8_t* rx_data,
|
|
|
|
const uint8_t rx_size,
|
|
|
|
uint32_t timeout);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|