]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Fixing RAM calculator and reduced actual SRAM usage
authorJacob Alexander <haata@kiibohd.com>
Fri, 15 Aug 2014 17:42:12 +0000 (10:42 -0700)
committerJacob Alexander <haata@kiibohd.com>
Fri, 15 Aug 2014 17:49:44 +0000 (10:49 -0700)
- Changed static variables to const that should have been const
- Updated CMake files to prepare for MCHCK custom bootloader
- Changed the USB ID numbers and ID number for bootloader
- Only generate DFU or Teensy binary image, not both
- Fixed RAM and FLASH calculator
- Added missing license in delay.c/h (much of it was taken from Teensy source though I've changed a bunch of it)
- Prepared mk20dx.c for upcoming bootloader addition
- mk20dx.h cleanup
- Reduced the MCHCK based flash size for the application image (bootloader changes requires more flash space)
- Fixed bugs in macro.c
- Added keyHold cli command
- Added show pending events debug message for PartialMap macro module

24 files changed:
CMakeLists.txt
Debug/cli/cli.c
Debug/cli/cli.h
Lib/CMake/arm.cmake
Lib/CMake/avr.cmake
Lib/CMake/initialize.cmake
Lib/CMake/modules.cmake
Lib/CMake/sizeCalculator
Lib/Interrupts.h
Lib/delay.c
Lib/delay.h
Lib/mk20dx.c
Lib/mk20dx.h
Lib/mk20dx128vlf5.ld
Macro/PartialMap/generatedKeymap.h
Macro/PartialMap/macro.c
Output/pjrcUSB/arm/usb_dev.c
Output/pjrcUSB/output_com.c
Output/uartOut/output_com.c
Output/usbMuxUart/output_com.c
Scan/ADCTest/scan_loop.c
Scan/DPH/scan_loop.c
Scan/MD1/scan_loop.c
Scan/MatrixARM/matrix_scan.c

index e053e0456bb24a3f41b9c4c88e1b916def057cb6..e7e92d100a4041227e89ab6c6b1ccf60b4366575 100644 (file)
@@ -31,7 +31,8 @@ set( CHIP
 ###
 # Compiler Intialization
 #
-include( Lib/CMake/initialize.cmake )
+set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/Lib/CMake )
+include( initialize )
 
 
 
index 2ee4d5ac79b959cd02e3ace3a51f396c2a63518c..fcee021eba86eaffd36731baaef75e39cf756f01 100644 (file)
@@ -35,8 +35,8 @@
 // ----- Variables -----
 
 // Basic command dictionary
-char*       basicCLIDictName = "General Commands";
-CLIDictItem basicCLIDict[] = {
+const char basicCLIDictName[] = "General Commands";
+const CLIDictItem basicCLIDict[] = {
        { "cliDebug", "Enables/Disables hex output of the most recent cli input.", cliFunc_cliDebug },
        { "help",     "You're looking at it :P", cliFunc_help },
        { "led",      "Enables/Disables indicator LED. Try a couple times just in case the LED is in an odd state.\r\n\t\t\033[33mWarning\033[0m: May adversely affect some modules...", cliFunc_led },
@@ -267,7 +267,7 @@ void CLI_commandLookup()
 }
 
 // Registers a command dictionary with the CLI
-void CLI_registerDictionary( CLIDictItem *cmdDict, char* dictName )
+void CLI_registerDictionary( const CLIDictItem *cmdDict, const char* dictName )
 {
        // Make sure this max limit of dictionaries hasn't been reached
        if ( CLIDictionariesUsed >= CLIMaxDictionaries )
@@ -277,8 +277,8 @@ void CLI_registerDictionary( CLIDictItem *cmdDict, char* dictName )
        }
 
        // Add dictionary
-       CLIDictNames[CLIDictionariesUsed] = dictName;
-       CLIDict[CLIDictionariesUsed++] = cmdDict;
+       CLIDictNames[CLIDictionariesUsed] = (char*)dictName;
+       CLIDict[CLIDictionariesUsed++] = (CLIDictItem*)cmdDict;
 }
 
 inline void CLI_tabCompletion()
index c9c18c78879488bd0aa6ddd418044d89c8fb4e7e..84266a336045d3a669f1af3a666664e51a7c01f6 100644 (file)
@@ -68,7 +68,7 @@ uint8_t CLIHexDebugMode;
 
 void CLI_init();
 void CLI_process();
-void CLI_registerDictionary( CLIDictItem *cmdDict, char* dictName );
+void CLI_registerDictionary( const CLIDictItem *cmdDict, const char* dictName );
 void CLI_argumentIsolation( char* string, char** first, char** second );
 
 void CLI_commandLookup();
index 1f8ca421033ea51ec7a0a94a5157ad066cbdd2e8..be2c8b3f5474b1e9a4e07423b6209f8585cff9d5 100644 (file)
@@ -34,8 +34,13 @@ set( MCU "${CHIP}" ) # For loading script compatibility
 
 
 #| Chip Size Database
+#| MCHCK Based
+if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
+       set( SIZE_RAM    16384 )
+       set( SIZE_FLASH 126976 )
+
 #| Teensy 3.0
-if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx128vlf5" )
+elseif ( "${CHIP}" MATCHES "mk20dx128" )
        set( SIZE_RAM    16384 )
        set( SIZE_FLASH 131072 )
 
@@ -84,12 +89,18 @@ message( "${COMPILER_SRCS}" )
 
 
 #| USB Defines, this is how the loader programs detect which type of chip base is used
-if ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
-       set( VENDOR_ID  "0x16C0" )
-       set( PRODUCT_ID "0x0487" )
-elseif ( "${CHIP}" MATCHES "mk20dx128vlf5" )
-       set( VENDOR_ID  "0x2323" )
-       set( PRODUCT_ID "0x0001" )
+if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
+       set( VENDOR_ID       "0x1C11" )
+       set( PRODUCT_ID      "0xB04D" )
+       set( BOOT_VENDOR_ID  "0x1C11" )
+       set( BOOT_PRODUCT_ID "0xB007" )
+       set( DFU 1 )
+elseif ( "${CHIP}" MATCHES "mk20dx128" OR "${CHIP}" MATCHES "mk20dx256" )
+       set( VENDOR_ID       "0x1C11" )
+       set( PRODUCT_ID      "0xB04D" )
+       set( BOOT_VENDOR_ID  "0x16c0" ) # TODO Double check, this is likely incorrect
+       set( BOOT_PRODUCT_ID "0x0487" )
+       set( TEENSY 1 )
 endif ()
 
 
@@ -98,18 +109,24 @@ endif ()
 #|     gnu89 = c89 plus GCC extensions
 #|     c99   = ISO C99 standard (not yet fully implemented)
 #|     gnu99 = c99 plus GCC extensions
-set( CSTANDARD "-std=gnu99" )
+#|     gnu11 = c11 plus GCC extensions
+set( CSTANDARD "-std=gnu11" )
 
 
 #| Warning Options
 #|  -Wall...:     warning level
-set( WARN "-Wall -g" )
+set( WARN "-Wall -ggdb3" )
 
 
 #| Tuning Options
 #|  -f...:        tuning, see GCC manual
 #| NOTE: -fshort-wchar is specified to allow USB strings be passed conveniently
-set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar -fno-builtin" )
+if( BOOTLOADER )
+       set( TUNING "-D_bootloader_ -Wno-main -msoft-float -mthumb -fplan9-extensions -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin" )
+       #set( TUNING "-mthumb -fdata-sections -ffunction-sections -fno-builtin -msoft-float -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -fwhole-program -Wno-main -nostartfiles -fplan9-extensions -D_bootloader_" )
+else()
+       set( TUNING "-mthumb -nostdlib -fdata-sections -ffunction-sections -fshort-wchar -fno-builtin -nostartfiles" )
+endif()
 
 
 #| Optimization level, can be [0, 1, 2, 3, s].
@@ -136,7 +153,14 @@ add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -D_${CHIP}_=1 -O${OPT} ${TUNING}
 
 
 #| Linker Flags
-set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=link.map,--cref -Wl,--gc-sections -mthumb -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld -nostartfiles" )
+if( BOOTLOADER )
+       # Bootloader linker flags
+       set( LINKER_FLAGS "${TUNING} -Wl,--gc-sections -fwhole-program -T${CMAKE_CURRENT_SOURCE_DIR}/../Lib/${CHIP}.bootloader.ld -nostartfiles -Wl,-Map=link.map" )
+       #set( LINKER_FLAGS "-Wl,-Map=link.map,--cref -Wl,--gc-sections -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/../Lib/${CHIP}.bootloader.ld" )
+else()
+       # Normal linker flags
+       set( LINKER_FLAGS "-Wl,-Map=link.map,--cref -Wl,--gc-sections -Wl,--no-wchar-size-warning -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
+endif()
 
 
 #| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
index 7e92a10b6ac503792cd79d9fb5e32da9e835a697..a6985778eda48fdfdb330fec0d9fe99b5f912f33 100644 (file)
@@ -36,6 +36,10 @@ message( STATUS "MCU Selected:" )
 message( "${MCU}" )
 
 
+#| Indicate to later build step that this is a Teensy
+set( Teensy )
+
+
 #| Chip Size Database
 #| Teensy 1.0
 if ( "${CHIP}" MATCHES "at90usb162" )
@@ -80,8 +84,10 @@ message( "${CPU}" )
 
 
 #| USB Defines
-set( VENDOR_ID  "0x16C0" )
-set( PRODUCT_ID "0x047D" )
+set( VENDOR_ID       "0x1C11" )
+set( PRODUCT_ID      "0xB04D" )
+set( BOOT_VENDOR_ID  "0x16C0" ) # TODO Double check, this is likely incorrect
+set( BOOT_PRODUCT_ID "0x047D" )
 
 
 #| Compiler flag to set the C Standard level.
index b3eaa5c0ba58b0c7f21bcc89040044bb4a196f01..ba370bc1885e8df516029d1a9d34797b642305f4 100644 (file)
@@ -50,7 +50,7 @@ if ( EXISTS compiler )
 endif ()
 
 #| Load the compiler family specific configurations
-include( Lib/CMake/${COMPILER_FAMILY}.cmake )
+include( ${COMPILER_FAMILY} )
 
 #| Binutils not set by CMake
 set( CMAKE_SIZE "${_CMAKE_TOOLCHAIN_PREFIX}size" )
index 35b3e2b3853a50dcaf3ac6bf9eac75469c5c50df..5cd2d3dcb4f83e4ea37d7e0e28135505f270451e 100644 (file)
@@ -129,6 +129,14 @@ message( "${DEBUG_SRCS}" )
 
 
 
+###
+# CMake Module Checking
+#
+find_package( Git REQUIRED )
+find_package( Ctags ) # Optional
+
+
+
 ###
 # Generate USB Defines
 #
@@ -240,13 +248,6 @@ ModuleCompatibility( ${DebugModulePath}  ${DebugModuleCompatibility}  )
 
 
 
-###
-# CMake Module Checking
-#
-find_package( Git REQUIRED )
-find_package( Ctags ) # Optional
-
-
 ###
 # ctag Generation
 #
@@ -287,19 +288,23 @@ set_target_properties( ${TARGET_ELF} PROPERTIES
 
 
 #| Convert the .ELF into a .bin to load onto the McHCK
-set( TARGET_BIN ${TARGET}.bin.dfu )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
-       COMMENT "Creating binary file to load:  ${TARGET_BIN}"
-)
+if( DEFINED DFU )
+       set( TARGET_BIN ${TARGET}.dfu.bin )
+       add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
+               COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
+               COMMENT "Creating dfu binary file:      ${TARGET_BIN}"
+       )
+endif()
 
 
 #| Convert the .ELF into a .HEX to load onto the Teensy
-set( TARGET_HEX ${TARGET}.teensy.hex )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
-       COMMENT "Creating iHex file to load:    ${TARGET_HEX}"
-)
+if ( DEFINED TEENSY )
+       set( TARGET_HEX ${TARGET}.teensy.hex )
+       add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
+               COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
+               COMMENT "Creating iHex file to load:    ${TARGET_HEX}"
+       )
+endif()
 
 
 #| Generate the Extended .LSS
