// http://www.hobbytronics.co.uk/raspberry-pi-gpio-pinout
328264
func (d *RaspberryPiDTDriver) createPinData() {
	switch d.BoardRevision() {
	case type0ne:
		d.pinConfigs = []*DTPinConfig{
			{[]string{"null"}, []string{"unassignable"}, 0, 0}, // 0 - spacer
			{[]string{"3.3v"}, []string{"unassignable"}, 0, 0},
			{[]string{"5v"}, []string{"unassignable"}, 0, 0},
			{[]string{"sda"}, []string{"i2c"}, 0, 0},
			{[]string{"do-not-connect-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"scl"}, []string{"i2c"}, 0, 0},
			{[]string{"ground"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio4"}, []string{"gpio"}, 4, 0},
			{[]string{"txd"}, []string{"serial"}, 0, 0},
			{[]string{"do-not-connect-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"rxd"}, []string{"serial"}, 0, 0},
			{[]string{"gpio17"}, []string{"gpio"}, 17, 0},
			{[]string{"gpio18"}, []string{"gpio"}, 18, 0}, // also supports PWM
			{[]string{"gpio21"}, []string{"gpio"}, 21, 0},
			{[]string{"do-not-connect-3"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio22"}, []string{"gpio"}, 22, 0},
			{[]string{"gpio23"}, []string{"gpio"}, 23, 0},
			{[]string{"do-not-connect-4"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio24"}, []string{"gpio"}, 24, 0},
			{[]string{"mosi"}, []string{"spi"}, 0, 0},
			{[]string{"do-not-connect-5"}, []string{"unassignable"}, 0, 0},
			{[]string{"miso"}, []string{"spi"}, 0, 0},
			{[]string{"gpio25"}, []string{"gpio"}, 25, 0},
			{[]string{"sclk"}, []string{"spi"}, 0, 0},
			{[]string{"ce0n"}, []string{"spi"}, 0, 0},
			{[]string{"do-not-connect-6"}, []string{"unassignable"}, 0, 0},
			{[]string{"ce1n"}, []string{"spi"}, 0, 0},
		}
	case typeTwo:
		d.pinConfigs = []*DTPinConfig{
			{[]string{"null"}, []string{"unassignable"}, 0, 0}, // 0 - spacer
			{[]string{"3.3v-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"5v-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"sda"}, []string{"i2c"}, 0, 0},
			{[]string{"5v-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"scl"}, []string{"i2c"}, 0, 0},
			{[]string{"ground-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio4"}, []string{"gpio"}, 4, 0},
			{[]string{"txd"}, []string{"serial"}, 0, 0},
			{[]string{"ground-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"rxd"}, []string{"serial"}, 0, 0},
			{[]string{"gpio17"}, []string{"gpio"}, 17, 0},
			{[]string{"gpio18"}, []string{"gpio"}, 18, 0}, // also supports PWM
			{[]string{"gpio27"}, []string{"gpio"}, 27, 0},
			{[]string{"ground-3"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio22"}, []string{"gpio"}, 22, 0},
			{[]string{"gpio23"}, []string{"gpio"}, 23, 0},
			{[]string{"3.3v-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio24"}, []string{"gpio"}, 24, 0},
			{[]string{"mosi"}, []string{"spi"}, 0, 0},
			{[]string{"ground-4"}, []string{"unassignable"}, 0, 0},
			{[]string{"miso"}, []string{"spi"}, 0, 0},
			{[]string{"gpio25"}, []string{"gpio"}, 25, 0},
			{[]string{"sclk"}, []string{"spi"}, 0, 0},
			{[]string{"gpio8"}, []string{"gpio"}, 8, 0},
			{[]string{"ground-5"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio7"}, []string{"gpio"}, 7, 0},
		}
	case typeAplusBPlusZeroPi2: // B+
		d.pinConfigs = []*DTPinConfig{
			{[]string{"null"}, []string{"unassignable"}, 0, 0}, // 0 - spacer
			{[]string{"3.3v-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"5v-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"sda"}, []string{"i2c"}, 0, 0},
			{[]string{"5v-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"scl"}, []string{"i2c"}, 0, 0},
			{[]string{"ground-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio4"}, []string{"gpio"}, 4, 0},
			{[]string{"txd"}, []string{"serial"}, 0, 0},
			{[]string{"ground-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"rxd"}, []string{"serial"}, 0, 0},
			{[]string{"gpio17"}, []string{"gpio"}, 17, 0},
			{[]string{"gpio18"}, []string{"gpio"}, 18, 0}, // also supports PWM
			{[]string{"gpio27"}, []string{"gpio"}, 21, 0},
			{[]string{"ground-3"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio22"}, []string{"gpio"}, 22, 0},
			{[]string{"gpio23"}, []string{"gpio"}, 23, 0},
			{[]string{"3.3v-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio24"}, []string{"gpio"}, 24, 0},
			{[]string{"mosi"}, []string{"spi"}, 0, 0},
			{[]string{"ground-4"}, []string{"unassignable"}, 0, 0},
			{[]string{"miso"}, []string{"spi"}, 0, 0},
			{[]string{"gpio25"}, []string{"gpio"}, 25, 0},
			{[]string{"sclk"}, []string{"spi"}, 0, 0},
			{[]string{"gpio8"}, []string{"gpio"}, 8, 0},
			{[]string{"ground-5"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio7"}, []string{"gpio"}, 7, 0},
			{[]string{"do-not-connect-1"}, []string{"unassignable"}, 0, 0},
			{[]string{"do-not-connect-2"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio5"}, []string{"gpio"}, 5, 0},
			{[]string{"ground-6"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio6"}, []string{"gpio"}, 6, 0},
			{[]string{"gpio12"}, []string{"gpio"}, 12, 0},
			{[]string{"gpio13"}, []string{"gpio"}, 13, 0},
			{[]string{"ground-7"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio19"}, []string{"gpio"}, 19, 0},
			{[]string{"gpio16"}, []string{"gpio"}, 16, 0},
			{[]string{"gpio26"}, []string{"gpio"}, 26, 0},
			{[]string{"gpio20"}, []string{"gpio"}, 20, 0},
			{[]string{"ground-8"}, []string{"unassignable"}, 0, 0},
			{[]string{"gpio21"}, []string{"gpio"}, 21, 0},
		}
	}
}
1022652
func (e *Adaptor) arduinoSetup() (err error) {
	if err = e.exportTristatePin(); err != nil {
		return err
	}

	err = pinWrite(e.tristate, sysfs.OUT, sysfs.LOW)
	if err != nil {
		return
	}

	for _, i := range []int{263, 262} {
		if err = e.newDigitalPin(i, sysfs.HIGH); err != nil {
			return err
		}
	}

	for _, i := range []int{240, 241, 242, 243} {
		if err = e.newDigitalPin(i, sysfs.LOW); err != nil {
			return err
		}
	}

	for _, i := range []string{"111", "115", "114", "109"} {
		if err = changePinMode(e, i, "1"); err != nil {
			return err
		}
	}

	for _, i := range []string{"131", "129", "40"} {
		if err = changePinMode(e, i, "0"); err != nil {
			return err
		}
	}

	err = e.tristate.Write(sysfs.HIGH)
	return
}
1186672
func (b *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
	b.mutex.Lock()
	defer b.mutex.Unlock()

	i, err := b.translatePin(pin)
	if err != nil {
		return
	}
	if b.digitalPins[i] == nil {
		b.digitalPins[i] = sysfs.NewDigitalPin(i)
		if err = muxPin(pin, "gpio"); err != nil {
			return
		}

		err := b.digitalPins[i].Export()
		if err != nil {
			return nil, err
		}
	}
	if err = b.digitalPins[i].Direction(dir); err != nil {
		return
	}
	return b.digitalPins[i], nil
}
812427
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)
}
813809
func (pfd *PiFaceDigital) InitBoard() error {

	err := pfd.mcp.Open()
	if err != nil {
		return err
	}

	var ioconfig byte
	ioconfig = (MCP23S17.BANK_OFF |
		MCP23S17.INT_MIRROR_OFF |
		MCP23S17.SEQOP_OFF |
		MCP23S17.DISSLW_OFF |
		MCP23S17.HAEN_ON |
		MCP23S17.ODR_OFF |
		MCP23S17.INTPOL_LOW)

	pfd.mcp.IOCON.SetValue(ioconfig)
	if pfd.mcp.IOCON.Value() != ioconfig {
		return fmt.Errorf("No PiFace Digital board detected (hardware_addr=%d, bus=%b, chip_select=%b).", pfd.mcp.HardwareAddress, pfd.mcp.Device.Bus, pfd.mcp.Device.Chip)
	}

	pfd.mcp.GPIOa.SetValue(0)
	pfd.mcp.IODIRa.SetValue(0)    // GPIOA as outputs
	pfd.mcp.IODIRb.SetValue(0xFF) // GPIOB as inputs
	pfd.mcp.GPPUb.SetValue(0xFF)  // input pullups on
	// pfd.EnableInterrupts()

	return nil
}
193491
func (s *BigSwitchBCFService) NewListBigSwitchBcfDevicesParams() *ListBigSwitchBcfDevicesParams {
	p := &ListBigSwitchBcfDevicesParams{}
	p.p = make(map[string]interface{})
	return p
}
715781
func main() {
	e := edison.NewAdaptor()
	e.Connect()

	led := gpio.NewLedDriver(e, "13")
	led.Start()

	for {
		led.Toggle()
		time.Sleep(1000 * time.Millisecond)
	}
}
364698
func UnassignPins(pins PinList) (er error) {
	er = nil

	for _, pin := range pins {
		e := UnassignPin(pin)
		if e != nil {
			er = e
		}
	}

	return
}
577660
func (d *RaspberryPiDTDriver) BoardRevision() pinoutRevision {
	revision := CpuInfo(0, "Revision")
	switch revision {
	case "0002", "0003":
		return type0ne
	case "0010":
		return typeAplusBPlusZeroPi2
	}

	// Pi 2 boards have different strings, but pinout is the same as B+
	revision = CpuInfo(0, "CPU revision")
	switch revision {
	case "5":
		return typeAplusBPlusZeroPi2
	case "7": //PI zero +
		return typeAplusBPlusZeroPi2
	}

	return typeTwo
}
876952
func (s *Adaptor) ServoWrite(pin string, angle byte) (err error) {
	if _, present := s.servoPins[pin]; !present {
		err = s.servoPinOpen(pin)
		if err != nil {
			return
		}
	}

	params := url.Values{
		"params":       {fmt.Sprintf("%v,%v", pin, angle)},
		"access_token": {s.AccessToken},
	}
	url := fmt.Sprintf("%v/servoSet", s.deviceURL())
	_, err = s.request("POST", url, params)
	return err
}
1326914
func NewGPIODriver(pinMap PinMap, dpf digitalPinFactory, apf analogPinFactory, ppf pwmPinFactory) GPIODriver {
	return &gpioDriver{
		pinMap: pinMap,
		dpf:    dpf,
		apf:    apf,
		ppf:    ppf,

		initializedPins: map[string]pin{},
	}
}
1104724
func (s *BigSwitchBCFService) ListBigSwitchBcfDevices(p *ListBigSwitchBcfDevicesParams) (*ListBigSwitchBcfDevicesResponse, error) {
	resp, err := s.cs.newRequest("listBigSwitchBcfDevices", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListBigSwitchBcfDevicesResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
649618
func (conn *GPIOConnection) Close() error {
	glog.V(2).Info("hd44780: closing all GPIO pins")
	pins := []embd.DigitalPin{
		conn.RS,
		conn.EN,
		conn.D4,
		conn.D5,
		conn.D6,
		conn.D7,
		conn.Backlight,
	}

	for _, pin := range pins {
		err := pin.Close()
		if err != nil {
			glog.Errorf("hd44780: error closing pin %+v: %s", pin, err)
			return err
		}
	}
	return nil
}
1162354
func (g *Driver) DigitalWrite(pin string, val byte) (err error) {
	var (
		grovePin, grovePort Grove
	)
	grovePin, grovePort, _, _, err = getGroveAddresses(pin)
	if err != nil {
		return err
	}
	err = g.SetGroveType(grovePort, CUSTOM)
	if err != nil {
		return err
	}
	time.Sleep(10 * time.Millisecond)
	err = g.SetGroveMode(grovePin, GROVE_OUTPUT_DIGITAL)
	if err != nil {
		return err
	}
	time.Sleep(10 * time.Millisecond)
	err = g.writeBytes([]byte{
		goPiGo3Address,
		SET_GROVE_STATE,
		byte(grovePin),
		byte(val),
	})
	return err
}
1269746
func NewInput(p uint) Pin {
	pin := Pin{
		Number: p,
	}
	exportGPIO(pin)
	time.Sleep(10 * time.Millisecond)
	pin.direction = inDirection
	setDirection(pin, inDirection, 0)
	pin = openPin(pin, false)
	return pin
}
304909
func (a *API) robotDevices(res http.ResponseWriter, req *http.Request) {
	if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil {
		jsonDevices := []*gobot.JSONDevice{}
		robot.Devices().Each(func(d gobot.Device) {
			jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d))
		})
		a.writeJSON(map[string]interface{}{"devices": jsonDevices}, res)
	} else {
		a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res)
	}
}
533409
func (p *pin) Close() error {
	return writeFile(filepath.Join(gpiobase, "unexport"), "%d", p.number)
}