Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial vusb console support #8559

Merged
merged 1 commit into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -801,8 +801,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