github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_nrf52833.go (about) 1 //go:build nrf52833 2 3 package machine 4 5 import ( 6 "device/nrf" 7 ) 8 9 // Hardware pins 10 const ( 11 P0_00 Pin = 0 12 P0_01 Pin = 1 13 P0_02 Pin = 2 14 P0_03 Pin = 3 15 P0_04 Pin = 4 16 P0_05 Pin = 5 17 P0_06 Pin = 6 18 P0_07 Pin = 7 19 P0_08 Pin = 8 20 P0_09 Pin = 9 21 P0_10 Pin = 10 22 P0_11 Pin = 11 23 P0_12 Pin = 12 24 P0_13 Pin = 13 25 P0_14 Pin = 14 26 P0_15 Pin = 15 27 P0_16 Pin = 16 28 P0_17 Pin = 17 29 P0_18 Pin = 18 30 P0_19 Pin = 19 31 P0_20 Pin = 20 32 P0_21 Pin = 21 33 P0_22 Pin = 22 34 P0_23 Pin = 23 35 P0_24 Pin = 24 36 P0_25 Pin = 25 37 P0_26 Pin = 26 38 P0_27 Pin = 27 39 P0_28 Pin = 28 40 P0_29 Pin = 29 41 P0_30 Pin = 30 42 P0_31 Pin = 31 43 P1_00 Pin = 32 44 P1_01 Pin = 33 45 P1_02 Pin = 34 46 P1_03 Pin = 35 47 P1_04 Pin = 36 48 P1_05 Pin = 37 49 P1_06 Pin = 38 50 P1_07 Pin = 39 51 P1_08 Pin = 40 52 P1_09 Pin = 41 53 P1_10 Pin = 42 54 P1_11 Pin = 43 55 P1_12 Pin = 44 56 P1_13 Pin = 45 57 P1_14 Pin = 46 58 P1_15 Pin = 47 59 ) 60 61 // Get peripheral and pin number for this GPIO pin. 62 func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { 63 if p >= 32 { 64 return nrf.P1, uint32(p - 32) 65 } else { 66 return nrf.P0, uint32(p) 67 } 68 } 69 70 func (uart *UART) setPins(tx, rx Pin) { 71 nrf.UART0.PSEL.TXD.Set(uint32(tx)) 72 nrf.UART0.PSEL.RXD.Set(uint32(rx)) 73 } 74 75 func (i2c *I2C) setPins(scl, sda Pin) { 76 i2c.Bus.PSEL.SCL.Set(uint32(scl)) 77 i2c.Bus.PSEL.SDA.Set(uint32(sda)) 78 } 79 80 // PWM 81 var ( 82 PWM0 = &PWM{PWM: nrf.PWM0} 83 PWM1 = &PWM{PWM: nrf.PWM1} 84 PWM2 = &PWM{PWM: nrf.PWM2} 85 PWM3 = &PWM{PWM: nrf.PWM3} 86 ) 87 88 const eraseBlockSizeValue = 4096 89 90 func eraseBlockSize() int64 { 91 return eraseBlockSizeValue 92 }