mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-20 04:26:04 +08:00
apps/system/spi: Add options to spec devtype, id for chip select.
This commit is contained in:

committed by
Gregory Nutt

parent
eb0b5b194f
commit
e050dce32d
@@ -156,6 +156,26 @@ int spitool_common_args(FAR struct spitool_s *spitool, FAR char **arg)
|
|||||||
spitool->mode = value;
|
spitool->mode = value;
|
||||||
return ret;
|
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':
|
case 'f':
|
||||||
ret = arg_decimal(arg, &value);
|
ret = arg_decimal(arg, &value);
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
|
@@ -143,6 +143,7 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv)
|
|||||||
|
|
||||||
/* Set up the transfer profile */
|
/* Set up the transfer profile */
|
||||||
|
|
||||||
|
seq.dev = SPIDEV_ID(spitool->devtype, spitool->csn);
|
||||||
seq.mode = spitool->mode;
|
seq.mode = spitool->mode;
|
||||||
seq.nbits = spitool->width;
|
seq.nbits = spitool->width;
|
||||||
seq.frequency = spitool->freq;
|
seq.frequency = spitool->freq;
|
||||||
|
@@ -137,6 +137,14 @@ static int spicmd_help(FAR struct spitool_s *spitool, int argc,
|
|||||||
"Default: %d Current: %d\n",
|
"Default: %d Current: %d\n",
|
||||||
CONFIG_SPITOOL_DEFMODE, spitool->mode);
|
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. "
|
spitool_printf(spitool, " [-u udelay] Delay after transfer in uS. "
|
||||||
"Default: 0 Current: %d\n", spitool->udelay);
|
"Default: 0 Current: %d\n", spitool->udelay);
|
||||||
|
|
||||||
@@ -387,6 +395,11 @@ int main(int argc, FAR char *argv[])
|
|||||||
g_spitool.count = CONFIG_SPITOOL_DEFWORDS;
|
g_spitool.count = CONFIG_SPITOOL_DEFWORDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_spitool.devtype == 0)
|
||||||
|
{
|
||||||
|
g_spitool.devtype = SPIDEVTYPE_USER;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse and process the command line */
|
/* Parse and process the command line */
|
||||||
|
|
||||||
spi_setup(&g_spitool);
|
spi_setup(&g_spitool);
|
||||||
|
@@ -149,6 +149,8 @@ struct spitool_s
|
|||||||
uint8_t width; /* [-w width] is the data width (8 or 16) */
|
uint8_t width; /* [-w width] is the data width (8 or 16) */
|
||||||
uint32_t freq; /* [-f freq] SPI frequency */
|
uint32_t freq; /* [-f freq] SPI frequency */
|
||||||
uint32_t count; /* [-x count] No of words to exchange */
|
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? */
|
bool command; /* [-c 0|1] Send as command or data? */
|
||||||
useconds_t udelay; /* [-u udelay] Delay in uS after transfer */
|
useconds_t udelay; /* [-u udelay] Delay in uS after transfer */
|
||||||
uint8_t mode; /* [-m mode] Mode to use for transfer */
|
uint8_t mode; /* [-m mode] Mode to use for transfer */
|
||||||
|
Reference in New Issue
Block a user