code: func PinMode(pin Pin, mode Mode) {
  
  	// Pin fsel register, 0 or 1 depending on bank
  	fselReg := uint8(pin) / 10
  	shift := (uint8(pin) % 10) * 3
  	f := uint32(0)
  
  	const in = 0   // 000
  	const out = 1  // 001
  	const alt0 = 4 // 100
  	const alt4 = 3 // 011
  	const alt5 = 2 // 010
  
  	switch mode {
  	case Input:
  		f = in
  	case Output:
  		f = out
  	case Clock:
  		switch pin {
  		case 4, 5, 6, 32, 34, 42, 43, 44:
  			f = alt0
  		case 20, 21:
  			f = alt5
  		default:
  			return
  		}
  	case Pwm:
  		switch pin {
  		case 12, 13, 40, 41, 45:
  			f = alt0
  		case 18, 19:
  			f = alt5
  		default:
  			return
  		}
  	case Spi:
  		switch pin {
  		case 7, 8, 9, 10, 11: // SPI0
  			f = alt0
  		case 35, 36, 37, 38, 39: // SPI0
  			f = alt0
  		case 16, 17, 18, 19, 20, 21: // SPI1
  			f = alt4
  		case 40, 41, 42, 43, 44, 45: // SPI2
  			f = alt4
  		default:
  			return
  		}
  	}
  
  	memlock.Lock()
  	defer memlock.Unlock()
  
  	const pinMask = 7 // 111 - pinmode is 3 bits
  
  	gpioMem[fselReg] = (gpioMem[fselReg] &^ (pinMask << shift)) | (f << shift)
  }
docs: // PinMode sets the mode of a given pin (Input, Output, Clock, Pwm or Spi)
  //
  // Clock is possible only for pins 4, 5, 6, 20, 21.
  // Pwm is possible only for pins 12, 13, 18, 19.
  //
  // Spi mode should not be set by this directly, use SpiBegin instead.