Skip to content

Instantly share code, notes, and snippets.

@Tosainu
Created August 19, 2016 07:46
Show Gist options
  • Save Tosainu/e2ca2af168754729a4c8de606b538d46 to your computer and use it in GitHub Desktop.
Save Tosainu/e2ca2af168754729a4c8de606b538d46 to your computer and use it in GitHub Desktop.
#include <cstdint>
template <class Address, class Register, Address address>
struct reg_t {
static inline void write(Register value) {
*reinterpret_cast<volatile Address*>(address) = value;
}
static inline Register read() {
return *reinterpret_cast<volatile Address*>(address);
}
};
template <uint32_t address>
using reg32_t = reg_t<uint32_t, uint32_t, address>;
using GPFSEL1 = reg32_t<0x20200004>;
using GPSET0 = reg32_t<0x2020001c>;
auto main() -> int {
// GPIO18の動作モードをOutputにする
GPFSEL1::write(1 << (3 * 8));
// GPIO18をHighにする
GPSET0::write(1 << 18);
while (1) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment