nodemcu-firmware icon indicating copy to clipboard operation
nodemcu-firmware copied to clipboard

Support sending strings with multi-byte-wide SPI

Open stuartpb opened this issue 3 years ago • 2 comments
trafficstars

The iteration in the loop in the prior version of spi.send assumes that the value of databits is the width of char when sending any string value.

  • [x] This PR is for the dev branch rather than for the release branch.
  • [x] This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • [ ] I haven't thoroughly tested my contribution - it's a simple enough change that, if it compiles and passes existing tests, it works (it only fixes behavior that was previously broken).
  • [x] The code changes are reflected in the documentation at docs/*. (This only fixes the function to more closely match the expected documented behavior.)

stuartpb avatar Jul 18 '22 20:07 stuartpb

There should probably be further tests with this to ensure that multi-char values from strings get read and sent properly - there could be endianness issues with the string layout.

Alternately, trying to send a string value with a databits value of anything other than 8 could be an error, or ignore the databits value and always use a width of 8 for strings, transmitted character-by-character (this override should probably be documented in that case).

stuartpb avatar Jul 18 '22 20:07 stuartpb

I don't see how platform_spi_send( id, spi_databits[id], pdata[ i ] ); would work with >8 bits? The pdata[i] would only pass 8 bits of data through to the function, given that pdata is of const char * type. Am I missing something?

jmattsson avatar Aug 01 '22 01:08 jmattsson