i2c  1.4.2
RoadNarrows Robotics I2C Package
i2ccore.h File Reference

I2C python C interface header. More...

#include "rnr/rnrconfig.h"

Go to the source code of this file.

Functions

int i2ccore_open (const char *device)
 Open a I2C bus device. More...
 
int i2ccore_close (int fd)
 Close an open I2C bus device. More...
 
int i2ccore_read (int fd, unsigned short cur_addr, unsigned short addr, byte_t buf[], unsigned int len)
 Read data from an attached device connected to the open I2C bus. More...
 
int i2ccore_write (int fd, unsigned short cur_addr, unsigned short addr, byte_t buf[], unsigned int len)
 Write data to an attached device connected to the open I2C bus. More...
 
int i2ccore_transfer (int fd, unsigned short cur_addr, unsigned short addr, byte_t wbuf[], unsigned int wcount, byte_t rbuf[], unsigned int rcount)
 Transfer data to an attached device connected to the open I2C bus reead back. More...
 
int i2ccore_check (int fd, unsigned short cur_addr, unsigned short addr)
 Test for the existence of a device with the given address. More...
 

Detailed Description

I2C python C interface header.

LastChangedDate
2016-01-28 14:19:12 -0700 (Thu, 28 Jan 2016)
Rev
4278
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file i2ccore.h.

Function Documentation

int i2ccore_check ( int  fd,
unsigned short  cur_addr,
unsigned short  addr 
)

Test for the existence of a device with the given address.

Parameters
fdFile descriptor.
cur_addrI2C address of last I/O operation.
addrI2C device address to read.
Returns
If device is found, returns 1, else returns 0.

Definition at line 3414 of file i2ccore_wrap.c.

References i2c_struct::addr, i2c_struct::fd, i2c_exists(), i2ccore_close(), i2ccore_open(), i2ccore_read(), i2ccore_transfer(), and i2ccore_write().

3415 {
3416  i2c_t i2c;
3417 
3418  i2c.fd = fd;
3419  i2c.addr = cur_addr;
3420 
3421  return i2c_exists(&i2c, addr);
3422 }
i2c_addr_t addr
address of the currently selected attached I2C device
Definition: i2c.h:82
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
I2C Bus Handle Type.
Definition: i2c.h:79
int i2c_exists(i2c_t *i2c, i2c_addr_t addr)
Test the existance of a device at the given address on the given I2C Bus.
Definition: i2ccom.c:199
int i2ccore_close ( int  fd)

Close an open I2C bus device.

Returns
On success, returns 0. On failure, returns -errno.

Definition at line 3309 of file i2ccore_wrap.c.

References i2c_struct::fd, and i2c_close().

Referenced by i2ccore_check().

3310 {
3311  i2c_t i2c;
3312 
3313  i2c.fd = fd;
3314 
3315  i2c_close(&i2c);
3316 
3317  return OK;
3318 }
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
void i2c_close(i2c_t *i2c)
Closes an I2C Bus.
Definition: i2ccom.c:137
I2C Bus Handle Type.
Definition: i2c.h:79
int i2ccore_open ( const char *  device)

Open a I2C bus device.

Parameters
deviceDevice name.
Returns
On success, returns open file descriptor. On failure, returns -errno.

Definition at line 3292 of file i2ccore_wrap.c.

References i2c_struct::fd, and i2c_open().

Referenced by i2ccore_check().

3293 {
3294  i2c_t i2c;
3295  int rc;
3296 
3297  rc = i2c_open(&i2c, device);
3298 
3299  return rc < 0? -errno: i2c.fd;
3300 }
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
I2C Bus Handle Type.
Definition: i2c.h:79
int i2c_open(i2c_t *i2c, const char *device)
Open the host I2C Bus device.
Definition: i2ccom.c:118
int i2ccore_read ( int  fd,
unsigned short  cur_addr,
unsigned short  addr,
byte_t  buf[],
unsigned int  count 
)

