Loading...
Searching...
No Matches
furi_hal_i2c.h File Reference

I2C HAL API. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <furi_hal_i2c_config.h>

Go to the source code of this file.

Enumerations

enum  FuriHalI2cBegin { FuriHalI2cBeginStart , FuriHalI2cBeginRestart , FuriHalI2cBeginResume }
 Transaction beginning signal. More...
 
enum  FuriHalI2cEnd { FuriHalI2cEndStop , FuriHalI2cEndAwaitRestart , FuriHalI2cEndPause }
 Transaction end signal. More...
 

Functions

void furi_hal_i2c_init_early (void)
 Early Init I2C.
 
void furi_hal_i2c_deinit_early (void)
 Early DeInit I2C.
 
void furi_hal_i2c_init (void)
 Init I2C.
 
void furi_hal_i2c_acquire (FuriHalI2cBusHandle *handle)
 Acquire I2C bus handle.
 
void furi_hal_i2c_release (FuriHalI2cBusHandle *handle)
 Release I2C bus handle.
 
bool furi_hal_i2c_tx (FuriHalI2cBusHandle *handle, uint8_t address, const uint8_t *data, size_t size, uint32_t timeout)
 Perform I2C TX transfer.
 
bool furi_hal_i2c_tx_ext (FuriHalI2cBusHandle *handle, uint16_t address, bool ten_bit, const uint8_t *data, size_t size, FuriHalI2cBegin begin, FuriHalI2cEnd end, uint32_t timeout)
 Perform I2C TX transfer, with additional settings.
 
bool furi_hal_i2c_rx (FuriHalI2cBusHandle *handle, uint8_t address, uint8_t *data, size_t size, uint32_t timeout)
 Perform I2C RX transfer.
 
bool furi_hal_i2c_rx_ext (FuriHalI2cBusHandle *handle, uint16_t address, bool ten_bit, uint8_t *data, size_t size, FuriHalI2cBegin begin, FuriHalI2cEnd end, uint32_t timeout)
 Perform I2C RX transfer, with additional settings.
 
bool furi_hal_i2c_trx (FuriHalI2cBusHandle *handle, uint8_t address, const uint8_t *tx_data, size_t tx_size, uint8_t *rx_data, size_t rx_size, uint32_t timeout)
 Perform I2C TX and RX transfers.
 
bool furi_hal_i2c_is_device_ready (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint32_t timeout)
 Check if I2C device presents on bus.
 
bool furi_hal_i2c_read_reg_8 (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t reg_addr, uint8_t *data, uint32_t timeout)
 Perform I2C device register read (8-bit)
 
bool furi_hal_i2c_read_reg_16 (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t reg_addr, uint16_t *data, uint32_t timeout)
 Perform I2C device register read (16-bit)
 
bool furi_hal_i2c_read_mem (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t mem_addr, uint8_t *data, size_t len, uint32_t timeout)
 Perform I2C device memory read.
 
bool furi_hal_i2c_write_reg_8 (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t reg_addr, uint8_t data, uint32_t timeout)
 Perform I2C device register write (8-bit)
 
bool furi_hal_i2c_write_reg_16 (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t reg_addr, uint16_t data, uint32_t timeout)
 Perform I2C device register write (16-bit)
 
bool furi_hal_i2c_write_mem (FuriHalI2cBusHandle *handle, uint8_t i2c_addr, uint8_t mem_addr, const uint8_t *data, size_t len, uint32_t timeout)
 Perform I2C device memory.
 

Detailed Description

I2C HAL API.

Enumeration Type Documentation

◆ FuriHalI2cBegin

Transaction beginning signal.

Enumerator
FuriHalI2cBeginStart 

Begin the transaction by sending a START condition followed by the address

FuriHalI2cBeginRestart 

Begin the transaction by sending a RESTART condition followed by the address

Note
Must follow a transaction ended with FuriHalI2cEndAwaitRestart
FuriHalI2cBeginResume 

Continue the previous transaction with new data

Note
Must follow a transaction ended with FuriHalI2cEndPause and be of the same type (RX/TX)

◆ FuriHalI2cEnd

Transaction end signal.

Enumerator
FuriHalI2cEndStop 

End the transaction by sending a STOP condition

FuriHalI2cEndAwaitRestart 

End the transaction by clock stretching

Note
Must be followed by a transaction using FuriHalI2cBeginRestart
FuriHalI2cEndPause 

Pauses the transaction by clock stretching

Note
Must be followed by a transaction using FuriHalI2cBeginResume

Function Documentation

◆ furi_hal_i2c_acquire()

void furi_hal_i2c_acquire ( FuriHalI2cBusHandle * handle)

Acquire I2C bus handle.

Parameters
handlePointer to FuriHalI2cBusHandle instance

