Hubo Library
|
Data Structures | |
class | BCM2835::BCM2835_Config |
Use to configure BCM2835 specific parameters. More... | |
Enumerations | |
enum | BCM2835::FunctionSelectType { BCM2835::Input = 0x00, BCM2835::Output = 0x01, BCM2835::Alternate0 = 0x04, BCM2835::Alternate1 = 0x05, BCM2835::Alternate2 = 0x06, BCM2835::Alternate3 = 0x07, BCM2835::Alternate4 = 0x03, BCM2835::Alternate5 = 0x02, BCM2835::FSEL_MASK = 0x07 } |
Prior to using a GPIO pin it requires to get defined for its use as input, output or one of the alternative functions. More... | |
enum | BCM2835::PullUpDownType { BCM2835::PUD_OFF = 0x00, BCM2835::PUD_DOWN = 0x01, BCM2835::PUD_UP = 0x02 } |
Pins configured as input can make use of internal pull up or down resistors. More... | |
Functions | |
bool | BCM2835::IsGPIOInitialized () |
Returns the status of the initialisation of the GPIO part of the library. More... | |
void | BCM2835::FunctionSelectPin (unsigned char pin, FunctionSelectType mode) |
Use FunctionSelect() to configure the mode of a BCM2835 pin. More... | |
void | BCM2835::WritePin (unsigned char pin, unsigned char value) |
Sets or clears a pin configured to be an output. More... | |
void | BCM2835::SetPin (unsigned char pin) |
Sets a pin configured as output to 1. More... | |
void | BCM2835::ClearPin (unsigned char pin) |
Resets a pin configured as output to 0. More... | |
void | BCM2835::SetPullUpDown (unsigned char pin, PullUpDownType pud) |
Enables or disables the BCM2835 internal pull -up or -down resistors for a pin configured as an input. More... | |
unsigned short | BCM2835::ReadPin (unsigned short pin) |
Reads the value of an (input) pin. More... | |
Hubo library provides basic support to configuring, reading and writing of the BCM2835 GPIO pins. In contrast to the Hubo hardware related functions the execution of the GPIO related functions will take place in the context of the callers thread - hence they will not be propagated to the Hubo background thread. However, in order to support for better multi threading behaviour a mutex is applied to each of the functions entry in order to protect operations at thread level. The usage of the mutex can be controlled through BCM2835_Config which provides a member to turn off the usage of the mutex for high performance operations.
Access to the BCM2835 is gained through the chips registers directly.
Hubo library will automatically detect the type of GPIO chip (BCM2708/BCM2709) during initialization. However, note that all pin numbering follows the BCM2835 pin numbering scheme - thus is not identical to the pin numbering of the GPIO pin headers of the various hardware versions of the Raspberry Pi!
Prior to using a GPIO pin it requires to get defined for its use as input, output or one of the alternative functions.
Pins configured as input can make use of internal pull up or down resistors.
If no resistors are to be used then use PUD_OFF.
Enumerator | |
---|---|
PUD_OFF |
Neither pull up nor poll down 0b00 |
PUD_DOWN |
Pull down active 0b01 |
PUD_UP |
Pull up active 0b10 |
void BCM2835::ClearPin | ( | unsigned char | pin | ) |
Resets a pin configured as output to 0.
This function is internally be used by WritePin().
pi | The output pin to reset to zero. |
void BCM2835::FunctionSelectPin | ( | unsigned char | pin, |
FunctionSelectType | mode | ||
) |
Use FunctionSelect() to configure the mode of a BCM2835 pin.
A failure initializing the library is usually indicating a problem with insufficient user rights creating the memory map in order to access the BCM registers.
pin | The pin to configure to operate in one of the modes. |
mode | One of the values of input, output or an alternative function. |
bool BCM2835::IsGPIOInitialized | ( | ) |
Returns the status of the initialisation of the GPIO part of the library.
unsigned short BCM2835::ReadPin | ( | unsigned short | pin | ) |
Reads the value of an (input) pin.
While this function is mainly be used on pins configured as inputs, it can also be used to read back the values set to an output. This can be handy in order to check the state of an output pin in a multi threaded application where multiple threads set one and the same output.
pin | The pin to read from. |
void BCM2835::SetPin | ( | unsigned char | pin | ) |
Sets a pin configured as output to 1.
This function is internally be used by WritePin().
pi | The output pin to set to 1. |
void BCM2835::SetPullUpDown | ( | unsigned char | pin, |
PullUpDownType | pud | ||
) |
Enables or disables the BCM2835 internal pull -up or -down resistors for a pin configured as an input.
pin | The input pin to apply or remove pull -up or -down resistors. |
pud | The value to set - hence pull up, pull down or no resistor at all. |
void BCM2835::WritePin | ( | unsigned char | pin, |
unsigned char | value | ||
) |
Sets or clears a pin configured to be an output.
If value is non zero the pin gets set otherwise the pin gets cleared.
pin | The output pin to modify. |
value | the value to set the pin to (0 or 1). |