itsybitsy-m4

Constants

  1. const RESET_MAGIC_VALUE = 0xf01669ef

used to reset into bootloader

  1. const (
  2. D0 = PA16 // UART0 RX/PWM available
  3. D1 = PA17 // UART0 TX/PWM available
  4. D2 = PA07
  5. D3 = PB22
  6. D4 = PA14 // PWM available
  7. D5 = PA15 // PWM available
  8. D6 = PB02 // dotStar clock
  9. D7 = PA18 // PWM available
  10. D8 = PB03 // dotStar data
  11. D9 = PA19 // PWM available
  12. D10 = PA20 // can be used for PWM or UART1 TX
  13. D11 = PA21 // can be used for PWM or UART1 RX
  14. D12 = PA23 // PWM available
  15. D13 = PA22 // PWM available
  16. )

GPIO Pins

  1. const (
  2. A0 = PA02 // ADC/AIN[0]
  3. A1 = PA05 // ADC/AIN[2]
  4. A2 = PB08 // ADC/AIN[3]
  5. A3 = PB09 // ADC/AIN[4]
  6. A4 = PA04 // ADC/AIN[5]
  7. A5 = PA06 // ADC/AIN[10]
  8. )

Analog pins

  1. const (
  2. LED = D13
  3. )
  1. const (
  2. USBCDC_DM_PIN = PA24
  3. USBCDC_DP_PIN = PA25
  4. )

UART0 aka USBCDC pins

  1. const (
  2. UART_TX_PIN = D1
  3. UART_RX_PIN = D0
  4. )

UART1 pins

  1. const (
  2. UART2_TX_PIN = A4
  3. UART2_RX_PIN = D2
  4. )

UART2 pins

  1. const (
  2. SDA_PIN = PA12 // SDA: SERCOM2/PAD[0]
  3. SCL_PIN = PA13 // SCL: SERCOM2/PAD[1]
  4. )

I2C pins

  1. const (
  2. SPI0_SCK_PIN = PA01 // SCK: SERCOM1/PAD[1]
  3. SPI0_MOSI_PIN = PA00 // MOSI: SERCOM1/PAD[0]
  4. SPI0_MISO_PIN = PB23 // MISO: SERCOM1/PAD[3]
  5. )

SPI pins

  1. const (
  2. TWI_FREQ_100KHZ = 100000
  3. TWI_FREQ_400KHZ = 400000
  4. )

