aboutsummaryrefslogtreecommitdiff
path: root/lib/usbhost/USB_Host_Shield_2.0/printhex.h
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-08-18 18:20:25 +1000
committerGitHub <noreply@github.com>2021-08-18 18:20:25 +1000
commitb16091659cc9a724a8800f77e631643b4ab089ad (patch)
treee44933472c6d100bd4fc5d8a693d9d21e3c32f6f /lib/usbhost/USB_Host_Shield_2.0/printhex.h
parentcf5e40c25139ff64ff246f1c6280e983ef75551c (diff)
downloadqmk_firmware-b16091659cc9a724a8800f77e631643b4ab089ad.tar.gz
qmk_firmware-b16091659cc9a724a8800f77e631643b4ab089ad.zip
Move USB Host Shield and Arduino core to `lib/` (#13973)
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/printhex.h')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/printhex.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/printhex.h b/lib/usbhost/USB_Host_Shield_2.0/printhex.h
new file mode 100644
index 000000000..369d7e1f7
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/printhex.h
@@ -0,0 +1,84 @@
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This software may be distributed and modified under the terms of the GNU
4General Public License version 2 (GPL2) as published by the Free Software
5Foundation and appearing in the file GPL2.TXT included in the packaging of
6this file. Please note that GPL2 Section 2[b] requires that all works based
7on this software must also be made publicly available under the terms of
8the GPL2 ("Copyleft").
9
10Contact information
11-------------------
12
13Circuits At Home, LTD
14Web : http://www.circuitsathome.com
15e-mail : support@circuitsathome.com
16 */
17
18#if !defined(_usb_h_) || defined(__PRINTHEX_H__)
19#error "Never include printhex.h directly; include Usb.h instead"
20#else
21#define __PRINTHEX_H__
22
23void E_Notifyc(char c, int lvl);
24
25template <class T>
26void PrintHex(T val, int lvl) {
27 int num_nibbles = sizeof (T) * 2;
28
29 do {
30 char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
31 if(v > 57) v += 7;
32 E_Notifyc(v, lvl);
33 } while(--num_nibbles);
34}
35
36template <class T>
37void PrintBin(T val, int lvl) {
38 for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1)
39 if(val & mask)
40 E_Notifyc('1', lvl);
41 else
42 E_Notifyc('0', lvl);
43}
44
45template <class T>
46void SerialPrintHex(T val) {
47 int num_nibbles = sizeof (T) * 2;
48
49 do {
50 char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
51 if(v > 57) v += 7;
52 USB_HOST_SERIAL.print(v);
53 } while(--num_nibbles);
54}
55
56template <class T>
57void PrintHex2(Print *prn, T val) {
58 T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2));
59
60 while(mask > 1) {
61 if(val < mask)
62 prn->print("0");
63
64 mask >>= 4;
65 }
66 prn->print((T)val, HEX);
67}
68
69template <class T> void D_PrintHex(T val, int lvl) {
70#ifdef DEBUG_USB_HOST
71 PrintHex<T > (val, lvl);
72#endif
73}
74
75template <class T>
76void D_PrintBin(T val, int lvl) {
77#ifdef DEBUG_USB_HOST
78 PrintBin<T > (val, lvl);
79#endif
80}
81
82
83
84#endif // __PRINTHEX_H__