@@ -331,8 +336,8 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
 
 #| After Changes Size Information
 add_custom_target( SizeAfter ALL
-       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ihex ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
-       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ihex ${TARGET_HEX} ${SIZE_FLASH} "Flash"
+       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram   ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
+       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
        DEPENDS ${TARGET_ELF}
        COMMENT "Chip usage for ${CHIP}"
 )
index 1bf814ead4b50f57482a314eab26c594fbec1ed2..affb1637b8a94dea393f1179930666b560ddbe3a 100755 (executable)
@@ -2,15 +2,24 @@
 #| Jacob Alexander 2014
 #| Arg List
 #| 1 - size binary   (e.g. avr-size)
-#| 2 - target binary (e.g. ihex)
+#| 2 - measurement type (flash or ram)
 #| 3 - binary file   (e.g. kiibohd.hex)
 #| 4 - total available (flash/ram) in bytes
-#| 5 - flash/ram
+#| 5 - flash/ram text
 
 
-# Looks for the data column, to get the flash/ram used (in bytes)
-# <size binary> --target=<target binary> <binary file> | cut -f2 | tail -n 1
-USED=$("$1" --target="$2" "$3" | cut -f2 | tail -n 1)
+case "$2" in
+"flash")
+       USED=$("$1" "$3" | tail -n-1 | awk '{ print $1+$2 }')
+       ;;
+"ram")
+       USED=$("$1" "$3" | tail -n-1 | awk '{ print $2+$3 }')
+       ;;
+*)
+       echo "INVALID Measurement type: $2"
+       exit 1
+esac
+
 
 # Calculates the total flash/ram used
 TOTAL="$4"
