Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Enumerations | Functions
BCM2835 GPIO support

## 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...

## Detailed Description

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!

## Enumeration Type Documentation

enum BCM2835::FunctionSelectType

Prior to using a GPIO pin it requires to get defined for its use as input, output or one of the alternative functions.

See also
  Please refer to FunctionSelect() for more information.

Note
  The library currently only supports functions for input and output. Pins however, can be used for alternative functions though.

Enumerator
Input | Pin is used as input 0b000
Output | Pin is used as output 0b001
Alternate0 | Alt. function 0 0b100
Alternate1 | Alt. function 1 0b101
Alternate2 | Alt. function 2 0b110
Alternate3 | Alt. function 3 0b111
Alternate4 | Alt. function 4 0b011
Alternate5 | Alt. function 5 0b010
FSEL_MASK | Function select bits mask 0b111

Definition at line 915 of file hubolib.h.

enum BCM2835::PullUpDownType

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.

See also
  Please refer to SetPullUpDown() for more information.

Enumerator
PUD_OFF | Neither pull up nor poll down 0b00
PUD_DOWN | Pull down active 0b01
PUD_UP | Pull up active 0b10

Definition at line 935 of file hubolib.h.

## Function Documentation

void BCM2835::ClearPin | ( | unsigned char | pin | ) |

Resets a pin configured as output to 0.

This function is internally be used by WritePin().

Parameters

  pi | The output pin to reset to zero.

See also
  See also SetPin() and WritePin(). For an example on how to use ClearPin() refer to the demos GPIOInputOutput.cpp and RCSocket.cpp.

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.

Parameters

  pin | The pin to configure to operate in one of the modes.
  mode | One of the values of input, output or an alternative function.

See also
  For more information see the enum type FunctionSelectType. For an example on how to use FunctionSelectPin() refer to the demos GPIOInputOutput.cpp and RCSocket.cpp.

bool BCM2835::IsGPIOInitialized | ( |  | ) |

Returns the status of the initialisation of the GPIO part of the library.

Returns
  True if the GPIO interface was initialized correct. If the function returns false then none of the GPIO interface functions must get called!

See also
  For an example on how to use IsGPIOInitialized() refer to the demos GPIOInputOutput.cpp and RCSocket.cpp.

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.

Parameters

  pin | The pin to read from.

Returns
  The value of the pin. This can either be 0 or 1.

See also
  For an example on how to use ReadPin() refer to the demo GPIOInputOutput.cpp.

void BCM2835::SetPin | ( | unsigned char | pin | ) |

Sets a pin configured as output to 1.

This function is internally be used by WritePin().

Parameters

  pi | The output pin to set to 1.

See also
  See also ClearPin() and WritePin(). For an example on how to use SetPin() refer to the demos GPIOInputOutput.cpp and RCSocket.cpp.

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.

Parameters

  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.

See also
  See also the enum type PullUpDownType. For an example on how to use SetPullUpDown() refer to the demo GPIOInputOutput.cpp.

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.

Parameters

  pin | The output pin to modify.
  value | the value to set the pin to (0 or 1).

See also
  See also SetPin() and ClearPin(). For an example on how to use WritePin() refer to the demo GPIOInputOutput.cpp.