diff --git a/Makefile b/Makefile index 31556bc2..09ac979c 100644 --- a/Makefile +++ b/Makefile @@ -612,6 +612,8 @@ endif @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=qtpy-rp2040 examples/echo @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=kb2040 examples/echo + @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=macropad-rp2040 examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=badger2040 examples/blinky1 diff --git a/README.md b/README.md index d6f65159..df90ec73 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ See the [getting started instructions](https://tinygo.org/getting-started/) for You can compile TinyGo programs for microcontrollers, WebAssembly and Linux. -The following 91 microcontroller boards are currently supported: +The following 92 microcontroller boards are currently supported: * [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333) * [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333) @@ -59,6 +59,7 @@ The following 91 microcontroller boards are currently supported: * [Adafruit ItsyBitsy M0](https://www.adafruit.com/product/3727) * [Adafruit ItsyBitsy M4](https://www.adafruit.com/product/3800) * [Adafruit ItsyBitsy nRF52840](https://www.adafruit.com/product/4481) +* [Adafruit KB2040](https://www.adafruit.com/product/5302) * [Adafruit MacroPad RP2040](https://www.adafruit.com/product/5100) * [Adafruit Matrix Portal M4](https://www.adafruit.com/product/4745) * [Adafruit Metro M4 Express Airlift](https://www.adafruit.com/product/4000) diff --git a/src/machine/board_kb2040.go b/src/machine/board_kb2040.go new file mode 100644 index 00000000..288f1ddf --- /dev/null +++ b/src/machine/board_kb2040.go @@ -0,0 +1,109 @@ +//go:build kb2040 + +package machine + +import ( + "device/rp" + "runtime/interrupt" +) + +// Onboard crystal oscillator frequency, in MHz. +const xoscFreq = 12 // MHz + +// GPIO Pins +const ( + D0 = GPIO0 + D1 = GPIO1 + D2 = GPIO2 + D3 = GPIO3 + D4 = GPIO4 + D5 = GPIO5 + D6 = GPIO6 + D7 = GPIO7 + D8 = GPIO8 + D9 = GPIO9 + D10 = GPIO10 +) + +// Analog pins +const ( + A0 = GPIO26 + A1 = GPIO27 + A2 = GPIO28 + A3 = GPIO29 +) + +// Note: there is no user-controllable LED on the KB2040 board +// const LED = notConnected + +// I2C Pins. +const ( + I2C0_SDA_PIN = GPIO12 + I2C0_SCL_PIN = GPIO13 + + I2C1_SDA_PIN = GPIO2 + I2C1_SCL_PIN = GPIO3 + + SDA_PIN = I2C0_SDA_PIN + SCL_PIN = I2C0_SCL_PIN +) + +// SPI default pins +const ( + // Default Serial Clock Bus 0 for SPI communications + SPI0_SCK_PIN = GPIO18 + // Default Serial Out Bus 0 for SPI communications + SPI0_SDO_PIN = GPIO19 // Tx + // Default Serial In Bus 0 for SPI communications + SPI0_SDI_PIN = GPIO20 // Rx + + // Default Serial Clock Bus 1 for SPI communications + SPI1_SCK_PIN = GPIO26 + // Default Serial Out Bus 1 for SPI communications + SPI1_SDO_PIN = GPIO27 // Tx + // Default Serial In Bus 1 for SPI communications + SPI1_SDI_PIN = GPIO28 // Rx +) + +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART1_TX_PIN = GPIO8 + UART1_RX_PIN = GPIO9 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } + + UART1 = &_UART1 + _UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART1, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) +} + +// USB identifiers +const ( + usb_STRING_PRODUCT = "KB2040" + usb_STRING_MANUFACTURER = "Adafruit" +) + +var ( + usb_VID uint16 = 0x239A + usb_PID uint16 = 0x8106 +) diff --git a/targets/kb2040.json b/targets/kb2040.json new file mode 100644 index 00000000..ce9360f5 --- /dev/null +++ b/targets/kb2040.json @@ -0,0 +1,11 @@ +{ + "inherits": [ + "rp2040" + ], + "serial-port": ["239a:8106"], + "build-tags": ["kb2040"], + "linkerscript": "targets/qtpy-rp2040.ld", + "extra-files": [ + "targets/qtpy-rp2040-boot-stage2.S" + ] +}