From b77e74cacd05812e67321b24e00528802a5b7ca1 Mon Sep 17 00:00:00 2001 From: Ben Blazak Date: Wed, 21 Mar 2012 16:51:42 -0700 Subject: [PATCH] doing something clever with macro prefixes, which didn't work i'd like to keep it around in the history though, just for fun - :) --- src/keyboard/ergodox/teensy-2-0.h | 61 ++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/keyboard/ergodox/teensy-2-0.h b/src/keyboard/ergodox/teensy-2-0.h index 7415ab0..9e0ce9b 100644 --- a/src/keyboard/ergodox/teensy-2-0.h +++ b/src/keyboard/ergodox/teensy-2-0.h @@ -1,36 +1,55 @@ /* ---------------------------------------------------------------------------- * ergoDOX controller: Teensy 2.0 specific exports * ---------------------------------------------------------------------------- - * Copyright (c) 2012 Ben Blazak - * Released under The MIT License (MIT) (see "license.md") at - * + * Copyright (c) 2012 Ben Blazak + * Released under The MIT License (MIT) (see "license.md") + * Project located at * ------------------------------------------------------------------------- */ -#include // for the register macros - - #ifndef TEENSY_2_0_h -#define TEENSY_2_0_h + #define TEENSY_2_0_h + #ifndef INCLUDE_PREFIX + #define INCLUDE_PREFIX teensy_ + #endif -// LED control -#define TEENSY_LED1_ON (OCR1A = 0xFF) -#define TEENSY_LED1_OFF (OCR1A = 0x00) -#define TEENSY_LED1_SET(n) (OCR1A = (uint8_t)(n)) -#define TEENSY_LED1_SET_PERCENT(n) (OCR1A = (uint8_t)((n) * 0xFF)) -#define TEENSY_LED2_ON (OCR1B = 0xFF) -#define TEENSY_LED2_OFF (OCR1B = 0x00) -#define TEENSY_LED2_SET(n) (OCR1B = (uint8_t)(n)) -#define TEENSY_LED2_SET_PERCENT(n) (OCR1B = (uint8_t)((n) * 0xFF)) -#define TEENSY_LED3_ON (OCR1C = 0xFF) -#define TEENSY_LED3_OFF (OCR1C = 0x00) -#define TEENSY_LED3_SET(n) (OCR1C = (uint8_t)(n)) -#define TEENSY_LED3_SET_PERCENT(n) (OCR1C = (uint8_t)((n) * 0xFF)) + #define prefix(s) INCLUDE_PREFIX##s + #define pprefix(s) PRIVATE_INCLUDE_PREFIX##s + // -------------------------------------------------------------------- -void teensy_init(void); + #include // for the register macros + // LED control + #define prefix(LED1_ON) (OCR1A = 0xFF) + #define prefix(LED1_OFF) (OCR1A = 0x00) + #define prefix(LED1_SET)(n) (OCR1A = (uint8_t)(n)) + #define prefix(LED1_SET_PERCENT)(n) (OCR1A = (uint8_t)((n) * 0xFF)) + #define prefix(LED2_ON) (OCR1B = 0xFF) + #define prefix(LED2_OFF) (OCR1B = 0x00) + #define prefix(LED2_SET)(n) (OCR1B = (uint8_t)(n)) + #define prefix(LED2_SET_PERCENT)(n) (OCR1B = (uint8_t)((n) * 0xFF)) + #define prefix(LED3_ON) (OCR1C = 0xFF) + #define prefix(LED3_OFF) (OCR1C = 0x00) + #define prefix(LED3_SET)(n) (OCR1C = (uint8_t)(n)) + #define prefix(LED3_SET_PERCENT)(n) (OCR1C = (uint8_t)((n) * 0xFF)) + + // -------------------------------------------------------------------- + + #ifdef PRIVATE_INCLUDE_PREFIX + + void pprefix(init)(void) + __attribute__((alias ("teensy_init"))); + + #endif + + // -------------------------------------------------------------------- + + #undef prefix + #undef pprefix + #undef INCLUDE_PREFIX + #undef PRIVATE_INCLUDE_PREFIX #endif