blob: 26443c8c240aaf86b1d9947e81be8c59070bce9f (
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
|
/*
* Copyright (C) 2017 hatkirby
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#include "link.h"
#define JOY_WRITE 2
#define JOY_READ 4
#define JOY_RW 6
void initializeLink()
{
REG_HS_CTRL |= JOY_RW;
REG_JOYTR = 0;
while ((REG_HS_CTRL & JOY_WRITE) == 0);
REG_HS_CTRL |= JOY_RW;
}
void waitForAck()
{
while ((REG_HS_CTRL & JOY_WRITE) == 0);
REG_HS_CTRL |= JOY_RW;
REG_JOYTR = 0;
while ((REG_HS_CTRL & JOY_WRITE) == 0);
REG_HS_CTRL |= JOY_RW;
}
u32 waitForResponse()
{
u32 val;
REG_JOYTR = 1;
while ((REG_HS_CTRL & JOY_WRITE) == 0);
val = REG_JOYRE;
REG_HS_CTRL |= JOY_RW;
REG_JOYTR = 0;
while ((REG_HS_CTRL & JOY_WRITE) == 0);
REG_HS_CTRL |= JOY_RW;
return val;
}
void sendS32(s32 val)
{
REG_JOYTR = val;
}
void sendU32(u32 val)
{
REG_JOYTR = val;
}
void directSendU32(u32 val)
{
REG_JOYTR = val;
while ((REG_HS_CTRL & JOY_READ) == 0);
REG_HS_CTRL |= JOY_RW;
}
|