digispark
Constants
const (
P0 Pin = 0
P1 Pin = 1
P2 Pin = 2
P3 Pin = 3
P4 Pin = 4
P5 Pin = 5
LED = P1
)
const (
TWI_FREQ_100KHZ = 100000
TWI_FREQ_400KHZ = 400000
)
TWI_FREQ is the I2C bus speed. Normally either 100 kHz, or 400 kHz for high-speed bus.
const NoPin = Pin(-1)
NoPin explicitly indicates “not a pin”. Use this pin if you want to leave oneof the pins in a peripheral unconfigured (if supported by the hardware).
const (
PinInput PinMode = iota
PinOutput
)
Variables
var (
ErrInvalidInputPin = errors.New("machine: invalid input pin")
ErrInvalidOutputPin = errors.New("machine: invalid output pin")
ErrInvalidClockPin = errors.New("machine: invalid clock pin")
ErrInvalidDataPin = errors.New("machine: invalid data pin")
)
var I2C0 = I2C{}
I2C0 is the only I2C interface on most AVRs.
var (
// UART0 is the hardware serial port on the AVR.
UART0 = UART{Buffer: NewRingBuffer()}
)
UART
func CPUFrequency
func CPUFrequency() uint32
Return the current CPU frequency in hertz.
func InitADC
func InitADC()
InitADC initializes the registers needed for ADC.
func NewRingBuffer
func NewRingBuffer() *RingBuffer
NewRingBuffer returns a new ring buffer.
type ADC
type ADC struct {
Pin Pin
}
func (ADC) Configure
func (a ADC) Configure()
Configure configures a ADCPin to be able to be used to read data.
func (ADC) Get
func (a ADC) Get() uint16
Get returns the current value of a ADC pin, in the range 0..0xffff. The AVRhas an ADC of 10 bits precision so the lower 6 bits will be zero.
type I2C
type I2C struct {
}
I2C on AVR.
func (I2C) ReadRegister
func (i2c I2C) ReadRegister(address uint8, register uint8, data []byte) error
ReadRegister transmits the register, restarts the connection as a readoperation, and reads the response.
Many I2C-compatible devices are organized in terms of registers. This methodis a shortcut to easily read such registers. Also, it only works for deviceswith 7-bit addresses, which is the vast majority.
func (I2C) Tx
func (i2c I2C) Tx(addr uint16, w, r []byte) error
Tx is a dummy implementation. I2C has not been implemented for ATtinydevices.
func (I2C) WriteRegister
func (i2c I2C) WriteRegister(address uint8, register uint8, data []byte) error
WriteRegister transmits first the register and then the data to theperipheral device.
Many I2C-compatible devices are organized in terms of registers. This methodis a shortcut to easily write to such registers. Also, it only works fordevices with 7-bit addresses, which is the vast majority.
type PWM
type PWM struct {
Pin Pin
}
type Pin
type Pin int8
Pin is a single pin on a chip, which may be connected to other hardwaredevices. It can either be used directly as GPIO pin or it can be used inother peripherals like ADC, I2C, etc.
func (Pin) Configure
func (p Pin) Configure(config PinConfig)
Configure sets the pin to input or output.
func (Pin) Get
func (p Pin) Get() bool
Get returns the current value of a GPIO pin.
func (Pin) High
func (p Pin) High()
High sets this GPIO pin to high, assuming it has been configured as an outputpin. It is hardware dependent (and often undefined) what happens if you set apin to high that is not configured as an output pin.
func (Pin) Low
func (p Pin) Low()
Low sets this GPIO pin to low, assuming it has been configured as an outputpin. It is hardware dependent (and often undefined) what happens if you set apin to low that is not configured as an output pin.
func (Pin) PortMaskClear
func (p Pin) PortMaskClear() (*volatile.Register8, uint8)
Return the register and mask to disable a given port. This can be used toimplement bit-banged drivers.
Warning: there are no separate pin set/clear registers on the AVR. Thereturned mask is only valid as long as no other pin in the same port has beenchanged.
func (Pin) PortMaskSet
func (p Pin) PortMaskSet() (*volatile.Register8, uint8)
Return the register and mask to enable a given GPIO pin. This can be used toimplement bit-banged drivers.
Warning: there are no separate pin set/clear registers on the AVR. Thereturned mask is only valid as long as no other pin in the same port has beenchanged.
func (Pin) Set
func (p Pin) Set(value bool)
Set changes the value of the GPIO pin. The pin must be configured as output.
type PinConfig
type PinConfig struct {
Mode PinMode
}
type PinMode
type PinMode uint8
type RingBuffer
type RingBuffer struct {
rxbuffer [bufferSize]volatile.Register8
head volatile.Register8
tail volatile.Register8
}
RingBuffer is ring buffer implementation inspired by post athttps://www.embeddedrelated.com/showthread/comp.arch.embedded/77084-1.php
It has some limitations currently due to how “volatile” variables that aremembers of a struct are not compiled correctly by TinyGo.See https://github.com/tinygo-org/tinygo/issues/151 for details.
func (*RingBuffer) Get
func (rb *RingBuffer) Get() (byte, bool)
Get returns a byte from the buffer. If the buffer is empty,the method will return a false as the second value.
func (*RingBuffer) Put
func (rb *RingBuffer) Put(val byte) bool
Put stores a byte in the buffer. If the buffer is alreadyfull, the method will return false.
func (*RingBuffer) Used
func (rb *RingBuffer) Used() uint8
Used returns how many bytes in buffer have been used.
type UART
type UART struct {
Buffer *RingBuffer
}
UART on the AVR is a dummy implementation. UART has not been implemented for ATtinydevices.
func (UART) Buffered
func (uart UART) Buffered() int
Buffered returns the number of bytes currently stored in the RX buffer.
func (UART) Configure
func (uart UART) Configure(config UARTConfig)
Configure is a dummy implementation. UART has not been implemented for ATtinydevices.
func (UART) Read
func (uart UART) Read(data []byte) (n int, err error)
Read from the RX buffer.
func (UART) ReadByte
func (uart UART) ReadByte() (byte, error)
ReadByte reads a single byte from the RX buffer.If there is no data in the buffer, returns an error.
func (UART) Receive
func (uart UART) Receive(data byte)
Receive handles adding data to the UART’s data buffer.Usually called by the IRQ handler for a machine.
func (UART) Write
func (uart UART) Write(data []byte) (n int, err error)
Write data to the UART.
func (UART) WriteByte
func (uart UART) WriteByte(c byte) error
WriteByte is a dummy implementation. UART has not been implemented for ATtinydevices.
type UARTConfig
type UARTConfig struct {
BaudRate uint32
TX Pin
RX Pin
}