avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Re: Variable Pinouts


From: Steve Franks
Subject: [avr-chat] Re: Variable Pinouts
Date: Thu, 24 Aug 2006 09:26:56 -0700

Since we've brought up the topic, I'll mention that I've been doing all my HAL's with template classes.  I've been very satisfied with it as a technique, and I can change processors/boards/etc smootly, just by changing the 'type' the template is based on.  Since templates are handled by the preprocessor, I don't think it adds overhead either.  You do need to do a couple extra things, though, such as wrapping your interrupt handlers, as well as many 3rd party headers in extern "C" {} blocks so the c++ compiler will chew on them.

Example:

struct Led1_Mega128_BoardA
{
    _inline_ Light(bool Onoff) { DDRblah=1; PORTblah=blah; }
};

struct Led2_Mega128_BoardA
{
    _inline_ Light(bool Onoff) { DDRblah=1; PORTblah=blah; }
};

template class hal
struct Somesuch : public hal
{
    using hal::Light;
    void DoSomething() { Light(1); }
};

main()
{
   Somesuch<Led1_Mega128_BoardA> thing1;
   Somesuch<Led2_Mega128_BoardA> thing2;

  thing1.DoSomething();
  thing2.DoSomething();

 ....

Another nice aspect is if you put the hal in one file and the behavior in another file, all the processor-specific includes are in a single file, which can really un-yuck your hierarchy sometimes.  Also it let's you conceal hardware details (such as inverted drive for leds) into a programmer-centric behavior ( i.e. 1=on always, regardless if led connected to Gnd or Vcc), which can make things nicer for teams with non-hw-savvy programmers on them.

Steve

--
Steve Franks, KE7BTE
Staff Engineer
La Palma Devices, LLC
http://www.lapalmadevices.com
(520) 312-0089
reply via email to

[Prev in Thread] Current Thread [Next in Thread]