libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
Pin Class Reference

Pin class to allow access to single pins. More...

#include <pin.h>

Public Member Functions

 Pin ()
 Create a null pin (pin with no effect). More...
 
 Pin (int pin)
 Create the pin instance. More...
 
int getPin (void)
 Get the pin number [0..31]. More...
 
void high (void)
 Set pin to output high. More...
 
void low (void)
 Set pin to output low. More...
 
void toggle (void)
 Toggle the pin on output. More...
 
int input (void)
 Set the pin to input and get it's value. More...
 
void output (int setting)
 Output a value on the pin. More...
 
bool isOutput (void)
 Get the input or output direction. More...
 
void pwm (const int decihz, const bool useCTRA=true, Pin *alternatePin=NULL)
 Output a PWM wave on a pin. More...
 

Detailed Description

Pin class to allow access to single pins.

What's with the attribute((always_inline))? SRLM found that the forced inlining is essential to performance. Without it GCC would not inline a function (even if marked) if it was used more than two or three times. This has a rather drastic performance impact. It does come at the expense of some space, however. For example, the high() function expands to 5 instructions:

mov r7, OUTA
rdlong  r6, r3
or  r7, r6
mov OUTA, r7
or  DIRA,r6

If you use high() in many places the total could add up. On the other hand, the forced inlining may give the optimizer more chances to make things small. You should try it both ways and compare.

The original source for this class was posted by David Michael Betz, and modified by SRLM.

Constructor & Destructor Documentation

INLINE Pin::Pin ( )

Create a null pin (pin with no effect).

INLINE Pin::Pin ( int  pin)

Create the pin instance.

Parameters
pinthe I/O pin number (0 through 31) to control.

Member Function Documentation

INLINE int Pin::getPin ( void  )

Get the pin number [0..31].

Returns -1 if no pin.

INLINE void Pin::high ( void  )

Set pin to output high.

INLINE int Pin::input ( void  )

Set the pin to input and get it's value.

Returns
1 if the pin is high, 0 if it is low.
INLINE bool Pin::isOutput ( void  )

Get the input or output direction.

Warning
Can only tell if the output bit is set for this cog (not all cogs)
Returns
true if output, false if input
INLINE void Pin::low ( void  )

Set pin to output low.

INLINE void Pin::output ( int  setting)

Output a value on the pin.

Parameters
setting1 to output high, 0 to output low.

Here is the call graph for this function:

void Pin::pwm ( const int  decihz,
const bool  useCTRA = true,
Pin alternatePin = NULL 
)
inline

Output a PWM wave on a pin.

Warning
You MUST stop the PWM by calling this function with a frequency of 0!. Otherwise the Propeller counters will continue to output the PWM, even if this class has been garbage collected and destroyed.
This function uses the Propeller counters. There are only two per cog, so that means that you can have up to two PWM waves and that's it! In addition, nothing else can use the counters.
Parameters
decihzThe frequency to PWM at. A parameter of 0 disables the PWM.
useCTRAExplicitly specify which counter to use. True for CTRA, false for CTRB
alternatePinSpecify a pin to have an alternating PWM on. That pin will be the logical inverse of whatever this pin is.

Here is the call graph for this function:

INLINE void Pin::toggle ( void  )

Toggle the pin on output.

If it was low, make it high. If it was high, make it low.


The documentation for this class was generated from the following file: