Skip to content

Commit

Permalink
Additional cleanups for V-USB code (#9310)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Jun 9, 2020
1 parent c2ed231 commit b996ffa
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 119 deletions.
3 changes: 0 additions & 3 deletions quantum/mcu_selection.mk
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ ifneq (,$(filter $(MCU),atmega32a))
F_CPU ?= 12000000

# unsupported features for now
NO_UART ?= yes
NO_SUSPEND_POWER_DOWN ?= yes
endif

Expand All @@ -284,7 +283,6 @@ ifneq (,$(filter $(MCU),atmega328p))
F_CPU ?= 16000000

# unsupported features for now
NO_UART ?= yes
NO_SUSPEND_POWER_DOWN ?= yes
endif

Expand All @@ -299,6 +297,5 @@ ifneq (,$(filter $(MCU),attiny85))
F_CPU ?= 16500000

# unsupported features for now
NO_UART ?= yes
NO_SUSPEND_POWER_DOWN ?= yes
endif
4 changes: 0 additions & 4 deletions tmk_core/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif

ifeq ($(strip $(NO_UART)), yes)
TMK_COMMON_DEFS += -DNO_UART
endif

ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif
Expand Down
7 changes: 0 additions & 7 deletions tmk_core/protocol/vusb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ SRC += $(VUSB_DIR)/main.c \
$(VUSB_PATH)/usbdrv/usbdrvasm.S \
$(VUSB_PATH)/usbdrv/oddebug.c

ifneq ($(strip $(CONSOLE_ENABLE)), yes)
ifndef NO_UART
SRC += $(COMMON_DIR)/sendchar_uart.c \
$(COMMON_DIR)/uart.c
endif
endif

# Search Path
VPATH += $(TMK_PATH)/$(VUSB_DIR)
VPATH += $(VUSB_PATH)
Expand Down
37 changes: 10 additions & 27 deletions tmk_core/protocol/vusb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
* This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
*/

#include <stdint.h>

#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <util/delay.h>

#include <usbdrv/usbdrv.h>
#include <usbdrv/oddebug.h>

#include "vusb.h"

#include "keyboard.h"
#include "host.h"
#include "timer.h"
#include "uart.h"
#include "debug.h"
#include "print.h"
#include "suspend.h"
#include "wait.h"
#include "sendchar.h"
Expand All @@ -28,8 +31,6 @@
# include "sleep_led.h"
#endif

#define UART_BAUD_RATE 115200

#ifdef CONSOLE_ENABLE
void console_task(void);
#endif
Expand All @@ -47,7 +48,7 @@ static void initForUsbConnectivity(void) {
usbDeviceDisconnect(); /* do this while interrupts are disabled */
while (--i) { /* fake USB disconnect for > 250 ms */
wdt_reset();
_delay_ms(1);
wait_ms(1);
}
usbDeviceConnect();
}
Expand All @@ -60,7 +61,7 @@ static void usb_remote_wakeup(void) {
USBDDR = ddr_orig | USBMASK;
USBOUT ^= USBMASK;

_delay_ms(25);
wait_ms(25);

USBOUT ^= USBMASK;
USBDDR = ddr_orig;
Expand All @@ -74,7 +75,6 @@ static void usb_remote_wakeup(void) {
* FIXME: Needs doc
*/
static void setup_usb(void) {
// debug("initForUsbConnectivity()\n");
initForUsbConnectivity();

// for Console_Task
Expand All @@ -95,10 +95,7 @@ int main(void) {
#ifdef CLKPR
// avoid unintentional changes of clock frequency in devices that have a
// clock prescaler
CLKPR = 0x80, CLKPR = 0;
#endif
#ifndef NO_UART
uart_init(UART_BAUD_RATE);
clock_prescale_set(clock_div_1);
#endif
keyboard_setup();

Expand All @@ -113,7 +110,6 @@ int main(void) {
sleep_led_init();
#endif

debug("main loop\n");
while (1) {
#if USB_COUNT_SOF
if (usbSofCount != 0) {
Expand All @@ -130,19 +126,6 @@ int main(void) {
# ifdef SLEEP_LED_ENABLE
sleep_led_enable();
# endif
/*
uart_putchar('S');
_delay_ms(1);
cli();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_bod_disable();
sei();
sleep_cpu();
sleep_disable();
_delay_ms(10);
uart_putchar('W');
*/
}
}
#endif
Expand Down
19 changes: 0 additions & 19 deletions tmk_core/protocol/vusb/sendchar_usart.c

This file was deleted.

102 changes: 43 additions & 59 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/wdt.h>
#include <util/delay.h>
#include <stdint.h>

#include <avr/wdt.h>

#include <usbdrv/usbdrv.h>

#include "usbconfig.h"
#include "host.h"
#include "report.h"
#include "host_driver.h"
#include "vusb.h"
#include "print.h"
#include "debug.h"
#include "wait.h"
#include "usb_descriptor_common.h"

#ifdef RAW_ENABLE
Expand Down Expand Up @@ -56,7 +59,7 @@ enum usb_interfaces {
#ifdef CONSOLE_ENABLE
CONSOLE_INTERFACE = NEXT_INTERFACE,
#endif
TOTAL_INTERFACES = NEXT_INTERFACE,
TOTAL_INTERFACES = NEXT_INTERFACE
};

#define MAX_INTERFACES 2
Expand Down Expand Up @@ -86,19 +89,13 @@ void vusb_transfer_keyboard(void) {
usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
if (debug_keyboard) {
print("V-USB: kbuf[");
pdec(kbuf_tail);
print("->");
pdec(kbuf_head);
print("](");
phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
print(")\n");
dprintf("V-USB: kbuf[%d->%d](%02X)\n", kbuf_tail, kbuf_head, (kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
}
}
break;
}
usbPoll();
_delay_ms(1);
wait_ms(1);
}
}

Expand Down Expand Up @@ -220,7 +217,7 @@ static void send_keyboard(report_keyboard_t *report) {
kbuf[kbuf_head] = *report;
kbuf_head = next;
} else {
debug("kbuf: full\n");
dprint("kbuf: full\n");
}

// NOTE: send key strokes of Macro
Expand Down Expand Up @@ -283,37 +280,35 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {

if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
debug("GET_REPORT:");
dprint("GET_REPORT:");
if (rq->wIndex.word == KEYBOARD_INTERFACE) {
usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
return sizeof(keyboard_report_sent);
}
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
debug("GET_IDLE: ");
// debug_hex(vusb_idle_rate);
dprint("GET_IDLE:");
usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
return 1;
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
vusb_idle_rate = rq->wValue.bytes[1];
debug("SET_IDLE: ");
debug_hex(vusb_idle_rate);
dprintf("SET_IDLE: %02X", vusb_idle_rate);
} else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
debug("SET_REPORT: ");
dprint("SET_REPORT:");
// Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
debug("SET_LED: ");
dprint("SET_LED:");
last_req.kind = SET_LED;
last_req.len = rq->wLength.word;
}
return USB_NO_MSG; // to get data in usbFunctionWrite
} else {
debug("UNKNOWN:");
dprint("UNKNOWN:");
}
} else {
debug("VENDOR:");
dprint("VENDOR:");
/* no vendor specific requests implemented */
}
debug("\n");
dprint("\n");
return 0; /* default for not implemented requests: return no data back to host */
}

Expand All @@ -323,9 +318,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
}
switch (last_req.kind) {
case SET_LED:
debug("SET_LED: ");
debug_hex(data[0]);
debug("\n");
dprintf("SET_LED: %02X\n", data[0]);
keyboard_led_state = data[0];
last_req.len = 0;
return 1;
Expand All @@ -342,13 +335,13 @@ void usbFunctionWriteOut(uchar *data, uchar len) {
#ifdef RAW_ENABLE
// Data from host must be divided every 8bytes
if (len != 8) {
debug("RAW: invalid length");
dprint("RAW: invalid length\n");
raw_output_received_bytes = 0;
return;
}

if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
debug("RAW: buffer full");
dprint("RAW: buffer full\n");
raw_output_received_bytes = 0;
} else {
for (uint8_t i = 0; i < 8; i++) {
Expand Down Expand Up @@ -404,29 +397,6 @@ const PROGMEM uchar keyboard_hid_report[] = {
0xC0 // End Collection
};

#ifdef RAW_ENABLE
const PROGMEM uchar raw_hid_report[] = {
0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
0xA1, 0x01, // Collection (Application)
// Data to host
0x09, 0x62, // Usage (Vendor Defined)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x95, RAW_BUFFER_SIZE, // Report Count
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data, Variable, Absolute)
// Data from host
0x09, 0x63, // Usage (Vendor Defined)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x95, RAW_BUFFER_SIZE, // Report Count
0x75, 0x08, // Report Size (8)
0x91, 0x02, // Output (Data, Variable, Absolute)
0xC0 // End Collection
};
#endif

#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
const PROGMEM uchar mouse_extra_hid_report[] = {
# ifdef MOUSE_ENABLE
Expand Down Expand Up @@ -511,6 +481,29 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
};
#endif

#ifdef RAW_ENABLE
const PROGMEM uchar raw_hid_report[] = {
0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
0xA1, 0x01, // Collection (Application)
// Data to host
0x09, 0x62, // Usage (Vendor Defined)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x95, RAW_BUFFER_SIZE, // Report Count
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data, Variable, Absolute)
// Data from host
0x09, 0x63, // Usage (Vendor Defined)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x95, RAW_BUFFER_SIZE, // Report Count
0x75, 0x08, // Report Size (8)
0x91, 0x02, // Output (Data, Variable, Absolute)
0xC0 // End Collection
};
#endif

#if defined(CONSOLE_ENABLE)
const PROGMEM uchar console_hid_report[] = {
0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
Expand Down Expand Up @@ -801,14 +794,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
usbMsgLen_t len = 0;

/*
debug("usbFunctionDescriptor: ");
debug_hex(rq->bmRequestType); debug(" ");
debug_hex(rq->bRequest); debug(" ");
debug_hex16(rq->wValue.word); debug(" ");
debug_hex16(rq->wIndex.word); debug(" ");
debug_hex16(rq->wLength.word); debug("\n");
*/
switch (rq->wValue.bytes[1]) {
case USBDESCR_DEVICE:
usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
Expand Down Expand Up @@ -892,6 +877,5 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
}
break;
}
// debug("desc len: "); debug_hex(len); debug("\n");
return len;
}

0 comments on commit b996ffa

Please sign in to comment.