@@ -35,7 +44,7 @@ fi
 
 # Displays Results
 NAME="$5"
-echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m ${USED}/${TOTAL}\tbytes"
+echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m \t${USED}/${TOTAL}\tbytes"
 
 exit 0
 
index 9348c3641f7c8d89ab69757570bf814087082223..a60466dfb64ad9c722adef399c1ab06eb67b8088 100644 (file)
@@ -1,15 +1,15 @@
 /* Copyright (C) 2013-2014 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
index 2975f3e4651a7717e314ad4cf8a053d4a42416b1..1f1d5aff545aa5c3777564055280a5aecd227aab 100644 (file)
@@ -1,10 +1,50 @@
+/* Teensyduino Core Library
+ * http://www.pjrc.com/teensy/
+ * Copyright (c) 2013 PJRC.COM, LLC.
+ * Modifications by Jacob Alexander 2013-2014
+ *
+ * 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:
+ *
+ * 1. The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * 2. If the Software is incorporated into a build system that allows
+ * selection among a list of target devices, then similar target
+ * devices manufactured by PJRC.COM must be included in the list of
+ * target devices and selectable in the same manner.
+ *
+ * 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.
+ */
+
+// ----- Local Includes -----
 
 #include "delay.h"
 #include "mk20dx.h"
 
+
+
+// ----- Variables -----
+
 // the systick interrupt is supposed to increment this at 1 kHz rate
 volatile uint32_t systick_millis_count = 0;
 
+
+
+// ----- Functions -----
+
 void yield(void) {};
 
 uint32_t micros(void)
index 58746efcfcccb533940db3802f9d630d513c1797..76f20060e47a2e730f98f979eb46b8922bbd281c 100644 (file)
@@ -1,14 +1,53 @@
+/* Teensyduino Core Library
+ * http://www.pjrc.com/teensy/
+ * Copyright (c) 2013 PJRC.COM, LLC.
+ * Modifications by Jacob Alexander 2013-2014
+ *
+ * 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:
+ *
+ * 1. The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * 2. If the Software is incorporated into a build system that allows
+ * selection among a list of target devices, then similar target
+ * devices manufactured by PJRC.COM must be included in the list of
+ * target devices and selectable in the same manner.
+ *
+ * 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 __DELAY_H
 #define __DELAY_H
 
+// ----- System Includes -----
+
 #include <stdint.h>
 
+
+
+// ----- Macros -----
+
 // Convenience Macros, for delay compatibility with AVR-GCC
 #define _delay_ms(val) delay( val )
 #define _delay_us(val) delayMicroseconds( val )
 
 
+
+// ----- Functions -----
+
 // the systick interrupt is supposed to increment this at 1 kHz rate
 extern volatile uint32_t systick_millis_count;
 
index 4913a759aa380a4dbf7052c492a242801324774f..b1a32ed43a72942f16be21755448913e6ebe47d9 100644 (file)
@@ -31,7 +31,6 @@
 
 // Local Includes
 #include "mk20dx.h"
-#include <print.h>
 
 
 
@@ -45,6 +44,8 @@ extern unsigned long _sbss;
 extern unsigned long _ebss;
 extern unsigned long _estack;
 
+const uint8_t sys_reset_to_loader_magic[22] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
+
 
 
 // ----- Function Declarations -----
@@ -354,23 +355,98 @@ const uint8_t flashconfigbytes[16] = {
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF
 };
+#elif defined(_mk20dx128vlf5_) && defined(_bootloader_)
+// XXX Byte labels may be in incorrect positions, double check before modifying
+//     FSEC is in correct location -Jacob
+__attribute__ ((section(".flashconfig"), used))
+const uint8_t flashconfigbytes[16] = {
+       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Backdoor Verif Key 28.3.1
+       0xFF, 0xFF, 0xFF, 0xFF, // Program Flash Protection Bytes FPROT0-3
+       0xBE, // Flash security byte FSEC
+       0x03, // Flash nonvolatile option byte FOPT
+       0xFF, // EEPROM Protection Byte FEPROT
+       0xFF, // Data Flash Protection Byte FDPROT
+};
 #endif
 
 
 
+// ----- Functions -----
+
+__attribute__((noreturn))
+static inline void jump_to_app( uintptr_t addr )
+{
+        // addr is in r0
+        __asm__("ldr sp, [%[addr], #0]\n"
+                "ldr pc, [%[addr], #4]"
+                :: [addr] "r" (addr));
+        // NOTREACHED
+        __builtin_unreachable();
+}
+
+void *memset( void *addr, int val, unsigned int len )
+{
+       char *buf = addr;
+
+       for (; len > 0; --len, ++buf)
+               *buf = val;
+       return (addr);
+}
+
+int memcmp( const void *a, const void *b, unsigned int len )
+{
+       const uint8_t *ap = a, *bp = b;
+       int val = 0;
+
+       for (; len > 0 && (val = *ap - *bp) == 0; --len, ++ap, ++bp)
+               /* NOTHING */;
+       return (val);
+}
+
+void *memcpy( void *dst, const void *src, unsigned int len )
+{
+       char *dstbuf = dst;
+       const char *srcbuf = src;
+
+       for (; len > 0; --len, ++dstbuf, ++srcbuf)
+               *dstbuf = *srcbuf;
+       return (dst);
+}
+
+
+
 // ----- Chip Entry Point -----
 
 __attribute__ ((section(".startup")))
 void ResetHandler()
 {
-       uint32_t *src = &_etext;
-       uint32_t *dest = &_sdata;
-
        // Disable Watchdog
        WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
        WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
        WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
 
+#if defined(_mk20dx128vlf5_) && defined(_bootloader_) // Bootloader Section
+       extern uint32_t _app_rom;
+
+       // We treat _app_rom as pointer to directly read the stack
+       // pointer and check for valid app code.  This is no fool
+       // proof method, but it should help for the first flash.
+       if ( RCM_SRS0 & 0x40 || _app_rom == 0xffffffff ||
+         memcmp( (uint8_t*)&VBAT, sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic) ) == 0 ) // Check for soft reload
+       {
+               memset( (uint8_t*)&VBAT, 0, sizeof(VBAT) );
+       }
+       else
+       {
+               uint32_t addr = (uintptr_t)&_app_rom;
+               SCB_VTOR = addr; // relocate vector table
+               jump_to_app( addr );
+       }
+#endif
+
+       uint32_t *src = &_etext;
+       uint32_t *dest = &_sdata;
+
        // Enable clocks to always-used peripherals
        SIM_SCGC5 = 0x00043F82; // Clocks active to all GPIO
        SIM_SCGC6 = SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
