Skip to content

Instantly share code, notes, and snippets.

View korken89's full-sized avatar

Emil Fresk korken89

View GitHub Profile
//! `rtic_sync::arbiter::Arbiter`-based shared bus `SpiDevice` implementation.
// TODO: upstream to rtic-sync
use embedded_hal::digital::OutputPin;
use embedded_hal_async::{
delay::DelayUs,
spi::{ErrorType, Operation, SpiBus, SpiDevice},
};
use embedded_hal_bus::spi::DeviceError;
@korken89
korken89 / rtc_monotonic.rs
Last active February 14, 2023 16:34
An RTIC monotonic based on RTC for nRF52 series
// RTIC Monotonic impl for the RTCs
use crate::hal::pac::{rtc0, RTC0, RTC1, RTC2};
pub use fugit::{self, ExtU32};
use rtic_monotonic::Monotonic;
pub struct MonoRtc<T: InstanceRtc> {
overflow: u8,
rtc: T,
}
Flashing /home/emifre/Git/widefind/anchor_cable/firmware/binary/target/thumbv7em-none-eabihf/release/anchor-cable-firmware
DEBUG jaylink > libusb 1.0.23.11397
DEBUG jaylink > libusb has capability API: true
DEBUG jaylink > libusb has HID access: true
DEBUG jaylink > libusb has hotplug support: true
DEBUG jaylink > libusb can detach kernel driver: true
DEBUG probe_rs::probe::daplink::tools > Could not open 1209:da42 in CMSIS-DAP v2 mode
DEBUG probe_rs::probe::daplink::tools > Attempting to open 1209:da42 in CMSIS-DAP v1 mode
TRACE probe_rs::probe::daplink::commands > Send buffer: [00, 11, 00, 12, 7A, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
TRACE probe_rs::probe::daplink::commands > Receive buffer: [11, 00, 00, 00, 00,
@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;
@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 / 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).
/// 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 / 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;
@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;
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);