TWI_FREQ is the I2C bus speed. Normally either 100 kHz, or 400 kHz for high-speed bus.

  1. const (
  2. I2SModeMaster I2SMode = iota
  3. I2SModeSlave
  4. I2SModePDM
  5. )
  1. const (
  2. I2StandardPhilips I2SStandard = iota
  3. I2SStandardMSB
  4. I2SStandardLSB
  5. )
  1. const (
  2. I2SClockSourceInternal I2SClockSource = iota
  3. I2SClockSourceExternal
  4. )
  1. const (
  2. I2SDataFormatDefault I2SDataFormat = 0
  3. I2SDataFormat8bit = 8
  4. I2SDataFormat16bit = 16
  5. I2SDataFormat24bit = 24
  6. I2SDataFormat32bit = 32
  7. )
  1. 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).

  1. const (
  2. PinAnalog PinMode = 1
  3. PinSERCOM PinMode = 2
  4. PinSERCOMAlt PinMode = 3
  5. PinTimer PinMode = 4
  6. PinTimerAlt PinMode = 5
  7. PinTCCPDEC PinMode = 6
  8. PinCom PinMode = 7
  9. PinSDHC PinMode = 8
  10. PinI2S PinMode = 9
  11. PinPCC PinMode = 10
  12. PinGMAC PinMode = 11
  13. PinACCLK PinMode = 12
  14. PinCCL PinMode = 13
  15. PinDigital PinMode = 14
  16. PinInput PinMode = 15
  17. PinInputPullup PinMode = 16
  18. PinOutput PinMode = 17
  19. PinPWME PinMode = PinTimer
  20. PinPWMF PinMode = PinTimerAlt
  21. PinPWMG PinMode = PinTCCPDEC
  22. PinInputPulldown PinMode = 18
  23. )
  1. const (
  2. PA00 Pin = 0
  3. PA01 Pin = 1
  4. PA02 Pin = 2
  5. PA03 Pin = 3
  6. PA04 Pin = 4
  7. PA05 Pin = 5
  8. PA06 Pin = 6
  9. PA07 Pin = 7
  10. PA08 Pin = 8
  11. PA09 Pin = 9
  12. PA10 Pin = 10
  13. PA11 Pin = 11
  14. PA12 Pin = 12
  15. PA13 Pin = 13
  16. PA14 Pin = 14
  17. PA15 Pin = 15
  18. PA16 Pin = 16
  19. PA17 Pin = 17
  20. PA18 Pin = 18
  21. PA19 Pin = 19
  22. PA20 Pin = 20
  23. PA21 Pin = 21
  24. PA22 Pin = 22
  25. PA23 Pin = 23
  26. PA24 Pin = 24
  27. PA25 Pin = 25
  28. PA26 Pin = 26
  29. PA27 Pin = 27
  30. PA28 Pin = 28
  31. PA29 Pin = 29
  32. PA30 Pin = 30
  33. PA31 Pin = 31
  34. PB00 Pin = 32
  35. PB01 Pin = 33
  36. PB02 Pin = 34
  37. PB03 Pin = 35
  38. PB04 Pin = 36
  39. PB05 Pin = 37
  40. PB06 Pin = 38
  41. PB07 Pin = 39
  42. PB08 Pin = 40
  43. PB09 Pin = 41
  44. PB10 Pin = 42
  45. PB11 Pin = 43
  46. PB12 Pin = 44
  47. PB13 Pin = 45
  48. PB14 Pin = 46
  49. PB15 Pin = 47
  50. PB16 Pin = 48
  51. PB17 Pin = 49
  52. PB18 Pin = 50
  53. PB19 Pin = 51
  54. PB20 Pin = 52
  55. PB21 Pin = 53
  56. PB22 Pin = 54
  57. PB23 Pin = 55
  58. PB24 Pin = 56
  59. PB25 Pin = 57
  60. PB26 Pin = 58
  61. PB27 Pin = 59
  62. PB28 Pin = 60
  63. PB29 Pin = 61
  64. PB30 Pin = 62
  65. PB31 Pin = 63
  66. )

Hardware pins

  1. const (
  2. // SERCOM_FREQ_REF is always reference frequency on SAMD51 regardless of CPU speed.
  3. SERCOM_FREQ_REF = 48000000
  4. // Default rise time in nanoseconds, based on 4.7K ohm pull up resistors
  5. riseTimeNanoseconds = 125
  6. // wire bus states
  7. wireUnknownState = 0
  8. wireIdleState = 1
  9. wireOwnerState = 2
  10. wireBusyState = 3
  11. // wire commands
  12. wireCmdNoAction = 0
  13. wireCmdRepeatStart = 1
  14. wireCmdRead = 2
  15. wireCmdStop = 3
  16. )
  1. const HSRAM_SIZE = 0x00030000

Variables

  1. var (
  2. I2C0 = I2C{
  3. Bus: sam.SERCOM2_I2CM,
  4. SERCOM: 2,
  5. }
  6. )

I2C on the ItsyBitsy M4.

  1. var (
  2. SPI0 = SPI{
  3. Bus: sam.SERCOM1_SPIM,
  4. SERCOM: 1,
  5. }
  6. )

SPI on the ItsyBitsy M4.

  1. var (
  2. ErrInvalidInputPin = errors.New("machine: invalid input pin")
  3. ErrInvalidOutputPin = errors.New("machine: invalid output pin")
  4. ErrInvalidClockPin = errors.New("machine: invalid clock pin")
  5. ErrInvalidDataPin = errors.New("machine: invalid data pin")
  6. )
  1. var (
  2. // UART0 is actually a USB CDC interface.
  3. UART0 = USBCDC{Buffer: NewRingBuffer()}
  4. // The first hardware serial port on the SAMD51. Uses the SERCOM3 interface.
  5. UART1 = UART{
  6. Buffer: NewRingBuffer(),
  7. Bus: sam.SERCOM3_USART_INT,
  8. SERCOM: 3,
  9. IRQVal: sam.IRQ_SERCOM3_2,
  10. }
  11. // The second hardware serial port on the SAMD51. Uses the SERCOM0 interface.
  12. UART2 = UART{
  13. Buffer: NewRingBuffer(),
  14. Bus: sam.SERCOM0_USART_INT,
  15. SERCOM: 0,
  16. IRQVal: sam.IRQ_SERCOM0_2,
  17. }
  18. )
  1. var (
  2. ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
  3. )

