mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
feature: driver: Add a Linux SPI into simulator.
N/A When SIM_SPI is valid, a specified Linux SPI device ‘spidevN.P’(N is bus number and P is CS number) is attached to nuttx simulator, shown as 'spi0' under /dev. One may type spi command (need SPITOOL valid) in NSH to control the Linux SPI and exchange data, other devices such sensors can use it to debug in simulator on a Ubuntu PC. Note that a USB<>SPI module (e.g. CH341A/B) should be plugged in to achieve Linux SPI ports. Change-Id: I275b2c2bbf6d14bcdf514c89efb9a2264d69e9a3 Signed-off-by: liucheng5 <liucheng5@xiaomi.com>
This commit is contained in:
@@ -58,7 +58,6 @@ config SIM_WTGAHRS2_UARTN
|
||||
---help---
|
||||
We can select the number accoding to which SIM_UARTX_NAME is uesd to sensor.
|
||||
This range is 0-4.
|
||||
endif
|
||||
|
||||
config SIM_I2CBUS_ID
|
||||
int "I2C host bus ID to attach to simulator"
|
||||
@@ -67,3 +66,13 @@ config SIM_I2CBUS_ID
|
||||
---help---
|
||||
This is the bus identifier that should be used by the host implementation to
|
||||
attach to the simulator driver.
|
||||
|
||||
config SIM_SPIDEV_NAME
|
||||
string "the name of SPI host dev to attach to simulator"
|
||||
default "/dev/spidev0.0"
|
||||
depends on SIM_SPI
|
||||
---help---
|
||||
This is the name of the SPI device on the host implementation to
|
||||
attach to the simulator driver.
|
||||
|
||||
endif
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#include <nuttx/fs/hostfs_rpmsg.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/spi/spi_transfer.h>
|
||||
#include <nuttx/rc/lirc_dev.h>
|
||||
#include <nuttx/rc/dummy.h>
|
||||
#include <nuttx/sensors/fakesensor.h>
|
||||
@@ -101,6 +102,9 @@ int sim_bringup(void)
|
||||
#ifdef CONFIG_MPU60X0_I2C
|
||||
FAR struct mpu_config_s *mpu_config;
|
||||
#endif
|
||||
#ifdef CONFIG_SIM_SPI
|
||||
FAR struct spi_dev_s *spidev;
|
||||
#endif
|
||||
|
||||
int ret = OK;
|
||||
|
||||
@@ -405,6 +409,26 @@ int sim_bringup(void)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SIM_SPI
|
||||
spidev = sim_spi_initialize(CONFIG_SIM_SPIDEV_NAME);
|
||||
if (spidev == NULL)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: sim_spi_initialize failed.\n");
|
||||
}
|
||||
#ifdef CONFIG_SYSTEM_SPITOOL
|
||||
else
|
||||
{
|
||||
ret = spi_register(spidev, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register SPI%d driver: %d\n",
|
||||
0, ret);
|
||||
sim_spi_uninitialize(spidev);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_SYSTEM_SPITOOL */
|
||||
#endif /* CONFIG_SIM_SPI */
|
||||
|
||||
#if defined(CONFIG_INPUT_BUTTONS_LOWER) && defined(CONFIG_SIM_BUTTONS)
|
||||
ret = btn_lower_initialize("/dev/buttons");
|
||||
if (ret < 0)
|
||||
|
||||
Reference in New Issue
Block a user