blob: beb123149cff0823be074113121c26a6880395e5 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
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
13class I2C;
14
15const UINT32 kExpectedLoopTiming = 260;
16
17class DigitalModule: public Module
18{
19 friend class I2C;
20 friend class Module;
21
22protected:
23 explicit DigitalModule(UINT8 moduleNumber);
24 virtual ~DigitalModule();
25
26public:
27 void SetPWM(UINT32 channel, UINT8 value);
28 UINT8 GetPWM(UINT32 channel);
29 void SetPWMPeriodScale(UINT32 channel, UINT32 squelchMask);
30 void SetRelayForward(UINT32 channel, bool on);
31 void SetRelayReverse(UINT32 channel, bool on);
32 bool GetRelayForward(UINT32 channel);
33 UINT8 GetRelayForward();
34 bool GetRelayReverse(UINT32 channel);
35 UINT8 GetRelayReverse();
36 bool AllocateDIO(UINT32 channel, bool input);
37 void FreeDIO(UINT32 channel);
38 void SetDIO(UINT32 channel, short value);
39 bool GetDIO(UINT32 channel);
40 UINT16 GetDIO();
41 bool GetDIODirection(UINT32 channel);
42 UINT16 GetDIODirection();
43 void Pulse(UINT32 channel, float pulseLength);
44 bool IsPulsing(UINT32 channel);
45 bool IsPulsing();
46 UINT32 AllocateDO_PWM();
47 void FreeDO_PWM(UINT32 pwmGenerator);
48 void SetDO_PWMRate(float rate);
49 void SetDO_PWMDutyCycle(UINT32 pwmGenerator, float dutyCycle);
50 void SetDO_PWMOutputChannel(UINT32 pwmGenerator, UINT32 channel);
51
52 I2C* GetI2C(UINT32 address);
53
54 static DigitalModule* GetInstance(UINT8 moduleNumber);
55 static UINT8 RemapDigitalChannel(UINT32 channel) { return 15 - channel; }; // TODO: Need channel validation
56 static UINT8 UnmapDigitalChannel(UINT32 channel) { return 15 - channel; }; // TODO: Need channel validation
57
58private:
59 SEM_ID m_digitalSemaphore;
60 SEM_ID m_relaySemaphore;
61 SEM_ID m_doPwmSemaphore;
62 tDIO *m_fpgaDIO;
63};
64
65#endif
66