Add stateful HD-rumble decoder with TinyUSB report normalization
Decode Nintendo HD-rumble words once in firmware into conventional low/high magnitudes and normalize stripped control SET_REPORT vs complete interrupt OUT reports through one path.
This commit is contained in:
parent
20c9c98f89
commit
bce94d38ce
21 changed files with 902 additions and 180 deletions
46
switch_haptics.h
Normal file
46
switch_haptics.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef SWITCH_HAPTICS_H
|
||||
#define SWITCH_HAPTICS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct SwitchRumbleOutput {
|
||||
uint8_t low_frequency_magnitude;
|
||||
uint8_t high_frequency_magnitude;
|
||||
};
|
||||
|
||||
size_t normalize_switch_output_report(uint8_t report_id,
|
||||
const uint8_t* payload,
|
||||
size_t payload_size,
|
||||
uint8_t output[64]);
|
||||
|
||||
class SwitchHapticsDecoder {
|
||||
public:
|
||||
SwitchHapticsDecoder();
|
||||
|
||||
void reset();
|
||||
SwitchRumbleOutput decode(const uint8_t payload[8]);
|
||||
|
||||
private:
|
||||
struct ActuatorState {
|
||||
uint8_t high_amplitude;
|
||||
uint8_t low_amplitude;
|
||||
uint8_t high_frequency;
|
||||
uint8_t low_frequency;
|
||||
uint32_t last_word;
|
||||
bool have_last_word;
|
||||
};
|
||||
|
||||
struct AmplitudePeak {
|
||||
uint8_t low;
|
||||
uint8_t high;
|
||||
};
|
||||
|
||||
static void reset_actuator(ActuatorState& state);
|
||||
static AmplitudePeak decode_actuator(ActuatorState& state, uint32_t word);
|
||||
static uint8_t amplitude_to_magnitude(uint8_t amplitude_index);
|
||||
|
||||
ActuatorState actuators_[2];
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue