#ifndef _DEVICE_HPP_ #define _DEVICE_HPP_ #include "../utils/BitField.hpp" #include #include class Device { public: Device(); void doSomething(); private: // // Register declarations // #ifdef EXAMPLE_CODE_FOR_REFERENCE union Control { struct OPM{ typedef Bits bits; enum { NO_CHANGE = 0, AS_STANDBY = 1}; }; struct CTRL_BR{ enum { NO_CHANGE = 0, BRANCH_NORMAL = 1}; }; struct CTRL_BR1 : CTRL_BR{ typedef Bits bits; }; struct CTRL_BR2 : CTRL_BR{ typedef Bits bits; }; union Bits { Control::OPM::bits OPM; Control::CTRL_BR1::bits CTRL_BR1; Control::CTRL_BR2::bits CTRL_BR2; } bits; uint16_t raw; }; #endif union Reg_Control { // bit 4 struct POWER_DEV{ typedef BitField Bits; enum{TURN_OFF = 0, TURN_ON = 1}; }; // bits 2-3 struct SPEED{ typedef BitField Bits; enum{STAND_STILL = 0, SLOW = 1, NORMAL = 2, FAST = 3}; }; union Bits{ Reg_Control::POWER_DEV::Bits POWER_DEV; Reg_Control::SPEED::Bits SPEED; } bits; // raw value. all bitfields will be "unified" here ;) uint8_t raw; // union Ctor with default value set to 0x00 Reg_Control(uint8_t v = 0x00) : raw(v) {} }; Reg_Control reg_control; }; #endif // _DEVICE_HPP_