2
0
Jack Humbert 8 лет назад
Родитель
Сommit
7dbe94d4ac
2 измененных файлов с 17 добавлено и 7 удалено
  1. 14 4
      quantum/config_common.h
  2. 3 3
      quantum/matrix.c

+ 14 - 4
quantum/config_common.h

@@ -26,18 +26,28 @@
 #define ROW2COL       1
 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
 
+#if defined(__AVR_ATmega32U4__)
+    #define pin_t uint8_t
+#else
+    #define pin_t uint16_t
+#endif
+
 /* I/O pins */
 // #define PINDEF(port, pin) (uint8_t)((((uint16_t)&PIN##port) << 4) + PIN##port##pin)
-#define PINDEF(port, pin) (uint8_t)(((((uint16_t)&PIN##port) - __SFR_OFFSET)<< 4) + PIN##port##pin)
+#define PINDEF(port, pin) ((pin_t)(((((uint16_t)&PIN##port) - __SFR_OFFSET)<< 4) + PIN##port##pin))
+
+static inline uint8_t* helper(pin_t p, uint8_t offset) {
+    return (uint8_t*)((p >> 4) + offset + __SFR_OFFSET);
+}
 
-#define PIN(p) (*((volatile uint16_t*)(p >> 4) + 0 + __SFR_OFFSET))
+#define PIN(p) *helper(p, 0)
 #define PIN_VALUE(p) (PIN(p) & _BV(p & 0xF))
 
-#define DDR(p) (*((volatile uint16_t*)(p >> 4) + 1 + __SFR_OFFSET))
+#define DDR(p) *helper(p, 1)
 #define DDR_OUTPUT(p) (DDR(p) |= _BV(p & 0xF))
 #define DDR_INPUT(p) (DDR(p) &= ~_BV(p & 0xF))
 
-#define PORT(p) (*((volatile uint16_t*)(p >> 4) + 2 + __SFR_OFFSET))
+#define PORT(p) *helper(p, 2)
 #define PORT_HIGH(p) (PORT(p) |= _BV(p & 0xF))
 #define PORT_LOW(p) (PORT(p) &= ~_BV(p & 0xF))
 

+ 3 - 3
quantum/matrix.c

@@ -60,8 +60,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #endif
 
 #if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
-static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
-static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
+static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
+static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
 #endif
 
 /* matrix state(1:on, 0:off) */
@@ -221,7 +221,7 @@ uint8_t matrix_scan(void)
 #   endif
 
     
-    dprintf("%x\n", PINDEF(B,0));
+    dprintf("%x\n", B0);
     matrix_scan_quantum();
 
     return 1;