align spi_recv to platform_spi_send_recv

This commit is contained in:
devsaurus 2015-10-26 22:39:33 +01:00
parent 7d77398921
commit d46bc5cc1f
1 changed files with 3 additions and 5 deletions

View File

@ -173,11 +173,12 @@ static int spi_send_recv( lua_State *L )
return spi_generic_send_recv( L, 1 ); return spi_generic_send_recv( L, 1 );
} }
// Lua: read = spi.recv( id, size ) // Lua: read = spi.recv( id, size, [default data] )
static int spi_recv( lua_State *L ) static int spi_recv( lua_State *L )
{ {
int id = luaL_checkinteger( L, 1 ); int id = luaL_checkinteger( L, 1 );
int size = luaL_checkinteger( L, 2 ), i; int size = luaL_checkinteger( L, 2 ), i;
int def = luaL_optinteger( L, 3, 0xffffffff );
luaL_Buffer b; luaL_Buffer b;
@ -189,10 +190,7 @@ static int spi_recv( lua_State *L )
luaL_buffinit( L, &b ); luaL_buffinit( L, &b );
for (i=0; i<size; i++) for (i=0; i<size; i++)
{ {
if (PLATFORM_OK != platform_spi_transaction( id, 0, 0, 0, 0, 0, 0, spi_databits[id] )) { luaL_addchar( &b, ( char )platform_spi_send_recv( id, spi_databits[id], def ) );
return luaL_error( L, "failed" );
}
luaL_addchar( &b, ( char )platform_spi_get_miso( id, 0, spi_databits[id] ) );
} }
luaL_pushresult( &b ); luaL_pushresult( &b );