|
|
@@ -458,9 +458,7 @@ static int l_spi_recv(lua_State *L) {
|
|
|
{
|
|
|
luat_spi_device_t *spi_device = (luat_spi_device_t *)luaL_testudata(L, 1, META_SPI);
|
|
|
if (spi_device){
|
|
|
- luat_spi_lock(spi_device->bus_id);
|
|
|
luat_spi_device_recv(spi_device, recv_buff, len);
|
|
|
- luat_spi_unlock(spi_device->bus_id);
|
|
|
ret = len;
|
|
|
}
|
|
|
else {
|
|
|
@@ -653,9 +651,7 @@ static int l_spi_device_transfer(lua_State *L) {
|
|
|
if(recv_buff == NULL)
|
|
|
return 0;
|
|
|
}
|
|
|
- luat_spi_lock(spi_device->bus_id);
|
|
|
int ret = luat_spi_device_transfer(spi_device, send_buff, send_length, recv_buff, recv_length);
|
|
|
- luat_spi_unlock(spi_device->bus_id);
|
|
|
if (send_mode == LUA_TTABLE){
|
|
|
luat_heap_free(send_buff);
|
|
|
}
|
|
|
@@ -692,9 +688,7 @@ static int l_spi_device_send(lua_State *L) {
|
|
|
luat_zbuff_t *buff = (luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE);
|
|
|
send_buff = (char*)(buff->addr+buff->cursor);
|
|
|
len = buff->len - buff->cursor;
|
|
|
- luat_spi_lock(spi_device->bus_id);
|
|
|
ret = luat_spi_device_send(spi_device, send_buff, len);
|
|
|
- luat_spi_unlock(spi_device->bus_id);
|
|
|
lua_pushinteger(L, ret);
|
|
|
}else if (lua_istable(L, 2)){
|
|
|
len = lua_rawlen(L, 2); //返回数组的长度
|
|
|
@@ -704,9 +698,7 @@ static int l_spi_device_send(lua_State *L) {
|
|
|
send_buff[i] = (char)lua_tointeger(L, -1);
|
|
|
lua_pop(L, 1); //将刚刚获取的元素值从栈中弹出
|
|
|
}
|
|
|
- luat_spi_lock(spi_device->bus_id);
|
|
|
ret = luat_spi_device_send(spi_device, send_buff, len);
|
|
|
- luat_spi_unlock(spi_device->bus_id);
|
|
|
lua_pushinteger(L, ret);
|
|
|
luat_heap_free(send_buff);
|
|
|
}else if(lua_isstring(L, 2)){
|
|
|
@@ -735,9 +727,7 @@ static int l_spi_device_recv(lua_State *L) {
|
|
|
int len = luaL_optinteger(L, 2,1);
|
|
|
char* recv_buff = luat_heap_malloc(len);
|
|
|
if(recv_buff == NULL) return 0;
|
|
|
- luat_spi_lock(spi_device->bus_id);
|
|
|
int ret = luat_spi_device_recv(spi_device, recv_buff, len);
|
|
|
- luat_spi_unlock(spi_device->bus_id);
|
|
|
if (ret > 0) {
|
|
|
lua_pushlstring(L, recv_buff, ret);
|
|
|
luat_heap_free(recv_buff);
|