1.路径优化。
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* @date 2023-11-06 MacRsh First version
|
||||
*/
|
||||
|
||||
#include "include/device/adc.h"
|
||||
#include "adc.h"
|
||||
|
||||
#ifdef MR_USING_ADC
|
||||
|
||||
@@ -66,7 +66,7 @@ static int mr_adc_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MR_CTRL_ADC_SET_CHANNEL_STATE:
|
||||
case MR_CTL_ADC_SET_CHANNEL_STATE:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ static int mr_adc_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
case MR_CTRL_ADC_GET_CHANNEL_STATE:
|
||||
case MR_CTL_ADC_GET_CHANNEL_STATE:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -154,7 +154,7 @@ int mr_adc_register(struct mr_adc *adc, const char *name, struct mr_drv *drv)
|
||||
adc->channel = 0;
|
||||
|
||||
/* Register the adc */
|
||||
return mr_dev_register(&adc->dev, name, Mr_Dev_Type_Adc, MR_SFLAG_RDONLY, &ops, drv);
|
||||
return mr_dev_register(&adc->dev, name, Mr_Dev_Type_ADC, MR_SFLAG_RDONLY, &ops, drv);
|
||||
}
|
||||
|
||||
#endif /* MR_USING_ADC */
|
||||
|
||||
75
device/adc.h
Normal file
75
device/adc.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* @copyright (c) 2023, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-06 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_ADC_H_
|
||||
#define _MR_ADC_H_
|
||||
|
||||
#include "mr_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef MR_USING_ADC
|
||||
|
||||
/**
|
||||
* @brief ADC channel state.
|
||||
*/
|
||||
#define MR_ADC_STATE_DISABLE MR_DISABLE /**< ADC disabled */
|
||||
#define MR_ADC_STATE_ENABLE MR_ENABLE /**< ADC enabled */
|
||||
|
||||
/**
|
||||
* @brief ADC channel state command.
|
||||
*/
|
||||
#define MR_CTL_ADC_SET_CHANNEL_STATE ((0x01|0x80) << 16) /**< Set channel state */
|
||||
#define MR_CTL_ADC_GET_CHANNEL_STATE ((0x01|0x00) << 16) /**< Get channel state */
|
||||
|
||||
/**
|
||||
* @brief ADC channel command.
|
||||
*/
|
||||
#define MR_CTL_ADC_SET_CHANNEL MR_CTL_SET_OFFSET /**< Set channel */
|
||||
#define MR_CTL_ADC_GET_CHANNEL MR_CTL_GET_OFFSET /**< Get channel */
|
||||
|
||||
/**
|
||||
* @brief ADC data type.
|
||||
*/
|
||||
typedef uint32_t mr_adc_data_t; /**< ADC read data type */
|
||||
|
||||
/**
|
||||
* @brief ADC structure.
|
||||
*/
|
||||
struct mr_adc
|
||||
{
|
||||
struct mr_dev dev; /**< Device */
|
||||
|
||||
uint32_t channel; /**< Channel */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADC operations structure.
|
||||
*/
|
||||
struct mr_adc_ops
|
||||
{
|
||||
int (*configure)(struct mr_adc *adc, int state);
|
||||
int (*channel_configure)(struct mr_adc *adc, int channel, int state);
|
||||
uint32_t (*read)(struct mr_adc *adc, int channel);
|
||||
};
|
||||
|
||||
/**
|
||||
* @addtogroup ADC.
|
||||
* @{
|
||||
*/
|
||||
int mr_adc_register(struct mr_adc *adc, const char *name, struct mr_drv *drv);
|
||||
/** @} */
|
||||
#endif /* MR_USING_ADC */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_ADC_H_ */
|
||||
14
device/can.c
14
device/can.c
@@ -6,7 +6,7 @@
|
||||
* @date 2023-11-22 MacRsh First version
|
||||
*/
|
||||
|
||||
#include "include/device/can.h"
|
||||
#include "can.h"
|
||||
|
||||
#ifdef MR_USING_CAN
|
||||
|
||||
@@ -114,7 +114,7 @@ int mr_can_bus_register(struct mr_can_bus *can_bus, const char *name, struct mr_
|
||||
can_bus->owner = MR_NULL;
|
||||
|
||||
/* Register the can-bus */
|
||||
return mr_dev_register(&can_bus->dev, name, Mr_Dev_Type_Can, MR_SFLAG_RDWR, &ops, drv);
|
||||
return mr_dev_register(&can_bus->dev, name, Mr_Dev_Type_CAN, MR_SFLAG_RDWR, &ops, drv);
|
||||
}
|
||||
|
||||
static int can_dev_filter_configure(struct mr_can_dev *can_dev, int id, int ide, int state)
|
||||
@@ -276,7 +276,7 @@ static int mr_can_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MR_CTRL_SET_CONFIG:
|
||||
case MR_CTL_SET_CONFIG:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -295,7 +295,7 @@ static int mr_can_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
}
|
||||
return MR_EINVAL;
|
||||
}
|
||||
case MR_CTRL_SET_RD_BUFSZ:
|
||||
case MR_CTL_SET_RD_BUFSZ:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -312,7 +312,7 @@ static int mr_can_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
case MR_CTRL_GET_CONFIG:
|
||||
case MR_CTL_GET_CONFIG:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -323,7 +323,7 @@ static int mr_can_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
}
|
||||
return MR_EINVAL;
|
||||
}
|
||||
case MR_CTRL_GET_RD_BUFSZ:
|
||||
case MR_CTL_GET_RD_BUFSZ:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -377,7 +377,7 @@ int mr_can_dev_register(struct mr_can_dev *can_dev, const char *name, int id, in
|
||||
can_dev->ide = ide;
|
||||
|
||||
/* Register the can-dev */
|
||||
return mr_dev_register(&can_dev->dev, name, Mr_Dev_Type_Can, MR_SFLAG_RDWR | MR_SFLAG_NONDRV, &ops, MR_NULL);
|
||||
return mr_dev_register(&can_dev->dev, name, Mr_Dev_Type_CAN, MR_SFLAG_RDWR | MR_SFLAG_NONDRV, &ops, MR_NULL);
|
||||
}
|
||||
|
||||
#endif /* MR_USING_CAN */
|
||||
|
||||
127
device/can.h
Normal file
127
device/can.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* @copyright (c) 2023, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-22 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _CAN_H_
|
||||
#define _CAN_H_
|
||||
|
||||
#include "mr_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef MR_USING_CAN
|
||||
|
||||
/**
|
||||
* @brief CAN default configuration.
|
||||
*/
|
||||
#define MR_CAN_CONFIG_DEFAULT \
|
||||
{ \
|
||||
500000, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CAN configuration structure.
|
||||
*/
|
||||
struct mr_can_config
|
||||
{
|
||||
uint32_t baud_rate; /**< Baud rate */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CAN identifier.
|
||||
*/
|
||||
#define MR_CAN_IDE_STD (0 << 29)
|
||||
#define MR_CAN_IDE_EXT (1 << 29)
|
||||
|
||||
/**
|
||||
* @brief CAN remote transmission request.
|
||||
*/
|
||||
#define MR_CAN_RTR_DATA (0 << 30)
|
||||
#define MR_CAN_RTR_REMOTE (1 << 30)
|
||||
|
||||
/**
|
||||
* @brief Help to set id.
|
||||
*/
|
||||
#define MR_CAN_ID(id, ide, rtr) ((id) | (ide) | (rtr)) /**< Set id-ide-rtr */
|
||||
|
||||
/**
|
||||
* @brief CAN id command.
|
||||
*/
|
||||
#define MR_CTL_CAN_SET_ID MR_CTL_SET_OFFSET /**< Set id */
|
||||
#define MR_CTL_CAN_GET_ID MR_CTL_GET_OFFSET /**< Get id */
|
||||
|
||||
/**
|
||||
* @brief CAN data type.
|
||||
*/
|
||||
typedef uint8_t mr_can_data_t; /**< CAN read/write data type */
|
||||
|
||||
/**
|
||||
* @brief CAN ISR events.
|
||||
*/
|
||||
#define MR_ISR_CAN_RD_INT (MR_ISR_RD | (0x01 << 16)) /**< Read interrupt */
|
||||
|
||||
/**
|
||||
* @brief CAN bus structure.
|
||||
*/
|
||||
struct mr_can_bus
|
||||
{
|
||||
struct mr_dev dev; /**< Device */
|
||||
|
||||
struct mr_can_config config; /**< Configuration */
|
||||
volatile void *owner; /**< Owner */
|
||||
volatile int hold; /**< Owner hold */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CAN bus operations structure.
|
||||
*/
|
||||
struct mr_can_bus_ops
|
||||
{
|
||||
int (*configure)(struct mr_can_bus *can_bus, struct mr_can_config *config);
|
||||
int (*filter_configure)(struct mr_can_bus *can_bus, int id, int ide, int state);
|
||||
int (*get_id)(struct mr_can_bus *can_bus);
|
||||
ssize_t (*read)(struct mr_can_bus *can_bus, uint8_t *buf, size_t size);
|
||||
ssize_t (*write)(struct mr_can_bus *can_bus, int id, int ide, int rtr, const uint8_t *buf, size_t size);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CAN id identifier.
|
||||
*/
|
||||
#define MR_CAN_ID_STD (0) /**< Standard identifier */
|
||||
#define MR_CAN_ID_EXT (1) /**< Extended identifier */
|
||||
|
||||
/**
|
||||
* @brief CAN device structure.
|
||||
*/
|
||||
struct mr_can_dev
|
||||
{
|
||||
struct mr_dev dev;
|
||||
|
||||
struct mr_can_config config;
|
||||
struct mr_ringbuf rd_fifo;
|
||||
size_t rd_bufsz;
|
||||
uint32_t id: 29;
|
||||
uint32_t ide: 1;
|
||||
uint32_t reserved: 2;
|
||||
};
|
||||
|
||||
/**
|
||||
* @addtogroup CAN.
|
||||
* @{
|
||||
*/
|
||||
int mr_can_bus_register(struct mr_can_bus *can_bus, const char *name, struct mr_drv *drv);
|
||||
int mr_can_dev_register(struct mr_can_dev *can_dev, const char *name, int id, int ide);
|
||||
/** @} */
|
||||
#endif /* MR_USING_CAN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _CAN_H_ */
|
||||
@@ -6,7 +6,7 @@
|
||||
* @date 2023-11-08 MacRsh First version
|
||||
*/
|
||||
|
||||
#include "include/device/dac.h"
|
||||
#include "dac.h"
|
||||
|
||||
#ifdef MR_USING_DAC
|
||||
|
||||
@@ -66,7 +66,7 @@ static int mr_dac_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MR_CTRL_DAC_SET_CHANNEL_STATE:
|
||||
case MR_CTL_DAC_SET_CHANNEL_STATE:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -94,7 +94,7 @@ static int mr_dac_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
case MR_CTRL_DAC_GET_CHANNEL_STATE:
|
||||
case MR_CTL_DAC_GET_CHANNEL_STATE:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -149,7 +149,7 @@ int mr_dac_register(struct mr_dac *dac, const char *name, struct mr_drv *drv)
|
||||
dac->channel = 0;
|
||||
|
||||
/* Register the dac */
|
||||
return mr_dev_register(&dac->dev, name, Mr_Dev_Type_Dac, MR_SFLAG_WRONLY, &ops, drv);
|
||||
return mr_dev_register(&dac->dev, name, Mr_Dev_Type_DAC, MR_SFLAG_WRONLY, &ops, drv);
|
||||
}
|
||||
|
||||
#endif /* MR_USING_DAC */
|
||||
|
||||
76
device/dac.h
Normal file
76
device/dac.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* @copyright (c) 2023, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-08 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_DAC_H_
|
||||
#define _MR_DAC_H_
|
||||
|
||||
#include "mr_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef MR_USING_DAC
|
||||
|
||||
/**
|
||||
* @brief DAC channel state.
|
||||
*/
|
||||
#define MR_DAC_STATE_DISABLE MR_DISABLE /**< DAC disabled */
|
||||
#define MR_DAC_STATE_ENABLE MR_ENABLE /**< DAC enabled */
|
||||
|
||||
/**
|
||||
* @brief DAC channel state command.
|
||||
*/
|
||||
#define MR_CTL_DAC_SET_CHANNEL_STATE ((0x01|0x80) << 16) /**< Set channel state */
|
||||
#define MR_CTL_DAC_GET_CHANNEL_STATE ((0x01|0x00) << 16) /**< Get channel state */
|
||||
|
||||
/**
|
||||
* @brief DAC channel command.
|
||||
*/
|
||||
#define MR_CTL_DAC_SET_CHANNEL MR_CTL_SET_OFFSET /**< Set channel */
|
||||
#define MR_CTL_DAC_GET_CHANNEL MR_CTL_GET_OFFSET /**< Get channel */
|
||||
|
||||
/**
|
||||
* @brief DAC data type.
|
||||
*/
|
||||
typedef uint32_t mr_dac_data_t; /**< DAC write data type */
|
||||
|
||||
/**
|
||||
* @brief DAC structure.
|
||||
*/
|
||||
struct mr_dac
|
||||
{
|
||||
struct mr_dev dev; /**< Device */
|
||||
|
||||
uint32_t channel; /**< Channel */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief DAC operations structure.
|
||||
*/
|
||||
struct mr_dac_ops
|
||||
{
|
||||
int (*configure)(struct mr_dac *dac, int state);
|
||||
int (*channel_configure)(struct mr_dac *dac, int channel, int state);
|
||||
void (*write)(struct mr_dac *dac, int channel, uint32_t data);
|
||||
};
|
||||
|
||||
/**
|
||||
* @addtogroup DAC.
|
||||
* @{
|
||||
*/
|
||||
int mr_dac_register(struct mr_dac *dac, const char *name, struct mr_drv *drv);
|
||||
/** @} */
|
||||
|
||||
#endif /* MR_USING_DAC */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_DAC_H_ */
|
||||
14
device/i2c.c
14
device/i2c.c
@@ -6,7 +6,7 @@
|
||||
* @date 2023-11-09 MacRsh First version
|
||||
*/
|
||||
|
||||
#include "include/device/i2c.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#ifdef MR_USING_I2C
|
||||
|
||||
@@ -103,7 +103,7 @@ int mr_i2c_bus_register(struct mr_i2c_bus *i2c_bus, const char *name, struct mr_
|
||||
i2c_bus->hold = MR_FALSE;
|
||||
|
||||
/* Register the i2c-bus */
|
||||
return mr_dev_register(&i2c_bus->dev, name, Mr_Dev_Type_I2c, MR_SFLAG_RDWR, &ops, drv);
|
||||
return mr_dev_register(&i2c_bus->dev, name, Mr_Dev_Type_I2C, MR_SFLAG_RDWR, &ops, drv);
|
||||
}
|
||||
|
||||
MR_INLINE int i2c_dev_take_bus(struct mr_i2c_dev *i2c_dev)
|
||||
@@ -294,7 +294,7 @@ static int mr_i2c_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MR_CTRL_SET_CONFIG:
|
||||
case MR_CTL_SET_CONFIG:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -322,7 +322,7 @@ static int mr_i2c_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
}
|
||||
return MR_EINVAL;
|
||||
}
|
||||
case MR_CTRL_SET_RD_BUFSZ:
|
||||
case MR_CTL_SET_RD_BUFSZ:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -339,7 +339,7 @@ static int mr_i2c_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
return MR_EINVAL;
|
||||
}
|
||||
|
||||
case MR_CTRL_GET_CONFIG:
|
||||
case MR_CTL_GET_CONFIG:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -350,7 +350,7 @@ static int mr_i2c_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
}
|
||||
return MR_EINVAL;
|
||||
}
|
||||
case MR_CTRL_GET_RD_BUFSZ:
|
||||
case MR_CTL_GET_RD_BUFSZ:
|
||||
{
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
@@ -405,7 +405,7 @@ int mr_i2c_dev_register(struct mr_i2c_dev *i2c_dev, const char *name, int addr,
|
||||
i2c_dev->addr_bits = addr_bits;
|
||||
|
||||
/* Register the i2c-device */
|
||||
return mr_dev_register(&i2c_dev->dev, name, Mr_Dev_Type_I2c, MR_SFLAG_RDWR | MR_SFLAG_NONDRV, &ops, MR_NULL);
|
||||
return mr_dev_register(&i2c_dev->dev, name, Mr_Dev_Type_I2C, MR_SFLAG_RDWR | MR_SFLAG_NONDRV, &ops, MR_NULL);
|
||||
}
|
||||
|
||||
#endif /* MR_USING_I2C */
|
||||
|
||||
128
device/i2c.h
Normal file
128
device/i2c.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* @copyright (c) 2023, MR Development Team
|
||||
*
|
||||
* @license SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @date 2023-11-09 MacRsh First version
|
||||
*/
|
||||
|
||||
#ifndef _MR_I2C_H_
|
||||
#define _MR_I2C_H_
|
||||
|
||||
#include "mr_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef MR_USING_I2C
|
||||
|
||||
/**
|
||||
* @brief I2C host/slave.
|
||||
*/
|
||||
#define MR_I2C_HOST (0) /**< I2C host */
|
||||
#define MR_I2C_SLAVE (1) /**< I2C slave */
|
||||
|
||||
/**
|
||||
* @brief I2C register bits.
|
||||
*/
|
||||
#define MR_I2C_REG_BITS_8 (8) /**< 8 bits register */
|
||||
#define MR_I2C_REG_BITS_16 (16) /**< 16 bits register */
|
||||
#define MR_I2C_REG_BITS_32 (32) /**< 32 bits register */
|
||||
|
||||
/**
|
||||
* @brief I2C default configuration.
|
||||
*/
|
||||
#define MR_I2C_CONFIG_DEFAULT \
|
||||
{ \
|
||||
100000, \
|
||||
MR_I2C_HOST, \
|
||||
MR_I2C_REG_BITS_8, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C configuration structure.
|
||||
*/
|
||||
struct mr_i2c_config
|
||||
{
|
||||
uint32_t baud_rate; /**< Baud rate */
|
||||
uint32_t host_slave: 1; /**< Host/slave */
|
||||
uint32_t reg_bits: 6; /**< Register bits */
|
||||
uint32_t reserved: 25;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief I2C register command.
|
||||
*/
|
||||
#define MR_CTL_I2C_SET_REG MR_CTL_SET_OFFSET /**< Set register */
|
||||
#define MR_CTL_I2C_GET_REG MR_CTL_GET_OFFSET /**< Get register */
|
||||
|
||||
/**
|
||||
* @brief I2C data type.
|
||||
*/
|
||||
typedef uint8_t mr_i2c_data_t; /**< I2C read/write data type */
|
||||
|
||||
/**
|
||||
* @brief I2C ISR events.
|
||||
*/
|
||||
#define MR_ISR_I2C_RD_INT (MR_ISR_RD | (0x01 << 16)) /**< Read interrupt */
|
||||
|
||||
/**
|
||||
* @brief I2C bus structure.
|
||||
*/
|
||||
struct mr_i2c_bus
|
||||
{
|
||||
struct mr_dev dev; /**< Device */
|
||||
|
||||
struct mr_i2c_config config; /**< Configuration */
|
||||
volatile void *owner; /**< Owner */
|
||||
volatile int hold; /**< Owner hold */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief I2C bus operations structure.
|
||||
*/
|
||||
struct mr_i2c_bus_ops
|
||||
{
|
||||
int (*configure)(struct mr_i2c_bus *i2c_bus, struct mr_i2c_config *config, int addr, int addr_bits);
|
||||
void (*start)(struct mr_i2c_bus *i2c_bus);
|
||||
void (*send_addr)(struct mr_i2c_bus *i2c_bus, int addr, int addr_bits);
|
||||
void (*stop)(struct mr_i2c_bus *i2c_bus);
|
||||
ssize_t (*read)(struct mr_i2c_bus *i2c_bus, uint8_t *buf, size_t size);
|
||||
ssize_t (*write)(struct mr_i2c_bus *i2c_bus, const uint8_t *buf, size_t size);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief I2C device address bits.
|
||||
*/
|
||||
#define MR_I2C_ADDR_BITS_7 (7) /**< 7 bit address */
|
||||
#define MR_I2C_ADDR_BITS_10 (10) /**< 10 bit address */
|
||||
|
||||
/**
|
||||
* @brief I2C device structure.
|
||||
*/
|
||||
struct mr_i2c_dev
|
||||
{
|
||||
struct mr_dev dev; /**< Device */
|
||||
|
||||
struct mr_i2c_config config; /**< Configuration */
|
||||
struct mr_ringbuf rd_fifo; /**< Read FIFO */
|
||||
size_t rd_bufsz; /**< Read buffer size */
|
||||
uint32_t addr: 16; /**< Address */
|
||||
uint32_t addr_bits: 16; /**< Address bits */
|
||||
};
|
||||
|
||||
/**
|
||||
* @addtogroup I2C.
|
||||
* @{
|
||||
*/
|
||||
int mr_i2c_bus_register(struct mr_i2c_bus *i2c_bus, const char *name, struct mr_drv *drv);
|
||||
int mr_i2c_dev_register(struct mr_i2c_dev *i2c_dev, const char *name, int addr, int addr_bits);
|
||||
/** @} */
|
||||
#endif /* MR_USING_I2C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _MR_I2C_H_ */
|
||||
Reference in New Issue
Block a user