Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Use of the preprocesser to keep HW straight

2007-03-26 by thormj_altea

With all this talk on using bits & shifts & macros, I figured I 
should toss another one out:  Keeping track of which bits are used 
using the preprocessor...

I've been playing around with SiLabs' 8051 chips and their nifty 
digital crossbar (err... that thing is a pain, but it is nifty), and 
coming the AVR world has been a bit of a shock -- all pins don't do 
all things.

Background:

I've been playing with the AT90PWM2, and I wanted to add a I2C *or* a 
SPI bus to the project (no, not a silly DALI control.  I want it to 
talk to an Echelon part),  but after combing through the datasheets, 
it looked like the EUSART 
  1. wouldn't do I2C (nuts)
  2. SPI [slave] requires an additional line for the select, 
     and I'm using that for the power stage output.  The datasheets
     don't mention a way of hardcoding it (there's only 2 chips.  It 
     is *always* selected)

But figuring that out was annoying.

I've even been thinking of a way to do something like:

#define	PIN1	ADC0
#define PIN2	ADC1
#define PIN22	OCRA
#define PIN33	OCRB

#define ADC0_used
#define ADC1_used
#define OCR_used

//*** CheckPorts.h
#ifdef ADC0_used
#ifdef PA1_DIGITAL
#error "Pin one is ADC & Digital"
#endif
#endif
#ifdef PSC2_used
#ifdef SPI_ALTERNATE
#error "PSC2 uses SPI/SS_a as Bottom Mosfet"
#endif
#endif
  ...

---
But:
  1. Is this really useful for the compiler?  I'm beginning to keep 
it straight (for the current project; maybe I shouldn't be doing 3 at 
once)...
  2. Note the disconnect -- #define PIN1  ADC0, but I still have to 
redo it vice-versa (#define ADC0_used).  Keeping track of this seems 
worse than #1.

Do you guys keep it all in your head and comments, or is there anyone 
out there with a better way?

Thanks,
Thor

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.