apps/system/spi: Add options to spec devtype, id for chip select.

This commit is contained in:
David S. Alessio 2019-10-18 07:43:38 -06:00 committed by Gregory Nutt
parent eb0b5b194f
commit e050dce32d
4 changed files with 43 additions and 7 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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 */