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/gamecube.h>
13#include <joybus/target.h>
14
16
18#define JOYBUS_GC_CONTROLLER(target) ((struct joybus_gc_controller *)(target))
19
25typedef void (*joybus_gc_controller_reset_cb_t)(struct joybus_gc_controller *controller);
26
33typedef void (*joybus_gc_controller_motor_cb_t)(struct joybus_gc_controller *controller, uint8_t state);
34
62
72void joybus_gc_controller_init(struct joybus_gc_controller *controller, uint16_t type);
73
81static inline bool joybus_gc_controller_is_wireless(struct joybus_gc_controller *controller)
82{
83 return joybus_id_get_type(controller->id) & JOYBUS_ID_GCN_WIRELESS;
84}
85
97void joybus_gc_controller_set_wireless_id(struct joybus_gc_controller *controller, uint16_t wireless_id);
98
106static inline uint16_t joybus_gc_controller_get_wireless_id(struct joybus_gc_controller *controller)
107{
108 return (controller->id[1] & 0xC0) << 2 | controller->id[2];
109}
110
121{
123}
124
134static inline void joybus_gc_controller_input_valid(struct joybus_gc_controller *controller, bool valid)
135{
136 controller->input_valid = valid;
137}
138
148 struct joybus_gc_controller_input *new_origin);
149
#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:106
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:377
static bool joybus_gc_controller_is_wireless(struct joybus_gc_controller *controller)
Check if the controller is a WaveBird controller.
Definition gc_controller.h:81
void joybus_gc_controller_init(struct joybus_gc_controller *controller, uint16_t type)
Initialize a GameCube controller.
Definition gc_controller.c:341
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:365
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:120
void(* joybus_gc_controller_reset_cb_t)(struct joybus_gc_controller *controller)
Callback type for GameCube controller reset events.
Definition gc_controller.h:25
static void joybus_gc_controller_input_valid(struct joybus_gc_controller *controller, bool valid)
Mark the input state as valid.
Definition gc_controller.h:134
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:33
GameCube controller input state.
Definition gamecube.h:32
GameCube controller Joybus target.
Definition gc_controller.h:38
joybus_gc_controller_motor_cb_t on_motor_state_change
Callback for controller motor state change events.
Definition gc_controller.h:60
joybus_gc_controller_reset_cb_t on_reset
Callback for controller reset events.
Definition gc_controller.h:57
uint8_t packed_input[8]
Packed input state buffer.
Definition gc_controller.h:51
struct joybus_gc_controller_input input
Current input state.
Definition gc_controller.h:48
struct joybus_target base
Controller ID.
Definition gc_controller.h:39
struct joybus_gc_controller_input origin
Origin input state.
Definition gc_controller.h:45
bool input_valid
Whether the input state is valid.
Definition gc_controller.h:54
A Joybus target, a device on the Joybus that can respond to commands.
Definition target.h:45