github.com/aykevl/tinygo@v0.5.0/src/machine/machine_nrf51.go (about)

     1  // +build nrf51
     2  
     3  package machine
     4  
     5  import (
     6  	"device/nrf"
     7  )
     8  
     9  const CPU_FREQUENCY = 16000000
    10  
    11  // Get peripheral and pin number for this GPIO pin.
    12  func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) {
    13  	return nrf.GPIO, p.Pin
    14  }
    15  
    16  func (uart UART) setPins(tx, rx uint32) {
    17  	nrf.UART0.PSELTXD = nrf.RegValue(tx)
    18  	nrf.UART0.PSELRXD = nrf.RegValue(rx)
    19  }
    20  
    21  //go:export UART0_IRQHandler
    22  func handleUART0() {
    23  	UART0.handleInterrupt()
    24  }
    25  
    26  func (i2c I2C) setPins(scl, sda uint8) {
    27  	i2c.Bus.PSELSCL = nrf.RegValue(scl)
    28  	i2c.Bus.PSELSDA = nrf.RegValue(sda)
    29  }
    30  
    31  // SPI
    32  func (spi SPI) setPins(sck, mosi, miso uint8) {
    33  	if sck == 0 {
    34  		sck = SPI0_SCK_PIN
    35  	}
    36  	if mosi == 0 {
    37  		mosi = SPI0_MOSI_PIN
    38  	}
    39  	if miso == 0 {
    40  		miso = SPI0_MISO_PIN
    41  	}
    42  	spi.Bus.PSELSCK = nrf.RegValue(sck)
    43  	spi.Bus.PSELMOSI = nrf.RegValue(mosi)
    44  	spi.Bus.PSELMISO = nrf.RegValue(miso)
    45  }