forked from uARM-Palm/uARM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevicePalmTungstenE.c
executable file
·156 lines (118 loc) · 3.44 KB
/
devicePalmTungstenE.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//(c) uARM project https://github.com/uARM-Palm/uARM [email protected]
#include "sspdev_TSC210x.h"
#include "SDL2/SDL.h"
#include "device.h"
#include "util.h"
#include "RAM.h"
/*
E button map (3 lowest outputs driven, only 3 used, all 5 inputs used):
btn output input
up 1 2
down 1 1
left 1 0
right 1 3
center 1 4
H1 0 0
H2 0 1
H3 0 2
H4 0 3
pwr 0 4
*/
struct Device {
struct Tsc210x *tsc210x;
};
bool deviceHasGrafArea(void)
{
return true;
}
enum RomChipType deviceGetRomMemType(void)
{
return RomStrataFlash16x;
}
uint32_t deviceGetRamSize(void)
{
return 32UL << 20;
}
enum RamTermination deviceGetRamTerminationStyle(void)
{
return RamTerminationMirror;
}
uint_fast8_t deviceGetSocRev(void)
{
return 0;
}
struct Device* deviceSetup(struct SocPeriphs *sp, struct Keypad *kp, struct VSD *vsd, FILE* nandFile)
{
struct ArmRam *weirdBusAccess;
struct Device *dev;
uint_fast8_t i;
dev = (struct Device*)malloc(sizeof(*dev));
if (!dev)
ERR("cannot alloc device");
weirdBusAccess = ramInit(sp->mem, 0x08000000ul, 0x280, (uint32_t*)malloc(0x280));
if (!weirdBusAccess)
ERR("Cannot init RAM4");
//PINTDAV is gpio shared 6
dev->tsc210x = tsc210xInitUWire(sp->uw, 0, sp->gpio, 6, TscType2102);
if (!dev->tsc210x)
ERR("Cannot init TSC2102");
for (i = 0; i < 2; i++) {
if (!keypadDefineCol(kp, i, 32 + i))
ERR("Cannot init keypad col %u as gpio %u", i, 32 + i);
}
for (i = 0; i < 5; i++) {
if (!keypadDefineRow(kp, i, 40 + i))
ERR("Cannot init keypad row %u as gpio %u", i, 40 + i);
}
//shared 0: Vusb active high
socGpioSetState(sp->gpio, 0, false);
//shared 1: VCC_in (Vusb or Vac) active low
socGpioSetState(sp->gpio, 1, false);
//shared 8 is SD wreite protect (high if protected)
socGpioSetState(sp->gpio, 8, false);
//shared 14 is headphone detect (active high)
socGpioSetState(sp->gpio, 14, false);
//mpuio 2 is AC-power detect (active low)
socGpioSetState(sp->gpio, 16 + 2, false);
//mpuio 4 is sd card detect (active low)
socGpioSetState(sp->gpio, 16 + 4, !vsd);
//full battery
tsc210xSetExtAdc(dev->tsc210x, TscExternalAdcBat1, 4200);
//keys
if (!keypadAddMatrixKey(kp, SDLK_F1, 0, 0))
ERR("Cannot init hardkey1\n");
if (!keypadAddMatrixKey(kp, SDLK_F2, 1, 0))
ERR("Cannot init hardkey1\n");
if (!keypadAddMatrixKey(kp, SDLK_F3, 2, 0))
ERR("Cannot init hardkey1\n");
if (!keypadAddMatrixKey(kp, SDLK_F4, 3, 0))
ERR("Cannot init hardkey1\n");
if (!keypadAddMatrixKey(kp, SDLK_ESCAPE, 4, 0))
ERR("Cannot init power key\n");
if (!keypadAddMatrixKey(kp, SDLK_DOWN, 1, 1))
ERR("Cannot init down key\n");
if (!keypadAddMatrixKey(kp, SDLK_UP, 2, 1))
ERR("Cannot init up key\n");
if (!keypadAddMatrixKey(kp, SDLK_LEFT, 0, 1))
ERR("Cannot init left key\n");
if (!keypadAddMatrixKey(kp, SDLK_RIGHT, 3, 1))
ERR("Cannot init right key\n");
if (!keypadAddMatrixKey(kp, SDLK_RETURN, 4, 1))
ERR("Cannot init select key\n");
return dev;
}
void devicePeriodic(struct Device *dev, uint32_t cycles)
{
if(!(cycles & 0x00007FFFUL))
tsc210xPeriodic(dev->tsc210x);
}
void deviceTouch(struct Device *dev, int x, int y)
{
x = x >= 0 ? 966 - x * 28 / 10 : x;
y = y >= 0 ? 31 + 22 * y / 10 : y;
tsc210xPenInput(dev->tsc210x, x, y);
}
void deviceKey(struct Device *dev, uint32_t key, bool down)
{
//nothing
}