LED clock
 All Files Functions Variables Macros Groups Pages
global.h
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
20 #pragma once
21 #include <libopencm3/stm32/gpio.h> // GPIO defines
22 #include <libopencm3/cm3/nvic.h> // interrupt defines
23 #include <libopencm3/stm32/exti.h> // external interrupt defines
24 
26 #define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
27 
31 #if defined(SYSTEM_BOARD)
32 /* on system board LED is on pin 11/PA1 */
33 #define LED_RCC RCC_GPIOA
34 #define LED_PORT GPIOA
35 #define LED_PIN GPIO1
36 #elif defined(BLUE_PILL)
37 /* on minimum system LED is on pin 2/PC13 */
38 #define LED_RCC RCC_GPIOC
39 #define LED_PORT GPIOC
40 #define LED_PIN GPIO13
41 #elif defined (MAPLE_MINI)
42 /* on maple mini LED is on pin 19/PB1 */
43 #define LED_RCC RCC_GPIOB
44 #define LED_PORT GPIOB
45 #define LED_PIN GPIO1
46 #endif
47 
52 #if defined(MAPLE_MINI)
53 /* on maple mini user button is on 32/PB8 */
54 #define BUTTON_RCC RCC_GPIOB
55 #define BUTTON_PORT GPIOB
56 #define BUTTON_PIN GPIO8
57 #define BUTTON_EXTI EXTI8
58 #define BUTTON_IRQ NVIC_EXTI9_5_IRQ
59 #define BUTTON_ISR exti9_5_isr
60 #endif
61 
64 inline void led_on(void)
65 {
66 #if defined(SYSTEM_BOARD) || defined(BLUE_PILL)
67  gpio_clear(LED_PORT, LED_PIN);
68 #elif defined(MAPLE_MINI)
69  gpio_set(LED_PORT, LED_PIN);
70 #endif
71 }
73 inline void led_off(void)
74 {
75 #if defined(SYSTEM_BOARD) || defined(BLUE_PILL)
76  gpio_set(LED_PORT, LED_PIN);
77 #elif defined(MAPLE_MINI)
78  gpio_clear(LED_PORT, LED_PIN);
79 #endif
80 }
82 inline void led_toggle(void)
83 {
84  gpio_toggle(LED_PORT, LED_PIN);
85 }
87 int _write(int file, char *ptr, int len);
93 char* b2s(uint32_t binary, uint8_t rjust);
94 
void led_off(void)
switch off board LED
Definition: global.h:73
int _write(int file, char *ptr, int len)
default printf output
Definition: main.c:113
void led_on(void)
switch on board LED
Definition: global.h:64
char * b2s(uint32_t binary, uint8_t rjust)
get binary representation of a number
Definition: main.c:132
void led_toggle(void)
toggle board LED
Definition: global.h:82