Reorganization for use with the CMake "Modules"
- Include option is currently "hacked" and needs to be fixed - Builds on Linux, but Mac and Windows needs to be tested - Loader script generation isn't complete
This commit is contained in:
		
							parent
							
								
									0415ba2481
								
							
						
					
					
						commit
						b4e1868d19
					
				
					 19 changed files with 2910 additions and 7 deletions
				
			
		
							
								
								
									
										190
									
								
								Debug/basic/print.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								Debug/basic/print.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,190 @@
 | 
			
		|||
/* Copyright (C) 2011 by Jacob Alexander
 | 
			
		||||
 * 
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 * 
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 * 
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// Compiler Includes
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
 | 
			
		||||
// AVR Includes
 | 
			
		||||
#include <avr/io.h>
 | 
			
		||||
#include <avr/pgmspace.h>
 | 
			
		||||
 | 
			
		||||
// Project Includes
 | 
			
		||||
#include "print.h"
 | 
			
		||||
 | 
			
		||||
// Defines
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// USB HID String Output
 | 
			
		||||
void usb_debug_putstr( char* s )
 | 
			
		||||
{
 | 
			
		||||
	while ( *s != '\0' )
 | 
			
		||||
		usb_debug_putchar( *s++ );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Multiple string Output
 | 
			
		||||
void usb_debug_putstrs( char* first, ... )
 | 
			
		||||
{
 | 
			
		||||
	// Initialize the variadic function parameter list
 | 
			
		||||
	va_list ap;
 | 
			
		||||
 | 
			
		||||
	// Get the first parameter
 | 
			
		||||
	va_start( ap, first );
 | 
			
		||||
	char *cur = first;
 | 
			
		||||
 | 
			
		||||
	// Loop through the variadic list until "\0\0\0" is found
 | 
			
		||||
	while ( !( cur[0] == '\0' && cur[1] == '\0' && cur[2] == '\0' ) )
 | 
			
		||||
	{
 | 
			
		||||
		// Print out the given string
 | 
			
		||||
		usb_debug_putstr( cur );
 | 
			
		||||
 | 
			
		||||
		// Get the next argument ready
 | 
			
		||||
		cur = va_arg( ap, char* );
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	va_end( ap ); // Not required, but good practice
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Print a constant string
 | 
			
		||||
void _print(const char *s)
 | 
			
		||||
{
 | 
			
		||||
	char c;
 | 
			
		||||
 | 
			
		||||
	// Acquire the character from flash, and print it, as long as it's not NULL
 | 
			
		||||
	// Also, if a newline is found, print a carrige return as well
 | 
			
		||||
	while ( ( c = pgm_read_byte(s++) ) != '\0' )
 | 
			
		||||
	{
 | 
			
		||||
		if ( c == '\n' )
 | 
			
		||||
			usb_debug_putchar('\r');
 | 
			
		||||
		usb_debug_putchar(c);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// String Functions
 | 
			
		||||
void int8ToStr( uint8_t in, char* out )
 | 
			
		||||
{
 | 
			
		||||
	// Position and sign containers
 | 
			
		||||
	uint8_t pos;
 | 
			
		||||
	pos = 0;
 | 
			
		||||
 | 
			
		||||
	// Evaluate through digits as decimal
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		out[pos++] = in % 10 + '0';
 | 
			
		||||
	}
 | 
			
		||||
	while ( (in /= 10) > 0 );
 | 
			
		||||
 | 
			
		||||
	// Append null
 | 
			
		||||
	out[pos] = '\0';
 | 
			
		||||
 | 
			
		||||
	// Reverse the string to the correct order
 | 
			
		||||
	revsStr(out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void int16ToStr( uint16_t in, char* out )
 | 
			
		||||
{
 | 
			
		||||
	// Position and sign containers
 | 
			
		||||
	uint16_t pos;
 | 
			
		||||
	pos = 0;
 | 
			
		||||
 | 
			
		||||
	// Evaluate through digits as decimal
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		out[pos++] = in % 10 + '0';
 | 
			
		||||
	}
 | 
			
		||||
	while ( (in /= 10) > 0 );
 | 
			
		||||
 | 
			
		||||
	// Append null
 | 
			
		||||
	out[pos] = '\0';
 | 
			
		||||
 | 
			
		||||
	// Reverse the string to the correct order
 | 
			
		||||
	revsStr(out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void hexToStr_op( uint16_t in, char* out, uint8_t op )
 | 
			
		||||
{
 | 
			
		||||
	// Position container
 | 
			
		||||
	uint16_t pos = 0;
 | 
			
		||||
 | 
			
		||||
	// Evaluate through digits as hex
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		uint16_t cur = in % 16;
 | 
			
		||||
		out[pos++] = cur + (( cur < 10 ) ? '0' : 'A' - 10);
 | 
			
		||||
	}
 | 
			
		||||
	while ( (in /= 16) > 0 );
 | 
			
		||||
 | 
			
		||||
	// Output formatting options
 | 
			
		||||
	switch ( op )
 | 
			
		||||
	{
 | 
			
		||||
	case 1: // Add 0x
 | 
			
		||||
		out[pos++] = 'x';
 | 
			
		||||
		out[pos++] = '0';
 | 
			
		||||
		break;
 | 
			
		||||
	case 2: //  8-bit padding
 | 
			
		||||
	case 4: // 16-bit padding
 | 
			
		||||
		while ( pos < op )
 | 
			
		||||
			out[pos++] = '0';
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Append null
 | 
			
		||||
	out[pos] = '\0';
 | 
			
		||||
 | 
			
		||||
	// Reverse the string to the correct order
 | 
			
		||||
	revsStr(out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void revsStr( char* in )
 | 
			
		||||
{
 | 
			
		||||
	// Iterators
 | 
			
		||||
	int i, j;
 | 
			
		||||
 | 
			
		||||
	// Temp storage
 | 
			
		||||
	char c;
 | 
			
		||||
 | 
			
		||||
	// Loop through the string, and reverse the order of the characters
 | 
			
		||||
	for ( i = 0, j = lenStr( in ) - 1; i < j; i++, j-- )
 | 
			
		||||
	{
 | 
			
		||||
		c = in[i];
 | 
			
		||||
		in[i] = in[j];
 | 
			
		||||
		in[j] = c;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t lenStr( char* in )
 | 
			
		||||
{
 | 
			
		||||
	// Iterator
 | 
			
		||||
	char *pos;
 | 
			
		||||
 | 
			
		||||
	// Loop until null is found
 | 
			
		||||
	for ( pos = in; *pos; pos++ );
 | 
			
		||||
 | 
			
		||||
	// Return the difference between the pointers of in and pos (which is the string length)
 | 
			
		||||
	return (pos - in);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										87
									
								
								Debug/basic/print.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								Debug/basic/print.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,87 @@
 | 
			
		|||
/* Copyright (C) 2011 by Jacob Alexander
 | 
			
		||||
 * 
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 * 
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 * 
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef print_h__
 | 
			
		||||
#define print_h__
 | 
			
		||||
 | 
			
		||||
// AVR Includes
 | 
			
		||||
#include <avr/pgmspace.h>
 | 
			
		||||
 | 
			
		||||
// Project Includes
 | 
			
		||||
#include "usb_keyboard_debug.h"
 | 
			
		||||
 | 
			
		||||
// Defines
 | 
			
		||||
#define NL "\r\n"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* XXX
 | 
			
		||||
 * Note that all the variadic functions below, take comma separated string lists, they are purposely not printf style (simplicity)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// Function Aliases
 | 
			
		||||
#define dPrint(c)         usb_debug_putchar(c)
 | 
			
		||||
#define dPrintStr(c)      usb_debug_putstr (c)
 | 
			
		||||
#define dPrintStrs(...)   usb_debug_putstrs(__VA_ARGS__, "\0\0\0")      // Convenience Variadic Macro
 | 
			
		||||
#define dPrintStrNL(c)    dPrintStrs       (c, NL)                      // Appends New Line Macro
 | 
			
		||||
#define dPrintStrsNL(...) usb_debug_putstrs(__VA_ARGS__, NL, "\0\0\0")  // Appends New Line Macro
 | 
			
		||||
 | 
			
		||||
// Special Msg Constructs (Uses VT100 tags)
 | 
			
		||||
#define dPrintMsg(colour_code_str,msg,...) \
 | 
			
		||||
                          usb_debug_putstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
 | 
			
		||||
#define printMsg(colour_code_str,msg,str) \
 | 
			
		||||
                          print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
 | 
			
		||||
 | 
			
		||||
// Info Messages
 | 
			
		||||
#define info_dPrint(...)  dPrintMsg        ("1;32",   "INFO",    __VA_ARGS__) // Info Msg
 | 
			
		||||
#define info_print(str)   printMsg         ("1;32",   "INFO",    str)         // Info Msg
 | 
			
		||||
 | 
			
		||||
// Warning Messages
 | 
			
		||||
#define warn_dPrint(...)  dPrintMsg        ("1;33",   "WARNING", __VA_ARGS__) // Warning Msg
 | 
			
		||||
#define warn_print(str)   printMsg         ("1;33",   "WARNING", str)         // Warning Msg
 | 
			
		||||
 | 
			
		||||
// Error Messages
 | 
			
		||||
#define erro_dPrint(...)  dPrintMsg        ("1;5;31", "ERROR",   __VA_ARGS__) // Error Msg
 | 
			
		||||
#define erro_print(str)   printMsg         ("1;5;31", "ERROR",   str)         // Error Msg
 | 
			
		||||
 | 
			
		||||
// Debug Messages
 | 
			
		||||
#define dbug_dPrint(...)  dPrintMsg        ("1;35",   "DEBUG",   __VA_ARGS__) // Debug Msg
 | 
			
		||||
#define dbug_print(str)   printMsg         ("1;35",   "DEBUG",   str)         // Debug Msg
 | 
			
		||||
 | 
			
		||||
// Static String Printing
 | 
			
		||||
#define print(s) _print(PSTR(s))
 | 
			
		||||
 | 
			
		||||
void _print(const char *s);
 | 
			
		||||
void usb_debug_putstr( char* s );
 | 
			
		||||
void usb_debug_putstrs( char* first, ... );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// String Functions
 | 
			
		||||
#define hexToStr(hex, out) hexToStr_op(hex, out, 1)
 | 
			
		||||
 | 
			
		||||
void int8ToStr  ( uint8_t  in,   char*  out );
 | 
			
		||||
void int16ToStr ( uint16_t in,   char*  out );
 | 
			
		||||
void hexToStr_op( uint16_t in,   char*  out, uint8_t op );
 | 
			
		||||
void revsStr    ( char*  in );
 | 
			
		||||
uint16_t lenStr ( char*  in );
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								Debug/basic/setup.cmake
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Debug/basic/setup.cmake
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
###| CMake Kiibohd Controller Debug Module |###
 | 
			
		||||
#
 | 
			
		||||
# Written by Jacob Alexander in 2011 for the Kiibohd Controller
 | 
			
		||||
#
 | 
			
		||||
# Released into the Public Domain
 | 
			
		||||
#
 | 
			
		||||
###
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
# Module C files
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
set( DEBUG_SRCS
 | 
			
		||||
	print.c
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
# Module Specific Options
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue