OpenMPTL - STM32F10X
C++ Microprocessor Template Library
gpio.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 /*
22  * This program contains derivative representations of CMSIS System
23  * View Description (SVD) files, and is subject to the "End User
24  * License Agreement for STMicroelectronics" (see "STM_License.html"
25  * in the containing directory).
26  */
27 
28 #ifndef ARCH_REG_GPIO_HPP_INCLUDED
29 #define ARCH_REG_GPIO_HPP_INCLUDED
30 
31 #include <register.hpp>
32 
33 namespace mptl {
34 
35 /**
36  * General-purpose and alternate-function I/Os (GPIOs and AFIOs)
37  */
38 template< char port >
39 struct GPIO
40 {
41  static_assert((port >= 'A') && (port <= 'G'), "invalid index for register");
42 
43  static constexpr unsigned gpio_no = port - 'A';
44  static constexpr reg_addr_t base_addr = 0x40010800 + gpio_no * 0x0400;
45 
46  using CRL = reg< uint32_t, base_addr + 0x00, rw, 0x44444444 >; /**< Port configuration register low */
47  using CRH = reg< uint32_t, base_addr + 0x04, rw, 0x44444444 >; /**< Port configuration register high */
48  using IDR = reg< uint32_t, base_addr + 0x08, ro, 0x00000000 >; /**< Port input data register */
49  using ODR = reg< uint32_t, base_addr + 0x0c, rw, 0x00000000 >; /**< Port output data register */
50  using BSRR = reg< uint32_t, base_addr + 0x10, wo, 0x00000000 >; /**< Port bit set/reset register */
51  using BRR = reg< uint32_t, base_addr + 0x14, wo, 0x00000000 >; /**< Port bit reset register */
52  using LCKR = reg< uint32_t, base_addr + 0x18, rw, 0x00000000 >; /**< Port configuration lock register */
53 
54  /**
55  * GPIO port configuration register: returns CRL or CRH type dependent on pin_no.
56  *
57  * NOTE: this is not from the reference manual
58  */
59  template<unsigned pin_no>
60  struct CRx
61  : public std::conditional< (pin_no < 8), CRL, CRH >::type
62  {
63  using type = typename std::conditional< (pin_no < 8), CRL, CRH >::type;
64 
65  using CNF = regbits< type, (pin_no % 8) * 4 + 2, 2 >;
66  using MODE = regbits< type, (pin_no % 8) * 4 , 2 >;
67  };
68 };
69 
70 } // namespace mptl
71 
72 #endif // ARCH_REG_GPIO_HPP_INCLUDED
uintptr_t reg_addr_t
static constexpr reg_addr_t base_addr
Definition: gpio.hpp:44
static constexpr unsigned gpio_no
Definition: gpio.hpp:43
General-purpose and alternate-function I/Os (GPIOs and AFIOs)
Definition: gpio.hpp:39
GPIO port configuration register: returns CRL or CRH type dependent on pin_no.
Definition: gpio.hpp:60