⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u2cwrapper.java

📁 一个网上的开源项目
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * library for Linux.
   * @return I2CBrdg.dll dynamic link library version number.
   */
  public static U2CVersionInfo getDllVersion() {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    U2CVersionInfo ver=new U2CVersionInfo();
    getDllVersionN(ver);
    return ver;
  }
  private static native void getDllVersionN(U2CVersionInfo ver);

  // --------------------------------------------------------------------------
  // I2C high level and configuration routines
  /**
   * Configures I2C bus frequency.
   * @param device U2C-12 device to configure.
   * @param frequency The frequency of I2C bus, where:<br>
   * 0 corresponds to I2C bus fast mode (400 kHz).<br>
   * 1 corresponds to I2C bus standard mode (100 kHz).<br>
   * 1+n corresponds to clock period of I2C bus equal to 10 + 2*n uS.<br>
   * For convenience following constants were introduced:<br>
   * U2C_I2C_FREQ_FAST    I2C bus fast mode (400 kHz)<br>
   * U2C_I2C_FREQ_STD     I2C bus standard mode (100 kHz)<br>
   * U2C_I2C_FREQ_83KHZ   83 kHz<br>
   * U2C_I2C_FREQ_71KHZ   71 kHz<br>
   * U2C_I2C_FREQ_62KHZ   62 kHz<br>
   * U2C_I2C_FREQ_50KHZ   50 kHz<br>
   * U2C_I2C_FREQ_25KHZ   25 kHz<br>
   * U2C_I2C_FREQ_10KHZ   10 kHz<br>
   * U2C_I2C_FREQ_5KHZ     5 kHz<br>
   * U2C_I2C_FREQ_2KHZ     2 kHz<br>
   */
  public static void setI2cFreq(U2CDevice device, int frequency)  throws U2CDeviceException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    int status=setI2cFreqN(device,frequency);
    U2CException.checkDeviceStatus(status);
  }
  private static native int setI2cFreqN(U2CDevice device, int frequency);

  /**
   * Obtains I2C bus frequency.
   * @param device U2C-12 device to obtain the I2C bus frequency.
   * @return I2C bus frequency. See {@link i2c.U2CWrapper#setI2cFreq(U2CDevice device, int frequency)}
   */
  public static int getI2cFreq(U2CDevice device) throws U2CDeviceException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    WrapedInt freq=new WrapedInt();
    int status=getI2cFreqN(device,freq);
    U2CException.checkDeviceStatus(status);
    return freq.get();
  }
  private static native int getI2cFreqN(U2CDevice device,WrapedInt freq);

  /**
   * Enables I2C bus clock synchronization.<br>
   * Clock synchronization (clock stretching) is used in situations where an I2C
   * slave is not able to co-operate with the clock speed provided by the U2C-12
   * I2C master and needs to slow down an I2C bus. I2C slave holds down the SCL
   * line low and in this way signals the I2C master about a wait state. If I2C
   * bus clock synchronization is enabled, U2C-12 device will wait until I2C
   * slave device releases the SCL line. <br>
   * <b>Warning:</b>
   * I2C bus clock synchronization (clock stretching) is implemented for I2C bus
   * frequences up to 100kHz. See U2C_SetI2cFreq() to learn how to change I2C
   * bus frequency.
   * @param device U2C-12 device.
   * @param enable Boolean whether clock stretching should be enabled.
   */
  public static void setClockSynch(U2CDevice device, boolean enable) throws U2CDeviceException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    int status=setClockSynchN(device,enable);
    U2CDeviceException.checkDeviceStatus(status);
  }
  private static native int setClockSynchN(U2CDevice device, boolean enable);

  /**
   * Checks if the I2C bus clock synchronization is enabled.<br>
   * See {@link i2c.U2CWrapper#setClockSynch(U2CDevice device, boolean enable)}
   * for more details
   * @param device U2C-12 device.
   * @return enable Boolean whether clock stretching is enabled.
   */
  public static boolean getClockSynch(U2CDevice device) throws U2CDeviceException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    WrapedInt enabled=new WrapedInt();
    int status=getClockSynchN(device,enabled);
    U2CException.checkDeviceStatus(status);
    return enabled.get()==1;
  }
  private static native int getClockSynchN(U2CDevice device,WrapedInt enabled);

  /**
   * Reads up to 256 bytes from the I2C slave device.
   * @param device U2C-12 device.
   * @param transaction Structure to be used during the I2C read transaction.
   */
  public static void read(U2CDevice device, U2CTransaction transaction)
      throws U2CDeviceException,U2CSlaveException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    int status=readN(device,transaction,transaction.buffer);
    U2CException.checkDeviceStatus(status);
    U2CException.checkSlaveStatus(status);
  }
  private static native int readN(U2CDevice device, U2CTransaction transaction,byte[] buffer);

  /**
   * Writes up to 256 bytes from the I2C slave device.
   * @param device U2C-12 device.
   * @param transaction Structure to be used during the I2C write transaction.
   */
  public static void write(U2CDevice device, U2CTransaction transaction)
      throws U2CDeviceException,U2CSlaveException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    int status=writeN(device,transaction,transaction.buffer);
    U2CException.checkDeviceStatus(status);
    U2CException.checkSlaveStatus(status);
  }
  private static native int writeN(U2CDevice device, U2CTransaction transaction,byte[] buffer);

  /**
   * Scans slave device addresses currently occupied by I2C slave devices
   * connected to the I2C bus.
   * @param device U2C-12 device.
   * @return List of slave devices.
   */
  public static U2CSlaveAdrList scanForSlaves(U2CDevice device) throws U2CDeviceException {
    if (!dllLoaded) {
      System.loadLibrary("U2CWrapper");
      dllLoaded=true;
    }
    U2CSlaveAdrList list=new U2CSlaveAdrList();
    int status=scanForSlavesN(device,list,list.list);
    U2CException.checkDeviceStatus(status);
    return list;
  }
  private static native int scanForSlavesN(U2CDevice device,U2CSlaveAdrList list,byte[] buf);

