Mercurial > pub > halpp
comparison l476rg-hal-test/src/main.cpp @ 2:0c59e7a7782a
Working on GPIO and RCC
author | cin |
---|---|
date | Mon, 16 Jan 2017 11:04:47 +0300 |
parents | a0b14b11ad9f |
children | 3d9705e842f8 |
comparison
equal
deleted
inserted
replaced
1:a0b14b11ad9f | 2:0c59e7a7782a |
---|---|
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 File: main.c | 3 File: main.c |
4 Info: Generated by Atollic TrueSTUDIO(R) 7.0.1 2017-01-12 | 4 Info: Generated by Atollic TrueSTUDIO(R) 7.0.1 2017-01-12 |
5 | 5 |
6 The MIT License (MIT) | 6 The MIT License (MIT) |
7 Copyright (c) 2009-2016 Atollic AB | 7 Copyright (c) 2009-2016 Atollic AB |
8 | 8 |
9 Permission is hereby granted, free of charge, to any person obtaining a copy | 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 | 10 of this software and associated documentation files (the "Software"), to deal |
11 in the Software without restriction, including without limitation the rights | 11 in the Software without restriction, including without limitation the rights |
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 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 | 13 copies of the Software, and to permit persons to whom the Software is |
14 furnished to do so, subject to the following conditions: | 14 furnished to do so, subject to the following conditions: |
15 | 15 |
16 The above copyright notice and this permission notice shall be included in all | 16 The above copyright notice and this permission notice shall be included in all |
17 copies or substantial portions of the Software. | 17 copies or substantial portions of the Software. |
18 | 18 |
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 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, | 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 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 | 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, | 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 | 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
25 SOFTWARE. | 25 SOFTWARE. |
26 ****************************************************************************** | 26 ****************************************************************************** |
27 */ | 27 */ |
28 | 28 |
29 /* Includes */ | 29 /* Includes */ |
30 #include "stm32l4xx.h" | 30 #include "stm32l4xx.h" |
31 #include "msp.h" | 31 #include "gpio.h" |
32 | 32 |
33 /* Private macro */ | 33 /* Private macro */ |
34 /* Private variables */ | 34 /* Private variables */ |
35 /* Private function prototypes */ | 35 /* Private function prototypes */ |
36 /* Private functions */ | 36 /* Private functions */ |
37 | 37 |
38 /** | 38 /** |
39 **=========================================================================== | 39 **=========================================================================== |
40 ** | 40 ** |
41 ** Abstract: main program | 41 ** Abstract: main program |
42 ** | 42 ** |
43 **=========================================================================== | 43 **=========================================================================== |
44 */ | 44 */ |
45 int main(void) | |
46 { | |
47 int i = 0; | |
48 | 45 |
49 /** | 46 using namespace halpp; |
50 * IMPORTANT NOTE! | |
51 * The symbol VECT_TAB_SRAM needs to be defined when building the project | |
52 * if code has been located to RAM and interrupts are used. | |
53 * Otherwise the interrupt table located in flash will be used. | |
54 * See also the <system_*.c> file and how the SystemInit() function updates | |
55 * SCB->VTOR register. | |
56 * E.g. SCB->VTOR = 0x20000000; | |
57 */ | |
58 | 47 |
59 /* TODO - Add your application code here */ | 48 template<typename TDev, unsigned short PIN> class TLed { |
49 TDev& m_dev; | |
50 public: | |
51 TLed(TDev& dev) : | |
52 m_dev(dev) { | |
60 | 53 |
61 /* Infinite loop */ | 54 } |
62 while (1) | 55 |
63 { | 56 void Init() const { |
64 Hardware::pwm1.SetPulse(150); | 57 m_dev.SetPinMode(5, halpp::GpioModeOutput); |
65 i++; | 58 m_dev.SetPinOutputType(5, halpp::GpioOutputType::GpioPushPull); |
66 } | 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 }; | |
81 | |
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) { | |
106 | |
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 */ | |
118 | |
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 } | |
67 } | 131 } |