~foura/uxn900

ref: 25bea2e6b0c9ecb4a734773be4bde7665893471d uxn900/src/main.c -rw-r--r-- 2.0 KiB
25bea2e6james palmer datetime: use the twl4030 rtc for an almost complete datetime device. 4 months ago
                                                                                
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
#include "uxn.h"
#include "dat.h"
#include "fns.h"

#include "dev/console.h"
#include "dev/controller.h"
#include "dev/datetime.h"
#include "dev/nil.h"
#include "dev/screen.h"
#include "dev/system.h"

Uint8      uxn_ram[64*1024];
Controller uxn_controller;
Screen     uxn_screen;

void
uxn_init(void)
{
	int i;
	Uint8 *rom;

	for(i = 0; i < sizeof(uxn_ram); i++)
		uxn_ram[i] = 0;

	rom = (Uint8 *) ROMADDR;
	for(i = 0; i < 0xf000; i++)
		uxn_ram[PAGE_PROGRAM + i] = rom[i];
}

int
uxn_halt(Uxn *u, Uint8 err, Uint16 addr)
{
	return 1;
}

int
uxn_interrupt(void)
{
	return 1;
}

void
watchdog_init(void)
{
	Uint8 data[2];

	data[0] = 0x5e;
	data[1] = 0x0;

	i2c_write(PHYSI2C1, 0x4b, data, 1, 1);

	data[1] = 0xff;

	i2c_read(PHYSI2C1, 0x4b, data, 1, 1);
	if(data[1] != 0x0)
		console_puts("watchdog: failed to disable\n");
}

void
main(void)
{
	Uxn u;

	timer_init(PHYSTIMER1);
	timer_init(PHYSTIMER2);
	timer_init(PHYSTIMER3);
	i2c_init(PHYSI2C1);
	i2c_init(PHYSI2C2);

	watchdog_init();
	screen_init(&uxn_screen);
	controller_init(&uxn_controller);

	uxn_init();
	uxn_boot(&u, &uxn_ram[0]);

	uxn_port(&u, 0x0, system_dei, system_deo);
	uxn_port(&u, 0x1, nil_dei,    console_deo);
	uxn_port(&u, 0x2, screen_dei, screen_deo);
	uxn_port(&u, 0x8, controller_dei, controller_deo);
	uxn_port(&u, 0xc, datetime_dei, datetime_deo);

	uxn_port(&u, 0x3, nil_dei, nil_deo);
	uxn_port(&u, 0x4, nil_dei, nil_deo);
	uxn_port(&u, 0x5, nil_dei, nil_deo);
	uxn_port(&u, 0x6, nil_dei, nil_deo);
	uxn_port(&u, 0x7, nil_dei, nil_deo);
	uxn_port(&u, 0x9, nil_dei, nil_deo);
	uxn_port(&u, 0xa, nil_dei, nil_deo);
	uxn_port(&u, 0xb, nil_dei, nil_deo);
	uxn_port(&u, 0xd, nil_dei, nil_deo);
	uxn_port(&u, 0xe, nil_dei, nil_deo);
	uxn_port(&u, 0xf, nil_dei, nil_deo);

	if(!uxn_eval(&u, PAGE_PROGRAM))
		return;

	for(;;) {
		controller_poll(&uxn_controller, &u);

		uxn_eval(&u, GETVECTOR(&u.dev[2]));
		if(uxn_screen.fg.changed || uxn_screen.bg.changed)
			screen_redraw(&uxn_screen);

		timer_delay(PHYSTIMER2, 16000);
	}
}