diff options
author | Alex Williams <alex.williams@ni.com> | 2018-10-12 17:17:13 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-10-19 10:17:08 -0700 |
commit | a830fab2a00acd158f14d716e3493ef50afd8aeb (patch) | |
tree | 96425e10026d94dfcef46ebbfa8cc5bccb5cf90f /mpm/lib/i2c/i2cdev.h | |
parent | 0e30a5ca0872762a36be15f030a763c7f67dd003 (diff) | |
download | uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.tar.gz uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.tar.bz2 uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.zip |
mpm: Add i2c APIs for simple transfers
Diffstat (limited to 'mpm/lib/i2c/i2cdev.h')
-rw-r--r-- | mpm/lib/i2c/i2cdev.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/mpm/lib/i2c/i2cdev.h b/mpm/lib/i2c/i2cdev.h new file mode 100644 index 000000000..4c7f84972 --- /dev/null +++ b/mpm/lib/i2c/i2cdev.h @@ -0,0 +1,58 @@ +/* + * Copyright 2018 Ettus Research, a National Instruments Company + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef _I2CDEV_H_FOUND_ +#define _I2CDEV_H_FOUND_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include <stddef.h> + +/* + * This API provides access to i2c devices. It uses the character device API + * from the Linux kernel and i2c-tools + * + * The kernel documentation can be found at + * https://www.kernel.org/doc/Documentation/i2c/dev-interface + */ + +/*! Initialize a i2cdev interface + * + * \param fd Return value of the file descriptor + * \param device Path of i2cdev device, e.g. "/dev/i2c0" + * \param timeout_ms Timeout to wait for ACK in ms + * + * \returns 0 if all is good, or an error code otherwise + */ +int i2cdev_open(int *fd, const char *device, const unsigned int timeout_ms); + +/*! Do an i2c transaction over i2cdev + * If both tx and rx are to be done in one transaction, first tx data is + * transmitted, followed by a repeated start condition, then the rx data is + * read. + * + * \param fd File descriptor for the i2cdev bus segment + * \param addr i2c device address + * \param ten_bit_addr Nonzero if true (typically 0) + * \param tx Buffer of data to be written to device + * \param tx_len Total number of non-addr bytes to be written + * \param rx Buffer where read data can be stored + * \param rx_len Total number of bytes to be read + * + * Assumption: spidev was configured properly beforehand. + * + * \returns 0 if all is golden + */ +int i2cdev_transfer(int fd, uint16_t addr, int ten_bit_addr, + uint8_t *tx, size_t tx_len, + uint8_t *rx, size_t rx_len); +#ifdef __cplusplus +} +#endif +#endif /* _I2CDEV_H_FOUND_ */ |