-
Notifications
You must be signed in to change notification settings - Fork 0
/
avr-misc.h
45 lines (45 loc) · 1.1 KB
/
avr-misc.h
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
44
45
#ifndef AVR_MISC_H
#define AVR_MISC_H
#define LIB_AVR_MISC
//-----------------------------------------------------------------------------
#include <stdlib.h>
#include "macro.h"
#include "avr-common.h"
#include "avr-interrupts.h"
#include "avr-delay.h"
#include "avr-eeprom.h"
#include "avr-GPIO.h"
//-----------------------------------------------------------------------------
class BYTEstack
{
public:
BYTEstack();
~BYTEstack();
void push(BYTE value);
BYTE pop();
BYTE size();
BYTE top();
BYTE operator [](const int i);
private:
BYTE m_count;
BYTE* m_buf;
};
//-----------------------------------------------------------------------------
template <typename Type>
char* toHexString(Type value)
{
BYTE count = sizeof(Type) * 2;
BYTE octet;
char* buf = (char*) malloc(count + 1);
buf[count] = '\0';
while(count)
{
octet = value & 0x0F;
buf[count - 1] = octet > 9 ? 'A' + octet - 10 : '0' + octet;
value >>= 4;
count--;
}
return buf;
}
//-----------------------------------------------------------------------------
#endif