1 /* Copyright (C) 2011 by Jacob Alexander
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // ----- Includes -----
32 // ----- Functions -----
34 // USB HID String Output
35 void usb_debug_putstr( char* s )
38 usb_debug_putchar( *s++ );
41 // Multiple string Output
42 void usb_debug_putstrs( char* first, ... )
44 // Initialize the variadic function parameter list
47 // Get the first parameter
48 va_start( ap, first );
51 // Loop through the variadic list until "\0\0\0" is found
52 while ( !( cur[0] == '\0' && cur[1] == '\0' && cur[2] == '\0' ) )
54 // Print out the given string
55 usb_debug_putstr( cur );
57 // Get the next argument ready
58 cur = va_arg( ap, char* );
61 va_end( ap ); // Not required, but good practice
64 // Print a constant string
65 void _print(const char *s)
69 // Acquire the character from flash, and print it, as long as it's not NULL
70 // Also, if a newline is found, print a carrige return as well
71 while ( ( c = pgm_read_byte(s++) ) != '\0' )
74 usb_debug_putchar('\r');
83 void int8ToStr( uint8_t in, char* out )
85 // Position and sign containers
89 // Evaluate through digits as decimal
92 out[pos++] = in % 10 + '0';
94 while ( (in /= 10) > 0 );
99 // Reverse the string to the correct order
104 void int16ToStr( uint16_t in, char* out )
106 // Position and sign containers
110 // Evaluate through digits as decimal
113 out[pos++] = in % 10 + '0';
115 while ( (in /= 10) > 0 );
120 // Reverse the string to the correct order
125 void hexToStr_op( uint16_t in, char* out, uint8_t op )
127 // Position container
130 // Evaluate through digits as hex
133 uint16_t cur = in % 16;
134 out[pos++] = cur + (( cur < 10 ) ? '0' : 'A' - 10);
136 while ( (in /= 16) > 0 );
138 // Output formatting options
145 case 2: // 8-bit padding
146 case 4: // 16-bit padding
155 // Reverse the string to the correct order
160 void revsStr( char* in )
168 // Loop through the string, and reverse the order of the characters
169 for ( i = 0, j = lenStr( in ) - 1; i < j; i++, j-- )
178 uint16_t lenStr( char* in )
183 // Loop until null is found
184 for ( pos = in; *pos; pos++ );
186 // Return the difference between the pointers of in and pos (which is the string length)