-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCardI2CX.h
177 lines (152 loc) · 4.06 KB
/
CCardI2CX.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef __CCARDI2CX_HH__
#define __CCARDI2CX_HH__
#include <time.h>
#include <Gpio.h>
#include "DsaController.h"
#include "DsaI2CPortState.h"
namespace IrvCS
{
typedef enum {
RegInput=0x00,
RegOutput=0x01,
RegPolarity=0x02,
RegConfig=0x03
} RegisterType;
/**
* Manage I2C expander state. @see https://www.kernel.org/doc/Documentation/i2c/dev-interface
**/
class CCardI2CX:public DsaController
{
public:
/**
* Initialize the I2C expander state
**/
CCardI2CX();
~CCardI2CX();
//
// DsaController interface methods
//
/**
* Perform the specified DSA operation.
* @param id the id of the DSA
* @param cmd the command to perform (Release or Deploy)
* @param timeoutSec the timeout in seconds
* @return the current register value (>=0) if successful
* @return OpStatus (<0)
*/
OpStatus performDsaOperation(DsaId id, DsaCmd cmd, int timeoutSec);
/**
* Get the sensor status for the given DSA/Cmd
*
* @param id the id of the DSA
* @param cmd the command to perform (Release or Deploy)
* @return 0 if off
* @return 1 if on
* @return <0 if error
**/
int getSensorStatus(DsaId id, DsaCmd cmd);
//
// lower level methods not for CCardCtl use only
//
/**
* Turn on or off the 3V payload power
* @param onOrOff 1 or 0
* @return 0 if successful
* @return <0 if failed
**/
int setPayloadPower(Gpio &pwrGpio, uint8_t onOrOff);
/**
* Set the state directly
* @return 0 if successful,
* @return < 0 if error
**/
int setState(uint8_t state);
/**
* Get the specified register
* @return register value or -1 for error
*
**/
int getRegister(const RegisterType regType);
/**
* Get the state
* @return 0 if successful,
* @return < 0 if error
**/
int getState(uint8_t &state);
/**
* Get the DSA deploy state.
* Use the lower 4 bits to represent DSA1 Release/Deploy state and
* the DSA2 Release/Deploy states. Use the upper 4 bits to flag error bits.
* @return the dsa deploy state in the lower 4 bits
* @return <0 if error
**/
uint8_t getDsaDeployState();
/**
* Get the current controller states
* @param portState the state of the I2C register 1
* @param deployState the deployment states
**/
int8_t getStates(uint8_t &portState, uint8_t &deployState);
/**
* Determine if our expander is ok.
**/
bool isOk();
/**
* Perform operation for DSA with given timeout
* @param id the id of the DSA
* @param cmd the command to perform
* @param timeoutSec the timeout in seconds
* @return the current register value (>=0) if successful
* @return OpStatus (<0)
**/
int dsaPerform(DsaId id, DsaCmd cmd, int timeoutSec=5);
/**
* Perform operation for MT
* @return OpStatus
**/
int mtPerform(uint8_t idBits, uint8_t cmd);
/**
* Check to see if there is any activity within a time interval.
* Switch to lower power mode if no activity.
* @return 0 if no change in state
* @return 1 if system has switched to idle mode
* @return -1 error encountered
**/
int idleCheck();
private:
/**
* Get the sensor status the DSA sensors
*
* @return status bits
* @return <0 if error
**/
int getSensorStatusBits();
/**
* Reset state to initial conditions
**/
int reset();
/**
* Set the state directly with no power on call
* @return 0 if successful,
* @return < 0 if error
**/
int setI2Cstate(uint8_t state);
int initGpios();
/**
* Power on if needed and reset state
* @return 0 if power is on
* @return <1 if errors encountered
**/
int powerOn();
bool isPoweredOn_;
time_t pwrTimestamp_;
DsaI2CPortState portState_;
int i2cdev_;
int addr_;
bool initialized_;
Gpio pl3VGpio_;
Gpio pl5VGpio_;
uint8_t dsaSenseBits_;
};
}
#endif