1 #include <fastgpioomega2.h>
3 FastGpioOmega2::FastGpioOmega2(void)
5 // setup the memory address space
6 _SetupAddress(REG_BLOCK_ADDR, REG_BLOCK_SIZE);
9 FastGpioOmega2::~FastGpioOmega2(void)
14 void FastGpioOmega2::setGpioOffset(int gpio){
18 this->ctrlOffset = REGISTER_CTRL0_OFFSET;
19 this->dataOffset = REGISTER_DATA0_OFFSET;
20 this->dataSetOffset = REGISTER_DSET0_OFFSET;
21 this->dataClrOffset = REGISTER_DCLR0_OFFSET;
24 this->ctrlOffset = REGISTER_CTRL1_OFFSET;
25 this->dataOffset = REGISTER_DATA1_OFFSET;
26 this->dataSetOffset = REGISTER_DSET1_OFFSET;
27 this->dataClrOffset = REGISTER_DCLR1_OFFSET;
29 this->ctrlOffset = REGISTER_CTRL2_OFFSET;
30 this->dataOffset = REGISTER_DATA2_OFFSET;
31 this->dataSetOffset = REGISTER_DSET2_OFFSET;
32 this->dataClrOffset = REGISTER_DCLR2_OFFSET;
36 int FastGpioOmega2::SetDirection(int pinNum, int bOutput)
38 unsigned long int regVal;
39 setGpioOffset(pinNum);
42 // read the current input and output settings
43 regVal = _ReadReg(ctrlOffset);
44 if (verbosityLevel > 0) printf("Direction setting read: 0x%08lx\n", regVal);
46 // set the OE for this pin
47 _SetBit(regVal, gpio, bOutput);
48 if (verbosityLevel > 0) printf("Direction setting write: 0x%08lx\n", regVal);
50 // write the new register value
51 _WriteReg(ctrlOffset, regVal);
54 return (EXIT_SUCCESS);
57 int FastGpioOmega2::GetDirection(int pinNum, int &bOutput)
59 unsigned long int regVal;
60 setGpioOffset(pinNum);
63 // read the current input and output settings
64 regVal = _ReadReg(ctrlOffset);
65 if (verbosityLevel > 0) printf("Direction setting read: 0x%08lx\n", regVal);
67 bOutput = _GetBit(regVal, gpio);
69 return (EXIT_SUCCESS);
72 int FastGpioOmega2::Set(int pinNum, int value)
74 unsigned long int regAddr;
75 unsigned long int regVal;
76 setGpioOffset(pinNum);
81 // write to the clear register
82 regAddr = dataClrOffset;
85 // write to the set register
86 regAddr = dataSetOffset;
89 // put the desired pin value into the register
90 regVal = (0x1 << gpio);
92 // write to the register
93 _WriteReg (regAddr, regVal);
98 int FastGpioOmega2::Read(int pinNum, int &value)
100 unsigned long int regVal;
101 setGpioOffset(pinNum);
104 // read the current value of all pins
105 regVal = _ReadReg (dataOffset);
107 // find the value of the specified pin
108 value = _GetBit(regVal, gpio);
113 unsigned long int FastGpioOmega2::ReadFull(int pinNum, int &value)
115 unsigned long int regVal;
116 setGpioOffset(pinNum);
119 // read the current value of all pins
120 regVal = _ReadReg (dataOffset);