diff options
author | Jack Humbert <jack.humb@gmail.com> | 2018-11-02 12:31:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-02 12:31:40 -0400 |
commit | 15f6278aa623ceda4c220daee1cbedb9e38e6a97 (patch) | |
tree | be1f80786f810c75d0f914899d299c530664d324 | |
parent | 5909d8aef1126357899b687155bfe377914891df (diff) | |
download | qmk_firmware-15f6278aa623ceda4c220daee1cbedb9e38e6a97.tar.gz qmk_firmware-15f6278aa623ceda4c220daee1cbedb9e38e6a97.zip |
Add support for Atmega32A to pin declarations and universal matrix (#4015)
* add computed pins from mcu type
* update for atmega32a
* doc typo
* add atmega16 chips, link to references
* remove avr include from config
* exclude assembler in config.h includes
* consolodate options, add 646
* fix typo in pindef
-rw-r--r-- | docs/internals_gpio_control.md | 2 | ||||
-rw-r--r-- | quantum/config_common.h | 156 | ||||
-rw-r--r-- | quantum/quantum.h | 20 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/usbdrv/usbdrvasm.S | 8 |
4 files changed, 118 insertions, 68 deletions
diff --git a/docs/internals_gpio_control.md b/docs/internals_gpio_control.md index 21643d30c..083e69664 100644 --- a/docs/internals_gpio_control.md +++ b/docs/internals_gpio_control.md | |||
@@ -12,7 +12,7 @@ The following functions can provide basic control of GPIOs and are found in `qua | |||
12 | |`setPinInputHigh(pin)`|Set pin as input with build in pull-up | | 12 | |`setPinInputHigh(pin)`|Set pin as input with build in pull-up | |
13 | |`setPinInputLow(pin)` |Set pin as input with build in pull-down (Supported only on STM32)| | 13 | |`setPinInputLow(pin)` |Set pin as input with build in pull-down (Supported only on STM32)| |
14 | |`setPinOutput(pin)` |Set pin as output | | 14 | |`setPinOutput(pin)` |Set pin as output | |
15 | |`writePinHige(pin)` |Set pin level as high, assuming it is an output | | 15 | |`writePinHigh(pin)` |Set pin level as high, assuming it is an output | |
16 | |`writePinLow(pin)` |Set pin level as low, assuming it is an output | | 16 | |`writePinLow(pin)` |Set pin level as low, assuming it is an output | |
17 | |`writePin(pin, level)`|Set pin level, assuming it is an output | | 17 | |`writePin(pin, level)`|Set pin level, assuming it is an output | |
18 | |`readPin(pin)` |Returns the level of the pin | | 18 | |`readPin(pin)` |Returns the level of the pin | |
diff --git a/quantum/config_common.h b/quantum/config_common.h index 288617255..cbff372ea 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright 2015-2017 Jack Humbert | 1 | /* Copyright 2015-2018 Jack Humbert |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 4 | * it under the terms of the GNU General Public License as published by |
@@ -14,8 +14,7 @@ | |||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef CONFIG_DEFINITIONS_H | 17 | #pragma once |
18 | #define CONFIG_DEFINITIONS_H | ||
19 | 18 | ||
20 | /* diode directions */ | 19 | /* diode directions */ |
21 | #define COL2ROW 0 | 20 | #define COL2ROW 0 |
@@ -23,57 +22,108 @@ | |||
23 | #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ | 22 | #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ |
24 | 23 | ||
25 | #ifdef __AVR__ | 24 | #ifdef __AVR__ |
25 | #ifndef __ASSEMBLER__ | ||
26 | #include <avr/io.h> | ||
27 | #endif | ||
28 | #define PORT_SHIFTER 4 // this may be 4 for all AVR chips | ||
29 | |||
30 | // If you want to add more to this list, reference the PINx definitions in these header | ||
31 | // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr | ||
32 | |||
33 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) | ||
34 | #define ADDRESS_BASE 0x00 | ||
35 | #define PINB_ADDRESS 0x3 | ||
36 | #define PINC_ADDRESS 0x6 | ||
37 | #define PIND_ADDRESS 0x9 | ||
38 | #define PINE_ADDRESS 0xC | ||
39 | #define PINF_ADDRESS 0xF | ||
40 | #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) | ||
41 | #define ADDRESS_BASE 0x00 | ||
42 | #define PINB_ADDRESS 0x3 | ||
43 | #define PINC_ADDRESS 0x6 | ||
44 | #define PIND_ADDRESS 0x9 | ||
45 | #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) | ||
46 | #define ADDRESS_BASE 0x00 | ||
47 | #define PINA_ADDRESS 0x0 | ||
48 | #define PINB_ADDRESS 0x3 | ||
49 | #define PINC_ADDRESS 0x6 | ||
50 | #define PIND_ADDRESS 0x9 | ||
51 | #define PINE_ADDRESS 0xC | ||
52 | #define PINF_ADDRESS 0xF | ||
53 | #elif defined(__AVR_ATmega32A__) | ||
54 | #define ADDRESS_BASE 0x10 | ||
55 | #define PIND_ADDRESS 0x0 | ||
56 | #define PINC_ADDRESS 0x3 | ||
57 | #define PINB_ADDRESS 0x6 | ||
58 | #define PINA_ADDRESS 0x9 | ||
59 | #else | ||
60 | #error "Pins are not defined" | ||
61 | #endif | ||
62 | |||
26 | /* I/O pins */ | 63 | /* I/O pins */ |
27 | #ifndef F0 | 64 | #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin) |
28 | #define B0 0x30 | 65 | |
29 | #define B1 0x31 | 66 | #ifdef PORTA |
30 | #define B2 0x32 | 67 | #define A0 PINDEF(A, 0) |
31 | #define B3 0x33 | 68 | #define A1 PINDEF(A, 1) |
32 | #define B4 0x34 | 69 | #define A2 PINDEF(A, 2) |
33 | #define B5 0x35 | 70 | #define A3 PINDEF(A, 3) |
34 | #define B6 0x36 | 71 | #define A4 PINDEF(A, 4) |
35 | #define B7 0x37 | 72 | #define A5 PINDEF(A, 5) |
36 | #define C0 0x60 | 73 | #define A6 PINDEF(A, 6) |
37 | #define C1 0x61 | 74 | #define A7 PINDEF(A, 7) |
38 | #define C2 0x62 | 75 | #endif |
39 | #define C3 0x63 | 76 | #ifdef PORTB |
40 | #define C4 0x64 | 77 | #define B0 PINDEF(B, 0) |
41 | #define C5 0x65 | 78 | #define B1 PINDEF(B, 1) |
42 | #define C6 0x66 | 79 | #define B2 PINDEF(B, 2) |
43 | #define C7 0x67 | 80 | #define B3 PINDEF(B, 3) |
44 | #define D0 0x90 | 81 | #define B4 PINDEF(B, 4) |
45 | #define D1 0x91 | 82 | #define B5 PINDEF(B, 5) |
46 | #define D2 0x92 | 83 | #define B6 PINDEF(B, 6) |
47 | #define D3 0x93 | 84 | #define B7 PINDEF(B, 7) |
48 | #define D4 0x94 | ||
49 | #define D5 0x95 | ||
50 | #define D6 0x96 | ||
51 | #define D7 0x97 | ||
52 | #define E0 0xC0 | ||
53 | #define E1 0xC1 | ||
54 | #define E2 0xC2 | ||
55 | #define E3 0xC3 | ||
56 | #define E4 0xC4 | ||
57 | #define E5 0xC5 | ||
58 | #define E6 0xC6 | ||
59 | #define E7 0xC7 | ||
60 | #define F0 0xF0 | ||
61 | #define F1 0xF1 | ||
62 | #define F2 0xF2 | ||
63 | #define F3 0xF3 | ||
64 | #define F4 0xF4 | ||
65 | #define F5 0xF5 | ||
66 | #define F6 0xF6 | ||
67 | #define F7 0xF7 | ||
68 | #define A0 0x00 | ||
69 | #define A1 0x01 | ||
70 | #define A2 0x02 | ||
71 | #define A3 0x03 | ||
72 | #define A4 0x04 | ||
73 | #define A5 0x05 | ||
74 | #define A6 0x06 | ||
75 | #define A7 0x07 | ||
76 | #endif | 85 | #endif |
86 | #ifdef PORTC | ||
87 | #define C0 PINDEF(C, 0) | ||
88 | #define C1 PINDEF(C, 1) | ||
89 | #define C2 PINDEF(C, 2) | ||
90 | #define C3 PINDEF(C, 3) | ||
91 | #define C4 PINDEF(C, 4) | ||
92 | #define C5 PINDEF(C, 5) | ||
93 | #define C6 PINDEF(C, 6) | ||
94 | #define C7 PINDEF(C, 7) | ||
95 | #endif | ||
96 | #ifdef PORTD | ||
97 | #define D0 PINDEF(D, 0) | ||
98 | #define D1 PINDEF(D, 1) | ||
99 | #define D2 PINDEF(D, 2) | ||
100 | #define D3 PINDEF(D, 3) | ||
101 | #define D4 PINDEF(D, 4) | ||
102 | #define D5 PINDEF(D, 5) | ||
103 | #define D6 PINDEF(D, 6) | ||
104 | #define D7 PINDEF(D, 7) | ||
105 | #endif | ||
106 | #ifdef PORTE | ||
107 | #define E0 PINDEF(E, 0) | ||
108 | #define E1 PINDEF(E, 1) | ||
109 | #define E2 PINDEF(E, 2) | ||
110 | #define E3 PINDEF(E, 3) | ||
111 | #define E4 PINDEF(E, 4) | ||
112 | #define E5 PINDEF(E, 5) | ||
113 | #define E6 PINDEF(E, 6) | ||
114 | #define E7 PINDEF(E, 7) | ||
115 | #endif | ||
116 | #ifdef PORTF | ||
117 | #define F0 PINDEF(F, 0) | ||
118 | #define F1 PINDEF(F, 1) | ||
119 | #define F2 PINDEF(F, 2) | ||
120 | #define F3 PINDEF(F, 3) | ||
121 | #define F4 PINDEF(F, 4) | ||
122 | #define F5 PINDEF(F, 5) | ||
123 | #define F6 PINDEF(F, 6) | ||
124 | #define F7 PINDEF(F, 7) | ||
125 | #endif | ||
126 | |||
77 | #elif defined(PROTOCOL_CHIBIOS) | 127 | #elif defined(PROTOCOL_CHIBIOS) |
78 | #define A0 PAL_LINE(GPIOA, 0) | 128 | #define A0 PAL_LINE(GPIOA, 0) |
79 | #define A1 PAL_LINE(GPIOA, 1) | 129 | #define A1 PAL_LINE(GPIOA, 1) |
@@ -200,5 +250,3 @@ | |||
200 | #define API_SYSEX_MAX_SIZE 32 | 250 | #define API_SYSEX_MAX_SIZE 32 |
201 | 251 | ||
202 | #include "song_list.h" | 252 | #include "song_list.h" |
203 | |||
204 | #endif | ||
diff --git a/quantum/quantum.h b/quantum/quantum.h index 1d3ee033f..fe670c8eb 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -140,26 +140,28 @@ extern uint32_t default_layer_state; | |||
140 | 140 | ||
141 | //Function substitutions to ease GPIO manipulation | 141 | //Function substitutions to ease GPIO manipulation |
142 | #ifdef __AVR__ | 142 | #ifdef __AVR__ |
143 | #define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset) | ||
144 | |||
143 | #define pin_t uint8_t | 145 | #define pin_t uint8_t |
144 | #define setPinInput(pin) _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF) | 146 | #define setPinInput(pin) PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF) |
145 | #define setPinInputHigh(pin) ({\ | 147 | #define setPinInputHigh(pin) ({\ |
146 | _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF);\ | 148 | PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF);\ |
147 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);\ | 149 | PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);\ |
148 | }) | 150 | }) |
149 | #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low") | 151 | #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low") |
150 | #define setPinOutput(pin) _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF) | 152 | #define setPinOutput(pin) PIN_ADDRESS(pin, 1) |= _BV(pin & 0xF) |
151 | 153 | ||
152 | #define writePinHigh(pin) _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF) | 154 | #define writePinHigh(pin) PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF) |
153 | #define writePinLow(pin) _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF) | 155 | #define writePinLow(pin) PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF) |
154 | static inline void writePin(pin_t pin, uint8_t level){ | 156 | static inline void writePin(pin_t pin, uint8_t level){ |
155 | if (level){ | 157 | if (level){ |
156 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); | 158 | PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF); |
157 | } else { | 159 | } else { |
158 | _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); | 160 | PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF); |
159 | } | 161 | } |
160 | } | 162 | } |
161 | 163 | ||
162 | #define readPin(pin) (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) | 164 | #define readPin(pin) (PIN_ADDRESS(pin, 0) & _BV(pin & 0xF)) |
163 | #elif defined(PROTOCOL_CHIBIOS) | 165 | #elif defined(PROTOCOL_CHIBIOS) |
164 | #define pin_t ioline_t | 166 | #define pin_t ioline_t |
165 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | 167 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) |
diff --git a/tmk_core/protocol/vusb/usbdrv/usbdrvasm.S b/tmk_core/protocol/vusb/usbdrv/usbdrvasm.S index 45fcf1831..2e8097da9 100644 --- a/tmk_core/protocol/vusb/usbdrv/usbdrvasm.S +++ b/tmk_core/protocol/vusb/usbdrv/usbdrvasm.S | |||
@@ -118,7 +118,7 @@ RTMODEL "__rt_version", "3" | |||
118 | # define polyH r21 | 118 | # define polyH r21 |
119 | # define scratch r23 | 119 | # define scratch r23 |
120 | 120 | ||
121 | #else /* __IAR_SYSTEMS_ASM__ */ | 121 | #else /* __IAR_SYSTEMS_ASM__ */ |
122 | /* Register assignments for usbCrc16 on gcc */ | 122 | /* Register assignments for usbCrc16 on gcc */ |
123 | /* Calling conventions on gcc: | 123 | /* Calling conventions on gcc: |
124 | * First parameter passed in r24/r25, second in r22/23 and so on. | 124 | * First parameter passed in r24/r25, second in r22/23 and so on. |
@@ -151,7 +151,7 @@ RTMODEL "__rt_version", "3" | |||
151 | ; unsigned table(unsigned char x) | 151 | ; unsigned table(unsigned char x) |
152 | ; { | 152 | ; { |
153 | ; unsigned value; | 153 | ; unsigned value; |
154 | ; | 154 | ; |
155 | ; value = (unsigned)x << 6; | 155 | ; value = (unsigned)x << 6; |
156 | ; value ^= (unsigned)x << 7; | 156 | ; value ^= (unsigned)x << 7; |
157 | ; if(parity(x)) | 157 | ; if(parity(x)) |
@@ -161,7 +161,7 @@ RTMODEL "__rt_version", "3" | |||
161 | ; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen) | 161 | ; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen) |
162 | ; { | 162 | ; { |
163 | ; unsigned crc = 0xffff; | 163 | ; unsigned crc = 0xffff; |
164 | ; | 164 | ; |
165 | ; while(argLen--) | 165 | ; while(argLen--) |
166 | ; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc); | 166 | ; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc); |
167 | ; return ~crc; | 167 | ; return ~crc; |
@@ -299,7 +299,7 @@ usbCrc16Append: | |||
299 | # define cnt16H r31 | 299 | # define cnt16H r31 |
300 | # define cntH r18 | 300 | # define cntH r18 |
301 | 301 | ||
302 | #else /* __IAR_SYSTEMS_ASM__ */ | 302 | #else /* __IAR_SYSTEMS_ASM__ */ |
303 | /* Register assignments for usbMeasureFrameLength on gcc */ | 303 | /* Register assignments for usbMeasureFrameLength on gcc */ |
304 | /* Calling conventions on gcc: | 304 | /* Calling conventions on gcc: |
305 | * First parameter passed in r24/r25, second in r22/23 and so on. | 305 | * First parameter passed in r24/r25, second in r22/23 and so on. |