Skip to content
Merged
5 changes: 5 additions & 0 deletions src/machine/board_circuitplay_bluefruit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const (
UART_RX_PIN = P0_30 // PORTB
)

// UART0 is the USB device
var (
UART0 = USB
)

// I2C pins
const (
SDA_PIN = P0_05 // I2C0 external
Expand Down
5 changes: 5 additions & 0 deletions src/machine/board_clue_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ const (
UART_TX_PIN = D1
)

// UART0 is the USB device
var (
UART0 = USB
)

// I2C pins
const (
SDA_PIN = D20 // I2C0 external
Expand Down
5 changes: 5 additions & 0 deletions src/machine/board_nrf52840-mdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const (
UART_RX_PIN Pin = 19
)

// UART0 is the USB device
var (
UART0 = USB
)

// I2C pins (unused)
const (
SDA_PIN = NoPin
Expand Down
8 changes: 8 additions & 0 deletions src/machine/board_pca10056_baremetal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build nrf52840,pca10056

package machine

// UART0 is the NRF UART
var (
UART0 = NRF_UART0
)
8 changes: 8 additions & 0 deletions src/machine/board_reelboard_baremetal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build nrf52840,reelboard

package machine

// UART0 is the NRF UART
var (
UART0 = NRF_UART0
)
6 changes: 3 additions & 3 deletions src/machine/machine_nrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type UART struct {

// UART
var (
// UART0 is the hardware serial port on the NRF.
UART0 = UART{Buffer: NewRingBuffer()}
// NRF_UART0 is the hardware UART on the NRF SoC.
NRF_UART0 = UART{Buffer: NewRingBuffer()}
)

// Configure the UART.
Expand All @@ -88,7 +88,7 @@ func (uart UART) Configure(config UARTConfig) {
nrf.UART0.INTENSET.Set(nrf.UART_INTENSET_RXDRDY_Msk)

// Enable RX IRQ.
intr := interrupt.New(nrf.IRQ_UART0, UART0.handleInterrupt)
intr := interrupt.New(nrf.IRQ_UART0, NRF_UART0.handleInterrupt)
intr.SetPriority(0xc0) // low priority
intr.Enable()
}
Expand Down
4 changes: 4 additions & 0 deletions src/machine/machine_nrf51.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"device/nrf"
)

var (
UART0 = NRF_UART0
)

func CPUFrequency() uint32 {
return 16000000
}
Expand Down
4 changes: 4 additions & 0 deletions src/machine/machine_nrf52.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"unsafe"
)

var (
UART0 = NRF_UART0
)

func CPUFrequency() uint32 {
return 64000000
}
Expand Down
19 changes: 18 additions & 1 deletion src/machine/usb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build sam
// +build sam nrf52840

package machine

Expand Down Expand Up @@ -376,6 +376,23 @@ type cdcLineInfo struct {
lineState uint8
}

// strToUTF16LEDescriptor converts a utf8 string into a string descriptor
// note: the following code only converts ascii characters to UTF16LE. In order
// to do a "proper" conversion, we would need to pull in the 'unicode/utf16'
// package, which at the time this was written added 512 bytes to the compiled
// binary.
func strToUTF16LEDescriptor(in string) []byte {
size := (len(in) << 1) + 2
out := make([]byte, size)
out[0] = byte(size)
out[1] = 0x03
for i, rune := range in {
out[(i<<1)+2] = byte(rune)
out[(i<<1)+3] = 0
}
return out
}

var (
// TODO: allow setting these
usb_STRING_LANGUAGE = [2]uint16{(3 << 8) | (2 + 2), 0x0409} // English
Expand Down
Loading