Bladeren bron

Preparing for mk20dx256vlh7

- Not ready yet
- Will require some more changes to Lib/mk20dx.c
simple
Jacob Alexander 9 jaren geleden
bovenliggende
commit
f5a1e1bcf5

+ 1
- 0
Bootloader/CMakeLists.txt Bestand weergeven

#| #|
set( CHIP set( CHIP
"mk20dx128vlf5" # McHCK mk20dx128vlf5 "mk20dx128vlf5" # McHCK mk20dx128vlf5
# "mk20dx256vlh7" # Kiibohd-dfu
) )





+ 10
- 3
Lib/CMake/arm.cmake Bestand weergeven



#| Chip Name (Linker) #| 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 #| "mk20dx256" # Teensy 3.1


message( STATUS "Chip Selected:" ) message( STATUS "Chip Selected:" )




#| Chip Size Database #| Chip Size Database
#| MCHCK Based
#| MCHCK Based / Kiibohd-dfu
if ( "${CHIP}" MATCHES "mk20dx128vlf5" ) if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
set( SIZE_RAM 16384 ) set( SIZE_RAM 16384 )
set( SIZE_FLASH 126976 ) set( SIZE_FLASH 126976 )


#| Kiibohd-dfu
elseif ( "${CHIP}" MATCHES "mk20dx256vlh7" )
set( SIZE_RAM 65536 )
set( SIZE_FLASH 253952 )

#| Teensy 3.0 #| Teensy 3.0
elseif ( "${CHIP}" MATCHES "mk20dx128" ) elseif ( "${CHIP}" MATCHES "mk20dx128" )
set( SIZE_RAM 16384 ) set( SIZE_RAM 16384 )


#| USB Defines, this is how the loader programs detect which type of chip base is used #| USB Defines, this is how the loader programs detect which type of chip base is used
message( STATUS "Bootloader Type:" ) message( STATUS "Bootloader Type:" )
if ( "${CHIP}" MATCHES "mk20dx128vlf5" )
if ( "${CHIP}" MATCHES "mk20dx128vlf5" OR "${CHIP}" MATCHES "mk20dx256vlh7" )
set( VENDOR_ID "0x1C11" ) set( VENDOR_ID "0x1C11" )
set( PRODUCT_ID "0xB04D" ) set( PRODUCT_ID "0xB04D" )
set( BOOT_VENDOR_ID "0x1C11" ) set( BOOT_VENDOR_ID "0x1C11" )

+ 2
- 2
Lib/Interrupts.h Bestand weergeven

#define __INTERRUPTS_H #define __INTERRUPTS_H


// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)


#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>


// ----- Defines ----- // ----- Defines -----


// ARM // 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 // Map the Interrupt Enable/Disable to the AVR names
#define cli() __disable_irq() #define cli() __disable_irq()

+ 1
- 1
Lib/MacroLib.h Bestand weergeven





// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)


#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

+ 1
- 1
Lib/MainLib.h Bestand weergeven





// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)


#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>



+ 1
- 1
Lib/OutputLib.h Bestand weergeven

// ----- Includes ----- // ----- Includes -----


// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)


#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

+ 1
- 1
Lib/ScanLib.h Bestand weergeven





// ARM // ARM
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)


#include <Lib/mk20dx.h> #include <Lib/mk20dx.h>
#include <Lib/delay.h> #include <Lib/delay.h>

+ 21
- 0
Lib/mk20dx.c Bestand weergeven

0xFF, // EEPROM Protection Byte FEPROT 0xFF, // EEPROM Protection Byte FEPROT
0xFF, // Data Flash Protection Byte FDPROT 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 #endif





+ 1
- 1
Lib/mk20dx.h Bestand weergeven

#define IRQ_SOFTWARE 45 #define IRQ_SOFTWARE 45
#define NVIC_NUM_INTERRUPTS 46 #define NVIC_NUM_INTERRUPTS 46


#elif defined(_mk20dx256_)
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
#define IRQ_DMA_CH0 0 #define IRQ_DMA_CH0 0
#define IRQ_DMA_CH1 1 #define IRQ_DMA_CH1 1
#define IRQ_DMA_CH2 2 #define IRQ_DMA_CH2 2

