Go Down

Topic: Pin Group class ? (Read 119 times) previous topic - next topic


Has anyone written a nice and elegant C++ class/template to implement some sort of "pin group" functionality?
Something that would allow code like:

Code: [Select]
pinGroup <4> BCDPort(6, 7, 8, 9);  // define a 4bit port on D6..D9
BCDPort.pinMode(OUTPUT, OUTPUT, OUTPUT, OUTPUT); // set direct of the bits
BCDPort = 0b1011;  // output 4 bits to the port

Full credit requires that it run on targets other than just AVR.
Extra credit if it's faster than a loop of digitalWrites, and a Gold Star if it recognizes when pins are actually contiguous in some hardware port and uses that fact.

Coding Badly

I have seen something like that.  If I can remember where I will let you know.

For some reason Cosa comes to mind.


You can do that with HWA:

Code: [Select]

/*  Include the HWA definitions for the target device
#include <hwa/attiny84a_pu.h>

/*  Create a HWA object named 'bcdport' as a set of 4 consecutive pins of port0:
 *  PA5,PA4,PA3,PA2
#define _hw_def_bcdport         _io1a, 0, port0, 4, 2

int main ( )
  /*  Configure the 'bcdport' pins as digital (default) outputs.
  hw( configure, bcdport, direction, output );

  /*  Write a BCD digit on the 'bcdport' output pins.
  for ( uint8_t i=0 ; ; i++ )
    hw( write, bcdport, i & 0x0F );

You'd need to create a '_io2a' class to handle 2 sets of consecutive pins.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131