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
24
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}
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition ARMIO.h:109
static const Address GPIOBase
virtual Result setAltFunction(Size pin, uint function)
Set alternate function.
BroadcomGPIO()
Constructor.
virtual Result initialize()
Initialize the Controller.
Arch::IO m_io
I/O instance.
Result
Result code.
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
@ Success
Definition IO.h:44
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int uint
Unsigned integer number.
Definition Types.h:44
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Device
Definition Memory.h:48
@ Writable
Definition Memory.h:42