func CPUFrequency

  1. func CPUFrequency() uint32

func InitADC

  1. func InitADC()

InitADC initializes the ADC.

func InitPWM

  1. func InitPWM()

InitPWM initializes the PWM interface.

func NewACMFunctionalDescriptor

  1. func NewACMFunctionalDescriptor(subtype, d0 uint8) ACMFunctionalDescriptor

NewACMFunctionalDescriptor returns a new USB ACMFunctionalDescriptor.

func NewCDCCSInterfaceDescriptor

  1. func NewCDCCSInterfaceDescriptor(subtype, d0, d1 uint8) CDCCSInterfaceDescriptor

NewCDCCSInterfaceDescriptor returns a new USB CDCCSInterfaceDescriptor.

func NewCDCDescriptor

  1. func NewCDCDescriptor(i IADDescriptor, c InterfaceDescriptor,
  2. h CDCCSInterfaceDescriptor,
  3. cm ACMFunctionalDescriptor,
  4. fd CDCCSInterfaceDescriptor,
  5. callm CMFunctionalDescriptor,
  6. ci EndpointDescriptor,
  7. di InterfaceDescriptor,
  8. outp EndpointDescriptor,
  9. inp EndpointDescriptor) CDCDescriptor

func NewCMFunctionalDescriptor

  1. func NewCMFunctionalDescriptor(subtype, d0, d1 uint8) CMFunctionalDescriptor

NewCMFunctionalDescriptor returns a new USB CMFunctionalDescriptor.

func NewConfigDescriptor

  1. func NewConfigDescriptor(totalLength uint16, interfaces uint8) ConfigDescriptor

NewConfigDescriptor returns a new USB ConfigDescriptor.

func NewDeviceDescriptor

  1. func NewDeviceDescriptor(class, subClass, proto, packetSize0 uint8, vid, pid, version uint16, im, ip, is, configs uint8) DeviceDescriptor

NewDeviceDescriptor returns a USB DeviceDescriptor.

func NewEndpointDescriptor

  1. func NewEndpointDescriptor(addr, attr uint8, packetSize uint16, interval uint8) EndpointDescriptor

NewEndpointDescriptor returns a new USB EndpointDescriptor.

func NewIADDescriptor

  1. func NewIADDescriptor(firstInterface, count, class, subClass, protocol uint8) IADDescriptor

NewIADDescriptor returns a new USB IADDescriptor.

func NewInterfaceDescriptor

  1. func NewInterfaceDescriptor(n, numEndpoints, class, subClass, protocol uint8) InterfaceDescriptor

NewInterfaceDescriptor returns a new USB InterfaceDescriptor.

func NewRingBuffer

  1. func NewRingBuffer() *RingBuffer

NewRingBuffer returns a new ring buffer.

func ResetProcessor

  1. func ResetProcessor()

ResetProcessor should perform a system reset in preparationto switch to the bootloader to flash new firmware.

type ACMFunctionalDescriptor

  1. type ACMFunctionalDescriptor struct {
  2. len uint8
  3. dtype uint8 // 0x24
  4. subtype uint8 // 1
  5. bmCapabilities uint8
  6. }

ACMFunctionalDescriptor is a Abstract Control Model (ACM) USB descriptor.

func (ACMFunctionalDescriptor) Bytes

  1. func (d ACMFunctionalDescriptor) Bytes() []byte

Bytes returns the ACMFunctionalDescriptor data.

type ADC

  1. type ADC struct {
  2. Pin Pin
  3. }

func (ADC) Configure

  1. func (a ADC) Configure()

Configure configures a ADCPin to be able to be used to read data.

func (ADC) Get

  1. func (a ADC) Get() uint16

Get returns the current value of a ADC pin, in the range 0..0xffff.

type CDCCSInterfaceDescriptor

  1. type CDCCSInterfaceDescriptor struct {
  2. len uint8 // 5
  3. dtype uint8 // 0x24
  4. subtype uint8
  5. d0 uint8
  6. d1 uint8
  7. }

CDCCSInterfaceDescriptor is a CDC CS interface descriptor.

func (CDCCSInterfaceDescriptor) Bytes

  1. func (d CDCCSInterfaceDescriptor) Bytes() []byte

Bytes returns CDCCSInterfaceDescriptor data.

