This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *itoaFixedWidth(int32_t zahl) { | |
static uint32_t subtractors[] = {1000000000, 100000000, 10000000, 1000000, | |
100000, 10000, 1000, 100, 10, 1}; | |
static char string[12]; | |
char n, *str = string, sign = zahl < 0 ? '-' : ' '; | |
uint32_t *sub = subtractors; | |
uint32_t u = zahl < 0 ? (uint32_t) -zahl : (uint32_t) zahl; | |
uint8_t i = 10; | |
*str++ = ' '; | |
while (i > 1 && u < *sub) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
// SEE https://godbolt.org/z/KroE8d | |
#ifndef TABLE | |
const uint16_t poloynom1 = 0x1021; | |
uint16_t crc_update(uint16_t signature, uint8_t inputByte) { | |
signature ^= inputByte << 8; // 16 Bit CRC | |
uint8_t i = 8; | |
while (i-- > 0) { // optimiezed for branchless. function like: p = (signature & 0x8000) ? poloynom1 : 0; | |
uint16_t p = poloynom1 & (0xffff * ((signature & 0x8000) != 0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void hexDump(char *description, void *basisAddr, void *startAddr, unsigned long len) { | |
unsigned char i = 0; | |
unsigned long tempAdr; | |
char hex[] = "0123456789abcdef"; | |
unsigned char buff[17], *ptrBuf; | |
unsigned char *pc = (unsigned char*) startAddr; | |
if (description != NULL) { | |
while (*description) | |
putchar(*description++); | |
putchar('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module rcube(v, r, center=false, $fn=40) translate(center ? [-v[0]/2,-v[1]/2,-v[2]/2] : [0,0,0]) hull() { | |
translate([r,r, r]) sphere(r=r); translate([r, r, v[2]-r]) sphere(r=r); | |
translate([v[0]-r, r, r]) sphere(r=r); translate([v[0]-r, r, v[2]-r]) sphere(r=r); | |
translate([r, v[1]-r,r]) sphere(r=r); translate([r, v[1]-r,v[2]-r]) sphere(r=r); | |
translate([v[0]-r, v[1]-r,r]) sphere(r=r); translate([v[0]-r, v[1]-r,v[2]-r]) sphere(r=r); | |
} | |
translate([0, 20, 0]) rcube([15,10,20], r=1, center=false); | |
translate([0, 0, 0]) cube([15,10,20], center=false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (uint64_t val) 26 till 11184819 correct, (uint32_t val) 19 bis 81920 correct | |
#define BITS 19 | |
#define MUL (((1L << BITS)/10) + 1) | |
unsigned long div10(unsigned long val) { | |
return ((unsigned long) val * MUL) >> BITS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t hexCharToNibbel(char hexChar) { | |
return (hexChar >= '0' && hexChar <= '9') ? hexChar - '0' : | |
(hexChar >= 'A' && hexChar <= 'F') ? hexChar - 'A' + 10 : 16; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example for xmega256d3 | |
// bit delay | |
static void delay(void) { | |
__no_operation(); | |
__no_operation(); | |
__no_operation(); | |
__no_operation(); | |
__no_operation(); | |
__no_operation(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *itoaUint32VarLen(uint32_t value, uint8_t fillWith0, uint8_t lenghtInChars) { | |
static uint8_t sBuf0[12]; // maximum Value -2147483649 = 12 | |
uint8_t *sBuf = &sBuf0[11], *sBufWerteBegrenzung; | |
uint32_t valueAlt; // Alte Wert für schneller % 10 Berechnung | |
*sBuf = 0; | |
if (value == 0) { | |
*--sBuf = '0'; | |
lenghtInChars--; | |
} else while (value) { | |
if (!lenghtInChars) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int atoi(const char *c) { | |
int result = 0; | |
int sign = 1; | |
if (!c) | |
return 0; | |
while (*c == ' ') | |
c++; | |
if (*c == '-') { | |
sign = -1; | |
c++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define _ 0 | |
#define S(x) x, | |
#define D(x) x x x | |
#define L(x) D(S(x)) | |
#define R(x) D(D(S(x))) | |
#define E(f,x) f(x)f(x+1)f(x+2) | |
char sudoku[] = { | |
1, _, _, _, _, 7, _, 9, _, | |
_, 3, _, _, 2, _, _, _, 8, |