circuitplay-express

Constants

  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 RESET_MAGIC_VALUE = 0xf01669ef

used to reset into bootloader

  1. const (
  2. D0 = PB09
  3. D1 = PB08
  4. D2 = PB02
  5. D3 = PB03
  6. D4 = PA28
  7. D5 = PA14
  8. D6 = PA05
  9. D7 = PA15
  10. D8 = PB23
  11. D9 = PA06
  12. D10 = PA07
  13. D11 = NoPin // does not seem to exist
  14. D12 = PA02
  15. D13 = PA17 // PWM available
  16. )

GPIO Pins

  1. const (
  2. A0 = PA02 // PWM available, also ADC/AIN[0]
  3. A1 = PA05 // ADC/AIN[5]
  4. A2 = PA06 // PWM available, also ADC/AIN[6]
  5. A3 = PA07 // PWM available, also ADC/AIN[7]
  6. A4 = PB03 // PORTB
  7. A5 = PB02 // PORTB
  8. A6 = PB09 // PORTB
  9. A7 = PB08 // PORTB
  10. A8 = PA11 // ADC/AIN[19]
  11. A9 = PA09 // ADC/AIN[17]
  12. A10 = PA04
  13. )

Analog Pins

  1. const (
  2. LED = D13
  3. NEOPIXELS = D8
  4. BUTTONA = D4
  5. BUTTONB = D5
  6. SLIDER = D7 // built-in slide switch
  7. BUTTON = BUTTONA
  8. BUTTON1 = BUTTONB
  9. LIGHTSENSOR = A8
  10. TEMPSENSOR = A9
  11. PROXIMITY = A10
  12. )
  1. const (
  2. USBCDC_DM_PIN = PA24
  3. USBCDC_DP_PIN = PA25
  4. )

USBCDC pins (logical UART0)

  1. const (
  2. UART_TX_PIN = PB08 // PORTB
  3. UART_RX_PIN = PB09 // PORTB
  4. )

UART0 pins (logical UART1)

  1. const (
  2. SDA_PIN = PB02 // I2C0 external
  3. SCL_PIN = PB03 // I2C0 external
  4. SDA1_PIN = PA00 // I2C1 internal
  5. SCL1_PIN = PA01 // I2C1 internal
  6. )

I2C pins

  1. const (
  2. SPI0_SCK_PIN = PA21 // SCK: SERCOM3/PAD[3]
  3. SPI0_MOSI_PIN = PA20 // MOSI: SERCOM3/PAD[2]
  4. SPI0_MISO_PIN = PA16 // MISO: SERCOM3/PAD[0]
  5. )

SPI pins (internal flash)

  1. const (
  2. I2S_SCK_PIN = PA10
  3. I2S_SD_PIN = PA08
  4. I2S_WS_PIN = NoPin // no WS, instead uses SCK to sync
  5. )

I2S 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. PinCom PinMode = 6
  8. //PinAC_CLK PinMode = 7
  9. PinDigital PinMode = 8
  10. PinInput PinMode = 9
  11. PinInputPullup PinMode = 10
  12. PinOutput PinMode = 11
  13. PinPWM PinMode = PinTimer
  14. PinPWMAlt PinMode = PinTimerAlt
  15. PinInputPulldown PinMode = 12
  16. )

Variables

  1. var (
  2. UART1 = UART{
  3. Buffer: NewRingBuffer(),
  4. Bus: sam.SERCOM4_USART,
  5. SERCOM: 4,
  6. }
  7. )

UART1 on the Circuit Playground Express.

  1. var (
  2. // external device
  3. I2C0 = I2C{
  4. Bus: sam.SERCOM5_I2CM,
  5. SERCOM: 5,
  6. }
  7. // internal device
  8. I2C1 = I2C{
  9. Bus: sam.SERCOM1_I2CM,
  10. SERCOM: 1,
  11. }
  12. )

I2C on the Circuit Playground Express.

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

SPI on the Circuit Playground Express.

  1. var (
  2. I2S0 = I2S{Bus: sam.I2S}
  3. )

I2S on the Circuit Playground Express.

  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. )
  1. var (
  2. ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
  3. )

func CPUFrequency

  1. func CPUFrequency() uint32

Return the current CPU frequency in hertz.

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 preperationto 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 SAMD21.

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 I2S

  1. type I2S struct {
  2. Bus *sam.I2S_Type
  3. }

I2S

func (I2S) Close

  1. func (i2s I2S) Close() error

Close the I2S bus.

func (I2S) Configure

  1. func (i2s I2S) Configure(config I2SConfig)

Configure is used to configure the I2S interface. You must call thisbefore you can use the I2S bus.

func (I2S) Read

  1. func (i2s I2S) Read(p []uint32) (n int, err error)

Read data from the I2S bus into the provided slice.The I2S bus must already have been configured correctly.

func (I2S) Write

  1. func (i2s I2S) Write(p []uint32) (n int, err error)

Write data to the I2S bus from the provided slice.The I2S bus must already have been configured correctly.

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!

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_SPI_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_Type
  4. SERCOM uint8
  5. Interrupt interrupt.Interrupt
  6. }

UART on the SAMD21.

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.