ICM42670 Portable Driver
Public API reference for the ICM-42670-P IMU driver
Loading...
Searching...
No Matches
ICM42670_stm32_hal.c File Reference

STM32 HAL SPI, I2C, and I3C transport adapters. More...

#include "ICM42670_stm32_hal.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for ICM42670_stm32_hal.c:

Macros

#define ICM42670_STM32_SPI_READ_BIT   0x80U
 
#define ICM42670_STM32_SPI_MAX_TRANSFER_LEN   16U
 

Functions

ICM42670_Status_t ICM42670_STM32_SPI_INIT (ICM42670_Config *config, ICM42670_STM32_SPIBus *bus, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin)
 Configure an ICM42670_Config for STM32 HAL SPI access.
 
int8_t ICM42670_STM32_SPI_ReadReg (void *handle, uint8_t reg_addr, uint8_t *data, uint16_t len)
 STM32 SPI register-read callback for ICM42670_Config.
 
int8_t ICM42670_STM32_SPI_WriteReg (void *handle, uint8_t reg_addr, const uint8_t *data, uint16_t len)
 STM32 SPI register-write callback for ICM42670_Config.
 

Detailed Description

STM32 HAL SPI, I2C, and I3C transport adapters.

Function Documentation

◆ ICM42670_STM32_SPI_INIT()

ICM42670_Status_t ICM42670_STM32_SPI_INIT ( ICM42670_Config config,
ICM42670_STM32_SPIBus bus,
SPI_HandleTypeDef *  hspi,
GPIO_TypeDef *  cs_port,
uint16_t  cs_pin 
)

Configure an ICM42670_Config for STM32 HAL SPI access.

This helper stores bus state, drives chip-select high, and installs the SPI read/write callbacks plus HAL_Delay.

Parameters
configDriver configuration to populate.
busSPI bus state owned by the caller.
hspiInitialized STM32 HAL SPI handle.
cs_portChip-select GPIO port.
cs_pinChip-select GPIO pin.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_STM32_SPIBus::cs_pin, ICM42670_STM32_SPIBus::cs_port, ICM42670_Config::delay_ms, ICM42670_Config::handle, ICM42670_STM32_SPIBus::hspi, ICM42670_ERROR, ICM42670_OK, ICM42670_STM32_SPI_ReadReg(), ICM42670_STM32_SPI_WriteReg(), ICM42670_Config::read_reg, ICM42670_STM32_SPIBus::timeout_ms, and ICM42670_Config::write_reg.

◆ ICM42670_STM32_SPI_ReadReg()

int8_t ICM42670_STM32_SPI_ReadReg ( void *  handle,
uint8_t  reg_addr,
uint8_t *  data,
uint16_t  len 
)

STM32 SPI register-read callback for ICM42670_Config.

Parameters
handlePointer to ICM42670_STM32_SPIBus.
reg_addrRegister address to read from.
dataDestination buffer.
lenNumber of bytes to read.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_STM32_SPIBus::cs_port, ICM42670_STM32_SPIBus::hspi, ICM42670_ERROR, and ICM42670_OK.

Referenced by ICM42670_STM32_SPI_INIT().

◆ ICM42670_STM32_SPI_WriteReg()

int8_t ICM42670_STM32_SPI_WriteReg ( void *  handle,
uint8_t  reg_addr,
const uint8_t *  data,
uint16_t  len 
)

STM32 SPI register-write callback for ICM42670_Config.

Parameters
handlePointer to ICM42670_STM32_SPIBus.
reg_addrRegister address to write to.
dataSource buffer.
lenNumber of bytes to write.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_STM32_SPIBus::cs_port, ICM42670_STM32_SPIBus::hspi, ICM42670_ERROR, and ICM42670_OK.

Referenced by ICM42670_STM32_SPI_INIT().