libjoybus
Joybus implementation for 32-bit MCUs
Loading...
Searching...
No Matches
gc_controller.h
1
7
8#pragma once
9
10#include <stdbool.h>
11
12#include <joybus/commands.h>
13#include <joybus/gamecube.h>
14#include <joybus/target.h>
15
17
19#define JOYBUS_GC_CONTROLLER(target) ((struct joybus_gc_controller *)(target))
20
26typedef void (*joybus_gc_controller_reset_cb_t)(struct joybus_gc_controller *controller);
27
34typedef void (*joybus_gc_controller_motor_cb_t)(struct joybus_gc_controller *controller, uint8_t state);
35
63
73void joybus_gc_controller_init(struct joybus_gc_controller *controller, uint16_t type);
74
86
98
106static inline bool joybus_gc_controller_is_wireless(struct joybus_gc_controller *controller)
107{
108 return joybus_id_get_type(controller->id) & JOYBUS_ID_GCN_WIRELESS;
109}
110
122void joybus_gc_controller_set_wireless_id(struct joybus_gc_controller *controller, uint16_t wireless_id);
123
131static inline uint16_t joybus_gc_controller_get_wireless_id(struct joybus_gc_controller *controller)
132{
133 return (controller->id[1] & 0xC0) << 2 | controller->id[2];
134}
135
146{
148}
149
159static inline void joybus_gc_controller_input_valid(struct joybus_gc_controller *controller, bool valid)
160{
161 controller->input_valid = valid;
162}
163
173 struct joybus_gc_controller_input *new_origin);
174
Joybus command codes and utilities.
#define JOYBUS_ID_GCN_WIRELESS_ID_FIXED
Wireless ID has been fixed.
Definition commands.h:97
static uint16_t joybus_id_get_type(const uint8_t *id)
Get the controller type from an "identify" buffer.
Definition commands.h:127
#define JOYBUS_ID_GCN_WIRELESS
Controller is wireless.
Definition commands.h:104
static uint16_t joybus_gc_controller_get_wireless_id(struct joybus_gc_controller *controller)
Get the current wireless ID of the controller.
Definition gc_controller.h:131
void joybus_gc_controller_set_origin(struct joybus_gc_controller *controller, struct joybus_gc_controller_input *new_origin)
Update the origin of the controller.
Definition gc_controller.c:400
static bool joybus_gc_controller_is_wireless(struct joybus_gc_controller *controller)
Check if the controller is a WaveBird controller.
Definition gc_controller.h:106
void joybus_gc_controller_init(struct joybus_gc_controller *controller, uint16_t type)
Initialize a GameCube controller.
Definition gc_controller.c:352
void joybus_gc_controller_set_wireless_id(struct joybus_gc_controller *controller, uint16_t wireless_id)
Set the wireless ID of the controller.
Definition gc_controller.c:388
void joybus_gc_controller_set_motor_callback(struct joybus_gc_controller *controller, joybus_gc_controller_motor_cb_t callback)
Set the motor state change callback for the controller.
Definition gc_controller.c:382
static bool joybus_gc_controller_wireless_id_fixed(struct joybus_gc_controller *controller)
Determine if the wireless ID has been fixed.
Definition gc_controller.h:145
void(* joybus_gc_controller_reset_cb_t)(struct joybus_gc_controller *controller)
Callback type for GameCube controller reset events.
Definition gc_controller.h:26
static void joybus_gc_controller_input_valid(struct joybus_gc_controller *controller, bool valid)
Mark the input state as valid.
Definition gc_controller.h:159
void(* joybus_gc_controller_motor_cb_t)(struct joybus_gc_controller *controller, uint8_t state)
Callback type for GameCube controller motor state change events.
Definition gc_controller.h:34
void joybus_gc_controller_set_reset_callback(struct joybus_gc_controller *controller, joybus_gc_controller_reset_cb_t callback)
Set the reset callback for the controller.
Definition gc_controller.c:376
GameCube controller input state.
Definition gamecube.h:32
GameCube controller Joybus target.
Definition gc_controller.h:39
joybus_gc_controller_motor_cb_t on_motor_state_change
Callback for controller motor state change events.
Definition gc_controller.h:61
joybus_gc_controller_reset_cb_t on_reset
Callback for controller reset events.
Definition gc_controller.h:58
uint8_t packed_input[8]
Packed input state buffer.
Definition gc_controller.h:52
struct joybus_gc_controller_input input
Current input state.
Definition gc_controller.h:49
struct joybus_target base
Controller ID.
Definition gc_controller.h:40
struct joybus_gc_controller_input origin
Origin input state.
Definition gc_controller.h:46
bool input_valid
Whether the input state is valid.
Definition gc_controller.h:55
A Joybus target, a device on the Joybus that can respond to commands.
Definition target.h:45