Gestion de la manette en mode 8bitPro - conversion vers data_gamepad generic
This commit is contained in:
parent
30b6c220f9
commit
c3295f047b
90
hid_app.c
90
hid_app.c
@ -47,9 +47,34 @@ static struct
|
|||||||
uint16_t vid, pid;
|
uint16_t vid, pid;
|
||||||
}hid_info[CFG_TUH_HID];
|
}hid_info[CFG_TUH_HID];
|
||||||
|
|
||||||
|
|
||||||
|
struct gamepad_data_t{
|
||||||
|
uint8_t joystick_x_gauche;
|
||||||
|
uint8_t joystick_y_gauche;
|
||||||
|
uint8_t joystick_x_droit;
|
||||||
|
uint8_t joystick_y_droit;
|
||||||
|
uint8_t gachette_gauche;
|
||||||
|
uint8_t gachette_droite;
|
||||||
|
uint8_t dpad;
|
||||||
|
bool bouton_A;
|
||||||
|
bool bouton_B;
|
||||||
|
bool bouton_X;
|
||||||
|
bool bouton_Y;
|
||||||
|
bool bouton_Start;
|
||||||
|
bool bouton_Select;
|
||||||
|
bool bouton_L;
|
||||||
|
bool bouton_L2;
|
||||||
|
bool bouton_R;
|
||||||
|
bool bouton_R2;
|
||||||
|
bool bouton_joystick_gauche;
|
||||||
|
bool bouton_joystick_droit;
|
||||||
|
};
|
||||||
|
|
||||||
static void process_kbd_report(hid_keyboard_report_t const *report);
|
static void process_kbd_report(hid_keyboard_report_t const *report);
|
||||||
static void process_mouse_report(hid_mouse_report_t const * report);
|
static void process_mouse_report(hid_mouse_report_t const * report);
|
||||||
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||||
|
void process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||||
|
void affiche_gamepad_data(struct gamepad_data_t _gamepad_report);
|
||||||
|
|
||||||
// HID report from 8bitPro
|
// HID report from 8bitPro
|
||||||
|
|
||||||
@ -76,8 +101,8 @@ typedef struct TU_ATTR_PACKED
|
|||||||
uint8_t x, y; // joystick Xg, Yg
|
uint8_t x, y; // joystick Xg, Yg
|
||||||
uint8_t z, rz; // joystick Xd, Yd
|
uint8_t z, rz; // joystick Xd, Yd
|
||||||
|
|
||||||
uint8_t gachette_droite; // ok
|
|
||||||
uint8_t gachette_gauche; // ok
|
uint8_t gachette_gauche; // ok
|
||||||
|
uint8_t gachette_droite; // ok
|
||||||
|
|
||||||
|
|
||||||
} _8bitpro_report_t ;
|
} _8bitpro_report_t ;
|
||||||
@ -115,6 +140,7 @@ typedef struct TU_ATTR_PACKED
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void hid_app_task(void)
|
void hid_app_task(void)
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
@ -199,7 +225,10 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// Generic report requires matching ReportID and contents with previous parsed report info
|
// Generic report requires matching ReportID and contents with previous parsed report info
|
||||||
|
// Report - 2dc8:6002 8BitDo 8BitDo SN30 Pro+
|
||||||
if(hid_info[instance].vid == 0x2dc8 && hid_info[instance].pid == 0x6002){
|
if(hid_info[instance].vid == 0x2dc8 && hid_info[instance].pid == 0x6002){
|
||||||
|
process_8bitpro_report(dev_addr, instance, report, len);
|
||||||
|
}else if(hid_info[instance].vid == 0x054c && hid_info[instance].pid == 0x054c){
|
||||||
process_generic_report(dev_addr, instance, report, len);
|
process_generic_report(dev_addr, instance, report, len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -316,6 +345,39 @@ static void process_mouse_report(hid_mouse_report_t const * report)
|
|||||||
cursor_movement(report->x, report->y, report->wheel);
|
cursor_movement(report->x, report->y, report->wheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Report - 2dc8:6002 8BitDo 8BitDo SN30 Pro+
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
void process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
||||||
|
struct gamepad_data_t gamepad_data;
|
||||||
|
_8bitpro_report_t gamepad_report;
|
||||||
|
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
||||||
|
|
||||||
|
// Copie des données du rapport vers la structure standard
|
||||||
|
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
||||||
|
gamepad_data.joystick_y_gauche = gamepad_report.y;
|
||||||
|
gamepad_data.joystick_x_droit = gamepad_report.z;
|
||||||
|
gamepad_data.joystick_y_droit = gamepad_report.rz;
|
||||||
|
gamepad_data.bouton_A = gamepad_report.b1;
|
||||||
|
gamepad_data.bouton_B = gamepad_report.b2;
|
||||||
|
gamepad_data.bouton_X = gamepad_report.b4;
|
||||||
|
gamepad_data.bouton_Y = gamepad_report.b5;
|
||||||
|
gamepad_data.bouton_L = gamepad_report.b7;
|
||||||
|
gamepad_data.bouton_R = gamepad_report.b8;
|
||||||
|
gamepad_data.bouton_L2 = gamepad_report.b9;
|
||||||
|
gamepad_data.bouton_R2 = gamepad_report.b10;
|
||||||
|
gamepad_data.bouton_Start = gamepad_report.b11;
|
||||||
|
gamepad_data.bouton_Select = gamepad_report.b12;
|
||||||
|
gamepad_data.bouton_joystick_gauche = gamepad_report.b15;
|
||||||
|
gamepad_data.bouton_joystick_droit = gamepad_report.b14;
|
||||||
|
gamepad_data.dpad = gamepad_report.hat_switch;
|
||||||
|
gamepad_data.gachette_droite = gamepad_report.gachette_droite;
|
||||||
|
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
||||||
|
|
||||||
|
affiche_gamepad_data(gamepad_data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Generic Report
|
// Generic Report
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -432,3 +494,29 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
|
|||||||
void process_gamepad_report(){
|
void process_gamepad_report(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void affiche_gamepad_data(struct gamepad_data_t _gamepad_report){
|
||||||
|
printf(">jxd:%d\n", _gamepad_report.joystick_x_gauche);
|
||||||
|
printf(">jyd:%d\n", _gamepad_report.joystick_y_gauche);
|
||||||
|
printf(">jxg:%d\n", _gamepad_report.joystick_x_droit);
|
||||||
|
printf(">jyg:%d\n", _gamepad_report.joystick_y_droit);
|
||||||
|
printf(">hat:%d\n", _gamepad_report.dpad);
|
||||||
|
|
||||||
|
printf(">ba:%d\n", _gamepad_report.bouton_A);
|
||||||
|
printf(">bb:%d\n", _gamepad_report.bouton_B);
|
||||||
|
printf(">bx:%d\n", _gamepad_report.bouton_X);
|
||||||
|
printf(">by:%d\n", _gamepad_report.bouton_Y);
|
||||||
|
printf(">bstart:%d\n", _gamepad_report.bouton_Start);
|
||||||
|
printf(">bselect:%d\n", _gamepad_report.bouton_Select);
|
||||||
|
printf(">bl:%d\n", _gamepad_report.bouton_L);
|
||||||
|
printf(">br:%d\n", _gamepad_report.bouton_R);
|
||||||
|
printf(">bl2:%d\n", _gamepad_report.bouton_L2);
|
||||||
|
printf(">br2:%d\n", _gamepad_report.bouton_R2);
|
||||||
|
printf(">bjg:%d\n", _gamepad_report.bouton_joystick_droit);
|
||||||
|
printf(">bjd:%d\n", _gamepad_report.bouton_joystick_gauche);
|
||||||
|
|
||||||
|
//printf(">data1:%d\n", _gamepad_report.data_1);
|
||||||
|
|
||||||
|
printf(">gd:%d\n", _gamepad_report.gachette_droite);
|
||||||
|
printf(">gg:%d\n", _gamepad_report.gachette_gauche);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user