Skip to content

Instantly share code, notes, and snippets.

@NewProggie
Created June 18, 2016 19:06
Show Gist options
  • Save NewProggie/0e9fe3204f7bd7eebe9a54d6adb763cb to your computer and use it in GitHub Desktop.
Save NewProggie/0e9fe3204f7bd7eebe9a54d6adb763cb to your computer and use it in GitHub Desktop.
#include <cstdint>
class Device {
public:
Device() {}
bool write8(uint8_t page, uint8_t addr, uint8_t v) {
return true;
}
bool write16(uint8_t page, uint8_t addr, uint16_t v) {
return true;
}
};
struct Registers {
union Control {
enum { PAGE = 0x16, ADDRESS = 0x17 };
struct OPM {
enum { NO_CHANGE = 0, AS_STANDBY = 1 };
};
struct Bits {
uint16_t OPM : 2;
uint16_t CTRL_BR1 : 2;
uint16_t CTRL_BR2 : 2;
} bits;
uint16_t raw;
Control(uint16_t v = 0x00) : raw(v) {}
};
};
int main() {
Registers::Control r;
r.bits.OPM = Registers::Control::OPM::AS_STANDBY;
Device device;
device.write16(Registers::Control::PAGE, Registers::Control::ADDRESS,
r.raw);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment