Preparing for mk20dx256vlh7
- Not ready yet - Will require some more changes to Lib/mk20dx.c
This commit is contained in:
parent
40b5665930
commit
f5a1e1bcf5
@ -21,6 +21,7 @@
|
||||
#|
|
||||
set( CHIP
|
||||
"mk20dx128vlf5" # McHCK mk20dx128vlf5
|
||||
# "mk20dx256vlh7" # Kiibohd-dfu
|
||||
)
|
||||
|
||||
|
||||
|
@ -25,7 +25,9 @@ set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- )
|
||||
|
||||
#| Chip Name (Linker)
|
||||
#|
|
||||
#| "mk20dx128" # Teensy 3.0 and McHCK mk20dx128
|
||||
#| "mk20dx128vlf5" # McHCK / Kiibohd-dfu
|
||||
#| "mk20dx256vlh7" # Kiibohd-dfu
|
||||
#| "mk20dx128" # Teensy 3.0
|
||||
#| "mk20dx256" # Teensy 3.1
|
||||
|
||||
message( STATUS "Chip Selected:" )
|
||||
@ -34,11 +36,16 @@ set( MCU "${CHIP}" ) # For loading script compatibility
|
||||
|
||||
|
||||
#| Chip Size Database
|
||||
#| MCHCK Based
|
||||
#| MCHCK Based / Kiibohd-dfu
|
||||
if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
|
||||
set( SIZE_RAM 16384 )
|
||||
set( SIZE_FLASH 126976 )
|
||||
|
||||
#| Kiibohd-dfu
|
||||
elseif ( "${CHIP}" MATCHES "mk20dx256vlh7" )
|
||||
set( SIZE_RAM 65536 )
|
||||
set( SIZE_FLASH 253952 )
|
||||
|
||||
#| Teensy 3.0
|
||||
elseif ( "${CHIP}" MATCHES "mk20dx128" )
|
||||
set( SIZE_RAM 16384 )
|
||||
@ -90,7 +97,7 @@ message( "${COMPILER_SRCS}" )
|
||||
|
||||
#| USB Defines, this is how the loader programs detect which type of chip base is used
|
||||
message( STATUS "Bootloader Type:" )
|
||||
if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
|
||||
if ( "${CHIP}" MATCHES "mk20dx128vlf5" OR "${CHIP}" MATCHES "mk20dx256vlh7" )
|
||||
set( VENDOR_ID "0x1C11" )
|
||||
set( PRODUCT_ID "0xB04D" )
|
||||
set( BOOT_VENDOR_ID "0x1C11" )
|
||||
|
@ -29,7 +29,7 @@
|
||||
#define __INTERRUPTS_H
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
#include <Lib/mk20dx.h>
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
// ----- Defines -----
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
// Map the Interrupt Enable/Disable to the AVR names
|
||||
#define cli() __disable_irq()
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
#include <Lib/mk20dx.h>
|
||||
#include <Lib/delay.h>
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
#include <Lib/mk20dx.h>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
// ----- Includes -----
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
#include <Lib/mk20dx.h>
|
||||
#include <Lib/delay.h>
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
// ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
|
||||
#include <Lib/mk20dx.h>
|
||||
#include <Lib/delay.h>
|
||||
|
21
Lib/mk20dx.c
21
Lib/mk20dx.c
@ -377,6 +377,27 @@ const uint8_t flashconfigbytes[16] = {
|
||||
0xFF, // EEPROM Protection Byte FEPROT
|
||||
0xFF, // Data Flash Protection Byte FDPROT
|
||||
};
|
||||
#elif defined(_mk20dx256vlh7_) && 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
|
||||
|
||||
//
|
||||
// Protecting the first 8k of Flash memory from being over-written while running (bootloader protection)
|
||||
// Still possible to overwrite the bootloader using an external flashing device
|
||||
// For more details see:
|
||||
// http://cache.freescale.com/files/training/doc/dwf/AMF_ENT_T1031_Boston.pdf (page 8)
|
||||
// http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf
|
||||
// http://cache.freescale.com/files/32bit/doc/ref_manual/K20P64M72SF1RM.pdf (28.34.6)
|
||||
//
|
||||
0xFF, 0xFF, 0xFF, 0xFE, // 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
|
||||
|
||||
|
||||
|
@ -1847,7 +1847,7 @@ typedef struct {
|
||||
#define IRQ_SOFTWARE 45
|
||||
#define NVIC_NUM_INTERRUPTS 46
|
||||
|
||||
#elif defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
#define IRQ_DMA_CH0 0
|
||||
#define IRQ_DMA_CH1 1
|
||||
#define IRQ_DMA_CH2 2
|
||||
|
114
Lib/mk20dx256vlh7.bootloader.ld
Normal file
114
Lib/mk20dx256vlh7.bootloader.ld
Normal file
@ -0,0 +1,114 @@
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2013 PJRC.COM, LLC.
|
||||
* Modifications by Jacob Alexander 2014 for use with McHCK and Kiibohd-dfu
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* XXX Not tested yet -HaaTa */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x0, LENGTH = 256K
|
||||
FLASH_APP (rx) : ORIGIN = 8K, LENGTH = 256K-8K
|
||||
RAM (rwx) : ORIGIN = 0x20000000 - 64K / 2, LENGTH = 64K
|
||||
}
|
||||
|
||||
/* Starting Address of the application ROM */
|
||||
_app_rom = ORIGIN( FLASH_APP );
|
||||
|
||||
FlexRAM = 0x14000000;
|
||||
FTFL = 0x40020000;
|
||||
SCB = 0xe000ed00;
|
||||
USB0 = 0x40072000;
|
||||
SIM = 0x40047000;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = 0;
|
||||
KEEP(* (.vectors))
|
||||
*(.startup*)
|
||||
*(.rodata*)
|
||||
. = 0x400;
|
||||
KEEP(* (.flashconfig))
|
||||
*(.text*)
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
} > FLASH
|
||||
|
||||
.ARM.exidx :
|
||||
{
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
__exidx_end = .;
|
||||
} > FLASH
|
||||
_etext = .;
|
||||
|
||||
.usbdescriptortable (NOLOAD) : {
|
||||
. = ALIGN(512);
|
||||
*(.usbdescriptortable*)
|
||||
} > RAM
|
||||
|
||||
.dmabuffers (NOLOAD) : {
|
||||
. = ALIGN(4);
|
||||
*(.dmabuffers*)
|
||||
} > RAM
|
||||
|
||||
.usbbuffers (NOLOAD) : {
|
||||
. = ALIGN(4);
|
||||
*(.usbbuffers*)
|
||||
} > RAM
|
||||
|
||||
.data : AT (_etext) {
|
||||
. = ALIGN(4);
|
||||
_sdata = .;
|
||||
*(SORT_BY_ALIGNMENT(.ramtext.*) SORT_BY_ALIGNMENT(.data*))
|
||||
*(.data*)
|
||||
. = ALIGN(4);
|
||||
_edata = .;
|
||||
} > RAM
|
||||
|
||||
.noinit (NOLOAD) : {
|
||||
*(.noinit*)
|
||||
} > RAM
|
||||
|
||||
.bss : {
|
||||
. = ALIGN(4);
|
||||
_sbss = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = .;
|
||||
__bss_end = .;
|
||||
} > RAM
|
||||
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
}
|
||||
|
101
Lib/mk20dx256vlh7.ld
Normal file
101
Lib/mk20dx256vlh7.ld
Normal file
@ -0,0 +1,101 @@
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2013 PJRC.COM, LLC.
|
||||
* Modifications by Jacob Alexander 2014 for use with McHCK and Kiibohd-dfu
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* XXX Not tested yet -HaaTa */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 8K, LENGTH = 256K-8K
|
||||
RAM (rwx) : ORIGIN = 0x20000000 - 64K / 2, LENGTH = 64K
|
||||
}
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = 0;
|
||||
KEEP(* (.vectors))
|
||||
*(.startup*)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
} > FLASH
|
||||
|
||||
.ARM.exidx :
|
||||
{
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
__exidx_end = .;
|
||||
} > FLASH
|
||||
_etext = .;
|
||||
|
||||
.usbdescriptortable (NOLOAD) : {
|
||||
. = ALIGN(512);
|
||||
*(.usbdescriptortable*)
|
||||
} > RAM
|
||||
|
||||
.dmabuffers (NOLOAD) : {
|
||||
. = ALIGN(4);
|
||||
*(.dmabuffers*)
|
||||
} > RAM
|
||||
|
||||
.usbbuffers (NOLOAD) : {
|
||||
. = ALIGN(4);
|
||||
*(.usbbuffers*)
|
||||
} > RAM
|
||||
|
||||
.data : AT (_etext) {
|
||||
. = ALIGN(4);
|
||||
_sdata = .;
|
||||
*(.data*)
|
||||
. = ALIGN(4);
|
||||
_edata = .;
|
||||
} > RAM
|
||||
|
||||
.noinit (NOLOAD) : {
|
||||
*(.noinit*)
|
||||
} > RAM
|
||||
|
||||
.bss : {
|
||||
. = ALIGN(4);
|
||||
_sbss = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = .;
|
||||
__bss_end = .;
|
||||
} > RAM
|
||||
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ typedef uint8_t var_uint_t;
|
||||
// This needs to be defined per microcontroller
|
||||
// e.g. mk20s -> 32 bit
|
||||
// atmega -> 16 bit
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
typedef uint32_t nat_ptr_t;
|
||||
#elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
typedef uint16_t nat_ptr_t;
|
||||
|
@ -33,7 +33,7 @@
|
||||
// USB Includes
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
|
||||
#include "avr/usb_keyboard_serial.h"
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
#include "arm/usb_dev.h"
|
||||
#include "arm/usb_keyboard.h"
|
||||
#include "arm/usb_serial.h"
|
||||
@ -549,7 +549,7 @@ inline int Output_putstr( char* str )
|
||||
{
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
uint16_t count = 0;
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
uint32_t count = 0;
|
||||
#endif
|
||||
// Count characters until NULL character, then send the amount counted
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
// USB Includes
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
#include "arm/uart_serial.h"
|
||||
#endif
|
||||
|
||||
@ -180,7 +180,7 @@ inline int Output_putstr( char* str )
|
||||
{
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
uint16_t count = 0;
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
uint32_t count = 0;
|
||||
#endif
|
||||
// Count characters until NULL character, then send the amount counted
|
||||
@ -195,7 +195,7 @@ inline int Output_putstr( char* str )
|
||||
inline void Output_softReset()
|
||||
{
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
SOFTWARE_RESET();
|
||||
#endif
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
// USB Includes
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
#include "../uartOut/arm/uart_serial.h"
|
||||
#include "../pjrcUSB/arm/usb_dev.h"
|
||||
#include "../pjrcUSB/arm/usb_keyboard.h"
|
||||
@ -468,7 +468,7 @@ inline int Output_putstr( char* str )
|
||||
{
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
uint16_t count = 0;
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
uint32_t count = 0;
|
||||
#endif
|
||||
// Count characters until NULL character, then send the amount counted
|
||||
|
@ -62,28 +62,28 @@ void analog_init(void)
|
||||
if (analog_config_bits == 8) {
|
||||
ADC0_CFG1 = ADC_CFG1_24MHZ + ADC_CFG1_MODE(0);
|
||||
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_CFG1 = ADC_CFG1_24MHZ + ADC_CFG1_MODE(0);
|
||||
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
|
||||
#endif
|
||||
} else if (analog_config_bits == 10) {
|
||||
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(2) + ADC_CFG1_ADLSMP;
|
||||
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(2) + ADC_CFG1_ADLSMP;
|
||||
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
|
||||
#endif
|
||||
} else if (analog_config_bits == 12) {
|
||||
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(1) + ADC_CFG1_ADLSMP;
|
||||
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(1) + ADC_CFG1_ADLSMP;
|
||||
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
|
||||
#endif
|
||||
} else {
|
||||
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(3) + ADC_CFG1_ADLSMP;
|
||||
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(3) + ADC_CFG1_ADLSMP;
|
||||
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
|
||||
#endif
|
||||
@ -91,12 +91,12 @@ void analog_init(void)
|
||||
|
||||
if (analog_reference_internal) {
|
||||
ADC0_SC2 = ADC_SC2_REFSEL(1); // 1.2V ref
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC2 = ADC_SC2_REFSEL(1); // 1.2V ref
|
||||
#endif
|
||||
} else {
|
||||
ADC0_SC2 = ADC_SC2_REFSEL(0); // vcc/ext ref
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC2 = ADC_SC2_REFSEL(0); // vcc/ext ref
|
||||
#endif
|
||||
}
|
||||
@ -104,27 +104,27 @@ void analog_init(void)
|
||||
num = analog_num_average;
|
||||
if (num <= 1) {
|
||||
ADC0_SC3 = ADC_SC3_CAL; // begin cal
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = ADC_SC3_CAL; // begin cal
|
||||
#endif
|
||||
} else if (num <= 4) {
|
||||
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(0);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(0);
|
||||
#endif
|
||||
} else if (num <= 8) {
|
||||
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(1);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(1);
|
||||
#endif
|
||||
} else if (num <= 16) {
|
||||
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(2);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(2);
|
||||
#endif
|
||||
} else {
|
||||
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(3);
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(3);
|
||||
#endif
|
||||
}
|
||||
@ -140,7 +140,7 @@ static void wait_for_cal(void)
|
||||
while (ADC0_SC3 & ADC_SC3_CAL) {
|
||||
// wait
|
||||
}
|
||||
#elif defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
while ((ADC0_SC3 & ADC_SC3_CAL) || (ADC1_SC3 & ADC_SC3_CAL)) {
|
||||
// wait
|
||||
}
|
||||
@ -160,7 +160,7 @@ static void wait_for_cal(void)
|
||||
//serial_print("ADC0_MG = ");
|
||||
//serial_phex16(sum);
|
||||
//serial_print("\n");
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
sum = ADC1_CLPS + ADC1_CLP4 + ADC1_CLP3 + ADC1_CLP2 + ADC1_CLP1 + ADC1_CLP0;
|
||||
sum = (sum / 2) | 0x8000;
|
||||
ADC1_PG = sum;
|
||||
@ -192,7 +192,7 @@ void analogReference(uint8_t type)
|
||||
analog_reference_internal = 1;
|
||||
if (calibrating) {
|
||||
ADC0_SC3 = 0; // cancel cal
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = 0; // cancel cal
|
||||
#endif
|
||||
}
|
||||
@ -204,7 +204,7 @@ void analogReference(uint8_t type)
|
||||
analog_reference_internal = 0;
|
||||
if (calibrating) {
|
||||
ADC0_SC3 = 0; // cancel cal
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
ADC1_SC3 = 0; // cancel cal
|
||||
#endif
|
||||
}
|
||||
@ -266,7 +266,7 @@ static const uint8_t channel2sc1a[] = {
|
||||
5, 14, 8, 9, 13, 12, 6, 7, 15, 4,
|
||||
0, 19, 3, 21, 26, 22, 23
|
||||
};
|
||||
#elif defined(_mk20dx256_)
|
||||
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
static const uint8_t channel2sc1a[] = {
|
||||
5, 14, 8, 9, 13, 12, 6, 7, 15, 4,
|
||||
0, 19, 3, 19+128, 26, 22, 23,
|
||||
@ -284,7 +284,7 @@ static const uint8_t channel2sc1a[] = {
|
||||
|
||||
// TODO: perhaps this should store the NVIC priority, so it works recursively?
|
||||
static volatile uint8_t analogReadBusyADC0 = 0;
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
static volatile uint8_t analogReadBusyADC1 = 0;
|
||||
#endif
|
||||
|
||||
@ -300,7 +300,7 @@ int analogRead(uint8_t pin)
|
||||
index = pin; // 0-13 refer to A0-A13
|
||||
} else if (pin <= 23) {
|
||||
index = pin - 14; // 14-23 are A0-A9
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
} else if (pin >= 26 && pin <= 31) {
|
||||
index = pin - 9; // 26-31 are A15-A20
|
||||
#endif
|
||||
@ -323,7 +323,7 @@ int analogRead(uint8_t pin)
|
||||
if (calibrating) wait_for_cal();
|
||||
//pin = 5; // PTD1/SE5b, pin 14, analog 0
|
||||
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
if (channel & 0x80) goto beginADC1;
|
||||
#endif
|
||||
|
||||
@ -350,7 +350,7 @@ startADC0:
|
||||
yield();
|
||||
}
|
||||
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
beginADC1:
|
||||
__disable_irq();
|
||||
startADC1:
|
||||
@ -387,7 +387,7 @@ startADC1:
|
||||
|
||||
void analogWriteDAC0(int val)
|
||||
{
|
||||
#if defined(_mk20dx256_)
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC0;
|
||||
if (analog_reference_internal) {
|
||||
DAC0_C0 = DAC_C0_DACEN; // 1.2V ref is DACREF_1
|
||||
|
@ -67,7 +67,7 @@ volatile uint8_t KeyIndex_BufferUsed;
|
||||
// Scan Module command dictionary
|
||||
char scanCLIDictName[] = "ADC Test Module Commands";
|
||||
const CLIDictItem scanCLIDict[] = {
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
#if defined(_mk20dx128_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // 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 },
|
||||
{ "adcInit", "Intialize/calibrate ADC: <ADC Resolution> <Vref> <Hardware averaging samples>"
|
||||
@ -75,7 +75,7 @@ const CLIDictItem scanCLIDict[] = {
|
||||
NL "\t\t Vref -> 0 (1.2 V), 1 (External)"
|
||||
NL "\t\tHw Avg Samples -> 0 (disabled), 4, 8, 16, 32", cliFunc_adcInit },
|
||||
#endif
|
||||
#if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // DAC is only supported on Teensy 3.1
|
||||
{ "dac", "Set DAC output value, from 0 to 4095 (1/4096 Vref to Vref).", cliFunc_dac },
|
||||
{ "dacVref", "Set DAC Vref. 0 is 1.2V. 1 is 3.3V.", cliFunc_dacVref },
|
||||
#endif
|
||||
@ -94,7 +94,7 @@ inline void Scan_setup()
|
||||
// Register Scan CLI dictionary
|
||||
CLI_registerDictionary( scanCLIDict, scanCLIDictName );
|
||||
}
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
{
|
||||
// Register Scan CLI dictionary
|
||||
CLI_registerDictionary( scanCLIDict, scanCLIDictName );
|
||||
@ -103,7 +103,7 @@ inline void Scan_setup()
|
||||
VREF_TRM = 0x60;
|
||||
VREF_SC = 0xE1; // Enable 1.2V Vref
|
||||
|
||||
#if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // DAC is only supported on Teensy 3.1
|
||||
// DAC Setup
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC0;
|
||||
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
|
||||
@ -167,7 +167,7 @@ void cliFunc_adc( char* args )
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
{
|
||||
}
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
{
|
||||
// Parse code from argument
|
||||
// NOTE: Only first argument is used
|
||||
@ -220,7 +220,7 @@ void cliFunc_adcInit( char* args )
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
{
|
||||
}
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
|
||||
{
|
||||
// Parse code from argument
|
||||
// NOTE: Only first argument is used
|
||||
@ -335,7 +335,7 @@ void cliFunc_adcInit( char* args )
|
||||
|
||||
void cliFunc_dac( char* args )
|
||||
{
|
||||
#if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // DAC is only supported on Teensy 3.1
|
||||
// Parse code from argument
|
||||
// NOTE: Only first argument is used
|
||||
char* arg1Ptr;
|
||||
@ -354,7 +354,7 @@ void cliFunc_dac( char* args )
|
||||
|
||||
void cliFunc_dacVref( char* args )
|
||||
{
|
||||
#if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
|
||||
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // DAC is only supported on Teensy 3.1
|
||||
// Parse code from argument
|
||||
// NOTE: Only first argument is used
|
||||
char* arg1Ptr;
|
||||
|
@ -61,7 +61,7 @@ void removeKeyValue( uint8_t keyValue );
|
||||
// UART Receive Buffer Full Interrupt
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
ISR(USART1_RX_vect)
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
void uart0_status_isr(void)
|
||||
#endif
|
||||
{
|
||||
@ -72,7 +72,7 @@ void uart0_status_isr(void)
|
||||
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
keyValue = UDR1;
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
// UART0_S1 must be read for the interrupt to be cleared
|
||||
if ( UART0_S1 & UART_S1_RDRF )
|
||||
{
|
||||
@ -129,7 +129,7 @@ inline void Scan_setup()
|
||||
// Reset the keyboard before scanning, we might be in a wierd state
|
||||
Scan_resetKeyboard();
|
||||
}
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
{
|
||||
// Setup the the UART interface for keyboard data input
|
||||
SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating
|
||||
@ -345,7 +345,7 @@ uint8_t Scan_sendData( uint8_t dataPayload )
|
||||
|
||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
|
||||
UDR1 = dataPayload;
|
||||
#elif defined(_mk20dx128_) // ARM
|
||||
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
|
||||
UART0_D = dataPayload;
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user