Fonction USB sur core1, récupération des données sur core0
This commit is contained in:
parent
6734142f03
commit
7f11642b10
@ -64,6 +64,7 @@ target_link_libraries( host_cdc_msc_hid PUBLIC
|
|||||||
hardware_spi
|
hardware_spi
|
||||||
hardware_sync
|
hardware_sync
|
||||||
pico_aon_timer
|
pico_aon_timer
|
||||||
|
pico_multicore
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
${HWDEP_LIBS}
|
${HWDEP_LIBS}
|
||||||
)
|
)
|
||||||
|
|||||||
65
hid_app.c
65
hid_app.c
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "bsp/board_api.h"
|
#include "bsp/board_api.h"
|
||||||
#include "gamepad.h"
|
#include "gamepad.h"
|
||||||
|
#include "hid_app.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -48,35 +49,15 @@ static struct
|
|||||||
}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);
|
struct gamepad_data_t process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||||
void process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
struct gamepad_data_t process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||||
void process_BDA_NSW_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
struct gamepad_data_t process_BDA_NSW_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);
|
void affiche_gamepad_data(struct gamepad_data_t _gamepad_report);
|
||||||
|
void refresh_gamepad_data(struct gamepad_data_t * gamepad_data);
|
||||||
|
|
||||||
// HID report from 8bitPro
|
// HID report from 8bitPro
|
||||||
|
|
||||||
@ -163,6 +144,8 @@ typedef struct TU_ATTR_PACKED
|
|||||||
|
|
||||||
} BDA_NSW_report_t ;
|
} BDA_NSW_report_t ;
|
||||||
|
|
||||||
|
struct gamepad_data_t gamepad_data;
|
||||||
|
|
||||||
|
|
||||||
void hid_app_task(void)
|
void hid_app_task(void)
|
||||||
{
|
{
|
||||||
@ -250,11 +233,11 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
|||||||
// 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+
|
// 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);
|
gamepad_data = process_8bitpro_report(dev_addr, instance, report, len);
|
||||||
}else if(hid_info[instance].vid == 0x054c && hid_info[instance].pid == 0x05c4){
|
}else if(hid_info[instance].vid == 0x054c && hid_info[instance].pid == 0x05c4){
|
||||||
process_SonyDualShock4_report(dev_addr, instance, report, len);
|
gamepad_data = process_SonyDualShock4_report(dev_addr, instance, report, len);
|
||||||
}else if(hid_info[instance].vid == 0x20d6 && hid_info[instance].pid == 0xa713){
|
}else if(hid_info[instance].vid == 0x20d6 && hid_info[instance].pid == 0xa713){
|
||||||
process_BDA_NSW_report(dev_addr, instance, report, len);
|
gamepad_data = process_BDA_NSW_report(dev_addr, instance, report, len);
|
||||||
}else{
|
}else{
|
||||||
process_generic_report(dev_addr, instance, report, len);
|
process_generic_report(dev_addr, instance, report, len);
|
||||||
}
|
}
|
||||||
@ -375,10 +358,11 @@ static void process_mouse_report(hid_mouse_report_t const * report)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Report - 2dc8:6002 8BitDo 8BitDo SN30 Pro+
|
// 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 process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
||||||
struct gamepad_data_t gamepad_data;
|
struct gamepad_data_t gamepad_data;
|
||||||
_8bitpro_report_t gamepad_report;
|
_8bitpro_report_t gamepad_report;
|
||||||
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
||||||
|
refresh_gamepad_data(&gamepad_data);
|
||||||
|
|
||||||
// Copie des données du rapport vers la structure standard
|
// Copie des données du rapport vers la structure standard
|
||||||
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
||||||
@ -402,16 +386,18 @@ void process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* r
|
|||||||
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
||||||
|
|
||||||
affiche_gamepad_data(gamepad_data);
|
affiche_gamepad_data(gamepad_data);
|
||||||
|
return gamepad_data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// 054c:05c4 Sony Corp. DualShock 4 [CUH-ZCT1x]
|
// 054c:05c4 Sony Corp. DualShock 4 [CUH-ZCT1x]
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
struct gamepad_data_t process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
||||||
struct gamepad_data_t gamepad_data;
|
struct gamepad_data_t gamepad_data;
|
||||||
SonyDualShock4_report_t gamepad_report;
|
SonyDualShock4_report_t gamepad_report;
|
||||||
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
||||||
|
refresh_gamepad_data(&gamepad_data);
|
||||||
|
|
||||||
// Copie des données du rapport vers la structure standard
|
// Copie des données du rapport vers la structure standard
|
||||||
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
||||||
@ -430,21 +416,23 @@ void process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t c
|
|||||||
gamepad_data.bouton_L2 = gamepad_report.b7;
|
gamepad_data.bouton_L2 = gamepad_report.b7;
|
||||||
gamepad_data.bouton_R = gamepad_report.b6;
|
gamepad_data.bouton_R = gamepad_report.b6;
|
||||||
gamepad_data.bouton_L = gamepad_report.b5;
|
gamepad_data.bouton_L = gamepad_report.b5;
|
||||||
gamepad_data.dpad = gamepad_report.hat_switch;
|
gamepad_data.dpad = gamepad_report.hat_switch;
|
||||||
gamepad_data.gachette_droite = gamepad_report.gachette_droite;
|
gamepad_data.gachette_droite = gamepad_report.gachette_droite;
|
||||||
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
||||||
|
|
||||||
affiche_gamepad_data(gamepad_data);
|
affiche_gamepad_data(gamepad_data);
|
||||||
|
return gamepad_data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Report - 20d6:a713 BDA NSW wired controller
|
// Report - 20d6:a713 BDA NSW wired controller
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void process_BDA_NSW_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
struct gamepad_data_t process_BDA_NSW_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
||||||
struct gamepad_data_t gamepad_data;
|
struct gamepad_data_t gamepad_data;
|
||||||
BDA_NSW_report_t gamepad_report;
|
BDA_NSW_report_t gamepad_report;
|
||||||
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
||||||
|
refresh_gamepad_data(&gamepad_data);
|
||||||
|
|
||||||
// Copie des données du rapport vers la structure standard
|
// Copie des données du rapport vers la structure standard
|
||||||
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
||||||
@ -470,6 +458,7 @@ void process_BDA_NSW_report(uint8_t dev_addr, uint8_t instance, uint8_t const* r
|
|||||||
gamepad_data.dpad = gamepad_report.hat_switch;
|
gamepad_data.dpad = gamepad_report.hat_switch;
|
||||||
|
|
||||||
affiche_gamepad_data(gamepad_data);
|
affiche_gamepad_data(gamepad_data);
|
||||||
|
return gamepad_data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,4 +570,16 @@ void affiche_gamepad_data(struct gamepad_data_t _gamepad_report){
|
|||||||
|
|
||||||
printf(">gd:%d\n", _gamepad_report.gachette_droite);
|
printf(">gd:%d\n", _gamepad_report.gachette_droite);
|
||||||
printf(">gg:%d\n", _gamepad_report.gachette_gauche);
|
printf(">gg:%d\n", _gamepad_report.gachette_gauche);
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh_gamepad_data(struct gamepad_data_t * gamepad_data){
|
||||||
|
gamepad_data->temps_ms = (uint32_t) get_absolute_time() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gamepad_connecte(){
|
||||||
|
return ((get_absolute_time() / 1000) - gamepad_data.temps_ms < 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gamepad_data_t get_gamepad_data(){
|
||||||
|
return gamepad_data;
|
||||||
}
|
}
|
||||||
29
hid_app.h
Normal file
29
hid_app.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct gamepad_data_t{
|
||||||
|
uint32_t temps_ms;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool gamepad_connecte();
|
||||||
|
struct gamepad_data_t get_gamepad_data();
|
||||||
30
main.c
30
main.c
@ -28,7 +28,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bsp/board_api.h"
|
#include "bsp/board_api.h"
|
||||||
|
#include "hid_app.h"
|
||||||
#include "lib/sd_driver/sd_card.h"
|
#include "lib/sd_driver/sd_card.h"
|
||||||
|
#include "pico/multicore.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "f_util.h"
|
#include "f_util.h"
|
||||||
@ -101,6 +103,22 @@ sd_card_t* sd_get_by_num(size_t num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usb_routine(){
|
||||||
|
while (1) {
|
||||||
|
// tinyusb host task
|
||||||
|
tuh_task();
|
||||||
|
|
||||||
|
led_blinking_task();
|
||||||
|
cdc_app_task();
|
||||||
|
hid_app_task();
|
||||||
|
|
||||||
|
|
||||||
|
//log_to_sd(big_big_buffer);
|
||||||
|
//log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------- MAIN -------------*/
|
/*------------- MAIN -------------*/
|
||||||
int main(void) {
|
int main(void) {
|
||||||
@ -154,14 +172,22 @@ int main(void) {
|
|||||||
strcat(big_big_buffer, buffer);
|
strcat(big_big_buffer, buffer);
|
||||||
size += strlen(buffer);
|
size += strlen(buffer);
|
||||||
}
|
}
|
||||||
|
multicore_launch_core1(usb_routine);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// tinyusb host task
|
// tinyusb host task
|
||||||
tuh_task();
|
/*tuh_task();
|
||||||
|
|
||||||
led_blinking_task();
|
led_blinking_task();
|
||||||
cdc_app_task();
|
cdc_app_task();
|
||||||
hid_app_task();
|
hid_app_task();*/
|
||||||
|
if(gamepad_connecte()){
|
||||||
|
struct gamepad_data_t gamepad_data;
|
||||||
|
gamepad_data = get_gamepad_data();
|
||||||
|
printf(">joystique_xd:%d\n", gamepad_data.joystick_x_gauche);
|
||||||
|
}
|
||||||
|
printf(">gc:%d\n", gamepad_connecte());
|
||||||
|
sleep_ms(1);
|
||||||
//log_to_sd(big_big_buffer);
|
//log_to_sd(big_big_buffer);
|
||||||
//log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB)
|
//log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user