type CDCDescriptor

  1. type CDCDescriptor struct {
  2. // IAD
  3. iad IADDescriptor // Only needed on compound device
  4. // Control
  5. cif InterfaceDescriptor
  6. header CDCCSInterfaceDescriptor
  7. // CDC control
  8. controlManagement ACMFunctionalDescriptor // ACM
  9. functionalDescriptor CDCCSInterfaceDescriptor // CDC_UNION
  10. callManagement CMFunctionalDescriptor // Call Management
  11. cifin EndpointDescriptor
  12. // CDC Data
  13. dif InterfaceDescriptor
  14. in EndpointDescriptor
  15. out EndpointDescriptor
  16. }

CDCDescriptor is the Communication Device Class (CDC) descriptor.

func (CDCDescriptor) Bytes

  1. func (d CDCDescriptor) Bytes() []byte

Bytes returns CDCDescriptor data.

type CMFunctionalDescriptor

  1. type CMFunctionalDescriptor struct {
  2. bFunctionLength uint8
  3. bDescriptorType uint8 // 0x24
  4. bDescriptorSubtype uint8 // 1
  5. bmCapabilities uint8
  6. bDataInterface uint8
  7. }

CMFunctionalDescriptor is the functional descriptor general format.

func (CMFunctionalDescriptor) Bytes

  1. func (d CMFunctionalDescriptor) Bytes() []byte

Bytes returns the CMFunctionalDescriptor data.

type ConfigDescriptor

  1. type ConfigDescriptor struct {
  2. bLength uint8 // 9
  3. bDescriptorType uint8 // 2
  4. wTotalLength uint16 // total length
  5. bNumInterfaces uint8
  6. bConfigurationValue uint8
  7. iConfiguration uint8
  8. bmAttributes uint8
  9. bMaxPower uint8
  10. }

ConfigDescriptor implements the standard USB configuration descriptor.

Table 9-10. Standard Configuration DescriptorbLength, bDescriptorType, wTotalLength, bNumInterfaces, bConfigurationValue, iConfigurationbmAttributes, bMaxPower

func (ConfigDescriptor) Bytes

  1. func (d ConfigDescriptor) Bytes() []byte

Bytes returns ConfigDescriptor data.

type DeviceDescriptor

  1. type DeviceDescriptor struct {
  2. bLength uint8 // 18
  3. bDescriptorType uint8 // 1 USB_DEVICE_DESCRIPTOR_TYPE
  4. bcdUSB uint16 // 0x200
  5. bDeviceClass uint8
  6. bDeviceSubClass uint8
  7. bDeviceProtocol uint8
  8. bMaxPacketSize0 uint8 // Packet 0
  9. idVendor uint16
  10. idProduct uint16
  11. bcdDevice uint16 // 0x100
  12. iManufacturer uint8
  13. iProduct uint8
  14. iSerialNumber uint8
  15. bNumConfigurations uint8
  16. }

DeviceDescriptor implements the USB standard device descriptor.

Table 9-8. Standard Device DescriptorbLength, bDescriptorType, bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, bMaxPacketSize0, idVendor, idProduct, bcdDevice, iManufacturer, iProduct, iSerialNumber, bNumConfigurations */

func (DeviceDescriptor) Bytes

  1. func (d DeviceDescriptor) Bytes() []byte

Bytes returns DeviceDescriptor data

type EndpointDescriptor

  1. type EndpointDescriptor struct {
  2. bLength uint8 // 7
  3. bDescriptorType uint8 // 5
  4. bEndpointAddress uint8
  5. bmAttributes uint8
  6. wMaxPacketSize uint16
  7. bInterval uint8
  8. }

EndpointDescriptor implements the standard USB endpoint descriptor.

Table 9-13. Standard Endpoint DescriptorbLength, bDescriptorType, bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval

func (EndpointDescriptor) Bytes

  1. func (d EndpointDescriptor) Bytes() []byte

Bytes returns EndpointDescriptor data.

type I2C

  1. type I2C struct {
  2. Bus *sam.SERCOM_I2CM_Type
  3. SERCOM uint8
  4. }

I2C on the SAMD51.

func (I2C) Configure

  1. func (i2c I2C) Configure(config I2CConfig) error

Configure is intended to setup the I2C interface.

func (I2C) ReadRegister

  1. 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) SetBaudRate

  1. func (i2c I2C) SetBaudRate(br uint32)

SetBaudRate sets the communication speed for the I2C.

func (I2C) Tx

  1. func (i2c I2C) Tx(addr uint16, w, r []byte) error

