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:
parent
f25dc56d3c
commit
e629ee8f40
|
@ -140,13 +140,21 @@ static int spi_send_recv( lua_State *L )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
luaL_Buffer b;
|
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 );
|
pdata = luaL_checklstring( L, argn, &datalen );
|
||||||
if (recv > 0) {
|
if (recv > 0) {
|
||||||
luaL_buffinit( L, &b );
|
luaL_buffinit( L, &b );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 0; i < datalen; i ++ )
|
for( i = 0; i < datalen; i += datachars )
|
||||||
{
|
{
|
||||||
if (recv > 0)
|
if (recv > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue