WPILib 2012
WPILibRoboticsLibraryforFRC
DigitalModule.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef DIGITAL_MODULE_H_
00008 #define DIGITAL_MODULE_H_
00009 
00010 #include "Module.h"
00011 #include "ChipObject.h"
00012 
00013 class I2C;
00014 
00015 const UINT32 kExpectedLoopTiming = 260;
00016 
00017 class DigitalModule: public Module
00018 {
00019         friend class I2C;
00020         friend class Module;
00021 
00022 protected:
00023         explicit DigitalModule(UINT8 moduleNumber);
00024         virtual ~DigitalModule();
00025 
00026 public:
00027         void SetPWM(UINT32 channel, UINT8 value);
00028         UINT8 GetPWM(UINT32 channel);
00029         void SetPWMPeriodScale(UINT32 channel, UINT32 squelchMask);
00030         void SetRelayForward(UINT32 channel, bool on);
00031         void SetRelayReverse(UINT32 channel, bool on);
00032         bool GetRelayForward(UINT32 channel);
00033         UINT8 GetRelayForward();
00034         bool GetRelayReverse(UINT32 channel);
00035         UINT8 GetRelayReverse();
00036         bool AllocateDIO(UINT32 channel, bool input);
00037         void FreeDIO(UINT32 channel);
00038         void SetDIO(UINT32 channel, short value);
00039         bool GetDIO(UINT32 channel);
00040         UINT16 GetDIO();
00041         bool GetDIODirection(UINT32 channel);
00042         UINT16 GetDIODirection();
00043         void Pulse(UINT32 channel, float pulseLength);
00044         bool IsPulsing(UINT32 channel);
00045         bool IsPulsing();
00046         UINT32 AllocateDO_PWM();
00047         void FreeDO_PWM(UINT32 pwmGenerator);
00048         void SetDO_PWMRate(float rate);
00049         void SetDO_PWMDutyCycle(UINT32 pwmGenerator, float dutyCycle);
00050         void SetDO_PWMOutputChannel(UINT32 pwmGenerator, UINT32 channel);
00051 
00052         I2C* GetI2C(UINT32 address);
00053 
00054         static DigitalModule* GetInstance(UINT8 moduleNumber);
00055         static UINT8 RemapDigitalChannel(UINT32 channel) { return 15 - channel; }; // TODO: Need channel validation
00056         static UINT8 UnmapDigitalChannel(UINT32 channel) { return 15 - channel; }; // TODO: Need channel validation
00057 
00058 private:
00059         SEM_ID m_digitalSemaphore;
00060         SEM_ID m_relaySemaphore;
00061         SEM_ID m_doPwmSemaphore;
00062         tDIO *m_fpgaDIO;
00063 };
00064 
00065 #endif
00066 
 All Classes Functions Variables