2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief Main Interrupt Service Routines.
8 * This file provides all exceptions handler and peripherals interrupt
10 ******************************************************************************
13 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
14 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
15 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
16 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
17 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
18 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
20 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
21 ******************************************************************************
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32f4xx_it.h"
28 #include "usbd_core.h"
29 #include "stm32f4_discovery.h"
30 #include "usbd_hid_core.h"
32 //Library config for this project!!!!!!!!!!!
33 #include "stm32f4xx_conf.h"
36 /* Private typedef -----------------------------------------------------------*/
37 /* Private define ------------------------------------------------------------*/
40 extern uint8_t Buffer[6];
41 /* Private macro -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 extern __IO uint8_t DemoEnterCondition;
44 uint8_t Counter = 0x00;
45 extern int8_t X_Offset;
46 extern int8_t Y_Offset;
47 extern __IO uint8_t UserButtonPressed;
48 __IO uint8_t TempAcceleration = 0;
49 /* Private function prototypes -----------------------------------------------*/
50 extern USB_OTG_CORE_HANDLE USB_OTG_dev;
51 static uint8_t *USBD_HID_GetPos (void);
52 extern uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
54 /******************************************************************************/
55 /* Cortex-M3 Processor Exceptions Handlers */
56 /******************************************************************************/
59 * @brief This function handles NMI exception.
63 void NMI_Handler(void)
68 * @brief This function handles Hard Fault exception.
72 void HardFault_Handler(void)
74 /* Go to infinite loop when Hard Fault exception occurs */
81 * @brief This function handles Memory Manage exception.
85 void MemManage_Handler(void)
87 /* Go to infinite loop when Memory Manage exception occurs */
94 * @brief This function handles Bus Fault exception.
98 void BusFault_Handler(void)
100 /* Go to infinite loop when Bus Fault exception occurs */
107 * @brief This function handles Usage Fault exception.
111 void UsageFault_Handler(void)
113 /* Go to infinite loop when Usage Fault exception occurs */
120 * @brief This function handles SVCall exception.
124 void SVC_Handler(void)
129 * @brief This function handles Debug Monitor exception.
133 void DebugMon_Handler(void)
138 * @brief This function handles PendSVC exception.
142 void PendSV_Handler(void)
147 * @brief This function handles SysTick Handler.
151 void SysTick_Handler(void)
154 uint8_t temp1, temp2 = 0x00;
156 if (DemoEnterCondition == 0x00)
158 TimingDelay_Decrement();
162 buf = USBD_HID_GetPos();
163 if((buf[1] != 0) ||(buf[2] != 0))
165 USBD_HID_SendReport (&USB_OTG_dev,
174 /* Disable All TIM4 Capture Compare Channels */
175 TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE);
176 TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE);
177 TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE);
178 TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE);
180 LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6);
181 /* Remove the offsets values from data */
182 Buffer[0] -= X_Offset;
183 Buffer[2] -= Y_Offset;
184 /* Update autoreload and capture compare registers value*/
185 temp1 = ABS((int8_t)(Buffer[0]));
186 temp2 = ABS((int8_t)(Buffer[2]));
187 TempAcceleration = MAX(temp1, temp2);
189 if(TempAcceleration != 0)
191 if ((int8_t)Buffer[0] < -2)
193 /* Enable TIM4 Capture Compare Channel 4 */
194 TIM_CCxCmd(TIM4, TIM_Channel_4, ENABLE);
195 /* Sets the TIM4 Capture Compare4 Register value */
196 TIM_SetCompare4(TIM4, TIM_CCR/TempAcceleration);
198 if ((int8_t)Buffer[0] > 2)
200 /* Enable TIM4 Capture Compare Channel 2 */
201 TIM_CCxCmd(TIM4, TIM_Channel_2, ENABLE);
202 /* Sets the TIM4 Capture Compare2 Register value */
203 TIM_SetCompare2(TIM4, TIM_CCR/TempAcceleration);
205 if ((int8_t)Buffer[2] > 2)
207 /* Enable TIM4 Capture Compare Channel 1 */
208 TIM_CCxCmd(TIM4, TIM_Channel_1, ENABLE);
209 /* Sets the TIM4 Capture Compare1 Register value */
210 TIM_SetCompare1(TIM4, TIM_CCR/TempAcceleration);
212 if ((int8_t)Buffer[2] < -2)
214 /* Enable TIM4 Capture Compare Channel 3 */
215 TIM_CCxCmd(TIM4, TIM_Channel_3, ENABLE);
216 /* Sets the TIM4 Capture Compare3 Register value */
217 TIM_SetCompare3(TIM4, TIM_CCR/TempAcceleration);
219 /* Time base configuration */
220 TIM_SetAutoreload(TIM4, TIM_ARR/TempAcceleration);
228 /******************************************************************************/
229 /* STM32Fxxx Peripherals Interrupt Handlers */
230 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
231 /* available peripheral interrupt handler's name please refer to the startup */
232 /* file (startup_stm32fxxx.s). */
233 /******************************************************************************/
236 * @brief This function handles PPP interrupt request.
240 /*void PPP_IRQHandler(void)
245 * @brief This function handles EXTI0_IRQ Handler.
249 void EXTI0_IRQHandler(void)
251 UserButtonPressed = 0x01;
253 /* Clear the EXTI line pending bit */
254 EXTI_ClearITPendingBit(USER_BUTTON_EXTI_LINE);
258 * @brief This function handles EXTI15_10_IRQ Handler.
262 void OTG_FS_WKUP_IRQHandler(void)
264 if(USB_OTG_dev.cfg.low_power)
266 /* Reset SLEEPDEEP and SLEEPONEXIT bits */
267 SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
269 /* After wake-up from sleep mode, reconfigure the system clock */
271 USB_OTG_UngateClock(&USB_OTG_dev);
273 EXTI_ClearITPendingBit(EXTI_Line18);
277 * @brief This function handles OTG_HS Handler.
281 void OTG_FS_IRQHandler(void)
283 USBD_OTG_ISR_Handler (&USB_OTG_dev);
287 * @brief USBD_HID_GetPos
289 * @retval Pointer to report
291 static uint8_t *USBD_HID_GetPos (void)
293 static uint8_t HID_Buffer[4] = {0};
298 if(((int8_t)Buffer[2]) < -2)
300 HID_Buffer[1] += CURSOR_STEP;
302 /* RIGHT Direction */
303 if(((int8_t)Buffer[2]) > 2)
305 HID_Buffer[1] -= CURSOR_STEP;
308 if(((int8_t)Buffer[0]) < -2)
310 HID_Buffer[2] += CURSOR_STEP;
313 if(((int8_t)Buffer[0]) > 2)
315 HID_Buffer[2] -= CURSOR_STEP;
320 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/