libpropeller
Making PropellerGCC Easier
|
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... | |
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.
INLINE Pin::Pin | ( | ) |
Create a null pin (pin with no effect).
INLINE Pin::Pin | ( | int | pin) |
Create the pin instance.
pin | the I/O pin number (0 through 31) to control. |
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.
INLINE bool Pin::isOutput | ( | void | ) |
Get the input or output direction.
INLINE void Pin::low | ( | void | ) |
Set pin to output low.
INLINE void Pin::output | ( | int | setting) |
Output a value on the pin.
setting | 1 to output high, 0 to output low. |
|
inline |
Output a PWM wave on a pin.
decihz | The frequency to PWM at. A parameter of 0 disables the PWM. |
useCTRA | Explicitly specify which counter to use. True for CTRA, false for CTRB |
alternatePin | Specify a pin to have an alternating PWM on. That pin will be the logical inverse of whatever this pin is. |
INLINE void Pin::toggle | ( | void | ) |
Toggle the pin on output.
If it was low, make it high. If it was high, make it low.