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

Allow some usbconfig.h overrides at the keyboard level #8647

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Apr 1, 2020

Description

Currently there is no way to override options within usbconfig.h, which is fine till you need to use different pins for the usb port.

If you add an override file at the keyboard level(as a short term workaround), it produces the following sort of errors:

Compiling: tmk_core/protocol/vusb/vusb.c                                                           In file included from tmk_core/protocol/vusb/vusb.c:22:0:
tmk_core/protocol/vusb/usbconfig.h:27:0: error: "USB_CFG_IOPORTNAME" redefined [-Werror]
 #define USB_CFG_IOPORTNAME      D
 ^
In file included from tmk_core/protocol/vusb/usbdrv/usbdrv.h:13:0,
                 from tmk_core/protocol/vusb/vusb.c:21:
keyboards/xd002/usbconfig.h:26:0: note: this is the location of the previous definition
 #define USB_CFG_IOPORTNAME      B
 ^
In file included from tmk_core/protocol/vusb/vusb.c:22:0:
tmk_core/protocol/vusb/usbconfig.h:35:0: error: "USB_CFG_DPLUS_BIT" redefined [-Werror]
 #define USB_CFG_DPLUS_BIT       2
 ^
In file included from tmk_core/protocol/vusb/usbdrv/usbdrv.h:13:0,
                 from tmk_core/protocol/vusb/vusb.c:21:
keyboards/xd002/usbconfig.h:34:0: note: this is the location of the previous definition
 #define USB_CFG_DPLUS_BIT       4
 ^
In file included from tmk_core/protocol/vusb/vusb.c:22:0:
tmk_core/protocol/vusb/usbconfig.h:81:0: error: "USB_CFG_HAVE_INTRIN_ENDPOINT3" redefined [-Werror]
 #define USB_CFG_HAVE_INTRIN_ENDPOINT3   1
 ^

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@zvecr zvecr requested review from fauxpark and a team April 1, 2020 20:48
@drashna drashna requested a review from a team April 2, 2020 07:26
@fauxpark
Copy link
Member

fauxpark commented Apr 2, 2020

Why not wrap them in #ifndefs and allow it to be overridden at the config.h level?

@zvecr
Copy link
Member Author

zvecr commented Apr 2, 2020

Why not wrap them in #ifndefs and allow it to be overridden at the config.h level?

This was just a short term, lightest touch bodge to get be back up and running since I rebased and picked up #8584. If we want the longer term solution I can prepare that instead.

@fauxpark
Copy link
Member

fauxpark commented Apr 2, 2020

The only things I can really see needing configurability are USB_CFG_IOPORTNAME, USB_CFG_DMINUS_BIT, and USB_CFG_DPLUS_BIT. The rest is sort of intrinsic to how QMK itself uses V-USB.

@zvecr
Copy link
Member Author

zvecr commented Apr 2, 2020

Currently the patch looks like:

diff --git a/tmk_core/protocol/vusb/usbconfig.h b/tmk_core/protocol/vusb/usbconfig.h
index f15616351..88d29ac94 100644
--- a/tmk_core/protocol/vusb/usbconfig.h
+++ b/tmk_core/protocol/vusb/usbconfig.h
@@ -23,16 +23,22 @@ section at the end of this file).
 */
 
 /* ---------------------------- Hardware Config ---------------------------- */
-
+#ifndef USB_CFG_IOPORTNAME
 #define USB_CFG_IOPORTNAME      D
+#endif
+
 /* This is the port where the USB bus is connected. When you configure it to
  * "B", the registers PORTB, PINB and DDRB will be used.
  */
+#ifndef USB_CFG_DMINUS_BIT
 #define USB_CFG_DMINUS_BIT      3
+#endif
 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
  * This may be any bit in the port.
  */
+#ifndef USB_CFG_DPLUS_BIT
 #define USB_CFG_DPLUS_BIT       2
+#endif
 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
  * This may be any bit in the port. Please note that D+ must also be connected
  * to interrupt pin INT0! [You can also use other interrupts, see section
@@ -78,7 +84,9 @@ section at the end of this file).
  * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
  * number).
  */
+#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
 #define USB_CFG_HAVE_INTRIN_ENDPOINT3   1
