1.新增软件I2C总线。
This commit is contained in:
9
Kconfig
9
Kconfig
@@ -49,7 +49,7 @@ menu "Device configure"
|
||||
|
||||
config MR_CFG_DESC_MAX
|
||||
int "Max number of descriptors"
|
||||
default 32
|
||||
default 64
|
||||
range 16 1024
|
||||
help
|
||||
"Maximum number of descriptors"
|
||||
@@ -133,6 +133,13 @@ menu "Device configure"
|
||||
range 0 MR_CFG_HEAP_SIZE
|
||||
help
|
||||
"This option sets the size of the RX (receive) buffer used by the I2C device."
|
||||
|
||||
config MR_USING_SOFT_I2C
|
||||
depends on MR_USING_PIN
|
||||
bool "Enable soft I2C"
|
||||
default n
|
||||
help
|
||||
"Enabling this option allows for the use of soft I2C."
|
||||
endmenu
|
||||
|
||||
config MR_USING_PIN
|
||||
|
||||
@@ -100,13 +100,6 @@ static int drv_i2c_bus_configure(struct mr_i2c_bus *i2c_bus, struct mr_i2c_confi
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(i2c_bus_data->sda_port, &GPIO_InitStructure);
|
||||
}
|
||||
if (config->host_slave == MR_I2C_HOST)
|
||||
{
|
||||
I2C_AcknowledgeConfig(i2c_bus_data->instance, state);
|
||||
} else
|
||||
{
|
||||
I2C_AcknowledgeConfig(i2c_bus_data->instance, DISABLE);
|
||||
}
|
||||
|
||||
/* Configure I2C */
|
||||
I2C_InitStructure.I2C_ClockSpeed = config->baud_rate;
|
||||
@@ -116,6 +109,7 @@ static int drv_i2c_bus_configure(struct mr_i2c_bus *i2c_bus, struct mr_i2c_confi
|
||||
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_Init(i2c_bus_data->instance, &I2C_InitStructure);
|
||||
I2C_Cmd(i2c_bus_data->instance, state);
|
||||
I2C_AcknowledgeConfig(i2c_bus_data->instance, state);
|
||||
|
||||
/* Configure NVIC */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = i2c_bus_data->irq;
|
||||
@@ -187,11 +181,14 @@ static void drv_i2c_bus_stop(struct mr_i2c_bus *i2c_bus)
|
||||
I2C_GenerateSTOP(i2c_bus_data->instance, ENABLE);
|
||||
}
|
||||
|
||||
static uint8_t drv_i2c_bus_read(struct mr_i2c_bus *i2c_bus)
|
||||
static uint8_t drv_i2c_bus_read(struct mr_i2c_bus *i2c_bus, int ack_state)
|
||||
{
|
||||
struct drv_i2c_bus_data *i2c_bus_data = (struct drv_i2c_bus_data *)i2c_bus->dev.drv->data;
|
||||
int i = 0;
|
||||
|
||||
/* Control ack */
|
||||
I2C_AcknowledgeConfig(i2c_bus_data->instance, ack_state);
|
||||
|
||||
/* Read data */
|
||||
while (I2C_CheckEvent(i2c_bus_data->instance, I2C_EVENT_MASTER_BYTE_RECEIVED) == RESET)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ static ssize_t mr_i2c_bus_isr(struct mr_dev *dev, int event, void *args)
|
||||
case MR_ISR_I2C_RD_INT:
|
||||
{
|
||||
struct mr_i2c_dev *i2c_dev = (struct mr_i2c_dev *)i2c_bus->owner;
|
||||
uint8_t data = ops->read(i2c_bus);
|
||||
uint8_t data = ops->read(i2c_bus, MR_ENABLE);
|
||||
|
||||
/* Read data to FIFO. if callback is set, call it */
|
||||
mr_ringbuf_push_force(&i2c_dev->rd_fifo, data);
|
||||
@@ -196,7 +196,7 @@ MR_INLINE ssize_t i2c_dev_read(struct mr_i2c_dev *i2c_dev, uint8_t *buf, size_t
|
||||
|
||||
for (rd_size = 0; rd_size < size; rd_size += sizeof(*rd_buf))
|
||||
{
|
||||
*rd_buf = ops->read(i2c_bus);
|
||||
*rd_buf = ops->read(i2c_bus, (size - rd_size) == sizeof(*rd_buf));
|
||||
rd_buf++;
|
||||
}
|
||||
return rd_size;
|
||||
@@ -379,7 +379,7 @@ static int mr_i2c_dev_ioctl(struct mr_dev *dev, int off, int cmd, void *args)
|
||||
}
|
||||
case MR_CTL_I2C_GET_RD_DATASZ:
|
||||
{
|
||||
if (args!= MR_NULL)
|
||||
if (args != MR_NULL)
|
||||
{
|
||||
size_t *size = (size_t *)args;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ struct mr_i2c_bus_ops
|
||||
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);
|
||||
uint8_t (*read)(struct mr_i2c_bus *i2c_bus);
|
||||
uint8_t (*read)(struct mr_i2c_bus *i2c_bus, int ack_state);
|
||||
void (*write)(struct mr_i2c_bus *i2c_bus, uint8_t data);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user