diff options
Diffstat (limited to 'src/machine/machine_nrf52840.go')
-rw-r--r-- | src/machine/machine_nrf52840.go | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/machine/machine_nrf52840.go b/src/machine/machine_nrf52840.go index 507db9837..6f8c4bb2d 100644 --- a/src/machine/machine_nrf52840.go +++ b/src/machine/machine_nrf52840.go @@ -19,8 +19,8 @@ func (p GPIO) getPortPin() (*nrf.GPIO_Type, uint8) { } func (uart UART) setPins(tx, rx uint32) { - nrf.UART0.PSEL.TXD = nrf.RegValue(tx) - nrf.UART0.PSEL.RXD = nrf.RegValue(rx) + nrf.UART0.PSEL.TXD.Set(tx) + nrf.UART0.PSEL.RXD.Set(rx) } //go:export UARTE0_UART0_IRQHandler @@ -29,8 +29,8 @@ func handleUART0() { } func (i2c I2C) setPins(scl, sda uint8) { - i2c.Bus.PSEL.SCL = nrf.RegValue(scl) - i2c.Bus.PSEL.SDA = nrf.RegValue(sda) + i2c.Bus.PSEL.SCL.Set(uint32(scl)) + i2c.Bus.PSEL.SDA.Set(uint32(sda)) } // SPI @@ -44,9 +44,9 @@ func (spi SPI) setPins(sck, mosi, miso uint8) { if miso == 0 { miso = SPI0_MISO_PIN } - spi.Bus.PSEL.SCK = nrf.RegValue(sck) - spi.Bus.PSEL.MOSI = nrf.RegValue(mosi) - spi.Bus.PSEL.MISO = nrf.RegValue(miso) + spi.Bus.PSEL.SCK.Set(uint32(sck)) + spi.Bus.PSEL.MOSI.Set(uint32(mosi)) + spi.Bus.PSEL.MISO.Set(uint32(miso)) } // InitADC initializes the registers needed for ADC. @@ -93,53 +93,53 @@ func (a ADC) Get() uint16 { return 0 } - nrf.SAADC.RESOLUTION = nrf.SAADC_RESOLUTION_VAL_12bit + nrf.SAADC.RESOLUTION.Set(nrf.SAADC_RESOLUTION_VAL_12bit) // Enable ADC. - nrf.SAADC.ENABLE = (nrf.SAADC_ENABLE_ENABLE_Enabled << nrf.SAADC_ENABLE_ENABLE_Pos) + nrf.SAADC.ENABLE.Set(nrf.SAADC_ENABLE_ENABLE_Enabled << nrf.SAADC_ENABLE_ENABLE_Pos) for i := 0; i < 8; i++ { - nrf.SAADC.CH[i].PSELN = nrf.SAADC_CH_PSELP_PSELP_NC - nrf.SAADC.CH[i].PSELP = nrf.SAADC_CH_PSELP_PSELP_NC + nrf.SAADC.CH[i].PSELN.Set(nrf.SAADC_CH_PSELP_PSELP_NC) + nrf.SAADC.CH[i].PSELP.Set(nrf.SAADC_CH_PSELP_PSELP_NC) } // Configure ADC. - nrf.SAADC.CH[0].CONFIG = ((nrf.SAADC_CH_CONFIG_RESP_Bypass << nrf.SAADC_CH_CONFIG_RESP_Pos) & nrf.SAADC_CH_CONFIG_RESP_Msk) | + nrf.SAADC.CH[0].CONFIG.Set(((nrf.SAADC_CH_CONFIG_RESP_Bypass << nrf.SAADC_CH_CONFIG_RESP_Pos) & nrf.SAADC_CH_CONFIG_RESP_Msk) | ((nrf.SAADC_CH_CONFIG_RESP_Bypass << nrf.SAADC_CH_CONFIG_RESN_Pos) & nrf.SAADC_CH_CONFIG_RESN_Msk) | ((nrf.SAADC_CH_CONFIG_GAIN_Gain1_5 << nrf.SAADC_CH_CONFIG_GAIN_Pos) & nrf.SAADC_CH_CONFIG_GAIN_Msk) | ((nrf.SAADC_CH_CONFIG_REFSEL_Internal << nrf.SAADC_CH_CONFIG_REFSEL_Pos) & nrf.SAADC_CH_CONFIG_REFSEL_Msk) | ((nrf.SAADC_CH_CONFIG_TACQ_3us << nrf.SAADC_CH_CONFIG_TACQ_Pos) & nrf.SAADC_CH_CONFIG_TACQ_Msk) | - ((nrf.SAADC_CH_CONFIG_MODE_SE << nrf.SAADC_CH_CONFIG_MODE_Pos) & nrf.SAADC_CH_CONFIG_MODE_Msk) + ((nrf.SAADC_CH_CONFIG_MODE_SE << nrf.SAADC_CH_CONFIG_MODE_Pos) & nrf.SAADC_CH_CONFIG_MODE_Msk)) // Set pin to read. - nrf.SAADC.CH[0].PSELN = nrf.RegValue(pwmPin) - nrf.SAADC.CH[0].PSELP = nrf.RegValue(pwmPin) + nrf.SAADC.CH[0].PSELN.Set(pwmPin) + nrf.SAADC.CH[0].PSELP.Set(pwmPin) // Destination for sample result. - nrf.SAADC.RESULT.PTR = nrf.RegValue(uintptr(unsafe.Pointer(&value))) - nrf.SAADC.RESULT.MAXCNT = 1 // One sample + nrf.SAADC.RESULT.PTR.Set(uint32(uintptr(unsafe.Pointer(&value)))) + nrf.SAADC.RESULT.MAXCNT.Set(1) // One sample // Start tasks. - nrf.SAADC.TASKS_START = 1 - for nrf.SAADC.EVENTS_STARTED == 0 { + nrf.SAADC.TASKS_START.Set(1) + for nrf.SAADC.EVENTS_STARTED.Get() == 0 { } - nrf.SAADC.EVENTS_STARTED = 0x00 + nrf.SAADC.EVENTS_STARTED.Set(0x00) // Start the sample task. - nrf.SAADC.TASKS_SAMPLE = 1 + nrf.SAADC.TASKS_SAMPLE.Set(1) // Wait until the sample task is done. - for nrf.SAADC.EVENTS_END == 0 { + for nrf.SAADC.EVENTS_END.Get() == 0 { } - nrf.SAADC.EVENTS_END = 0x00 + nrf.SAADC.EVENTS_END.Set(0x00) // Stop the ADC - nrf.SAADC.TASKS_STOP = 1 - for nrf.SAADC.EVENTS_STOPPED == 0 { + nrf.SAADC.TASKS_STOP.Set(1) + for nrf.SAADC.EVENTS_STOPPED.Get() == 0 { } - nrf.SAADC.EVENTS_STOPPED = 0 + nrf.SAADC.EVENTS_STOPPED.Set(0) // Disable the ADC. - nrf.SAADC.ENABLE = (nrf.SAADC_ENABLE_ENABLE_Disabled << nrf.SAADC_ENABLE_ENABLE_Pos) + nrf.SAADC.ENABLE.Set(nrf.SAADC_ENABLE_ENABLE_Disabled << nrf.SAADC_ENABLE_ENABLE_Pos) if value < 0 { value = 0 @@ -174,21 +174,21 @@ func (pwm PWM) Set(value uint16) { p := pwms[i] - p.PSEL.OUT[0] = nrf.RegValue(pwm.Pin) - p.PSEL.OUT[1] = nrf.RegValue(pwm.Pin) - p.PSEL.OUT[2] = nrf.RegValue(pwm.Pin) - p.PSEL.OUT[3] = nrf.RegValue(pwm.Pin) - p.ENABLE = (nrf.PWM_ENABLE_ENABLE_Enabled << nrf.PWM_ENABLE_ENABLE_Pos) - p.PRESCALER = nrf.PWM_PRESCALER_PRESCALER_DIV_2 - p.MODE = nrf.PWM_MODE_UPDOWN_Up - p.COUNTERTOP = 16384 // frequency - p.LOOP = 0 - p.DECODER = (nrf.PWM_DECODER_LOAD_Common << nrf.PWM_DECODER_LOAD_Pos) | (nrf.PWM_DECODER_MODE_RefreshCount << nrf.PWM_DECODER_MODE_Pos) - p.SEQ[0].PTR = nrf.RegValue(uintptr(unsafe.Pointer(&pwmChannelSequence[i]))) - p.SEQ[0].CNT = 1 - p.SEQ[0].REFRESH = 1 - p.SEQ[0].ENDDELAY = 0 - p.TASKS_SEQSTART[0] = 1 + p.PSEL.OUT[0].Set(uint32(pwm.Pin)) + p.PSEL.OUT[1].Set(uint32(pwm.Pin)) + p.PSEL.OUT[2].Set(uint32(pwm.Pin)) + p.PSEL.OUT[3].Set(uint32(pwm.Pin)) + p.ENABLE.Set(nrf.PWM_ENABLE_ENABLE_Enabled << nrf.PWM_ENABLE_ENABLE_Pos) + p.PRESCALER.Set(nrf.PWM_PRESCALER_PRESCALER_DIV_2) + p.MODE.Set(nrf.PWM_MODE_UPDOWN_Up) + p.COUNTERTOP.Set(16384) // frequency + p.LOOP.Set(0) + p.DECODER.Set((nrf.PWM_DECODER_LOAD_Common << nrf.PWM_DECODER_LOAD_Pos) | (nrf.PWM_DECODER_MODE_RefreshCount << nrf.PWM_DECODER_MODE_Pos)) + p.SEQ[0].PTR.Set(uint32(uintptr(unsafe.Pointer(&pwmChannelSequence[i])))) + p.SEQ[0].CNT.Set(1) + p.SEQ[0].REFRESH.Set(1) + p.SEQ[0].ENDDELAY.Set(0) + p.TASKS_SEQSTART[0].Set(1) break } |