[bsp][hc32] 修复SPI驱动的片选脚获取方式

This commit is contained in:
Kai 2024-10-28 10:51:32 +08:00 committed by Meco Man
parent e83b8fd820
commit 91eca8d573
1 changed files with 8 additions and 16 deletions

View File

@ -496,24 +496,20 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL); RT_ASSERT(device->bus != RT_NULL);
RT_ASSERT(device->bus->parent.user_data != RT_NULL);
RT_ASSERT(message != RT_NULL); RT_ASSERT(message != RT_NULL);
struct hc32_spi *spi_drv = rt_container_of(device->bus, struct hc32_spi, spi_bus); struct hc32_spi *spi_drv = rt_container_of(device->bus, struct hc32_spi, spi_bus);
CM_SPI_TypeDef *spi_instance = spi_drv->config->Instance; CM_SPI_TypeDef *spi_instance = spi_drv->config->Instance;
struct hc32_hw_spi_cs *cs = device->parent.user_data;
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS)) if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
{ {
if (device->config.mode & RT_SPI_CS_HIGH) if (device->config.mode & RT_SPI_CS_HIGH)
{ rt_pin_write(device->cs_pin, PIN_HIGH);
GPIO_SetPins(cs->port, cs->pin);
}
else else
{ rt_pin_write(device->cs_pin, PIN_LOW);
GPIO_ResetPins(cs->port, cs->pin);
}
} }
LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name, LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name,
(uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length); (uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length);
@ -621,16 +617,12 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
/* clear error flag */ /* clear error flag */
SPI_ClearStatus(spi_instance, SPI_FLAG_CLR_ALL); SPI_ClearStatus(spi_instance, SPI_FLAG_CLR_ALL);
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS)) if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
{ {
if (device->config.mode & RT_SPI_CS_HIGH) if (device->config.mode & RT_SPI_CS_HIGH)
{ rt_pin_write(device->cs_pin, PIN_LOW);
GPIO_ResetPins(cs->port, cs->pin);
}
else else
{ rt_pin_write(device->cs_pin, PIN_HIGH);
GPIO_SetPins(cs->port, cs->pin);
}
} }
return message->length; return message->length;