nrf: add micro:bit board

This commit is contained in:
Ayke van Laethem
2018-10-05 14:14:32 +02:00
parent e4fa1a8288
commit bc9210b674
10 changed files with 139 additions and 22 deletions
+32
View File
@@ -0,0 +1,32 @@
// +build nrf,microbit
package machine
// The micro:bit does not have a 32kHz crystal on board.
const HasLowFrequencyCrystal = false
// Buttons on the micro:bit (A and B)
const (
BUTTON = BUTTON1
BUTTON1 = 5
BUTTON2 = 11
)
// UART pins
const (
UART_TX_PIN = 24
UART_RX_PIN = 25
)
// ADC pins
const (
ADC0 = 0
ADC1 = 1
ADC2 = 2
)
// I2C pins
const (
SDA_PIN = 20
SCL_PIN = 19
)
+3
View File
@@ -2,6 +2,9 @@
package machine
// The PCA10040 has a low-frequency (32kHz) crystal oscillator on board.
const HasLowFrequencyCrystal = true
// LEDs on the PCA10040 (nRF52832 dev board)
const (
LED = LED1
+13 -9
View File
@@ -19,22 +19,25 @@ const (
// Configure this pin with the given configuration.
func (p GPIO) Configure(config GPIOConfig) {
cfg := config.Mode | nrf.GPIO_PIN_CNF_DRIVE_S0S1 | nrf.GPIO_PIN_CNF_SENSE_Disabled
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
port, pin := p.getPortPin()
port.PIN_CNF[pin] = nrf.RegValue(cfg)
}
// Set the pin to high or low.
// Warning: only use this on an output pin!
func (p GPIO) Set(high bool) {
port, pin := p.getPortPin()
if high {
nrf.P0.OUTSET = 1 << p.Pin
port.OUTSET = 1 << pin
} else {
nrf.P0.OUTCLR = 1 << p.Pin
port.OUTCLR = 1 << pin
}
}
// Get returns the current value of a GPIO pin.
func (p GPIO) Get() bool {
return (nrf.P0.IN>>p.Pin)&1 != 0
port, pin := p.getPortPin()
return (port.IN>>pin)&1 != 0
}
// UART
@@ -62,7 +65,7 @@ func (uart UART) Configure(config UARTConfig) {
nrf.UART0.INTENSET = nrf.UART_INTENSET_RXDRDY_Msk
// Enable RX IRQ.
arm.EnableIRQ(nrf.IRQ_UARTE0_UART0)
arm.EnableIRQ(nrf.IRQ_UART0)
}
// SetBaudRate sets the communication speed for the UART.
@@ -89,8 +92,7 @@ func (uart UART) WriteByte(c byte) error {
return nil
}
//go:export UARTE0_UART0_IRQHandler
func handleUART0() {
func (uart UART) handleInterrupt() {
if nrf.UART0.EVENTS_RXDRDY != 0 {
bufferPut(byte(nrf.UART0.RXD))
nrf.UART0.EVENTS_RXDRDY = 0x0
@@ -128,13 +130,15 @@ func (i2c I2C) Configure(config I2CConfig) {
}
// do config
nrf.P0.PIN_CNF[config.SCL] = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) |
sclPort, sclPin := GPIO{config.SCL}.getPortPin()
sclPort.PIN_CNF[sclPin] = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) |
(nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos) |
(nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos) |
(nrf.GPIO_PIN_CNF_DRIVE_S0D1 << nrf.GPIO_PIN_CNF_DRIVE_Pos) |
(nrf.GPIO_PIN_CNF_SENSE_Disabled << nrf.GPIO_PIN_CNF_SENSE_Pos)
nrf.P0.PIN_CNF[config.SDA] = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) |
sdaPort, sdaPin := GPIO{config.SDA}.getPortPin()
sdaPort.PIN_CNF[sdaPin] = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) |
(nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos) |
(nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos) |
(nrf.GPIO_PIN_CNF_DRIVE_S0D1 << nrf.GPIO_PIN_CNF_DRIVE_Pos) |
+17
View File
@@ -0,0 +1,17 @@
// +build nrf51
package machine
import (
"device/nrf"
)
// Get peripheral and pin number for this GPIO pin.
func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
return nrf.GPIO, p.Pin
}
//go:export UART0_IRQHandler
func handleUART0() {
UART0.handleInterrupt()
}
+10
View File
@@ -7,6 +7,16 @@ import (
"unsafe"
)
// Get peripheral and pin number for this GPIO pin.
func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
return nrf.P0, p.Pin
}
//go:export UARTE0_UART0_IRQHandler
func handleUART0() {
UART0.handleInterrupt()
}
// InitADC initializes the registers needed for ADC.
func InitADC() {
return // no specific setup on nrf52 machine.