all: format code according to Go 1.19 rules

Go 1.19 started reformatting code in a way that makes it more obvious
how it will be rendered on pkg.go.dev. It gets it almost right, but not
entirely. Therefore, I had to modify some of the comments so that they
are formatted correctly.
This commit is contained in:
Ayke van Laethem
2022-08-03 16:24:47 +02:00
committed by Ayke
parent f936125658
commit c7a23183e8
114 changed files with 509 additions and 381 deletions
-1
View File
@@ -4,7 +4,6 @@
// This contains the pin mappings for the Arduino MKR1000 board.
//
// For more information, see: https://store.arduino.cc/usa/arduino-mkr1000-with-headers-mounted
//
package machine
// used to reset into bootloader
-1
View File
@@ -4,7 +4,6 @@
// This contains the pin mappings for the Arduino MKR WiFi 1010 board.
//
// For more information, see: https://store.arduino.cc/usa/mkr-wifi-1010
//
package machine
// used to reset into bootloader
-1
View File
@@ -4,7 +4,6 @@
// This contains the pin mappings for the Arduino Nano33 IoT board.
//
// For more information, see: https://store.arduino.cc/nano-33-iot
//
package machine
// used to reset into bootloader
+3 -3
View File
@@ -6,7 +6,6 @@
// For more information, see: https://shop.pimoroni.com/products/badger-2040
// Also
// - Badger 2040 schematic: https://cdn.shopify.com/s/files/1/0174/1800/files/badger_2040_schematic.pdf?v=1645702148
//
package machine
import (
@@ -58,14 +57,15 @@ const (
// QSPI pins¿?
const (
/* TODO
/*
TODO
SPI0_SD0_PIN Pin = QSPI_SD0
SPI0_SD1_PIN Pin = QSPI_SD1
SPI0_SD2_PIN Pin = QSPI_SD2
SPI0_SD3_PIN Pin = QSPI_SD3
SPI0_SCK_PIN Pin = QSPI_SCLKGPIO6
SPI0_CS_PIN Pin = QSPI_CS
*/
)
+5 -6
View File
@@ -10,11 +10,11 @@
//
// Special version of bossac is required.
// This executable can be obtained two ways:
// 1) In Arduino IDE, install support for the board ("Arduino Mbed OS Nano Boards")
// Search for "tools/bossac/1.9.1-arduino2/bossac" in Arduino IDEs directory
// 2) Download https://downloads.arduino.cc/packages/package_index.json
// Search for "bossac-1.9.1-arduino2" in that file
// Download tarball for your OS and unpack it
// 1. In Arduino IDE, install support for the board ("Arduino Mbed OS Nano Boards")
// Search for "tools/bossac/1.9.1-arduino2/bossac" in Arduino IDEs directory
// 2. Download https://downloads.arduino.cc/packages/package_index.json
// Search for "bossac-1.9.1-arduino2" in that file
// Download tarball for your OS and unpack it
//
// Once you have the executable, make it accessible in your PATH as "bossac_arduino2".
//
@@ -29,7 +29,6 @@
//
// SoftDevice overwrites original bootloader and flashing method described above is not avalable anymore.
// Instead, please use debug probe and flash your code with "nano-33-ble-s140v7" target.
//
package machine
const HasLowFrequencyCrystal = true
-1
View File
@@ -10,7 +10,6 @@
// Also
// - Datasheets: https://docs.arduino.cc/hardware/nano-rp2040-connect
// - Nano RP2040 Connect technical reference: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-01-technical-reference
//
package machine
import (
-1
View File
@@ -4,7 +4,6 @@
// This contains the pin mappings for the ProductivityOpen P1AM-100 board.
//
// For more information, see: https://facts-engineering.github.io/
//
package machine
// used to reset into bootloader
-1
View File
@@ -17,7 +17,6 @@
//
// - https://wiki.seeedstudio.com/XIAO_BLE/
// - https://github.com/Seeed-Studio/ArduinoCore-mbed/tree/master/variants/SEEED_XIAO_NRF52840_SENSE
//
package machine
const HasLowFrequencyCrystal = true
-1
View File
@@ -6,7 +6,6 @@
// XIAO RP2040 is a microcontroller using the Raspberry Pi RP2040 chip.
//
// - https://wiki.seeedstudio.com/XIAO-RP2040/
//
package machine
import (
+2 -2
View File
@@ -264,7 +264,7 @@ func (pwm PWM) Configure(config PWMConfig) error {
// SetPeriod updates the period of this PWM peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -694,7 +694,7 @@ func (pwm PWM) SetInverting(channel uint8, inverting bool) {
// cycle, in other words the fraction of time the channel output is high (or low
// when inverted). For example, to set it to a 25% duty cycle, use:
//
// pwm.Set(channel, pwm.Top() / 4)
// pwm.Set(channel, pwm.Top() / 4)
//
// pwm.Set(channel, 0) will set the output to low and pwm.Set(channel,
// pwm.Top()) will set the output to high, assuming the output isn't inverted.
+2 -2
View File
@@ -134,7 +134,7 @@ func (pwm PWM) Configure(config PWMConfig) error {
// SetPeriod updates the period of this PWM peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -375,7 +375,7 @@ func (pwm PWM) SetInverting(channel uint8, inverting bool) {
// cycle, in other words the fraction of time the channel output is high (or low
// when inverted). For example, to set it to a 25% duty cycle, use:
//
// pwm.Set(channel, pwm.Top() / 4)
// pwm.Set(channel, pwm.Top() / 4)
//
// pwm.Set(channel, 0) will set the output to low and pwm.Set(channel,
// pwm.Top()) will set the output to high, assuming the output isn't inverted.
+9 -10
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAMD21-Family-DataSheet-DS40001882D.pdf
//
package machine
import (
@@ -88,10 +87,11 @@ const (
// SERCOM and SERCOM-ALT.
//
// Observations:
// * There are six SERCOMs. Those SERCOM numbers can be encoded in 3 bits.
// * Even pad numbers are always on even pins, and odd pad numbers are always on
// - There are six SERCOMs. Those SERCOM numbers can be encoded in 3 bits.
// - Even pad numbers are always on even pins, and odd pad numbers are always on
// odd pins.
// * Pin pads come in pairs. If PA00 has pad 0, then PA01 has pad 1.
// - Pin pads come in pairs. If PA00 has pad 0, then PA01 has pad 1.
//
// With this information, we can encode SERCOM pin/pad numbers much more
// efficiently. First of all, due to pads coming in pairs, we can ignore half
// the pins: the information for an odd pin can be calculated easily from the
@@ -1285,17 +1285,16 @@ var (
// 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:
//
// spi.Tx(tx, rx)
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
//
// spi.Tx(nil, rx)
func (spi SPI) Tx(w, r []byte) error {
switch {
case w == nil:
@@ -1441,7 +1440,7 @@ func (tcc *TCC) Configure(config PWMConfig) error {
// SetPeriod updates the period of this TCC peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -1709,7 +1708,7 @@ func (tcc *TCC) SetInverting(channel uint8, inverting bool) {
// cycle, in other words the fraction of time the channel output is high (or low
// when inverted). For example, to set it to a 25% duty cycle, use:
//
// tcc.Set(channel, tcc.Top() / 4)
// tcc.Set(channel, tcc.Top() / 4)
//
// tcc.Set(channel, 0) will set the output to low and tcc.Set(channel,
// tcc.Top()) will set the output to high, assuming the output isn't inverted.
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAMD21-Family-DataSheet-DS40001882D.pdf
//
package machine
import (
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAMD21-Family-DataSheet-DS40001882D.pdf
//
package machine
import (
+9 -10
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import (
@@ -250,12 +249,13 @@ const (
// SERCOM and SERCOM-ALT.
//
// Observations:
// * There are eight SERCOMs. Those SERCOM numbers can be encoded in 4 bits.
// * Even pad numbers are usually on even pins, and odd pad numbers are usually
// - There are eight SERCOMs. Those SERCOM numbers can be encoded in 4 bits.
// - Even pad numbers are usually on even pins, and odd pad numbers are usually
// on odd pins. The exception is SERCOM-ALT, which sometimes swaps pad 0 and 1.
// With that, there is still an invariant that the pad number for an odd pin is
// the pad number for the corresponding even pin with the low bit toggled.
// * Pin pads come in pairs. If PA00 has pad 0, then PA01 has pad 1.
// - Pin pads come in pairs. If PA00 has pad 0, then PA01 has pad 1.
//
// With this information, we can encode SERCOM pin/pad numbers much more
// efficiently. Due to pads coming in pairs, we can ignore half the pins: the
// information for an odd pin can be calculated easily from the preceding even
@@ -1538,17 +1538,16 @@ var (
// 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:
//
// spi.Tx(tx, rx)
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
//
// spi.Tx(nil, rx)
func (spi SPI) Tx(w, r []byte) error {
switch {
case w == nil:
@@ -1672,7 +1671,7 @@ func (tcc *TCC) Configure(config PWMConfig) error {
// SetPeriod updates the period of this TCC peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -1962,7 +1961,7 @@ func (tcc *TCC) SetInverting(channel uint8, inverting bool) {
// cycle, in other words the fraction of time the channel output is high (or low
// when inverted). For example, to set it to a 25% duty cycle, use:
//
// tcc.Set(channel, tcc.Top() / 4)
// tcc.Set(channel, tcc.Top() / 4)
//
// tcc.Set(channel, 0) will set the output to low and tcc.Set(channel,
// tcc.Top()) will set the output to high, assuming the output isn't inverted.
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAM_D5xE5x_Family_Data_Sheet_DS60001507F.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAM_D5xE5x_Family_Data_Sheet_DS60001507F.pdf
//
package machine
import "device/sam"
-1
View File
@@ -5,7 +5,6 @@
//
// Datasheet:
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf
//
package machine
import "device/sam"
-1
View File
@@ -462,7 +462,6 @@ func (spi SPI) Transfer(w byte) (byte, error) {
// interface, there must always be the same number of bytes written as bytes read.
// This is accomplished by sending zero bits if r is bigger than w or discarding
// the incoming data if w is bigger than r.
//
func (spi SPI) Tx(w, r []byte) error {
toTransfer := len(w)
if len(r) > toTransfer {
+1 -1
View File
@@ -726,7 +726,7 @@ func (p Pin) getPad() (pad *volatile.Register32, mux *volatile.Register32) {
//
// The reference manual refers to this functionality as a "Daisy Chain". The
// associated docs are found in the i.MX RT1060 Processor Reference Manual:
// "Chapter 11.3.3 Daisy chain - multi pads driving same module input pin"
// "Chapter 11.3.3 Daisy chain - multi pads driving same module input pin"
type muxSelect struct {
mux uint8 // AF mux selection (NOT a Pin type)
sel *volatile.Register32 // AF selection register
+2 -1
View File
@@ -204,7 +204,8 @@ func (spi *SPI) hasHardwareCSPin() bool {
// getClockDivisor finds the SPI prescalar that minimizes the error between
// requested frequency and possible frequencies available with the LPSPI clock.
// this routine is based on Teensyduino (libraries/SPI/SPI.cpp):
// `void SPIClass::setClockDivider_noInline(uint32_t clk)`
//
// void SPIClass::setClockDivider_noInline(uint32_t clk)
func (spi *SPI) getClockDivisor(freq uint32) uint32 {
const clock = 132000000 // LPSPI root clock frequency (PLL2)
d := uint32(clock)
+4 -2
View File
@@ -188,8 +188,10 @@ func (uart *UART) WriteByte(c byte) error {
//
// This is an integral (non-floating point) translation of the logic at the
// beginning of:
// void HardwareSerial::begin(uint32_t baud, uint16_t format)
// (from Teensyduino: `cores/teensy4/HardwareSerial.cpp`)
//
// void HardwareSerial::begin(uint32_t baud, uint16_t format)
//
// (from Teensyduino: cores/teensy4/HardwareSerial.cpp)
//
// We don't want to use floating point here in case it gets called from an ISR
// or very early during system init.
+3 -4
View File
@@ -133,17 +133,16 @@ func (spi SPI) Transfer(w byte) (byte, error) {
// 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:
//
// spi.Tx(tx, rx)
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
//
// spi.Tx(nil, rx)
func (spi SPI) Tx(w, r []byte) error {
var err error
+2 -2
View File
@@ -299,7 +299,7 @@ func (pwm *PWM) Configure(config PWMConfig) error {
// SetPeriod updates the period of this PWM peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -449,7 +449,7 @@ func (pwm *PWM) SetInverting(channel uint8, inverting bool) {
// Set updates the channel value. This is used to control the channel duty
// cycle. For example, to set it to a 25% duty cycle, use:
//
// ch.Set(ch.Top() / 4)
// ch.Set(ch.Top() / 4)
//
// ch.Set(0) will set the output to low and ch.Set(ch.Top()) will set the output
// to high, assuming the output isn't inverted.
+22 -7
View File
@@ -66,10 +66,12 @@ var (
// Passing a nil value for w or r skips the transfer corresponding to write
// or read, respectively.
//
// i2c.Tx(addr, nil, r)
// i2c.Tx(addr, nil, r)
//
// Performs only a read transfer.
//
// i2c.Tx(addr, w, nil)
// i2c.Tx(addr, w, nil)
//
// Performs only a write transfer.
func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
// timeout in microseconds.
@@ -79,11 +81,14 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
// Configure initializes i2c peripheral and configures I2C config's pins passed.
// Here's a list of valid SDA and SCL GPIO pins on bus I2C0 of the rp2040:
// SDA: 0, 4, 8, 12, 16, 20
// SCL: 1, 5, 9, 13, 17, 21
//
// SDA: 0, 4, 8, 12, 16, 20
// SCL: 1, 5, 9, 13, 17, 21
//
// Same as above for I2C1 bus:
// SDA: 2, 6, 10, 14, 18, 26
// SCL: 3, 7, 11, 15, 19, 27
//
// SDA: 2, 6, 10, 14, 18, 26
// SCL: 3, 7, 11, 15, 19, 27
func (i2c *I2C) Configure(config I2CConfig) error {
const defaultBaud uint32 = 100_000 // 100kHz standard mode
if config.SCL == 0 {
@@ -107,6 +112,7 @@ func (i2c *I2C) Configure(config I2CConfig) error {
// SetBaudRate sets the I2C frequency. It has the side effect of also
// enabling the I2C hardware if disabled beforehand.
//
//go:inline
func (i2c *I2C) SetBaudRate(br uint32) error {
@@ -168,6 +174,7 @@ func (i2c *I2C) enable() {
}
// Implemented as per 4.3.10.3. Disabling DW_apb_i2c section.
//
//go:inline
func (i2c *I2C) disable() error {
const MAX_T_POLL_COUNT = 64 // 64 us timeout corresponds to around 1000kb/s i2c transfer rate.
@@ -203,6 +210,7 @@ func (i2c *I2C) init(config I2CConfig) error {
}
// reset sets I2C register RESET bits in the reset peripheral and then clears them.
//
//go:inline
func (i2c *I2C) reset() {
resetVal := i2c.deinit()
@@ -213,6 +221,7 @@ func (i2c *I2C) reset() {
}
// deinit sets reset bit for I2C. Must call reset to reenable I2C after deinit.
//
//go:inline
func (i2c *I2C) deinit() (resetVal uint32) {
switch {
@@ -348,18 +357,21 @@ func (i2c *I2C) tx(addr uint8, tx, rx []byte, timeout_us uint64) (err error) {
}
// writeAvailable determines non-blocking write space available
//
//go:inline
func (i2c *I2C) writeAvailable() uint32 {
return rp.I2C0_IC_COMP_PARAM_1_TX_BUFFER_DEPTH_Pos - i2c.Bus.IC_TXFLR.Get()
}
// readAvailable determines number of bytes received
//
//go:inline
func (i2c *I2C) readAvailable() uint32 {
return i2c.Bus.IC_RXFLR.Get()
}
// Equivalent to IC_CLR_TX_ABRT.Get() (side effect clears ABORT_REASON)
//
//go:inline
func (i2c *I2C) clearAbortReason() {
// Note clearing the abort flag also clears the reason, and
@@ -369,13 +381,16 @@ func (i2c *I2C) clearAbortReason() {
}
// getAbortReason reads IC_TX_ABRT_SOURCE register.
//
//go:inline
func (i2c *I2C) getAbortReason() uint32 {
return i2c.Bus.IC_TX_ABRT_SOURCE.Get()
}
// returns true if RAW_INTR_STAT bits in mask are all set. performs:
// RAW_INTR_STAT & mask == mask
//
// RAW_INTR_STAT & mask == mask
//
//go:inline
func (i2c *I2C) interrupted(mask uint32) bool {
reg := i2c.Bus.IC_RAW_INTR_STAT.Get()
+13 -8
View File
@@ -45,8 +45,10 @@ type pwmGroup struct {
}
// Equivalent of
// var pwmSlice []pwmGroup = (*[8]pwmGroup)(unsafe.Pointer(rp.PWM))[:]
// return &pwmSlice[index]
//
// var pwmSlice []pwmGroup = (*[8]pwmGroup)(unsafe.Pointer(rp.PWM))[:]
// return &pwmSlice[index]
//
// 0x14 is the size of a pwmGroup.
func getPWMGroup(index uintptr) *pwmGroup {
return (*pwmGroup)(unsafe.Pointer(uintptr(unsafe.Pointer(rp.PWM)) + 0x14*index))
@@ -112,7 +114,7 @@ func (pwm *pwmGroup) peripheral() uint8 {
// SetPeriod updates the period of this PWM peripheral in nanoseconds.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// Where frequency is in hertz. If you use a period of 0, a period
// that works well for LEDs will be picked.
@@ -167,7 +169,7 @@ func (p *pwmGroup) SetInverting(channel uint8, inverting bool) {
// cycle, in other words the fraction of time the channel output is high (or low
// when inverted). For example, to set it to a 25% duty cycle, use:
//
// pwm.Set(channel, pwm.Top() / 4)
// pwm.Set(channel, pwm.Top() / 4)
//
// pwm.Set(channel, 0) will set the output to low and pwm.Set(channel,
// pwm.Top()) will set the output to high, assuming the output isn't inverted.
@@ -238,14 +240,17 @@ func (pwm *pwmGroup) setPhaseCorrect(correct bool) {
}
// Takes any of the following:
// rp.PWM_CH0_CSR_DIVMODE_DIV, rp.PWM_CH0_CSR_DIVMODE_FALL,
// rp.PWM_CH0_CSR_DIVMODE_LEVEL, rp.PWM_CH0_CSR_DIVMODE_RISE
//
// rp.PWM_CH0_CSR_DIVMODE_DIV, rp.PWM_CH0_CSR_DIVMODE_FALL,
// rp.PWM_CH0_CSR_DIVMODE_LEVEL, rp.PWM_CH0_CSR_DIVMODE_RISE
func (pwm *pwmGroup) setDivMode(mode uint32) {
pwm.CSR.ReplaceBits(mode<<rp.PWM_CH0_CSR_DIVMODE_Pos, rp.PWM_CH0_CSR_DIVMODE_Msk, 0)
}
// setPeriod sets the pwm peripheral period (frequency). Calculates DIV_INT,DIV_FRAC and sets it from following equation:
// cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)
//
// cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)
//
// where cycles is amount of clock cycles per PWM period.
func (pwm *pwmGroup) setPeriod(period uint64) error {
// This period calculation algorithm consists of
@@ -303,7 +308,7 @@ func (pwm *pwmGroup) setPeriod(period uint64) error {
// frac's (DIV_FRAC) default value on reset is 0. Max value for frac is 15 (4 bits). This is known as a fixed-point
// fractional number.
//
// cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)
// cycles = (TOP+1) * (CSRPHCorrect + 1) * (DIV_INT + DIV_FRAC/16)
func (pwm *pwmGroup) setClockDiv(Int, frac uint8) {
pwm.DIV.ReplaceBits((uint32(frac)<<rp.PWM_CH0_DIV_FRAC_Pos)|
u32max(uint32(Int), 1)<<rp.PWM_CH0_DIV_INT_Pos, rp.PWM_CH0_DIV_FRAC_Msk|rp.PWM_CH0_DIV_INT_Msk, 0)
+17 -10
View File
@@ -58,21 +58,21 @@ const _SPITimeout = 10 * 1000 // 10 ms
// 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:
//
// spi.Tx(tx, rx)
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
// spi.Tx(nil, rx)
//
// Remark: This implementation (RP2040) allows reading into buffer with a custom repeated
// value on tx.
//
// spi.Tx([]byte{0xff}, rx) // may cause unwanted heap allocations.
// spi.Tx([]byte{0xff}, rx) // may cause unwanted heap allocations.
//
// This form sends 0xff and puts the result into rx buffer. Useful for reading from SD cards
// which require 0xff input on SI.
@@ -150,13 +150,17 @@ func (spi SPI) GetBaudRate() uint32 {
// Default baudrate of 115200 is used if Frequency == 0. Default
// word length (data bits) is 8.
// Below is a list of GPIO pins corresponding to SPI0 bus on the rp2040:
// SI : 0, 4, 17 a.k.a RX and MISO (if rp2040 is master)
// SO : 3, 7, 19 a.k.a TX and MOSI (if rp2040 is master)
// SCK: 2, 6, 18
//
// SI : 0, 4, 17 a.k.a RX and MISO (if rp2040 is master)
// SO : 3, 7, 19 a.k.a TX and MOSI (if rp2040 is master)
// SCK: 2, 6, 18
//
// SPI1 bus GPIO pins:
// SI : 8, 12
// SO : 11, 15
// SCK: 10, 14
//
// SI : 8, 12
// SO : 11, 15
// SCK: 10, 14
//
// No pin configuration is needed of SCK, SDO and SDI needed after calling Configure.
func (spi SPI) Configure(config SPIConfig) error {
const defaultBaud uint32 = 115200
@@ -217,6 +221,7 @@ func (spi SPI) setFormat(databits, mode uint8, frameFormat uint32) {
}
// reset resets SPI and waits until reset is done.
//
//go:inline
func (spi SPI) reset() {
resetVal := spi.deinit()
@@ -240,12 +245,14 @@ func (spi SPI) deinit() (resetVal uint32) {
}
// isWritable returns false if no space is available to write. True if a write is possible
//
//go:inline
func (spi SPI) isWritable() bool {
return spi.Bus.SSPSR.HasBits(rp.SPI0_SSPSR_TNF)
}
// isReadable returns true if a read is possible i.e. data is present
//
//go:inline
func (spi SPI) isReadable() bool {
return spi.Bus.SSPSR.HasBits(rp.SPI0_SSPSR_RNE)
+2 -1
View File
@@ -72,7 +72,8 @@ func (p Pin) Configure(config PinConfig) {
}
// Configure this pin with the given configuration including alternate
// function mapping if necessary.
//
// function mapping if necessary.
func (p Pin) ConfigureAltFunc(config PinConfig, altFunc uint8) {
// Configure the GPIO pin.
p.enableClock()
+2 -2
View File
@@ -115,7 +115,7 @@ func (t *TIM) SetMatchInterrupt(channel uint8, callback ChannelCallback) error {
// SetPeriod updates the period of this PWM peripheral.
// To set a particular frequency, use the following formula:
//
// period = 1e9 / frequency
// period = 1e9 / frequency
//
// If you use a period of 0, a period that works well for LEDs will be picked.
//
@@ -195,7 +195,7 @@ func (t *TIM) Channel(pin Pin) (uint8, error) {
// Set updates the channel value. This is used to control the channel duty
// cycle. For example, to set it to a 25% duty cycle, use:
//
// t.Set(ch, t.Top() / 4)
// t.Set(ch, t.Top() / 4)
//
// ch.Set(0) will set the output to low and ch.Set(ch.Top()) will set the output
// to high, assuming the output isn't inverted.
+3 -4
View File
@@ -25,17 +25,16 @@ var (
// 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:
//
// spi.Tx(tx, rx)
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
//
// spi.Tx(nil, rx)
func (spi SPI) Tx(w, r []byte) error {
var err error
+21 -24
View File
@@ -114,24 +114,21 @@ func (kb *keyboard) Write(b []byte) (n int, err error) {
// stateful method with respect to the receiver Keyboard, meaning that its exact
// behavior will depend on the current state of its UTF-8 decode state machine:
//
// (a) If the given byte is a valid ASCII encoding (0-127), then a keypress
// sequence is immediately transmitted for the respective Keycode.
// 1. If the given byte is a valid ASCII encoding (0-127), then a keypress
// sequence is immediately transmitted for the respective Keycode.
// 2. If the given byte represents the final byte in a multi-byte codepoint,
// then a keypress sequence is immediately transmitted by translating the
// multi-byte codepoint to its respective Keycode.
// 3. If the given byte appears to represent high bits for a multi-byte
// codepoint, then the bits are copied to the receiver's internal state
// machine buffer for use by a subsequent call to WriteByte() (or Write())
// that completes the codepoint.
// 4. If the given byte is out of range, or contains illegal bits for the
// current state of the UTF-8 decoder, then the UTF-8 decode state machine
// is reset to its initial state.
//
// (b) If the given byte represents the final byte in a multi-byte codepoint,
// then a keypress sequence is immediately transmitted by translating the
// multi-byte codepoint to its respective Keycode.
//
// (c) If the given byte appears to represent high bits for a multi-byte
// codepoint, then the bits are copied to the receiver's internal state
// machine buffer for use by a subsequent call to WriteByte() (or Write())
// that completes the codepoint.
//
// (d) If the given byte is out of range, or contains illegal bits for the
// current state of the UTF-8 decoder, then the UTF-8 decode state machine
// is reset to its initial state.
//
// In cases (c) and (d), a keypress sequence is not generated and no data is
// transmitted. In case (c), additional bytes must be received via WriteByte()
// In cases 3 and 4, a keypress sequence is not generated and no data is
// transmitted. In case 3, additional bytes must be received via WriteByte()
// (or Write()) to complete or discard the current codepoint.
func (kb *keyboard) WriteByte(b byte) error {
switch {
@@ -211,13 +208,13 @@ func (kb *keyboard) writeKeycode(c Keycode) error {
//
// The following values of Keycode are supported:
//
// 0x0020 - 0x007F ASCII (U+0020 to U+007F) [USES LAYOUT]
// 0x0080 - 0xC1FF Unicode (U+0080 to U+C1FF) [USES LAYOUT]
// 0xC200 - 0xDFFF UTF-8 packed (U+0080 to U+07FF) [USES LAYOUT]
// 0xE000 - 0xE0FF Modifier key (bitmap, 8 keys, Shift/Ctrl/Alt/GUI)
// 0xE200 - 0xE2FF System key (HID usage code, page 1)
// 0xE400 - 0xE7FF Media/Consumer key (HID usage code, page 12)
// 0xF000 - 0xFFFF Normal key (HID usage code, page 7)
// 0x0020 - 0x007F ASCII (U+0020 to U+007F) [USES LAYOUT]
// 0x0080 - 0xC1FF Unicode (U+0080 to U+C1FF) [USES LAYOUT]
// 0xC200 - 0xDFFF UTF-8 packed (U+0080 to U+07FF) [USES LAYOUT]
// 0xE000 - 0xE0FF Modifier key (bitmap, 8 keys, Shift/Ctrl/Alt/GUI)
// 0xE200 - 0xE2FF System key (HID usage code, page 1)
// 0xE400 - 0xE7FF Media/Consumer key (HID usage code, page 12)
// 0xF000 - 0xFFFF Normal key (HID usage code, page 7)
func (kb *keyboard) Press(c Keycode) error {
if err := kb.Down(c); nil != err {
return err
+1
View File
@@ -5,6 +5,7 @@ type Keycode uint16
// keycode returns the given Unicode codepoint translated to a Keycode sequence.
// Unicode codepoints greater than U+FFFF are unsupported.
//
//go:inline
func keycode(p uint16) Keycode {
if p < 0x80 {