# Raspberry Pi

## Linux Kernel vs. Raspberry Pi driver
On a recent Raspberry Pi that's using the `vc4_kms_3d` dtoverlay, you have to use the [Linux Kernel driver](#compilation-using-the-linux-kernel-driver) and disable the Raspberry Pi driver with `-DHAVE_RPI_API=0` to use CEC.

## Raspberry Pi driver
If you're compiling the old Raspberry Pi API driver, then the path to the required headers and libraries can be set manually, in case it's not in a standard system directory:
```
cmake -DRPI_INCLUDE_DIR=/path/to/vc/include \
      -DRPI_LIB_DIR=/path/to/vc/lib \
      ..
```

The headers and libraries are installed in /opt/vc when using Raspbian, but they may be installed somewhere else when using another distribution. Please ask the distribution's maintainers for help in case compilation fails and you're not using Raspbian.

If you're cross compiling, then you can set the correct toolchain like this (for the Raspberry Pi):
```
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/CrossCompile.cmake \
      -DXCOMPILE_BASE_PATH=/path/to/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi \
      -DXCOMPILE_LIB_PATH=/path/to/firmware/hardfp/opt/vc/lib \
      -DRPI_INCLUDE_DIR=/path/to/firmware/hardfp/opt/vc/include \
      -DRPI_LIB_DIR=/path/to/firmware/hardfp/opt/vc/lib \
      ..
```

## Compilation using the Linux Kernel driver
To compile libCEC on a new Raspbian installation, follow these instructions:
```
sudo apt-get update
sudo apt-get -y install cmake libudev-dev libxrandr-dev python3-dev swig git
cd
git clone https://github.com/Pulse-Eight/libcec.git
mkdir libcec/build
cd libcec/build
cmake  -DHAVE_LINUX_API=1 -DHAVE_RPI_API=0 ..
make -j4
sudo make install
sudo ldconfig
```

## Compilation using the old Raspberry Pi driver
To compile libCEC on a new Raspbian installation, follow these instructions:
```
sudo apt-get update
sudo apt-get -y install cmake libudev-dev libxrandr-dev python3-dev swig git
cd
git clone https://github.com/Pulse-Eight/libcec.git
mkdir libcec/build
cd libcec/build
cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib ..
make -j4
sudo make install
sudo ldconfig
```

## Examples
Example implementations using libCEC can be found here:
* [github.com/Pulse-Eight/libcec/blob/master/src/cec-client/cec-client.cpp](https://github.com/Pulse-Eight/libcec/blob/master/src/cec-client/cec-client.cpp)
* [github.com/DrGeoff/cec_simplest](https://github.com/DrGeoff/cec_simplest)
