diff --git a/utility/mcufriend_shield.h b/utility/mcufriend_shield.h index e3ecd60..6df24ce 100644 --- a/utility/mcufriend_shield.h +++ b/utility/mcufriend_shield.h @@ -90,6 +90,38 @@ #define PIN_HIGH(p, b) (p) |= (1<<(b)) #define PIN_OUTPUT(p, b) *(&p-1) |= (1<<(b)) +//################################### MEGA4809 NANO_EVERY 4808 ############################## +#elif defined(__AVR_ATmega4808__) // Thinary EVERY-4808 with Nano-Shield_Adapter +#warning EVERY-4808 with Nano-Shield_Adapter +#define RD_PORT VPORTD // +#define RD_PIN 0 +#define WR_PORT VPORTD +#define WR_PIN 1 +#define CD_PORT VPORTD +#define CD_PIN 2 +#define CS_PORT VPORTD +#define CS_PIN 3 +#define RESET_PORT VPORTF +#define RESET_PIN 2 + +#define AMASK 0xFF +#define write_8(x) { VPORTA.OUT = ((x) << 6) | ((x) >> 2); } +#define read_8() ( (VPORTA.IN >> 6) | (VPORTA.IN << 2) ) +#define setWriteDir() { VPORTA_DIR |= AMASK; } +#define setReadDir() { VPORTA_DIR &= ~AMASK; } + +//#define WRITE_DELAY { WR_ACTIVE; WR_ACTIVE; } //6.47s no_inline +#define WRITE_DELAY { WR_ACTIVE2; WR_ACTIVE; } //-Os=5.43s @20MHz always_inline. (-O1=5.41s, -O3=5.25s) +#define READ_DELAY { RD_ACTIVE4; } //ID=0x7789 +#define write8(x) { write_8(x); WRITE_DELAY; WR_STROBE; } +#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); } +#define READ_8(dst) { RD_STROBE; READ_DELAY; dst = read_8(); RD_IDLE; } +#define READ_16(dst) { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); } + +#define PIN_LOW(p, b) (p).OUT &= ~(1<<(b)) +#define PIN_HIGH(p, b) (p).OUT |= (1<<(b)) +#define PIN_OUTPUT(p, b) (p).DIR |= (1<<(b)) + //################################### MEGA4809 NANO_EVERY ############################## #elif defined(__AVR_ATmega4809__) && defined(ARDUINO_AVR_NANO_EVERY) // EVERY-4809 with Nano-Shield_Adapter #warning EVERY-4809 with Nano-Shield_Adapter using VPORT.OUT and BLD/BST