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 "stm32f10x.h"
11 
12 class DrvGpio {
13 public:
14 
15  //Generic functions
16  void init(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd = DrvTypes::PUPD_NONE);
17  void setPinFuncMode(DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd = DrvTypes::PUPD_NONE);
18  inline operator bool() {
19  return ((mGpio->IDR & mPinMask) != 0) ? true : false;
20  }
21  inline bool operator =(bool state) {
22  if (state) {
23  mGpio->BSRR = mPinMask;
24  }
25  else {
26  mGpio->BRR = mPinMask;
27  }
28  return state;
29  }
30  static void setPinFuncMode(DrvTypes::PORT port, DrvTypes::PIN pin, DrvTypes::GPIO_MODE mode, DrvTypes::GPIO_PUPD pupd = DrvTypes::PUPD_NONE);
31 
32 private:
33  DrvTypes::PORT mPort;
34  DrvTypes::PIN mPin;
35  GPIO_TypeDef* mGpio;
36  uint32_t mPinMask;
37 };
38 
39 #endif /* DRV_GPIO_HPP_ */