Support sending strings with multi-byte-wide SPI

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.
This commit is contained in:
Stuart P. Bentley 2022-07-18 13:21:04 -07:00 committed by GitHub
parent f25dc56d3c
commit e629ee8f40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -140,13 +140,21 @@ static int spi_send_recv( lua_State *L )
else
{
luaL_Buffer b;
size_t datachars = spi_databits[id] / 8;
if (spi_databits[id] % 8 != 0) {
return luaL_error( L, "attempt to send string with non-character-divisible databits" );
}
if (datalen % datachars != 0) {
return luaL_error( L, "attempt to send string with non-databits-divisible length" );
}
pdata = luaL_checklstring( L, argn, &datalen );
if (recv > 0) {
luaL_buffinit( L, &b );
}
for( i = 0; i < datalen; i ++ )
for( i = 0; i < datalen; i += datachars )
{
if (recv > 0)
{