@@ -71,10 +71,16 @@ typedef struct _jc_cal_t
|
||||
u16 cry_min;
|
||||
} jc_cal_t;
|
||||
|
||||
enum {
|
||||
INPUT_POLL_HAS_PACKET,
|
||||
INPUT_POLL_NO_PACKET,
|
||||
INPUT_POLL_EXIT,
|
||||
};
|
||||
|
||||
static jc_cal_t jc_cal_ctx;
|
||||
static usb_ops_t usb_ops;
|
||||
|
||||
static bool _jc_calibration(jc_gamepad_rpt_t *jc_pad)
|
||||
static bool _jc_calibration(const jc_gamepad_rpt_t *jc_pad)
|
||||
{
|
||||
// Calibrate left stick.
|
||||
if (jc_cal_ctx.cl_step != JC_CAL_MAX_STEPS)
|
||||
@@ -119,22 +125,24 @@ static bool _jc_calibration(jc_gamepad_rpt_t *jc_pad)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _jc_poll(gamepad_report_t *rpt)
|
||||
static int _jc_poll(gamepad_report_t *rpt)
|
||||
{
|
||||
static gamepad_report_t prev_rpt = {0};
|
||||
|
||||
// Poll Joy-Con.
|
||||
jc_gamepad_rpt_t *jc_pad = joycon_poll();
|
||||
|
||||
if (!jc_pad)
|
||||
return false;
|
||||
return INPUT_POLL_NO_PACKET;
|
||||
|
||||
// Exit emulation if Left stick and Home are pressed.
|
||||
if (jc_pad->l3 && jc_pad->home)
|
||||
return true;
|
||||
return INPUT_POLL_EXIT;
|
||||
|
||||
if (jc_cal_ctx.cl_step != JC_CAL_MAX_STEPS || jc_cal_ctx.cr_step != JC_CAL_MAX_STEPS)
|
||||
{
|
||||
if (!_jc_calibration(jc_pad))
|
||||
return false;
|
||||
return INPUT_POLL_NO_PACKET;
|
||||
}
|
||||
|
||||
// Re-calibrate on disconnection.
|
||||
@@ -282,7 +290,12 @@ static bool _jc_poll(gamepad_report_t *rpt)
|
||||
//rpt->btn13 = jc_pad->cap;
|
||||
//rpt->btn14 = jc_pad->home;
|
||||
|
||||
return false;
|
||||
if (!memcmp(rpt, &prev_rpt, sizeof(gamepad_report_t)))
|
||||
return INPUT_POLL_NO_PACKET;
|
||||
|
||||
memcpy(&prev_rpt, rpt, sizeof(gamepad_report_t));
|
||||
|
||||
return INPUT_POLL_HAS_PACKET;
|
||||
}
|
||||
|
||||
typedef struct _touchpad_report_t
|
||||
@@ -351,12 +364,14 @@ static u8 _hid_transfer_start(usb_ctxt_t *usbs, u32 len)
|
||||
|
||||
static bool _hid_poll_jc(usb_ctxt_t *usbs)
|
||||
{
|
||||
if (_jc_poll((gamepad_report_t *)USB_EP_BULK_IN_BUF_ADDR))
|
||||
int res = _jc_poll((gamepad_report_t *)USB_EP_BULK_IN_BUF_ADDR);
|
||||
if (res == INPUT_POLL_EXIT)
|
||||
return true;
|
||||
|
||||
// Send HID report.
|
||||
if (_hid_transfer_start(usbs, sizeof(gamepad_report_t)))
|
||||
return true; // EP Error.
|
||||
if (res == INPUT_POLL_HAS_PACKET)
|
||||
if (_hid_transfer_start(usbs, sizeof(gamepad_report_t)))
|
||||
return true; // EP Error.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2003-2008 Alan Stern
|
||||
* Copyright (c) 2009 Samsung Electronics
|
||||
* Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
|
||||
* Copyright (c) 2019-2023 CTCaer
|
||||
* Copyright (c) 2019-2024 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <storage/sdmmc_driver.h>
|
||||
#include <utils/btn.h>
|
||||
#include <utils/sprintf.h>
|
||||
#include <utils/util.h>
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
@@ -758,7 +759,7 @@ static int _scsi_inquiry(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
||||
|
||||
buf += 4;
|
||||
s_printf((char *)buf, "%04X%s",
|
||||
ums->lun.storage->cid.serial, ums->lun.type == MMC_SD ? " SD卡 " : " eMMC ");
|
||||
ums->lun.storage->cid.serial, ums->lun.type == MMC_SD ? " SD " : " eMMC ");
|
||||
|
||||
switch (ums->lun.partition)
|
||||
{
|
||||
@@ -803,15 +804,15 @@ static int _scsi_inquiry(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt)
|
||||
break;
|
||||
case EMMC_GPP + 1:
|
||||
s_printf((char *)buf, "%s%s",
|
||||
ums->lun.type == MMC_SD ? "SD卡 " : "eMMC ", "GPP");
|
||||
ums->lun.type == MMC_SD ? "SD " : "eMMC ", "GPP");
|
||||
break;
|
||||
case EMMC_BOOT0 + 1:
|
||||
s_printf((char *)buf, "%s%s",
|
||||
ums->lun.type == MMC_SD ? "SD卡 " : "eMMC ", "BOOT0");
|
||||
ums->lun.type == MMC_SD ? "SD " : "eMMC ", "BOOT0");
|
||||
break;
|
||||
case EMMC_BOOT1 + 1:
|
||||
s_printf((char *)buf, "%s%s",
|
||||
ums->lun.type == MMC_SD ? "SD卡 " : "eMMC ", "BOOT1");
|
||||
ums->lun.type == MMC_SD ? "SD " : "eMMC ", "BOOT1");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1843,10 +1844,11 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs)
|
||||
ums.bulk_ctxt.bulk_out_buf = (u8 *)USB_EP_BULK_OUT_BUF_ADDR;
|
||||
|
||||
// Set LUN parameters.
|
||||
ums.lun.ro = usbs->ro;
|
||||
ums.lun.type = usbs->type;
|
||||
ums.lun.partition = usbs->partition;
|
||||
ums.lun.offset = usbs->offset;
|
||||
ums.lun.ro = usbs->ro;
|
||||
ums.lun.type = usbs->type;
|
||||
ums.lun.partition = usbs->partition;
|
||||
ums.lun.num_sectors = usbs->sectors;
|
||||
ums.lun.offset = usbs->offset;
|
||||
ums.lun.removable = 1; // Always removable to force OSes to use prevent media removal.
|
||||
ums.lun.unit_attention_data = SS_RESET_OCCURRED;
|
||||
|
||||
@@ -1899,10 +1901,14 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs)
|
||||
|
||||
ums.set_text(ums.label, "#C7EA46 状态:#开启UMS");
|
||||
|
||||
if (usbs->sectors)
|
||||
ums.lun.num_sectors = usbs->sectors;
|
||||
else
|
||||
ums.lun.num_sectors = ums.lun.storage->sec_cnt;
|
||||
// If partition sectors are not set get them from hardware.
|
||||
if (!ums.lun.num_sectors)
|
||||
{
|
||||
if (usbs->type == MMC_EMMC && (ums.lun.partition - 1)) // eMMC BOOT0/1.
|
||||
ums.lun.num_sectors = emmc_storage.ext_csd.boot_mult << 8;
|
||||
else
|
||||
ums.lun.num_sectors = ums.lun.storage->sec_cnt; // eMMC GPP or SD.
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
@@ -1932,7 +1938,9 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs)
|
||||
|
||||
_handle_ep0_ctrl(&ums);
|
||||
|
||||
if (_parse_scsi_cmd(&ums, &ums.bulk_ctxt) || (ums.state > UMS_STATE_NORMAL))
|
||||
_parse_scsi_cmd(&ums, &ums.bulk_ctxt);
|
||||
|
||||
if (ums.state > UMS_STATE_NORMAL)
|
||||
continue;
|
||||
|
||||
_handle_ep0_ctrl(&ums);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Enhanced USB Device (EDCI) driver for Tegra X1
|
||||
*
|
||||
* Copyright (c) 2019-2023 CTCaer
|
||||
* Copyright (c) 2019-2024 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -355,9 +355,15 @@ int usb_device_init()
|
||||
if (usb_init_done)
|
||||
return USB_RES_OK;
|
||||
|
||||
// Ease the stress to APB.
|
||||
bpmp_clk_rate_relaxed(true);
|
||||
|
||||
// Initialize USB2 controller PHY.
|
||||
_usb_init_phy();
|
||||
|
||||
// Restore OC.
|
||||
bpmp_clk_rate_relaxed(false);
|
||||
|
||||
// AHB USB performance cfg.
|
||||
AHB_GIZMO(AHB_GIZMO_AHB_MEM) |= AHB_MEM_DONT_SPLIT_AHB_WR | AHB_MEM_ENB_FAST_REARBITRATE;
|
||||
AHB_GIZMO(AHB_GIZMO_USB) |= AHB_GIZMO_IMMEDIATE;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* eXtensible USB Device driver (XDCI) for Tegra X1
|
||||
*
|
||||
* Copyright (c) 2020-2022 CTCaer
|
||||
* Copyright (c) 2020-2024 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -883,6 +883,9 @@ static void _xusbd_init_device_clocks()
|
||||
|
||||
int xusb_device_init()
|
||||
{
|
||||
// Ease the stress to APB.
|
||||
bpmp_clk_rate_relaxed(true);
|
||||
|
||||
// Disable USB2 device controller clocks.
|
||||
CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = BIT(CLK_L_USBD);
|
||||
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = BIT(CLK_L_USBD);
|
||||
@@ -920,6 +923,9 @@ int xusb_device_init()
|
||||
// Initialize device clocks.
|
||||
_xusbd_init_device_clocks();
|
||||
|
||||
// Restore OC.
|
||||
bpmp_clk_rate_relaxed(false);
|
||||
|
||||
// Enable AHB redirect for access to IRAM for Event/EP ring buffers.
|
||||
mc_enable_ahb_redirect();
|
||||
|
||||
@@ -1005,7 +1011,7 @@ static void _xusb_device_power_down()
|
||||
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_W_CLR) = BIT(CLK_W_XUSB);
|
||||
}
|
||||
|
||||
static int _xusb_queue_trb(u32 ep_idx, void *trb, bool ring_doorbell)
|
||||
static int _xusb_queue_trb(u32 ep_idx, const void *trb, bool ring_doorbell)
|
||||
{
|
||||
int res = USB_RES_OK;
|
||||
data_trb_t *next_trb;
|
||||
@@ -1220,7 +1226,7 @@ static int _xusb_wait_ep_stopped(u32 endpoint)
|
||||
return USB_RES_OK;
|
||||
}
|
||||
|
||||
static int _xusb_handle_transfer_event(transfer_event_trb_t *trb)
|
||||
static int _xusb_handle_transfer_event(const transfer_event_trb_t *trb)
|
||||
{
|
||||
// Advance dequeue list.
|
||||
data_trb_t *next_trb;
|
||||
@@ -1455,7 +1461,7 @@ static int _xusb_handle_get_ep_status(u32 ep_idx)
|
||||
return _xusb_issue_data_trb(xusb_ep_status_descriptor, 2, USB_DIR_IN);
|
||||
}
|
||||
|
||||
static int _xusb_handle_get_class_request(usb_ctrl_setup_t *ctrl_setup)
|
||||
static int _xusb_handle_get_class_request(const usb_ctrl_setup_t *ctrl_setup)
|
||||
{
|
||||
u8 _bRequest = ctrl_setup->bRequest;
|
||||
u16 _wIndex = ctrl_setup->wIndex;
|
||||
@@ -1486,7 +1492,7 @@ stall:
|
||||
return USB_RES_OK;
|
||||
}
|
||||
|
||||
static int _xusb_handle_get_descriptor(usb_ctrl_setup_t *ctrl_setup)
|
||||
static int _xusb_handle_get_descriptor(const usb_ctrl_setup_t *ctrl_setup)
|
||||
{
|
||||
u32 size;
|
||||
void *descriptor;
|
||||
@@ -1615,7 +1621,7 @@ static int _xusb_handle_get_descriptor(usb_ctrl_setup_t *ctrl_setup)
|
||||
return _xusb_issue_data_trb(descriptor, size, USB_DIR_IN);
|
||||
}
|
||||
|
||||
static void _xusb_handle_set_request_dev_address(usb_ctrl_setup_t *ctrl_setup)
|
||||
static void _xusb_handle_set_request_dev_address(const usb_ctrl_setup_t *ctrl_setup)
|
||||
{
|
||||
u32 addr = ctrl_setup->wValue & 0xFF;
|
||||
|
||||
@@ -1627,7 +1633,7 @@ static void _xusb_handle_set_request_dev_address(usb_ctrl_setup_t *ctrl_setup)
|
||||
usbd_xotg->device_state = XUSB_ADDRESSED_STS_WAIT;
|
||||
}
|
||||
|
||||
static void _xusb_handle_set_request_configuration(usb_ctrl_setup_t *ctrl_setup)
|
||||
static void _xusb_handle_set_request_configuration(const usb_ctrl_setup_t *ctrl_setup)
|
||||
{
|
||||
usbd_xotg->config_num = ctrl_setup->wValue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user