1 #include <fastgpioomega.h>
3 FastGpioOmega::FastGpioOmega(void)
5 // setup the memory address space
6 _SetupAddress(REGISTER_BLOCK_ADDR, REGISTER_BLOCK_SIZE);
9 FastGpioOmega::~FastGpioOmega(void)
15 int FastGpioOmega::SetDirection(int pinNum, int bOutput)
17 unsigned long int regVal;
19 // read the current input and output settings
20 regVal = _ReadReg(REGISTER_OE_OFFSET);
21 if (verbosityLevel > 0) printf("Direction setting read: 0x%08lx\n", regVal);
23 // set the OE for this pin
24 _SetBit(regVal, pinNum, bOutput);
25 if (verbosityLevel > 0) printf("Direction setting write: 0x%08lx\n", regVal);
27 // write the new register value
28 _WriteReg(REGISTER_OE_OFFSET, regVal);
31 return (EXIT_SUCCESS);
34 int FastGpioOmega::GetDirection(int pinNum, int &bOutput)
36 unsigned long int regVal;
38 // read the current input and output settings
39 regVal = _ReadReg(REGISTER_OE_OFFSET);
40 if (verbosityLevel > 0) printf("Direction setting read: 0x%08lx\n", regVal);
42 // find the OE for this pin
43 bOutput = _GetBit(regVal, pinNum);
46 return (EXIT_SUCCESS);
49 int FastGpioOmega::Set(int pinNum, int value)
51 unsigned long int regAddr;
52 unsigned long int regVal;
55 // write to the clear register
56 regAddr = REGISTER_CLEAR_OFFSET;
59 // write to the set register
60 regAddr = REGISTER_SET_OFFSET;
63 // put the desired pin value into the register
64 regVal = (0x1 << pinNum);
66 // write to the register
67 _WriteReg (regAddr, regVal);
73 int FastGpioOmega::Read(int pinNum, int &value)
75 unsigned long int regVal;
77 // read the current value of all pins
78 regVal = _ReadReg (REGISTER_IN_OFFSET);
80 // find the value of the specified pin
81 value = _GetBit(regVal, pinNum);
87 unsigned long int FastGpioOmega::ReadFull(int pinNum, int &value)
89 unsigned long int regVal;
90 // read the current value of all pins
91 regVal = _ReadReg (REGISTER_IN_OFFSET);
93 // find the value of the specified pin
94 value = _GetBit(regVal, pinNum);