103 lines
2.1 KiB
C++
103 lines
2.1 KiB
C++
|
|
/*
|
|||
|
|
* PinIOOverride.h
|
|||
|
|
*
|
|||
|
|
* Created on: 18 <EFBFBD><EFBFBD><EFBFBD>. 2019 <EFBFBD>.
|
|||
|
|
* Author: titov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef SOURCE_DRIVER_PINIOOVERRIDE_H_
|
|||
|
|
#define SOURCE_DRIVER_PINIOOVERRIDE_H_
|
|||
|
|
|
|||
|
|
#include "../peripheral/IGpioOverride.hh"
|
|||
|
|
|
|||
|
|
namespace driver {
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
class PinIOOverride : public peripheral::IGpioOverride {
|
|||
|
|
public:
|
|||
|
|
typedef unsigned short Id;
|
|||
|
|
|
|||
|
|
struct Input {
|
|||
|
|
PortType data;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
struct Output {
|
|||
|
|
PortType priority;
|
|||
|
|
PortType overriding;
|
|||
|
|
PortType data;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
PinIOOverride( Id id, bool priority, const volatile Input & input, volatile Output & output );
|
|||
|
|
|
|||
|
|
bool getOverrideStatus() const override;
|
|||
|
|
void setupOverride() override;
|
|||
|
|
void setOverrideValue(TOutValue value) override;
|
|||
|
|
bool getHidenValue() const override;
|
|||
|
|
void resetOverride() override;
|
|||
|
|
private:
|
|||
|
|
const volatile Input & input;
|
|||
|
|
volatile Output & output;
|
|||
|
|
|
|||
|
|
const PortType mask;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline driver::PinIOOverride<PortType>::PinIOOverride(
|
|||
|
|
Id id, bool priority, const volatile Input & input, volatile Output & output ) :
|
|||
|
|
input(input), output(output), mask( static_cast<PortType>(1) << id ) {
|
|||
|
|
|
|||
|
|
if( priority )
|
|||
|
|
output.priority |= mask;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline bool driver::PinIOOverride<PortType>::getOverrideStatus() const {
|
|||
|
|
|
|||
|
|
return output.overriding & mask;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline void driver::PinIOOverride<PortType>::setupOverride() {
|
|||
|
|
|
|||
|
|
output.data = input.data;
|
|||
|
|
output.overriding |= mask;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline void driver::PinIOOverride<PortType>::setOverrideValue(TOutValue value) {
|
|||
|
|
|
|||
|
|
switch(value) {
|
|||
|
|
case hi_z: {
|
|||
|
|
output.data = input.data;
|
|||
|
|
} break;
|
|||
|
|
case high: {
|
|||
|
|
output.data |= mask;
|
|||
|
|
} break;
|
|||
|
|
case low: {
|
|||
|
|
output.data &= ~mask;
|
|||
|
|
} break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline bool driver::PinIOOverride<PortType>::getHidenValue() const {
|
|||
|
|
|
|||
|
|
return input.data & mask;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
template<typename PortType>
|
|||
|
|
inline void driver::PinIOOverride<PortType>::resetOverride() {
|
|||
|
|
|
|||
|
|
output.overriding &= ~mask;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif /* SOURCE_DRIVER_PINIOOVERRIDE_H_ */
|