doing something clever with macro prefixes, which didn't work

i'd like to keep it around in the history though, just for fun - :)
partial-rewrite
Ben Blazak 2012-03-21 16:51:42 -07:00
parent 19725eed4a
commit b77e74cacd
1 changed files with 40 additions and 21 deletions

View File

@ -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
* <https://github.com/benblazak/ergodox-firmware>
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#include <avr/io.h> // 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 <avr/io.h> // 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