|
libjoybus
Joybus implementation for 32-bit MCUs
|
Commands for communicating with GameCube and N64 controllers. More...
Typedefs | |
| typedef void(* | joybus_n64_accessory_detect_cb_t) (int accessory_type, void *user_data) |
| Callback type for N64 accessory detection. | |
Enumerations | |
| enum | joybus_n64_accessory_type { JOYBUS_N64_ACCESSORY_NONE = 0 , JOYBUS_N64_ACCESSORY_UNKNOWN , JOYBUS_N64_ACCESSORY_CONTROLLER_PAK , JOYBUS_N64_ACCESSORY_RUMBLE_PAK , JOYBUS_N64_ACCESSORY_TRANSFER_PAK , JOYBUS_N64_ACCESSORY_BIO_SENSOR , JOYBUS_N64_ACCESSORY_SNAP_STATION } |
| N64 controller accessory types. More... | |
Functions | |
| int | joybus_identify (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Identify the target device attached to the Joybus. | |
| int | joybus_reset (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Reset the target device attached to the Joybus. | |
| int | joybus_gcn_read (struct joybus *bus, enum joybus_gcn_analog_mode analog_mode, enum joybus_gcn_motor_state motor_state, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Read the current input state of a GameCube controller. | |
| int | joybus_gcn_read_origin (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Read the origin (neutral) state of a GameCube controller. | |
| int | joybus_gcn_calibrate (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Calibrate a GameCube controller, setting its current input state as the origin. | |
| int | joybus_gcn_read_long (struct joybus *bus, enum joybus_gcn_motor_state motor_state, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Read the current input state of a GameCube controller, with full precision. | |
| int | joybus_gcn_probe_device (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Send a "probe device" command to a WaveBird controller. | |
| int | joybus_gcn_fix_device (struct joybus *bus, uint16_t wireless_id, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Send a "fix device" command to a WaveBird controller. | |
| int | joybus_gcn_unpack_input (struct joybus_gc_controller_input *dest, const uint8_t *src, enum joybus_gcn_analog_mode analog_mode) |
| Unpack raw input data from a GameCube controller. | |
| int | joybus_n64_read (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Read the current input state of an N64 controller. | |
| int | joybus_n64_accessory_write (struct joybus *bus, uint16_t addr, const uint8_t *data, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Write data to a N64 controller's accessory port. | |
| int | joybus_n64_accessory_read (struct joybus *bus, uint16_t addr, uint8_t *response, joybus_transfer_cb_t callback, void *user_data) |
| Read data from a N64 controller's accessory port. | |
| void | joybus_n64_accessory_detect (struct joybus *bus, joybus_n64_accessory_detect_cb_t callback, void *user_data) |
| Detect the accessory connected to a N64 controller. | |
| void | joybus_n64_motor_start (struct joybus *bus) |
| Start the rumble motor in a N64 Rumble Pak. | |
| void | joybus_n64_motor_stop (struct joybus *bus) |
| Stop the rumble motor in a N64 Rumble Pak. | |
Commands for communicating with GameCube and N64 controllers.
N64 specific Joybus commands.
GameCube specific Joybus commands.
Common Joybus commands.
| typedef void(* joybus_n64_accessory_detect_cb_t) (int accessory_type, void *user_data) |
Callback type for N64 accessory detection.
| accessory_type | the detected accessory type, one of JOYBUS_N64_ACCESSORY_* |
| user_data | user data passed to the detection function |
N64 controller accessory types.
| int joybus_gcn_calibrate | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Calibrate a GameCube controller, setting its current input state as the origin.
| bus | the Joybus to use |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_CALIBRATE_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_fix_device | ( | struct joybus * | bus, |
| uint16_t | wireless_id, | ||
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Send a "fix device" command to a WaveBird controller.
Non-wireless controllers will ignore this command. If successful, the response buffer will contain the updated controller ID.
| bus | the Joybus to use |
| wireless_id | the 10-bit wireless ID to fix the controller to |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_FIX_DEVICE_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_probe_device | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Send a "probe device" command to a WaveBird controller.
Non-wireless controllers will ignore this command.
| bus | the Joybus to use |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_PROBE_DEVICE_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_read | ( | struct joybus * | bus, |
| enum joybus_gcn_analog_mode | analog_mode, | ||
| enum joybus_gcn_motor_state | motor_state, | ||
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Read the current input state of a GameCube controller.
| bus | the Joybus to use |
| analog_mode | the analog mode to use (one of JOYBUS_GCN_ANALOG_MODE_*) |
| motor_state | the motor state to use (one of JOYBUS_GCN_MOTOR_*) |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_read_long | ( | struct joybus * | bus, |
| enum joybus_gcn_motor_state | motor_state, | ||
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Read the current input state of a GameCube controller, with full precision.
| bus | the Joybus to use |
| motor_state | the motor state to use (one of JOYBUS_GCN_MOTOR_*) |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_LONG_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_read_origin | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Read the origin (neutral) state of a GameCube controller.
| bus | the Joybus to use |
| response | buffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_ORIGIN_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_gcn_unpack_input | ( | struct joybus_gc_controller_input * | dest, |
| const uint8_t * | src, | ||
| enum joybus_gcn_analog_mode | analog_mode ) |
Unpack raw input data from a GameCube controller.
The "full" internal input state of a GameCube controller is 10 bytes long, so there are various ways to "pack" the input state into 8 bytes. Depending on the analog mode, either one pair of analog inputs can be omitted, or two pairs of analog inputs can be truncated to 4 bits.
All production games, with the exception of Luigi's Mansion, use analog mode 3. This mode omits the analog A/B inputs, and sends the substick X/Y and triggers at full precision. Analog A/B buttons were only present in pre-production GameCube controllers.
| dest | pointer to a joybus_gc_controller_input struct to store the unpacked data |
| src | pointer to the response buffer from a "read" command |
| analog_mode | the analog mode used when reading (one of JOYBUS_GCN_ANALOG_MODE_*) |
| int joybus_identify | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Identify the target device attached to the Joybus.
Calls the provided callback when complete. The response buffer will be populated with a 3-byte response containing the device ID and status.
| bus | the Joybus to use |
| response | buffer to store the response in |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| void joybus_n64_accessory_detect | ( | struct joybus * | bus, |
| joybus_n64_accessory_detect_cb_t | callback, | ||
| void * | user_data ) |
Detect the accessory connected to a N64 controller.
This function initiates an asynchronous sequence of commands to detect the accessory type. The provided callback will be called with the detected accessory type once the detection sequence is complete.
| bus | the Joybus to use |
| callback | a callback function to call when the detection is complete |
| user_data | user data to pass to the callback function |
| int joybus_n64_accessory_read | ( | struct joybus * | bus, |
| uint16_t | addr, | ||
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Read data from a N64 controller's accessory port.
Address checksum is automatically calculated.
| bus | the Joybus to use |
| addr | the address to read from, must be 32-byte aligned |
| response | buffer to store the response in, must be at least JOYBUS_CMD_N64_ACCESSORY_READ_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_n64_accessory_write | ( | struct joybus * | bus, |
| uint16_t | addr, | ||
| const uint8_t * | data, | ||
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Write data to a N64 controller's accessory port.
Address checksum is automatically calculated.
| bus | the Joybus to use |
| addr | the address to write to, must be 32-byte aligned |
| data | the data to write |
| response | buffer to store the response in, must be at least JOYBUS_CMD_N64_WRITE_MEM_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| void joybus_n64_motor_start | ( | struct joybus * | bus | ) |
Start the rumble motor in a N64 Rumble Pak.
| bus | the Joybus to use |
| void joybus_n64_motor_stop | ( | struct joybus * | bus | ) |
Stop the rumble motor in a N64 Rumble Pak.
| bus | the Joybus to use |
| int joybus_n64_read | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Read the current input state of an N64 controller.
| bus | the Joybus to use |
| response | buffer to store the response in, must be at least JOYBUS_CMD_N64_READ_RX bytes |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |
| int joybus_reset | ( | struct joybus * | bus, |
| uint8_t * | response, | ||
| joybus_transfer_cb_t | callback, | ||
| void * | user_data ) |
Reset the target device attached to the Joybus.
| bus | the Joybus to use |
| response | buffer to store the response in |
| callback | a callback function to call when the transfer is complete |
| user_data | user data to pass to the callback function |