Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions components/drivers/include/drivers/dev_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ rt_err_t rt_spi_driver_register(struct rt_spi_driver *driver);
rt_err_t rt_spi_device_register(struct rt_spi_device *device);

#define RT_SPI_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, spi, BUILIN)

rt_inline const void *rt_spi_device_id_data(struct rt_spi_device *device)
{
return device->id ? device->id->data : (device->ofw_id ? device->ofw_id->data : RT_NULL);
}
#endif /* RT_USING_DM */

/**
Expand Down Expand Up @@ -598,7 +603,7 @@ rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const st
*
* @return the actual length of transmitted.
*/
rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message);
rt_ssize_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message);

/**
* @brief This function can send data then receive data from QSPI device
Expand All @@ -611,7 +616,7 @@ rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qsp
*
* @return the status of transmit.
*/
rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length,void *recv_buf, rt_size_t recv_length);
rt_ssize_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length,void *recv_buf, rt_size_t recv_length);

/**
* @brief This function can send data to QSPI device
Expand All @@ -622,7 +627,7 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
*
* @return the status of transmit.
*/
rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length);
rt_ssize_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length);

#ifdef __cplusplus
}
Expand Down
6 changes: 5 additions & 1 deletion components/drivers/spi/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
config RT_USING_SPI
menuconfig RT_USING_SPI
bool "Using SPI Bus/Device device drivers"
default n

Expand Down Expand Up @@ -235,3 +235,7 @@ config RT_USING_SPI
select RT_USING_LWIP
default n
endif

if RT_USING_DM && RT_USING_SPI
osource "$(SOC_DM_SPI_DIR)/Kconfig"
endif
32 changes: 15 additions & 17 deletions components/drivers/spi/dev_qspi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "drivers/dev_spi.h"

extern rt_err_t spi_bus_register(struct rt_spi_bus *bus,
const char *name,
const struct rt_spi_ops *ops);

rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configuration *cfg)
{
RT_ASSERT(device != RT_NULL);
Expand Down Expand Up @@ -67,21 +71,15 @@ rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configu

rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops)
{
rt_err_t result = RT_EOK;

result = rt_spi_bus_register(bus, name, ops);
if(result == RT_EOK)
{
/* set SPI bus to qspi modes */
bus->mode = RT_SPI_BUS_MODE_QSPI;
}
/* set SPI bus to qspi modes */
bus->mode = RT_SPI_BUS_MODE_QSPI;

return result;
return spi_bus_register(bus, name, ops);
}

rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message)
rt_ssize_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message)
{
rt_err_t result;
rt_ssize_t result;

RT_ASSERT(device != RT_NULL);
RT_ASSERT(message != RT_NULL);
Expand Down Expand Up @@ -130,7 +128,7 @@ rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qsp
return result;
}

rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length)
rt_ssize_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length)
{
RT_ASSERT(send_buf);
RT_ASSERT(recv_buf);
Expand All @@ -139,7 +137,7 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
struct rt_qspi_message message;
unsigned char *ptr = (unsigned char *)send_buf;
rt_size_t count = 0;
rt_err_t result = 0;
rt_ssize_t result = 0;

message.instruction.content = ptr[0];
message.instruction.qspi_lines = 1;
Expand Down Expand Up @@ -208,23 +206,23 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
{
result = -RT_EIO;
}
else
else if (result > 0)
{
result = recv_length;
}

return result;
}

rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length)
rt_ssize_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length)
{
RT_ASSERT(send_buf);
RT_ASSERT(length != 0);

struct rt_qspi_message message;
unsigned char *ptr = (unsigned char *)send_buf;
rt_size_t count = 0;
rt_err_t result = 0;
rt_ssize_t result = 0;

message.instruction.content = ptr[0];
message.instruction.qspi_lines = 1;
Expand Down Expand Up @@ -294,7 +292,7 @@ rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_si
{
result = -RT_EIO;
}
else
else if (result > 0)
{
result = length;
}
Expand Down
14 changes: 13 additions & 1 deletion components/drivers/spi/dev_spi_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ void spi_bus_scan_devices(struct rt_spi_bus *bus)
continue;
}

spi_dev = rt_calloc(1, sizeof(*spi_dev));
if ((bus->mode & RT_SPI_BUS_MODE_SPI) == RT_SPI_BUS_MODE_SPI)
{
spi_dev = rt_calloc(1, sizeof(struct rt_spi_device));
}
else if ((bus->mode & RT_SPI_BUS_MODE_QSPI) == RT_SPI_BUS_MODE_QSPI)
{
spi_dev = rt_calloc(1, sizeof(struct rt_qspi_device));
}
else
{
LOG_E("Unknown bus mode = %x", bus->mode);
RT_ASSERT(0);
}

if (!spi_dev)
{
Expand Down
18 changes: 13 additions & 5 deletions components/drivers/spi/dev_spi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
extern rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name);
extern rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name);

rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
const char *name,
const struct rt_spi_ops *ops)
rt_err_t spi_bus_register(struct rt_spi_bus *bus,
const char *name,
const struct rt_spi_ops *ops)
{
rt_err_t result;

Expand All @@ -42,8 +42,6 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
bus->ops = ops;
/* initialize owner */
bus->owner = RT_NULL;
/* set bus mode */
bus->mode = RT_SPI_BUS_MODE_SPI;

#ifdef RT_USING_DM
if (!bus->slave)
Expand Down Expand Up @@ -77,6 +75,16 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
return RT_EOK;
}

rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
const char *name,
const struct rt_spi_ops *ops)
{
/* set bus mode */
bus->mode = RT_SPI_BUS_MODE_SPI;

return spi_bus_register(bus, name, ops);
}

rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
const char *name,
const char *bus_name,
Expand Down
Loading