simplified version with chip defines

matrix_update
Jack Humbert 7 years ago
parent b653791d21
commit a4601e0f77

@ -17,24 +17,49 @@
#ifndef CONFIG_DEFINITIONS_H
#define CONFIG_DEFINITIONS_H
#if defined(__AVR__)
#include <avr/io.h>
#endif
/* diode directions */
#define COL2ROW 0
#define ROW2COL 1
#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
#if defined(__AVR__)
#include <avr/io.h>
#define PORT_SHIFTER 4
#if defined(__AVR_ATmega32U4__)
#define pin_t uint8_t
#define ADDRESS_BASE 0x00
#define PINB_ADDRESS 0x3
#define PINC_ADDRESS 0x6
#define PIND_ADDRESS 0x9
#define PINE_ADDRESS 0xC
#define PINF_ADDRESS 0xF
#elif defined(__AVR_AT90USB1286__)
#define pin_t uint8_t
#define ADDRESS_BASE 0x00
#define PINA_ADDRESS 0x0
#define PINB_ADDRESS 0x3
#define PINC_ADDRESS 0x6
#define PIND_ADDRESS 0x9
#define PINE_ADDRESS 0xC
#define PINF_ADDRESS 0xF
#elif defined(__AVR_ATmega32a__)
#define pin_t uint8_t
#define ADDRESS_BASE 0x10
#define PIND_ADDRESS 0x0
#define PINC_ADDRESS 0x3
#define PINB_ADDRESS 0x6
#define PINB_ADDRESS 0x9
#else
#define pin_t uint16_t
#define ADDRESS_BASE 0x0
#endif
/* I/O pins */
// #define PINDEF(port, pin) (uint8_t)((((uint16_t)&PIN##port) << 4) + PIN##port##pin)
#define PINDEF(port, pin) ((pin_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))
#define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
#ifdef PORTA
#define A0 PINDEF(A, 0)
@ -96,6 +121,70 @@
#define F6 PINDEF(F, 6)
#define F7 PINDEF(F, 7)
#endif
#endif
#if defined(PROTOCOL_CHIBIOS)
#include "hal.h"
#define pin_t uint64_t
#ifdef GPIOA
#define A0 (GPIOA + 0)
#define A1 (GPIOA + 1)
#define A2 (GPIOA + 2)
#define A3 (GPIOA + 3)
#define A4 (GPIOA + 4)
#define A5 (GPIOA + 5)
#define A6 (GPIOA + 6)
#define A7 (GPIOA + 7)
#define A8 (GPIOA + 8)
#define A9 (GPIOA + 9)
#define A10 (GPIOA + 10)
#define A11 (GPIOA + 11)
#define A12 (GPIOA + 12)
#define A13 (GPIOA + 13)
#define A14 (GPIOA + 14)
#define A15 (GPIOA + 15)
#endif
#ifdef GPIOB
#define B0 (GPIOB + 0)
#define B1 (GPIOB + 1)
#define B2 (GPIOB + 2)
#define B3 (GPIOB + 3)
#define B4 (GPIOB + 4)
#define B5 (GPIOB + 5)
#define B6 (GPIOB + 6)
#define B7 (GPIOB + 7)
#define B8 (GPIOB + 8)
#define B9 (GPIOB + 9)
#define B10 (GPIOB + 10)
#define B11 (GPIOB + 11)
#define B12 (GPIOB + 12)
#define B13 (GPIOB + 13)
#define B14 (GPIOB + 14)
#define B15 (GPIOB + 15)
#endif
#ifdef GPIOC
#define C0 (GPIOC + 0)
#define C1 (GPIOC + 1)
#define C2 (GPIOC + 2)
#define C3 (GPIOC + 3)
#define C4 (GPIOC + 4)
#define C5 (GPIOC + 5)
#define C6 (GPIOC + 6)
#define C7 (GPIOC + 7)
#define C8 (GPIOC + 8)
#define C9 (GPIOC + 9)
#define C10 (GPIOC + 10)
#define C11 (GPIOC + 11)
#define C12 (GPIOC + 12)
#define C13 (GPIOC + 13)
#define C14 (GPIOC + 14)
#define C15 (GPIOC + 15)
#endif
#endif
/* USART configuration */

@ -1,4 +1,5 @@
/* Copyright 2016 Wez Furlong
* 2017 Jack Humbert
*
* 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
@ -14,23 +15,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
// Some helpers for controlling gpio pins
#if defined(PROTOCOL_CHIBIOS)
#include "hal.h"
#define PIN_VALUE(p) palReadPad(p & 0xFFFFFFF0, p & 0xF)
#define DDR_OUTPUT(p) palSetPadMode(p & 0xFFFFFFF0, p & 0xF, PAL_MODE_OUTPUT_PUSHPULL)
#define DDR_INPUT(p) palSetPadMode(p & 0xFFFFFFF0, p & 0xF, PAL_MODE_INPUT_PULLDOWN)
#define PORT_HIGH(p) palSetPad(p & 0xFFFFFFF0, p & 0xF)
#define PORT_LOW(p) palClearPad(p & 0xFFFFFFF0, p & 0xF)
#endif
#if defined(__AVR__)
#include <avr/io.h>
#endif
static inline volatile uint8_t* helper(pin_t p, uint8_t offset) {
return (volatile uint8_t*)((p >> 4) + offset + __SFR_OFFSET);
}
#define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
#define PIN(p) *helper(p, 0)
#define PIN(p) PIN_ADDRESS(p, 0)
#define PIN_VALUE(p) (PIN(p) & _BV(p & 0xF))
#define DDR(p) *helper(p, 1)
#define DDR(p) PIN_ADDRESS(p, 1)
#define DDR_OUTPUT(p) (DDR(p) |= _BV(p & 0xF))
#define DDR_INPUT(p) (DDR(p) &= ~_BV(p & 0xF))
#define PORT(p) *helper(p, 2)
#define PORT(p) PIN_ADDRESS(p, 2)
#define PORT_HIGH(p) (PORT(p) |= _BV(p & 0xF))
#define PORT_LOW(p) (PORT(p) &= ~_BV(p & 0xF))
@ -69,3 +82,5 @@ static inline void digitalWrite(uint8_t pin, int mode) {
static inline bool digitalRead(uint8_t pin) {
return _SFR_IO8(pin >> 4) & _BV(pin & 0xf);
}
#endif
Loading…
Cancel
Save