diff options
| author | Joel Challis <git@zvecr.com> | 2021-02-28 15:52:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-28 15:52:58 +0000 |
| commit | 5ba4391cf29ce624f17593417212b3dbca1609ad (patch) | |
| tree | 61580567d52c26c482e57083eb85a19991a7d601 /tmk_core/protocol | |
| parent | 415a8bc249d5c366487f69b3547198d17044a5de (diff) | |
| download | qmk_firmware-5ba4391cf29ce624f17593417212b3dbca1609ad.tar.gz qmk_firmware-5ba4391cf29ce624f17593417212b3dbca1609ad.zip | |
Refactor of USB code within split_common (#11890)
* Initial refactor of usb code within split_common
* Add headers
* Correct disable condition
* Format
* Align func name
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/chibios.mk | 1 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/usb_util.c | 21 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa.mk | 1 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/usb_util.c | 34 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb.mk | 1 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/usb_util.c | 24 |
6 files changed, 82 insertions, 0 deletions
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk index 80554abb3..d01697835 100644 --- a/tmk_core/protocol/chibios.mk +++ b/tmk_core/protocol/chibios.mk | |||
| @@ -6,6 +6,7 @@ SRC += $(CHIBIOS_DIR)/usb_main.c | |||
| 6 | SRC += $(CHIBIOS_DIR)/main.c | 6 | SRC += $(CHIBIOS_DIR)/main.c |
| 7 | SRC += usb_descriptor.c | 7 | SRC += usb_descriptor.c |
| 8 | SRC += $(CHIBIOS_DIR)/usb_driver.c | 8 | SRC += $(CHIBIOS_DIR)/usb_driver.c |
| 9 | SRC += $(CHIBIOS_DIR)/usb_util.c | ||
| 9 | SRC += $(LIBSRC) | 10 | SRC += $(LIBSRC) |
| 10 | 11 | ||
| 11 | VPATH += $(TMK_PATH)/$(PROTOCOL_DIR) | 12 | VPATH += $(TMK_PATH)/$(PROTOCOL_DIR) |
diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c new file mode 100644 index 000000000..5945e8a8d --- /dev/null +++ b/tmk_core/protocol/chibios/usb_util.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include <hal.h> | ||
| 17 | #include "usb_util.h" | ||
| 18 | |||
| 19 | void usb_disable(void) { usbStop(&USBD1); } | ||
| 20 | |||
| 21 | bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; } | ||
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk index 1cc1fa04e..9d9fb728b 100644 --- a/tmk_core/protocol/lufa.mk +++ b/tmk_core/protocol/lufa.mk | |||
| @@ -44,6 +44,7 @@ ifeq ($(strip $(VIRTSER_ENABLE)), yes) | |||
| 44 | endif | 44 | endif |
| 45 | 45 | ||
| 46 | SRC += $(LUFA_SRC) | 46 | SRC += $(LUFA_SRC) |
| 47 | SRC += $(LUFA_DIR)/usb_util.c | ||
| 47 | 48 | ||
| 48 | # Search Path | 49 | # Search Path |
| 49 | VPATH += $(TMK_PATH)/$(LUFA_DIR) | 50 | VPATH += $(TMK_PATH)/$(LUFA_DIR) |
diff --git a/tmk_core/protocol/lufa/usb_util.c b/tmk_core/protocol/lufa/usb_util.c new file mode 100644 index 000000000..9e943a21b --- /dev/null +++ b/tmk_core/protocol/lufa/usb_util.c | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include <LUFA/Drivers/USB/USB.h> | ||
| 17 | #include "usb_util.h" | ||
| 18 | #include "wait.h" | ||
| 19 | |||
| 20 | void usb_disable(void) { | ||
| 21 | USB_Disable(); | ||
| 22 | USB_DeviceState = DEVICE_STATE_Unattached; | ||
| 23 | } | ||
| 24 | |||
| 25 | bool usb_connected_state(void) { return USB_Device_IsAddressSet(); } | ||
| 26 | |||
| 27 | #if defined(OTGPADE) | ||
| 28 | bool usb_vbus_state(void) { | ||
| 29 | USB_OTGPAD_On(); // enables VBUS pad | ||
| 30 | wait_us(5); | ||
| 31 | |||
| 32 | return USB_VBUS_GetStatus(); // checks state of VBUS | ||
| 33 | } | ||
| 34 | #endif | ||
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk index 1de600308..e4d013b38 100644 --- a/tmk_core/protocol/vusb.mk +++ b/tmk_core/protocol/vusb.mk | |||
| @@ -5,6 +5,7 @@ VUSB_PATH = $(LIB_PATH)/vusb | |||
| 5 | 5 | ||
| 6 | SRC += $(VUSB_DIR)/main.c \ | 6 | SRC += $(VUSB_DIR)/main.c \ |
| 7 | $(VUSB_DIR)/vusb.c \ | 7 | $(VUSB_DIR)/vusb.c \ |
| 8 | $(VUSB_DIR)/usb_util.c \ | ||
| 8 | $(VUSB_PATH)/usbdrv/usbdrv.c \ | 9 | $(VUSB_PATH)/usbdrv/usbdrv.c \ |
| 9 | $(VUSB_PATH)/usbdrv/usbdrvasm.S \ | 10 | $(VUSB_PATH)/usbdrv/usbdrvasm.S \ |
| 10 | $(VUSB_PATH)/usbdrv/oddebug.c | 11 | $(VUSB_PATH)/usbdrv/oddebug.c |
diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c new file mode 100644 index 000000000..602854dbe --- /dev/null +++ b/tmk_core/protocol/vusb/usb_util.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include <usbdrv/usbdrv.h> | ||
| 17 | #include "usb_util.h" | ||
| 18 | |||
| 19 | void usb_disable(void) { usbDeviceDisconnect(); } | ||
| 20 | |||
| 21 | bool usb_connected_state(void) { | ||
| 22 | usbPoll(); | ||
| 23 | return usbConfiguration; | ||
| 24 | } | ||
