Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/input/joycon.h
1476 views
1
/*
2
* Ambient light sensor driver for Nintendo Switch's Rohm BH1730
3
*
4
* Copyright (c) 2018 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef __JOYCON_H_
20
#define __JOYCON_H_
21
22
#include <utils/types.h>
23
24
#define JC_BTNS_DIRECTION_PAD 0xF0000
25
#define JC_BTNS_PREV_NEXT 0x800080
26
#define JC_BTNS_ENTER 0x400008
27
#define JC_BTNS_ESC 0x4
28
29
#define JC_BTNS_ALL (JC_BTNS_PREV_NEXT | JC_BTNS_ENTER | JC_BTNS_DIRECTION_PAD | JC_BTNS_ESC)
30
31
typedef struct _jc_bt_conn_t
32
{
33
u8 type;
34
u8 mac[6];
35
u8 host_mac[6];
36
u8 ltk[16];
37
} jc_bt_conn_t;
38
39
typedef struct _jc_gamepad_rpt_t
40
{
41
union
42
{
43
struct
44
{
45
// Joy-Con (R).
46
/*00*/ u32 y:1;
47
/*01*/ u32 x:1;
48
/*02*/ u32 b:1;
49
/*03*/ u32 a:1;
50
/*04*/ u32 sr_r:1;
51
/*05*/ u32 sl_r:1;
52
/*06*/ u32 r:1;
53
/*07*/ u32 zr:1;
54
55
// Shared
56
/*08*/ u32 minus:1;
57
/*09*/ u32 plus:1;
58
/*10*/ u32 r3:1;
59
/*11*/ u32 l3:1;
60
/*12*/ u32 home:1;
61
/*13*/ u32 cap:1;
62
/*14*/ u32 pad:1;
63
/*15*/ u32 wired:1;
64
65
// Joy-Con (L).
66
/*16*/ u32 down:1;
67
/*17*/ u32 up:1;
68
/*18*/ u32 right:1;
69
/*19*/ u32 left:1;
70
/*20*/ u32 sr_l:1;
71
/*21*/ u32 sl_l:1;
72
/*22*/ u32 l:1;
73
/*23*/ u32 zl:1;
74
};
75
u32 buttons;
76
};
77
78
u16 lstick_x;
79
u16 lstick_y;
80
u16 rstick_x;
81
u16 rstick_y;
82
bool center_stick_l;
83
bool center_stick_r;
84
bool conn_l;
85
bool conn_r;
86
bool sio_mode;
87
u8 batt_info_l; // Also Sio Connected status.
88
u8 batt_info_r; // Also Sio IRQ.
89
jc_bt_conn_t bt_conn_l;
90
jc_bt_conn_t bt_conn_r;
91
} jc_gamepad_rpt_t;
92
93
typedef struct _jc_calib_t
94
{
95
u16 x_max:12;
96
u16 y_max:12;
97
u16 x_center:12;
98
u16 y_center:12;
99
u16 x_min:12;
100
u16 y_min:12;
101
} __attribute__((packed)) jc_calib_t;
102
103
void jc_init_hw();
104
void jc_deinit();
105
jc_gamepad_rpt_t *joycon_poll();
106
jc_gamepad_rpt_t *jc_get_bt_pairing_info(bool *is_l_hos, bool *is_r_hos);
107
108
#endif
109
110