Skip to content

Commit

Permalink
add UART
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Sep 13, 2024
1 parent e5d767c commit f8cfff7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
23 changes: 22 additions & 1 deletion src/machine/machine_rp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package machine

import (
"device/rp"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
)
Expand All @@ -18,6 +19,26 @@ const (
_PICO_SPINLOCK_ID_IRQ = 9
)

// UART on the RP2040
var (
UART0 = &_UART0
_UART0 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART0,
}

UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: rp.UART1,
}
)

func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)
UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt)
}

//go:linkname machineInit runtime.machineInit
func machineInit() {
// Reset all peripherals to put system into a known state,
Expand Down Expand Up @@ -96,7 +117,7 @@ const (
)

// DMA channels usable on the RP2040.
var dmaChannels = (*[12]dmaChannel)(unsafe.Pointer(rp.DMA))
var dmaChannels = (*[12 + 4*rp2350ExtraReg]dmaChannel)(unsafe.Pointer(rp.DMA))

//go:inline
func boolToBit(a bool) uint32 {
Expand Down
28 changes: 0 additions & 28 deletions src/machine/machine_rp2040_gpio.go

This file was deleted.

10 changes: 10 additions & 0 deletions src/machine/machine_rp2_2350.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const (
rp.RESETS_RESET_USBCTRL
)

// 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
)

const (
PinOutput PinMode = iota
PinInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build rp2040
//go:build rp2040 || rp2350

package machine

Expand Down
2 changes: 1 addition & 1 deletion src/machine/uart.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build atmega || esp || nrf || sam || sifive || stm32 || k210 || nxp || rp2040
//go:build atmega || esp || nrf || sam || sifive || stm32 || k210 || nxp || rp2040 || rp2350

package machine

Expand Down

0 comments on commit f8cfff7

Please sign in to comment.