diff options
author | Ryan <fauxpark@gmail.com> | 2021-08-18 18:20:25 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 18:20:25 +1000 |
commit | b16091659cc9a724a8800f77e631643b4ab089ad (patch) | |
tree | e44933472c6d100bd4fc5d8a693d9d21e3c32f6f /lib/usbhost/USB_Host_Shield_2.0/printhex.h | |
parent | cf5e40c25139ff64ff246f1c6280e983ef75551c (diff) | |
download | qmk_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.h | 84 |
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 | |||
3 | This software may be distributed and modified under the terms of the GNU | ||
4 | General Public License version 2 (GPL2) as published by the Free Software | ||
5 | Foundation and appearing in the file GPL2.TXT included in the packaging of | ||
6 | this file. Please note that GPL2 Section 2[b] requires that all works based | ||
7 | on this software must also be made publicly available under the terms of | ||
8 | the GPL2 ("Copyleft"). | ||
9 | |||
10 | Contact information | ||
11 | ------------------- | ||
12 | |||
13 | Circuits At Home, LTD | ||
14 | Web : http://www.circuitsathome.com | ||
15 | e-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 | |||
23 | void E_Notifyc(char c, int lvl); | ||
24 | |||
25 | template <class T> | ||
26 | void 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 | |||
36 | template <class T> | ||
37 | void 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 | |||
45 | template <class T> | ||
46 | void 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 | |||
56 | template <class T> | ||
57 | void 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 | |||
69 | template <class T> void D_PrintHex(T val, int lvl) { | ||
70 | #ifdef DEBUG_USB_HOST | ||
71 | PrintHex<T > (val, lvl); | ||
72 | #endif | ||
73 | } | ||
74 | |||
75 | template <class T> | ||
76 | void 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__ | ||