+ 114
- 0
Lib/mk20dx256vlh7.bootloader.ld Bestand weergeven

/* 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
- 0
Lib/mk20dx256vlh7.ld Bestand weergeven

/* 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);
}


+ 1
- 1
Macro/PartialMap/kll.h Bestand weergeven

// This needs to be defined per microcontroller // This needs to be defined per microcontroller
// e.g. mk20s -> 32 bit // e.g. mk20s -> 32 bit
// atmega -> 16 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; typedef uint32_t nat_ptr_t;
#elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
typedef uint16_t nat_ptr_t; typedef uint16_t nat_ptr_t;

+ 2
- 2
Output/pjrcUSB/output_com.c Bestand weergeven

// USB Includes // USB Includes
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
#include "avr/usb_keyboard_serial.h" #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_dev.h"
#include "arm/usb_keyboard.h" #include "arm/usb_keyboard.h"
#include "arm/usb_serial.h" #include "arm/usb_serial.h"
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
uint16_t count = 0; 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; uint32_t count = 0;
#endif #endif
// Count characters until NULL character, then send the amount counted // Count characters until NULL character, then send the amount counted

+ 3
- 3
Output/uartOut/output_com.c Bestand weergeven



// USB Includes // USB Includes
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #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" #include "arm/uart_serial.h"
#endif #endif


{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
uint16_t count = 0; 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; uint32_t count = 0;
#endif #endif
// Count characters until NULL character, then send the amount counted // Count characters until NULL character, then send the amount counted
inline void Output_softReset() inline void Output_softReset()
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #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(); SOFTWARE_RESET();
#endif #endif
} }

+ 2
- 2
Output/usbMuxUart/output_com.c Bestand weergeven



// USB Includes // USB Includes
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) #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 "../uartOut/arm/uart_serial.h"
#include "../pjrcUSB/arm/usb_dev.h" #include "../pjrcUSB/arm/usb_dev.h"
#include "../pjrcUSB/arm/usb_keyboard.h" #include "../pjrcUSB/arm/usb_keyboard.h"
{ {
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
uint16_t count = 0; 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; uint32_t count = 0;
#endif #endif
// Count characters until NULL character, then send the amount counted // Count characters until NULL character, then send the amount counted

+ 21
- 21
Scan/ADCTest/analog.c Bestand weergeven

if (analog_config_bits == 8) { if (analog_config_bits == 8) {
ADC0_CFG1 = ADC_CFG1_24MHZ + ADC_CFG1_MODE(0); ADC0_CFG1 = ADC_CFG1_24MHZ + ADC_CFG1_MODE(0);
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3); 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_CFG1 = ADC_CFG1_24MHZ + ADC_CFG1_MODE(0);
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3); ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
#endif #endif
} else if (analog_config_bits == 10) { } else if (analog_config_bits == 10) {
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(2) + ADC_CFG1_ADLSMP; ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(2) + ADC_CFG1_ADLSMP;
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3); 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_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(2) + ADC_CFG1_ADLSMP;
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3); ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(3);
#endif #endif
} else if (analog_config_bits == 12) { } else if (analog_config_bits == 12) {
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(1) + ADC_CFG1_ADLSMP; ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(1) + ADC_CFG1_ADLSMP;
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2); 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_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(1) + ADC_CFG1_ADLSMP;
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2); ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
#endif #endif
} else { } else {
ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(3) + ADC_CFG1_ADLSMP; ADC0_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(3) + ADC_CFG1_ADLSMP;
ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2); 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_CFG1 = ADC_CFG1_12MHZ + ADC_CFG1_MODE(3) + ADC_CFG1_ADLSMP;
ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2); ADC1_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(2);
#endif #endif


if (analog_reference_internal) { if (analog_reference_internal) {
ADC0_SC2 = ADC_SC2_REFSEL(1); // 1.2V ref 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 ADC1_SC2 = ADC_SC2_REFSEL(1); // 1.2V ref
#endif #endif
} else { } else {
ADC0_SC2 = ADC_SC2_REFSEL(0); // vcc/ext ref 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 ADC1_SC2 = ADC_SC2_REFSEL(0); // vcc/ext ref
#endif #endif
} }
num = analog_num_average; num = analog_num_average;
if (num <= 1) { if (num <= 1) {
ADC0_SC3 = ADC_SC3_CAL; // begin cal ADC0_SC3 = ADC_SC3_CAL; // begin cal
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
ADC1_SC3 = ADC_SC3_CAL; // begin cal ADC1_SC3 = ADC_SC3_CAL; // begin cal
#endif #endif
} else if (num <= 4) { } else if (num <= 4) {
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(0); 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); ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(0);
#endif #endif
} else if (num <= 8) { } else if (num <= 8) {
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(1); 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); ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(1);
#endif #endif
} else if (num <= 16) { } else if (num <= 16) {
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(2); 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); ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(2);
#endif #endif
} else { } else {
ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(3); 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); ADC1_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(3);
#endif #endif
} }
while (ADC0_SC3 & ADC_SC3_CAL) { while (ADC0_SC3 & ADC_SC3_CAL) {
// wait // wait
} }
#elif defined(_mk20dx256_)
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
while ((ADC0_SC3 & ADC_SC3_CAL) || (ADC1_SC3 & ADC_SC3_CAL)) { while ((ADC0_SC3 & ADC_SC3_CAL) || (ADC1_SC3 & ADC_SC3_CAL)) {
// wait // wait
} }
//serial_print("ADC0_MG = "); //serial_print("ADC0_MG = ");
//serial_phex16(sum); //serial_phex16(sum);
//serial_print("\n"); //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 = ADC1_CLPS + ADC1_CLP4 + ADC1_CLP3 + ADC1_CLP2 + ADC1_CLP1 + ADC1_CLP0;
sum = (sum / 2) | 0x8000; sum = (sum / 2) | 0x8000;
ADC1_PG = sum; ADC1_PG = sum;
analog_reference_internal = 1; analog_reference_internal = 1;
if (calibrating) { if (calibrating) {
ADC0_SC3 = 0; // cancel cal ADC0_SC3 = 0; // cancel cal
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
ADC1_SC3 = 0; // cancel cal ADC1_SC3 = 0; // cancel cal
#endif #endif
} }
analog_reference_internal = 0; analog_reference_internal = 0;
if (calibrating) { if (calibrating) {
ADC0_SC3 = 0; // cancel cal ADC0_SC3 = 0; // cancel cal
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
ADC1_SC3 = 0; // cancel cal ADC1_SC3 = 0; // cancel cal
#endif #endif
} }
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 5, 14, 8, 9, 13, 12, 6, 7, 15, 4,
0, 19, 3, 21, 26, 22, 23 0, 19, 3, 21, 26, 22, 23
}; };
#elif defined(_mk20dx256_)
#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
static const uint8_t channel2sc1a[] = { static const uint8_t channel2sc1a[] = {
5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 5, 14, 8, 9, 13, 12, 6, 7, 15, 4,
0, 19, 3, 19+128, 26, 22, 23, 0, 19, 3, 19+128, 26, 22, 23,


// TODO: perhaps this should store the NVIC priority, so it works recursively? // TODO: perhaps this should store the NVIC priority, so it works recursively?
static volatile uint8_t analogReadBusyADC0 = 0; static volatile uint8_t analogReadBusyADC0 = 0;
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
static volatile uint8_t analogReadBusyADC1 = 0; static volatile uint8_t analogReadBusyADC1 = 0;
#endif #endif


index = pin; // 0-13 refer to A0-A13 index = pin; // 0-13 refer to A0-A13
} else if (pin <= 23) { } else if (pin <= 23) {
index = pin - 14; // 14-23 are A0-A9 index = pin - 14; // 14-23 are A0-A9
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
} else if (pin >= 26 && pin <= 31) { } else if (pin >= 26 && pin <= 31) {
index = pin - 9; // 26-31 are A15-A20 index = pin - 9; // 26-31 are A15-A20
#endif #endif
if (calibrating) wait_for_cal(); if (calibrating) wait_for_cal();
//pin = 5; // PTD1/SE5b, pin 14, analog 0 //pin = 5; // PTD1/SE5b, pin 14, analog 0


#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
if (channel & 0x80) goto beginADC1; if (channel & 0x80) goto beginADC1;
#endif #endif


yield(); yield();
} }


#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
beginADC1: beginADC1:
__disable_irq(); __disable_irq();
startADC1: startADC1:


void analogWriteDAC0(int val) void analogWriteDAC0(int val)
{ {
#if defined(_mk20dx256_)
#if defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
SIM_SCGC2 |= SIM_SCGC2_DAC0; SIM_SCGC2 |= SIM_SCGC2_DAC0;
if (analog_reference_internal) { if (analog_reference_internal) {
DAC0_C0 = DAC_C0_DACEN; // 1.2V ref is DACREF_1 DAC0_C0 = DAC_C0_DACEN; // 1.2V ref is DACREF_1

+ 8
- 8
Scan/ADCTest/scan_loop.c Bestand weergeven

// Scan Module command dictionary // Scan Module command dictionary
char scanCLIDictName[] = "ADC Test Module Commands"; char scanCLIDictName[] = "ADC Test Module Commands";
const CLIDictItem scanCLIDict[] = { 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]" { "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 }, 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>" { "adcInit", "Intialize/calibrate ADC: <ADC Resolution> <Vref> <Hardware averaging samples>"
NL "\t\t Vref -> 0 (1.2 V), 1 (External)" NL "\t\t Vref -> 0 (1.2 V), 1 (External)"
NL "\t\tHw Avg Samples -> 0 (disabled), 4, 8, 16, 32", cliFunc_adcInit }, NL "\t\tHw Avg Samples -> 0 (disabled), 4, 8, 16, 32", cliFunc_adcInit },
#endif #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 }, { "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 }, { "dacVref", "Set DAC Vref. 0 is 1.2V. 1 is 3.3V.", cliFunc_dacVref },
#endif #endif
// Register Scan CLI dictionary // Register Scan CLI dictionary
CLI_registerDictionary( scanCLIDict, scanCLIDictName ); CLI_registerDictionary( scanCLIDict, scanCLIDictName );
} }
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
#elif defined(_mk20dx128_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
{ {
// Register Scan CLI dictionary // Register Scan CLI dictionary
CLI_registerDictionary( scanCLIDict, scanCLIDictName ); CLI_registerDictionary( scanCLIDict, scanCLIDictName );
VREF_TRM = 0x60; VREF_TRM = 0x60;
VREF_SC = 0xE1; // Enable 1.2V Vref 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 // DAC Setup
SIM_SCGC2 |= SIM_SCGC2_DAC0; SIM_SCGC2 |= SIM_SCGC2_DAC0;
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2 DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #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 // Parse code from argument
// NOTE: Only first argument is used // NOTE: Only first argument is used
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #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 // Parse code from argument
// NOTE: Only first argument is used // NOTE: Only first argument is used


void cliFunc_dac( 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 // Parse code from argument
// NOTE: Only first argument is used // NOTE: Only first argument is used
char* arg1Ptr; char* arg1Ptr;


void cliFunc_dacVref( 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 // Parse code from argument
// NOTE: Only first argument is used // NOTE: Only first argument is used
char* arg1Ptr; char* arg1Ptr;

+ 4
- 4
Scan/MBC-55X/scan_loop.c Bestand weergeven

// UART Receive Buffer Full Interrupt // UART Receive Buffer Full Interrupt
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
ISR(USART1_RX_vect) ISR(USART1_RX_vect)
#elif defined(_mk20dx128_) // ARM
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
void uart0_status_isr(void) void uart0_status_isr(void)
#endif #endif
{ {


#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
keyValue = UDR1; keyValue = UDR1;
#elif defined(_mk20dx128_) // ARM
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
// UART0_S1 must be read for the interrupt to be cleared // UART0_S1 must be read for the interrupt to be cleared
if ( UART0_S1 & UART_S1_RDRF ) if ( UART0_S1 & UART_S1_RDRF )
{ {
// Reset the keyboard before scanning, we might be in a wierd state // Reset the keyboard before scanning, we might be in a wierd state
Scan_resetKeyboard(); Scan_resetKeyboard();
} }
#elif defined(_mk20dx128_) // ARM
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
{ {
// Setup the the UART interface for keyboard data input // Setup the the UART interface for keyboard data input
SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating


#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
UDR1 = dataPayload; UDR1 = dataPayload;
#elif defined(_mk20dx128_) // ARM
#elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
UART0_D = dataPayload; UART0_D = dataPayload;
#endif #endif