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
007public class PWMJNI extends DIOJNI {
008  /**
009   * Initializes a PWM port.
010   *
011   * @param halPortHandle the port to initialize
012   * @return the created pwm handle
013   */
014  public static native int initializePWMPort(int halPortHandle);
015
016  /**
017   * Checks if a pwm channel is valid.
018   *
019   * @param channel the channel to check
020   * @return true if the channel is valid, otherwise false
021   */
022  public static native boolean checkPWMChannel(int channel);
023
024  /**
025   * Frees a PWM port.
026   *
027   * @param pwmPortHandle the pwm handle
028   */
029  public static native void freePWMPort(int pwmPortHandle);
030
031  /**
032   * Sets the configuration settings for the PWM channel.
033   *
034   * <p>All values are in microseconds.
035   *
036   * @param pwmPortHandle the PWM handle
037   * @param maxPwm the maximum PWM value
038   * @param deadbandMaxPwm the high range of the center deadband
039   * @param centerPwm the center PWM value
040   * @param deadbandMinPwm the low range of the center deadband
041   * @param minPwm the minimum PWM value
042   */
043  public static native void setPWMConfigMicroseconds(
044      int pwmPortHandle,
045      int maxPwm,
046      int deadbandMaxPwm,
047      int centerPwm,
048      int deadbandMinPwm,
049      int minPwm);
050
051  /**
052   * Gets the pwm configuration settings for the PWM channel.
053   *
054   * <p>Values are in microseconds.
055   *
056   * @param pwmPortHandle the PWM handle
057   * @return the pwm configuration settings
058   */
059  public static native PWMConfigDataResult getPWMConfigMicroseconds(int pwmPortHandle);
060
061  /**
062   * Sets if the FPGA should output the center value if the input value is within the deadband.
063   *
064   * @param pwmPortHandle the PWM handle
065   * @param eliminateDeadband true to eliminate deadband, otherwise false
066   */
067  public static native void setPWMEliminateDeadband(int pwmPortHandle, boolean eliminateDeadband);
068
069  /**
070   * Gets the current eliminate deadband value.
071   *
072   * @param pwmPortHandle the PWM handle
073   * @return true if set, otherwise false
074   */
075  public static native boolean getPWMEliminateDeadband(int pwmPortHandle);
076
077  /**
078   * Sets a PWM channel to the desired pulse width in microseconds.
079   *
080   * @param pwmPortHandle the PWM handle
081   * @param microsecondPulseTime the PWM value to set
082   */
083  public static native void setPulseTimeMicroseconds(int pwmPortHandle, int microsecondPulseTime);
084
085  /**
086   * Sets a PWM channel to the desired scaled value.
087   *
088   * <p>The values range from -1 to 1 and the period is controlled by the PWM Period and MinHigh
089   * registers.
090   *
091   * @param pwmPortHandle the PWM handle
092   * @param speed the scaled PWM value to set
093   */
094  public static native void setPWMSpeed(int pwmPortHandle, double speed);
095
096  /**
097   * Sets a PWM channel to the desired position value.
098   *
099   * <p>The values range from 0 to 1 and the period is controlled by the PWM Period and MinHigh
100   * registers.
101   *
102   * @param pwmPortHandle the PWM handle
103   * @param position the positional PWM value to set
104   */
105  public static native void setPWMPosition(int pwmPortHandle, double position);
106
107  /**
108   * Gets the current microsecond pulse time from a PWM channel.
109   *
110   * @param pwmPortHandle the PWM handle
111   * @return the current PWM microsecond pulse time
112   */
113  public static native int getPulseTimeMicroseconds(int pwmPortHandle);
114
115  /**
116   * Gets a scaled value from a PWM channel.
117   *
118   * <p>The values range from -1 to 1.
119   *
120   * @param pwmPortHandle the PWM handle
121   * @return the current speed PWM value
122   */
123  public static native double getPWMSpeed(int pwmPortHandle);
124
125  /**
126   * Gets a position value from a PWM channel.
127   *
128   * <p>The values range from 0 to 1.
129   *
130   * @param pwmPortHandle the PWM handle
131   * @return the current positional PWM value
132   */
133  public static native double getPWMPosition(int pwmPortHandle);
134
135  /**
136   * Sets a PWM channel to be disabled.
137   *
138   * <p>The channel is disabled until the next time it is set. Note this is different from just
139   * setting a 0 speed, as this will actively stop all signaling on the channel.
140   *
141   * @param pwmPortHandle the PWM handle.
142   */
143  public static native void setPWMDisabled(int pwmPortHandle);
144
145  /**
146   * Forces a PWM signal to go to 0 temporarily.
147   *
148   * @param pwmPortHandle the PWM handle.
149   */
150  public static native void latchPWMZero(int pwmPortHandle);
151
152  /**
153   * Sets the PWM output to be a continuous high signal while enabled.
154   *
155   * @param pwmPortHandle the PWM handle.
156   */
157  public static native void setAlwaysHighMode(int pwmPortHandle);
158
159  /**
160   * Sets how how often the PWM signal is squelched, thus scaling the period.
161   *
162   * @param pwmPortHandle the PWM handle.
163   * @param squelchMask the 2-bit mask of outputs to squelch
164   */
165  public static native void setPWMPeriodScale(int pwmPortHandle, int squelchMask);
166
167  /** Utility class. */
168  private PWMJNI() {}
169}