/* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2019 PJRC.COM, LLC. * * 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 _avr_emulation_h_ #define _avr_emulation_h_ #include "core/imxrt.h" #include "core/core_pins.h" #include "core/pins_arduino.h" #ifdef __cplusplus // bitband addressing for atomic access to data direction register static inline void GPIO_SETBIT_ATOMIC(volatile uint32_t *reg, uint32_t mask) { __disable_irq(); *reg |= mask; __enable_irq(); } static inline void GPIO_CLRBIT_ATOMIC(volatile uint32_t *reg, uint32_t mask) { __disable_irq(); *reg &= ~mask; __enable_irq(); } #define CONFIG_PULLUP ( IOMUXC_PAD_DSE(7) | IOMUXC_PAD_PKE | IOMUXC_PAD_PUE | IOMUXC_PAD_PUS(3) | IOMUXC_PAD_HYS ) #define CONFIG_NOPULLUP ( IOMUXC_PAD_DSE(7)) // SPI Control Register ­ SPCR #define SPIE 7 // SPI Interrupt Enable - not supported #define SPE 6 // SPI Enable #define DORD 5 // DORD: Data Order #define MSTR 4 // MSTR: Master/Slave Select #define CPOL 3 // CPOL: Clock Polarity #define CPHA 2 // CPHA: Clock Phase #define SPR1 1 // Clock: 3 = 125 kHz, 2 = 250 kHz, 1 = 1 MHz, 0->4 MHz #define SPR0 0 // SPI Status Register ­ SPSR #define SPIF 7 // SPIF: SPI Interrupt Flag #define WCOL 6 // WCOL: Write COLlision Flag - not implemented #define SPI2X 0 // SPI2X: Double SPI Speed Bit // SPI Data Register ­ SPDR class SPCRemulation; class SPSRemulation; class SPDRemulation; class SPCRemulation { public: inline SPCRemulation & operator = (int val) __attribute__((always_inline)) { /* uint32_t ctar, mcr, sim6; //serial_print("SPCR="); //serial_phex(val); //serial_print("\n"); sim6 = SIM_SCGC6; if (!(sim6 & SIM_SCGC6_SPI0)) { //serial_print("init1\n"); SIM_SCGC6 = sim6 | SIM_SCGC6_SPI0; SPI0_CTAR0 = SPI_CTAR_FMSZ(7) | SPI_CTAR_PBR(1) | SPI_CTAR_BR(1) | SPI_CTAR_CSSCK(1); } if (!(val & (1<