예제 #1
0
// I2cStart initializes i2c device for addresss
func (e *JouleAdaptor) I2cStart(address int) (err error) {
	if e.i2cDevice != nil {
		return
	}

	// TODO: handle the additional I2C buses
	e.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-0", address)
	return
}
예제 #2
0
// I2cStart initializes i2c device for addresss
func (e *EdisonAdaptor) I2cStart(address int) (err error) {
	if e.i2cDevice != nil {
		return
	}

	if err = e.tristate.Write(sysfs.LOW); err != nil {
		return
	}

	for _, i := range []int{14, 165, 212, 213} {
		io := sysfs.NewDigitalPin(i)
		if err = io.Export(); err != nil {
			return
		}
		if err = io.Direction(sysfs.IN); err != nil {
			return
		}
		if err = io.Unexport(); err != nil {
			return
		}
	}

	for _, i := range []int{236, 237, 204, 205} {
		io := sysfs.NewDigitalPin(i)
		if err = io.Export(); err != nil {
			return
		}
		if err = io.Direction(sysfs.OUT); err != nil {
			return
		}
		if err = io.Write(sysfs.LOW); err != nil {
			return
		}
		if err = io.Unexport(); err != nil {
			return
		}
	}

	for _, i := range []string{"28", "27"} {
		if err = changePinMode(i, "1"); err != nil {
			return
		}
	}

	if err = e.tristate.Write(sysfs.HIGH); err != nil {
		return
	}

	e.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-6", address)
	return
}
예제 #3
0
// I2cStart starts a i2c device in specified address
func (r *RaspiAdaptor) I2cStart(address int) (err error) {
	if r.i2cDevice == nil {
		r.i2cDevice, err = sysfs.NewI2cDevice(r.i2cLocation, address)
	}
	return err
}
예제 #4
0
// I2cStart initializes i2c device for addresss
func (e *EdisonAdaptor) I2cStart(address int) (err error) {
	if e.i2cDevice != nil {
		return
	}

	// FIXME: the I2cDevice interface doesn,t support multiple buses,
	// like the miniboard.. We select bus-6 by default here.

	if e.miniboard {
		for _, i := range []string{"20", "19"} /* bus-1 */ {
			//for _, i := range []string{"28", "27"} /* bus-6 */ {
			if err = changePinMode(i, "1"); err != nil {
				return
			}
		}

		e.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)

	} else {

		if err = e.tristate.Write(sysfs.LOW); err != nil {
			return
		}

		// Confiure IO18, IO19
		// (ref: mraa's intel_edison_fab_c.c, func mraa_intel_edison_i2c_init_pre)
		for _, i := range []int{14, 165, 212, 213} {
			io := sysfs.NewDigitalPin(i)
			if err = io.Export(); err != nil {
				return
			}
			if err = io.Direction(sysfs.IN); err != nil {
				return
			}
			if err = io.Unexport(); err != nil {
				return
			}
		}

		// Continue on..
		for _, i := range []int{236, 237, 204, 205} {
			io := sysfs.NewDigitalPin(i)
			if err = io.Export(); err != nil {
				return
			}
			if err = io.Direction(sysfs.OUT); err != nil {
				return
			}
			if err = io.Write(sysfs.LOW); err != nil {
				return
			}
			if err = io.Unexport(); err != nil {
				return
			}
		}

		// Activate the I2c bus-6
		for _, i := range []string{"28", "27"} {
			if err = changePinMode(i, "1"); err != nil {
				return
			}
		}

		if err = e.tristate.Write(sysfs.HIGH); err != nil {
			return
		}

		e.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-6", address)
	}

	return
}
예제 #5
0
// I2cStart starts a i2c device in specified address on i2c bus /dev/i2c-1
func (b *BeagleboneAdaptor) I2cStart(address int) (err error) {
	if b.i2cDevice == nil {
		b.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)
	}
	return
}
예제 #6
0
// I2cStart starts a i2c device in specified address on i2c bus /dev/i2c-1
func (b *BeagleboneAdaptor) I2cStart(address byte) (err error) {
	b.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)
	return
}
예제 #7
0
// I2cStart starts an i2c device in specified address.
// This assumes that the bus used is /dev/i2c-1, which corresponds to
// pins labeled TWI1-SDA and TW1-SCK (pins 9 and 11 on header 13).
func (c *ChipAdaptor) I2cStart(address int) (err error) {
	if c.i2cDevice == nil {
		c.i2cDevice, err = sysfs.NewI2cDevice("/dev/i2c-1", address)
	}
	return err
}
예제 #8
0
// I2cStart starts a i2c device in specified address
func (r *RaspiAdaptor) I2cStart(address byte) (err error) {
	r.i2cDevice, err = sysfs.NewI2cDevice(r.i2cLocation, address)
	return err
}