Read data from an attached device connected to the open I2C bus.

Parameters
fdFile descriptor.
cur_addrI2C address of last I/O operation.
addrI2C device address to read.
[out]bufOutput buffer.
countNumber of byte to read.
Returns
On success, returns number of bytes read. On failure, returns -errno.

Definition at line 3333 of file i2ccore_wrap.c.

References i2c_struct::addr, i2c_struct::fd, and i2c_read().

Referenced by i2ccore_check().

3335 {
3336  i2c_t i2c;
3337  int n;
3338 
3339  i2c.fd = fd;
3340  i2c.addr = cur_addr;
3341 
3342  n = i2c_read(&i2c, addr, buf, count);
3343 
3344  return n < 0? -errno: n;
3345 }
i2c_addr_t addr
address of the currently selected attached I2C device
Definition: i2c.h:82
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
I2C Bus Handle Type.
Definition: i2c.h:79
int i2c_read(i2c_t *i2c, i2c_addr_t addr, byte_t *buf, uint_t len)
Read from an I2C device.
Definition: i2ccom.c:147
int i2ccore_transfer ( int  fd,
unsigned short  cur_addr,
unsigned short  addr,
byte_t  wbuf[],
unsigned int  wcount,
byte_t  rbuf[],
unsigned int  rcount 
)

Transfer data to an attached device connected to the open I2C bus reead back.

Parameters
fdFile descriptor.
cur_addrI2C address of last I/O operation.
addrI2C device address to read.
[in]wbufInput buffer.
wcountNumber of byte to write.
[out]rbufOutput buffer.
rcountNumber of byte to read.
Returns
On success, returns 0. On failure, returns -errno.

Definition at line 3390 of file i2ccore_wrap.c.

References i2c_struct::addr, i2c_struct::fd, and i2c_transfer().

Referenced by i2ccore_check().

3393 {
3394  i2c_t i2c;
3395  int rc;
3396 
3397  i2c.fd = fd;
3398  i2c.addr = cur_addr;
3399 
3400  rc = i2c_transfer(&i2c, addr, wbuf, wcount, rbuf, rcount);
3401 
3402  return rc < 0? -errno: rc;
3403 }
i2c_addr_t addr
address of the currently selected attached I2C device
Definition: i2c.h:82
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
I2C Bus Handle Type.
Definition: i2c.h:79
int i2c_transfer(i2c_t *i2c, i2c_addr_t addr, const byte_t *write_buf, uint_t write_len, byte_t *read_buf, uint_t read_len)
Perform a transfer with an I2C device.
Definition: i2ccom.c:171
int i2ccore_write ( int  fd,
unsigned short  cur_addr,
unsigned short  addr,
byte_t  buf[],
unsigned int  count 
)

Write data to an attached device connected to the open I2C bus.

Parameters
fdFile descriptor.
cur_addrI2C address of last I/O operation.
addrI2C device address to read.
[in]bufInput buffer.
countNumber of byte to write.
Returns
On success, returns number of bytes written. On failure, returns -errno.

Definition at line 3360 of file i2ccore_wrap.c.

References i2c_struct::addr, i2c_struct::fd, and i2c_write().

Referenced by i2ccore_check().

3362 {
3363  i2c_t i2c;
3364  int n;
3365 
3366  i2c.fd = fd;
3367  i2c.addr = cur_addr;
3368 
3369  n = i2c_write(&i2c, addr, buf, count);
3370 
3371  return n < 0? -errno: n;
3372 }
i2c_addr_t addr
address of the currently selected attached I2C device
Definition: i2c.h:82
int i2c_write(i2c_t *i2c, i2c_addr_t addr, const byte_t *buf, uint_t len)
Write to an I2C device.
Definition: i2ccom.c:159
I2C python modules.
int fd
opened file descriptor of the I2C bus device
Definition: i2c.h:81
I2C Bus Handle Type.
Definition: i2c.h:79