Skip to content

Instantly share code, notes, and snippets.

@nerdralph
nerdralph / array.c
Created Apr 11, 2021
avr-gcc extern __flash array bug
View array.c
#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 / inverse.c
Created Dec 7, 2020
odd integer inverse calculator
View inverse.c
// 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;
View cmsis-dap.log
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 / exponent.c
Created Nov 12, 2020
generate lookup table for powers of 1.414, i.e. sqrt(2)
View exponent.c
// 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 Mar 22, 2020
cleaned up fridge door alarm
View FridgeAlarmNR.ino
/* 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 Feb 5, 2020
MicroCore Oscillator Calibration
View OscillatorCalibration.ino
/*
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 Jan 7, 2020
picoI2C ssd1306 128x32 test
View ssd1306.cpp
/* 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 / blink-MicroCore.ino
Last active Dec 24, 2019
blink example for MicroCorre using sleep and millis
View blink-MicroCore.ino
@nerdralph
nerdralph / t13tune.ino
Last active Dec 23, 2019
prototype MicroCore OSCCAL tuner for ATtiny13
View t13tune.ino
// 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 / spew.c
Created Apr 3, 2018
spew a char to stdout
View spew.c
/* 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];