WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
DigitalModule.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef DIGITAL_MODULE_H_
8 #define DIGITAL_MODULE_H_
9 
10 #include "Module.h"
11 #include "ChipObject.h"
12 
13 class I2C;
14 
15 const uint32_t kExpectedLoopTiming = 260;
16 
17 class DigitalModule: public Module
18 {
19  friend class I2C;
20  friend class Module;
21 
22 protected:
23  explicit DigitalModule(uint8_t moduleNumber);
24  virtual ~DigitalModule();
25 
26 public:
27  void SetPWM(uint32_t channel, uint8_t value);
28  uint8_t GetPWM(uint32_t channel);
29  void SetPWMPeriodScale(uint32_t channel, uint32_t squelchMask);
30  void SetRelayForward(uint32_t channel, bool on);
31  void SetRelayReverse(uint32_t channel, bool on);
32  bool GetRelayForward(uint32_t channel);
33  uint8_t GetRelayForward();
34  bool GetRelayReverse(uint32_t channel);
35  uint8_t GetRelayReverse();
36  bool AllocateDIO(uint32_t channel, bool input);
37  void FreeDIO(uint32_t channel);
38  void SetDIO(uint32_t channel, short value);
39  bool GetDIO(uint32_t channel);
40  uint16_t GetDIO();
41  bool GetDIODirection(uint32_t channel);
42  uint16_t GetDIODirection();
43  void Pulse(uint32_t channel, float pulseLength);
44  bool IsPulsing(uint32_t channel);
45  bool IsPulsing();
46  uint32_t AllocateDO_PWM();
47  void FreeDO_PWM(uint32_t pwmGenerator);
48  void SetDO_PWMRate(float rate);
49  void SetDO_PWMDutyCycle(uint32_t pwmGenerator, float dutyCycle);
50  void SetDO_PWMOutputChannel(uint32_t pwmGenerator, uint32_t channel);
51  uint16_t GetLoopTiming();
52 
53  I2C* GetI2C(uint32_t address);
54 
55  static DigitalModule* GetInstance(uint8_t moduleNumber);
56  static uint8_t RemapDigitalChannel(uint32_t channel) { return 15 - channel; }; // TODO: Need channel validation
57  static uint8_t UnmapDigitalChannel(uint32_t channel) { return 15 - channel; }; // TODO: Need channel validation
58 
59 private:
60  SEM_ID m_digitalSemaphore;
61  SEM_ID m_relaySemaphore;
62  SEM_ID m_doPwmSemaphore;
63  tDIO *m_fpgaDIO;
64 };
65 
66 #endif
67 
void SetRelayForward(uint32_t channel, bool on)
Definition: DigitalModule.cpp:160
bool IsPulsing()
Definition: DigitalModule.cpp:419
uint16_t GetDIODirection()
Definition: DigitalModule.cpp:376
void SetDIO(uint32_t channel, short value)
Definition: DigitalModule.cpp:294
void SetRelayReverse(uint32_t channel, bool on)
Definition: DigitalModule.cpp:181
void SetDO_PWMDutyCycle(uint32_t pwmGenerator, float dutyCycle)
Definition: DigitalModule.cpp:502
uint32_t AllocateDO_PWM()
Definition: DigitalModule.cpp:433
void FreeDIO(uint32_t channel)
Definition: DigitalModule.cpp:282
void SetDO_PWMOutputChannel(uint32_t pwmGenerator, uint32_t channel)
Definition: DigitalModule.cpp:474
Definition: Module.h:15
uint16_t GetLoopTiming()
Definition: DigitalModule.cpp:528
void SetDO_PWMRate(float rate)
Definition: DigitalModule.cpp:458
void Pulse(uint32_t channel, float pulseLength)
Definition: DigitalModule.cpp:391
void SetPWM(uint32_t channel, uint8_t value)
Definition: DigitalModule.cpp:119
uint8_t GetPWM(uint32_t channel)
Definition: DigitalModule.cpp:133
Definition: I2C.h:22
bool AllocateDIO(uint32_t channel, bool input)
Definition: DigitalModule.cpp:252
uint8_t GetRelayReverse()
Definition: DigitalModule.cpp:234
uint16_t GetDIO()
Definition: DigitalModule.cpp:343
static DigitalModule * GetInstance(uint8_t moduleNumber)
Definition: DigitalModule.cpp:26
uint8_t GetRelayForward()
Definition: DigitalModule.cpp:211
void FreeDO_PWM(uint32_t pwmGenerator)
Definition: DigitalModule.cpp:445
void SetPWMPeriodScale(uint32_t channel, uint32_t squelchMask)
Definition: DigitalModule.cpp:147
Definition: DigitalModule.h:17
DigitalModule(uint8_t moduleNumber)
Definition: DigitalModule.cpp:51
I2C * GetI2C(uint32_t address)
Definition: DigitalModule.cpp:544