Tx does a single I2C transaction at the specified address.It clocks out the given address, writes the bytes in w, reads back len®bytes and stores them in r, and generates a stop condition on the bus.

func (I2C) WriteByte

  1. func (i2c I2C) WriteByte(data byte) error

WriteByte writes a single byte to the I2C bus.

func (I2C) WriteRegister

  1. 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 I2CConfig

  1. type I2CConfig struct {
  2. Frequency uint32
  3. SCL Pin
  4. SDA Pin
  5. }

I2CConfig is used to store config info for I2C.

type I2SClockSource

  1. type I2SClockSource uint8

type I2SConfig

  1. type I2SConfig struct {
  2. SCK Pin
  3. WS Pin
  4. SD Pin
  5. Mode I2SMode
  6. Standard I2SStandard
  7. ClockSource I2SClockSource
  8. DataFormat I2SDataFormat
  9. AudioFrequency uint32
  10. MasterClockOutput bool
  11. Stereo bool
  12. }

All fields are optional and may not be required or used on a particular platform.

type I2SDataFormat

  1. type I2SDataFormat uint8

type I2SMode

  1. type I2SMode uint8

type I2SStandard

  1. type I2SStandard uint8

type IADDescriptor

  1. type IADDescriptor struct {
  2. bLength uint8 // 8
  3. bDescriptorType uint8 // 11
  4. bFirstInterface uint8
  5. bInterfaceCount uint8
  6. bFunctionClass uint8
  7. bFunctionSubClass uint8
  8. bFunctionProtocol uint8
  9. iFunction uint8
  10. }

IADDescriptor is an Interface Association Descriptor, which is usedto bind 2 interfaces together in CDC composite device.

Standard Interface Association Descriptor:bLength, bDescriptorType, bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass,bFunctionProtocol, iFunction

func (IADDescriptor) Bytes

  1. func (d IADDescriptor) Bytes() []byte

Bytes returns IADDescriptor data.

type InterfaceDescriptor

  1. type InterfaceDescriptor struct {
  2. bLength uint8 // 9
  3. bDescriptorType uint8 // 4
  4. bInterfaceNumber uint8
  5. bAlternateSetting uint8
  6. bNumEndpoints uint8
  7. bInterfaceClass uint8
  8. bInterfaceSubClass uint8
  9. bInterfaceProtocol uint8
  10. iInterface uint8
  11. }

InterfaceDescriptor implements the standard USB interface descriptor.

Table 9-12. Standard Interface DescriptorbLength, bDescriptorType, bInterfaceNumber, bAlternateSetting, bNumEndpoints, bInterfaceClass,bInterfaceSubClass, bInterfaceProtocol, iInterface

func (InterfaceDescriptor) Bytes

  1. func (d InterfaceDescriptor) Bytes() []byte

Bytes returns InterfaceDescriptor data.

type MSCDescriptor

  1. type MSCDescriptor struct {
  2. msc InterfaceDescriptor
  3. in EndpointDescriptor
  4. out EndpointDescriptor
  5. }

MSCDescriptor is not used yet.

type PWM

  1. type PWM struct {
  2. Pin Pin
  3. }

func (PWM) Configure

  1. func (pwm PWM) Configure()

Configure configures a PWM pin for output.

func (PWM) Set

  1. func (pwm PWM) Set(value uint16)

Set turns on the duty cycle for a PWM pin using the provided value.

type Pin

  1. 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

  1. func (p Pin) Configure(config PinConfig)

Configure this pin with the given configuration.

func (Pin) Get

  1. func (p Pin) Get() bool

Get returns the current value of a GPIO pin.

func (Pin) High

  1. 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

  1. 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

  1. func (p Pin) PortMaskClear() (*uint32, uint32)

Return the register and mask to disable a given port. This can be used toimplement bit-banged drivers.

func (Pin) PortMaskSet

  1. func (p Pin) PortMaskSet() (*uint32, uint32)

Return the register and mask to enable a given GPIO pin. This can be used toimplement bit-banged drivers.

func (Pin) Set

  1. func (p Pin) Set(high bool)

Set the pin to high or low.Warning: only use this on an output pin!

func (Pin) Toggle

  1. func (p Pin) Toggle()

Toggle switches an output pin from low to high or from high to low.Warning: only use this on an output pin!

type PinConfig

  1. type PinConfig struct {
  2. Mode PinMode
  3. }

type PinMode

  1. type PinMode uint8

