Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
rpihw::driver::bcm2835 Class Reference

Broadcom BCM2835 controller. More...

#include <bcm2835.hpp>

Public Types

enum  Registers {
  GPFSEL0 = 0, GPFSEL1 = 1, GPFSEL2 = 2, GPFSEL3 = 3,
  GPFSEL4 = 4, GPFSEL5 = 5, GPSET0 = 7, GPSET1 = 8,
  GPCLR0 = 10, GPCLR1 = 11, GPLEV0 = 13, GPLEV1 = 14,
  GPEDS0 = 15, GPEDS1 = 16, GPREN0 = 18, GPREN1 = 19,
  GPFEN0 = 21, GPFEN1 = 22, GPHEN0 = 24, GPHEN1 = 25,
  GPLEN0 = 27, GPLEN1 = 28, GPPUD0 = 37, GPPUDCLK0 = 38,
  GPPUDCLK1 = 39, PWM_CTL = 1, PWM_STA = 2, PWM_DMAC = 3,
  PWM_RNG1 = 4, PWM_DAT1 = 5, PWM_FIF1 = 6, PWM_RNG2 = 7,
  PWM_DAT2 = 8
}
 BCM2708 registers. More...
 
enum  RpiPins {
  PIN3 = 2, PIN5 = 3, PIN7 = 4, PIN8 = 14,
  PIN10 = 15, PIN11 = 17, PIN12 = 18, PIN13 = 27,
  PIN15 = 22, PIN16 = 23, PIN18 = 24, PIN19 = 10,
  PIN21 = 9, PIN22 = 25, PIN23 = 11, PIN24 = 8,
  PIN26 = 7
}
 Raspberry Pi pins.
 

Public Member Functions

 bcm2835 ()
 Constructor method.
 
virtual ~bcm2835 ()
 Destructor method.
 
void setup (uint8_t pin, uint8_t mode, uint8_t pull_mode=PULL_OFF)
 Sets the mode of a GPIO pin. More...
 
void write (uint8_t pin, bool value)
 Sets the value of a output pin. More...
 
bool read (uint8_t pin) const
 Returns the value of a input pin. More...
 
bool checkEvent (uint8_t pin) const
 Returns the event state of a GPIO pin. More...
 
void setRisingEvent (uint8_t pin, bool enabled)
 Enables/disables the rising edge event on a GPIO pin. More...
 
void setFallingEvent (uint8_t pin, bool enabled)
 Enables/disables the falling edge event on a GPIO pin. More...
 
void setHighEvent (uint8_t pin, bool enabled)
 Enables/disables the high event on a GPIO pin. More...
 
void setLowEvent (uint8_t pin, bool enabled)
 Enables/disables the low event on a GPIO pin. More...
 
void setPullUpDown (uint8_t pin, uint8_t mode)
 Enables/disables the pull-up/down control on a GPIO pin. More...
 

Private Member Functions

void setBit (uint8_t offset, uint8_t index, bool value)
 Sets a bit value on one of the GPIO controller registers. More...
 
bool getBit (uint8_t offset, uint8_t index) const
 Returns a bit value from one of the GPIO controller registers. More...
 
void waitCycles (size_t cycles) const
 Wait some CPU cycles. More...
 

Private Attributes

int m_mem_fd
 File descriptor of /dev/mem.
 
volatile uint32_t * m_gpio
 GPIO controller virtual address.
 
volatile uint32_t * m_pwm
 PWM controller virtual address.
 

Detailed Description

Broadcom BCM2835 controller.

Definition at line 59 of file bcm2835.hpp.

Member Enumeration Documentation

BCM2708 registers.

Enumerator
GPFSEL0 

PWM Channel 2 Data

The function select registers are used to define the operation of the general-purpose I/O pins. Each of the 54 GPIO pins uses 3 bit to select the function, therefore all registers contain at most 10 GPIO.

====================GPFSEL====================
pin - 9 8 7 6 5 4 3 2 1 0
0. xx 000 000 000 000 000 000 000 000 000 000 32 bit = 3 x 10 pin + 2 reserved
pin - 19 18 17 16 15 14 13 12 11 10
1. xx 000 000 000 000 000 000 000 000 000 000 ...
pin - 29 28 27 26 25 24 23 22 21 20
2. xx 000 000 000 000 000 000 000 000 000 000 ...
pin - 39 38 37 36 35 34 33 32 31 30
3. xx 000 000 000 000 000 000 000 000 000 000 ...
pin - 49 48 47 46 45 44 43 42 41 40
4. xx 000 000 000 000 000 000 000 000 000 000 ...
pin - - - - - - - 53 52 51 50
5. xx xxx xxx xxx xxx xxx xxx 000 000 000 000 32 bit = 3 x 4 pin + 20 reserved
==============================================

Codes

  • 000 = GPIO pin X is an input
  • 001 = GPIO pin X is an output
  • 100 = GPIO pin X takes alternate function 0
  • 101 = GPIO pin X takes alternate function 1
  • 110 = GPIO pin X takes alternate function 2
  • 111 = GPIO pin X takes alternate function 3
  • 011 = GPIO pin X takes alternate function 4
  • 010 = GPIO pin X takes alternate function 5
