mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 21:43:40 +00:00
nrf: add nrf52840-mdk board
With the help of Chillance on GitHub.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// +build nrf52840_mdk
|
||||
|
||||
package machine
|
||||
|
||||
const HasLowFrequencyCrystal = true
|
||||
|
||||
// LEDs on the nrf52840-mdk (nRF52840 dev board)
|
||||
const (
|
||||
LED = LED_GREEN
|
||||
LED_GREEN = 22
|
||||
LED_RED = 23
|
||||
LED_BLUE = 24
|
||||
)
|
||||
|
||||
// UART pins
|
||||
const (
|
||||
UART_TX_PIN = 20
|
||||
UART_RX_PIN = 19
|
||||
)
|
||||
|
||||
// I2C pins (unused)
|
||||
const (
|
||||
SDA_PIN = 0xff
|
||||
SCL_PIN = 0xff
|
||||
)
|
||||
@@ -70,8 +70,7 @@ func (uart UART) Configure(config UARTConfig) {
|
||||
uart.SetBaudRate(config.BaudRate)
|
||||
|
||||
// Set TX and RX pins from board.
|
||||
nrf.UART0.PSELTXD = UART_TX_PIN
|
||||
nrf.UART0.PSELRXD = UART_RX_PIN
|
||||
uart.setPins(UART_TX_PIN, UART_RX_PIN)
|
||||
|
||||
nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled
|
||||
nrf.UART0.TASKS_STARTTX = 1
|
||||
@@ -165,8 +164,7 @@ func (i2c I2C) Configure(config I2CConfig) {
|
||||
}
|
||||
|
||||
i2c.Bus.ENABLE = nrf.TWI_ENABLE_ENABLE_Enabled
|
||||
i2c.Bus.PSELSCL = nrf.RegValue(config.SCL)
|
||||
i2c.Bus.PSELSDA = nrf.RegValue(config.SDA)
|
||||
i2c.setPins(config.SCL, config.SDA)
|
||||
}
|
||||
|
||||
// WriteTo writes a slice of data bytes to a peripheral with a specific address.
|
||||
|
||||
@@ -11,7 +11,17 @@ func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
|
||||
return nrf.GPIO, p.Pin
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx uint32) {
|
||||
nrf.UART0.PSELTXD = nrf.RegValue(tx)
|
||||
nrf.UART0.PSELRXD = nrf.RegValue(rx)
|
||||
}
|
||||
|
||||
//go:export UART0_IRQHandler
|
||||
func handleUART0() {
|
||||
UART0.handleInterrupt()
|
||||
}
|
||||
|
||||
func (i2c I2C) setPins(scl, sda uint8) {
|
||||
i2c.Bus.PSELSCL = nrf.RegValue(scl)
|
||||
i2c.Bus.PSELSDA = nrf.RegValue(sda)
|
||||
}
|
||||
|
||||
@@ -12,11 +12,21 @@ func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
|
||||
return nrf.P0, p.Pin
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx uint32) {
|
||||
nrf.UART0.PSELTXD = nrf.RegValue(tx)
|
||||
nrf.UART0.PSELRXD = nrf.RegValue(rx)
|
||||
}
|
||||
|
||||
//go:export UARTE0_UART0_IRQHandler
|
||||
func handleUART0() {
|
||||
UART0.handleInterrupt()
|
||||
}
|
||||
|
||||
func (i2c I2C) setPins(scl, sda uint8) {
|
||||
i2c.Bus.PSELSCL = nrf.RegValue(scl)
|
||||
i2c.Bus.PSELSDA = nrf.RegValue(sda)
|
||||
}
|
||||
|
||||
// InitADC initializes the registers needed for ADC.
|
||||
func InitADC() {
|
||||
return // no specific setup on nrf52 machine.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// +build nrf52840
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/nrf"
|
||||
)
|
||||
|
||||
// Get peripheral and pin number for this GPIO pin.
|
||||
func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
|
||||
if p.Pin >= 32 {
|
||||
return nrf.P1, p.Pin - 32
|
||||
} else {
|
||||
return nrf.P0, p.Pin
|
||||
}
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx uint32) {
|
||||
nrf.UART0.PSEL.TXD = nrf.RegValue(tx)
|
||||
nrf.UART0.PSEL.RXD = nrf.RegValue(rx)
|
||||
}
|
||||
|
||||
//go:export UARTE0_UART0_IRQHandler
|
||||
func handleUART0() {
|
||||
UART0.handleInterrupt()
|
||||
}
|
||||
|
||||
func (i2c I2C) setPins(scl, sda uint8) {
|
||||
i2c.Bus.PSEL.SCL = nrf.RegValue(scl)
|
||||
i2c.Bus.PSEL.SDA = nrf.RegValue(sda)
|
||||
}
|
||||
Reference in New Issue
Block a user