Skip to content

Instantly share code, notes, and snippets.

View kammce's full-sized avatar

Khalil Estell kammce

  • Bay Area, California
  • 21:23 (UTC -08:00)
View GitHub Profile
@kammce
kammce / escape_hatch.cpp
Last active October 30, 2024 01:54
A means to escape from an infinite loop using C++ exceptions and interrupts
void read_sensor_data(hal::i2c& p_device)
{
hal::byte status = 0;
do {
status = hal::write_then_read<1>(p_device,
0x11,
std::to_array<hal::byte>({ 0xAA }),
hal::never_timeout())[0];
} while (status & (1 << 5)); // but the sensor is dead 😱 !!!
@kammce
kammce / ld2410c.cpp
Last active April 10, 2024 20:54
Quick driver for the ld2410c human presence board
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@kammce
kammce / auto-gh.sh
Created March 23, 2024 07:02
Command to automate deploying sweeping changes through github repos. Pass it a list of github URLs, absolute path to a script and a commit message.
#!/bin/bash
# Check if enough arguments are passed
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <file_with_repo_urls> <path_to_script> <'commit_message'>"
exit 1
fi
REPO_FILE=$1
SCRIPT_PATH=$2
@kammce
kammce / create_libhal_clangd.sh
Created March 19, 2024 19:58
Use this to create a `.clangd` file for workspace folders containing libhal libraries. Should work with any conan project that generates a `compile_commands.json` file
#!/bin/bash
# Start the .clangd file afresh
echo "" > .clangd
# Get the absolute path to the script's directory
root_dir=$(pwd)
# Iterate over all directories in the current directory
for dir in */ ; do
@kammce
kammce / EULA.html
Created May 20, 2023 17:01
Arm Gnu Toolchain EULA
This file has been truncated, but you can view the full file.
<div class="modal__header">
<h3 class="title"></h3>
</div>
<div class="modal__body eula-content no-footer"><p>Contains code from project GNU Binutils (https://www.gnu.org/software/binutils/),<br>
GNU Debugger (https://www.gnu.org/software/gdb/) under the following license(s).<br>
<br>
<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GNU GENERAL PUBLIC LICENSE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Version 3, 29 June 2007<br>
<br>
{
"schemaVersion": 1,
"label": "",
"logoSvg": "<svg version='1.1' id='Capa_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 310.797 310.797' style='enable-background:new 0 0 310.797 310.797;' xml:space='preserve'><g><path d='M208.859,27.307L208.8,11.308L189.311,0l-87.893,51.407l0.11,19.635L63.697,93.104l0.073,47.457l-18.592,11.161 l-0.155,101.334l20.214,11.833l12.422-7.502l18.173,11.395v30.12l20.075,11.895l87.333-50.921l-0.053-21.302l45.583-26.463v-38.133 l17.004-10.152V60.551L208.859,27.307z M187.302,33.392l6.559-3.846l0.048,23.674l-6.607,3.86V33.392z M158.816,50.059l6.558-3.836 l0.049,23.653l-6.606,3.86V50.059z M129.173,67.389l6.558-3.844l0.049,23.68l-6.606,3.871V67.389z M101.529,87.725l-0.049,13.891 l20.164,11.813l87.158-51.046l0.095-17.363l23.033,14.225l-107.389,63.021L83.517,98.361L101.529,87.725z M73.18,167.153 l20.375-12.225l-0.105,7.768l-20.383,12.171L73.18,167.153z M72.604,203.263l0.018-1.205l20.374-12.225l-0.105,7.768l-20.382,12.17 L
#include <cinttypes>
#include <cstdio>
#include <functional>
namespace embed {
/// An empty settings structure used to indicate that a module or interface does
/// not have generic settings.
struct empty_settings {};
#include <bitset>
#include <cinttypes>
#include <cstdio>
#include <limits>
#include <type_traits>
namespace xstd {
struct bitrange {
uint32_t position;
@kammce
kammce / xstdbitset.cpp
Last active August 6, 2021 14:28
[Benchmark] C-style multibit insert vs C++ bitset
#include <bitset>
#include <cinttypes>
#include <cstdio>
#include <limits>
#include <type_traits>
namespace xstd {
struct bitrange {
uint32_t position;
@kammce
kammce / picolibc_attempt_notes.cpp
Created July 3, 2021 16:58
Getting picolibc to work
struct _reent r = {0, (FILE *) 0, (FILE *) 1, (FILE *) 0};
struct _reent *_impure_ptr = &r;
extern "C" void __cxa_pure_virtual()
{
// put your error handling here
}
extern "C" void __cxa_atexit() {}