Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
printhex.h
00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 00017 Contact information 00018 ------------------- 00019 00020 Circuits At Home, LTD 00021 Web : http://www.circuitsathome.com 00022 e-mail : support@circuitsathome.com 00023 */ 00024 00025 #if !defined(_usb_h_) || defined(__PRINTHEX_H__) 00026 #error "Never include printhex.h directly; include Usb.h instead" 00027 #else 00028 #define __PRINTHEX_H__ 00029 00030 void E_Notifyc(char c, int lvl); 00031 00032 template <class T> 00033 void PrintHex(T val, int lvl) { 00034 int num_nibbles = sizeof (T) * 2; 00035 00036 do { 00037 char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); 00038 if(v > 57) v += 7; 00039 E_Notifyc(v, lvl); 00040 } while(--num_nibbles); 00041 } 00042 00043 template <class T> 00044 void PrintBin(T val, int lvl) { 00045 for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1) 00046 if(val & mask) 00047 E_Notifyc('1', lvl); 00048 else 00049 E_Notifyc('0', lvl); 00050 } 00051 00052 template <class T> 00053 void SerialPrintHex(T val) { 00054 // int num_nibbles = sizeof (T) * 2; 00055 00056 // do { 00057 // char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); 00058 // if(v > 57) v += 7; 00059 // USB_HOST_SERIAL.print(v); 00060 // } while(--num_nibbles); 00061 } 00062 00063 class Print; 00064 00065 template <class T> 00066 void PrintHex2(Print *prn, T val) { 00067 // T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2)); 00068 00069 // while(mask > 1) { 00070 // if(val < mask) 00071 // prn->print("0"); 00072 00073 // mask >>= 4; 00074 // } 00075 // prn->print((T)val, HEX); 00076 } 00077 00078 template <class T> void D_PrintHex(T val __attribute__((unused)), int lvl __attribute__((unused))) { 00079 #ifdef DEBUG_USB_HOST 00080 PrintHex<T > (val, lvl); 00081 #endif 00082 } 00083 00084 template <class T> 00085 void D_PrintBin(T val, int lvl) { 00086 #ifdef DEBUG_USB_HOST 00087 PrintBin<T > (val, lvl); 00088 #endif 00089 } 00090 00091 00092 00093 #endif // __PRINTHEX_H__
Generated on Tue Jul 12 2022 18:12:04 by
1.7.2