summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/project.c
blob: be329fafb5d265d2cab77abfbc4359d848908788 (plain) (blame)
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
/*
 * project.c
 *
 *  Created on: Jan 8, 2023
 *      Author: bruce
 */

#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stm32l4xx.h>
#include "project.h"
#include "player_actions.h"
#include "hw4.h"
#include "local_control.h"
#include "remote_control.h"
#include "GPIO.h"

#define LOCAL_MODE (1)
#define REMOTE_MODE (2)

static uint8_t state = STOPPED_STATE;

uint8_t *project_get_state() {
	return &state;
}

void project_run() {
	int mode = LOCAL_MODE;
	local_control_start();
//	remote_control_start();

	GPIO_Init();
	NVIC_EnableIRQ(EXTI15_10_IRQn);

	for (;;) {
		switch (mode) {
		case REMOTE_MODE:
			remote_control_loop(); break;
		case LOCAL_MODE:
			local_control_loop(); break;
		}

		if (state == PAUSED_STATE)
			pause_loop();
	}
}

void EXTI15_10_IRQHandler() {
    if (~EXTI->PR1 & EXTI_PR1_PIF13)
    	return;

    EXTI->PR1 |= EXTI_PR1_PIF13;

	int status = !(GPIOC->IDR & GPIO_PIN_13);
	printf("%i\r\n", status);
}