1 // Copyright 2012 Emilie Gillet.
2 //
3 // Author: Emilie Gillet (emilie.o.gillet@gmail.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 //
23 // See http://creativecommons.org/licenses/MIT/ for more information.
24 //
25 // -----------------------------------------------------------------------------
26 //
27 // Driver for the debug (timing) pin.
28 
29 #ifndef ELEMENTS_DRIVERS_DEBUG_PIN_H_
30 #define ELEMENTS_DRIVERS_DEBUG_PIN_H_
31 
32 #include "stmlib/stmlib.h"
33 
34 #ifndef TEST
35 #include <stm32f4xx_conf.h>
36 #endif
37 
38 namespace elements {
39 
40 class DebugPin {
41  public:
DebugPin()42   DebugPin() { }
~DebugPin()43   ~DebugPin() { }
44 #ifdef TEST
Init()45   static void Init() { }
High()46   static void High() { }
Low()47   static void Low() { }
48 #else
Init()49   static void Init() {
50     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
51 
52     GPIO_InitTypeDef gpio_init;
53     gpio_init.GPIO_Pin = GPIO_Pin_9;
54     gpio_init.GPIO_Mode = GPIO_Mode_OUT;
55     gpio_init.GPIO_OType = GPIO_OType_PP;
56     gpio_init.GPIO_Speed = GPIO_Speed_25MHz;
57     gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
58     GPIO_Init(GPIOA, &gpio_init);
59   }
High()60   static inline void High() {
61     GPIOA->BSRRL = GPIO_Pin_9;
62   }
Low()63   static inline void Low() {
64     GPIOA->BSRRH = GPIO_Pin_9;
65   }
66 #endif
67  private:
68   DISALLOW_COPY_AND_ASSIGN(DebugPin);
69 };
70 
71 #define TIC DebugPin::High();
72 #define TOC DebugPin::Low();
73 
74 }  // namespace elements
75 
76 #endif  // ELEMENTS_DRIVERS_DEBUG_PIN_H_
77