Skip to content

Instantly share code, notes, and snippets.

@nerdralph
nerdralph / array.c
Created April 11, 2021 11:08
avr-gcc extern __flash array bug
#include <stdint.h>
extern __flash const uint8_t digital_pin_to_bit_mask_PGM[];
uint8_t read_array(uint8_t i)
{
return digital_pin_to_bit_mask_PGM[i]; // bug: uses ld
// return *(digital_pin_to_bit_mask_PGM + i); // uses lpm
}
@nerdralph
nerdralph / cmsis-dap.log
Created December 13, 2020 23:24
openOCD scan
sudo ./openocd -f ~/devel/dap/cmsis-dap.cfg
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev (2020-10-13-17:27)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = 1.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
@nerdralph
nerdralph / inverse.c
Created December 7, 2020 16:08
odd integer inverse calculator
// Ralph Doncaster 2020 public domain software
// calculate the 64-bit inverse of odd integers
#include <stdio.h>
#include <stdint.h>
#define END_RANGE 9999
int main()
{
uint64_t neg1 = (uint64_t) -1LL;
@nerdralph
nerdralph / exponent.c
Created November 12, 2020 23:38
generate lookup table for powers of 1.414, i.e. sqrt(2)
// Ralph Doncaster 2020 public domain software
// generate lookup table for powers of sqrt(2)
#include <stdio.h>
#include <math.h>
int main()
{
double sqrt2 = sqrt(2.0);
for (double d = 2; d <= 16; d += 1) {
printf( "1.414^%d = %lf\n", (int)d, pow(sqrt2, d) );
@nerdralph
nerdralph / FridgeAlarmNR.ino
Last active March 22, 2020 17:42
cleaned up fridge door alarm
/* Fridge Door Alarm for the ATTiny13[A]
*
* Functionality:
*
* Door opens, door open chime.
* After 60 seconds, door-open warning beep.
* If door still open, warning beeps every 30 seconds.
* After 5 minutes, continous alarm signal.
* Door closes, door close chime.
* If Silent Running pressed, no door chimes for ONE operation.
@nerdralph
nerdralph / OscillatorCalibration.ino
Created February 5, 2020 00:13
MicroCore Oscillator Calibration
/*
ATtiny13 internal oscillator tuner
By Ralph Doncaster (2019)
Tweaked and tuned by MCUdude
------------------------------------------------------------------------------
[ See diagram: https://github.com/MCUdude/MicroCore#minimal-setup ]
Tunes the internal oscillator using a software serial implementation
@nerdralph
nerdralph / ssd1306.cpp
Created January 7, 2020 19:28
picoI2C ssd1306 128x32 test
/* ssd1306 test for picoI2C
* Ralph Doncaster (c) 2019
* free software - MIT license
*/
#include <stdint.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "picoI2C.h"
@nerdralph
nerdralph / t13tune.ino
Last active December 23, 2019 17:40
prototype MicroCore OSCCAL tuner for ATtiny13
// t13 OSCCAL tuner
// Ralph Doncaster 2019 public domain software
// repeatedly press 'x' until OSCCAL value stabilizes
// output value is timing delta in cycles followed by OSCCAL
#define BAUD_RATE 115200
#include <BBUart.h>
#include <avr/sleep.h>
#define UART_RX 1
@nerdralph
nerdralph / blink-MicroCore.ino
Last active December 24, 2019 14:56
blink example for MicroCorre using sleep and millis
@nerdralph
nerdralph / spew.c
Created April 3, 2018 15:24
spew a char to stdout
/* 2018 Ralph Doncaster public domain software */
/* spew a char to stdout, null if none provided */
#include <unistd.h>
#include <string.h>
int main(int argc, char** argv){
char buf[1024];
char c = 0;
if( argc > 1 ) c = *argv[1];