-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.c
250 lines (192 loc) · 6.37 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
/* Library includes. */
#include "stm32f10x.h"
#include "misc.h"
#include "stm32f10x_it.h"
#include "stm32f10x_rcc.h"
/*app includes. */
//#include "stm3210e_lcd.h"
#include "leds.h"
#include "touch.h"
#include "lcd.h"
#include "menu.h"
#include "speaker.h"
#include "timer.h"
#include "ds1820.h"
#include "serial.h"
/*-----------------------------------------------------------*/
/* The period of the system clock in nano seconds. This is used to calculate
the jitter time in nano seconds. */
#define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
/*-----------------------------------------------------------*/
/**
* Configure the hardware for the App.
*/
static void prvSetupHardware( void );
/*-----------------------------------------------------------*/
xTaskHandle xLCDTaskHandle,
xTouchTaskHandle,
xAdcTaskHandle ,
xBeepTaskHandle,
xTimerSetupHandle,
xDS1820Handle;
// Needed by file core_cm3.h
volatile int ITM_RxBuffer;
/*-----------------------------------------------------------*/
void item_1_callback(unsigned char button_down)
{
if (button_down)
vLEDToggle(D4_PORT, D4_PIN);
}
void item_2_callback(unsigned char button_down)
{
printf("Button %d\r\n", button_down);
vLEDSet(D4_PORT, D4_PIN, button_down);
}
void example_applet(int init)
{
if (init)
{
lcd_printf(20, 1, 20, "Example Applet");
lcd_printf(34, 13, 4, "Back");
}
}
int example_applet_touch_handler(int xx, int yy)
{
lcd_fill(0, 0, 150, 40, 0xFF);
lcd_printf(1,1, 20, "Touch %d,%d", xx, yy);
// return non-zero to exit applet
return xx > 200 && yy > 200;
}
struct menu frobnicate_menu[] =
{
{"Item 1", NULL, NULL, item_1_callback, NULL},
{"Item 2", NULL, NULL, item_2_callback, NULL},
{"Item 3", NULL, NULL, item_1_callback, NULL},
{"Item 4", NULL, NULL, item_1_callback, NULL},
{"Item 5", NULL, NULL, item_1_callback, NULL},
{"Back", NULL, NULL, NULL},
{NULL, NULL, NULL, NULL}
};
struct menu main_menu[] =
{
{"Frobnicate", frobnicate_menu, NULL, NULL},
{"Set temperature", NULL, NULL, NULL},
{"Applet", NULL, example_applet, NULL, example_applet_touch_handler},
{NULL, NULL, NULL, NULL}
};
/**
* Main.
*/
int main( void )
{
prvSetupHardware();// set up peripherals etc
USARTInit(USART_PARAMS1);
printf("Hello!\r\n");
lcd_init();
vLEDInit();
menu_set_root(main_menu);
xTaskCreate( vTouchTask,
( signed portCHAR * ) "touch",
configMINIMAL_STACK_SIZE +1000,
NULL,
tskIDLE_PRIORITY+2,
&xTouchTaskHandle );
/* Create you application tasks if needed here
xTaskCreate( vKegTask,
( signed portCHAR * ) "ADC",
configMINIMAL_STACK_SIZE +1000,
NULL,
tskIDLE_PRIORITY+2,
&xAdcTaskHandle ); */
/* Start the scheduler. */
vTaskStartScheduler();
printf("FAIL\r\n");
/* Will only get here if there was insufficient memory to create the idle
task. */
return 0;
}
/*-----------------------------------------------------------*/
// HARDWARE SETUP
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
/* Start with the clocks in their expected state. */
RCC_DeInit();
/* Enable HSE (high speed external clock). */
RCC_HSEConfig( RCC_HSE_ON );
/* Wait till HSE is ready. */
while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET )
{
}
/* 2 wait states required on the flash. */
*( ( unsigned portLONG * ) 0x40022000 ) = 0x02;
/* HCLK = SYSCLK */
RCC_HCLKConfig( RCC_SYSCLK_Div1 );
/* PCLK2 = HCLK */
RCC_PCLK2Config( RCC_HCLK_Div1 );
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config( RCC_HCLK_Div2 );
/* PLLCLK = 8MHz * 9 = 72 MHz. */
RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 );
/* Enable PLL. */
RCC_PLLCmd( ENABLE );
/* Wait till PLL is ready. */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source. */
RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );
/* Wait till PLL is used as system clock source. */
while( RCC_GetSYSCLKSource() != 0x08 )
{
}
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF |
RCC_APB2Periph_AFIO,
ENABLE );
/* SPI2 Periph clock enable */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
/* Set the Vector Table base address at 0x08000000 */
NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
/* Configure HCLK clock as SysTick clock source. */
SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
}
/*-----------------------------------------------------------*/
// STACK OVERFLOW HOOK - TURNS ON LED
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOC, &GPIO_InitStructure );
GPIO_WriteBit( GPIOC, GPIO_Pin_7, 1 );
for( ;; );
}
/*-----------------------------------------------------------*/
/* Keep the linker happy. */
void assert_failed( unsigned portCHAR* pcFile, unsigned portLONG ulLine )
{
printf("FAILED %s %d\r\n", pcFile, ulLine);
for( ;; )
{
}
}