Skip to content

Instantly share code, notes, and snippets.

View spe-ciellt's full-sized avatar

Stefan Petersen spe-ciellt

View GitHub Profile
@spe-ciellt
spe-ciellt / gist:2ac72d6032b8e8fae4bbbdf6671ed782
Created November 20, 2018 13:31
How to get an instantiation of an templated class as template parameter
Consider I have a class i2c_t which is a templated class. Then I'll do:
using i2c1_t = i2c_t<I2C_1, 32, i2c_speed::FULL, 5>;
i2c1_t i2c1;
Then I want to do the following:
using mic_volume_t = chips::i2c::mcp4651<i2c1, 1>;
mic_volume_t mic_volume;
so that I can do
mic_volume.set_volume(3);
@spe-ciellt
spe-ciellt / ad9850.c
Created March 12, 2016 18:20
Proof-of-concept for programming AD9850 DDS using serial interface. Code is using SPI on an Arduino Nano (ATMega328p).
/*
* Copyright (c) 2016 Stefan Petersen, Ciellt AB
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@spe-ciellt
spe-ciellt / cvs-clean.py
Created December 12, 2015 14:50
Python program to remove CVS $Id tags from a set of files.
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import os
import re
import shutil
import sys
re_cvs_line = re.compile(r'^(.*)\$.*\$(.*)$')
@spe-ciellt
spe-ciellt / install-avr-chain.txt
Created May 31, 2015 08:44
How to install a newer avr-gcc (that supports xmega32e5) into Ubuntu 14.04.
curl -O http://se.archive.ubuntu.com/ubuntu/pool/universe/g/gcc-avr/gcc-avr_4.8.1+Atmel3.4.4-2_amd64.deb
curl -O http://se.archive.ubuntu.com/ubuntu/pool/universe/b/binutils-avr/binutils-avr_2.24+Atmel3.4.4-1_amd64.deb
curl -O http://se.archive.ubuntu.com/ubuntu/pool/universe/a/avr-libc/avr-libc_1.8.0+Atmel3.4.4-1_all.deb
sudo dpkg -i binutils-avr_2.24+Atmel3.4.4-1_amd64.deb
sudo dpkg -i gcc-avr_4.8.1+Atmel3.4.4-2_amd64.deb
sudo dpkg -i avr-libc_1.8.0+Atmel3.4.4-1_all.deb
@spe-ciellt
spe-ciellt / atomthread-avr-use-timer0.diff
Created May 27, 2015 11:19
How to change from Timer1 (16-bit) to Timer0 (8-bit) in AVR Arduino port and set timer tick to 1 ms.
diff --git a/ports/avr/atomport.c b/ports/avr/atomport.c
index 9ae5555..4107a1d 100644
--- a/ports/avr/atomport.c
+++ b/ports/avr/atomport.c
@@ -277,21 +277,21 @@ void archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_poi
*/
void avrInitSystemTickTimer ( void )
{
- /* Set timer 1 compare match value for configured system tick,
- * with a prescaler of 256. We will get a compare match 1A
@spe-ciellt
spe-ciellt / atom-semaphore-test.c
Last active August 29, 2015 14:21
A simple example on using semaphores in atomthreads for interrupt handling.
/*
* Copyright (c) 2015, Stefan Petersen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright