embkernel
 All Classes Functions Variables Typedefs Groups Pages
DrvGpio.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef DRV_GPIO_HPP_
7 #define DRV_GPIO_HPP_
8 
9 #include "DrvTypes.hpp"
10 #include "stm32f4xx.h"
11 
12 class DrvGpio {
13 public:
14 
15  //Generic functions
16  void init(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd =
17  DrvTypes::PUPD_NONE);
18  void setPinFuncMode(DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd = DrvTypes::PUPD_NONE);
19  inline operator bool() {
20  return ((mGpio->IDR & mPinMask) != 0) ? true : false;
21  }
22  inline bool operator =(bool state) {
23  volatile uint32_t* bsrr = (uint32_t*) &mGpio->BSRRL;
24  if (state) {
25  *bsrr = mPinMask;
26  }
27  else {
28  *bsrr = mPinMask << 16;
29  }
30  return state;
31  }
32  static void setPinFuncMode(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_FUNCTION func, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd =
33  DrvTypes::PUPD_NONE);
34 
35 private:
36  DrvTypes::PORT mPort;
37  DrvTypes::PIN mPin;
38  GPIO_TypeDef* mGpio;
39  uint32_t mPinMask;
40 };
41 
42 #endif /* DRV_GPIO_HPP_ */