-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.cpp
More file actions
43 lines (38 loc) · 899 Bytes
/
utils.cpp
File metadata and controls
43 lines (38 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "utils.h"
char itoa_buf[8] = "\0\0\0\0\0\0\0\0";
char * itoa(uint16_t x, int base) {
uint8_t i = 6;
do {
char c = (x % base) + '0';
if (c > '9'){
c = c - '9' + 'A' - 1;
}
itoa_buf[i--] = c;
x /= base;
} while(x);
// Must immediately use this.
return itoa_buf + i + 1;
}
uint8_t strlen(const uint8_t* s) {
uint8_t* t = s;
while(*t) t++;
return t - s;
}
uint8_t popcount(uint8_t n) {
n = ((n & 0xaa) >> 1) + ((n & 0x55) >> 0);
n = ((n & 0xcc) >> 2) + ((n & 0x33) >> 0);
n = ((n & 0xf0) >> 4) + ((n & 0x0f) >> 0);
return n;
};
char loadPStrBuf [128];
char * loadPStr(char * pAddr) {
int i;
char * ptr = loadPStrBuf;
for(i = 0; i < 127; i++) {
char c = pgm_read_byte(pAddr + i);
if(!c) break;
ptr[i] = c;
}
ptr[i] = 0;
return loadPStrBuf;
}