type RingBuffer

  1. type RingBuffer struct {
  2. rxbuffer [bufferSize]volatile.Register8
  3. head volatile.Register8
  4. tail volatile.Register8
  5. }

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

  1. 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

  1. 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

  1. func (rb *RingBuffer) Used() uint8

Used returns how many bytes in buffer have been used.

type SPI

  1. type SPI struct {
  2. Bus *sam.SERCOM_SPIM_Type
  3. SERCOM uint8
  4. }

SPI

func (SPI) Configure

  1. func (spi SPI) Configure(config SPIConfig) error

Configure is intended to setup the SPI interface.

func (SPI) Transfer

  1. func (spi SPI) Transfer(w byte) (byte, error)

Transfer writes/reads a single byte using the SPI interface.

func (SPI) Tx

  1. func (spi SPI) Tx(w, r []byte) error

Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/readinterface, there must always be the same number of bytes written as bytes read.The Tx method knows about this, and offers a few different ways of calling it.

This form sends the bytes in tx buffer, putting the resulting bytes read into the rx buffer.Note that the tx and rx buffers must be the same size:

  1. spi.Tx(tx, rx)

This form sends the tx buffer, ignoring the result. Useful for sending “commands” that return zerosuntil all the bytes in the command packet have been received:

  1. spi.Tx(tx, nil)

This form sends zeros, putting the result into the rx buffer. Good for reading a “result packet”:

  1. spi.Tx(nil, rx)

type SPIConfig

  1. type SPIConfig struct {
  2. Frequency uint32
  3. SCK Pin
  4. MOSI Pin
  5. MISO Pin
  6. LSBFirst bool
  7. Mode uint8
  8. }

SPIConfig is used to store config info for SPI.

type UART

  1. type UART struct {
  2. Buffer *RingBuffer
  3. Bus *sam.SERCOM_USART_INT_Type
  4. SERCOM uint8
  5. IRQVal uint32 // RXC interrupt
  6. }

UART on the SAMD51.

func (UART) Buffered

  1. func (uart UART) Buffered() int

Buffered returns the number of bytes currently stored in the RX buffer.

func (UART) Configure

  1. func (uart UART) Configure(config UARTConfig) error

Configure the UART.

func (UART) Read

  1. func (uart UART) Read(data []byte) (n int, err error)

Read from the RX buffer.

func (UART) ReadByte

  1. 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

  1. 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) SetBaudRate

  1. func (uart UART) SetBaudRate(br uint32)

SetBaudRate sets the communication speed for the UART.

func (UART) Write

  1. func (uart UART) Write(data []byte) (n int, err error)

Write data to the UART.

func (UART) WriteByte

  1. func (uart UART) WriteByte(c byte) error

WriteByte writes a byte of data to the UART.

type UARTConfig

  1. type UARTConfig struct {
  2. BaudRate uint32
  3. TX Pin
  4. RX Pin
  5. }

type USBCDC

  1. type USBCDC struct {
  2. Buffer *RingBuffer
  3. }

USBCDC is the USB CDC aka serial over USB interface on the SAMD21.

func (USBCDC) Buffered

  1. func (usbcdc USBCDC) Buffered() int

Buffered returns the number of bytes currently stored in the RX buffer.

func (USBCDC) Configure

  1. func (usbcdc USBCDC) Configure(config UARTConfig)

Configure the USB CDC interface. The config is here for compatibility with the UART interface.

func (USBCDC) DTR

  1. func (usbcdc USBCDC) DTR() bool

func (USBCDC) RTS

  1. func (usbcdc USBCDC) RTS() bool

func (USBCDC) Read

  1. func (usbcdc USBCDC) Read(data []byte) (n int, err error)

Read from the RX buffer.

func (USBCDC) ReadByte

  1. func (usbcdc USBCDC) ReadByte() (byte, error)

ReadByte reads a single byte from the RX buffer.If there is no data in the buffer, returns an error.

func (USBCDC) Receive

  1. func (usbcdc USBCDC) Receive(data byte)

Receive handles adding data to the UART’s data buffer.Usually called by the IRQ handler for a machine.

func (USBCDC) Write

  1. func (usbcdc USBCDC) Write(data []byte) (n int, err error)

Write data to the USBCDC.

func (USBCDC) WriteByte

  1. func (usbcdc USBCDC) WriteByte(c byte) error

WriteByte writes a byte of data to the USB CDC interface.