Skip to content

Instantly share code, notes, and snippets.

View Lauszus's full-sized avatar

Kristian Sloth Lauszus Lauszus

View GitHub Profile
@Lauszus
Lauszus / flexcan_bit_timing.py
Last active March 29, 2022 13:27
Python port of the "FLEXCAN_CalculateImprovedTimingValues" function from the NXP SDK
#!/usr/bin/env python3
#
# Copyright (c) 2015, Freescale Semiconductor, Inc.
# Copyright 2016-2021 NXP
# Copyright 2022 Kristian Sloth Lauszus
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Python port of the "FLEXCAN_CalculateImprovedTimingValues" function from the NXP SDK
@Lauszus
Lauszus / gh-get-artifacts-dev.py
Last active March 7, 2022 22:08
Scripts for downloading a Github actions workflow artifact
import json
import zipfile
from typing import Union, Optional
import requests
GITHUB_OAUTH_TOKEN = ''
OWNER = ''
REPO = ''
@Lauszus
Lauszus / pigpio.c
Last active February 2, 2022 21:58
Examples of setting the drive strength of a Raspberry Pi GPIO PAD using either pigpio or WiringPi
// gcc -Wall -O3 -pthread -o set_drive_strength pigpio.c -lpigpio
#include <stdlib.h>
#include <pigpio.h>
int main(int argc, char *argv[]) {
if (gpioInitialise() < 0) return 1;
int strength_ma = argc > 1 ? atoi(argv[1]) : 8;
@Lauszus
Lauszus / pre-commit
Last active April 20, 2021 23:46
clang-format pre-commit hook
#!/bin/sh
# Check if this is the initial commit
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@Lauszus
Lauszus / max98357a-no-din-overlay.dts
Created February 23, 2021 16:24
Maxim MAX98357A audio DAC without using the PCM_DIN pin
// Overlay for Maxim MAX98357A audio DAC without using the PCM_DIN pin
// dtparams:
// sdmode-pin - Specify GPIO pin to which SD_MODE is connected (default 20).
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
@Lauszus
Lauszus / mcp2515-spi0-4cs-overlay.dts
Last active February 16, 2024 11:50
Raspberry Pi device tree overlay for creating up to four CAN-Bus interfaces on spi0 using four MCP2515's
/*
* Device tree overlay for mcp251x on any spi interface by Kristian Sloth Lauszus.
* Should be used with the "spi0-4cs" overlay.
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
@Lauszus
Lauszus / main.py
Created October 1, 2020 13:50
Siglent SDS2000X plus hack
import hashlib
SCOPEID = '0000000000000000'
Model = 'SDS2000X+'
# Note that 'AWG' should be used for the 'FG' option
# If you have the 100 MHz model, then first upgrade it to 200 MHz, then 350 MHz and finally 500 MHz
bwopt = ('25M', '40M', '50M', '60M', '70M', '100M', '150M', '200M', '250M', '300M', '350M', '500M', '750M', '1000M', 'MAX', 'AWG', 'WIFI', 'MSO', 'FLX', 'CFD', 'I2S', '1553', 'PWA')
hashkey = '5zao9lyua01pp7hjzm3orcq90mds63z6zi5kv7vmv3ih981vlwn06txnjdtas3u2wa8msx61i12ueh14t7kqwsfskg032nhyuy1d9vv2wm925rd18kih9xhkyilobbgy'
@Lauszus
Lauszus / os-release-bionic
Last active October 31, 2023 12:52
Nvidia SDKManager on Ubuntu 20.04
# Put in "/usr/lib/os-release-bionic"
NAME="Ubuntu"
VERSION="18.04 (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04"
VERSION_ID="18.04"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
@Lauszus
Lauszus / 80-can.network
Last active September 25, 2023 01:10
Ubuntu 20.04 auto configure CAN bus interfaces using systemd
[Match]
Name=can*
[CAN]
BitRate=250000
# Put this file in: "/etc/systemd/network/" and then run "sudo systemctl enable systemd-networkd" to enable systemd-networkd
# Now start systemd-networkd: "sudo systemctl start systemd-networkd"
# Credit: https://github.com/linux-can/can-utils/issues/68#issuecomment-584505426
@Lauszus
Lauszus / hass_install_notes.md
Last active December 9, 2019 22:12
Home Assistant Docker installation notes on a Raspberry Pi 3

Install some required packages first:

sudo apt-get update
sudo apt-get install -y \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common