Add i2c_smbus_linux.h/cpp driver to handle ioctl-driven I2C access to /dev/i2c-x nodes on Linux
This commit is contained in:
parent
1b288ce0b2
commit
0b5e8b400e
6 changed files with 82 additions and 11 deletions
Binary file not shown.
16
OpenAuraSDK/OpenAuraSDK.pro
Normal file
16
OpenAuraSDK/OpenAuraSDK.pro
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
TEMPLATE = app
|
||||
CONFIG += console c++11
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
i2c_smbus.cpp \
|
||||
AuraController.cpp \
|
||||
OpenAuraSDK.cpp \
|
||||
i2c_smbus_linux.cpp
|
||||
|
||||
HEADERS += \
|
||||
i2c_smbus.h \
|
||||
i2c_smbus_linux.h \
|
||||
AuraController.h \
|
||||
OpenAuraSDK.h
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include "i2c_smbus.h"
|
||||
#include <string.h>
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_write_quick(u8 addr, u8 value)
|
||||
{
|
||||
|
|
@ -118,4 +119,4 @@ s32 i2c_smbus_interface::i2c_smbus_write_i2c_block_data(u8 addr, u8 command, u8
|
|||
data.block[0] = length;
|
||||
memcpy(&data.block[1], values, length);
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,19 +8,18 @@
|
|||
| GNU GPL v2 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <windows.h>
|
||||
#ifndef I2C_SMBUS_H
|
||||
#define I2C_SMBUS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "inpout32.h"
|
||||
|
||||
typedef UINT8 u8;
|
||||
typedef UINT16 u16;
|
||||
typedef UINT32 uint32_t;
|
||||
typedef INT32 s32;
|
||||
|
||||
#pragma comment(lib, "inpout32.lib")
|
||||
#pragma once
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef int s32;
|
||||
|
||||
#ifdef WIN32
|
||||
//Data for SMBus Messages
|
||||
#define I2C_SMBUS_BLOCK_MAX 32
|
||||
|
||||
|
|
@ -30,6 +29,11 @@ union i2c_smbus_data
|
|||
u16 word;
|
||||
u8 block[I2C_SMBUS_BLOCK_MAX + 2];
|
||||
};
|
||||
#else
|
||||
|
||||
#include <linux/i2c.h>
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
// i2c_smbus_xfer read or write markers
|
||||
#define I2C_SMBUS_READ 1
|
||||
|
|
@ -64,4 +68,6 @@ public:
|
|||
|
||||
//Virtual function to be implemented by the driver
|
||||
virtual s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data) = 0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* I2C_SMBUS_H */
|
||||
|
|
|
|||
29
OpenAuraSDK/i2c_smbus_linux.cpp
Normal file
29
OpenAuraSDK/i2c_smbus_linux.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*-----------------------------------------*\
|
||||
| i2c_smbus_linux.cpp |
|
||||
| |
|
||||
| Linux i2c/smbus driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/14/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "i2c_smbus.h"
|
||||
#include "i2c_smbus_linux.h"
|
||||
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
s32 i2c_smbus_linux::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, union i2c_smbus_data* data)
|
||||
{
|
||||
struct i2c_smbus_ioctl_data args;
|
||||
|
||||
//Tell I2C host which slave address to transfer to
|
||||
ioctl(handle, I2C_SLAVE, addr);
|
||||
|
||||
args.read_write = read_write;
|
||||
args.command = command;
|
||||
args.size = size;
|
||||
args.data = data;
|
||||
|
||||
return ioctl(handle, I2C_SMBUS, &args);
|
||||
}
|
||||
19
OpenAuraSDK/i2c_smbus_linux.h
Normal file
19
OpenAuraSDK/i2c_smbus_linux.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*-----------------------------------------*\
|
||||
| i2c_smbus_linux.h |
|
||||
| |
|
||||
| Definitions and types for Linux i2c/smbus|
|
||||
| driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/14/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "i2c_smbus.h"
|
||||
|
||||
class i2c_smbus_linux : public i2c_smbus_interface
|
||||
{
|
||||
public:
|
||||
int handle;
|
||||
|
||||
private:
|
||||
s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue