avr: add support for the digispark

Blinking the on-board LED works. Nothing else has been tested yet.
This commit is contained in:
Ayke van Laethem
2018-11-20 18:34:14 +01:00
parent a96e2879b2
commit 9392ef900d
14 changed files with 421 additions and 291 deletions
+48
View File
@@ -0,0 +1,48 @@
// +build avr,attiny
package machine
import (
"device/avr"
)
// Configure sets the pin to input or output.
func (p GPIO) Configure(config GPIOConfig) {
if config.Mode == GPIO_OUTPUT { // set output bit
*avr.DDRB |= 1 << p.Pin
} else { // configure input: clear output bit
*avr.DDRB &^= 1 << p.Pin
}
}
// Set changes the value of the GPIO pin. The pin must be configured as output.
func (p GPIO) Set(value bool) {
if value { // set bits
*avr.PORTB |= 1 << p.Pin
} else { // clear bits
*avr.PORTB &^= 1 << p.Pin
}
}
// Get returns the current value of a GPIO pin.
func (p GPIO) Get() bool {
val := *avr.PINB & (1 << p.Pin)
return (val > 0)
}
// 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
}