diff --git a/MCUFRIEND_kbv.cpp b/MCUFRIEND_kbv.cpp index 582368a..db13462 100644 --- a/MCUFRIEND_kbv.cpp +++ b/MCUFRIEND_kbv.cpp @@ -15,14 +15,14 @@ #include "MCUFRIEND_kbv.h" #if defined(USE_SERIAL) -#include "mcufriend_serial.h" +#include "utility/mcufriend_serial.h" //uint8_t running; #elif defined(__MBED__) -#include "mcufriend_mbed.h" +#include "utility/mcufriend_mbed.h" #elif defined(__CC_ARM) -#include "mcufriend_keil.h" +#include "utility/mcufriend_keil.h" #else -#include "mcufriend_shield.h" +#include "utility/mcufriend_shield.h" #endif #define MIPI_DCS_REV1 (1<<0) diff --git a/bitmaps/miniwoof.bmp b/extras/bitmaps/miniwoof.bmp similarity index 100% rename from bitmaps/miniwoof.bmp rename to extras/bitmaps/miniwoof.bmp diff --git a/bitmaps/test.bmp b/extras/bitmaps/test.bmp similarity index 100% rename from bitmaps/test.bmp rename to extras/bitmaps/test.bmp diff --git a/bitmaps/woof.bmp b/extras/bitmaps/woof.bmp similarity index 100% rename from bitmaps/woof.bmp rename to extras/bitmaps/woof.bmp diff --git a/mcufriend_history.txt b/extras/mcufriend_history.txt similarity index 100% rename from mcufriend_history.txt rename to extras/mcufriend_history.txt diff --git a/mcufriend_how_to.txt b/extras/mcufriend_how_to.txt similarity index 68% rename from mcufriend_how_to.txt rename to extras/mcufriend_how_to.txt index b57a94c..864c1e6 100644 --- a/mcufriend_how_to.txt +++ b/extras/mcufriend_how_to.txt @@ -19,37 +19,58 @@ Most of them will write some text to the Serial window (9600 baud). The BMP ex An Adafruit constructor(cs, rs, wr, rd, rst) IGNORES any arguments. i.e. it only uses the shield control pins 10. It currently supports UNO shields with "mcufriend.com" pcbs with controllers: ------ HX8347-A 240x320 ID=0x8347 #define SUPPORT_8347A new Untested +HX8347-A 240x320 ID=0x8347 #define SUPPORT_8347A *** Untested *** HX8347-D 240x320 ID=0x4747 #define SUPPORT_8347D +HX8347-G 240x320 ID=0x7575 #define SUPPORT_8347D HX8347-I 240x320 ID=0x9595 #define SUPPORT_8347D +HX8352-A 240x400 ID=0x5252 #define SUPPORT_8352A +HX8357-D 320x480 ID=0x8357 ILI9302 240x320 ID=0x9302 ILI9320 240x320 ID=0x9320 ILI9325 240x320 ID=0x9325 +ILI9326 240x400 ID=0x9326 #define SUPPORT_9326_5420 ILI9327 240x400 ID=0x9327 +ILI9328 240x320 ID=0x9328 ILI9329 240x320 ID=0x9329 +ILI9331 240x320 ID=0x9331 ILI9335 240x320 ID=0x9335 ILI9338 240x320 ID=0x9338 ILI9341 240x320 ID=0x9341 ILI9481 320x480 ID=0x9481 ILI9486 320x480 ID=0x9486 ILI9488 320x480 ID=0x9488 -LGDP4535 240x320 ID=0x4535 -RM68090 240x320 ID=0x6809 +LGDP4532 240x320 ID=0x4532 #define SUPPORT_4532 +LGDP4535 240x320 ID=0x4535 #define SUPPORT_4535 R61505V 240x320 ID=0xB505 -R61505W 240x320 ID=0xC505 new Untested -R61509V 240x400 ID=0xB509 +R61505W 240x320 ID=0xC505 +R61509V 240x400 ID=0xB509 #define SUPPORT_B509_7793 R61520 240x320 ID=0x1520 ------ S6D0139 240x320 ID=0x0139 removed due to lack of tester -S6D0154 240x320 ID=0x0154 +R61526A 240x320 ID=0x1526 +R61581 320x480 ID=0x1581 +RM68090 240x320 ID=0x6809 +RM68140 320x480 ID=0x6814 #define SUPPORT_68140 +S6D0139 240x320 ID=0x0139 #define SUPPORT_0139 *** Untested *** +S6D0154 240x320 ID=0x0154 #define SUPPORT_0154 SPFD5408 240x320 ID=0x5408 +SPFD5420 240x400 ID=0x5420 #define SUPPORT_9326_5420 SSD1963 800x480 ID=0x1963 SSD1289 240x320 ID=0x1289 #define SUPPORT_1289 -ST7781 240x320 ID=0x7783 +ST7781 240x320 ID=0x7783 #define SUPPORT_7781 ST7789V 240x320 ID=0x7789 +ST7793 240x400 ID=0x7793 #define SUPPORT_B509_7793 +ST7796 320x480 ID=0x7796 +UNKNOWN 320x480 ID=0x1511 +UNKNOWN 240x320 ID=0x1602 +UNKNOWN 240x320 ID=0xAC11 -11. It should run on a UNO, MEGA2560, LEONARDO, DUE, ZERO and M0-PRO. +Most of these controllers are #define SUPPORT_xxxx by default. +You can save Flash memory on a Uno by commenting out the macro(s). + +11. It should run on a UNO, MEGA2560, LEONARDO, DUE, ZERO, M0-PRO, +It also runs on NUCLEO-F103 and TEENSY3.2 with Sparkfun Adapter 12. These Mcufriend-style shields tend to have a resistive TouchScreen on A1, 7, A2, 6 but are not always the same rotation of direction. +Run the diagnose_Touchpins.ino sketch to detect which pins are used Run the TouchScreen_Calibr_kbv.ino sketch to diagnose your model and then scale the result from TouchScreen.h methods() The Resistive TouchScreen does not work on the Due. It seems to be upset by sharing pins. I have discovered why. (You need a new Touch library.) diff --git a/ILI9341_regValues.txt b/extras/unused/ILI9341_regValues.txt similarity index 100% rename from ILI9341_regValues.txt rename to extras/unused/ILI9341_regValues.txt diff --git a/mcufriend_special_2.h b/extras/unused/mcufriend_special_2.h similarity index 100% rename from mcufriend_special_2.h rename to extras/unused/mcufriend_special_2.h diff --git a/utility/mcufriend_keil.h b/utility/mcufriend_keil.h new file mode 100644 index 0000000..89ad485 --- /dev/null +++ b/utility/mcufriend_keil.h @@ -0,0 +1,61 @@ +#ifndef MCUFRIEND_KEIL_H_ +#define MCUFRIEND_KEIL_H_ + +#if defined(USE_SERIAL) +#include "mcufriend_keil_spi.h" +#else +#include "pin_shield_1.h" //shield pin macros e.g. A2_PORT, PIN_OUTPUT() +#include "pin_shield_8.h" //macros for write_8(), read_8(), setWriteDir(), ... + +// control pins as used in MCUFRIEND shields + #define RD_PORT A0_PORT + #define RD_PIN A0_PIN + #define WR_PORT A1_PORT + #define WR_PIN A1_PIN + #define CD_PORT A2_PORT + #define CD_PIN A2_PIN + #define CS_PORT A3_PORT + #define CS_PIN A3_PIN + #define RESET_PORT A4_PORT + #define RESET_PIN A4_PIN + +// general purpose pin macros + #define RD_ACTIVE PIN_LOW(RD_PORT, RD_PIN) + #define RD_IDLE PIN_HIGH(RD_PORT, RD_PIN) + #define RD_OUTPUT PIN_OUTPUT(RD_PORT, RD_PIN) + #define WR_ACTIVE PIN_LOW(WR_PORT, WR_PIN) + #define WR_IDLE PIN_HIGH(WR_PORT, WR_PIN) + #define WR_OUTPUT PIN_OUTPUT(WR_PORT, WR_PIN) + #define CD_COMMAND PIN_LOW(CD_PORT, CD_PIN) + #define CD_DATA PIN_HIGH(CD_PORT, CD_PIN) + #define CD_OUTPUT PIN_OUTPUT(CD_PORT, CD_PIN) + #define CS_ACTIVE PIN_LOW(CS_PORT, CS_PIN) + #define CS_IDLE PIN_HIGH(CS_PORT, CS_PIN) + #define CS_OUTPUT PIN_OUTPUT(CS_PORT, CS_PIN) + #define RESET_ACTIVE PIN_LOW(RESET_PORT, RESET_PIN) + #define RESET_IDLE PIN_HIGH(RESET_PORT, RESET_PIN) + #define RESET_OUTPUT PIN_OUTPUT(RESET_PORT, RESET_PIN) + +// General macros. IOCLR registers are 1 cycle when optimised. +#define WR_STROBE { WR_ACTIVE; WR_IDLE; } //PWLW=TWRL=50ns +#define RD_STROBE RD_IDLE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE //PWLR=TRDL=150ns +#if defined(TEENSY) || defined(__ARM_ARCH_7EM__) // || defined(STM32L476xx) +#define write8(d) { write_8(d); WR_ACTIVE; WR_ACTIVE; WR_STROBE; } // STROBEs are defined later +// read 250ns after RD_ACTIVE goes low +#define read8() ( RD_STROBE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE, read_8() ) +#else +#define write8(d) { write_8(d); WR_STROBE; } // STROBEs are defined later +// read 250ns after RD_ACTIVE goes low +#define read8() ( RD_STROBE, read_8() ) +#endif + +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { dst = read8(); RD_IDLE; } +#define READ_16(dst) { dst = read8(); dst = (dst<<8) | read8(); RD_IDLE; } + +#define CTL_INIT() { RD_OUTPUT; WR_OUTPUT; CD_OUTPUT; CS_OUTPUT; RESET_OUTPUT; } +#define WriteCmd(x) { CD_COMMAND; write16(x); } +#define WriteData(x) { CD_DATA; write16(x); } + +#endif //!USE_SERIAL +#endif //MCUFRIEND_KEIL_H_ diff --git a/mcufriend_serial.h b/utility/mcufriend_serial.h similarity index 100% rename from mcufriend_serial.h rename to utility/mcufriend_serial.h diff --git a/mcufriend_shield.h b/utility/mcufriend_shield.h similarity index 100% rename from mcufriend_shield.h rename to utility/mcufriend_shield.h diff --git a/mcufriend_special.h b/utility/mcufriend_special.h similarity index 100% rename from mcufriend_special.h rename to utility/mcufriend_special.h diff --git a/utility/pin_shield_1.h b/utility/pin_shield_1.h new file mode 100644 index 0000000..644faf3 --- /dev/null +++ b/utility/pin_shield_1.h @@ -0,0 +1,545 @@ +#ifndef PIN_SHIELD_1_H_ +#define PIN_SHIELD_1_H_ + +// just provide macros for the Arduino pins +// i.e. PIN_LOW(), PIN_HIGH(), PIN_OUTPUT(), PIN_INPUT(), PIN_READ() + +#define LPC810 810 +#define LPC812 812 +#define LPC1343 1343 +#define LPC1768 1768 +#define LPC2103 2103 +#define LPC2148 2148 +#warning Using pin_SHIELD_1.h + +#if 0 + +#elif defined(NUCLEO) || defined(TARGET_NUCLEO_F072RB) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F103RB) +#define PIN_MODE2(reg, pin, mode) reg=(reg&~(0x3<<((pin)<<1)))|(mode<<((pin)<<1)) +#if __MBED__ +#warning MBED knows everything +#elif defined(STM32F072xB) + #include +#elif defined(STM32F103xB) + #if defined(__CC_ARM) + #include + #else + #include + #endif +#elif defined(STM32L476xx) + #include +#elif defined(STM32F401xE) || defined(STM32F411xE) + #include +#endif + #define D0_PORT GPIOA + #define D0_PIN 3 + #define D1_PORT GPIOA + #define D1_PIN 2 + #define D2_PORT GPIOA + #define D2_PIN 10 + #define D3_PORT GPIOB + #define D3_PIN 3 + #define D4_PORT GPIOB + #define D4_PIN 5 + #define D5_PORT GPIOB + #define D5_PIN 4 + #define D6_PORT GPIOB + #define D6_PIN 10 + #define D7_PORT GPIOA + #define D7_PIN 8 + #define D8_PORT GPIOA + #define D8_PIN 9 + #define D9_PORT GPIOC + #define D9_PIN 7 + #define D10_PORT GPIOB + #define D10_PIN 6 + #define D11_PORT GPIOA + #define D11_PIN 7 + #define D12_PORT GPIOA + #define D12_PIN 6 + #define D13_PORT GPIOA + #define D13_PIN 5 + #define A0_PORT GPIOA + #define A0_PIN 0 + #define A1_PORT GPIOA + #define A1_PIN 1 + #define A2_PORT GPIOA + #define A2_PIN 4 + #define A3_PORT GPIOB + #define A3_PIN 0 + #define A4_PORT GPIOC + #define A4_PIN 1 + #define A5_PORT GPIOC + #define A5_PIN 0 +// Shield Control macros +#define PIN_LOW(port, pin) (port)->BSRR = (1<<((pin)+16)) +#define PIN_HIGH(port, pin) (port)->BSRR = (1<<(pin)) +//#define PIN_LOW(port, pin) (port)->ODR &= ~(1<<(pin)) +//#define PIN_HIGH(port, pin) (port)->ODR |= (1<<(pin)) +#define PIN_READ(port, pin) (port)->IDR & (1<<(pin)) +#if defined(STM32F103xB) + #warning STM32F103xB ****************************** +#define PIN_MODE4(reg, pin, mode) reg=(reg&~(0xF<<((pin)<<2)))|(mode<<((pin)<<2)) +#define PIN_OUTPUT(port, pin) PIN_MODE4((port)->CRL, pin, 0x3) //50MHz push-pull only 0-7 +#define PIN_INPUT(port, pin) PIN_MODE4((port)->CRL, pin, 0x4) //digital input +#else +#define PIN_OUTPUT(port, pin) PIN_MODE2((port)->MODER, pin, 0x1) +#define PIN_INPUT(port, pin) PIN_MODE2((port)->MODER, pin, 0x0) //.kbv check this +#endif + +#elif __TARGET_PROCESSOR == LPC1768 + #include +// configure macros for the control pins + #define D0_PORT LPC_GPIO0 + #define D0_PIN 3 + #define D1_PORT LPC_GPIO0 + #define D1_PIN 2 + #define D2_PORT LPC_GPIO0 + #define D2_PIN 24 //p16 + #define D3_PORT LPC_GPIO0 + #define D3_PIN 23 //p15 + #define D4_PORT LPC_GPIO0 + #define D4_PIN 16 //p14 + #define D5_PORT LPC_GPIO0 + #define D5_PIN 15 //p13 + #define D6_PORT LPC_GPIO0 + #define D6_PIN 17 //p12 + #define D7_PORT LPC_GPIO0 + #define D7_PIN 18 //p11 + #define D8_PORT LPC_GPIO0 + #define D8_PIN 1 //p10 + #define D9_PORT LPC_GPIO0 + #define D9_PIN 0 //p9 + #define D10_PORT LPC_GPIO0 + #define D10_PIN 6 //p8 + #define D11_PORT LPC_GPIO0 + #define D11_PIN 9 //p5 + #define D12_PORT LPC_GPIO0 + #define D12_PIN 8 //p6 miso + #define D13_PORT LPC_GPIO0 + #define D13_PIN 7 //p7 + #define A0_PORT LPC_GPIO0 + #define A0_PIN 25 //p17 + #define A1_PORT LPC_GPIO0 + #define A1_PIN 26 //p18 + #define A2_PORT LPC_GPIO1 + #define A2_PIN 30 //p19 + #define A3_PORT LPC_GPIO1 + #define A3_PIN 31 //p20 + #define A4_PORT LPC_GPIO0 + #define A4_PIN 10 //p28 + #define A5_PORT LPC_GP100 + #define A5_PIN 11 //p27 +// Shield Control macros +#define PIN_LOW(port, pin) (port)->FIOCLR = (1u<<(pin)) +#define PIN_HIGH(port, pin) (port)->FIOSET = (1u<<(pin)) +#define PIN_OUTPUT(port, pin) (port)->FIODIR |= (1u<<(pin)) +#define PIN_INPUT(port, pin) (port)->FIODIR &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port)->FIOPIN & (1u<<(pin)) + +#elif defined(MK20D7) && defined(TEENSY) + #include + #define D0_PORT PTB + #define D0_PIN 16 + #define D1_PORT PTB + #define D1_PIN 17 + #define D2_PORT PTD + #define D2_PIN 0 + #define D3_PORT PTA + #define D3_PIN 12 + #define D4_PORT PTA + #define D4_PIN 13 + #define D5_PORT PTD + #define D5_PIN 7 + #define D6_PORT PTD + #define D6_PIN 4 + #define D7_PORT PTD + #define D7_PIN 2 + #define D8_PORT PTD + #define D8_PIN 3 + #define D9_PORT PTC + #define D9_PIN 3 + #define D10_PORT PTC + #define D10_PIN 4 + #define D11_PORT PTC + #define D11_PIN 6 + #define D12_PORT PTC + #define D12_PIN 7 + #define D13_PORT PTC + #define D13_PIN 5 + #define A0_PORT PTD + #define A0_PIN 1 + #define A1_PORT PTC + #define A1_PIN 0 + #define A2_PORT PTB + #define A2_PIN 0 + #define A3_PORT PTB + #define A3_PIN 1 + #define A4_PORT PTB + #define A4_PIN 3 + #define A5_PORT PTB + #define A5_PIN 2 +// Shield Control macros. Deliberately avoid the IOSET registers +#define PIN_LOW(port, pin) (port)->PCOR = (1<<(pin)) +#define PIN_HIGH(port, pin) (port)->PSOR = (1<<(pin)) +//#define PIN_LOW(port, pin) (port)->PDOR &= ~(1<<(pin)) +//#define PIN_HIGH(port, pin) (port)->PDOR |= (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port)->PDDR |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port)->PDDR &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port)->PDIR & (1u<<(pin)) + + +#elif defined(MKL25Z4) || defined(TARGET_KL25Z) + #include + #define D0_PORT PTA + #define D0_PIN 1 + #define D1_PORT PTA + #define D1_PIN 2 + #define D2_PORT PTD + #define D2_PIN 4 + #define D3_PORT PTA + #define D3_PIN 12 + #define D4_PORT PTA + #define D4_PIN 4 + #define D5_PORT PTA + #define D5_PIN 5 + #define D6_PORT PTC + #define D6_PIN 8 + #define D7_PORT PTC + #define D7_PIN 9 + #define D8_PORT PTA + #define D8_PIN 13 + #define D9_PORT PTD + #define D9_PIN 5 + #define D10_PORT PTD + #define D10_PIN 0 + #define D11_PORT PTD + #define D11_PIN 2 + #define D12_PORT PTD + #define D12_PIN 3 + #define D13_PORT PTD + #define D13_PIN 1 + #define A0_PORT PTB + #define A0_PIN 0 + #define A1_PORT PTB + #define A1_PIN 1 + #define A2_PORT PTB + #define A2_PIN 2 + #define A3_PORT PTB + #define A3_PIN 3 + #define A4_PORT PTC + #define A4_PIN 2 + #define A5_PORT PTC + #define A5_PIN 1 +// Shield Control macros. Deliberately avoid the IOSET registers +#define PIN_LOW(port, pin) (port)->PCOR = (1<<(pin)) +#define PIN_HIGH(port, pin) (port)->PSOR = (1<<(pin)) +//#define PIN_LOW(port, pin) (port)->PDOR &= ~(1<<(pin)) +//#define PIN_HIGH(port, pin) (port)->PDOR |= (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port)->PDDR |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port)->PDDR &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port)->PDIR & (1u<<(pin)) + +#elif defined(MKL05Z4) + #include + #define D0_PORT PTB + #define D0_PIN 2 + #define D1_PORT PTB + #define D1_PIN 1 + #define D2_PORT PTA + #define D2_PIN 11 + #define D3_PORT PTB + #define D3_PIN 5 + #define D4_PORT PTA + #define D4_PIN 10 + #define D5_PORT PTA + #define D5_PIN 12 + #define D6_PORT PTB + #define D6_PIN 6 + #define D7_PORT PTB + #define D7_PIN 7 + #define D8_PORT PTB + #define D8_PIN 13 + #define D9_PORT PTB + #define D9_PIN 5 + #define D10_PORT PTA + #define D10_PIN 0 + #define D11_PORT PTA + #define D11_PIN 2 + #define D12_PORT PTA + #define D12_PIN 3 + #define D13_PORT PTB + #define D13_PIN 1 + #define A0_PORT PTB + #define A0_PIN 8 + #define A1_PORT PTB + #define A1_PIN 9 + #define A2_PORT PTA + #define A2_PIN 8 + #define A3_PORT PTA + #define A3_PIN 0 + #define A4_PORT PTA + #define A4_PIN 9 + #define A5_PORT PTB + #define A5_PIN 13 +// Shield Control macros +//#define PIN_LOW(port, pin) (port)->PCOR = (1<<(pin)) +//#define PIN_HIGH(port, pin) (port)->PSOR = (1<<(pin)) +#define PIN_LOW(port, pin) (port)->PDOR &= ~(1<<(pin)) +#define PIN_HIGH(port, pin) (port)->PDOR |= (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port)->PDDR |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port)->PDDR &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port)->PDIR & (1u<<(pin)) + +#elif defined(MK20D5) || defined(TARGET_K20D50M) + #include + #define D0_PORT PTE + #define D0_PIN 1 + #define D1_PORT PTE + #define D1_PIN 0 + #define D2_PORT PTA + #define D2_PIN 5 + #define D3_PORT PTD + #define D3_PIN 4 + #define D4_PORT PTC + #define D4_PIN 8 + #define D5_PORT PTA + #define D5_PIN 1 + #define D6_PORT PTC + #define D6_PIN 3 + #define D7_PORT PTC + #define D7_PIN 4 + #define D8_PORT PTA + #define D8_PIN 13 + #define D9_PORT PTA + #define D9_PIN 5 + #define D10_PORT PTC + #define D10_PIN 0 + #define D11_PORT PTD + #define D11_PIN 2 + #define D12_PORT PTD + #define D12_PIN 3 + #define D13_PORT PTD + #define D13_PIN 1 + #define A0_PORT PTC + #define A0_PIN 0 + #define A1_PORT PTC + #define A1_PIN 1 + #define A2_PORT PTD + #define A2_PIN 6 + #define A3_PORT PTD + #define A3_PIN 5 + #define A4_PORT PTB + #define A4_PIN 1 + #define A5_PORT PTB + #define A5_PIN 0 +// Shield Control macros. Deliberately avoid the IOSET registers +#define PIN_LOW(port, pin) (port)->PCOR = (1<<(pin)) +#define PIN_HIGH(port, pin) (port)->PSOR = (1<<(pin)) +//#define PIN_LOW(port, pin) (port)->PDOR &= ~(1<<(pin)) +//#define PIN_HIGH(port, pin) (port)->PDOR |= (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port)->PDDR |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port)->PDDR &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port)->PDIR & (1u<<(pin)) + + +#elif defined(ZERO) + #include +// configure macros for the data pins +#if defined(D21_XPRO) + #define D0_PORT PORT->Group[1] + #define D0_PIN 9 + #define D1_PORT PORT->Group[1] + #define D1_PIN 8 + #define D2_PORT PORT->Group[1] + #define D2_PIN 14 + #define D3_PORT PORT->Group[1] + #define D3_PIN 2 + #define D4_PORT PORT->Group[1] + #define D4_PIN 5 + #define D5_PORT PORT->Group[0] + #define D5_PIN 21 + #define D6_PORT PORT->Group[1] + #define D6_PIN 15 + #define D7_PORT PORT->Group[0] + #define D7_PIN 17 + #define D8_PORT PORT->Group[1] + #define D8_PIN 6 + #define D9_PORT PORT->Group[1] + #define D9_PIN 7 + #define D10_PORT PORT->Group[0] + #define D10_PIN 5 + #define D11_PORT PORT->Group[0] + #define D11_PIN 6 + #define D12_PORT PORT->Group[0] + #define D12_PIN 4 + #define D13_PORT PORT->Group[0] + #define D13_PIN 7 + #define A0_PORT PORT->Group[1] + #define A0_PIN 0 + #define A1_PORT PORT->Group[1] + #define A1_PIN 1 + #define A2_PORT PORT->Group[0] + #define A2_PIN 10 + #define A3_PORT PORT->Group[0] + #define A3_PIN 11 + #define A4_PORT PORT->Group[0] + #define A4_PIN 8 + #define A5_PORT PORT->Group[0] + #define A5_PIN 9 +#elif defined(M0_PRO) + #define D0_PORT PORT->Group[0] + #define D0_PIN 11 + #define D1_PORT PORT->Group[0] + #define D1_PIN 10 + #define D2_PORT PORT->Group[0] + #define D2_PIN 8 + #define D3_PORT PORT->Group[0] + #define D3_PIN 9 + #define D4_PORT PORT->Group[0] + #define D4_PIN 14 + #define D5_PORT PORT->Group[0] + #define D5_PIN 15 + #define D6_PORT PORT->Group[0] + #define D6_PIN 20 + #define D7_PORT PORT->Group[0] + #define D7_PIN 21 + #define D8_PORT PORT->Group[0] + #define D8_PIN 6 + #define D9_PORT PORT->Group[0] + #define D9_PIN 7 + #define D10_PORT PORT->Group[0] + #define D10_PIN 18 + #define D11_PORT PORT->Group[0] + #define D11_PIN 16 + #define D12_PORT PORT->Group[0] + #define D12_PIN 19 + #define D13_PORT PORT->Group[0] + #define D13_PIN 17 + #define A0_PORT PORT->Group[0] + #define A0_PIN 2 + #define A1_PORT PORT->Group[1] + #define A1_PIN 8 + #define A2_PORT PORT->Group[1] + #define A2_PIN 9 + #define A3_PORT PORT->Group[0] + #define A3_PIN 4 + #define A4_PORT PORT->Group[0] + #define A4_PIN 5 + #define A5_PORT PORT->Group[1] + #define A5_PIN 2 + +#endif +// Shield Control macros. +#define PIN_LOW(port, pin) (port).OUTCLR.reg = (1<<(pin)) +#define PIN_HIGH(port, pin) (port).OUTSET.reg = (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port).DIR.reg |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port).DIR.reg &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port).IN.reg & (1u<<(pin)) + + +#elif defined(__AVR_ATxmegaA4U__) + #include + // PD6, PD7 is used for USB. I could have used PORTA for bus, PORTC for MSPI, SPI and remap + #define D0_PORT PORTE + #define D0_PIN 2 + #define D1_PORT PORTE + #define D1_PIN 3 + #define D2_PORT PORTC + #define D2_PIN 2 + #define D3_PORT PORTC + #define D3_PIN 3 + #define D4_PORT PORTC + #define D4_PIN 4 + #define D5_PORT PORTC + #define D5_PIN 5 + #define D6_PORT PORTC + #define D6_PIN 6 + #define D7_PORT PORTC + #define D7_PIN 7 + #define D8_PORT PORTC + #define D8_PIN 0 + #define D9_PORT PORTC + #define D9_PIN 1 + #define D10_PORT PORTD + #define D10_PIN 0 + #define D11_PORT PORTD + #define D11_PIN 3 + #define D12_PORT PORTD + #define D12_PIN 2 + #define D13_PORT PORTD + #define D13_PIN 1 + #define A0_PORT PORTB + #define A0_PIN 0 + #define A1_PORT PORTB + #define A1_PIN 1 + #define A2_PORT PORTB + #define A2_PIN 2 + #define A3_PORT PORTB + #define A3_PIN 3 + #define A4_PORT PORTE + #define A4_PIN 0 + #define A5_PORT PORTE + #define A5_PIN 1 +// Shield Control macros. +#define PIN_LOW(port, pin) (port).OUTCLR.reg = (1<<(pin)) +#define PIN_HIGH(port, pin) (port).OUTSET.reg = (1<<(pin)) +#define PIN_OUTPUT(port, pin) (port).DIR.reg |= (1<<(pin)) +#define PIN_INPUT(port, pin) (port).DIR.reg &= ~(1u<<(pin)) +#define PIN_READ(port, pin) (port).IN.reg & (1u<<(pin)) + + +#elif defined(__AVR_ATtiny1634__) + #include + // + #define D0_PORT PORTA + #define D0_PIN 7 + #define D1_PORT PORTB + #define D1_PIN 0 + #define D2_PORT PORTA + #define D2_PIN 0 + #define D3_PORT PORTA + #define D3_PIN 3 + #define D4_PORT PORTA + #define D4_PIN 4 + #define D5_PORT PORTB + #define D5_PIN 3 + #define D6_PORT PORTA + #define D6_PIN 1 + #define D7_PORT PORTA + #define D7_PIN 0 + #define D8_PORT PORTA + #define D8_PIN 2 + #define D9_PORT PORTB + #define D9_PIN 2 + #define D10_PORT PORTA + #define D10_PIN 6 + #define D11_PORT PORTB + #define D11_PIN 2 + #define D12_PORT PORTB + #define D12_PIN 1 + #define D13_PORT PORTC + #define D13_PIN 1 + #define A0_PORT PORTB + #define A0_PIN 3 + #define A1_PORT PORTC + #define A1_PIN 0 + #define A2_PORT PORTA + #define A2_PIN 5 + #define A3_PORT PORTB + #define A3_PIN 2 + #define A4_PORT PORTB + #define A4_PIN 1 + #define A5_PORT PORTC + #define A5_PIN 1 +#else +#error MCU unselected +#endif // MCUs + +#endif //PIN_SHIELD_1_H +#if 0 +#if defined(M0_PRO) +#endif +#if defined(D21_XPRO) +#endif +#endif diff --git a/utility/pin_shield_8.h b/utility/pin_shield_8.h new file mode 100644 index 0000000..d7e7335 --- /dev/null +++ b/utility/pin_shield_8.h @@ -0,0 +1,286 @@ +#ifndef PIN_SHIELD_8_H_ +#define PIN_SHIELD_8_H_ + +// just provide macros for the 8-bit data bus +// i.e. write_8(), read_8(), setWriteDir(), setReadDir() + + +#define LPC810 810 +#define LPC812 812 +#define LPC1343 1343 +#define LPC1768 1768 +#define LPC2103 2103 +#define LPC2148 2148 +#warning Using pin_SHIELD_8.h + +#if 0 + +#elif defined(NUCLEO) || defined(TARGET_NUCLEO_F072RB) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F103RB) +#if __MBED__ +#warning MBED knows everything +#elif defined(STM32F072xB) + #include +#elif defined(STM32F103xB) + #if defined(__CC_ARM) + #include + #else + #include + #endif +#elif defined(STM32L476xx) + #include +#elif defined(STM32F401xE) || defined(STM32F411xE) + #include +#endif +// configure macros for the data pins. -00=10.06, -O1=7.85, -O1t=7.21, -O2=7.87, -O3=7.45, -O3t=7.03 + #define write_8(d) { \ + GPIOA->BSRR = 0x0700 << 16; \ + GPIOB->BSRR = 0x0438 << 16; \ + GPIOC->BSRR = 0x0080 << 16; \ + GPIOA->BSRR = (((d) & (1<<0)) << 9) \ + | (((d) & (1<<2)) << 8) \ + | (((d) & (1<<7)) << 1); \ + GPIOB->BSRR = (((d) & (1<<3)) << 0) \ + | (((d) & (1<<4)) << 1) \ + | (((d) & (1<<5)) >> 1) \ + | (((d) & (1<<6)) << 4); \ + GPIOC->BSRR = (((d) & (1<<1)) << 6); \ + } + #define read_8() ( (((GPIOA->IDR & (1<<9)) >> 9) \ + | ((GPIOC->IDR & (1<<7)) >> 6) \ + | ((GPIOA->IDR & (1<<10)) >> 8) \ + | ((GPIOB->IDR & (1<<3)) >> 0) \ + | ((GPIOB->IDR & (1<<5)) >> 1) \ + | ((GPIOB->IDR & (1<<4)) << 1) \ + | ((GPIOB->IDR & (1<<10)) >> 4) \ + | ((GPIOA->IDR & (1<<8)) >> 1))) +// be wise to clear both MODER bits properly. +#if defined(STM32F103xB) +#define GROUP_MODE(port, reg, mask, val) {port->reg = (port->reg & ~(mask)) | ((mask)&(val)); } +#define GP_OUT(port, reg, mask) GROUP_MODE(port, reg, mask, 0x33333333) +#define GP_INP(port, reg, mask) GROUP_MODE(port, reg, mask, 0x44444444) +// PA10,PA9,PA8 PB10 PB5,PB4,PB3 PC7 +#define setWriteDir() {GP_OUT(GPIOA, CRH, 0xFFF); GP_OUT(GPIOB, CRH, 0xF00); GP_OUT(GPIOB, CRL, 0xFFF000); GP_OUT(GPIOC, CRL, 0xF0000000); } +#define setReadDir() {GP_INP(GPIOA, CRH, 0xFFF); GP_INP(GPIOB, CRH, 0xF00); GP_INP(GPIOB, CRL, 0xFFF000); GP_INP(GPIOC, CRL, 0xF0000000); } +#else + #define setWriteDir() { setReadDir(); \ + GPIOA->MODER |= 0x150000; GPIOB->MODER |= 0x100540; GPIOC->MODER |= 0x4000; } + #define setReadDir() { GPIOA->MODER &= ~0x3F0000; GPIOB->MODER &= ~0x300FC0; GPIOC->MODER &= ~0xC000; } +#endif + + +#elif __TARGET_PROCESSOR == LPC1768 + #include +// configure macros for the data pins + #define write_8(d) { \ + LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & ~0x01878003) \ + | (((d) & (1<<0)) << 1) \ + | (((d) & (1<<1)) >> 1) \ + | (((d) & (1<<2)) << 22) \ + | (((d) & (1<<3)) << 20) \ + | (((d) & (1<<4)) << 12) \ + | (((d) & (1<<5)) << 10) \ + | (((d) & (1<<6)) << 11) \ + | (((d) & (1<<7)) << 11); \ + } + #define read_8() ( (((LPC_GPIO0->FIOPIN & (1<<1)) >> 1) \ + | ((LPC_GPIO0->FIOPIN & (1<<0)) << 1) \ + | ((LPC_GPIO0->FIOPIN & (1<<24)) >> 22) \ + | ((LPC_GPIO0->FIOPIN & (1<<23)) >> 20) \ + | ((LPC_GPIO0->FIOPIN & (1<<16)) >> 12) \ + | ((LPC_GPIO0->FIOPIN & (1<<15)) >> 10) \ + | ((LPC_GPIO0->FIOPIN & (1<<17)) >> 11) \ + | ((LPC_GPIO0->FIOPIN & (1<<18)) >> 11))) + #define setWriteDir() {LPC_GPIO0->FIODIR |= 0x01878003; } + #define setReadDir() {LPC_GPIO0->FIODIR &= ~0x01878003; } + + +#elif defined(MKL25Z4) || defined(TARGET_KL25Z) + #include +// configure macros for the data pins +#if 1 +#define AMASK ((1<<13)|(1<<12)|(1<<5)|(1<<4)) +#define CMASK ((1<<9)|(1<<8)) +#define DMASK ((1<<5)|(1<<4)) + #define write_8(d) { \ + PTA->PCOR = AMASK; PTC->PCOR = CMASK; PTD->PCOR = DMASK; \ + PTA->PSOR = (((d) & (1<<0)) << 13) \ + | (((d) & (1<<3)) << 9) \ + | (((d) & (1<<4)) >> 0) \ + | (((d) & (1<<5)) >> 0); \ + PTC->PSOR = (((d) & (1<<6)) << 2) \ + | (((d) & (1<<7)) << 2); \ + PTD->PSOR = (((d) & (1<<1)) << 4) \ + | (((d) & (1<<2)) << 2); \ + } + #define read_8() ( (((PTA->PDIR & (1<<13)) >> 13) \ + | ((PTA->PDIR & (1<<12)) >> 9) \ + | ((PTA->PDIR & (3<<4)) >> 0) \ + | ((PTC->PDIR & (3<<8)) >> 2) \ + | ((PTD->PDIR & (1<<4)) >> 2) \ + | ((PTD->PDIR & (1<<5)) >> 4))) + #define setWriteDir() {PTA->PDDR |= AMASK;PTC->PDDR |= CMASK;PTD->PDDR |= DMASK; } + #define setReadDir() {PTA->PDDR &= ~AMASK;PTC->PDDR &= ~CMASK;PTD->PDDR &= ~DMASK; } +#else + #define write_8(d) { \ + PTA->PDOR = (PTA->PDOR & ~0x3030) \ + | (((d) & (1<<0)) << 13) \ + | (((d) & (1<<3)) << 9) \ + | (((d) & (3<<4)) << 0); \ + PTC->PDOR = (PTC->PDOR & ~0x0300) \ + | (((d) & (3<<6)) << 2); \ + PTD->PDOR = (PTD->PDOR & ~0x0030) \ + | (((d) & (1<<1)) << 4) \ + | (((d) & (1<<2)) << 2); \ + } + #define read_8() ( (((PTA->PDIR & (1<<13)) >> 13) \ + | ((PTA->PDIR & (1<<12)) >> 9) \ + | ((PTA->PDIR & (3<<4)) >> 0) \ + | ((PTC->PDIR & (3<<8)) >> 2) \ + | ((PTD->PDIR & (1<<4)) >> 2) \ + | ((PTD->PDIR & (1<<5)) >> 4))) + #define setWriteDir() {PTA->PDDR |= 0x3030;PTC->PDDR |= 0x0300;PTD->PDDR |= 0x0030; } + #define setReadDir() {PTA->PDDR &= ~0x3030;PTC->PDDR &= ~0x0300;PTD->PDDR &= ~0x0030; } +#endif + +#elif defined(MKL05Z4) || defined(TARGET_KL05Z) + #include +// configure macros for the data pins + #define write_8(d) { \ + PTA->PDOR = (PTA->PDOR & ~0x1C00) \ + | (((d) & (1<<2)) << 9) \ + | (((d) & (1<<4)) << 6) \ + | (((d) & (1<<5)) << 7); \ + PTB->PDOR = (PTB->PDOR & ~0x0CE0) \ + | (((d) & (3<<0)) << 10) \ + | (((d) & (1<<3)) << 2) \ + | (((d) & (3<<6)) << 0); \ + } + #define read_8() ( (((PTA->PDIR & (1<<11)) >> 9) \ + | ((PTA->PDIR & (1<<10)) >> 6) \ + | ((PTA->PDIR & (1<<12)) >> 7) \ + | ((PTB->PDIR & (3<<10)) >> 10) \ + | ((PTB->PDIR & (1<<5)) >> 2) \ + | ((PTB->PDIR & (3<<6)) >> 0))) + #define setWriteDir() { PTA->PDDR |= 0x1C00; PTB->PDDR |= 0x0CE0; } + #define setReadDir() { PTA->PDDR &= ~0x1C00; PTB->PDDR &= ~0x0CE0; } + + +#elif defined(MK20D7) && defined(TEENSY) + #include +// configure macros for the data pins +#define AMASK ((1<<12)|(1<<13)) +#define CMASK ((1<<3)) +#define DMASK ((1<<0)|(1<<2)|(1<<3)|(1<<4)|(1<<7)) + + #define write_8(d) { \ + PTA->PCOR = AMASK; PTC->PCOR = CMASK; PTD->PCOR = DMASK; \ + PTA->PSOR = (((d) & (1<<3)) << 9) \ + | (((d) & (1<<4)) << 9); \ + PTC->PSOR = (((d) & (1<<1)) << 2); \ + PTD->PSOR = (((d) & (1<<0)) << 3) \ + | (((d) & (1<<2)) >> 2) \ + | (((d) & (1<<5)) << 2) \ + | (((d) & (1<<6)) >> 2) \ + | (((d) & (1<<7)) >> 5); \ + } + #define read_8() ( (((PTD->PDIR & (1<<3)) >> 3) \ + | ((PTC->PDIR & (1<<3)) >> 2) \ + | ((PTD->PDIR & (1<<0)) << 2) \ + | ((PTA->PDIR & (1<<12)) >> 9) \ + | ((PTA->PDIR & (1<<13)) >> 9) \ + | ((PTD->PDIR & (1<<7)) >> 2) \ + | ((PTD->PDIR & (1<<4)) << 2) \ + | ((PTD->PDIR & (1<<2)) << 5))) + #define setWriteDir() {PTA->PDDR |= AMASK;PTC->PDDR |= CMASK;PTD->PDDR |= DMASK; } + #define setReadDir() {PTA->PDDR &= ~AMASK;PTC->PDDR &= ~CMASK;PTD->PDDR &= ~DMASK; } + +#elif defined(MK20D5) || defined(TARGET_K20D50M) + #include +// configure macros for the data pins +#define AMASK ((1<<12)|(1<<5)|(1<<2)|(1<<1)) +#define CMASK ((1<<8)|(1<<4)|(1<<3)) +#define DMASK ((1<<4)) + #define write_8(d) { \ + PTA->PCOR = AMASK; PTC->PCOR = CMASK; PTD->PCOR = DMASK; \ + PTA->PSOR = (((d) & (1<<0)) << 12) \ + | (((d) & (1<<1)) << 1) \ + | (((d) & (1<<2)) << 3) \ + | (((d) & (1<<5)) >> 4); \ + PTC->PSOR = (((d) & (1<<4)) << 4) \ + | (((d) & (3<<6)) >> 3); \ + PTD->PSOR = (((d) & (1<<3)) << 1); \ + } + #define read_8() ( (((PTA->PDIR & (1<<5)) >> 3) \ + | ((PTA->PDIR & (1<<1)) << 4) \ + | ((PTA->PDIR & (1<<12)) >> 12) \ + | ((PTA->PDIR & (1<<2)) >> 1) \ + | ((PTC->PDIR & (1<<8)) >> 4) \ + | ((PTC->PDIR & (3<<3)) << 3) \ + | ((PTD->PDIR & (1<<4)) >> 1))) + #define setWriteDir() {PTA->PDDR |= AMASK;PTC->PDDR |= CMASK;PTD->PDDR |= DMASK; } + #define setReadDir() {PTA->PDDR &= ~AMASK;PTC->PDDR &= ~CMASK;PTD->PDDR &= ~DMASK; } + +#elif defined(ZERO) + #include + + #ifndef PORTA + #define PORTA PORT->Group[0] + #define PORTB PORT->Group[1] + #endif +// configure macros for the data pins +#if defined(D21_XPRO) + #define AMASK 0x00220000 + #define BMASK 0x0000C0E4 + #define write_8(d) { \ + PORTA.OUT.reg = (PORTA.OUT.reg & ~AMASK) \ + | (((d) & (1<<5)) << 16) \ + | (((d) & (1<<7)) << 10); \ + PORTB.OUT.reg = (PORTB.OUT.reg & ~BMASK) \ + | (((d) & (3<<0)) << 6) \ + | (((d) & (1<<2)) << 12) \ + | (((d) & (1<<3)) >> 1) \ + | (((d) & (1<<4)) << 1) \ + | (((d) & (1<<6)) << 9); \ + } + #define read_8() ( (((PORTA.IN.reg & (1<<21)) >> 16) \ + | ((PORTA.IN.reg & (1<<17)) >> 10) \ + | ((PORTB.IN.reg & (3<<6)) >> 6) \ + | ((PORTB.IN.reg & (1<<14)) >> 12) \ + | ((PORTB.IN.reg & (1<<2)) << 1) \ + | ((PORTB.IN.reg & (1<<5)) >> 1) \ + | ((PORTB.IN.reg & (1<<15)) >> 9))) + #define setWriteDir() { \ + PORTA.DIRSET.reg = AMASK; \ + PORTB.DIRSET.reg = BMASK; \ + PORTA.WRCONFIG.reg = (AMASK>>16) | (0<<22) | (0<<28) | (1<<30) | (1<<31); \ + PORTB.WRCONFIG.reg = (BMASK & 0xFFFF) | (0<<22) | (0<<28) | (1<<30); \ + } + #define setReadDir() { \ + PORTA.DIRCLR.reg = AMASK; \ + PORTB.DIRCLR.reg = BMASK; \ + PORTA.WRCONFIG.reg = (AMASK>>16) | (1<<17) | (0<<28) | (1<<30) | (1<<31); \ + PORTB.WRCONFIG.reg = (BMASK & 0xFFFF) | (1<<17) | (0<<28) | (1<<30); \ + } +#else + #define DMASK 0x0030C3C0 + #define write_8(x) {PORTA.OUTCLR.reg = (DMASK); \ + PORTA.OUTSET.reg = (((x) & 0x0F) << 6) \ + | (((x) & 0x30) << 10) \ + | (((x) & 0xC0)<<14); } + #define read_8() (((PORTA.IN.reg >> 6) & 0x0F) \ + | ((PORTA.IN.reg >> 10) & 0x30) \ + | ((PORTA.IN.reg >> 14) & 0xC0)) + #define setWriteDir() { PORTA.DIRSET.reg = DMASK; \ + PORTA.WRCONFIG.reg = (DMASK & 0xFFFF) | (0<<22) | (1<<28) | (1<<30); \ + PORTA.WRCONFIG.reg = (DMASK>>16) | (0<<22) | (1<<28) | (1<<30) | (1<<31); \ + } + #define setReadDir() { PORTA.DIRCLR.reg = DMASK; \ + PORTA.WRCONFIG.reg = (DMASK & 0xFFFF) | (1<<17) | (1<<28) | (1<<30); \ + PORTA.WRCONFIG.reg = (DMASK>>16) | (1<<17) | (1<<28) | (1<<30) | (1<<31); \ + } +#endif +#else +#error MCU unselected +#endif // MCUs + +#endif //PIN_SHIELD_8_H