mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
9673ad3774
This avoids duplication of code. None of the smoke tests have changed their output.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// +build avr,attiny
|
|
|
|
package machine
|
|
|
|
import (
|
|
"device/avr"
|
|
"runtime/volatile"
|
|
)
|
|
|
|
// Configure sets the pin to input or output.
|
|
func (p Pin) Configure(config PinConfig) {
|
|
if config.Mode == PinOutput { // set output bit
|
|
avr.DDRB.SetBits(1 << uint8(p))
|
|
} else { // configure input: clear output bit
|
|
avr.DDRB.ClearBits(1 << uint8(p))
|
|
}
|
|
}
|
|
|
|
func (p Pin) getPortMask() (*volatile.Register8, uint8) {
|
|
return avr.PORTB, 1 << uint8(p)
|
|
}
|
|
|
|
// Get returns the current value of a GPIO pin.
|
|
func (p Pin) Get() bool {
|
|
val := avr.PINB.Get() & (1 << uint8(p))
|
|
return (val > 0)
|
|
}
|
|
|
|
// UART on the AVR is a dummy implementation. UART has not been implemented for ATtiny
|
|
// devices.
|
|
type UART struct {
|
|
Buffer *RingBuffer
|
|
}
|
|
|
|
// Configure is a dummy implementation. UART has not been implemented for ATtiny
|
|
// devices.
|
|
func (uart UART) Configure(config UARTConfig) {
|
|
}
|
|
|
|
// WriteByte is a dummy implementation. UART has not been implemented for ATtiny
|
|
// devices.
|
|
func (uart UART) WriteByte(c byte) error {
|
|
return nil
|
|
}
|
|
|
|
// Tx is a dummy implementation. I2C has not been implemented for ATtiny
|
|
// devices.
|
|
func (i2c I2C) Tx(addr uint16, w, r []byte) error {
|
|
return nil
|
|
}
|