aboutsummaryrefslogtreecommitdiffhomepage
path: root/workspace/ts100/src/Main.c
blob: 1762b02c6058020f2935d989ec22c89f121819ce (plain)
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
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. **********************
 File Name :      main.c
 Version :        S100 APP Ver 2.11
 Description:
 Author :         Celery
 Data:            2015/07/07
 History:
 2016/8/11	Updates by Ben V. Brown <ralim@ralimtek.com> - Cleanup and english comments
 2015/07/07   ͳһ������
 *******************************************************************************/
#include <string.h>
#include <stdio.h>
#include "APP_Version.h"
#include "Disk.h"
#include "Bios.h"
#include "usb_lib.h"
#include "I2C.h"
#include "Flash.h"
#include "MMA8652FC.h"
#include "UI.h"
#include "Oled.h"
#include "CTRL.h"
#include "Hardware.h"
int main(void) {
	RCC_Config(); //setup system clock
	NVIC_Config(0x4000);
	Init_Timer2(); //init the timers
	Init_Timer3();
	GPIO_Config();//setup all the GPIO pins

	USB_Port(DISABLE);//disable the USB hardware
	Delay_Ms(200);//pause to let hardware stabilize
	USB_Port(ENABLE);//enable the USB hardware
	USB_Init();
	I2C_Configuration(); //init the i2c bus

	Adc_Init(); //init adc and dma
	if (Get_CtrlStatus() != CONFIG)
		StartUp_Accelerated();//start the accelerometer if not in config mode

	System_Init();//load known safe values
	Init_Oled();//init the OLED display
	Clear_Screen();//clear the display buffer to black
	Init_Gtime();//init the count down timers
	APP_Init();//pick operating mode via input voltage

	Disk_BuffInit();//fill the buffer for the virtual disk
	Config_Analysis(); //read in config from virtual disk
	Pid_Init(); //init the pid to starting values
	Set_gKey(NO_KEY); //reset keys to all off
	Start_Watchdog(3000);//start the system watchdog as 3 seconds

	while (1) {
		Clear_Watchdog(); //reset the Watchdog
		if (Get_CtrlStatus() != CONFIG && LEAVE_WAIT_TIMER== 0) {
			Check_Accelerated(); //update readings from the accelerometer
			LEAVE_WAIT_TIMER = 50;//reset timer so we dont poll accelerometer for another 500ms
		}
		OLed_Display(); //Draw in the Oled display for this mode
		Status_Tran();  //Handle user input and mode changing
	}
}
/******************************** END OF FILE *********************************/