◆ furi_hal_i2c_is_device_ready()

bool furi_hal_i2c_is_device_ready ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint32_t timeout )

Check if I2C device presents on bus.

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
timeoutTimeout in milliseconds
Returns
true if device present and is ready, false otherwise

◆ furi_hal_i2c_read_mem()

bool furi_hal_i2c_read_mem ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t mem_addr,
uint8_t * data,
size_t len,
uint32_t timeout )

Perform I2C device memory read.

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
mem_addrMemory start address
dataPointer to data buffer
lenSize of data buffer
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_read_reg_16()

bool furi_hal_i2c_read_reg_16 ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t reg_addr,
uint16_t * data,
uint32_t timeout )

Perform I2C device register read (16-bit)

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
reg_addrRegister address
dataPointer to register value
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_read_reg_8()

bool furi_hal_i2c_read_reg_8 ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t reg_addr,
uint8_t * data,
uint32_t timeout )

Perform I2C device register read (8-bit)

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
reg_addrRegister address
dataPointer to register value
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_release()

void furi_hal_i2c_release ( FuriHalI2cBusHandle * handle)

Release I2C bus handle.

Parameters
handlePointer to FuriHalI2cBusHandle instance acquired in furi_hal_i2c_acquire

◆ furi_hal_i2c_rx()

bool furi_hal_i2c_rx ( FuriHalI2cBusHandle * handle,
uint8_t address,
uint8_t * data,
size_t size,
uint32_t timeout )

Perform I2C RX transfer.

Parameters
handlePointer to FuriHalI2cBusHandle instance
addressI2C slave address
dataPointer to data buffer
sizeSize of data buffer
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_rx_ext()

bool furi_hal_i2c_rx_ext ( FuriHalI2cBusHandle * handle,
uint16_t address,
bool ten_bit,
uint8_t * data,
size_t size,
FuriHalI2cBegin begin,
FuriHalI2cEnd end,
uint32_t timeout )

Perform I2C RX transfer, with additional settings.

Parameters
handlePointer to FuriHalI2cBusHandle instance
addressI2C slave address
ten_bitWhether the address is 10 bits wide
dataPointer to data buffer
sizeSize of data buffer
beginHow to begin the transaction
endHow to end the transaction
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_trx()

bool furi_hal_i2c_trx ( FuriHalI2cBusHandle * handle,
uint8_t address,
const uint8_t * tx_data,
size_t tx_size,
uint8_t * rx_data,
size_t rx_size,
uint32_t timeout )

Perform I2C TX and RX transfers.

Parameters
handlePointer to FuriHalI2cBusHandle instance
addressI2C slave address
tx_dataPointer to TX data buffer
tx_sizeSize of TX data buffer
rx_dataPointer to RX data buffer
rx_sizeSize of RX data buffer
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_tx()

bool furi_hal_i2c_tx ( FuriHalI2cBusHandle * handle,
uint8_t address,
const uint8_t * data,
size_t size,
uint32_t timeout )

Perform I2C TX transfer.

Parameters
handlePointer to FuriHalI2cBusHandle instance
addressI2C slave address
dataPointer to data buffer
sizeSize of data buffer
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_tx_ext()

bool furi_hal_i2c_tx_ext ( FuriHalI2cBusHandle * handle,
uint16_t address,
bool ten_bit,
const uint8_t * data,
size_t size,
FuriHalI2cBegin begin,
FuriHalI2cEnd end,
uint32_t timeout )

Perform I2C TX transfer, with additional settings.

Parameters
handlePointer to FuriHalI2cBusHandle instance
addressI2C slave address
ten_bitWhether the address is 10 bits wide
dataPointer to data buffer
sizeSize of data buffer
beginHow to begin the transaction
endHow to end the transaction
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_write_mem()

bool furi_hal_i2c_write_mem ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t mem_addr,
const uint8_t * data,
size_t len,
uint32_t timeout )

Perform I2C device memory.

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
mem_addrMemory start address
dataPointer to data buffer
lenSize of data buffer
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_write_reg_16()

bool furi_hal_i2c_write_reg_16 ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t reg_addr,
uint16_t data,
uint32_t timeout )

Perform I2C device register write (16-bit)

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
reg_addrRegister address
dataRegister value
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise

◆ furi_hal_i2c_write_reg_8()

bool furi_hal_i2c_write_reg_8 ( FuriHalI2cBusHandle * handle,
uint8_t i2c_addr,
uint8_t reg_addr,
uint8_t data,
uint32_t timeout )

Perform I2C device register write (8-bit)

Parameters
handlePointer to FuriHalI2cBusHandle instance
i2c_addrI2C slave address
reg_addrRegister address
dataRegister value
timeoutTimeout in milliseconds
Returns
true on successful transfer, false otherwise