add : USB CDC虚拟串口通讯
This commit is contained in:
38
4G/tools/_temp/script/temp_script/clib.lua
Normal file
38
4G/tools/_temp/script/temp_script/clib.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local uartReceiveCallbacks = {}
|
||||
local uartSentCallbacks = {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uart.on = function(id, event, callback)
|
||||
if event == "receive" then
|
||||
uartReceiveCallbacks[id] = callback
|
||||
elseif event == "sent" then
|
||||
uartSentCallbacks[id] = callback
|
||||
end
|
||||
end
|
||||
|
||||
rtos.on(rtos.MSG_UART_RXDATA, function(id, length)
|
||||
if uartReceiveCallbacks[id] then
|
||||
uartReceiveCallbacks[id](id, length)
|
||||
end
|
||||
end)
|
||||
|
||||
rtos.on(rtos.MSG_UART_TX_DONE, function(id)
|
||||
if uartSentCallbacks[id] then
|
||||
uartSentCallbacks[id](id)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user