mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-25 03:02:26 +00:00
Merge branch 'master' into renesas-ra
This commit is contained in:
commit
cd1726c009
20
.pre-commit-config.yaml
Normal file
20
.pre-commit-config.yaml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: codespell
|
||||||
|
name: codespell
|
||||||
|
entry: codespell
|
||||||
|
types_or: [c, header]
|
||||||
|
language: system
|
||||||
|
|
||||||
|
- id: unit-test
|
||||||
|
name: unit-test
|
||||||
|
files: ^(src/|test/unit-test/)
|
||||||
|
entry: sh -c "cd test/unit-test && ceedling test:all"
|
||||||
|
pass_filenames: false
|
||||||
|
types_or: [c, header]
|
||||||
|
language: system
|
@ -91,9 +91,8 @@ typedef struct TU_ATTR_PACKED
|
|||||||
uint8_t counter : 6; // +1 each report
|
uint8_t counter : 6; // +1 each report
|
||||||
};
|
};
|
||||||
|
|
||||||
// comment out since not used by this example
|
uint8_t l2_trigger; // 0 released, 0xff fully pressed
|
||||||
// uint8_t l2_trigger; // 0 released, 0xff fully pressed
|
uint8_t r2_trigger; // as above
|
||||||
// uint8_t r2_trigger; // as above
|
|
||||||
|
|
||||||
// uint16_t timestamp;
|
// uint16_t timestamp;
|
||||||
// uint8_t battery;
|
// uint8_t battery;
|
||||||
@ -105,6 +104,45 @@ typedef struct TU_ATTR_PACKED
|
|||||||
|
|
||||||
} sony_ds4_report_t;
|
} sony_ds4_report_t;
|
||||||
|
|
||||||
|
typedef struct TU_ATTR_PACKED {
|
||||||
|
// First 16 bits set what data is pertinent in this structure (1 = set; 0 = not set)
|
||||||
|
uint8_t set_rumble : 1;
|
||||||
|
uint8_t set_led : 1;
|
||||||
|
uint8_t set_led_blink : 1;
|
||||||
|
uint8_t set_ext_write : 1;
|
||||||
|
uint8_t set_left_volume : 1;
|
||||||
|
uint8_t set_right_volume : 1;
|
||||||
|
uint8_t set_mic_volume : 1;
|
||||||
|
uint8_t set_speaker_volume : 1;
|
||||||
|
uint8_t set_flags2;
|
||||||
|
|
||||||
|
uint8_t reserved;
|
||||||
|
|
||||||
|
uint8_t motor_right;
|
||||||
|
uint8_t motor_left;
|
||||||
|
|
||||||
|
uint8_t lightbar_red;
|
||||||
|
uint8_t lightbar_green;
|
||||||
|
uint8_t lightbar_blue;
|
||||||
|
uint8_t lightbar_blink_on;
|
||||||
|
uint8_t lightbar_blink_off;
|
||||||
|
|
||||||
|
uint8_t ext_data[8];
|
||||||
|
|
||||||
|
uint8_t volume_left;
|
||||||
|
uint8_t volume_right;
|
||||||
|
uint8_t volume_mic;
|
||||||
|
uint8_t volume_speaker;
|
||||||
|
|
||||||
|
uint8_t other[9];
|
||||||
|
} sony_ds4_output_report_t;
|
||||||
|
|
||||||
|
static bool ds4_mounted = false;
|
||||||
|
static uint8_t ds4_dev_addr = 0;
|
||||||
|
static uint8_t ds4_instance = 0;
|
||||||
|
static uint8_t motor_left = 0;
|
||||||
|
static uint8_t motor_right = 0;
|
||||||
|
|
||||||
// check if device is Sony DualShock 4
|
// check if device is Sony DualShock 4
|
||||||
static inline bool is_sony_ds4(uint8_t dev_addr)
|
static inline bool is_sony_ds4(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
@ -124,7 +162,23 @@ static inline bool is_sony_ds4(uint8_t dev_addr)
|
|||||||
|
|
||||||
void hid_app_task(void)
|
void hid_app_task(void)
|
||||||
{
|
{
|
||||||
// nothing to do
|
if (ds4_mounted)
|
||||||
|
{
|
||||||
|
const uint32_t interval_ms = 200;
|
||||||
|
static uint32_t start_ms = 0;
|
||||||
|
|
||||||
|
uint32_t current_time_ms = board_millis();
|
||||||
|
if ( current_time_ms - start_ms >= interval_ms)
|
||||||
|
{
|
||||||
|
start_ms = current_time_ms;
|
||||||
|
|
||||||
|
sony_ds4_output_report_t output_report = {0};
|
||||||
|
output_report.set_rumble = 1;
|
||||||
|
output_report.motor_left = motor_left;
|
||||||
|
output_report.motor_right = motor_right;
|
||||||
|
tuh_hid_send_report(ds4_dev_addr, ds4_instance, 5, &output_report, sizeof(output_report));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -149,6 +203,14 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
|||||||
// Sony DualShock 4 [CUH-ZCT2x]
|
// Sony DualShock 4 [CUH-ZCT2x]
|
||||||
if ( is_sony_ds4(dev_addr) )
|
if ( is_sony_ds4(dev_addr) )
|
||||||
{
|
{
|
||||||
|
if (!ds4_mounted)
|
||||||
|
{
|
||||||
|
ds4_dev_addr = dev_addr;
|
||||||
|
ds4_instance = instance;
|
||||||
|
motor_left = 0;
|
||||||
|
motor_right = 0;
|
||||||
|
ds4_mounted = true;
|
||||||
|
}
|
||||||
// request to receive report
|
// request to receive report
|
||||||
// tuh_hid_report_received_cb() will be invoked when report is available
|
// tuh_hid_report_received_cb() will be invoked when report is available
|
||||||
if ( !tuh_hid_receive_report(dev_addr, instance) )
|
if ( !tuh_hid_receive_report(dev_addr, instance) )
|
||||||
@ -162,6 +224,10 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
|||||||
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
|
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
|
||||||
{
|
{
|
||||||
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
|
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
|
||||||
|
if (ds4_mounted && ds4_dev_addr == dev_addr && ds4_instance == instance)
|
||||||
|
{
|
||||||
|
ds4_mounted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if different than 2
|
// check if different than 2
|
||||||
@ -179,8 +245,8 @@ bool diff_report(sony_ds4_report_t const* rpt1, sony_ds4_report_t const* rpt2)
|
|||||||
result = diff_than_2(rpt1->x, rpt2->x) || diff_than_2(rpt1->y , rpt2->y ) ||
|
result = diff_than_2(rpt1->x, rpt2->x) || diff_than_2(rpt1->y , rpt2->y ) ||
|
||||||
diff_than_2(rpt1->z, rpt2->z) || diff_than_2(rpt1->rz, rpt2->rz);
|
diff_than_2(rpt1->z, rpt2->z) || diff_than_2(rpt1->rz, rpt2->rz);
|
||||||
|
|
||||||
// check the reset with mem compare
|
// check the rest with mem compare
|
||||||
result |= memcmp(&rpt1->rz + 1, &rpt2->rz + 1, sizeof(sony_ds4_report_t)-4);
|
result |= memcmp(&rpt1->rz + 1, &rpt2->rz + 1, sizeof(sony_ds4_report_t)-6);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -234,6 +300,10 @@ void process_sony_ds4(uint8_t const* report, uint16_t len)
|
|||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The left and right triggers control the intensity of the left and right rumble motors
|
||||||
|
motor_left = ds4_report.l2_trigger;
|
||||||
|
motor_right = ds4_report.r2_trigger;
|
||||||
|
|
||||||
prev_report = ds4_report;
|
prev_report = ds4_report;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,49 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
|
|||||||
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
|
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, const void* report, uint16_t len)
|
||||||
|
{
|
||||||
|
TU_LOG2("HID Send Report %d\r\n", report_id);
|
||||||
|
|
||||||
|
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||||
|
|
||||||
|
if (hid_itf->ep_out == 0)
|
||||||
|
{
|
||||||
|
// This HID does not have an out endpoint (other than control)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (len > CFG_TUH_HID_EPOUT_BUFSIZE
|
||||||
|
|| (report_id != 0 && len > (CFG_TUH_HID_EPOUT_BUFSIZE - 1)))
|
||||||
|
{
|
||||||
|
// ep_out buffer is not large enough to hold contents
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// claim endpoint
|
||||||
|
TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_out) );
|
||||||
|
|
||||||
|
if (report_id == 0)
|
||||||
|
{
|
||||||
|
// No report ID in transmission
|
||||||
|
memcpy(&hid_itf->epout_buf[0], report, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hid_itf->epout_buf[0] = report_id;
|
||||||
|
memcpy(&hid_itf->epout_buf[1], report, len);
|
||||||
|
++len; // 1 more byte for report_id
|
||||||
|
}
|
||||||
|
|
||||||
|
TU_LOG3_MEM(hid_itf->epout_buf, len, 2);
|
||||||
|
|
||||||
|
if ( !usbh_edpt_xfer(dev_addr, hid_itf->ep_out, hid_itf->epout_buf, len) )
|
||||||
|
{
|
||||||
|
usbh_edpt_release(dev_addr, hid_itf->ep_out);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USBH API
|
// USBH API
|
||||||
|
@ -106,7 +106,7 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance);
|
|||||||
|
|
||||||
// Send report using interrupt endpoint
|
// Send report using interrupt endpoint
|
||||||
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
|
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
|
||||||
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, const void* report, uint16_t len);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Callbacks (Weak is optional)
|
// Callbacks (Weak is optional)
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
|
|
||||||
#define CI_HS_REG(_port) ((ci_hs_regs_t*) _ci_controller[_port].reg_base)
|
#define CI_HS_REG(_port) ((ci_hs_regs_t*) _ci_controller[_port].reg_base)
|
||||||
|
|
||||||
|
// Clean means to push any cached changes to RAM and invalidate "removes" the
|
||||||
|
// entry from the cache.
|
||||||
#if defined(__CORTEX_M) && __CORTEX_M == 7 && __DCACHE_PRESENT == 1
|
#if defined(__CORTEX_M) && __CORTEX_M == 7 && __DCACHE_PRESENT == 1
|
||||||
#define CleanInvalidateDCache_by_Addr SCB_CleanInvalidateDCache_by_Addr
|
#define CleanInvalidateDCache_by_Addr SCB_CleanInvalidateDCache_by_Addr
|
||||||
#else
|
#else
|
||||||
@ -199,6 +201,8 @@ static void bus_reset(uint8_t rhport)
|
|||||||
_dcd_data.qhd[0][0].qtd_overlay.next = _dcd_data.qhd[0][1].qtd_overlay.next = QTD_NEXT_INVALID;
|
_dcd_data.qhd[0][0].qtd_overlay.next = _dcd_data.qhd[0][1].qtd_overlay.next = QTD_NEXT_INVALID;
|
||||||
|
|
||||||
_dcd_data.qhd[0][0].int_on_setup = 1; // OUT only
|
_dcd_data.qhd[0][0].int_on_setup = 1; // OUT only
|
||||||
|
|
||||||
|
CleanInvalidateDCache_by_Addr((uint32_t*) &_dcd_data, sizeof(dcd_data_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_init(uint8_t rhport)
|
void dcd_init(uint8_t rhport)
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_RP2040) && !CFG_TUD_RPI_PIO_USB
|
#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_RP2040) && !CFG_TUD_RPI_PIO_USB
|
||||||
|
|
||||||
#include "pico.h"
|
#include "pico.h"
|
||||||
|
#include "hardware/sync.h"
|
||||||
#include "rp2040_usb.h"
|
#include "rp2040_usb.h"
|
||||||
|
|
||||||
#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
|
#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
|
||||||
@ -384,6 +385,11 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void)
|
|||||||
/* Controller API
|
/* Controller API
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// older SDK
|
||||||
|
#ifndef PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY
|
||||||
|
#define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff
|
||||||
|
#endif
|
||||||
|
|
||||||
void dcd_init (uint8_t rhport)
|
void dcd_init (uint8_t rhport)
|
||||||
{
|
{
|
||||||
assert(rhport == 0);
|
assert(rhport == 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user