Definition in file proxdev_i2c.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "i2ccom.h"
#include "bsproxy.h"
Go to the source code of this file.
Defines | |
| #define | I2C_DEV_NAME_DFT "/dev/i2c-0" |
| default I2C device | |
Functions | |
| static int | cb_i2c_scan (i2c_t *pI2C, i2c_dev_t addr, void *context) |
| Scanned device callback. | |
| int | ProxDevI2CScan (BsProxyDev_T *pProxDev, byte_t bufScan[], size_t sizeBuf) |
| Scan I2C Bus for attached address. | |
| int | ProxDevI2CTrans (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufWrite[], size_t countWrite, byte_t bufRead[], size_t countRead) |
| Perform a write/read transaction between an I2C device. | |
| int | ProxDevI2CWrite (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufWrite[], size_t countWrite) |
| Write buffer to an I2C device. | |
| int | ProxDevI2CRead (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufRead[], size_t countRead) |
| Read bytes from an I2C device. | |
Variables | |
| static byte_t | i2c_scanned_dev [128] |
| scanned device vector | |
| static byte_t | i2c_scanned_cnt |
| scanned device count | |
|
||||||||||||||||
|
Scanned device callback.
Definition at line 85 of file proxdev_i2c.c. References i2c_scanned_cnt, and i2c_scanned_dev. Referenced by ProxDevI2CScan(). 00086 { 00087 i2c_scanned_dev[i2c_scanned_cnt++] = (byte_t)addr; 00088 return 1; 00089 }
|
|
||||||||||||||||||||
|
Read bytes from an I2C device.
Definition at line 212 of file proxdev_i2c.c. References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec. Referenced by CmdDevRead(). 00214 { 00215 i2c_t i2c; 00216 int n; 00217 00218 pthread_mutex_lock(&pProxDev->m_mutDev); 00219 00220 i2c.fd = pProxDev->m_unDevSpec.i2c.m_fd; 00221 i2c.dev = 0; 00222 00223 n = i2c_llread(&i2c, i2cAddr, (char *)bufRead, (uint_t)countRead); 00224 00225 if( n <= 0 ) 00226 { 00227 LOGSYSERROR("%s: i2c_llread(0x%02x...)", pProxDev->m_sDevName, i2cAddr); 00228 } 00229 00230 pthread_mutex_unlock(&pProxDev->m_mutDev); 00231 00232 return n; 00233 }
|
|
||||||||||||||||
|
Scan I2C Bus for attached address. The addresses of all discovered devices are returned.
Definition at line 107 of file proxdev_i2c.c. References cb_i2c_scan(), BsProxyDev_T::i2c, i2c_scanned_cnt, i2c_scanned_dev, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, and BsProxyDev_T::m_unDevSpec. Referenced by CmdDevScan(). 00108 { 00109 i2c_t i2c; 00110 int n; 00111 00112 pthread_mutex_lock(&pProxDev->m_mutDev); 00113 00114 i2c.fd = pProxDev->m_unDevSpec.i2c.m_fd; 00115 i2c.dev = 0; 00116 00117 i2c_scanned_cnt = 0; 00118 00119 i2c_scan(&i2c, cb_i2c_scan, NULL); 00120 00121 for(n=0; n<i2c_scanned_cnt && n<sizeBuf; ++n) 00122 { 00123 bufScan[n] = i2c_scanned_dev[n]; 00124 } 00125 00126 pthread_mutex_unlock(&pProxDev->m_mutDev); 00127 00128 return n; 00129 }
|
|
||||||||||||||||||||||||||||
|
Perform a write/read transaction between an I2C device.
Definition at line 143 of file proxdev_i2c.c. References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec. Referenced by BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPIMUCmdGetCooked(), BPIMUCmdGetIds(), BPIMUCmdGetRaw(), and CmdDevTrans(). 00146 { 00147 i2c_t i2c; 00148 int n; 00149 00150 pthread_mutex_lock(&pProxDev->m_mutDev); 00151 00152 i2c.fd = pProxDev->m_unDevSpec.i2c.m_fd; 00153 i2c.dev = i2cAddr; 00154 00155 n = i2c_lltransfer(&i2c, i2cAddr, 00156 (char *)bufWrite, (uint_t)countWrite, 00157 (char *)bufRead, (uint_t)countRead); 00158 00159 if( n <= 0 ) 00160 { 00161 LOGSYSERROR("%s: i2c_lltransfer(0x%02x...)", pProxDev->m_sDevName, i2cAddr); 00162 } 00163 00164 pthread_mutex_unlock(&pProxDev->m_mutDev); 00165 00166 return n; 00167 }
|
|
||||||||||||||||||||
|
Write buffer to an I2C device.
Definition at line 179 of file proxdev_i2c.c. References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec. Referenced by BPFootCmdSetCal(), BPIMUCmdSetCal(), BPIMUCmdSetOrientation(), and CmdDevWrite(). 00181 { 00182 i2c_t i2c; 00183 int n; 00184 00185 pthread_mutex_lock(&pProxDev->m_mutDev); 00186 00187 i2c.fd = pProxDev->m_unDevSpec.i2c.m_fd; 00188 i2c.dev = 0; 00189 00190 n = i2c_llwrite(&i2c, i2cAddr, (char *)bufWrite, (uint_t)countWrite); 00191 00192 if( n <= 0 ) 00193 { 00194 LOGSYSERROR("%s: i2c_llwrite(0x%02x...)", pProxDev->m_sDevName, i2cAddr); 00195 } 00196 00197 pthread_mutex_unlock(&pProxDev->m_mutDev); 00198 00199 return n; 00200 }
|
1.4.6