pins.h
Go to the documentation of this file.
1 /*
2  * KubOS HAL
3  * Copyright (C) 2016 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
22 #ifndef KUBOS_HAL_STM32F4_PINS_H
23 #define KUBOS_HAL_STM32F4_PINS_H
24 
25 #include "stm32f4xx.h"
26 #include "stm32f4xx_hal_gpio.h"
27 
28 #define K_NUM_PINS (16 * 5)
29 
30 #define K_LED_GREEN K_LED_0
31 #define K_LED_0 YOTTA_CFG_HARDWARE_PINS_LED1
32 
33 #define K_LED_ORANGE K_LED_1
34 #define K_LED_1 YOTTA_CFG_HARDWARE_PINS_LED2
35 
36 #define K_LED_RED K_LED_2
37 #define K_LED_2 YOTTA_CFG_HARDWARE_PINS_LED3
38 
39 #define K_LED_BLUE K_LED_3
40 #define K_LED_3 YOTTA_CFG_HARDWARE_PINS_LED4
41 
42 #define K_LED_COUNT 4
43 
44 #define K_BUTTON_0 YOTTA_CFG_HARDWARE_PINS_USER_BUTTON
45 
46 #define STM32F4_PIN_OFFSET(p) ((p) % 16)
47 #define STM32F4_PIN_MASK(p) (1 << STM32F4_PIN_OFFSET(p))
48 #define STM32F4_PIN_GPIO(p) ((GPIO_TypeDef *) (GPIOA_BASE + (((p) / 16) * 0x400)))
49 #define STM32F4_PIN_AHB1ENR_BIT(p) (1 << ((p) / 16))
50 
51 #define CHECK_BIT(src, bit) (READ_BIT((src), (bit)) == (bit))
52 #define CHECK_SET_BIT(dest, bit) do { \
53  uint32_t tmpreg = READ_BIT(dest, bit); \
54  if (!tmpreg) { \
55  SET_BIT(dest, bit); \
56  /* Delay after an RCC peripheral clock enabling */ \
57  tmpreg = READ_BIT(dest, bit);\
58  } \
59 } while(0)
60 
61 typedef struct {
62  GPIO_TypeDef *gpio;
63  uint16_t pin;
64  uint32_t ahb1enr_bit;
65 } KPinDesc;
66 
67 typedef enum {
68  PA0 = 0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15,
73 } KPin;
74 
75 
76 
77 #endif
78 /* @} */
Definition: pins.h:72
Definition: pins.h:68
Definition: pins.h:70
uint16_t pin
Definition: pins.h:63
Definition: pins.h:70
Definition: pins.h:69
Definition: pins.h:70
Definition: pins.h:68
Definition: pins.h:72
Definition: pins.h:71
Definition: pins.h:72
Definition: pins.h:68
Definition: pins.h:69
Definition: pins.h:68
Definition: pins.h:71
Definition: pins.h:72
Definition: pins.h:68
Definition: pins.h:69
Definition: pins.h:71
Definition: pins.h:61
Definition: pins.h:72
Definition: pins.h:69
Definition: pins.h:72
Definition: pins.h:71
GPIO_TypeDef * gpio
Definition: pins.h:62
Definition: pins.h:71
Definition: pins.h:70
Definition: pins.h:70
Definition: pins.h:70
Definition: pins.h:72
Definition: pins.h:69
Definition: pins.h:69
Definition: pins.h:72
Definition: pins.h:70
Definition: pins.h:72
Definition: pins.h:69
Definition: pins.h:71
Definition: pins.h:68
Definition: pins.h:70
Definition: pins.h:69
Definition: pins.h:69
Definition: pins.h:71
Definition: pins.h:72
Definition: pins.h:72
Definition: pins.h:68
Definition: pins.h:70
Definition: pins.h:68
Definition: pins.h:71
Definition: pins.h:70
Definition: pins.h:69
Definition: pins.h:68
Definition: pins.h:71
Definition: pins.h:68
Definition: pins.h:69
Definition: pins.h:68
Definition: pins.h:71
Definition: pins.h:69
KPin
Definition: pins.h:67
Definition: pins.h:70
Definition: pins.h:71
Definition: pins.h:71
Definition: pins.h:71
Definition: pins.h:71
Definition: pins.h:72
Definition: pins.h:70
Definition: pins.h:71
Definition: pins.h:69
uint32_t ahb1enr_bit
Definition: pins.h:64
Definition: pins.h:68
Definition: pins.h:69
Definition: pins.h:70
Definition: pins.h:68
Definition: pins.h:70
Definition: pins.h:69
Definition: pins.h:68
Definition: pins.h:70
Definition: pins.h:72
Definition: pins.h:72
Definition: pins.h:72
Definition: pins.h:71
Definition: pins.h:68
Definition: pins.h:70
Definition: pins.h:68
Definition: pins.h:72
Definition: pins.h:69