-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
80 lines (64 loc) · 1.93 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
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/binary_info.h"
#include "core_msg.h"
#include "joystick.h"
#include "joy_wii_i2c.h"
#include "game_data.h"
#include "screen.h"
#include "control.h"
#define VGA_PIN_BASE 2
#define JOY_SDA 12
#define JOY_SCL 13
#define AUDIO_OUT 16
#define SAMPLE_FREQUENCY 22050
void core1_main(void);
static struct JOYSTICK joy;
static void blink_led(void)
{
static int led_state = 1;
static int frame_count = 0;
if (frame_count++ >= 15) {
frame_count = 0;
led_state = !led_state;
gpio_put(PICO_DEFAULT_LED_PIN, led_state);
}
}
int main(void)
{
// pin names
bi_decl(bi_pin_mask_with_name(3 << (VGA_PIN_BASE + 0), "VGA Blue 0-1"));
bi_decl(bi_pin_mask_with_name(3 << (VGA_PIN_BASE + 2), "VGA Green 0-1"));
bi_decl(bi_pin_mask_with_name(3 << (VGA_PIN_BASE + 4), "VGA Red 0-1"));
bi_decl(bi_1pin_with_name(VGA_PIN_BASE + 6, "VGA H-Sync"));
bi_decl(bi_1pin_with_name(VGA_PIN_BASE + 7, "VGA V-Sync"));
bi_decl(bi_1pin_with_name(JOY_SDA, "Joystick SDA"));
bi_decl(bi_1pin_with_name(JOY_SCL, "Joystick SCL"));
bi_decl(bi_1pin_with_name(AUDIO_OUT, "Audio output"));
stdio_init_all();
//sleep_ms(5000); printf("=====\nstarting\n");
// start core 1
core_msg_init();
multicore_launch_core1(core1_main);
multicore_fifo_pop_blocking(); // wait for core1 to start
multicore_fifo_push_blocking(0);
// start LED output
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
gpio_put(PICO_DEFAULT_LED_PIN, 1);
//sleep_ms(5000); printf("Starting...\n");
joy_wii_i2c_init(&joy, JOY_SDA, JOY_SCL);
msg_audio_init(AUDIO_OUT, SAMPLE_FREQUENCY);
if (screen_init(VGA_PIN_BASE) < 0) {
return 1;
}
control_init(&joy);
msg_music_start(game_music, SAMPLE_FREQUENCY, 0x100, true);
while (true) {
blink_led();
joy_wii_i2c_update(&joy);
control_update(&joy);
screen_render(&joy);
}
}