Advertisement
Guest User

Lee Richmond

a guest
Dec 25th, 2009
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. template<unsigned int P, unsigned char N, bool = N >= 8>
  2. struct GpioMode
  3. {
  4.   inline static void mode(Mode::Mode_ m)
  5.   {
  6.     reinterpret_cast<GPIO_TypeDef*>(P)->CRH &= ~(0xf<<((N-8)*4));
  7.     reinterpret_cast<GPIO_TypeDef*>(P)->CRH |= m<<((N-8)*4);
  8.   }
  9. };
  10.  
  11. template<unsigned int P, unsigned char N>
  12. struct GpioMode<P, N, false>
  13. {
  14.   inline static void mode(Mode::Mode_ m)
  15.   {
  16.     reinterpret_cast<GPIO_TypeDef*>(P)->CRL &= ~(0xf<<(N*4));
  17.     reinterpret_cast<GPIO_TypeDef*>(P)->CRL |= m<<(N*4);
  18.   }
  19. };
  20.  
  21. template<unsigned int P, unsigned char N>
  22. class Gpio
  23. {
  24. public:
  25.   static void mode(Mode::Mode_ m)
  26.   {
  27.     GpioMode<P, N>::mode(m);
  28.   }
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement