0
|
1 /*
|
2
|
2 ******************************************************************************
|
|
3 File: main.c
|
|
4 Info: Generated by Atollic TrueSTUDIO(R) 7.0.1 2017-01-12
|
0
|
5
|
2
|
6 The MIT License (MIT)
|
|
7 Copyright (c) 2009-2016 Atollic AB
|
0
|
8
|
2
|
9 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10 of this software and associated documentation files (the "Software"), to deal
|
|
11 in the Software without restriction, including without limitation the rights
|
|
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13 copies of the Software, and to permit persons to whom the Software is
|
|
14 furnished to do so, subject to the following conditions:
|
0
|
15
|
2
|
16 The above copyright notice and this permission notice shall be included in all
|
|
17 copies or substantial portions of the Software.
|
0
|
18
|
2
|
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25 SOFTWARE.
|
|
26 ******************************************************************************
|
|
27 */
|
0
|
28
|
|
29 /* Includes */
|
|
30 #include "stm32l4xx.h"
|
2
|
31 #include "gpio.h"
|
0
|
32
|
|
33 /* Private macro */
|
|
34 /* Private variables */
|
|
35 /* Private function prototypes */
|
|
36 /* Private functions */
|
|
37
|
|
38 /**
|
2
|
39 **===========================================================================
|
|
40 **
|
|
41 ** Abstract: main program
|
|
42 **
|
|
43 **===========================================================================
|
|
44 */
|
|
45
|
|
46 using namespace halpp;
|
|
47
|
|
48 template<typename TDev, unsigned short PIN> class TLed {
|
|
49 TDev& m_dev;
|
|
50 public:
|
|
51 TLed(TDev& dev) :
|
|
52 m_dev(dev) {
|
|
53
|
|
54 }
|
|
55
|
|
56 void Init() const {
|
|
57 m_dev.SetPinMode(5, halpp::GpioModeOutput);
|
|
58 m_dev.SetPinOutputType(5, halpp::GpioOutputType::GpioPushPull);
|
|
59 m_dev.SetPinPullMode(5, halpp::GpioPullMode::GpioNoPull);
|
|
60 }
|
|
61
|
|
62 void Set() const {
|
|
63 m_dev.WritePin(PIN, 1);
|
|
64 }
|
|
65
|
|
66 void Reset() const {
|
|
67 m_dev.WritePin(PIN, 0);
|
|
68 }
|
|
69
|
|
70 void Toogle() const {
|
|
71 m_dev.TooglePin(PIN);
|
|
72 }
|
|
73 };
|
|
74
|
|
75 class AHB2Bus {
|
|
76 public:
|
|
77 static void Enable(unsigned int flag) {
|
|
78 RCC->AHB2ENR |= flag;
|
|
79 }
|
|
80 };
|
0
|
81
|
2
|
82 template<typename TBus, unsigned short ENF> class TDevice {
|
|
83 public:
|
|
84 static void Enable() {
|
|
85 TBus::Enable(ENF);
|
|
86 }
|
|
87 };
|
|
88
|
|
89 class GpioA : public TGpio<GPIO_TypeDef>, public TDevice<AHB2Bus, RCC_AHB2ENR_GPIOAEN> {
|
|
90 static GpioA m_instance;
|
|
91 typedef TGpio<GPIO_TypeDef> GpioBase;
|
|
92 public:
|
|
93
|
|
94 GpioA(GPIO_TypeDef& dev) : GpioBase(dev) {
|
|
95
|
|
96 }
|
|
97
|
|
98 static GpioA& instance() {
|
|
99 return m_instance;
|
|
100 }
|
|
101 };
|
|
102
|
|
103 GpioA GpioA::m_instance(*GPIOA);
|
|
104
|
|
105 int main(void) {
|
0
|
106
|
2
|
107 /**
|
|
108 * IMPORTANT NOTE!
|
|
109 * The symbol VECT_TAB_SRAM needs to be defined when building the project
|
|
110 * if code has been located to RAM and interrupts are used.
|
|
111 * Otherwise the interrupt table located in flash will be used.
|
|
112 * See also the <system_*.c> file and how the SystemInit() function updates
|
|
113 * SCB->VTOR register.
|
|
114 * E.g. SCB->VTOR = 0x20000000;
|
|
115 */
|
|
116
|
|
117 /* TODO - Add your application code here */
|
0
|
118
|
2
|
119 GpioA::Enable();
|
|
120
|
|
121 TLed<halpp::TGpio<GPIO_TypeDef>, 5> led1(GpioA::instance());
|
|
122 led1.Init();
|
|
123
|
|
124 /* Infinite loop */
|
|
125 while (1) {
|
|
126 led1.Toogle();
|
|
127
|
|
128 for (int i = 0; i < 1000000; i++) {
|
|
129 }
|
|
130 }
|
0
|
131 }
|