#| Set the Compilers (must be set first)
include( CMakeForceCompiler )
-set( CMAKE_SYSTEM_NAME Generic )
cmake_force_c_compiler ( avr-gcc AVRCCompiler )
cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
-set( CMAKE_CROSSCOMPILING on )
-message( STATUS ${CMAKE_CROSSCOMPILING})
###
COMMENT "Size after generation:"
)
+
+
+###
+# Setup Loader Script
+#
+
+#| Provides the user with the correct teensy-loader-cli command for the built .HEX file
+#| teensy-loader-cli must be in the user's path
+if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
+ configure_file( LoadFile/bash load )
+endif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
+
+#| TODO Windows
+if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
+ message( STATUS "Load Script is on my TODO List for Windows..." )
+endif( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
+
+++ /dev/null
-/* 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);
-}
-
+++ /dev/null
-/* 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
-
+++ /dev/null
-###| 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
-#
-
--- /dev/null
+###| CMake Kiibohd Controller Debug Module |###
+#
+# Written by Jacob Alexander in 2011 for the Kiibohd Controller
+#
+# Released into the Public Domain
+#
+###
+
+
+###
+# Module C files
+#
+
+#| XXX Requires the ../ due to how the paths are constructed
+set( DEBUG_SRCS
+ ../led/led.c
+ ../print/print.c
+)
+
+
+###
+# Module Specific Options
+#
+add_definitions(
+ -I${HEAD_DIR}/Debug/led
+ -I${HEAD_DIR}/Debug/print
+)
+
--- /dev/null
+/* 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.
+ */
+
+// ----- Includes -----
+
+// AVR Includes
+
+// Project Includes
+#include "led.h"
+
+
+
+// ----- Functions -----
+
+// Error LED Setup
+void init_errorLED()
+{
+ // Use pin D6 as an output (LED)
+ DDRD |= (1<<6);
+}
+
+// Error LED Control
+void errorLED( uint8_t on )
+{
+ // Error LED On (D6)
+ if ( on ) {
+ PORTD |= (1<<6);
+ }
+ // Error LED Off
+ else {
+ PORTD &= ~(1<<6);
+ }
+}
+
--- /dev/null
+/* 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 __led_h
+#define __led_h
+
+// ----- Includes -----
+
+// AVR Includes
+#include <avr/io.h>
+
+
+
+// ----- Functions -----
+
+void init_errorLED( void );
+void errorLED( uint8_t on );
+
+#endif
+
--- /dev/null
+###| 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
+ led.c
+)
+
+
+###
+# Module Specific Options
+#
+
+
+###
+# Just in case, you only want this module and are using others as well
+#
+add_definitions( -I${HEAD_DIR}/Debug/off )
+
--- /dev/null
+/* 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 __led_h
+#define __led_h
+
+// ----- Disabler Defines -----
+#define init_errorLED()
+#define errorLED(on)
+
+#endif
+
--- /dev/null
+/* 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__
+
+// ----- Disabler Defines -----
+
+#define dPrint(c)
+#define dPrintStr(c)
+#define dPrintStrs(...)
+#define dPrintStrNL(c)
+#define dPrintStrsNL(...)
+
+// Special Msg Constructs (Uses VT100 tags)
+#define dPrintMsg(colour_code_str,msg,...)
+#define printMsg(colour_code_str,msg,str)
+
+// Info Messages
+#define info_dPrint(...)
+#define info_print(str)
+
+// Warning Messages
+#define warn_dPrint(...)
+#define warn_print(str)
+
+// Error Messages
+#define erro_dPrint(...)
+#define erro_print(str)
+
+// Debug Messages
+#define dbug_dPrint(...)
+#define dbug_print(str)
+
+// Static String Printing
+#define print(s) _print(PSTR(s))
+
+// Output Functions
+#define _print(s)
+#define usb_debug_putstr(s)
+#define usb_debug_putstrs(s, ...)
+
+// String Functions
+#define hexToStr(hex, out)
+#define int8ToStr(in, out)
+#define int16ToStr(in, out)
+#define hexToStr_op(in, out, op)
+#define revsStr(in)
+#define lenStr(in)
+
+#endif
+
--- /dev/null
+###| CMake Kiibohd Controller Debug Module |###
+#
+# Written by Jacob Alexander in 2011 for the Kiibohd Controller
+#
+# Released into the Public Domain
+#
+###
+
+
+###
+# Module C files
+#
+#| None!
+
+
+###
+# Module Specific Options
+#
+
--- /dev/null
+/* 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.
+ */
+
+// ----- Includes -----
+
+// Compiler Includes
+#include <stdarg.h>
+
+// Project Includes
+#include "print.h"
+
+
+
+// ----- Functions -----
+
+// 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);
+}
+
--- /dev/null
+/* 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__
+
+// ----- Includes -----
+
+// AVR Includes
+#include <avr/pgmspace.h>
+
+// Project Includes
+#include "usb_keyboard_debug.h"
+
+
+
+// ----- Defines -----
+#define NL "\r\n"
+
+
+
+// ----- Functions and Corresponding Function Aliases -----
+
+/* 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
+
--- /dev/null
+###| 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
+#
+
+
+###
+# Just in case, you only want this module and are using others as well
+#
+add_definitions( -I${HEAD_DIR}/Debug/off )
+
+/* 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 __KEYMAP_h
#define __KEYMAP_h
+// ----- Includes -----
+
#include "usb_keys.h"
+
+
+// ----- Defines -----
+
// Modifier Mask
#define MODIFIERS_KEYPAD 0
#define MODIFIERS_KEYBOARD 4
-static uint8_t keypad_modifierMask[] = {};
+
+
+
+// ----- Variables -----
+
+//static uint8_t keypad_modifierMask[] = {};
static uint8_t keyboard_modifierMask[] = { 1, 17, 33, 49 };
-static uint8_t alternate_modifierMask[] = { 1, 17, 33, 49, 62 };
+//static uint8_t alternate_modifierMask[] = { 1, 17, 33, 49, 62 };
// Default 1-indexed key mappings
+/*
static uint8_t keypadDefaultMap[] = { 0,
KEYPAD_7,
KEYPAD_8,
KEYPAD_0,
KEYPAD_PERIOD,
KEYPAD_PLUS };
-
+*/
static uint8_t defaultMap[] = { 0,
KEY_GUI,
KEY_1,
KEY_LEFT,
KEY_RIGHT,
KEY_SPACE };
-
+/*
static uint8_t navigationMap[] = { 0,
KEY_GUI,
KEY_F1,
165,
KEY_RIGHT_ALT,
KEY_SPACE };
-
+*/
#endif
+/* 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 __usb_keys_h
#define __usb_keys_h
+// ----- Defines -----
// List of Modifiers
#define KEY_CTRL 0x01
#define KEYS_RGUI 231
// 232 - 65535 Reserved
-
-
-
-
#endif
--- /dev/null
+#!/bin/bash
+
+#| Loads the hex file onto the teensy
+
+sudo teensy-loader-cli -mmcu=@MCU@ -w @TARGET_HEX@
+
+exit 0
+
+++ /dev/null
-#!/bin/bash
-
-#| Loads the hex file onto the teensy++ 2.0
-
-sudo teensy-loader-cli -mmcu=at90usb1286 -w Build/main.hex
-
-exit 0
-
--- /dev/null
+/* 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.
+ */
+
+// ----- Includes -----
+
+// AVR Includes
+
+// Project Includes
+#include <usb_com.h>
+#include <scan_loop.h>
+#include <print.h>
+
+// Keymaps
+#include <keymap.h>
+#include <usb_keys.h>
+
+// Local Includes
+#include "macro.h"
+
+
+
+// ----- Functions -----
+
+// Given a sampling array, and the current number of detected keypress
+// Add as many keypresses from the sampling array to the USB key send array as possible.
+void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map )
+{
+ for ( uint8_t key = 0; key < numberOfKeys + 1; key++ ) {
+ if ( keys[key] & (1 << 7) ) {
+ // TODO Debug Out
+ uint8_t modFound = 0;
+
+ // Determine if the key is a modifier
+ for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) {
+ // Modifier found
+ if ( modifiers[mod] == key ) {
+ USBKeys_Modifiers |= map[key];
+ modFound = 1;
+ break;
+ }
+ }
+ if ( modFound )
+ continue;
+
+ // Too many keys
+ if ( *validKeys >= USBKeys_MaxSize )
+ break;
+
+ // Allow ignoring keys with 0's
+ if ( map[key] != 0 )
+ USBKeys_Array[(*validKeys)++] = map[key];
+ }
+ }
+}
+
+void process_macros(void)
+{
+ // Layout Setup
+ uint8_t validKeys = 0;
+
+ uint8_t *keyboard_MODMASK = keyboard_modifierMask;
+ uint8_t keyboard_NUMMODS = MODIFIERS_KEYBOARD;
+ uint8_t *keyboard_MAP = defaultMap;
+
+ // Debounce Sampling Array to USB Data Array
+ keyPressDetection( KeyIndex_Array, &validKeys, KeyIndex_Size, keyboard_MODMASK, keyboard_NUMMODS, keyboard_MAP );
+}
+
--- /dev/null
+/* 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 __macro_h
+#define __macro_h
+
+// ----- Includes -----
+
+// Compiler Includes
+#include <stdint.h>
+
+
+
+// ----- Functions -----
+
+void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map );
+void process_macros(void);
+
+#endif
+
#
set( MACRO_SRCS
+ macro.c
)
* THE SOFTWARE.
*/
+// ----- Includes -----
+
+// Local Includes
#include "matrix.h"
+
+
+// ----- Macros -----
+
#define REG_SET(reg) reg |= (1 << ( matrix[row][col] % 10 ) )
#define PIN_SET_COL(pin) \
break
+
+// ----- Variables -----
+
+uint8_t KeyIndex_Array[KEYBOARD_SIZE + 1];
+
+
+
+// ----- Functions -----
+
void matrix_pinSetup( uint8_t *matrix )
{
// Setup the variables
#ifndef __MATRIX_H
#define __MATRIX_H
+// ----- Includes -----
+
+// Compiler Includes
+#include <stdint.h>
+
+
// ----- Quick Map (don't change) -----
#define pinA0 0
#define pinA1 1
// ----- Key Settings -----
-#define keyboardSize 16 // # of keys
+#define KEYBOARD_SIZE 16 // # of keys
+#define MAX_ROW_SIZE 16 // # of keys in the largest row
// ----- Matrix Configuration -----
-static uint8_t matrix_pinout[][] = {
+static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
// The mode allows for optimization in the kind of scanning algorithms that are done
//
// The key numbers are used to translate into the keymap table (array) (and always start from 1, not 0).
+// Thus if a row doesn't use all the key positions, you can denote it as 0, which will be ignored/skipped on each scan
// See the keymap.h file for the various preconfigured arrays.
// Scan Mode | Col 1 | Col 2 | Col 3 | Col 4 | Col 4 | ...
};
+
// ----- Variables -----
// NOTE: Highest Bit: Valid keypress (0x80 is valid keypress)
// Other Bits: Pressed state sample counter
-uint8_t keyboardDetectArray[keyboardSize + 1];
+extern uint8_t KeyIndex_Array [KEYBOARD_SIZE + 1];
+ static const uint8_t KeyIndex_Size = KEYBOARD_SIZE;
* THE SOFTWARE.
*/
+// ----- Includes -----
+
+// Local Includes
+#include "scan_loop.h"
+
+
+
+// ----- Defines -----
-#include <stdint.h>
-#include <usb_keyboard_debug.h>
-#include <keymap.h>
// Debouncing Defines
#define SAMPLE_THRESHOLD 110
-#define MAX_SAMPLES 127 // Max is 127, reaching 128 is very bad
+#define MAX_SAMPLES 127 // Max is 127, reaching 128 is very bad
+
+
+
+// ----- Macros -----
+
// Loop over all of the sampled keys of the given array
// If the number of samples is higher than the sample threshold, flag the high bit, clear otherwise
// This should be resetting VERY quickly, cutting off a potentially valid keypress is not an issue
table[key] = ( table[key] & ~(1 << 7) ) > SAMPLE_THRESHOLD ? (1 << 7) : 0x00; \
} \
-// NOTE: Highest Bit: Valid keypress (0x80 is valid keypress)
-// Other Bits: Pressed state sample counter
-#define KEYBOARD_SIZE 23
-uint8_t keyboardDetectArray[KEYBOARD_SIZE + 1];
-
-// Interrupt Variable
-volatile uint8_t sendKeypresses = 0;
-
-// USB Data Send
-void usb_send( uint8_t validKeys )
-{
- // TODO undo potentially old keys
- for ( uint8_t c = validKeys; c < 6; c++ )
- keyboard_keys[c] = 0;
- // Send keypresses
- usb_keyboard_send();
- // Clear sendKeypresses Flag
- sendKeypresses = 0;
+// ----- Variables -----
- // Clear modifiers
- keyboard_modifier_keys = 0;
-}
+// Keeps track of the number of scans, so we only do a debounce assess when it would be valid (as it throws away data)
+uint8_t scan_count = 0;
-// Given a sampling array, and the current number of detected keypress
-// Add as many keypresses from the sampling array to the USB key send array as possible.
-void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map ) {
- for ( uint8_t key = 0; key < numberOfKeys + 1; key++ ) {
- if ( keys[key] & (1 << 7) ) {
- pint8( key );
- //print(" ");
- uint8_t modFound = 0;
-
- // Determine if the key is a modifier
- for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) {
- // Modifier found
- if ( modifiers[mod] == key ) {
- keyboard_modifier_keys |= map[key];
- modFound = 1;
- break;
- }
- }
- if ( modFound )
- continue;
-
- // Too many keys
- if ( *validKeys == 6 )
- break;
-
- // Allow ignoring keys with 0's
- if ( map[key] != 0 )
- keyboard_keys[(*validKeys)++] = map[key];
- }
- }
-}
+// ----- Functions -----
// Main Detection Loop
-void scan_loop( void )
+void scan_loop()
{
//matrix_pinSetup( matrix_pinout );
- uint8_t count = 0;
-
- for ( ;; ) {
- //matrix_scan( matrix_pinout, keyboardDetectArray );
-
- // Check count to see if the sample threshold may have been reached, otherwise collect more data
- if ( count++ < MAX_SAMPLES )
- continue;
-
- // Reset Sample Counter
- count = 0;
-
- // Assess debouncing sample table
- //DEBOUNCE_ASSESS(keyDetectArray,KEYBOARD_SIZE)
-
- // Send keypresses over USB if the ISR has signalled that it's time
- if ( !sendKeypresses )
- continue;
-
- // Layout Setup
- uint8_t validKeys = 0;
-
- uint8_t *keyboard_MODMASK = keyboard_modifierMask;
- uint8_t keyboard_NUMMODS = MODIFIERS_KEYBOARD;
- uint8_t *keyboard_MAP = defaultMap;
- // TODO Layout Switching
+ //matrix_scan( matrix_pinout, keyboardDetectArray );
- // TODO Macro Processing
+ // Check count to see if the sample threshold may have been reached, otherwise collect more data
+ if ( scan_count++ < MAX_SAMPLES )
+ return;
- // Debounce Sampling Array to USB Data Array
- keyPressDetection( keyboardDetectArray, &validKeys, KEYBOARD_SIZE, keyboard_MODMASK, keyboard_NUMMODS, keyboard_MAP );
+ // Reset Sample Counter
+ scan_count = 0;
- // Send USB Data
- usb_send( validKeys );
- }
+ // Assess debouncing sample table
+ //DEBOUNCE_ASSESS(keyDetectArray,KEYBOARD_SIZE)
}
#ifndef __SCAN_LOOP_H
#define __SCAN_LOOP_H
-//extern uint8_t keyboardDetectArray[KEYBOARDZ
-extern volatile uint8_t sendKeypresses;
+// ----- Includes -----
+
+// Local Includes
+#include "matrix.h"
+
+
+
+// ----- Functions -----
void scan_loop( void );
#
set( USB_SRCS
+ usb_com.c
usb_keyboard_debug.c
)
--- /dev/null
+/* 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.
+ */
+
+// ----- Includes -----
+
+// Compiler Includes
+#include <util/delay.h>
+
+// AVR Includes
+
+// Project Includes
+#include "usb_keyboard_debug.h"
+
+// Local Includes
+#include "usb_com.h"
+
+
+
+// ----- Variables -----
+
+// which modifier keys are currently pressed
+// 1=left ctrl, 2=left shift, 4=left alt, 8=left gui
+// 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
+ uint8_t USBKeys_Modifiers = 0;
+
+// which keys are currently pressed, up to 6 keys may be down at once
+ uint8_t USBKeys_Array[USB_MAX_KEY_SEND] = {0,0,0,0,0,0};
+
+// The number of keys sent to the usb in the array
+ uint8_t USBKeys_Sent;
+
+// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
+volatile uint8_t USBKeys_LEDs = 0;
+
+
+
+// ----- Functions -----
+
+// USB Module Setup
+void usb_setup(void)
+{
+ // Initialize the USB, and then wait for the host to set configuration.
+ // If the Teensy is powered without a PC connected to the USB port,
+ // this will wait forever.
+ usb_init();
+ while ( !usb_configured() ) /* wait */ ;
+
+ // Wait an extra second for the PC's operating system to load drivers
+ // and do whatever it does to actually be ready for input
+ _delay_ms(1000);
+}
+
+
+// USB Data Send
+void usb_send(void)
+{
+ // TODO undo potentially old keys
+ for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
+ USBKeys_Array[c] = 0;
+
+ // Send keypresses
+ usb_keyboard_send();
+
+ // Clear modifiers
+ USBKeys_Modifiers = 0;
+}
+
--- /dev/null
+/* 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 __usb_com_h
+#define __usb_com_h
+
+// ----- Includes -----
+
+// AVR Includes
+
+// Compiler Includes
+#include <stdint.h>
+
+// Local Includes
+
+
+
+// ----- Defines -----
+
+// Indicator for other modules through USBKeys_MaxSize for how capable the USB module is when sending large number of keypresses
+#define USB_MAX_KEY_SEND 6
+
+
+// You can change these to give your code its own name.
+#define STR_MANUFACTURER L"MfgName"
+#define STR_PRODUCT L"Keyboard"
+
+
+// Mac OS-X and Linux automatically load the correct drivers. On
+// Windows, even though the driver is supplied by Microsoft, an
+// INF file is needed to load the driver. These numbers need to
+// match the INF file.
+#define VENDOR_ID 0x16C0
+#define PRODUCT_ID 0x047D
+
+
+
+// ----- Variables -----
+
+// Variables used to communciate to the usb module
+extern uint8_t USBKeys_Modifiers;
+extern uint8_t USBKeys_Array[USB_MAX_KEY_SEND];
+extern uint8_t USBKeys_Sent;
+extern volatile uint8_t USBKeys_LEDs;
+ static const uint8_t USBKeys_MaxSize = USB_MAX_KEY_SEND;
+
+
+
+// ----- Functions -----
+
+void usb_setup(void);
+void usb_send(void);
+
+#endif
+
*
**************************************************************************/
-// You can change these to give your code its own name.
-#define STR_MANUFACTURER L"MfgName"
-#define STR_PRODUCT L"Keyboard"
-
-
-// Mac OS-X and Linux automatically load the correct drivers. On
-// Windows, even though the driver is supplied by Microsoft, an
-// INF file is needed to load the driver. These numbers need to
-// match the INF file.
-#define VENDOR_ID 0x16C0
-#define PRODUCT_ID 0x047D
-
-
// USB devices are supposed to implment a halt feature, which is
// rarely (if ever) used. If you comment this line out, the halt
// code will be removed, saving 102 bytes of space (gcc 4.3.0).
// packet, or send a zero length packet.
static volatile uint8_t debug_flush_timer=0;
-// which modifier keys are currently pressed
-// 1=left ctrl, 2=left shift, 4=left alt, 8=left gui
-// 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
-uint8_t keyboard_modifier_keys=0;
-
-// which keys are currently pressed, up to 6 keys may be down at once
-uint8_t keyboard_keys[6]={0,0,0,0,0,0};
-
// protocol setting from the host. We use exactly the same report
// either way, so this variable only stores the setting since we
// are required to be able to report which setting is in use.
// count until idle timeout
static uint8_t keyboard_idle_count=0;
-// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
-volatile uint8_t keyboard_leds=0;
-
/**************************************************************************
*
{
int8_t r;
- keyboard_modifier_keys = modifier;
- keyboard_keys[0] = key;
+ USBKeys_Modifiers = modifier;
+ USBKeys_Array[0] = key;
r = usb_keyboard_send();
if (r) return r;
- keyboard_modifier_keys = 0;
- keyboard_keys[0] = 0;
+ USBKeys_Modifiers = 0;
+ USBKeys_Array[0] = 0;
return usb_keyboard_send();
}
-// send the contents of keyboard_keys and keyboard_modifier_keys
+// send the contents of USBKeys_Array and USBKeys_Modifiers
int8_t usb_keyboard_send(void)
{
uint8_t i, intr_state, timeout;
cli();
UENUM = KEYBOARD_ENDPOINT;
}
- UEDATX = keyboard_modifier_keys;
+ UEDATX = USBKeys_Modifiers;
UEDATX = 0;
for (i=0; i<6; i++) {
- UEDATX = keyboard_keys[i];
+ UEDATX = USBKeys_Array[i];
}
UEINTX = 0x3A;
keyboard_idle_count = 0;
keyboard_idle_count++;
if (keyboard_idle_count == keyboard_idle_config) {
keyboard_idle_count = 0;
- UEDATX = keyboard_modifier_keys;
+ UEDATX = USBKeys_Modifiers;
UEDATX = 0;
for (i=0; i<6; i++) {
- UEDATX = keyboard_keys[i];
+ UEDATX = USBKeys_Array[i];
}
UEINTX = 0x3A;
}
if (bmRequestType == 0xA1) {
if (bRequest == HID_GET_REPORT) {
usb_wait_in_ready();
- UEDATX = keyboard_modifier_keys;
+ UEDATX = USBKeys_Modifiers;
UEDATX = 0;
for (i=0; i<6; i++) {
- UEDATX = keyboard_keys[i];
+ UEDATX = USBKeys_Array[i];
}
usb_send_in();
return;
if (bmRequestType == 0x21) {
if (bRequest == HID_SET_REPORT) {
usb_wait_receive_out();
- keyboard_leds = UEDATX;
+ USBKeys_LEDs = UEDATX;
usb_ack_out();
usb_send_in();
return;
#define usb_serial_h__
#include <stdint.h>
+#include "usb_com.h"
void usb_init(void); // initialize everything
uint8_t usb_configured(void); // is the USB port configured
int8_t usb_keyboard_press(uint8_t key, uint8_t modifier);
int8_t usb_keyboard_send(void);
-extern uint8_t keyboard_modifier_keys;
-extern uint8_t keyboard_keys[6];
-extern volatile uint8_t keyboard_leds;
+
int8_t usb_debug_putchar(uint8_t c); // transmit a character
void usb_debug_flush_output(void); // immediately transmit any buffered output
* THE SOFTWARE.
*/
+// ----- Includes -----
+
+// AVR Includes
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
-#include <util/delay.h>
+
+// Project Includes
//#include "usb_keys.h"
#include "scan_loop.h"
//#include "layouts.h"
//#include "usb_keyboard.h"
-// TEMP INCLUDES
#include "usb_keyboard_debug.h"
#include "print.h"
-
-#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+#include "led.h"
+// ----- Defines -----
// Verified Keypress Defines
#define USB_TRANSFER_DIVIDER 10 // 1024 == 1 Send of keypresses per second, 1 == 1 Send of keypresses per ~1 millisecond
-// Error LED Control
-void errorLED( uint8_t on )
-{
- // Error LED On
- if ( on ) {
- PORTD |= (1<<6);
- }
- // Error LED Off
- else {
- PORTD &= ~(1<<6);
- }
-}
+// ----- Macros -----
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+
+
+
+// ----- Variables -----
+
+// Timer Interrupt for flagging a send of the sampled key detection data to the USB host
+uint16_t sendKeypressCounter = 0;
+
+// Flag generated by the timer interrupt
+volatile uint8_t sendKeypresses = 0;
+
-// Initial Pin Setup
-// If the matrix is properly set, this function does not need to be changed
+
+// ----- Functions -----
+
+// Initial Pin Setup, make sure they are sane
inline void pinSetup(void)
{
// For each pin, 0=input, 1=output
DDRA = 0x00;
DDRB = 0x00;
DDRC = 0x00;
- DDRD = 0x40; // LED Setup
+ DDRD = 0x00;
DDRE = 0x00;
DDRF = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
- PORTD = 0x40; // LED Enable
+ PORTD = 0x00;
PORTE = 0x00;
PORTF = 0x00;
}
-int main( void )
+int main(void)
{
// Setup with 16 MHz clock
CPU_PRESCALE( 0 );
// Configuring Pins
pinSetup();
- // Initialize the USB, and then wait for the host to set configuration.
- // If the Teensy is powered without a PC connected to the USB port,
- // this will wait forever.
- usb_init();
- while ( !usb_configured() ) /* wait */ ;
-
- // Wait an extra second for the PC's operating system to load drivers
- // and do whatever it does to actually be ready for input
- _delay_ms(1000);
+ // Setup USB Module
+ usb_setup();
// Setup ISR Timer for flagging a kepress send to USB
// Set to 256 * 1024 (8 bit timer with Clock/1024 prescalar) timer
TCCR0B = 0x03;
TIMSK0 = (1 << TOIE0);
- uint16_t led = 0;
// Main Detection Loop
while ( 1 ) {
//scan_loop();
// HID Debug Error message
erro_print("Detection loop error, this is very bad...bug report!");
+
+ // Send keypresses over USB if the ISR has signalled that it's time
+ if ( !sendKeypresses )
+ continue;
+
+ // Send USB Data
+ usb_send();
+
+ // Clear sendKeypresses Flag
+ sendKeypresses = 0;
}
}
-// Timer Interrupt for flagging a send of the sampled key detection data to the USB host
-uint16_t sendKeypressCounter = 0;
-
ISR( TIMER0_OVF_vect )
{
sendKeypressCounter++;
set( USBModule "pjrc" )
##| Debugging source to use, each module has it's own set of defines that it sets
-set( DebugModule "basic" )
+set( DebugModule "full" )