Skip to content

Commit

Permalink
Initial vusb console support (qmk#8559)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and drashna committed May 24, 2020
1 parent 095f497 commit 37fd43e
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 49 deletions.
1 change: 1 addition & 0 deletions tmk_core/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/debug.c \
$(COMMON_DIR)/sendchar_null.c \
$(COMMON_DIR)/util.c \
$(COMMON_DIR)/eeconfig.c \
$(COMMON_DIR)/report.c \
Expand Down
2 changes: 1 addition & 1 deletion tmk_core/common/sendchar_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sendchar.h"

int8_t sendchar(uint8_t c) { return 0; }
__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; }
4 changes: 3 additions & 1 deletion tmk_core/protocol/ibm4704.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ ISR(IBM4704_INT_VECT) {
case STOP:
// Data:Low
WAIT(data_lo, 100, state);
rbuf_enqueue(data);
if (!rbuf_enqueue(data)) {
print("rbuf: full\n");
}
ibm4704_error = IBM4704_ERR_NONE;
goto DONE;
break;
Expand Down
2 changes: 0 additions & 2 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,6 @@ int8_t sendchar(uint8_t c) {
Endpoint_SelectEndpoint(ep);
return -1;
}
#else
int8_t sendchar(uint8_t c) { return 0; }
#endif

/*******************************************************************************
Expand Down
7 changes: 3 additions & 4 deletions tmk_core/protocol/vusb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ SRC += $(VUSB_DIR)/main.c \
$(VUSB_DIR)/usbdrv/oddebug.c


ifdef NO_UART
SRC += $(COMMON_DIR)/sendchar_null.c
else
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)
Expand Down
47 changes: 42 additions & 5 deletions tmk_core/protocol/vusb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@
#include "uart.h"
#include "debug.h"
#include "suspend.h"
#include "wait.h"
#include "sendchar.h"

#ifdef SLEEP_LED_ENABLE
# include "sleep_led.h"
#endif

#define UART_BAUD_RATE 115200

#ifdef CONSOLE_ENABLE
void console_task(void);
#endif

#ifdef RAW_ENABLE
void raw_hid_task(void);
#endif

/* This is from main.c of USBaspLoader */
static void initForUsbConnectivity(void) {
uint8_t i = 0;
Expand All @@ -39,10 +50,9 @@ static void initForUsbConnectivity(void) {
_delay_ms(1);
}
usbDeviceConnect();
sei();
}

void usb_remote_wakeup(void) {
static void usb_remote_wakeup(void) {
cli();

int8_t ddr_orig = USBDDR;
Expand All @@ -59,6 +69,23 @@ void usb_remote_wakeup(void) {
sei();
}

/** \brief Setup USB
*
* FIXME: Needs doc
*/
static void setup_usb(void) {
// debug("initForUsbConnectivity()\n");
initForUsbConnectivity();

// for Console_Task
print_set_sendchar(sendchar);
}

/** \brief Main
*
* FIXME: Needs doc
*/
int main(void) __attribute__((weak));
int main(void) {
bool suspended = false;
#if USB_COUNT_SOF
Expand All @@ -76,8 +103,10 @@ int main(void) {
keyboard_setup();

host_set_driver(vusb_driver());
debug("initForUsbConnectivity()\n");
initForUsbConnectivity();
setup_usb();
sei();

wait_ms(50);

keyboard_init();
#ifdef SLEEP_LED_ENABLE
Expand Down Expand Up @@ -120,18 +149,26 @@ int main(void) {
if (!suspended) {
usbPoll();

// TODO: configuration process is incosistent. it sometime fails.
// TODO: configuration process is inconsistent. it sometime fails.
// To prevent failing to configure NOT scan keyboard during configuration
if (usbConfiguration && usbInterruptIsReady()) {
keyboard_task();
}
vusb_transfer_keyboard();

#ifdef RAW_ENABLE
usbPoll();

if (usbConfiguration && usbInterruptIsReady3()) {
raw_hid_task();
}
#endif
#ifdef CONSOLE_ENABLE
usbPoll();

if (usbConfiguration && usbInterruptIsReady3()) {
console_task();
}
#endif
} else if (suspend_wakeup_condition()) {
usb_remote_wakeup();
Expand Down
Loading

0 comments on commit 37fd43e

Please sign in to comment.