Skip to content

Commit

Permalink
[Keyboard] Manually cherrypick USB-related fixes for Drop keyboards.
Browse files Browse the repository at this point in the history
- Gentoli:drop-ok@a0c746e USBCV HID tests (partially applied, upstream diverged in qmk#8156)
- Gentoli:drop-ok@1a106ef USBCV Chapter 9 disabled remote wakeup failure
- Gentoli:drop-ok@b5a9a23 USB30CV Chapter 9 failure
  • Loading branch information
xwu committed Jul 27, 2021
1 parent ae2c235 commit b3730b7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
17 changes: 11 additions & 6 deletions tmk_core/common/arm_atsam/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "i2c_master.h"
#include "md_rgb_matrix.h"
#include "suspend.h"
#include "./usb/ui.h"

/** \brief Suspend idle
*
Expand Down Expand Up @@ -36,12 +37,16 @@ void suspend_power_down(void) {

__attribute__((weak)) void matrix_power_up(void) {}
__attribute__((weak)) void matrix_power_down(void) {}
bool suspend_wakeup_condition(void) {
matrix_power_up();
matrix_scan();
matrix_power_down();
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
if (matrix_get_row(r)) return true;
bool suspend_wakeup_condition(void) {
if (ui_is_remotewakeup_enabled()) {
matrix_power_up();
matrix_scan();
matrix_power_down();
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
if (matrix_get_row(r)) return true;
}
} else {
matrix_power_down();
}
return false;
}
Expand Down
9 changes: 7 additions & 2 deletions tmk_core/protocol/arm_atsam/usb/udi_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/

#include <string.h>
#include "conf_usb.h"
#include "usb_protocol.h"
#include "udd.h"
#include "udc.h"
#include "udi_hid.h"

COMPILER_WORD_ALIGNED
static uint8_t udi_hid_desc_buf[sizeof(usb_hid_descriptor_t)];

/**
* \ingroup udi_hid_group
* \defgroup udi_hid_group_internal Implementation of HID common library
Expand Down Expand Up @@ -129,8 +133,9 @@ static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc) {
// - or USB_DT_HID_REPORT descriptor
// - or USB_DT_HID_PHYSICAL descriptor
if (USB_DT_HID == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
// USB_DT_HID descriptor requested then send it
udd_g_ctrlreq.payload = (uint8_t *)ptr_hid_desc;
// USB_DT_HID descriptor requested; copy into word-aligned buffer, then send it
memcpy(udi_hid_desc_buf, (uint8_t *)ptr_hid_desc, sizeof(usb_hid_descriptor_t));
udd_g_ctrlreq.payload = udi_hid_desc_buf;
udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, ptr_hid_desc->bLength);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tmk_core/protocol/arm_atsam/usb/udi_hid_kbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ UDC_DESC_STORAGE udc_desc_t udc_desc = {
.conf.bNumInterfaces = USB_DEVICE_NB_INTERFACE,
.conf.bConfigurationValue = 1,
.conf.iConfiguration = 0,
.conf.bmAttributes = /* USB_CONFIG_ATTR_MUST_SET | */ USB_DEVICE_ATTR,
.conf.bmAttributes = USB_CONFIG_ATTR_MUST_SET | USB_DEVICE_ATTR,
.conf.bMaxPower = USB_CONFIG_MAX_POWER(USB_DEVICE_POWER),
.hid_kbd = UDI_HID_KBD_DESC,
#ifdef RAW_ENABLE
Expand Down
10 changes: 7 additions & 3 deletions tmk_core/protocol/arm_atsam/usb/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
//! Sequence process running each \c SEQUENCE_PERIOD ms
#define SEQUENCE_PERIOD 150

static bool ui_is_wakeup_enabled = true;

#if 0
/* Interrupt on "pin change" from push button to do wakeup on USB
* Note:
Expand All @@ -68,13 +70,15 @@ static void ui_wakeup_handler(void)
}
#endif

void ui_init(void) {}
void ui_init(void) { ui_is_wakeup_enabled = true; }

void ui_powerdown(void) {}

void ui_wakeup_enable(void) {}
void ui_wakeup_enable(void) { ui_is_wakeup_enabled = true; }

void ui_wakeup_disable(void) { ui_is_wakeup_enabled = false; }

void ui_wakeup_disable(void) {}
bool ui_is_remotewakeup_enabled(void) { return ui_is_wakeup_enabled; }

void ui_wakeup(void) {}

Expand Down
5 changes: 5 additions & 0 deletions tmk_core/protocol/arm_atsam/usb/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#ifndef _UI_H_
#define _UI_H_

#include <stdbool.h>

//! \brief Initializes the user interface
void ui_init(void);

Expand All @@ -59,6 +61,9 @@ void ui_wakeup_enable(void);
//! \brief Disables the asynchronous interrupts of the user interface
void ui_wakeup_disable(void);

//! \brief Returns remote wakeup state
bool ui_is_remotewakeup_enabled(void);

//! \brief Exits the user interface of power down mode
void ui_wakeup(void);

Expand Down

0 comments on commit b3730b7

Please sign in to comment.