Skip to content

Commit

Permalink
actualize UART
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Mar 4, 2024
1 parent aa5d8f1 commit 45e1f42
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions devices/hardware/uart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 45e1f42

Please sign in to comment.