Skip to content

Instantly share code, notes, and snippets.

@mcbridejc
mcbridejc / Adding SPI chip selects on Raspberry Pi.md
Last active October 26, 2025 17:06
How to add or change SPI chip select pins on raspberry PI with device tree overlay

The raspberry pi SPI0 by default has 2 CS pins configured. The SPI driver in the kernel uses GPIOS toggled by software, rather than hardware controlled chip selects. This means that any GPIO can be used for a chip select, and any number of them can be supported concurrently. All of these setup for the SPI driver is defined in the device tree, and we can use device tree overlays stored in /boot to dynamically configure the device tree.

The attached example creates a SPI device with 5 CS pins, on GPIO 8, 7, 1, 5, and 6.

To compile it to a binary: dtc -@ -I dts -O dtb -o spi-cs-extend.dtbo spi-cs-extend.dts

Then place spi-cs-extend.dtbo into /boot/overlays and add the following line to your /boot/config.txt: dtoverlay=spi-cs-extend.

@foonathan
foonathan / borrow.cpp
Last active August 24, 2023 08:42
Quick'n'dirty implementation of Rust's borrow checker for a C++Now Lightning Talk - not supposed to be used
#include <iostream>
#include "borrow_checker.hpp"
int main()
{
auto i = 42;
// borrow `i` under name `ref`
borrow_var(ref, i)