From: Dave Hylands <dhylands@gm...> - 2006-04-14 20:34:47
> I am trying to write code to interface with our MG1101 microgyro. It
> doesn't appear to be i2c-compliant, so I am going to bit-bang a driver ou=
> from some working code that interfaced it with an EB63 microcontroller. =
> set pins on the robotstix, I was going to use i2c-io, but I am not sure h=
> to do this from within my C program. Any suggestions?
The best way would be to use the fucntions found in
robostix/gumstix/Common/i2c-io-api.c (and the corresponding .h file).
So, to set the direction of PORT C, pin 4 to input. You'd use the
I2C_IO_SetGPIODir function. The i2cDev parameter is the file handle of
the /dev/i2c-0 file that you would have opened earlier. The port
parameter is a number, with 0 =3D PortA, 1 =3D PortB, 2 =3D PortC, etc.
mask contains a bit mask of the bits you want to affect, and val
contains a bitmask of the the values you want to set.
So, the robostix is effectively doing:
DDRx &=3D ~mask;
DDRx |=3D ( val & mask );
So here's the function call to set PORT C pin 4 to input:
if ( !I2C_IO_SetGPIODir( i2cDev, 3, 1 << 4, 1 << 4 ))
... Setting direction failed...
Note, that you could also use 0xFF or 0 as the last argument, because
the mask is applied to the value as well.
Similarly, you can use I2C_IO_SetGPIO to set the value of the actual GPIO p=
Vancouver, BC, Canada