Hi,
Anyone have some iic code to write to i2c under freeBSD ?
My i2c display is detected at 0x0c.
The i2c write was taken from various sources and the most 'reliable' match I found was
the code donw the thread.
I don't know if I am doing this correct. All I could find was writing one byte at the time.
I also tried, but I guess is not the right way
Anyone have some iic code to write to i2c under freeBSD ?
My i2c display is detected at 0x0c.
Code:
Hardware may not support START/STOP scanning; trying less-reliable read method.
Scanning I2C devices on /dev/iic2: 0x3c
root@s2wcom:/home/s2wcom/oled # devinfo | grep iic
iichb0
iicbus0
iic0
iichb1
iicbus1
iic1
iichb2
iicbus2
iic2
The i2c write was taken from various sources and the most 'reliable' match I found was
the code donw the thread.
I don't know if I am doing this correct. All I could find was writing one byte at the time.
Code:
int _i2c_write(int slave, int idev, const unsigned char* pb,
unsigned char offset, size_t bytes)
{
int8_t buf[2];
struct iic_msg msg;
struct iic_rdwr_data rdwr;
for(int i=0;i<bytes;i++)
{
buf[0] = i;
buf[1] = pb[i];
msg.slave = slave<<1;
msg.flags = 0;
msg.len = 2;
msg.buf = buf;
rdwr.msgs = &msg;
rdwr.nmsgs = 1;
if ( ioctl(idev, I2CRDWR, &rdwr) < 0 ) // hang bang !
{
perror("I2CRDWR");
return(-1);
}
}
return(0);
}
I also tried, but I guess is not the right way
Code:
int _i2c_write(int slave, int idev, const unsigned char* pb,
unsigned char offset, size_t bytes)
{
int8_t buf[LARGE_ENOUGH];
struct iic_msg msg;
struct iic_rdwr_data rdwr;
buf[0] = 0;
memcpy(buf+1,pb,bytes);
msg.slave = slave<<1;
msg.flags = 0;
msg.len = 1+bytes;
msg.buf = buf;
rdwr.msgs = &msg;
rdwr.nmsgs = 1;
if ( ioctl(idev, I2CRDWR, &rdwr) < 0 ) // hang bang !
{
perror("I2CRDWR");
return(-1);
}
return(0);
}