Created
August 19, 2016 07:46
-
-
Save Tosainu/e2ca2af168754729a4c8de606b538d46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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