56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
|
|
|
|
#ifndef __I2CDEVICE_H__
|
|
#define __I2CDEVICE_H__
|
|
|
|
#include "i2c.h"
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <cmsis_os.h>
|
|
#include "FreeRTOS.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum eI2C_BUS_MODE {
|
|
I2C_BUS_DMA,
|
|
I2C_BUS_IT,
|
|
} I2C_BUS_MODE_t;
|
|
|
|
typedef struct sI2C_BUS {
|
|
I2C_HandleTypeDef *hi2c;
|
|
struct sI2C_BUS *next_ptr;
|
|
volatile TaskHandle_t task_waitfor_cmpl;
|
|
volatile bool task_waitfor_ret;
|
|
osMutexId mutex;
|
|
I2C_BUS_MODE_t mode;
|
|
} I2C_BUS_t;
|
|
|
|
typedef struct sI2C_DEV {
|
|
I2C_BUS_t *bus;
|
|
const char *name;
|
|
uint16_t addr;
|
|
} I2C_DEV_t;
|
|
|
|
int I2C_DEV_open(I2C_DEV_t *i2c_dev, char *name, uint16_t addr,
|
|
I2C_BUS_t *bus);
|
|
|
|
bool I2C_DEV_begin(I2C_DEV_t *i2c_dev, uint32_t millisec);
|
|
|
|
void I2C_DEV_end(I2C_DEV_t *i2c_dev);
|
|
|
|
bool I2C_DEV_read_mem(I2C_DEV_t *i2c_dev, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *buff_out, size_t len_out);
|
|
bool I2C_DEV_write_mem(I2C_DEV_t *i2c_dev, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *buff_out, size_t len_out);
|
|
bool I2C_DEV_read_registers(I2C_DEV_t *i2c_dev, uint8_t id, uint8_t *buff_out, size_t len_out);
|
|
bool I2C_DEV_write_register(I2C_DEV_t *i2c_dev, uint8_t id, uint8_t val);
|
|
bool I2C_DEV_transfer(I2C_DEV_t *i2c_dev, const uint8_t *buff_tx, size_t len_tx, uint8_t *buff_rx, size_t len_rx);
|
|
bool I2C_DEV_receive(I2C_DEV_t *i2c_dev, uint8_t *buff_rx, size_t len_rx);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
|
|
#endif /* __I2CDEVICE_H__ */
|