Example #1
0
File: i2c.go Project: 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
}
Example #2
0
File: spi.go Project: 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
}