Merge remote-tracking branch 'qmk/master' into vial

This commit is contained in:
Ilya Zhuravlev
2021-06-26 16:11:57 -04:00
4671 changed files with 157519 additions and 33974 deletions
@@ -305,6 +305,9 @@ int main(void) {
// dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
}
#endif // CONSOLE_ENABLE
// Run housekeeping
housekeeping_task();
}
return 1;
+1
View File
@@ -6,6 +6,7 @@ SRC += $(CHIBIOS_DIR)/usb_main.c
SRC += $(CHIBIOS_DIR)/main.c
SRC += usb_descriptor.c
SRC += $(CHIBIOS_DIR)/usb_driver.c
SRC += $(CHIBIOS_DIR)/usb_util.c
SRC += $(LIBSRC)
VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
+1 -15
View File
@@ -51,12 +51,6 @@
#ifdef MIDI_ENABLE
# include "qmk_midi.h"
#endif
#ifdef STM32_EEPROM_ENABLE
# include "eeprom_stm32.h"
#endif
#ifdef EEPROM_DRIVER
# include "eeprom_driver.h"
#endif
#include "suspend.h"
#include "wait.h"
@@ -150,13 +144,6 @@ int main(void) {
halInit();
chSysInit();
#ifdef STM32_EEPROM_ENABLE
EEPROM_Init();
#endif
#ifdef EEPROM_DRIVER
eeprom_driver_init();
#endif
// TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
@@ -270,7 +257,6 @@ int main(void) {
#endif
// Run housekeeping
housekeeping_task_kb();
housekeeping_task_user();
housekeeping_task();
}
}
+26 -3
View File
@@ -930,9 +930,32 @@ void send_consumer(uint16_t data) {
#ifdef CONSOLE_ENABLE
int8_t sendchar(uint8_t c) {
// The previous implmentation had timeouts, but I think it's better to just slow down
// and make sure that everything is transferred, rather than dropping stuff
return chnWrite(&drivers.console_driver.driver, &c, 1);
static bool timed_out = false;
/* The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
*
* When a 5ms timeout write has timed out, hid_listen is most likely not running, or not
* listening to this keyboard, so we go into the timed_out state. In this state we assume
* that hid_listen is most likely not gonna be connected to us any time soon, so it would
* be wasteful to write follow-up characters with a 5ms timeout, it would all add up and
* unncecessarily slow down the firmware. However instead of just dropping the characters,
* we write them with a TIME_IMMEDIATE timeout, which is a zero timeout,
* and this will succeed only if hid_listen gets connected again. When a write with
* TIME_IMMEDIATE timeout succeeds, we know that hid_listen is listening to us again, and
* we can go back to the timed_out = false state, and following writes will be executed
* with a 5ms timeout. The reason we don't just send all characters with the TIME_IMMEDIATE
* timeout is that this could cause bytes to be lost even if hid_listen is running, if there
* is a lot of data being sent over the console.
*
* This logic will work correctly as long as hid_listen is able to receive at least 200
* bytes per second. On a heavily overloaded machine that's so overloaded that it's
* unusable, and constantly swapping, hid_listen might have trouble receiving 200 bytes per
* second, so some bytes might be lost on the console.
*/
const sysinterval_t timeout = timed_out ? TIME_IMMEDIATE : TIME_MS2I(5);
const size_t result = chnWriteTimeout(&drivers.console_driver.driver, &c, 1, timeout);
timed_out = (result == 0);
return result;
}
// Just a dummy function for now, this could be exposed as a weak function
+21
View File
@@ -0,0 +1,21 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 <hal.h>
#include "usb_util.h"
void usb_disable(void) { usbStop(&USBD1); }
bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }
+3 -2
View File
@@ -44,6 +44,7 @@ ifeq ($(strip $(VIRTSER_ENABLE)), yes)
endif
SRC += $(LUFA_SRC)
SRC += $(LUFA_DIR)/usb_util.c
# Search Path
VPATH += $(TMK_PATH)/$(LUFA_DIR)
@@ -66,8 +67,8 @@ LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8
LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8
LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1
# Remote wakeup fix for ATmega32U2 https://github.com/tmk/tmk_keyboard/issues/361
ifeq ($(MCU),atmega32u2)
# Remote wakeup fix for ATmega16/32U2 https://github.com/tmk/tmk_keyboard/issues/361
ifneq (,$(filter $(MCU), at90usb162 atmega16u2 atmega32u2))
LUFA_OPTS += -DNO_LIMITED_CONTROLLER_CONNECT
endif
+7 -7
View File
@@ -829,9 +829,10 @@ static void send_consumer(uint16_t data) {
* FIXME: Needs doc
*/
int8_t sendchar(uint8_t c) {
// Not wait once timeouted.
// Do not wait if the previous write has timed_out.
// Because sendchar() is called so many times, waiting each call causes big lag.
static bool timeouted = false;
// The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
static bool timed_out = false;
// prevents Console_Task() from running during sendchar() runs.
// or char will be lost. These two function is mutually exclusive.
@@ -845,11 +846,11 @@ int8_t sendchar(uint8_t c) {
goto ERROR_EXIT;
}
if (timeouted && !Endpoint_IsReadWriteAllowed()) {
if (timed_out && !Endpoint_IsReadWriteAllowed()) {
goto ERROR_EXIT;
}
timeouted = false;
timed_out = false;
uint8_t timeout = SEND_TIMEOUT;
while (!Endpoint_IsReadWriteAllowed()) {
@@ -860,7 +861,7 @@ int8_t sendchar(uint8_t c) {
goto ERROR_EXIT;
}
if (!(timeout--)) {
timeouted = true;
timed_out = true;
goto ERROR_EXIT;
}
_delay_ms(1);
@@ -1106,8 +1107,7 @@ int main(void) {
#endif
// Run housekeeping
housekeeping_task_kb();
housekeeping_task_user();
housekeeping_task();
}
}
+34
View File
@@ -0,0 +1,34 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 <LUFA/Drivers/USB/USB.h>
#include "usb_util.h"
#include "wait.h"
void usb_disable(void) {
USB_Disable();
USB_DeviceState = DEVICE_STATE_Unattached;
}
bool usb_connected_state(void) { return USB_Device_IsAddressSet(); }
#if defined(OTGPADE)
bool usb_vbus_state(void) {
USB_OTGPAD_On(); // enables VBUS pad
wait_us(5);
return USB_VBUS_GetStatus(); // checks state of VBUS
}
#endif
+1 -1
View File
@@ -5,7 +5,7 @@
#include "usb_descriptor.h"
#include "process_midi.h"
#if API_SYSEX_ENABLE
# include "api.h"
# include "api_sysex.h"
#endif
/*******************************************************************************
+1
View File
@@ -5,6 +5,7 @@ VUSB_PATH = $(LIB_PATH)/vusb
SRC += $(VUSB_DIR)/main.c \
$(VUSB_DIR)/vusb.c \
$(VUSB_DIR)/usb_util.c \
$(VUSB_PATH)/usbdrv/usbdrv.c \
$(VUSB_PATH)/usbdrv/usbdrvasm.S \
$(VUSB_PATH)/usbdrv/oddebug.c
+1 -2
View File
@@ -173,8 +173,7 @@ int main(void) {
#endif
// Run housekeeping
housekeeping_task_kb();
housekeeping_task_user();
housekeeping_task();
}
}
}
+24
View File
@@ -0,0 +1,24 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 <usbdrv/usbdrv.h>
#include "usb_util.h"
void usb_disable(void) { usbDeviceDisconnect(); }
bool usb_connected_state(void) {
usbPoll();
return usbConfiguration;
}
+22 -19
View File
@@ -38,33 +38,36 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma once
#define XT_DATA_IN() \
do { \
XT_DATA_DDR &= ~(1 << XT_DATA_BIT); \
XT_DATA_PORT |= (1 << XT_DATA_BIT); \
#include "quantum.h"
#define XT_DATA_IN() \
do { \
setPinInput(XT_DATA_PIN); \
writePinHigh(XT_DATA_PIN); \
} while (0)
#define XT_DATA_READ() (XT_DATA_PIN & (1 << XT_DATA_BIT))
#define XT_DATA_READ() readPin(XT_DATA_PIN)
#define XT_DATA_LO() \
do { \
XT_DATA_PORT &= ~(1 << XT_DATA_BIT); \
XT_DATA_DDR |= (1 << XT_DATA_BIT); \
#define XT_DATA_LO() \
do { \
writePinLow(XT_DATA_PIN); \
setPinOutput(XT_DATA_PIN); \
} while (0)
#define XT_CLOCK_IN() \
do { \
XT_CLOCK_DDR &= ~(1 << XT_CLOCK_BIT); \
XT_CLOCK_PORT |= (1 << XT_CLOCK_BIT); \
#define XT_CLOCK_IN() \
do { \
setPinInput(XT_CLOCK_PIN); \
writePinHigh(XT_CLOCK_PIN); \
} while (0)
#define XT_CLOCK_READ() (XT_CLOCK_PIN & (1 << XT_CLOCK_BIT))
#define XT_CLOCK_READ() readPin(XT_CLOCK_PIN)
#define XT_CLOCK_LO() \
do { \
XT_CLOCK_PORT &= ~(1 << XT_CLOCK_BIT); \
XT_CLOCK_DDR |= (1 << XT_CLOCK_BIT); \
#define XT_CLOCK_LO() \
do { \
writePinLow(XT_CLOCK_PIN); \
setPinOutput(XT_CLOCK_PIN); \
} while (0)
void xt_host_init(void);
void xt_host_init(void);
uint8_t xt_host_recv(void);
+8 -5
View File
@@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdbool.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "xt.h"
#include "wait.h"
#include "debug.h"
@@ -60,7 +59,7 @@ void xt_host_init(void) {
/* soft reset: pull clock line down for 20ms */
XT_DATA_LO();
XT_CLOCK_LO();
_delay_ms(20);
wait_ms(20);
/* input mode with pullup */
XT_CLOCK_IN();
@@ -120,9 +119,10 @@ ISR(XT_INT_VECT) {
* Ring buffer to store scan codes from keyboard
*------------------------------------------------------------------*/
#define PBUF_SIZE 32
static uint8_t pbuf[PBUF_SIZE];
static uint8_t pbuf_head = 0;
static uint8_t pbuf_tail = 0;
static uint8_t pbuf[PBUF_SIZE];
static uint8_t pbuf_head = 0;
static uint8_t pbuf_tail = 0;
static inline void pbuf_enqueue(uint8_t data) {
uint8_t sreg = SREG;
cli();
@@ -135,6 +135,7 @@ static inline void pbuf_enqueue(uint8_t data) {
}
SREG = sreg;
}
static inline uint8_t pbuf_dequeue(void) {
uint8_t val = 0;
@@ -148,6 +149,7 @@ static inline uint8_t pbuf_dequeue(void) {
return val;
}
static inline bool pbuf_has_data(void) {
uint8_t sreg = SREG;
cli();
@@ -155,6 +157,7 @@ static inline bool pbuf_has_data(void) {
SREG = sreg;
return has_data;
}
static inline void pbuf_clear(void) {
uint8_t sreg = SREG;
cli();