Skip to content

Instantly share code, notes, and snippets.

View barafael's full-sized avatar
💭
fighting the red and yellow squiggles

Rafael Bachmann barafael

💭
fighting the red and yellow squiggles
View GitHub Profile
@barafael
barafael / Cargo.toml
Created August 11, 2023 08:16
clap+humantime+serde+figment
[package]
name = "clapment"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.72"
clap = { version = "4.3.21", features = ["derive"] }
figment = { version = "0.10.10", features = ["env", "json", "toml"] }
humantime = "2.1.0"
trait PushUnique {
type Item;
fn push_unique(&mut self, item: Self::Item) -> Result<(), Self::Item>;
}
impl<T> PushUnique for Vec<T>
where
T: PartialEq,
{
type Item = T;
#![no_main]
#![no_std]
use defmt_rtt as _; // global logger
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
#[defmt::panic_handler]
fn panic() -> ! {
cortex_m::asm::udf()
cargo-valgrind: version 2.0.3
XML format mismatch between `valgrind` and `cargo valgrind`: custom: duplicate field `stack`
XML output of valgrind:
```xml
<?xml version="1.0"?>
<valgrindoutput>
<protocolversion>4</protocolversion>
<protocoltool>memcheck</protocoltool>
--- rtic_v0.5/stm32f0_hid_mouse/src/main.rs 2022-02-10 14:15:04.270648800 +0100
+++ rtic_v1/stm32f0_hid_mouse/src/main.rs 2022-02-10 10:32:55.309537420 +0100
@@ -1,13 +1,16 @@
+/*
#![deny(unsafe_code)]
+*/
#![deny(warnings)]
#![no_std]
#![no_main]
@barafael
barafael / lib.rs
Created January 26, 2022 13:20
tokio::select can panic (see docs or run this for example)
use tokio::sync::mpsc;
#[derive(Debug)]
pub enum Message {
SomeU8(u8),
SomeBool(bool),
SomeChar(char),
}
/// Panics if all the channel sender handles are gone (disables all branches).
@barafael
barafael / Vec.hpp
Created April 27, 2021 21:56
A constant size vector type
#pragma once
#ifndef ARDUINO_AVR_UNO
#include <cstddef>
#endif
template<typename T, size_t SIZE>
class Vec {
public:
Vec(std::initializer_list<T> init) {
@barafael
barafael / random_blink.ino
Created March 5, 2021 21:38
Random Blink
fn print_i2c_it_flags(b: &stm32f0xx_hal::stm32f0::R<u32, stm32f0xx_hal::stm32f0::Reg<u32, pac::i2c1::_ISR>>) {
rprintln!("{");
if b.txe().is_empty() {
rprintln!("TXE Transmit Data Register Empty");
}
if b.txis().is_empty() {
rprintln!("TXIS Transmit Interrupt Status");
}
if b.rxne().is_not_empty() {
@barafael
barafael / packets.c
Created October 8, 2020 15:35
Vulnerability hidden by type conversion
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct packet_st {
char *data;
size_t length;
} packet_t;