Merged in david_alessio/apps/bugfix/spitool-exch-parse-txdata (pull request #202)

Bugfix/spitool exch parse txdata

* friendlier I2C "knock-knock" uses only read request

    While many I2C slave devices have multiple indexed registers, some have
    only one register and it's not indexed.  For example, the I2C bus switch
    TCA9548A has only a Control Register, attempting to index to "Reg[0]"
    alters its contents to 0x00 disabling all subordinate buses.  This patch
    fixes that problem by simply trying to read something/anything from the
    slave.  This also helps coax out slaves with register files that start
    from a higher index, i.e. the AT24CS0x, FLASH chips with a UUID that
    appears as a 2nd I2C slave at (address+8), report their serial number at
    Reg[80]-Reg[8F] and will NAK a read of Reg[0].

* modify get/set to prevent write of reg index if not specifed

* correctly parse exch txdata args, if any

* should always call the board's deselect

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
David Alessio 2019-10-17 14:05:44 +00:00 committed by Gregory Nutt
parent 3a23523147
commit 0d8ed9c0de

View File

@ -105,7 +105,14 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv)
/* There may be transmit data on the command line */ /* There may be transmit data on the command line */
if (argndx < argc) if (argc - argndx > spitool->count)
{
spitool_printf(spitool, g_spitoomanyargs, argv[0]);
return ERROR;
}
while (argndx < argc)
{ {
FAR uint8_t *a = (uint8_t *)argv[argndx]; FAR uint8_t *a = (uint8_t *)argv[argndx];
while (*a) while (*a)
@ -125,12 +132,6 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv)
argndx += 1; argndx += 1;
} }
if (argndx != argc)
{
spitool_printf(spitool, g_spitoomanyargs, argv[0]);
return ERROR;
}
/* Get a handle to the SPI bus */ /* Get a handle to the SPI bus */
fd = spidev_open(spitool->bus); fd = spidev_open(spitool->bus);
@ -148,7 +149,7 @@ int spicmd_exch(FAR struct spitool_s *spitool, int argc, FAR char **argv)
seq.ntrans = 1; seq.ntrans = 1;
seq.trans = &trans; seq.trans = &trans;
trans.deselect = false; trans.deselect = true;
#ifdef CONFIG_SPI_CMDDATA #ifdef CONFIG_SPI_CMDDATA
trans.cmd = spitool->command; trans.cmd = spitool->command;
#endif #endif