From 089b1a50137ab8de3c117fec0330a0aa23da30cf Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 13:33:45 +0000 Subject: [PATCH 1/6] Add `WENCGetEncodeData` --- include/padscore/wpad.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/padscore/wpad.h b/include/padscore/wpad.h index d449c5d0..c222f418 100644 --- a/include/padscore/wpad.h +++ b/include/padscore/wpad.h @@ -34,6 +34,7 @@ typedef struct WPADStatusMotionPlus WPADStatusMotionPlus; typedef struct WPADStatusBalanceBoard WPADStatusBalanceBoard; typedef struct WPADStatusTrain WPADStatusTrain; typedef WPADStatusProController WPADStatusPro; +typedef struct WENCParams WENCParams; typedef enum WPADError { @@ -740,6 +741,13 @@ struct WPADAddress WUT_CHECK_OFFSET(WPADAddress, 0x00, btDeviceAddress); WUT_CHECK_SIZE(WPADAddress, 0x6); +//! Continuation parameters for WENCGetEncodeData +struct WENCParams +{ + WUT_UNKNOWN_BYTES(32); +}; +WUT_CHECK_SIZE(WENCParams, 32); + typedef void (*WPADCallback)(WPADChan channel, WPADError status); typedef WPADCallback WPADControlLedCallback; typedef WPADCallback WPADControlDpdCallback; @@ -893,6 +901,23 @@ WPADSendStreamData(WPADChan channel, void *data, uint32_t size); +/** + * Encode 16-bit LPCM as 4-bit Yamaha ADPCM + * \param params encoding continuation params, written on first call, and read and updated on each subsequent call + * \param continuing should be TRUE if continuing encoding stream with the params produced via a prior call + * \param samples 16-bit LPCM sample buffer + * \param sampleCount number of 16-bit LPCM samples + * \param outEncodedData buffer for the returned adpcm samples, buffer size should be equal to {(sampleCount + 1) / 2} + * \return Number of LPCM-16 samples + * \sa WPADSendStreamData + */ +uint32_t +WENCGetEncodeData(WENCParams *params, + BOOL continuing, + const int16_t *samples, + uint32_t sampleCount, + uint8_t *outEncodedData); + /** * Returns the global Wii Remote speaker volume */ From 98c919fa166bd6c0f2d1b286be5375c62623ac26 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 14:03:23 +0000 Subject: [PATCH 2/6] `const` and out --- include/padscore/wpad.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/padscore/wpad.h b/include/padscore/wpad.h index c222f418..ed38c0cb 100644 --- a/include/padscore/wpad.h +++ b/include/padscore/wpad.h @@ -898,7 +898,7 @@ WPADCanSendStreamData(WPADChan channel); */ WPADError WPADSendStreamData(WPADChan channel, - void *data, + const void *data, uint32_t size); /** @@ -933,11 +933,11 @@ WPADSetSpeakerVolume(uint8_t volume); /** * Gets whether MotionPlus is enabled for the WPAD - * \param enabled is set if MotionPlus is enabled + * \param outEnabled is set to true if MotionPlus is enabled */ int32_t WPADIsMplsAttached(WPADChan channel, - BOOL *enabled, + BOOL *outEnabled, WPADCallback callback); /** @@ -956,6 +956,7 @@ WPADGetInfo(WPADChan channel, /** * Retrieves status info from the controller asynchronously + * \param callback pointer to function called when info is obtained */ WPADError WPADGetInfoAsync(WPADChan channel, @@ -1222,7 +1223,7 @@ WPADiIsAvailableCmdQueue(WPADiQueue *queue, */ int32_t WPADiHIDParser(WPADChan channel, - uint8_t *hidData); + const uint8_t *hidData); /** @@ -1372,7 +1373,7 @@ WPADiGetGameType(void); * - WPADiWriteGameData */ void -WPADSetGameTitleUtf16(uint16_t *title); +WPADSetGameTitleUtf16(const uint16_t *title); /** * Gets game title stored on specified controller @@ -1392,7 +1393,7 @@ WPADGetGameTitleUtf16(WPADChan channel, */ WPADError WPADGetGameDataTimestamp(WPADChan channel, - OSTime *timestamp); + OSTime *outTimestamp); /** * Write custom game data to the controller's EEPROM @@ -1413,7 +1414,7 @@ WPADGetGameDataTimestamp(WPADChan channel, */ WPADError WPADiWriteGameData(WPADChan channel, - void *source, + const void *source, uint16_t size, uint32_t offset, WPADCallback callback); From ea29036691cc8d284ca41315354c65906548e93b Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 14:27:42 +0000 Subject: [PATCH 3/6] WPADInfo changes --- include/padscore/wpad.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/padscore/wpad.h b/include/padscore/wpad.h index ed38c0cb..15245b25 100644 --- a/include/padscore/wpad.h +++ b/include/padscore/wpad.h @@ -690,11 +690,11 @@ WUT_CHECK_SIZE(WPADStatusTrain, 0x2e); //! Controller status info struct WPADInfo { - uint32_t irEnabled; - uint32_t speakerEnabled; - uint32_t extensionAttached; - uint32_t batteryLow; - uint32_t batteryNearEmpty; + BOOL irEnabled; + BOOL speakerEnabled; + BOOL extensionAttached; + BOOL batteryLow; + BOOL speakerBufNearEmpty; uint8_t batteryLevel; uint8_t led; uint8_t protocol; @@ -704,7 +704,7 @@ WUT_CHECK_OFFSET(WPADInfo, 0x00, irEnabled); WUT_CHECK_OFFSET(WPADInfo, 0x04, speakerEnabled); WUT_CHECK_OFFSET(WPADInfo, 0x08, extensionAttached); WUT_CHECK_OFFSET(WPADInfo, 0x0c, batteryLow); -WUT_CHECK_OFFSET(WPADInfo, 0x10, batteryNearEmpty); +WUT_CHECK_OFFSET(WPADInfo, 0x10, speakerBufNearEmpty); WUT_CHECK_OFFSET(WPADInfo, 0x14, batteryLevel); WUT_CHECK_OFFSET(WPADInfo, 0x15, led); WUT_CHECK_OFFSET(WPADInfo, 0x16, protocol); @@ -949,6 +949,8 @@ WPADIsMplsIntegrated(WPADChan channel); /** * Retrieves status info from the controller + * \return WPAD_ERROR_NO_CONTROLLER if info request fails + * \return WPAD_ERROR_NOT_READY if controller is not connected */ WPADError WPADGetInfo(WPADChan channel, From 8a6e2d877dbb8e3c393675d357721ff63b039689 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 14:29:45 +0000 Subject: [PATCH 4/6] WPADInfo changes --- include/padscore/wpad.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/padscore/wpad.h b/include/padscore/wpad.h index 15245b25..0a52fb15 100644 --- a/include/padscore/wpad.h +++ b/include/padscore/wpad.h @@ -959,6 +959,8 @@ WPADGetInfo(WPADChan channel, /** * Retrieves status info from the controller asynchronously * \param callback pointer to function called when info is obtained + * \return WPAD_ERROR_NO_CONTROLLER if info request fails + * \return WPAD_ERROR_NOT_READY if controller is not connected */ WPADError WPADGetInfoAsync(WPADChan channel, From cd797b2096088df17dc9c51bf4cfa7f202ab3465 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 15:22:48 +0000 Subject: [PATCH 5/6] Add `KPADSetSamplingCallback` --- include/padscore/kpad.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/padscore/kpad.h b/include/padscore/kpad.h index 0de8ac1a..5079bc14 100644 --- a/include/padscore/kpad.h +++ b/include/padscore/kpad.h @@ -338,6 +338,7 @@ WUT_CHECK_OFFSET(KPADUnifiedWpadStatus, 0x40, format); WUT_CHECK_SIZE(KPADUnifiedWpadStatus, 0x44); typedef WPADConnectCallback KPADConnectCallback; +typedef WPADSamplingCallback KPADSamplingCallback; //! Callback used for `KPADSetControlMplsCallback()`. typedef void (*KPADControlMplsCallback)(KPADChan chan, KPADControlMplsStatus status); @@ -461,6 +462,13 @@ KPADConnectCallback KPADSetConnectCallback(KPADChan chan, KPADConnectCallback callback); +/** + * Same usage as \link WPADSetSamplingCallback\endlink, except compatible with other KPAD functions + */ +KPADSamplingCallback +KPADSetSamplingCallback(KPADChan channel, + KPADSamplingCallback callback); + /** * Returns the amount of memory needed for `KPADSetMplsWorkarea()`. */ From 37bb9841b98eb4e139bda24b6d21d22b8bd08ab7 Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Sun, 2 Feb 2025 16:07:40 +0000 Subject: [PATCH 6/6] Miscellaneous comment changes --- include/padscore/wpad.h | 45 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/include/padscore/wpad.h b/include/padscore/wpad.h index 0a52fb15..f8d66566 100644 --- a/include/padscore/wpad.h +++ b/include/padscore/wpad.h @@ -892,9 +892,13 @@ WPADCanSendStreamData(WPADChan channel); * make sure the data is in the format the speaker was initialized for, * (4-bit Yamaha ADPCM by default) * \param data audio encoded in initialized format - * \param size number of bytes to send + * \param size number of bytes to send, up to 20 bytes may be sent per call * \return `WPAD_ERROR_NOT_READY`, if not possible to send data at this moment - * \return `WPAD_ERROR_NO_CONTROLLER`, if channel is invalid, data is null or size is more than 20 + * \return `WPAD_ERROR_NO_CONTROLLER`, if channel is invalid, data is NULL or size is more than 20 + * + * \sa WPADControlSpeaker + * \sa WPADCanSendStreamData + * \sa WENCGetEncodeData */ WPADError WPADSendStreamData(WPADChan channel, @@ -909,6 +913,7 @@ WPADSendStreamData(WPADChan channel, * \param sampleCount number of 16-bit LPCM samples * \param outEncodedData buffer for the returned adpcm samples, buffer size should be equal to {(sampleCount + 1) / 2} * \return Number of LPCM-16 samples + * * \sa WPADSendStreamData */ uint32_t @@ -925,8 +930,8 @@ uint8_t WPADGetSpeakerVolume(void); /** - * Sets the global Wii Remote speaker volume - * only applies to later initialized Wii Remote speakers + * Sets the global Wii Remote speaker volume. + * Only applies to Wii Remotes whose speakers are initialized after this call. */ void WPADSetSpeakerVolume(uint8_t volume); @@ -971,11 +976,10 @@ WPADGetInfoAsync(WPADChan channel, * Reads from the device's memory * \param destination where the received data will be stored * \param size number of bytes to read - * \param address - * device memory address, see + * \param address device memory address, see * EEPROM Memory and * Control Registers - * \param completionCallback function to be called upon completion + * \param callback function to be called upon completion * \sa * - WPADWriteMemoryAsync() * - WPADReadExtReg() @@ -991,8 +995,7 @@ WPADReadMemoryAsync(WPADChan channel, * Writes to the device's memory * \param source data to be written to the controller * \param size number of bytes to write - * \param address - * device memory address, see + * \param address device memory address, see * EEPROM Memory and * Control Registers * \param callback function to be called upon completion @@ -1025,6 +1028,7 @@ WPADReadExtReg(WPADChan channel, /** * Writes to the registers of the Wii Remote's peripherals * \param address address within the peripheral's memory space + * \param peripheral target peripheral memory area * \sa * - WPADWriteMemoryAsync() * - WPADReadExtReg() @@ -1032,8 +1036,7 @@ WPADReadExtReg(WPADChan channel, * Usage: * \code * // Setting speaker volume on specific controller - * uint8_t volume; - * volume = 0x40; + * uint8_t volume = 0x40; * WPADWriteExtReg(WPAD_CHAN_0, &volume, 1, WPAD_PERIPHERAL_SPACE_SPEAKER, 0x05, nullptr); * \endcode */ @@ -1132,8 +1135,8 @@ BOOL WPADStartSyncDevice(void); /** - * Starts attempts to sync with a WPAD with the specified properties, - * if unable to do so, starts a normal sync as with WPADStartSyncDevice + * Starts attempts to sync with a WPAD with the specified properties. + * If unable to find a device, does the same as \link WPADStartSyncDevice \endlink * \param deviceAddress Bluetooth address of the device to connect to. * \param deviceName Bluetooth name of the device to connect to (up to 24 characters) * \return TRUE if sync started @@ -1142,8 +1145,8 @@ WPADStartSyncDevice(void); * \code * WPADAddress addr; * memset(&addr, 0x10, 6); - * // Initially searches for device with address 10:10:10:10:10:10 and name "Nintendo" - * WPADStartSyncDeviceEx(&addr, "Nintendo"); + * // Initially searches for device with address 10:10:10:10:10:10 and name "Nintendo RVL-CNT-01" (Wii Remote) + * WPADStartSyncDeviceEx(&addr, "Nintendo RVL-CNT-01"); * \endcode */ BOOL @@ -1156,6 +1159,8 @@ WPADStartSyncDeviceEx(WPADAddress* deviceAddress, * - `WPAD_ERROR_NONE` when controller connects. * - `WPAD_ERROR_NO_CONTROLLER` when controller disconnects. * \return the previously used callback + * + * \warning May overwrite callbacks used internally by KPAD. If using KPAD, \link KPADSetConnectCallback \endlink is preferable. */ WPADConnectCallback WPADSetConnectCallback(WPADChan channel, @@ -1197,6 +1202,8 @@ WPADGetLatestIndexInBuf(WPADChan channel); * Registers a callback to be invoked whenever new `WPADStatus*` data is stored in the * ring buffer. * + * \warning May overwrite callbacks used internally by KPAD. If using KPAD, \link KPADSetSamplingCallback \endlink is preferable. + * * \sa * - `WPADSetAutoSamplingBuf()` * - `WPADGetLatestIndexInBuf()` @@ -1291,8 +1298,8 @@ WPADiSendEnableDPDCSB(WPADiQueue *cmdQueue, WPADCallback callback); /** - * Queues HID Report for enabling speakers - * used internally by \link WPADControlSpeaker \link + * Queues HID Report for enabling speakers. + * Used internally by \link WPADControlSpeaker \link * \return TRUE if successfully added to queue */ BOOL @@ -1332,7 +1339,7 @@ WPADiSendWriteDataCmd(WPADiQueue *cmdQueue, /** * Queues HID Report for a multi-byte memory write - * used internally by \link WPADWriteMemory \endlink + * used internally by \link WPADWriteMemoryAsync \endlink * \return TRUE if successfully added to queue */ BOOL @@ -1344,7 +1351,7 @@ WPADiSendWriteData(WPADiQueue *cmdQueue, /** * Queues HID Report for a memory read - * used internally by \link WPADReadMemory \endlink + * used internally by \link WPADReadMemoryAsync \endlink * \return TRUE if successfully added to queue */ BOOL