libdragon
Loading...
Searching...
No Matches
controller.h
Go to the documentation of this file.
1
8#ifndef __LIBDRAGON_CONTROLLER_H
9#define __LIBDRAGON_CONTROLLER_H
10
11#include <stdint.h>
12
13#include "joybus.h"
14#include "joybus_accessory.h"
15#include "joypad.h"
16
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/*****************************************************************************
27 * Deprecated API
28 *
29 * The following API is deprecated and will be removed in the future.
30 * This API is being kept for compatibility with existing code. The
31 * implementation is now based on the Joypad Subsystem, which fixes
32 * several deficiencies and implements first-class support for GameCube
33 * controllers. The Controller Subsystem will emit deprecation warnings
34 * when used and suggest replacement functions and data structures.
35 ****************************************************************************/
36
45#define CONTROLLER_1_INSERTED 0xF000
47#define CONTROLLER_2_INSERTED 0x0F00
49#define CONTROLLER_3_INSERTED 0x00F0
51#define CONTROLLER_4_INSERTED 0x000F
62#define ACCESSORY_NONE 0
64#define ACCESSORY_MEMPAK 1
66#define ACCESSORY_RUMBLEPAK 2
68#define ACCESSORY_VRU 3
70#define ACCESSORY_TRANSFERPAK 4
81#define ERROR_NONE 0x0
83#define ERROR_BAD_COMMAND 0x1
85#define ERROR_NOT_PRESENT 0x2
97typedef struct SI_condat
98{
100 unsigned : 16;
102 unsigned err : 2;
104 unsigned : 14;
105
106 union
107 {
108 struct
109 {
111 unsigned int data : 32;
112 };
113 struct
114 {
116 unsigned A : 1;
118 unsigned B : 1;
120 unsigned Z : 1;
122 unsigned start : 1;
124 unsigned up : 1;
126 unsigned down : 1;
128 unsigned left : 1;
130 unsigned right : 1;
132 unsigned : 2;
134 unsigned L : 1;
136 unsigned R : 1;
138 unsigned C_up : 1;
140 unsigned C_down : 1;
142 unsigned C_left : 1;
144 unsigned C_right : 1;
146 signed x : 8;
148 signed y : 8;
149 };
150 };
151} _SI_condat;
152
162typedef struct SI_condat_gc
163{
164 union
165 {
166 struct
167 {
169 uint64_t data;
170 };
171 struct
172 {
173 unsigned err : 2;
174 unsigned origin_unchecked : 1;
175 unsigned start : 1;
176 unsigned y : 1;
177 unsigned x : 1;
178 unsigned b : 1;
179 unsigned a : 1;
180 unsigned unused2 : 1;
181 unsigned l : 1;
182 unsigned r : 1;
183 unsigned z : 1;
184 unsigned up : 1;
185 unsigned down : 1;
186 unsigned right : 1;
187 unsigned left : 1;
188 unsigned stick_x : 8;
189 unsigned stick_y : 8;
190
191 unsigned cstick_x : 8;
192 unsigned cstick_y : 8;
193 unsigned analog_l : 8;
194 unsigned analog_r : 8;
195 };
196 };
198
208 struct SI_condat_gc data;
209 uint8_t deadzone0;
210 uint8_t deadzone1;
211};
212
223typedef struct controller_data
224{
226 struct SI_condat c[4];
228 struct SI_condat_gc gc[4];
230
237typedef struct controller_origin_data
238{
240 struct SI_origdat_gc gc[4];
242
243/**************************************
244 * DEPRECATED FUNCTIONS
245 **************************************/
246
248
249__attribute__((deprecated("use joybus_exec_cmd instead")))
250void execute_raw_command(
251 int controller,
252 uint8_t command_id,
253 size_t send_len,
254 size_t recv_len,
255 const void *send_data,
256 void *recv_data
257);
258
259__attribute__((deprecated("use joypad_read_n64_inputs instead")))
260void controller_read( struct controller_data * data );
261
262__attribute__((deprecated("use joypad_get_inputs instead")))
263void controller_read_gc( struct controller_data * data, const uint8_t rumble[4] );
264
265__attribute__((deprecated("use joypad subsystem instead")))
266void controller_read_gc_origin( struct controller_origin_data * data);
267
268__attribute__((deprecated("use joypad_init instead")))
269void controller_init( void );
270
271__attribute__((deprecated("use joypad_poll instead")))
272void controller_scan( void );
273
274__attribute__((deprecated("use joypad_get_buttons_pressed instead")))
275struct controller_data get_keys_down( void );
276
277__attribute__((deprecated("use joypad_get_buttons_released instead")))
278struct controller_data get_keys_up( void );
279
280__attribute__((deprecated("use joypad_get_buttons_held instead")))
281struct controller_data get_keys_held( void );
282
283__attribute__((deprecated("use joypad_get_inputs instead")))
284struct controller_data get_keys_pressed( void );
285
286__attribute__((deprecated("use joypad_get_identifier instead")))
287int get_controllers_present( void );
288
289__attribute__((deprecated("use joypad_get_accessory_type instead")))
290int get_accessories_present( struct controller_data * data );
291
292__attribute__((deprecated("use joypad_get_accessory_type instead")))
293int identify_accessory( int controller );
294
295__attribute__((deprecated("use joypad_get_direction instead")))
296int get_dpad_direction( int controller );
297
298__attribute__((deprecated("use joybus_accessory_read instead")))
299int read_mempak_address( int controller, uint16_t address, uint8_t *data );
300
301__attribute__((deprecated("use joybus_accessory_write instead")))
302int write_mempak_address( int controller, uint16_t address, uint8_t *data );
303
304__attribute__((deprecated("use joypad_set_rumble_active instead")))
305void rumble_start( int controller );
306
307__attribute__((deprecated("use joypad_set_rumble_active instead")))
308void rumble_stop( int controller );
309
311
312#ifdef __cplusplus
313}
314#endif
315
/* controller */
317
318#endif
unsigned err
Status of the last command.
Definition controller.h:102
SI GameCube controller origin data for all controller ports.
Definition controller.h:238
SI controller data for all controller ports.
Definition controller.h:224
SI GameCube controller origin data.
Definition controller.h:207
SI Nintendo 64 controller data.
Definition controller.h:98
SI GameCube controller data.
Definition controller.h:163
int joybus_accessory_read(int port, uint16_t addr, uint8_t *data)
Synchronously perform a Joybus N64 accessory read command.
Definition joybus_accessory.c:132
int joybus_accessory_write(int port, uint16_t addr, const uint8_t *data)
Synchronously perform a Joybus N64 accessory write command.
Definition joybus_accessory.c:146
void joypad_set_rumble_active(joypad_port_t port, bool active)
Activate or deactivate rumble on a Joypad port.
Definition joypad.c:918
joypad_8way_t joypad_get_direction(joypad_port_t port, joypad_2d_t axes)
Get the 8-way direction for a Joypad port's directional axes.
Definition joypad.c:1106
joypad_inputs_t joypad_read_n64_inputs(joypad_port_t port)
Read the inputs from a Nintendo 64 controller synchronously.
Definition joypad.c:687
joypad_inputs_t joypad_get_inputs(joypad_port_t port)
Get the current Joypad inputs state for a Joypad port.
Definition joypad.c:940
joypad_accessory_type_t joypad_get_accessory_type(joypad_port_t port)
Get the Joypad accessory type for a Joypad port.
Definition joypad.c:876
void joypad_init(void)
Initialize the Joypad subsystem.
Definition joypad.c:713
joypad_buttons_t joypad_get_buttons_released(joypad_port_t port)
Get the Joypad buttons that were released since the last time Joypads were read for a Joypad port.
Definition joypad.c:964
void joypad_poll(void)
Fetch the current Joypad input state.
Definition joypad.c:750
joypad_buttons_t joypad_get_buttons_held(joypad_port_t port)
Get the Joypad buttons that are held down since the last time Joypads were read for a Joypad port.
Definition joypad.c:973
joypad_buttons_t joypad_get_buttons_pressed(joypad_port_t port)
Get the Joypad buttons that were pressed since the last time Joypads were read for a Joypad port.
Definition joypad.c:955
joybus_identifier_t joypad_get_identifier(joypad_port_t port)
Get the Joybus device identifier for a Joypad port.
Definition joypad.c:862
Joybus Subsystem.
Joybus accessory utilities.
Joypad Subsystem.