Skip to content

Commit

Permalink
targets: modify UART implementation for TKey to implement Serialer in…
Browse files Browse the repository at this point in the history
…terface

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 2, 2024
1 parent 58b1a03 commit 1e3157b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/machine/machine_tkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ var (
)

// Thw TKey UART is fixed at 62500 baud, 8N1.
func (uart *UART) Configure(config UARTConfig) {
}

func (uart *UART) SetBaudRate(br uint32) {
func (uart *UART) Configure(config UARTConfig) error {
return nil
}

// Write a slice of data bytes to the UART.
func (uart *UART) Write(data []byte) (n int, err error) {
for _, c := range data {
if err := uart.WriteByte(c); err != nil {
Expand All @@ -100,6 +99,7 @@ func (uart *UART) Write(data []byte) (n int, err error) {
return len(data), nil
}

// WriteByte writes a byte of data to the UART.
func (uart *UART) WriteByte(c byte) error {
for uart.Bus.TX_STATUS.Get() == 0 {
}
Expand All @@ -109,17 +109,29 @@ func (uart *UART) WriteByte(c byte) error {
return nil
}

// Buffered returns the number of bytes buffered in the UART.
func (uart *UART) Buffered() int {
return int(uart.Bus.RX_BYTES.Get())
}

// ReadByte reads a byte of data from the UART.
func (uart *UART) ReadByte() (byte, error) {
for uart.Bus.RX_STATUS.Get() == 0 {
}

return byte(uart.Bus.RX_DATA.Get()), nil
}

// DTR is not available on the TKey.
func (uart *UART) DTR() bool {
return false
}

// RTS is not available on the TKey.
func (uart *UART) RTS() bool {
return false
}

// GetRNG returns 32 bits of cryptographically secure random data
func GetRNG() (uint32, error) {
for tkey.TRNG.STATUS.Get() == 0 {
Expand Down

0 comments on commit 1e3157b

Please sign in to comment.