]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/printhex.h
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
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
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
18 #if !defined(_usb_h_) || defined(__PRINTHEX_H__)
19 #error "Never include printhex.h directly; include Usb.h instead"
21 #define __PRINTHEX_H__
23 void E_Notifyc(char c
, int lvl
);
26 void PrintHex(T val
, int lvl
) {
27 int num_nibbles
= sizeof (T
) * 2;
30 char v
= 48 + (((val
>> (num_nibbles
- 1) * 4)) & 0x0f);
33 } while(--num_nibbles
);
37 void PrintBin(T val
, int lvl
) {
38 for(T mask
= (((T
)1) << ((sizeof (T
) << 3) - 1)); mask
; mask
>>= 1)
46 void SerialPrintHex(T val
) {
47 int num_nibbles
= sizeof (T
) * 2;
50 char v
= 48 + (((val
>> (num_nibbles
- 1) * 4)) & 0x0f);
52 USB_HOST_SERIAL
.print(v
);
53 } while(--num_nibbles
);
57 void PrintHex2(Print
*prn
, T val
) {
58 T mask
= (((T
)1) << (((sizeof (T
) << 1) - 1) << 2));
66 prn
->print((T
)val
, HEX
);
69 template <class T
> void D_PrintHex(T val
, int lvl
) {
71 PrintHex
<T
> (val
, lvl
);
76 void D_PrintBin(T val
, int lvl
) {
78 PrintBin
<T
> (val
, lvl
);
84 #endif // __PRINTHEX_H__