Skip to content

Instantly share code, notes, and snippets.

View korken89's full-sized avatar

Emil Fresk korken89

View GitHub Profile
@korken89
korken89 / singleton.hpp
Last active September 11, 2017 12:41
Singleton definition, just to remember
class Singleton {
public:
static Singleton& instance() {
static Singleton instance_;
return instance_;
}
private: // use protected: if it should be inherited from
Singleton() = default;
~Singleton() = default;
1738.721042] usb 5-1.3: new high-speed USB device number 9 using xhci_hcd
[ 1738.821241] usb 5-1.3: New USB device found, idVendor=1a40, idProduct=0101
[ 1738.821244] usb 5-1.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[ 1738.821245] usb 5-1.3: Product: USB 2.0 Hub
[ 1738.849689] hub 5-1.3:1.0: USB hub found
[ 1738.849717] hub 5-1.3:1.0: 4 ports detected
[ 1739.137051] usb 5-1.3.1: new full-speed USB device number 10 using xhci_hcd
[ 1739.603519] usb 5-1.3.1: New USB device found, idVendor=0403, idProduct=6001
[ 1739.603522] usb 5-1.3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1739.603523] usb 5-1.3.1: Product: FT232R USB UART
(gdb) set debug remote 1
(gdb) start
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Sending packet: $k#6b...Ack
Sending packet: $?#3f...Ack
Packet received: W00
Sending packet: $Hg0#df...Ack
Packet received:
Sending packet: $qXfer:memory-map:read::0,3fb#e5...Ack
extern crate rand;
use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
@korken89
korken89 / main.rs
Created July 16, 2018 12:49
Test f32 vs f64 sinf kernel
const S1: f64 = -0.166666666416265235595; /* -0x15555554cbac77.0p-55 */
const S2: f64 = 0.0083333293858894631756; /* 0x111110896efbb2.0p-59 */
const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */
const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */
pub fn k_sinf(x: f64) -> f32 {
let z = x * x;
let w = z * z;
let r = S3 + z * S4;
let s = z * x;
@korken89
korken89 / main.rs
Created July 16, 2018 13:34
Test sinf and cosf kernels f32 vs f64 with relative
//
// Sin functions
//
const S1: f64 = -0.166666666416265235595; /* -0x15555554cbac77.0p-55 */
const S2: f64 = 0.0083333293858894631756; /* 0x111110896efbb2.0p-59 */
const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */
const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */
pub fn k_sinf(x: f64) -> f32 {
let z = x * x;
/// Trait for implementing WideSlice
pub trait ToWideSlice<'a> {
fn to_wideslice(&'a mut self) -> WideSlice<'a>;
}
/// The platform independent data storage
#[derive(Debug)]
pub struct WideSlice<'a> {
slices: &'a mut [*mut f64],
len: usize,
@korken89
korken89 / length_match.py
Created July 9, 2019 21:07
KiCAD bus length matching script which also adds in the "Pad to die length" into the calculations
#!/usr/bin/env python3
import sys
import os
import re
import time
import pcbnew
"""
This is a modified version of https://github.com/mithro/kicad-length-matching-checks.git
which also adds in the "Pad to die length" into the calculations (plus different formating).
@korken89
korken89 / add_pad_to_die_length.py
Last active July 18, 2019 14:44
This is a script which adds the die to pad lengths to a package in a PCB design
#!/usr/bin/env python3
import sys, math
import pcbnew
"""
This is a script which adds the die to pad lengths to a package in a PCB design.
Based on the script here: https://forum.kicad.info/t/die-length-doesnt-seem-to-work/786
By Emil Fresk (@korken89), https://www.github.com/korken89
@korken89
korken89 / main.rs
Last active September 10, 2019 07:13
Mutex trait test
//! main.rs
#![no_main]
#![no_std]
use core::{
cell::RefCell,
marker::{Send, Sync},
};
use cortex_m::interrupt::CriticalSection;