@@ -486,11 +562,17 @@ void ResetHandler()
        SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL | SIM_SOPT2_TRACECLKSEL | SIM_SOPT2_CLKOUTSEL( 6 );
 
 #endif
+
+#if !defined(_bootloader_)
        // Initialize the SysTick counter
        SYST_RVR = (F_CPU / 1000) - 1;
        SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_TICKINT | SYST_CSR_ENABLE;
 
        __enable_irq();
+#else
+       // Disable Watchdog for bootloader
+       WDOG_STCTRLH &= ~WDOG_STCTRLH_WDOGEN;
+#endif
 
        main();
        while ( 1 ); // Shouldn't get here...
index 42be1540067cbf840ca67d8e682381001bda1915..fba3ce9785dd253b2fdaaaf4704e163fed510acd 100644 (file)
@@ -1,6 +1,7 @@
 /* Teensyduino Core Library
  * http://www.pjrc.com/teensy/
  * Copyright (c) 2013 PJRC.COM, LLC.
+ * Modified by Jacob Alexander 2014
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
 #ifndef _mk20dx_h_
 #define _mk20dx_h_
 
-//#define F_CPU 96000000
-//#define F_CPU 48000000
-//#define F_CPU 24000000
-//#define F_BUS 48000000
-//#define F_BUS 24000000
-//#define F_MEM 24000000
+// ----- Defines -----
 
 #if (F_CPU == 96000000)
  #define F_BUS 48000000
 #define NULL ((void *)0)
 #endif
 
+
+
+// ----- Includes -----
+
 #include <stdint.h>
 
+
+
+// ----- Registers -----
+
 // chapter 11: Port control and interrupts (PORT)
 #define PORT_PCR_ISF                   (uint32_t)0x01000000            // Interrupt Status Flag
 #define PORT_PCR_IRQC(n)               (uint32_t)(((n) & 15) << 16)    // Interrupt Configuration
 #define SIM_SOPT1               *(volatile uint32_t *)0x40047000 // System Options Register 1
 #define SIM_SOPT1CFG            *(volatile uint32_t *)0x40047004 // SOPT1 Configuration Register
 #define SIM_SOPT2               *(volatile uint32_t *)0x40048004 // System Options Register 2
-#define SIM_SOPT2_USBSRC               (uint32_t)0x00040000            // 0=USB_CLKIN, 1=FFL/PLL 
+#define SIM_SOPT2_USBSRC               (uint32_t)0x00040000            // 0=USB_CLKIN, 1=FFL/PLL
 #define SIM_SOPT2_PLLFLLSEL            (uint32_t)0x00010000            // 0=FLL, 1=PLL
 #define SIM_SOPT2_TRACECLKSEL          (uint32_t)0x00001000            // 0=MCGOUTCLK, 1=CPU
 #define SIM_SOPT2_PTD7PAD              (uint32_t)0x00000800            // 0=normal, 1=double drive PTD7
 #define MCG_C2                  *(volatile uint8_t  *)0x40064001 // MCG Control 2 Register
 #define MCG_C2_IRCS                    (uint8_t)0x01                   // Internal Reference Clock Select, Selects between the fast or slow internal reference clock source.
 #define MCG_C2_LP                      (uint8_t)0x02                   // Low Power Select, Controls whether the FLL or PLL is disabled in BLPI and BLPE modes.
-#define MCG_C2_EREFS                   (uint8_t)0x04                   // External Reference Select, Selects the source for the external reference clock. 
+#define MCG_C2_EREFS                   (uint8_t)0x04                   // External Reference Select, Selects the source for the external reference clock.
 #define MCG_C2_HGO0                    (uint8_t)0x08                   // High Gain Oscillator Select, Controls the crystal oscillator mode of operation
 #define MCG_C2_RANGE0(n)               (uint8_t)(((n) & 0x03) << 4)    // Frequency Range Select, Selects the frequency range for the crystal oscillator
 #define MCG_C2_LOCRE0                  (uint8_t)0x80                   // Loss of Clock Reset Enable, Determines whether an interrupt or a reset request is made following a loss of OSC0 
 #define MCG_C6                  *(volatile uint8_t  *)0x40064005 // MCG Control 6 Register
 #define MCG_C6_VDIV0(n)                        (uint8_t)((n) & 0x1F)           // VCO 0 Divider
 #define MCG_C6_CME0                    (uint8_t)0x20                   // Clock Monitor Enable
-#define MCG_C6_PLLS                    (uint8_t)0x40                   // PLL Select, Controls whether the PLL or FLL output is selected as the MCG source when CLKS[1:0]=00. 
+#define MCG_C6_PLLS                    (uint8_t)0x40                   // PLL Select, Controls whether the PLL or FLL output is selected as the MCG source when CLKS[1:0]=00.
 #define MCG_C6_LOLIE0                  (uint8_t)0x80                   // Loss of Lock Interrrupt Enable
 #define MCG_S                   *(volatile uint8_t  *)0x40064006 // MCG Status Register
 #define MCG_S_IRCST                    (uint8_t)0x01                   // Internal Reference Clock Status
@@ -1960,8 +1964,32 @@ typedef struct {
 // Other
 #define VBAT                    *(volatile uint8_t *)0x4003E000 // Register available in all power states
 
+
+
+// ----- Macros -----
+
+#define SOFTWARE_RESET()        SCB_AIRCR = 0x5FA0004
+
+
+
+// ----- Variables -----
+
+extern const uint8_t sys_reset_to_loader_magic[22];
+
+
+
+// ----- Functions -----
+
+void *memset( void *addr, int val, unsigned int len );
+void *memcpy( void *dst, const void *src, unsigned int len );
+int memcmp( const void *a, const void *b, unsigned int len );
+
 extern int nvic_execution_priority(void);
 
+
+
+// ----- Interrupts -----
+
 extern void nmi_isr(void);
 extern void hard_fault_isr(void);
 extern void memmanage_fault_isr(void);
@@ -2053,7 +2081,5 @@ extern void portd_isr(void);
 extern void porte_isr(void);
 extern void software_isr(void);
 
-#define SOFTWARE_RESET()        SCB_AIRCR = 0x5FA0004
-
 #endif
 
index d4b3e4101c4623c44a4114a156bc5a29f0ae6ae4..4ab5626c8cdc7211f4ddd2f7300737bfe46ad47f 100644 (file)
@@ -31,7 +31,7 @@
 
 MEMORY
 {
-       FLASH (rx) : ORIGIN = 3K, LENGTH = 128K-3K
+       FLASH (rx) : ORIGIN = 4K, LENGTH = 128K-4K
        RAM  (rwx) : ORIGIN = 0x20000000 - 16K / 2, LENGTH = 16K
 }
 
index c2cfb4e35bb81b28d1e51bdc9648de193a08ad5f..20eee0280da51d1fa1b36bb8fe0f61e81681f96e 100644 (file)
 
 // ----- Includes -----
 
+// Project Includes
 #include <print.h>
+#include <scan_loop.h>
+#include <macro.h>
+#include <output_com.h>
 
 // USB HID Keymap list
 #include <usb_hid.h>
@@ -44,7 +48,7 @@
 
 // ResultMacro struct, one is created per ResultMacro, no duplicates
 typedef struct ResultMacro {
-       uint8_t *guide;
+       const uint8_t *guide;
        unsigned int pos;
        uint8_t  state;
        uint8_t  stateType;
@@ -91,7 +95,7 @@ typedef enum TriggerMacroState {
 
 // TriggerMacro struct, one is created per TriggerMacro, no duplicates
 typedef struct TriggerMacro {
-       uint8_t *guide;
+       const uint8_t *guide;
        unsigned int result;
        unsigned int pos;
        TriggerMacroState state;
@@ -156,13 +160,15 @@ typedef struct Capability {
 } Capability;
 
 // Total Number of Capabilities
-#define CapabilitiesNum sizeof( void* ) / 4 + sizeof( uint8_t )
+#define CapabilitiesNum sizeof( CapabilitiesList ) / sizeof( Capability )
 
 // Indexed Capabilities Table
-// TODO Should be moved to the Scan Module
-Capability CapabilitiesList[] = {
+// TODO Generated from .kll files in each module
+const Capability CapabilitiesList[] = {
        { debugPrint_capability, 1 },
        { debugPrint2_capability, 2 },
+       { Macro_layerStateToggle_capability, sizeof(unsigned int) + 1 },
+       { Output_usbCodeSend_capability, 1 },
 };
 
 
@@ -175,7 +181,7 @@ Capability CapabilitiesList[] = {
 // Define_RM( index );
 //  * index  - Result Macro index number
 //  Must be used after Guide_RM
-#define Guide_RM( index ) static uint8_t rm##index##_guide[]
+#define Guide_RM( index ) const uint8_t rm##index##_guide[]
 #define Define_RM( index ) { rm##index##_guide, 0, 0, 0 }
 
 Guide_RM( 0 ) = { 1, 0, 0xDA, 0 };
@@ -208,13 +214,13 @@ ResultMacro ResultMacroList[] = {
 // Define_TM( index, result );
 //  * index   - Trigger Macro index number
 //  * result  - Result Macro index number which is triggered by this Trigger Macro
-#define Guide_TM( index ) static uint8_t tm##index##_guide[]
-#define Define_TM( index, result ) { tm##index##_guide, result, 0 }
+#define Guide_TM( index ) const uint8_t tm##index##_guide[]
+#define Define_TM( index, result ) { tm##index##_guide, result, 0, TriggerMacro_Waiting }
 
-Guide_TM( 0 ) = { 1, 0x10, 0x01, 0x73, 0 };
-Guide_TM( 1 ) = { 1, 0x0F, 0x01, 0x73, 1, 0x00, 0x01, 0x75, 0 };
-Guide_TM( 2 ) = { 2, 0xF0, 0x01, 0x73, 0x00, 0x01, 0x74, 0 };
-Guide_TM( 3 ) = { 1, 0x10, 0x01, 0x76, 0 };
+Guide_TM( 0 ) = { 1, 0x00, 0x01, 0x73, 0 };
+Guide_TM( 1 ) = { 1, 0x00, 0x01, 0x73, 1, 0x00, 0x01, 0x75, 0 };
+Guide_TM( 2 ) = { 2, 0x00, 0x01, 0x73, 0x00, 0x01, 0x74, 0 };
+Guide_TM( 3 ) = { 1, 0x00, 0x01, 0x76, 0 };
 
 
 // -- Trigger Macro List
@@ -246,7 +252,7 @@ TriggerMacro TriggerMacroList[] = {
 //  * layer       - basename of the layer
 //  * scanCode    - Hex value of the scanCode
 //  * triggerList - Trigger List (see Trigger Lists)
-#define Define_TL( layer, scanCode ) static unsigned int layer##_tl_##scanCode[]
+#define Define_TL( layer, scanCode ) const unsigned int layer##_tl_##scanCode[]
 
 // -- Trigger Lists
 //
@@ -538,17 +544,17 @@ Define_TL( myname2, 0x06 ) = { 0 };
 //                 -
 
 // Default Map for ScanCode Lookup
-static unsigned int *default_scanMap[] = {
+const unsigned int *default_scanMap[] = {
 default_tl_0x00, default_tl_0x01, default_tl_0x02, default_tl_0x03, default_tl_0x04, default_tl_0x05, default_tl_0x06, default_tl_0x07, default_tl_0x08, default_tl_0x09, default_tl_0x0A, default_tl_0x0B, default_tl_0x0C, default_tl_0x0D, default_tl_0x0E, default_tl_0x0F, default_tl_0x10, default_tl_0x11, default_tl_0x12, default_tl_0x13, default_tl_0x14, default_tl_0x15, default_tl_0x16, default_tl_0x17, default_tl_0x18, default_tl_0x19, default_tl_0x1A, default_tl_0x1B, default_tl_0x1C, default_tl_0x1D, default_tl_0x1E, default_tl_0x1F, default_tl_0x20, default_tl_0x21, default_tl_0x22, default_tl_0x23, default_tl_0x24, default_tl_0x25, default_tl_0x26, default_tl_0x27, default_tl_0x28, default_tl_0x29, default_tl_0x2A, default_tl_0x2B, default_tl_0x2C, default_tl_0x2D, default_tl_0x2E, default_tl_0x2F, default_tl_0x30, default_tl_0x31, default_tl_0x32, default_tl_0x33, default_tl_0x34, default_tl_0x35, default_tl_0x36, default_tl_0x37, default_tl_0x38, default_tl_0x39, default_tl_0x3A, default_tl_0x3B, default_tl_0x3C, default_tl_0x3D, default_tl_0x3E, default_tl_0x3F, default_tl_0x40, default_tl_0x41, default_tl_0x42, default_tl_0x43, default_tl_0x44, default_tl_0x45, default_tl_0x46, default_tl_0x47, default_tl_0x48, default_tl_0x49, default_tl_0x4A, default_tl_0x4B, default_tl_0x4C, default_tl_0x4D, default_tl_0x4E, default_tl_0x4F, default_tl_0x50, default_tl_0x51, default_tl_0x52, default_tl_0x53, default_tl_0x54, default_tl_0x55, default_tl_0x56, default_tl_0x57, default_tl_0x58, default_tl_0x59, default_tl_0x5A, default_tl_0x5B, default_tl_0x5C, default_tl_0x5D, default_tl_0x5E, default_tl_0x5F, default_tl_0x60, default_tl_0x61, default_tl_0x62, default_tl_0x63, default_tl_0x64, default_tl_0x65, default_tl_0x66, default_tl_0x67, default_tl_0x68, default_tl_0x69, default_tl_0x6A, default_tl_0x6B, default_tl_0x6C, default_tl_0x6D, default_tl_0x6E, default_tl_0x6F, default_tl_0x70, default_tl_0x71, default_tl_0x72, default_tl_0x73, default_tl_0x74, default_tl_0x75, default_tl_0x76, default_tl_0x77, default_tl_0x78, default_tl_0x79, default_tl_0x7A, default_tl_0x7B, default_tl_0x7C, default_tl_0x7D, default_tl_0x7E, default_tl_0x7F, default_tl_0x80, default_tl_0x81, default_tl_0x82, default_tl_0x83, default_tl_0x84, default_tl_0x85, default_tl_0x86, default_tl_0x87, default_tl_0x88, default_tl_0x89, default_tl_0x8A, default_tl_0x8B, default_tl_0x8C, default_tl_0x8D, default_tl_0x8E, default_tl_0x8F, default_tl_0x90, default_tl_0x91, default_tl_0x92, default_tl_0x93, default_tl_0x94, default_tl_0x95, default_tl_0x96, default_tl_0x97, default_tl_0x98, default_tl_0x99, default_tl_0x9A, default_tl_0x9B, default_tl_0x9C, default_tl_0x9D, default_tl_0x9E, default_tl_0x9F, default_tl_0xA0, default_tl_0xA1, default_tl_0xA2, default_tl_0xA3, default_tl_0xA4, default_tl_0xA5, default_tl_0xA6, default_tl_0xA7, default_tl_0xA8, default_tl_0xA9, default_tl_0xAA, default_tl_0xAB, default_tl_0xAC, default_tl_0xAD, default_tl_0xAE, default_tl_0xAF, default_tl_0xB0, default_tl_0xB1, default_tl_0xB2, default_tl_0xB3, default_tl_0xB4, default_tl_0xB5, default_tl_0xB6, default_tl_0xB7, default_tl_0xB8, default_tl_0xB9, default_tl_0xBA, default_tl_0xBB, default_tl_0xBC, default_tl_0xBD, default_tl_0xBE, default_tl_0xBF, default_tl_0xC0, default_tl_0xC1, default_tl_0xC2, default_tl_0xC3, default_tl_0xC4, default_tl_0xC5, default_tl_0xC6, default_tl_0xC7, default_tl_0xC8, default_tl_0xC9, default_tl_0xCA, default_tl_0xCB, default_tl_0xCC, default_tl_0xCD, default_tl_0xCE, default_tl_0xCF, default_tl_0xD0, default_tl_0xD1, default_tl_0xD2, default_tl_0xD3, default_tl_0xD4, default_tl_0xD5, default_tl_0xD6, default_tl_0xD7, default_tl_0xD8, default_tl_0xD9, default_tl_0xDA, default_tl_0xDB, default_tl_0xDC, default_tl_0xDD, default_tl_0xDE, default_tl_0xDF, default_tl_0xE0, default_tl_0xE1, default_tl_0xE2, default_tl_0xE3, default_tl_0xE4, default_tl_0xE5, default_tl_0xE6, default_tl_0xE7, default_tl_0xE8, default_tl_0xE9, default_tl_0xEA, default_tl_0xEB, default_tl_0xEC, default_tl_0xED, default_tl_0xEE, default_tl_0xEF, default_tl_0xF0, default_tl_0xF1, default_tl_0xF2, default_tl_0xF3, default_tl_0xF4, default_tl_0xF5, default_tl_0xF6, default_tl_0xF7, default_tl_0xF8, default_tl_0xF9, default_tl_0xFA, default_tl_0xFB, default_tl_0xFC, default_tl_0xFD, default_tl_0xFE, default_tl_0xFF,
 };
 
 // Layer <name> for ScanCode Lookup
-static unsigned int *myname_scanMap[] = {
+const unsigned int *myname_scanMap[] = {
 0, 0, 0, 0, myname_tl_0x05, myname_tl_0x06, myname_tl_0x07
 };
 
 // Layer <name> for ScanCode Lookup
-static unsigned int *myname2_scanMap[] = {
+const unsigned int *myname2_scanMap[] = {
 0, 0, 0, myname2_tl_0x04, myname2_tl_0x05, myname2_tl_0x06
 };
 
@@ -574,9 +580,9 @@ static unsigned int *myname2_scanMap[] = {
 // The name is defined for cli debugging purposes (Null terminated string)
 
 typedef struct Layer {
-       unsigned int **triggerMap;
-       char *name;
-       uint8_t max;
+       const unsigned int **triggerMap;
+       const char *name;
+       const uint8_t max;
        uint8_t state;
 } Layer;
 
index 38d918e56135eb64824362f977be98e6bb22f200..49d94953a58f7197c1da21c95351f6898bbc18ad 100644 (file)
@@ -39,6 +39,7 @@
 
 void cliFunc_capList   ( char* args );
 void cliFunc_capSelect ( char* args );
+void cliFunc_keyHold   ( char* args );
 void cliFunc_keyPress  ( char* args );
 void cliFunc_keyRelease( char* args );
 void cliFunc_layerList ( char* args );
@@ -80,12 +81,13 @@ typedef enum ResultMacroEval {
 // ----- Variables -----
 
 // Macro Module command dictionary
-char*       macroCLIDictName = "Macro Module Commands";
-CLIDictItem macroCLIDict[] = {
+const char macroCLIDictName[] = "Macro Module Commands";
+const CLIDictItem macroCLIDict[] = {
        { "capList",     "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
        { "capSelect",   "Triggers the specified capabilities. First two args are state and stateType." NL "\t\t\033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
-       { "keyPress",    "Send key-presses to the macro module. Held until released. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyPress },
-       { "keyRelease",  "Release a key-press from the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
+       { "keyHold",     "Send key-hold events to the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyHold },
+       { "keyPress",    "Send key-press events to the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyPress },
+       { "keyRelease",  "Send key-release event to macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
        { "layerList",   "List available layers.", cliFunc_layerList },
        { "layerState",  "Modify specified indexed layer state <layer> <state byte>." NL "\t\t\033[35mL2\033[0m Indexed Layer 0x02" NL "\t\t0 Off, 1 Shift, 2 Latch, 4 Lock States", cliFunc_layerState },
        { "macroDebug",  "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
@@ -146,7 +148,8 @@ void Macro_layerStateToggle_capability( uint8_t state, uint8_t stateType, uint8_
        }
 
        // Get layer index from arguments
-       unsigned int layer = (unsigned int)(&args[0]);
+       // Cast pointer to uint8_t to unsigned int then access that memory location
+       unsigned int layer = *(unsigned int*)(&args[0]);
 
        // Get layer toggle byte
        uint8_t toggleByte = args[ sizeof(unsigned int) ];
@@ -229,7 +232,7 @@ unsigned int *Macro_layerLookup( uint8_t scanCode )
                if ( (layer->state & 0x01) ^ (latch>>1) ^ ((layer->state & 0x04)>>2) )
                {
                        // Lookup layer
-                       unsigned int **map = layer->triggerMap;
+                       unsigned int **map = (unsigned int**)layer->triggerMap;
 
                        // Determine if layer has key defined
                        if ( map != 0 && *map[ scanCode ] != 0 )
@@ -238,7 +241,7 @@ unsigned int *Macro_layerLookup( uint8_t scanCode )
        }
 
        // Do lookup on default layer
-       unsigned int **map = LayerIndex[0].triggerMap;
+       unsigned int **map = (unsigned int**)LayerIndex[0].triggerMap;
 
        // Determine if layer has key defined
        if ( map == 0 && *map[ scanCode ] == 0 )
@@ -615,6 +618,7 @@ inline void Macro_process()
 
                // Proceed, decrementing the step counter
                macroStepCounter--;
+               dbug_print("Macro Step");
        }
 
        // Update pending trigger list, before processing TriggerMacros
@@ -713,7 +717,6 @@ inline void Macro_setup()
        // Initialize TriggerMacro states
        for ( unsigned int macro = 0; macro < TriggerMacroNum; macro++ )
        {
-               TriggerMacroList[ macro ].result = 0;
                TriggerMacroList[ macro ].pos    = 0;
                TriggerMacroList[ macro ].state  = TriggerMacro_Waiting;
        }
@@ -734,6 +737,7 @@ void cliFunc_capList( char* args )
 {
        print( NL );
        info_msg("Capabilities List");
+       printHex( CapabilitiesNum );
 
        // Iterate through all of the capabilities and display them
        for ( unsigned int cap = 0; cap < CapabilitiesNum; cap++ )
@@ -812,6 +816,34 @@ void cliFunc_capSelect( char* args )
        }
 }
 
+void cliFunc_keyHold( char* args )
+{
+       // Parse codes from arguments
+       char* curArgs;
+       char* arg1Ptr;
+       char* arg2Ptr = args;
+
+       // Process all args
+       for ( ;; )
+       {
+               curArgs = arg2Ptr;
+               CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
+
+               // Stop processing args if no more are found
+               if ( *arg1Ptr == '\0' )
+                       break;
+
+               // Ignore non-Scancode numbers
+               switch ( arg1Ptr[0] )
+               {
+               // Scancode
+               case 'S':
+                       Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode
+                       break;
+               }
+       }
+}
+
 void cliFunc_keyPress( char* args )
 {
        // Parse codes from arguments
@@ -881,7 +913,7 @@ void cliFunc_layerList( char* args )
                print(" - ");
 
                // Display layer name
-               dPrint( LayerIndex[ layer ].name );
+               dPrint( (char*)LayerIndex[ layer ].name );
 
                // Default map
                if ( layer == 0 )
@@ -956,6 +988,39 @@ void cliFunc_macroDebug( char* args )
 
 void cliFunc_macroList( char* args )
 {
+       // Show pending key events
+       print( NL );
+       info_msg("Pending Key Events: ");
+       printInt16( (uint16_t)macroTriggerListBufferSize );
+       print(" : ");
+       for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
+       {
+               printHex( macroTriggerListBuffer[ key ].scanCode );
+               print(" ");
+       }
+
+       // Show pending trigger macros
+       print( NL );
+       info_msg("Pending Trigger Macros: ");
+       printInt16( (uint16_t)macroTriggerMacroPendingListSize );
+       print(" : ");
+       for ( unsigned int macro = 0; macro < macroTriggerMacroPendingListSize; macro++ )
+       {
+               printHex( macroTriggerMacroPendingList[ macro ] );
+               print(" ");
+       }
+
+       // Show pending result macros
+       print( NL );
+       info_msg("Pending Result Macros: ");
+       printInt16( (uint16_t)macroResultMacroPendingListSize );
+       print(" : ");
+       for ( unsigned int macro = 0; macro < macroResultMacroPendingListSize; macro++ )
+       {
+               printHex( macroResultMacroPendingList[ macro ] );
+               print(" ");
+       }
+
        // Show available trigger macro indices
        print( NL );
        info_msg("Trigger Macros Range: T0 -> T");
@@ -1176,7 +1241,13 @@ void cliFunc_macroStep( char* args )
        char* arg2Ptr;
        CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
 
+       // Default to 1, if no argument given
+       unsigned int count = (unsigned int)decToInt( arg1Ptr );
+
+       if ( count == 0 )
+               count = 1;
+
        // Set the macro step counter, negative int's are cast to uint
-       macroStepCounter = (unsigned int)decToInt( arg1Ptr );
+       macroStepCounter = count;
 }
 
index 3b2d3a98e7dca758089932bc2bf19ba471ee9ed5..0ea7e9f53d5bf43a31483d1c86ba4540bc3bd389 100644 (file)
@@ -700,8 +700,7 @@ void usb_device_reload()
        }
        else
        {
-               // This line must be exactly the same in the bootloader
-               const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
+               // Copies variable into the VBAT register, must be identical to the variable in the bootloader to jump to the bootloader flash mode
                for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )(&VBAT)[pos] = sys_reset_to_loader_magic[ pos ];
                SOFTWARE_RESET();
        }
index 735dcbb1f0ed28ab14872a383386959267a6896e..020ada1b2a0afa23ac7095421b1384b159159637 100644 (file)
@@ -56,8 +56,8 @@ void cliFunc_setMod     ( char* args );
 // ----- Variables -----
 
 // Output Module command dictionary
-char*       outputCLIDictName = "USB Module Commands";
-CLIDictItem outputCLIDict[] = {
+const char outputCLIDictName[] = "USB Module Commands";
+const CLIDictItem outputCLIDict[] = {
        { "kbdProtocol", "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode", cliFunc_kbdProtocol },
        { "readLEDs",    "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc.", cliFunc_readLEDs },
        { "sendKeys",    "Send the prepared list of USB codes and modifier byte.", cliFunc_sendKeys },
index 2f1762f6f42b151967605a36d7deab1c1dd727a9..796af63e294faad71357d5d1c991d07c4aa9978e 100644 (file)
@@ -52,8 +52,8 @@ void cliFunc_setMod     ( char* args );
 // ----- Variables -----
 
 // Output Module command dictionary
-char*       outputCLIDictName = "USB Module Commands - NOT WORKING";
-CLIDictItem outputCLIDict[] = {
+const char outputCLIDictName[] = "USB Module Commands - NOT WORKING";
+const CLIDictItem outputCLIDict[] = {
        { "kbdProtocol", "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode", cliFunc_kbdProtocol },
        { "readLEDs",    "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc.", cliFunc_readLEDs },
        { "sendKeys",    "Send the prepared list of USB codes and modifier byte.", cliFunc_sendKeys },
index 86f5cf6b5a4c0258e26657b2e62804d04a992a51..5e664e1403f60c52be1d71d9215bb75851c1ee10 100644 (file)
@@ -57,8 +57,8 @@ void cliFunc_setMod     ( char* args );
 // ----- Variables -----
 
 // Output Module command dictionary
-char*       outputCLIDictName = "USB Module Commands - NOT WORKING";
-CLIDictItem outputCLIDict[] = {
+const char outputCLIDictName[] = "USB Module Commands - NOT WORKING";
+const CLIDictItem outputCLIDict[] = {
        { "kbdProtocol", "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode", cliFunc_kbdProtocol },
        { "readLEDs",    "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc.", cliFunc_readLEDs },
        { "readUART",    "Read UART buffer until empty.", cliFunc_readUART },
index fef476b374618478006a347775a220b2a610953e..6bc41a6edd041549b4df443968c14a57e72a87d6 100644 (file)
@@ -65,8 +65,8 @@ volatile uint8_t KeyIndex_BufferUsed;
 
 
 // Scan Module command dictionary
-char*       scanCLIDictName = "ADC Test Module Commands";
-CLIDictItem scanCLIDict[] = {
+char scanCLIDictName[] = "ADC Test Module Commands";
+const CLIDictItem scanCLIDict[] = {
 #if defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
        { "adc",     "Read the specified number of values from the ADC at the given pin: <pin> [# of reads]"
                  NL "\t\t See \033[35mLib/pin_map.teensy3\033[0m for ADC0 channel number.", cliFunc_adc },
index 69d5719aee862f5bb836a3c487423a04f3dc0a70..324c4c92b311bb2c653e3d7bf93e7a049e4f640b 100644 (file)
@@ -149,8 +149,8 @@ volatile uint8_t KeyIndex_BufferUsed;
 
 
 // Scan Module command dictionary
-char*       scanCLIDictName = "DPH Module Commands";
-CLIDictItem scanCLIDict[] = {
+const char scanCLIDictName[] = "DPH Module Commands";
+const CLIDictItem scanCLIDict[] = {
        { "echo",        "Example command, echos the arguments.", cliFunc_echo },
        { "avgDebug",    "Enables/Disables averaging results." NL "\t\tDisplays each average, starting from Key 0x00, ignoring 0 valued averages.", cliFunc_avgDebug },
        { "keyDebug",    "Enables/Disables long debug for each keypress." NL "\t\tkeycode - [strobe:mux] : sense val : threshold+delta=total : margin", cliFunc_keyDebug },
index 0d70dcac1d32ad6a268a77741849a93cd7d56d69..9d28055429794d2554344bfd315d8b42579d345b 100644 (file)
@@ -46,8 +46,8 @@ void cliFunc_echo( char* args );
 // ----- Variables -----
 
 // Scan Module command dictionary
-char*       scanCLIDictName = "Scan Module Commands";
-CLIDictItem scanCLIDict[] = {
+const char scanCLIDictName[] = "Scan Module Commands";
+const CLIDictItem scanCLIDict[] = {
        { "echo",        "Example command, echos the arguments.", cliFunc_echo },
        { 0, 0, 0 } // Null entry for dictionary end
 };
index e3b5429dd4139298d13ee5a27a2a1d4c412d574a..11ecba3511cac7d24dea9469c6d6612f09442904 100644 (file)
@@ -49,8 +49,8 @@ void cliFunc_matrixState( char* args );
 // ----- Variables -----
 
 // Scan Module command dictionary
-char*       matrixCLIDictName = "Matrix Module Commands";
-CLIDictItem matrixCLIDict[] = {
+const char matrixCLIDictName[] = "Matrix Module Commands";
+const CLIDictItem matrixCLIDict[] = {
        { "matrixDebug",  "Enables matrix debug mode, prints out each scan code." NL "\t\tIf argument \033[35mT\033[0m is given, prints out each scan code state transition.", cliFunc_matrixDebug },
        { "matrixState",  "Prints out the current scan table N times." NL "\t\t \033[1mO\033[0m - Off, \033[1;33mP\033[0m - Press, \033[1;32mH\033[0m - Hold, \033[1;35mR\033[0m - Release, \033[1;31mI\033[0m - Invalid", cliFunc_matrixState },
        { 0, 0, 0 } // Null entry for dictionary end