GPSET0 

PWM Channel 2 Data

=================GPSET===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = No effect
  • 1 = Set GPIO pin X
GPCLR0 

PWM Channel 2 Data

=================GPCLR===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = No effect
  • 1 = Clear GPIO pin n
GPLEV0 

PWM Channel 2 Data

=================GPLEV===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = GPIO pin X is low
  • 1 = GPIO pin X is high
GPEDS0 

PWM Channel 2 Data

=================GPEDS===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = Event not detected on GPIO pin X
  • 1 = Event detected on GPIO pin X
GPREN0 

PWM Channel 2 Data

=================GPREN===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = Rising edge detect disabled on GPIO pin X
  • 1 = Rising edge on GPIO pin X sets corresponding bit in GPEDS
GPFEN0 

PWM Channel 2 Data

=================GPFEN===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = Falling edge detect disabled on GPIO pin X
  • 1 = Falling edge on GPIO pin X sets corresponding bit in GPEDS
GPHEN0 

PWM Channel 2 Data

=================GPHEN===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = High detect disabled on GPIO pin X
  • 1 = High on GPIO pin n sets corresponding bit in GPEDS
GPLEN0 

PWM Channel 2 Data

=================GPLEN===============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = Low detect disabled on GPIO pin X
  • 1 = Low on GPIO pin n sets corresponding bit in GPEDS
GPPUD0 

PWM Channel 2 Data

=================GPPUD===============
0. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx00 32 bit = 2 control bits + 8 reserved
=====================================

Codes

  • 00 = Disable pull-up/down
  • 01 = Enable pull-down control
  • 10 = Enable pull-up control
  • 11 = Reserved
GPPUDCLK0 

PWM Channel 2 Data

The GPIO Pull-up/down Clock Registers control the actuation of internal pull-downs on the respective GPIO pins. These registers must be used in conjunction with the GPPUD register to effect GPIO Pull-up/down changes. The following sequence of events is required:

  1. Write to GPPUD to set the required control signal
  2. Wait 150 cycles – this provides the required set-up time for the control signal
  3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to modify
  4. Wait 150 cycles – this provides the required hold time for the control signal
  5. Write to GPPUD to remove the control signal
  6. Write to GPPUDCLK0/1 to remove the clock
===============GPPUDCLK==============
pin 31 ... ... 0
0. 00000000000000000000000000000000 32 bit = 32 pin
pin 53 ... ... 32
1. xxxxxxxx000000000000000000000000 32 bit = 24 pin + 8 reserved
=====================================

Codes

  • 0 = No effect
  • 1 = Assert clock on line X
PWM_CTL 

================== PWM Controller registers ==================

PWM Channel 2 Data

==================CTL================
xxxxxxxxxxxxxxxxx0x0000000000000 32 bit = 14 fields + 18 reserved
=====================================

PWM Channel 2 Data

Bit Field name Description
=================================================================
15 MSEN2 Channel 2 M/S enable
0 = PWM algorithm is used
1 = M/S transmission is used
-----------------------------------------------------------------
13 USEF2 Channel 2 use FIFO
0 = Data register is transmitted
1 = Fifo is used for transmission
-----------------------------------------------------------------
12 POLA2 Channel 2 polarity
0 = 0->low 1->high
1 = 0->high 1->low
-----------------------------------------------------------------
11 SBIT2 Channel 2 silence bit
Defines the state of the output
when no transmission takes place.
-----------------------------------------------------------------
10 RPTL2 Channel 2 repeat last data
0 = Transmission interrupts when
FIFO is empty
1 = Last data in FIFO is
transmitted repetedly until
FIFO is not empty
-----------------------------------------------------------------
9 MODE2 Channel 2 mode
0 = PWM mode
1 = Serialiser mode
-----------------------------------------------------------------
8 PWEN2 Channel 2 enable
0 = Channel is disabled
1 = Channel is enabled
-----------------------------------------------------------------
7 MSEN1 Channel 1 M/S enable
0 = PWM algorithm is used
1 = M/S transmission is used
-----------------------------------------------------------------
6 CLRF1 Clear FIFO
0 = Clears FIFO
1 = Has no effect
This is a single shot operation.
This bit always reads 0.
-----------------------------------------------------------------
5 USEF1 Channel 1 use FIFO
0 = Data register is transmitted
1 = Fifo is used for transmission
-----------------------------------------------------------------
4 POLA1 Channel 1 use FIFO
0 = 0->low 1->high
1 = 0->high 1->low
-----------------------------------------------------------------
3 SBIT1 Channel 1 silence bit
Defines the state of the output
when no transmission takes place.
-----------------------------------------------------------------
2 RPTL1 Channel 1 repeat last data
0 = Transmission interrupts when
FIFO is empty
1 = Last data in FIFO is
transmitted repetedly until
FIFO is not empty
-----------------------------------------------------------------
1 MODE1 Channel 1 mode
0 = PWM mode
1 = Serialiser mode
-----------------------------------------------------------------
0 PWEN1 Channel 1 enable
0 = Channel is disabled
1 = Channel is enabled
=================================================================
PWM_STA 