+#endif
 /* Define this to 1 if you want to compile a version with three endpoints: The
  * default control endpoint 0, an interrupt-in endpoint 3 (or the number
  * configured below) and a catch-all default interrupt-in endpoint as above.
@@ -123,7 +131,9 @@ section at the end of this file).
  * data from a static buffer, set it to 0 and return the data from
  * usbFunctionSetup(). This saves a couple of bytes.
  */
+#ifndef USB_CFG_IMPLEMENT_FN_WRITEOUT
 #define USB_CFG_IMPLEMENT_FN_WRITEOUT   1
+#endif
 /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
  * You must implement the function usbFunctionWriteOut() which receives all
  * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
@@ -160,7 +170,9 @@ section at the end of this file).
 /* This macro (if defined) is executed when a USB SET_ADDRESS request was
  * received.
  */
+#ifndef USB_COUNT_SOF
 #define USB_COUNT_SOF                   1
+#endif
 /* define this macro to 1 if you need the global variable "usbSofCount" which
  * counts SOF packets. This feature requires that the hardware interrupt is
  * connected to D- instead of D+.
@@ -342,11 +354,23 @@ section at the end of this file).
 /* #define USB_INTR_VECTOR         INT0_vect */
 
 /* Set INT1 for D- falling edge to count SOF */
+#ifndef USB_INTR_CFG
 /* #define USB_INTR_CFG            EICRA */
+#endif
+#ifndef USB_INTR_CFG_SET
 #define USB_INTR_CFG_SET        ((1 << ISC11) | (0 << ISC10))
+#endif
 /* #define USB_INTR_CFG_CLR        0 */
 /* #define USB_INTR_ENABLE         EIMSK */
+#ifndef USB_INTR_ENABLE_BIT
 #define USB_INTR_ENABLE_BIT     INT1
+#endif
 /* #define USB_INTR_PENDING        EIFR */
+#ifndef USB_INTR_PENDING_BIT
 #define USB_INTR_PENDING_BIT    INTF1
+#endif
+#ifndef USB_INTR_VECTOR
 #define USB_INTR_VECTOR         INT1_vect
+#endif
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 9ecbe0c7a..00314ebe8 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -19,7 +19,7 @@ along with this program.  If not, see <http:https://www.gnu.org/licenses/>.
 #include <avr/wdt.h>
 #include <stdint.h>
 #include "usbdrv.h"
-#include <usbconfig.h>
+#include "usbconfig.h"
 #include "host.h"
 #include "report.h"
 #include "print.h"

Ive also seen https://codeandlife.com/2012/02/22/v-usb-with-attiny45-attiny85-without-a-crystal/ override some extra config to do with clock configuration but ive not needed it yet.

@zvecr zvecr force-pushed the feature/usbconfig_include branch from 2ac1932 to 6d7ebc8 Compare April 20, 2020 19:35
@zvecr zvecr changed the title Allow usbconfig.h to still exist at the keyboard level Allow some usbconfig.h overrides at the keyboard level Apr 20, 2020
@zvecr zvecr requested a review from drashna April 20, 2020 19:35
@zvecr
Copy link
Member Author

zvecr commented Apr 20, 2020

Updated with the proposed longer term changes.

@zvecr zvecr requested a review from fauxpark April 20, 2020 23:02
@zvecr zvecr mentioned this pull request Apr 20, 2020
15 tasks
Copy link
Member

@drashna drashna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zvecr zvecr merged commit 374525c into qmk:master Apr 28, 2020
mrlinuxfish pushed a commit to mrlinuxfish/qmk_firmware that referenced this pull request May 3, 2020
bitherder pushed a commit to bitherder/qmk_firmware that referenced this pull request May 15, 2020
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request May 24, 2020
sowbug pushed a commit to sowbug/qmk_firmware that referenced this pull request May 24, 2020
fdidron pushed a commit to zsa/qmk_firmware that referenced this pull request Jun 12, 2020
turky pushed a commit to turky/qmk_firmware that referenced this pull request Jun 13, 2020
jakobaa pushed a commit to jakobaa/qmk_firmware that referenced this pull request Jul 7, 2020
sjmacneil pushed a commit to sjmacneil/qmk_firmware that referenced this pull request Feb 19, 2021
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants