libjoybus
Joybus implementation for 32-bit MCUs
Loading...
Searching...
No Matches
gcn_controller.h
1
9
10#pragma once
11
12#include <stdbool.h>
13
14#include <joybus/identify.h>
15#include <joybus/target.h>
17
19
21#define JOYBUS_TARGET_GCN_CONTROLLER(target) ((struct joybus_target_gcn_controller *)(target))
22
29
36typedef void (*joybus_target_gcn_controller_motor_cb)(struct joybus_target_gcn_controller *controller, uint8_t state);
37
66
74
84
94
106
118
126{
127 return controller->id.type & JOYBUS_TYPE_GCN_WIRELESS;
128}
129
142 uint16_t wireless_id);
143
151{
152 return joybus_id_get_wireless_id(&controller->id);
153}
154
164{
165 return controller->id.type & JOYBUS_TYPE_GCN_WIRELESS_ID_FIXED;
166}
167
177static inline void joybus_target_gcn_controller_input_valid(struct joybus_target_gcn_controller *controller, bool valid)
178{
179 controller->input_valid = valid;
180}
181
191 struct joybus_gcn_controller_state *new_origin);
192
Common definitions for GameCube controllers.
static bool joybus_target_gcn_controller_is_wireless(struct joybus_target_gcn_controller *controller)
Check if the controller is a WaveBird controller.
Definition gcn_controller.h:125
static void joybus_target_gcn_controller_input_valid(struct joybus_target_gcn_controller *controller, bool valid)
Mark the input state as valid.
Definition gcn_controller.h:177
void joybus_target_gcn_controller_set_reset_cb(struct joybus_target_gcn_controller *controller, joybus_target_gcn_controller_reset_cb callback)
Set the reset callback for the controller.
Definition gcn_controller.c:364
void joybus_target_gcn_controller_init_with_type(struct joybus_target_gcn_controller *controller, uint16_t type)
Initialize a GameCube controller target with a specific controller type.
Definition gcn_controller.c:339
void joybus_target_gcn_controller_set_origin(struct joybus_target_gcn_controller *controller, struct joybus_gcn_controller_state *new_origin)
Update the origin of the controller.
Definition gcn_controller.c:388
void(* joybus_target_gcn_controller_motor_cb)(struct joybus_target_gcn_controller *controller, uint8_t state)
Callback type for GameCube controller motor state change events.
Definition gcn_controller.h:36
void(* joybus_target_gcn_controller_reset_cb)(struct joybus_target_gcn_controller *controller)
Callback type for GameCube controller reset events.
Definition gcn_controller.h:28
static bool joybus_target_gcn_controller_wireless_id_fixed(struct joybus_target_gcn_controller *controller)
Determine if the wireless ID has been fixed.
Definition gcn_controller.h:163
void joybus_target_gcn_controller_set_motor_cb(struct joybus_target_gcn_controller *controller, joybus_target_gcn_controller_motor_cb callback)
Set the motor state change callback for the controller.
Definition gcn_controller.c:370
static void joybus_target_gcn_controller_init_wavebird(struct joybus_target_gcn_controller *controller)
Initialize a GameCube controller target as a WaveBird receiver.
Definition gcn_controller.h:90
void joybus_target_gcn_controller_set_wireless_id(struct joybus_target_gcn_controller *controller, uint16_t wireless_id)
Set the wireless ID of the controller.
Definition gcn_controller.c:376
static uint16_t joybus_target_gcn_controller_get_wireless_id(struct joybus_target_gcn_controller *controller)
Get the current wireless ID of the controller.
Definition gcn_controller.h:150
static void joybus_target_gcn_controller_init(struct joybus_target_gcn_controller *controller)
Initialize a GameCube controller target as a regular wired controller.
Definition gcn_controller.h:80
Joybus device identification values and utilities.
#define JOYBUS_DEVICE_GCN_WAVEBIRD
WaveBird receiver (DOL-005)
Definition identify.h:93
static uint16_t joybus_id_get_wireless_id(const struct joybus_id *id)
Get the 10-bit wireless ID from an "identify" buffer.
Definition identify.h:156
#define JOYBUS_DEVICE_GCN_CONTROLLER
GameCube controller (DOL-003)
Definition identify.h:90
#define JOYBUS_TYPE_GCN_WIRELESS
Controller is wireless.
Definition identify.h:43
uint16_t type
Type flags.
Definition identify.h:1
#define JOYBUS_TYPE_GCN_WIRELESS_ID_FIXED
Wireless ID has been fixed.
Definition identify.h:44
GameCube controller input/origin state.
Definition gcn_controller.h:43
Represents the 3-byte ID field from an "identify" buffer.
Definition identify.h:98
uint16_t type
Type flags.
Definition identify.h:100
GameCube controller Joybus target.
Definition gcn_controller.h:41
joybus_target_gcn_controller_reset_cb on_reset
Callback for controller reset events.
Definition gcn_controller.h:61
joybus_target_gcn_controller_motor_cb on_motor_state_change
Callback for controller motor state change events.
Definition gcn_controller.h:64
struct joybus_target base
Base target interface.
Definition gcn_controller.h:43
struct joybus_id id
Controller ID.
Definition gcn_controller.h:46
struct joybus_gcn_controller_state origin
Origin input state.
Definition gcn_controller.h:49
bool input_valid
Whether the input state is valid.
Definition gcn_controller.h:58
struct joybus_gcn_controller_state input
Current input state.
Definition gcn_controller.h:52
uint8_t packed_input[8]
Packed input state buffer.
Definition gcn_controller.h:55
Interface for a Joybus target, a device on the Joybus which responds to commands from a host.
Definition target.h:69