From 45e1f42f39089b01307113c76a4f6e5b147fcae8 Mon Sep 17 00:00:00 2001 From: gram Date: Mon, 4 Mar 2024 10:26:33 +0100 Subject: [PATCH] actualize UART --- devices/hardware/uart.go | 47 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/devices/hardware/uart.go b/devices/hardware/uart.go index 03cf76f..18cbde4 100644 --- a/devices/hardware/uart.go +++ b/devices/hardware/uart.go @@ -2,58 +2,47 @@ package hardware import ( "github.com/hybridgroup/mechanoid/engine" + "github.com/orsinium-labs/wypes" ) var _ engine.Device = &UART{} type UARTConfig struct{} -type UART struct { - Engine *engine.Engine +type UART struct{} + +func NewUARTDevice() *UART { + return &UART{} } -func NewUARTDevice(e *engine.Engine) *UART { - return &UART{ - Engine: e, - } +func (UART) Init() error { + return nil } -func (uart *UART) Init() error { +func (UART) Modules() wypes.Modules { // this is where the host machine's UART would be initialized // and all the hosted functions setup - if uart.Engine == nil { - return engine.ErrInvalidEngine + return wypes.Modules{ + "machine": wypes.Module{ + "__tinygo_uart_configure": wypes.H3(UARTConfigure), + "__tinygo_uart_read": wypes.H3(UARTRead), + "__tinygo_uart_write": wypes.H3(UARTWrite), + }, } - - if err := uart.Engine.Interpreter.DefineFunc("machine", "__tinygo_uart_configure", UARTConfigure); err != nil { - println(err.Error()) - return err - } - - if err := uart.Engine.Interpreter.DefineFunc("machine", "__tinygo_uart_read", UARTRead); err != nil { - println(err.Error()) - return err - } - - if err := uart.Engine.Interpreter.DefineFunc("machine", "__tinygo_uart_write", UARTWrite); err != nil { - println(err.Error()) - return err - } - - return nil } -func UARTConfigure(bus uint8, tx Pin, rx Pin) { +func UARTConfigure(bus wypes.UInt8, tx wypes.UInt8, rx wypes.UInt8) wypes.Void { // Not implemented + return wypes.Void{} } -func UARTRead(bus uint8, buf *byte, bufLen int) int { +func UARTRead(bus wypes.UInt8, buf wypes.Byte, bufLen wypes.UInt32) wypes.UInt32 { // Not implemented return 0 } -func UARTWrite(bus uint8, buf *byte, bufLen int) int { +func UARTWrite(bus wypes.UInt8, buf wypes.Byte, bufLen wypes.UInt32) wypes.UInt32 { // Not implemented return 0 }