/* not implemented yet

// I2C low level routines
   public static native void start(U2CDevice device) throws U2CDeviceException;
     public static native void repeatedStart(U2CDevice device) throws U2CDeviceException;
   public static native void stop(U2CDevice device) throws U2CDeviceException;
     public static native void putByte(U2CDevice device, byte data) throws U2CDeviceException;
   public static native byte getByte(U2CDevice device) throws U2CDeviceException;
     public static native void putByteWithAck(U2CDevice device, byte data) throws U2CDeviceException;
     public static native byte getByteWithAck(U2CDevice device, boolean ack) throws U2CDeviceException;
     public static native putAck(U2CDevice device, boolean ack) throws U2CDeviceException;
     public static native boolean ack getAck(U2CDevice device) throws U2CDeviceException;

// I2c wire level routines
   public static native U2C_ReadScl(U2CDevice device, U2C_LINE_STATE *pState) throws U2CDeviceException;
   public static native U2C_ReadSda(U2CDevice device, U2C_LINE_STATE *pState) throws U2CDeviceException;
   public static native U2C_ReleaseScl(U2CDevice device) throws U2CDeviceException;
   public static native U2C_ReleaseSda(U2CDevice device) throws U2CDeviceException;
   public static native U2C_DropScl(U2CDevice device) throws U2CDeviceException;
   public static native U2C_DropSda(U2CDevice device) throws U2CDeviceException;

// GPIO routines
   public static native U2C_SetIoDirection(U2CDevice device, ULONG Value, ULONG Mask) throws U2CDeviceException;
   public static native U2C_GetIoDirection(U2CDevice device, ULONG *pValue) throws U2CDeviceException;
   public static native U2C_IoWrite(U2CDevice device, ULONG Value, ULONG Mask) throws U2CDeviceException;
   public static native U2C_IoRead(U2CDevice device, ULONG *pValue) throws U2CDeviceException;
   public static native U2C_SetSingleIoDirection(U2CDevice device, ULONG IoNumber, BOOL bOutput) throws U2CDeviceException;
   public static native U2C_GetSingleIoDirection(U2CDevice device, ULONG IoNumber, BOOL *pbOutput) throws U2CDeviceException;
   public static native U2C_SingleIoWrite(U2CDevice device, ULONG IoNumber, BOOL Value) throws U2CDeviceException;
   public static native U2C_SingleIoRead(U2CDevice device, ULONG IoNumber, BOOL *pValue) throws U2CDeviceException;

// SPI configuration routines
   public static native U2C_SpiSetConfig(U2CDevice device, BYTE CPOL, BYTE CPHA) throws U2CDeviceException;
   public static native U2C_SpiGetConfig(U2CDevice device, BYTE *pCPOL, BYTE *pCPHA) throws U2CDeviceException;
   public static native U2C_SpiSetConfigEx(U2CDevice device, DWORD Config) throws U2CDeviceException;
   public static native U2C_SpiGetConfigEx(U2CDevice device, DWORD *pConfig) throws U2CDeviceException;
   public static native U2C_SpiSetFreq(U2CDevice device, BYTE Frequency) throws U2CDeviceException;
   public static native U2C_SpiGetFreq(U2CDevice device, BYTE *pFrequency) throws U2CDeviceException;
   public static native U2C_SpiReadWrite(U2CDevice device, BYTE *pOutBuffer, BYTE *pInBuffer, WORD Length) throws U2CDeviceException;
   public static native U2C_SpiWrite(U2CDevice device, BYTE *pOutBuffer, WORD Length) throws U2CDeviceException;
   public static native U2C_SpiRead(U2CDevice device, BYTE *pInBuffer, WORD Length) throws U2CDeviceException;

   not implemented yet */
}


class WrapedInt {
  private int i;
  public void set(int i) {this.i=i;}
  public int get() { return i; }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -