FreeNOS
BroadcomGPIO.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <Log.h>
19 #include "BroadcomGPIO.h"
20 
22 {
23 }
24 
26 {
27  if (m_io.map(IO_BASE + GPIOBase, PAGESIZE,
29  != IO::Success)
30  return IOError;
31 
32  return Success;
33 }
34 
36 {
37  // pin is a BCM2835 GPIO pin number NOT RPi pin number
38  //
39  // There are 6 control registers, each control the functions of a block
40  // of 10 pins.
41  // Each control register has 10 sets of 3 bits per GPIO pin:
42  //
43  // 000 = GPIO Pin X is an input
44  // 001 = GPIO Pin X is an output
45  // 100 = GPIO Pin X takes alternate function 0
46  // 101 = GPIO Pin X takes alternate function 1
47  // 110 = GPIO Pin X takes alternate function 2
48  // 111 = GPIO Pin X takes alternate function 3
49  // 011 = GPIO Pin X takes alternate function 4
50  // 010 = GPIO Pin X takes alternate function 5
51  //
52  uint shift = (pin % 10) * 3;
53  m_io.set(FunctionSelect0 + (pin / 10),
54  function << shift);
55  return Success;
56 }
BroadcomGPIO::IOError
@ IOError
Definition: BroadcomGPIO.h:76
BroadcomGPIO::GPIOBase
static const Address GPIOBase
Definition: BroadcomGPIO.h:42
Memory::Writable
@ Writable
Definition: Memory.h:42
IO::map
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition: IO.cpp:38
Memory::User
@ User
Definition: Memory.h:44
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
Memory::Device
@ Device
Definition: Memory.h:48
BroadcomGPIO::BroadcomGPIO
BroadcomGPIO()
Constructor.
Definition: BroadcomGPIO.cpp:21
Memory::Readable
@ Readable
Definition: Memory.h:41
Log.h
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
BroadcomGPIO::initialize
virtual Result initialize()
Initialize the Controller.
Definition: BroadcomGPIO.cpp:25
BroadcomGPIO::Success
@ Success
Definition: BroadcomGPIO.h:74
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
BroadcomGPIO::setAltFunction
virtual Result setAltFunction(Size pin, uint function)
Set alternate function.
Definition: BroadcomGPIO.cpp:35
IO::Success
@ Success
Definition: IO.h:44
BroadcomGPIO::FunctionSelect0
@ FunctionSelect0
Definition: BroadcomGPIO.h:49
BroadcomGPIO::Result
Result
Result code.
Definition: BroadcomGPIO.h:72
ARMIO::set
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition: ARMIO.h:109
BroadcomGPIO.h
BroadcomGPIO::m_io
Arch::IO m_io
I/O instance.
Definition: BroadcomGPIO.h:106