Please run it on your NUCLEO-L152

Dependencies:   mbed

Committer:
davidprentice
Date:
Wed Sep 18 10:38:19 2019 +0000
Revision:
1:d88d2ad55fac
Parent:
0:b608c7f02f80
Added messages to Serial Terminal (9600 baud)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidprentice 0:b608c7f02f80 1 #ifndef MCUFRIEND_MBED_H_
davidprentice 0:b608c7f02f80 2 #define MCUFRIEND_MBED_H_
davidprentice 0:b608c7f02f80 3
davidprentice 0:b608c7f02f80 4 #include <mbed.h>
davidprentice 0:b608c7f02f80 5
davidprentice 0:b608c7f02f80 6 #if defined(USE_SERIAL)
davidprentice 0:b608c7f02f80 7 #include "mcufriend_keil_spi.h"
davidprentice 0:b608c7f02f80 8 #else
davidprentice 0:b608c7f02f80 9
davidprentice 0:b608c7f02f80 10 BusOut digitalL(D0, D1, D2, D3, D4, D5, D6, D7);
davidprentice 0:b608c7f02f80 11 BusOut digitalH(D8, D9, D10, D11, D12, D13, NC, NC);
davidprentice 0:b608c7f02f80 12 BusOut analog(A0, A1, A2, A3, A4, A5, NC, NC);
davidprentice 0:b608c7f02f80 13
davidprentice 0:b608c7f02f80 14 #include "pin_shield_1.h" //shield pin macros e.g. A2_PORT, PIN_OUTPUT()
davidprentice 0:b608c7f02f80 15 #include "pin_shield_8.h" //macros for write_8(), read_8(), setWriteDir(), ...
davidprentice 0:b608c7f02f80 16
davidprentice 0:b608c7f02f80 17 // control pins as used in MCUFRIEND shields
davidprentice 0:b608c7f02f80 18 #define RD_PORT A0_PORT
davidprentice 0:b608c7f02f80 19 #define RD_PIN A0_PIN
davidprentice 0:b608c7f02f80 20 #define WR_PORT A1_PORT
davidprentice 0:b608c7f02f80 21 #define WR_PIN A1_PIN
davidprentice 0:b608c7f02f80 22 #define CD_PORT A2_PORT
davidprentice 0:b608c7f02f80 23 #define CD_PIN A2_PIN
davidprentice 0:b608c7f02f80 24 #define CS_PORT A3_PORT
davidprentice 0:b608c7f02f80 25 #define CS_PIN A3_PIN
davidprentice 0:b608c7f02f80 26 #define RESET_PORT A4_PORT
davidprentice 0:b608c7f02f80 27 #define RESET_PIN A4_PIN
davidprentice 0:b608c7f02f80 28
davidprentice 0:b608c7f02f80 29 // general purpose pin macros
davidprentice 0:b608c7f02f80 30 #define RD_ACTIVE PIN_LOW(RD_PORT, RD_PIN)
davidprentice 0:b608c7f02f80 31 #define RD_IDLE PIN_HIGH(RD_PORT, RD_PIN)
davidprentice 0:b608c7f02f80 32 #define RD_OUTPUT PIN_OUTPUT(RD_PORT, RD_PIN)
davidprentice 0:b608c7f02f80 33 #define WR_ACTIVE PIN_LOW(WR_PORT, WR_PIN)
davidprentice 0:b608c7f02f80 34 #define WR_IDLE PIN_HIGH(WR_PORT, WR_PIN)
davidprentice 0:b608c7f02f80 35 #define WR_OUTPUT PIN_OUTPUT(WR_PORT, WR_PIN)
davidprentice 0:b608c7f02f80 36 #define CD_COMMAND PIN_LOW(CD_PORT, CD_PIN)
davidprentice 0:b608c7f02f80 37 #define CD_DATA PIN_HIGH(CD_PORT, CD_PIN)
davidprentice 0:b608c7f02f80 38 #define CD_OUTPUT PIN_OUTPUT(CD_PORT, CD_PIN)
davidprentice 0:b608c7f02f80 39 #define CS_ACTIVE PIN_LOW(CS_PORT, CS_PIN)
davidprentice 0:b608c7f02f80 40 #define CS_IDLE PIN_HIGH(CS_PORT, CS_PIN)
davidprentice 0:b608c7f02f80 41 #define CS_OUTPUT PIN_OUTPUT(CS_PORT, CS_PIN)
davidprentice 0:b608c7f02f80 42 #define RESET_ACTIVE PIN_LOW(RESET_PORT, RESET_PIN)
davidprentice 0:b608c7f02f80 43 #define RESET_IDLE PIN_HIGH(RESET_PORT, RESET_PIN)
davidprentice 0:b608c7f02f80 44 #define RESET_OUTPUT PIN_OUTPUT(RESET_PORT, RESET_PIN)
davidprentice 0:b608c7f02f80 45
davidprentice 0:b608c7f02f80 46 #define WR_ACTIVE2 {WR_ACTIVE; WR_ACTIVE;}
davidprentice 0:b608c7f02f80 47 #define WR_ACTIVE4 {WR_ACTIVE2; WR_ACTIVE2;}
davidprentice 0:b608c7f02f80 48 #define WR_ACTIVE8 {WR_ACTIVE4; WR_ACTIVE4;}
davidprentice 0:b608c7f02f80 49 #define RD_ACTIVE2 {RD_ACTIVE; RD_ACTIVE;}
davidprentice 0:b608c7f02f80 50 #define RD_ACTIVE4 {RD_ACTIVE2; RD_ACTIVE2;}
davidprentice 0:b608c7f02f80 51 #define RD_ACTIVE8 {RD_ACTIVE4; RD_ACTIVE4;}
davidprentice 0:b608c7f02f80 52 #define RD_ACTIVE16 {RD_ACTIVE8; RD_ACTIVE8;}
davidprentice 0:b608c7f02f80 53 #define WR_IDLE2 {WR_IDLE; WR_IDLE;}
davidprentice 0:b608c7f02f80 54 #define WR_IDLE4 {WR_IDLE2; WR_IDLE2;}
davidprentice 0:b608c7f02f80 55 #define RD_IDLE2 {RD_IDLE; RD_IDLE;}
davidprentice 0:b608c7f02f80 56 #define RD_IDLE4 {RD_IDLE2; RD_IDLE2;}
davidprentice 0:b608c7f02f80 57
davidprentice 0:b608c7f02f80 58 #if defined(__MK20DX128__) || defined(___MK20DX256__) // Teensy3.0 || 3.2 96MHz
davidprentice 0:b608c7f02f80 59 #define WRITE_DELAY { WR_ACTIVE2; }
davidprentice 0:b608c7f02f80 60 #define READ_DELAY { RD_ACTIVE4; RD_ACTIVE; }
davidprentice 0:b608c7f02f80 61 #elif defined(__MK64FX512__) || defined(TARGET_M4) // Teensy3.5 120MHz thanks to PeteJohno
davidprentice 0:b608c7f02f80 62 #define WRITE_DELAY { WR_ACTIVE4; }
davidprentice 0:b608c7f02f80 63 #define READ_DELAY { RD_ACTIVE8; }
davidprentice 0:b608c7f02f80 64 #elif defined(__MK66FX1M0__) || defined(TARGET_M4) // Teensy3.6 180MHz untested. delays can possibly be reduced.
davidprentice 0:b608c7f02f80 65 #define WRITE_DELAY { WR_ACTIVE8; }
davidprentice 0:b608c7f02f80 66 #define READ_DELAY { RD_ACTIVE8; RD_ACTIVE8; }
davidprentice 0:b608c7f02f80 67 #elif defined(TARGET_M7) // Nucleo-F767 216MHz untested. delays can possibly be reduced.
davidprentice 0:b608c7f02f80 68 #define WRITE_DELAY { WR_ACTIVE8; WR_ACTIVE2; }
davidprentice 0:b608c7f02f80 69 #define IDLE_DELAY { WR_IDLE2;WR_IDLE; }
davidprentice 0:b608c7f02f80 70 #define READ_DELAY { RD_ACTIVE16; RD_ACTIVE16; RD_ACTIVE4; }
davidprentice 0:b608c7f02f80 71 #define READ_IDLE { RD_IDLE2;RD_IDLE; }
davidprentice 0:b608c7f02f80 72 #else
davidprentice 0:b608c7f02f80 73 //#error unspecified delays
davidprentice 0:b608c7f02f80 74 //#define WRITE_DELAY { WR_ACTIVE2; }
davidprentice 0:b608c7f02f80 75 //#define READ_DELAY { RD_ACTIVE4; RD_ACTIVE; }
davidprentice 0:b608c7f02f80 76 #define WRITE_DELAY
davidprentice 0:b608c7f02f80 77 #define READ_DELAY
davidprentice 0:b608c7f02f80 78 #endif
davidprentice 0:b608c7f02f80 79
davidprentice 0:b608c7f02f80 80 #if !defined(IDLE_DELAY)
davidprentice 0:b608c7f02f80 81 #define IDLE_DELAY WR_IDLE
davidprentice 0:b608c7f02f80 82 #endif
davidprentice 0:b608c7f02f80 83 #if !defined(READ_IDLE)
davidprentice 0:b608c7f02f80 84 #define READ_IDLE RD_IDLE
davidprentice 0:b608c7f02f80 85 #endif
davidprentice 0:b608c7f02f80 86
davidprentice 0:b608c7f02f80 87 // General macros. IOCLR registers are 1 cycle when optimised.
davidprentice 0:b608c7f02f80 88 #define WR_STROBE { WR_ACTIVE; WR_IDLE; } //PWLW=TWRL=50ns
davidprentice 0:b608c7f02f80 89 #define RD_STROBE RD_IDLE, RD_ACTIVE, RD_ACTIVE, RD_ACTIVE //PWLR=TRDL=150ns
davidprentice 0:b608c7f02f80 90 #define write8(d) { write_8(d); WRITE_DELAY; WR_STROBE; IDLE_DELAY; } // STROBEs are defined later
davidprentice 0:b608c7f02f80 91 #define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
davidprentice 0:b608c7f02f80 92 #define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); READ_IDLE; } // read 250ns after RD_ACTIVE goes low
davidprentice 0:b608c7f02f80 93 #define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }
davidprentice 0:b608c7f02f80 94
davidprentice 0:b608c7f02f80 95 #define CTL_INIT() { RD_OUTPUT; WR_OUTPUT; CD_OUTPUT; CS_OUTPUT; RESET_OUTPUT; }
davidprentice 0:b608c7f02f80 96 #define WriteCmd(x) { CD_COMMAND; write16(x); CD_DATA; }
davidprentice 0:b608c7f02f80 97 #define WriteData(x) { write16(x); }
davidprentice 0:b608c7f02f80 98
davidprentice 0:b608c7f02f80 99 #endif //!USE_SERIAL
davidprentice 0:b608c7f02f80 100 #endif //MCUFRIEND_KEIL_H_