diff --git a/system/spi/spi_common.c b/system/spi/spi_common.c index d23692399..21017ceca 100644 --- a/system/spi/spi_common.c +++ b/system/spi/spi_common.c @@ -156,6 +156,26 @@ int spitool_common_args(FAR struct spitool_s *spitool, FAR char **arg) spitool->mode = value; return ret; + case 'n': + ret = arg_decimal(arg, &value); + if ((value < 0) || (value > 0xffff)) + { + goto out_of_range; + } + + spitool->csn = value; + return ret; + + case 't': + ret = arg_decimal(arg, &value); + if ((value < 0) || (value > SPIDEVTYPE_USER)) + { + goto out_of_range; + } + + spitool->devtype = value; + return ret; + case 'f': ret = arg_decimal(arg, &value); if (value == 0) diff --git a/system/spi/spi_exch.c b/system/spi/spi_exch.c index 087d50bb8..bd9677586 100644 --- a/system/spi/spi_exch.c +++ b/system/spi/spi_exch.c @@ -143,6 +143,7 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv) /* Set up the transfer profile */ + seq.dev = SPIDEV_ID(spitool->devtype, spitool->csn); seq.mode = spitool->mode; seq.nbits = spitool->width; seq.frequency = spitool->freq; diff --git a/system/spi/spi_main.c b/system/spi/spi_main.c index de6efdee6..8e8de73dc 100644 --- a/system/spi/spi_main.c +++ b/system/spi/spi_main.c @@ -137,6 +137,14 @@ static int spicmd_help(FAR struct spitool_s *spitool, int argc, "Default: %d Current: %d\n", CONFIG_SPITOOL_DEFMODE, spitool->mode); + spitool_printf(spitool, " [-n CSn] chip select number. " + "Default: %d Current: %d\n", + 0, spitool->csn); + + spitool_printf(spitool, " [-t devtype] Chip Select type (see spi_devtype_e). " + "Default: %d Current: %d\n", + SPIDEVTYPE_USER, spitool->devtype); + spitool_printf(spitool, " [-u udelay] Delay after transfer in uS. " "Default: 0 Current: %d\n", spitool->udelay); @@ -387,6 +395,11 @@ int main(int argc, FAR char *argv[]) g_spitool.count = CONFIG_SPITOOL_DEFWORDS; } + if (g_spitool.devtype == 0) + { + g_spitool.devtype = SPIDEVTYPE_USER; + } + /* Parse and process the command line */ spi_setup(&g_spitool); diff --git a/system/spi/spitool.h b/system/spi/spitool.h index 890aed1ad..211f4ffdd 100644 --- a/system/spi/spitool.h +++ b/system/spi/spitool.h @@ -145,13 +145,15 @@ struct spitool_s { /* Sticky options */ - uint8_t bus; /* [-b bus] is the SPI bus number */ - uint8_t width; /* [-w width] is the data width (8 or 16) */ - uint32_t freq; /* [-f freq] SPI frequency */ - uint32_t count; /* [-x count] No of words to exchange */ - bool command; /* [-c 0|1] Send as command or data? */ - useconds_t udelay; /* [-u udelay] Delay in uS after transfer */ - uint8_t mode; /* [-m mode] Mode to use for transfer */ + uint8_t bus; /* [-b bus] is the SPI bus number */ + uint8_t width; /* [-w width] is the data width (8 or 16) */ + uint32_t freq; /* [-f freq] SPI frequency */ + uint32_t count; /* [-x count] No of words to exchange */ + uint32_t csn; /* [-n CSn] Chip select number for devtype */ + uint32_t devtype; /* [-t devtype] DevType (see spi_devtype_e) */ + bool command; /* [-c 0|1] Send as command or data? */ + useconds_t udelay; /* [-u udelay] Delay in uS after transfer */ + uint8_t mode; /* [-m mode] Mode to use for transfer */ /* Output streams */