This repository has been archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
119 lines (100 loc) · 2.06 KB
/
test.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
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/cm3/systick.h>
#include "led.h"
#include "cdcacm.h"
#include "output.h"
#include "fan.h"
#include "smps.h"
#include "piezo.h"
#include "button.h"
#include "battery.h"
#include "usart.h"
#include "pswitch.h"
#include "analogue.h"
#include "i2c.h"
#define DELAY 4000
#define delay(x) do { for (int i = 0; i < x * 1000; i++) \
__asm__("nop"); \
} while(0)
usbd_device *usbd_dev;
void init(void) {
rcc_clock_setup_in_hse_8mhz_out_72mhz();
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPDEN);
i2c_init();
led_init();
output_init();
fan_init();
smps_init();
piezo_init();
button_init();
battery_init();
usart_init();
pswitch_init();
analogue_init();
}
void flash_output(int i) { output_on(i); delay(DELAY); output_off(i); }
void flash_stat(int i) { output_stat_on(i); delay(DELAY); output_stat_off(i); }
int main(void) {
init();
while(1) {
// Outputs
flash_output(0);
flash_output(2);
flash_output(3);
flash_output(4);
flash_output(5);
flash_output(1);
delay(DELAY);
// Output status LEDs
flash_stat(0);
flash_stat(2);
flash_stat(3);
flash_stat(4);
flash_stat(5);
flash_stat(1);
delay(DELAY);
// Fan
fan_on();
delay(4*DELAY);
fan_off();
delay(DELAY);
// 5V SMPS
smps_on();
delay(DELAY);
smps_off();
delay(DELAY);
// Piezo
for (int i=0; i<2000; i++) {
piezo_toggle();
delay(1);
}
// I2C U1
#if 0
// XXX jmorse
battery_vbus();
#endif
// Run LED (also indicates if I2C works)
led_set(LED_RUN);
delay(DELAY);
led_clear(LED_RUN);
delay(DELAY);
// I2C U4
#if 0
// XXX jmorse
f_vbus();
#endif
// Error LED
led_set(LED_ERROR);
delay(DELAY);
led_clear(LED_ERROR);
delay(DELAY);
}
return 0;
}