Skip to content

Commit

Permalink
fix writeByte not returning error on some platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Jul 13, 2023
1 parent e0a84ca commit 1b729a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/machine/machine_atmega.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (i2c *I2C) stop() {
}

// writeByte writes a single byte to the I2C bus.
func (i2c *I2C) writeByte(data byte) {
func (i2c *I2C) writeByte(data byte) error {
// Write data to register.
avr.TWDR.Set(data)

Expand All @@ -107,6 +107,7 @@ func (i2c *I2C) writeByte(data byte) {
// Wait till data is transmitted.
for !avr.TWCR.HasBits(avr.TWCR_TWINT) {
}
return nil
}

// readByte reads a single byte from the I2C bus.
Expand Down
3 changes: 2 additions & 1 deletion src/machine/machine_fe310.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
uart.Receive(c)
}

func (uart *UART) writeByte(c byte) {
func (uart *UART) writeByte(c byte) error {
for sifive.UART0.TXDATA.Get()&sifive.UART_TXDATA_FULL != 0 {
}

sifive.UART0.TXDATA.Set(uint32(c))
return nil
}

// SPI on the FE310. The normal SPI0 is actually a quad-SPI meant for flash, so it is best
Expand Down
3 changes: 2 additions & 1 deletion src/machine/machine_k210.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
uart.Receive(c)
}

func (uart *UART) writeByte(c byte) {
func (uart *UART) writeByte(c byte) error {
for uart.Bus.TXDATA.Get()&kendryte.UARTHS_TXDATA_FULL != 0 {
}

uart.Bus.TXDATA.Set(uint32(c))
return nil
}

func (uart *UART) flush() {}
Expand Down

0 comments on commit 1b729a1

Please sign in to comment.