annotate l476rg-hal-test/src/main.cpp @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0d3eea2dd7ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1 /*
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
3 File: main.c
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
4 Info: Generated by Atollic TrueSTUDIO(R) 7.0.1 2017-01-12
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
5
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
6 The MIT License (MIT)
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
7 Copyright (c) 2009-2016 Atollic AB
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
8
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
9 Permission is hereby granted, free of charge, to any person obtaining a copy
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
10 of this software and associated documentation files (the "Software"), to deal
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
11 in the Software without restriction, including without limitation the rights
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
13 copies of the Software, and to permit persons to whom the Software is
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
14 furnished to do so, subject to the following conditions:
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
15
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
16 The above copyright notice and this permission notice shall be included in all
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
17 copies or substantial portions of the Software.
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
18
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
25 SOFTWARE.
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
26 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
27 */
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
28
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
29 /* Includes */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
30 #include "stm32l4xx.h"
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
31 #include "gpio.h"
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
32
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
33 /* Private macro */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
34 /* Private variables */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
35 /* Private function prototypes */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
36 /* Private functions */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
37
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
38 /**
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
39 **===========================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
40 **
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
41 ** Abstract: main program
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
42 **
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
43 **===========================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
44 */
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
45
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
46 using namespace halpp;
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
47
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
48 template<typename TDev, typename TCounter = uint32_t> class TTimerBase {
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
49 public:
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
50 typedef TCounter counter_t;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
51
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
52 static void init() {
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
53 TDev::instance()->EGR = TIM_EGR_UG;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
54 }
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
55
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
56 static void period(counter_t value) {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
57 TDev::instance()->ARR = value;
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
58 }
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
59
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
60 static counter_t period() {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
61 return (counter_t) TDev::instance()->ARR;
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
62 }
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
63
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
64 static void prescaler(counter_t value) {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
65 TDev::instance()->PSC = value;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
66 }
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
67
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
68 static counter_t prescaler() {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
69 return TDev::instance()->PSC;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
70 }
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
71
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
72 static uint32_t resolution() {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
73 return TDev::frequency() / prescaler();
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
74 }
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
75 };
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
76
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
77 template<typename TDev, typename TCounter = uint32_t> class TTimerChannel1 {
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
78 public:
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
79 typedef TCounter counter_t;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
80 static void duty(counter_t value) {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
81 TDev::instance()->CCR1 = (uint32_t)value;
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
82 }
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
83
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
84 static counter_t duty() {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
85 return (counter_t)TDev::instance()->CCR1;
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
86 }
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
87 };
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
88
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
89 template<typename TDev, unsigned short PIN, typename TTraits = TGpioTraits<TDev> > class TLed {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
90 TLed();
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
91 explicit TLed(const TLed&);
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
92 public:
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
93 static void Init() {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
94 TTraits::SetPinMode(PIN, GpioModeOutput);
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
95 TTraits::SetPinOutputType(PIN, GpioPushPull);
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
96 TTraits::SetPinPullMode(PIN, GpioNoPull);
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
97 }
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
98
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
99 static void Set() {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
100 TTraits::WritePin(PIN, 1);
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
101 }
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
102
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
103 static void Reset() {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
104 TTraits::WritePin(PIN, 0);
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
105 }
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
106
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
107 static void Toogle() {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
108 TTraits::TooglePin(PIN);
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
109 }
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
110 };
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
111
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
112 class AHB2Bus {
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
113 public:
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
114 static void enable(unsigned int flag) {
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
115 RCC->AHB2ENR |= flag;
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
116 }
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
117
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
118 static uint32_t clock() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
119
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
120 }
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
121 };
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
122
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
123 class APB1Bus {
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
124 public:
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
125 static void enable(unsigned int flag) {
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
126 RCC->APB1ENR1 |= flag;
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
127 }
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
128 };
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
129
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
130 class APB1Bus2 {
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
131 static void enable(uint32_t flag) {
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
132 RCC->APB1ENR2 |= flag;
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
133 }
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
134 };
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
135
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
136 template <typename TRegs, typename TBus, uint32_t BASE, uint32_t ENF> class TDevice {
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
137 public:
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
138 typedef TBus bus_t;
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
139
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
140 static TRegs* instance() {
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
141 return (TRegs*) BASE;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
142 }
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
143
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
144 static void enable() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
145 TBus::enable(ENF);
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
146 }
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
147
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
148 static uint32_t frequency() {
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
149 return 80000000;
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
150 }
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
151 };
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
152
6
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
153 class OscMsi {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
154 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
155
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
156 class OscHsi {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
157 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
158
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
159 class OscHse {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
160 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
161
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
162 class OscLsi {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
163 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
164
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
165 class OscLse {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
166 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
167
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
168 class Pll {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
169 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
170
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
171 class Pclk1 {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
172 public:
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
173 uint32_t clock() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
174 return APB1Bus::clock();
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
175 }
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
176 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
177
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
178 class Rcc {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
179 public:
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
180 typedef enum {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
181 PClk1,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
182 Apb1TimerClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
183 PClk2,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
184 Apb2TimerClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
185 HClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
186 SysClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
187 HsiClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
188 HseClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
189 LsiClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
190 LseClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
191 MsiClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
192 PllClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
193 PllQClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
194 PllPClk,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
195 PllSai1P,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
196 PllSai1Q,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
197 PllSai1R,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
198 PllSai2P,
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
199 PllSai2R
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
200 } ClockSource;
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
201
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
202 template <ClockSource clk> unit32_t clock();
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
203 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
204
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
205 class SysClk {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
206 public:
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
207 uint32_t clock() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
208 }
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
209 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
210
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
211 class UartClockMux {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
212 public:
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
213 template <typename TClk> void select_clock_source();
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
214 };
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
215
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
216 template<> void UartClockMux::select_clock_source<Pclk1>() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
217 }
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
218
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
219 template<> void UartClockMux::select_clock_source<SysClk>() {
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
220 }
ca42336826bd working on clock sources
cin
parents: 5
diff changeset
221
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
222 class Hardware {
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
223 public:
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
224 typedef TDevice<GPIO_TypeDef, GPIOA_BASE, AHB2Bus, RCC_AHB2ENR_GPIOAEN> GpioA;
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
225 typedef TDevice<TIM_TypeDef, TIM3_BASE, APB1Bus, RCC_APB1ENR1_TIM3EN> Tim3;
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
226
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
227 typedef TLed<GpioA, 5> GreenLed;
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
228 typedef TLed<GpioA, 6> Led2;
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
229 typedef TPwmOut<GpioA, 7, Tim3, 2> PwmLed3;
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
230 };
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
231
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
232 int main(void) {
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
233
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
234 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
235 * IMPORTANT NOTE!
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
236 * The symbol VECT_TAB_SRAM needs to be defined when building the project
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
237 * if code has been located to RAM and interrupts are used.
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
238 * Otherwise the interrupt table located in flash will be used.
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
239 * See also the <system_*.c> file and how the SystemInit() function updates
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
240 * SCB->VTOR register.
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
241 * E.g. SCB->VTOR = 0x20000000;
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
242 */
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
243
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
244 /* TODO - Add your application code here */
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
245
3
3d9705e842f8 working on rcc and bus
cin
parents: 2
diff changeset
246 Hardware::GpioA::Enable();
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
247 Hardware::Tim3::Enable();
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
248 Hardware::GreenLed::Init();
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
249 Hardware::Led2::Init();
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
250 Hardware::PwmLed3::Init(1000);
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
251
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
252 int ii = 0;
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
253 /* Infinite loop */
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
254 while (1) {
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
255 Hardware::GreenLed::Toogle();
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
256 Hardware::Led2::Toogle();
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
257
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
258 Hardware::PwmLed3::SetDutyFactor(ii / 10.f);
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
259
5
0d3eea2dd7ea working on devices and timers
cin
parents: 4
diff changeset
260 ii = (ii + 1) % 11; // 0 .. 10
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
261
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
262 for (int i = 0; i < 1000000; i++) {
4
ca4f5b55b391 working on pwm
cin
parents: 3
diff changeset
263
2
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
264 }
0c59e7a7782a Working on GPIO and RCC
cin
parents: 1
diff changeset
265 }
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
266 }