forked from GeorgeSinodakis/cpp_stm32f103_snakeGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
57 lines (48 loc) · 872 Bytes
/
main.cpp
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
#include <stdint.h>
#include "delay.h"
#include "rcc.h"
#include "gpio.h"
#include "st7735.h"
#include "snake.h"
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
Game snake;
void configureGpio(void)
{
GPIOA_clock_enable();
GPIOA_mode(INPUT_PULL_UPDOWN, 10);
GPIOA_mode(INPUT_PULL_UPDOWN, 11);
GPIOA_mode(INPUT_PULL_UPDOWN, 12);
GPIOA_mode(INPUT_PULL_UPDOWN, 15);
GPIOA_set(10);
GPIOA_set(11);
GPIOA_set(12);
GPIOA_set(15);
}
void checkButtons()
{
startCount(300);
while(!endCount())
{
if(!GPIOA_read(10)) snake.goUp();
if(!GPIOA_read(11)) snake.goDown();
if(!GPIOA_read(12)) snake.goLeft();
if(!GPIOA_read(15)) snake.goRight();
}
}
int main(void)
{
clock_72Mhz();
configureGpio();
st7735_init(3);
snake.init();
while (1)
{
snake.draw();
snake.loss_check();
checkButtons();
snake.move();
}
}