PWM Channel 2 Data

==================STA================
xxxxxxxxxxxxxxxxxxxx000000000000 32 bit = 12 fields + 20 reserved
=====================================

PWM Channel 2 Data

Bit Field name Description
=============================================================
12 STA4 Channel 4 state
11 STA3 Channel 3 state
10 STA2 Channel 2 state
9 STA1 Channel 1 state
8 BERR Bus error flag
7 GAPO4 Channel 4 gap cccurred flag
6 GAPO3 Channel 3 gap cccurred flag
5 GAPO2 Channel 2 gap cccurred flag
4 GAPO1 Channel 1 gap cccurred flag
3 RERR1 FIFO read error flag
2 WERR1 FIFO write error flag
1 EMPT1 FIFO empty flag
0 FULL1 FIFO full flag
=============================================================
PWM_DMAC 

PWM Channel 2 Data

=================DMAC================
0xxxxxxxxxxxxxxxx000000000000000 32 bit = 16 fields + 16 reserved
=====================================

PWM Channel 2 Data

Bit Field name Description
=============================================================
31 ENAB DMA Enable
15:8 PANIC DMA Threshold for PANIC signal
7:0 DREQ DMA Threshold for DREQ signal
=============================================================
PWM_RNG1 

PWM Channel 2 Data

=================RNG1================
0. 00000000000000000000000000000000 32 bit = 32 fields
=====================================
PWM_DAT1 

PWM Channel 2 Data

=================DAT1================
0. 00000000000000000000000000000000 32 bit = 32 fields
=====================================
PWM_FIF1 

PWM Channel 2 Data

=================FIF1================
0. 00000000000000000000000000000000 32 bit = 32 fields
=====================================
PWM_RNG2 

PWM Channel 2 Data

=================RNG2================
0. 00000000000000000000000000000000 32 bit = 32 fields
=====================================
PWM_DAT2 

PWM Channel 2 Data

=================DAT2================
0. 00000000000000000000000000000000 32 bit = 32 fields
=====================================

Definition at line 64 of file bcm2835.hpp.

Member Function Documentation

bool rpihw::driver::bcm2835::checkEvent ( uint8_t  pin) const
inline

Returns the event state of a GPIO pin.

Parameters
[in]pinThe GPIO pin.
Returns
The event state.

Definition at line 69 of file bcm2835-inl.hpp.

bool rpihw::driver::bcm2835::getBit ( uint8_t  offset,
uint8_t  index 
) const
inlineprivate

Returns a bit value from one of the GPIO controller registers.

Parameters
[in]offsetThe register offset.
[in]indexThe bit position.
Returns
The bit value.

Definition at line 37 of file bcm2835-inl.hpp.

bool rpihw::driver::bcm2835::read ( uint8_t  pin) const
inline

Returns the value of a input pin.

Parameters
[in]pinThe input pin.
Returns
The value of input pin.

Definition at line 60 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setBit ( uint8_t  offset,
uint8_t  index,
bool  value 
)
inlineprivate

Sets a bit value on one of the GPIO controller registers.

Parameters
[in]offsetThe register offset.
[in]indexThe bit position.
[in]valueThe bit value.

Definition at line 30 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setFallingEvent ( uint8_t  pin,
bool  enabled 
)
inline

Enables/disables the falling edge event on a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]enabledIf true enable the falling edge event.

Definition at line 87 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setHighEvent ( uint8_t  pin,
bool  enabled 
)
inline

Enables/disables the high event on a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]enabledIf true enable the high event.

Definition at line 96 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setLowEvent ( uint8_t  pin,
bool  enabled 
)
inline

Enables/disables the low event on a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]enabledIf true enable the low event.

Definition at line 105 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setPullUpDown ( uint8_t  pin,
uint8_t  mode 
)

Enables/disables the pull-up/down control on a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]modeThe pull resistor mode.
void rpihw::driver::bcm2835::setRisingEvent ( uint8_t  pin,
bool  enabled 
)
inline

Enables/disables the rising edge event on a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]enabledIf true enable the rising edge event.

Definition at line 78 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::setup ( uint8_t  pin,
uint8_t  mode,
uint8_t  pull_mode = PULL_OFF 
)

Sets the mode of a GPIO pin.

Parameters
[in]pinThe GPIO pin.
[in]modeThe GPIO mode.
[in]pull_modeThe pull resistor mode.
void rpihw::driver::bcm2835::waitCycles ( size_t  cycles) const
inlineprivate

Wait some CPU cycles.

Parameters
[in]cyclesNumber of CPU cycles.

Definition at line 44 of file bcm2835-inl.hpp.

void rpihw::driver::bcm2835::write ( uint8_t  pin,
bool  value 
)
inline

Sets the value of a output pin.

Parameters
[in]pinThe output pin.
[in]valueThe value of output pin.

Definition at line 51 of file bcm2835-inl.hpp.


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