Skip to content

Commit

Permalink
Fix USB port detection threshold (stuffing error on Drop ALT)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmerrill committed Nov 7, 2020
1 parent a4126f1 commit d799876
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions tmk_core/protocol/arm_atsam/usb/usb2422.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,16 @@ void USB_ExtraSetState(uint8_t state) {

void USB_HandleExtraDevice(void) {
uint16_t adcval;
uint16_t adc_threshold;

if (usb_host_port == USB_HOST_PORT_1)
if (usb_host_port == USB_HOST_PORT_1) {
adcval = adc_get(ADC_CON2);
else if (usb_host_port == USB_HOST_PORT_2)
adc_threshold = USB_EXTRA_ADC_THRESHOLD;
}
else if (usb_host_port == USB_HOST_PORT_2) {
adcval = adc_get(ADC_CON1);
adc_threshold = USB_EXTRA_ADC_THRESHOLD_P1;
}
else
return;

Expand All @@ -405,7 +410,7 @@ void USB_HandleExtraDevice(void) {
// Check for a forced disable state (such as overload prevention)
if (usb_extra_state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG) {
// Detect unplug and reset state to disabled
if (adc_extra > USB_EXTRA_ADC_THRESHOLD) usb_extra_state = USB_EXTRA_STATE_DISABLED;
if (adc_extra > adc_threshold) usb_extra_state = USB_EXTRA_STATE_DISABLED;

return; // Return even if unplug detected
}
Expand All @@ -417,9 +422,9 @@ void USB_HandleExtraDevice(void) {
}

// dpf("a %i %i\r\n",adcval, adc_extra);
if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < USB_EXTRA_ADC_THRESHOLD)
if (usb_extra_state == USB_EXTRA_STATE_DISABLED && adc_extra < adc_threshold)
USB_ExtraSetState(USB_EXTRA_STATE_ENABLED);
else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > USB_EXTRA_ADC_THRESHOLD)
else if (usb_extra_state == USB_EXTRA_STATE_ENABLED && adc_extra > adc_threshold)
USB_ExtraSetState(USB_EXTRA_STATE_DISABLED);
}

Expand Down
3 changes: 2 additions & 1 deletion tmk_core/protocol/arm_atsam/usb/usb2422.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ typedef struct {

#define PORT_DETECT_RETRY_INTERVAL 2000

#define USB_EXTRA_ADC_THRESHOLD 900
#define USB_EXTRA_ADC_THRESHOLD 850
#define USB_EXTRA_ADC_THRESHOLD_P1 1250

#define USB_EXTRA_STATE_DISABLED 0
#define USB_EXTRA_STATE_ENABLED 1
Expand Down

0 comments on commit d799876

Please sign in to comment.