Skip to content

Instantly share code, notes, and snippets.

@cibomahto
cibomahto / Makefile
Created November 30, 2018 06:33
"Trammell Mode" RGB blink pattern for UPDuino v2.0
chip.bin: chip.v blink.v upduino_v2.pcf
yosys -q -p "synth_ice40 -blif chip.blif" chip.v blink.v correction_lut.v
arachne-pnr -d 5k -P sg48 -p upduino_v2.pcf chip.blif -o chip.txt
icepack chip.txt chip.bin
.PHONY: flash
flash:
iceprog chip.bin
.PHONY: clean
chip.bin: chip.v blink.v upduino_v2.pcf
yosys -q -p "synth_ice40 -blif chip.blif" chip.v blink.v correction_lut_8.v correction_lut_16.v icnd2110.v
arachne-pnr -d 5k -P sg48 -p upduino_v2.pcf chip.blif -o chip.txt
icepack chip.txt chip.bin
.PHONY: flash
flash:
iceprog chip.bin
.PHONY: clean
@cibomahto
cibomahto / razerdisco.c
Created October 22, 2019 20:16
Disco / crash feature for DeathAdder 2000 mouse
/*******************************************************
Windows HID simplification
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009
@cibomahto
cibomahto / readme.md
Last active March 28, 2020 13:09
Use Raspberry Pi 3 as a SWD for STM32F4
  1. Start with this raspberry pi image (Raspbian Buster Lite):

https://www.raspberrypi.org/downloads/raspbian/

2020-02-13-raspbian-buster-lite.img

  1. Enable WiFi by adding 'wpa_supplicant.conf' to the boot partition:

country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

@cibomahto
cibomahto / divider_calculator.py
Created June 4, 2020 14:34
Resistor divider brute force calculation
#For MT3608:
# Vout = Vref*(1+R1/R2)
import numpy as np
resistor_vals_E24 = np.array([1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1])
resistor_vals_E96 = np.array([1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.15, 2.21, 2.26, 2.32, 2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76])
def calc_best_divisor(equation, v_out, resistor_vals):
# Generate a big array of all values in decades 100-100000
name: Firmware build
on:
push:
branches:
- master
- github_actions
tags:
- '*'
pull_request:
@cibomahto
cibomahto / capture.ino
Created December 9, 2020 13:37
plot.pde
// Modified sensor code for Arduino
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
/*
* Macro Definitions
*/
#define SPEC_TRG A0
#define SPEC_ST A1
import numpy as np
# Common resistor values for 5%
resistor_vals_E24 = np.array([1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1])
# Common resistor values for 1%
resistor_vals_E96 = np.array([1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.15, 2.21, 2.26, 2.32, 2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76])
def BL9352A_resistor_calc(Vout, resistor_vals):
# Generate a big array of all resistor values over some decades
@cibomahto
cibomahto / power.json
Last active March 9, 2021 13:46
Power supply graph generator
{
"type": "powersupply",
"name": "5V wall wart",
"voltage": 5,
"loads" : [
{
"type": "dcdc",
"name": "12V supply for control boards",
"voltage": 12,
"efficiency": 0.85,
@cibomahto
cibomahto / inductor_measure.py
Created April 7, 2021 17:20
Measure an inductor using a function generator and oscilloscope
# Measure an inductor using a function generator and oscilloscope.
#
# Based on:
# https://www.tek.com/document/application-note/capacitance-and-inductance-measurements-using-oscilloscope-and-function-ge
import math
import quantiphy
def calc_inductance(f,Rref,Va1,Va2,phase):
Z = (Va2*Rref)/math.sqrt(Va1*Va1-(2*Va1*Va2*math.cos(phase))+Va2*Va2)