75 lines
3.6 KiB
C#
75 lines
3.6 KiB
C#
|
namespace Unosquare.WiringPi.Native
|
|||
|
{
|
|||
|
using System.Runtime.InteropServices;
|
|||
|
|
|||
|
public partial class WiringPi
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Simple device read. Some devices present data when you read them without having to do any register transactions.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CRead", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CRead(int fd);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// These read an 8-bit value from the device register indicated.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <param name="reg">The reg.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg8", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CReadReg8(int fd, int reg);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// These read a 16-bit value from the device register indicated.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <param name="reg">The reg.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CReadReg16", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CReadReg16(int fd, int reg);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Simple device write. Some devices accept data this way without needing to access any internal registers.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <param name="data">The data.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWrite", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CWrite(int fd, int data);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// These write an 8-bit data value into the device register indicated.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <param name="reg">The reg.</param>
|
|||
|
/// <param name="data">The data.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg8", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CWriteReg8(int fd, int reg, int data);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// These write a 16-bit data value into the device register indicated.
|
|||
|
/// </summary>
|
|||
|
/// <param name="fd">The fd.</param>
|
|||
|
/// <param name="reg">The reg.</param>
|
|||
|
/// <param name="data">The data.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CWriteReg16", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CWriteReg16(int fd, int reg, int data);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// This initializes the I2C system with your given device identifier.
|
|||
|
/// The ID is the I2C number of the device and you can use the i2cdetect program to find this out. wiringPiI2CSetup()
|
|||
|
/// will work out which revision Raspberry Pi you have and open the appropriate device in /dev.
|
|||
|
/// The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.
|
|||
|
/// E.g. the popular MCP23017 GPIO expander is usually device Id 0x20, so this is the number you would pass into wiringPiI2CSetup().
|
|||
|
/// </summary>
|
|||
|
/// <param name="devId">The dev identifier.</param>
|
|||
|
/// <returns>The result.</returns>
|
|||
|
[DllImport(WiringPiLibrary, EntryPoint = "wiringPiI2CSetup", SetLastError = true)]
|
|||
|
public static extern int WiringPiI2CSetup(int devId);
|
|||
|
}
|
|||
|
}
|