001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.hal; 006 007import java.nio.ByteBuffer; 008 009public class SPIJNI extends JNIWrapper { 010 public static final int INVALID_PORT = -1; 011 public static final int ONBOARD_CS0_PORT = 0; 012 public static final int ONBOARD_CS1_PORT = 1; 013 public static final int ONBOARD_CS2_PORT = 2; 014 public static final int ONBOARD_CS3_PORT = 3; 015 public static final int MXP_PORT = 4; 016 017 public static final int SPI_MODE0 = 0; 018 public static final int SPI_MODE1 = 1; 019 public static final int SPI_MODE2 = 2; 020 public static final int SPI_MODE3 = 3; 021 022 public static native void spiInitialize(int port); 023 024 public static native int spiTransaction( 025 int port, ByteBuffer dataToSend, ByteBuffer dataReceived, byte size); 026 027 public static native int spiTransactionB( 028 int port, byte[] dataToSend, byte[] dataReceived, byte size); 029 030 public static native int spiWrite(int port, ByteBuffer dataToSend, byte sendSize); 031 032 public static native int spiWriteB(int port, byte[] dataToSend, byte sendSize); 033 034 public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, byte size); 035 036 public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, byte size); 037 038 public static native void spiClose(int port); 039 040 public static native void spiSetSpeed(int port, int speed); 041 042 public static native void spiSetMode(int port, int mode); 043 044 public static native int spiGetMode(int port); 045 046 public static native void spiSetChipSelectActiveHigh(int port); 047 048 public static native void spiSetChipSelectActiveLow(int port); 049 050 public static native void spiInitAuto(int port, int bufferSize); 051 052 public static native void spiFreeAuto(int port); 053 054 public static native void spiStartAutoRate(int port, double period); 055 056 public static native void spiStartAutoTrigger( 057 int port, 058 int digitalSourceHandle, 059 int analogTriggerType, 060 boolean triggerRising, 061 boolean triggerFalling); 062 063 public static native void spiStopAuto(int port); 064 065 public static native void spiSetAutoTransmitData(int port, byte[] dataToSend, int zeroSize); 066 067 public static native void spiForceAutoRead(int port); 068 069 public static native int spiReadAutoReceivedData( 070 int port, ByteBuffer buffer, int numToRead, double timeout); 071 072 public static native int spiReadAutoReceivedData( 073 int port, int[] buffer, int numToRead, double timeout); 074 075 public static native int spiGetAutoDroppedCount(int port); 076 077 public static native void spiConfigureAutoStall( 078 int port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead); 079}