Exemplo n.º 1
0
Arquivo: i2c.go Projeto: zyxar/berry
func openDeviceI2c(irq, rst uint8) (d *deviceI2c, err error) {
	dev, err := bus.NewI2C(0, 0x01)
	if err != nil {
		return
	}
	d = &deviceI2c{
		irq:   core.Pin(irq),
		reset: core.Pin(rst),
		dev:   dev,
	}
	d.irq.Input()
	d.reset.Output()
	d.reset.DigitalWrite(core.HIGH)
	d.reset.DigitalWrite(core.LOW)
	core.Delay(400)
	d.reset.DigitalWrite(core.HIGH)
	core.Delay(10)
	return
}
Exemplo n.º 2
0
Arquivo: spi.go Projeto: zyxar/berry
func openDeviceSPI(clk, miso, mosi, ss uint8) (device Device, err error) {
	d := &deviceSPI{
		ss:   core.Pin(ss),
		clk:  core.Pin(clk),
		miso: core.Pin(miso),
		mosi: core.Pin(mosi),
	}
	d.ss.Output()
	d.clk.Output()
	d.mosi.Output()
	d.miso.Input()
	d.ss.DigitalWrite(core.LOW)
	// core.Delay(1000)
	if !SendCommandCheckAck(d, []byte{COMMAND_GETFIRMWAREVERSION}, defaultTimeoutMs) {
		err = ErrDeviceNotReady
		return
	}
	d.ss.DigitalWrite(core.HIGH)
	device = d
	return
}