USB Device - Joystick/Mouse  1.0
hal.h
Go to the documentation of this file.
1 #ifndef _HAL_H_
2 #define _HAL_H_
3 
4 #include "stm32f4xx.h"
5 #include "stm32f4xx_conf.h"
6 
7 // definice vazby HW na timer 1ms
8 #define ARM_HW_TIMER_TIMx (TIM3)
9 #define ARM_HW_TIMER_TIMx_IRQ (TIM3_IRQn)
10 #define ARM_HW_TIMER_TIMx_RCC (RCC_APB1Periph_TIM3)
11 #define ARM_HW_TIMER_TIMx_IRQHandler (TIM3_IRQHandler)
12 
13 #define TRUE (0xFF)
14 #define FALSE (0x00)
15 #ifndef NULL
16  #define NULL (0x00)
17 #endif
18 
19 //=== USB ===================================================================================//
20 #define USB_AF ()
21 #define USB_ID_PORT (GPIOA)
22 #define USB_ID_PIN (GPIO_PinSource10)
23 #define USB_DP_PORT (GPIOA)
24 #define USB_DP_PIN (GPIO_PinSource12)
25 #define USB_DM_PORT (GPIOA)
26 #define USB_DM_PIN (GPIO_PinSource11)
27 #define USB_FS_PORT (GPIOA)
28 #define USB_FS_PIN (GPIO_PinSource9)
29 #define USB_PSO_PORT (GPIOH)
30 #define USB_PSO_PIN (GPIO_PinSource5)
31 #define USB_GPIO_CLK (RCC_AHB2Periph_OTG_FS)
32 #define USB_ALTERNATE_FNC (GPIO_AF_OTG1_FS)
33 
34 #define USB_OTG_FULL_SPEED (3)
35 #define DCFG_FRAME_INTERVAL (0)
36 #define USB_NUM_EP (4)
37 #define MAX_EPS (15) // + EP 0
38 
39 #define RX0_FIFO_SIZE 128
40 #define TX0_FIFO_SIZE 64
41 #define TX1_FIFO_SIZE 128
42 #define TX2_FIFO_SIZE 0
43 #define TX3_FIFO_SIZE 0
44 
45 
46 //=== COM ===================================================================================//
47 #define COMn (1)
48 
49 #define COM0_VALIDITY (true) // validni
50 #define COM0_USART (USART3)
51 #define COM0_USART_CLK (RCC_APB1Periph_USART3)
52 #define COM0_USART_IRQHandler (USART3_IRQHandler)
53 #define COM0_USART_IRQ (USART3_IRQn)
54 #define COM0_USART_RX_GPIO_CLK (RCC_AHB1Periph_GPIOC)
55 #define COM0_USART_TX_GPIO_CLK (RCC_AHB1Periph_GPIOC)
56 #define COM0_USART_RX_GPIO_PORT (GPIOC)
57 #define COM0_USART_TX_GPIO_PORT (GPIOC)
58 #define COM0_USART_RX_PIN_SRC (GPIO_PinSource11)
59 #define COM0_USART_TX_PIN_SRC (GPIO_PinSource10)
60 #define COM0_USART_FC_RTS_GPIO_CLK (0)// neni(RCC_AHB1Periph_GPIOB)
61 #define COM0_USART_FC_CTS_GPIO_CLK (0)// neni(RCC_AHB1Periph_GPIOB)
62 #define COM0_USART_FC_RTS_GPIO_PORT (0)// neni(GPIOB)
63 #define COM0_USART_FC_CTS_GPIO_PORT (0)// neni(GPIOB)
64 #define COM0_USART_FC_RTS_PIN_SRC (0)// neni(GPIO_PinSource14)
65 #define COM0_USART_FC_CTS_PIN_SRC (0)// neni(GPIO_PinSource13)
66 #define COM0_USART_PIN_AF (GPIO_AF_USART3)
67 #define COM0_RS485_DIR_GPIO (0)// neni
68 #define COM0_RS485_DIR_PIN_SRC (0)
69 #define COM0_RS485_DIR_PIN_INVERT (false)
70 #define COM0_RS485_DIR_TX_DELAY (0)
71 #define COM0_RS485_BLOCK_RX_BY_TX (false)
72 #define COM0_SEND_BYTES_ECHO (false)
73 
74 extern const bool COMn_VALIDITY[COMn];// pro moznost ponechat poradi COMu, ale nektere z nich znevalidnit
75 extern const uint32_t COMn_USART[COMn];
76 extern const uint32_t COMn_USART_CLK[COMn];
77 extern const IRQn COMn_USART_IRQ[COMn];
78 extern const uint32_t COMn_USART_RX_GPIO_CLK[COMn];
79 extern const uint32_t COMn_USART_TX_GPIO_CLK[COMn];
80 extern const uint32_t COMn_USART_RX_GPIO_PORT[COMn];
81 extern const uint32_t COMn_USART_TX_GPIO_PORT[COMn];
82 extern const uint8_t COMn_USART_TX_PIN_SRC[COMn];
83 extern const uint8_t COMn_USART_RX_PIN_SRC[COMn];
84 extern const uint32_t COMn_USART_FC_RTS_GPIO_CLK[COMn];
85 extern const uint32_t COMn_USART_FC_CTS_GPIO_CLK[COMn];
86 extern const uint32_t COMn_USART_FC_RTS_GPIO_PORT[COMn];
87 extern const uint32_t COMn_USART_FC_CTS_GPIO_PORT[COMn];
88 extern const uint8_t COMn_USART_FC_RTS_PIN_SRC[COMn];
89 extern const uint8_t COMn_USART_FC_CTS_PIN_SRC[COMn];
90 extern const uint8_t COMn_USART_PIN_AF[COMn];
91 extern const uint32_t COMn_RS485_DIR_GPIO_C[COMn];// alternativa pro Storm01-Ccko
92 extern const uint8_t COMn_RS485_DIR_PIN_SRC_C[COMn];// alternativa pro Storm01-Ccko
93 extern const uint32_t COMn_RS485_DIR_GPIO_D[COMn];// alternativa pro Storm01-Dcko
94 extern const uint8_t COMn_RS485_DIR_PIN_SRC_D[COMn];// alternativa pro Storm01-Dcko
95 extern uint32_t COMn_RS485_DIR_GPIO[COMn];// vysledek bud C nebo D - default je C
96 extern uint8_t COMn_RS485_DIR_PIN_SRC[COMn];// vysledek bud C nebo D - default je C
97 extern const bool COMn_RS485_DIR_PIN_INVERT[COMn];
98 extern const uint32_t COMn_RS485_DIR_TX_DELAY[COMn];
99 extern const bool COMn_RS485_BLOCK_RX_BY_TX[COMn];
100 extern const bool COMn_SEND_BYTES_ECHO[COMn];
101 
102 
103 //=== LOGy =================================================================================//
104 #define LOG_COM_PORT (0)
105 #define LOG_COM_BR (115200)
106 #define LOG_COM_PARITY (0)
107 
108 //=== LEDky ================================================================================//
109 #define LEDn (4)
110 
111 #define LED0_PIN (GPIO_Pin_8)
112 #define LED0_GPIO_PORT (GPIOG)
113 #define LED0_GPIO_PUPD (GPIO_PuPd_UP)
114 #define LED0_GPIO_OTYPE (GPIO_OType_PP)
115 #define LED0_INVERT (TRUE)
116 
117 #define LED1_PIN (GPIO_Pin_6)
118 #define LED1_GPIO_PORT (GPIOG)
119 #define LED1_GPIO_PUPD (GPIO_PuPd_UP)
120 #define LED1_GPIO_OTYPE (GPIO_OType_PP)
121 #define LED1_INVERT (TRUE)
122 
123 #define LED2_PIN (GPIO_Pin_7)
124 #define LED2_GPIO_PORT (GPIOC )
125 #define LED2_GPIO_PUPD (GPIO_PuPd_UP)
126 #define LED2_GPIO_OTYPE (GPIO_OType_PP)
127 #define LED2_INVERT (TRUE)
128 
129 #define LED3_PIN (GPIO_Pin_9)
130 #define LED3_GPIO_PORT (GPIOI)
131 #define LED3_GPIO_PUPD (GPIO_PuPd_UP)
132 #define LED3_GPIO_OTYPE (GPIO_OType_PP)
133 #define LED3_INVERT (TRUE)
134 
135 extern const uint32_t LED_GPIO_PORT[LEDn];
136 extern const uint16_t LED_GPIO_PIN[LEDn];
137 extern const GPIOPuPd_TypeDef LED_GPIO_PUPD[LEDn];
138 extern const GPIOOType_TypeDef LED_GPIO_OTYPE[LEDn];
139 extern const uint8_t LED_INVERT_ON_OFF[LEDn];
140 
141 //=== BUTTONy ==============================================================================//
142 #define BUTTONn (2)
143 
144 #define BUTTON0_PIN (GPIO_Pin_15)
145 #define BUTTON0_GPIO_PORT (GPIOG)
146 #define BUTTON0_GPIO_PUPD (GPIO_PuPd_UP)
147 #define BUTTON0_EXTI_LINE (EXTI_Line15)
148 #define BUTTON0_EXTI_PORT_SOURCE (EXTI_PortSourceGPIOG)
149 #define BUTTON0_EXTI_PIN_SOURCE (EXTI_PinSource15)
150 #define BUTTON0_EXTI_IRQn (EXTI15_10_IRQn)
151 #define BUTTON0_INVERT (true)
152 
153 #define BUTTON1_PIN (GPIO_Pin_13)
154 #define BUTTON1_GPIO_PORT (GPIOC)
155 #define BUTTON1_GPIO_PUPD (GPIO_PuPd_UP)
156 #define BUTTON1_EXTI_LINE (EXTI_Line13)
157 #define BUTTON1_EXTI_PORT_SOURCE (EXTI_PortSourceGPIOC)
158 #define BUTTON1_EXTI_PIN_SOURCE (EXTI_PinSource13)
159 #define BUTTON1_EXTI_IRQn (EXTI15_10_IRQn)
160 #define BUTTON1_INVERT (true)
161 
162 extern const uint32_t BUTTONn_PORT[BUTTONn];
163 extern const uint16_t BUTTONn_PIN[BUTTONn];
164 extern const GPIOPuPd_TypeDef BUTTONn_PUPD[BUTTONn];
165 extern const uint16_t BUTTONn_EXTI_LINE[BUTTONn];
166 extern const uint8_t BUTTONn_PIN_SOURCE[BUTTONn];
167 extern const IRQn BUTTONn_IRQn[BUTTONn];
168 extern const bool BUTTONn_INVERT_ON_OFF[BUTTONn];
169 
170 //=== JOYSTICK ============================================================================//
171 //#define IOE_I2C I2C1
172 //#define IOE_I2C_CLK RCC_APB1Periph_I2C1
173 //#define IOE_I2C_SCL_PIN GPIO_Pin_6
174 //#define IOE_I2C_SCL_GPIO_PORT GPIOB
175 //#define IOE_I2C_SCL_GPIO_CLK RCC_AHB1Periph_GPIOB
176 //#define IOE_I2C_SCL_SOURCE GPIO_PinSource6
177 //#define IOE_I2C_SCL_AF GPIO_AF_I2C1
178 //#define IOE_I2C_SDA_PIN GPIO_Pin_9
179 //#define IOE_I2C_SDA_GPIO_PORT GPIOB
180 //#define IOE_I2C_SDA_GPIO_CLK RCC_AHB1Periph_GPIOB
181 //#define IOE_I2C_SDA_SOURCE GPIO_PinSource9
182 //#define IOE_I2C_SDA_AF GPIO_AF_I2C1
183 //#define IOE_I2C_DR ((uint32_t)0x40005410)
184 //#define IOE_IT_PIN GPIO_Pin_2
185 //#define IOE_IT_GPIO_PORT GPIOI
186 //#define IOE_IT_GPIO_CLK RCC_AHB1Periph_GPIOI
187 //#define IOE_IT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOI
188 //#define IOE_IT_EXTI_PIN_SOURCE EXTI_PinSource2
189 //#define IOE_IT_EXTI_LINE EXTI_Line2
190 //#define IOE_IT_EXTI_IRQn EXTI2_IRQn
191 //
197 //#define JOY_GPIO_PINS (uint32_t)(JOY_UP | JOY_RIGHT | JOY_LEFT | JOY_DOWN | JOY_PUSH)
198 //#define JOY_GPIO_PUPD (GPIO_PuPd_UP)
199 
200 // vrati hodiny ke GPIO
201 uint32_t getGPIO_AHB1_Clk(GPIO_TypeDef* gpio);
202 uint32_t getGPIO_AHB1_Clk(uint32_t gpio);
203 uint32_t getGPIO_EXTI_PortSource(GPIO_TypeDef *gpio);
204 uint32_t getGPIO_EXTI_PortSource(uint32_t gpio);
205 
206 //Nastavi hodiny
207 void initClockTree();
208 
209 #endif //_HAL_H_
const uint8_t LED_INVERT_ON_OFF[LEDn]
Definition: hal.c:39
const uint32_t COMn_USART_RX_GPIO_PORT[COMn]
Definition: hal.c:12
uint8_t COMn_RS485_DIR_PIN_SRC[COMn]
Definition: hal.c:28
const uint32_t BUTTONn_PORT[BUTTONn]
Definition: hal.c:42
const uint16_t LED_GPIO_PIN[LEDn]
Definition: hal.c:36
const bool BUTTONn_INVERT_ON_OFF[BUTTONn]
Definition: hal.c:48
const uint8_t COMn_USART_RX_PIN_SRC[COMn]
Definition: hal.c:14
const uint32_t COMn_USART_CLK[COMn]
Definition: hal.c:8
const uint16_t BUTTONn_EXTI_LINE[BUTTONn]
Definition: hal.c:45
const bool COMn_VALIDITY[COMn]
Definition: hal.c:6
#define BUTTONn
Definition: hal.h:142
const uint32_t COMn_USART_FC_RTS_GPIO_PORT[COMn]
Definition: hal.c:18
const uint32_t COMn_USART[COMn]
Definition: hal.c:7
void initClockTree()
Definition: hal.c:92
const IRQn COMn_USART_IRQ[COMn]
Definition: hal.c:9
const GPIOPuPd_TypeDef BUTTONn_PUPD[BUTTONn]
Definition: hal.c:44
const uint8_t COMn_USART_FC_CTS_PIN_SRC[COMn]
Definition: hal.c:21
const bool COMn_RS485_DIR_PIN_INVERT[COMn]
Definition: hal.c:29
const uint8_t COMn_USART_FC_RTS_PIN_SRC[COMn]
Definition: hal.c:20
const uint32_t COMn_USART_TX_GPIO_CLK[COMn]
Definition: hal.c:11
const GPIOOType_TypeDef LED_GPIO_OTYPE[LEDn]
Definition: hal.c:38
const GPIOPuPd_TypeDef LED_GPIO_PUPD[LEDn]
Definition: hal.c:37
const uint32_t COMn_USART_FC_CTS_GPIO_PORT[COMn]
Definition: hal.c:19
const uint8_t COMn_RS485_DIR_PIN_SRC_D[COMn]
Definition: hal.c:26
const bool COMn_RS485_BLOCK_RX_BY_TX[COMn]
Definition: hal.c:31
const uint32_t COMn_USART_FC_CTS_GPIO_CLK[COMn]
Definition: hal.c:17
const bool COMn_SEND_BYTES_ECHO[COMn]
Definition: hal.c:32
#define LEDn
Definition: hal.h:109
uint32_t getGPIO_EXTI_PortSource(GPIO_TypeDef *gpio)
Definition: hal.c:72
#define COMn
Definition: hal.h:47
const uint16_t BUTTONn_PIN[BUTTONn]
Definition: hal.c:43
const uint8_t COMn_RS485_DIR_PIN_SRC_C[COMn]
Definition: hal.c:24
const IRQn BUTTONn_IRQn[BUTTONn]
Definition: hal.c:47
const uint8_t BUTTONn_PIN_SOURCE[BUTTONn]
Definition: hal.c:46
const uint32_t COMn_RS485_DIR_GPIO_D[COMn]
Definition: hal.c:25
const uint32_t COMn_RS485_DIR_GPIO_C[COMn]
Definition: hal.c:23
const uint32_t LED_GPIO_PORT[LEDn]
Definition: hal.c:35
const uint32_t COMn_RS485_DIR_TX_DELAY[COMn]
Definition: hal.c:30
const uint8_t COMn_USART_PIN_AF[COMn]
Definition: hal.c:22
const uint32_t COMn_USART_TX_GPIO_PORT[COMn]
Definition: hal.c:13
const uint32_t COMn_USART_RX_GPIO_CLK[COMn]
Definition: hal.c:10
const uint8_t COMn_USART_TX_PIN_SRC[COMn]
Definition: hal.c:15
uint32_t getGPIO_AHB1_Clk(GPIO_TypeDef *gpio)
Definition: hal.c:52
uint32_t COMn_RS485_DIR_GPIO[COMn]
Definition: hal.c:27
const uint32_t COMn_USART_FC_RTS_GPIO_CLK[COMn]
Definition: hal.c:16