forked from OpenStickCommunity/GP2040-CE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRV8833-Based Rumble (for XInput) (OpenStickCommunity#1090)
* Captured rumble data -> featureData * Add endpoint_out_checked and initial write to xinput_out_buffer * Copy to featureData during endpoint_out claim * Revert to simpler logic (endpoint_out always checked in process) * Add GamepadRumbleState, update rumble state in XInput driver * Create hard-coded DRV8833RumbleAddon, test 0 and 255 values * Fix rumble state comparison * Add rumble duty rescaling * Properly handle case where one motor is zero and other is non-zero * Working in WebConfig * Remove leftover debug code
- Loading branch information
1 parent
9ef24e5
commit c309d35
Showing
15 changed files
with
536 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef RUMBLE_H_ | ||
#define RUMBLE_H_ | ||
|
||
#include <vector> | ||
#include <string> | ||
#include "gpaddon.h" | ||
#include "gamepad/GamepadState.h" | ||
|
||
#ifndef DRV8833_RUMBLE_ENABLED | ||
#define DRV8833_RUMBLE_ENABLED 0 | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_LEFT_MOTOR_PIN | ||
#define DRV8833_RUMBLE_LEFT_MOTOR_PIN -1 //26 | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_RIGHT_MOTOR_PIN | ||
#define DRV8833_RUMBLE_RIGHT_MOTOR_PIN -1 //27 | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_MOTOR_SLEEP_PIN | ||
#define DRV8833_RUMBLE_MOTOR_SLEEP_PIN -1 //22 | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_PWM_FREQUENCY | ||
#define DRV8833_RUMBLE_PWM_FREQUENCY 10000 // 10 kHz | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_DUTY_MIN | ||
#define DRV8833_RUMBLE_DUTY_MIN 0.0f | ||
#endif | ||
|
||
#ifndef DRV8833_RUMBLE_DUTY_MAX | ||
#define DRV8833_RUMBLE_DUTY_MAX 100.0f | ||
#endif | ||
|
||
// DRV8833 Rumble Module | ||
#define DRV8833RumbleName "DRV8833Rumble" | ||
|
||
// Scale uint8 to 0 -> 100 range | ||
#define motorToDuty(m) (100.0f * (m/255.0f)) | ||
// Rescale from 0 -> 100 range to min -> max range | ||
#define scaleDuty(in, min, max) ((in/100.0f) * (max-min) + min) | ||
|
||
// Buzzer Speaker | ||
class DRV8833RumbleAddon : public GPAddon | ||
{ | ||
public: | ||
virtual bool available(); | ||
virtual void setup(); | ||
virtual void preprocess() {} | ||
virtual void process(); | ||
virtual std::string name() { return DRV8833RumbleName; } | ||
private: | ||
uint32_t pwmSetFreqDuty(uint slice, uint channel, uint32_t frequency, float duty); | ||
bool compareRumbleState(Gamepad * gamepad); | ||
void setRumbleState(Gamepad * gamepad); | ||
void disableMotors(); | ||
void enableMotors(Gamepad * gamepad); | ||
uint8_t leftMotorPin; | ||
uint8_t rightMotorPin; | ||
uint8_t motorSleepPin; | ||
uint8_t leftMotorPinSlice; | ||
uint8_t leftMotorPinChannel; | ||
uint8_t rightMotorPinSlice; | ||
uint8_t rightMotorPinChannel; | ||
uint32_t pwmFrequency; | ||
float dutyMin; | ||
float dutyMax; | ||
uint32_t sysClock; | ||
GamepadRumbleState currentRumbleState; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.