Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Arduino Due and the IDE 1.5.8 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions Pixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
* - K. Townsend http://microBuilder.eu (lpc1343codebase Project)
*/

/*
* Added support for Arduino Due including the 1.5.8 IDE
* Currently tested with Arduino Due + TFT320QVT (SSD1289) + TFT Mega Shield V1.1 by Lseeduino (you can also hook it directly to the Due)
*
* Collaborator: CMBSolutions
* Date: December, 20 2014
* Contact: git@cmbsolutions.nl
*/

#include "Pixels.h"

RGB::RGB(uint8_t r, uint8_t g, uint8_t b) {
Expand Down Expand Up @@ -1437,11 +1446,19 @@ void PixelsBase::drawPixel(int16_t x, int16_t y) {
void PixelsBase::fill(int color, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {

if (x2 < x1) {
swap(x1, x2);
#if defined(dueSwap)
swap(int16_t, x1, x2);
#else
swap(x1, x2);
#endif
}

if (y2 < y1) {
swap(y1, y2);
#if defined(dueSwap)
swap(int16_t, y1, y2);
#else
swap(y1, y2);
#endif
}

if ( x1 >= width ) {
Expand Down
63 changes: 48 additions & 15 deletions Pixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
* More platforms coming soon
*/



/*
* Added support for Arduino Due including the 1.5.8 IDE
* Currently tested with Arduino Due + TFT320QVT (SSD1289) + TFT Mega Shield V1.1 by Lseeduino (you can also hook it directly to the Due)
*
* Collaborator: CMBSolutions
* Date: December, 20 2014
* Contact: git@cmbsolutions.nl
*/

#ifndef PIXELS_BASE_H
#define PIXELS_BASE_H

Expand All @@ -40,20 +51,42 @@
#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);

#elif defined(__SAM3X8E__)
#include <Arduino.h>
#define PROGMEM
#define prog_uchar const unsigned char
#define pgm_read_byte(x) (*((char *)x))
#define pgm_read_word(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
#define pgm_read_byte_near(x) (*((char *)x))
#define pgm_read_byte_far(x) (*((char *)x))
// #define pgm_read_word(x) (*((short *)(x & 0xfffffffe)))
// #define pgm_read_word_near(x) (*((short *)(x & 0xfffffffe))
// #define pgm_read_word_far(x) (*((short *)(x & 0xfffffffe)))
#define pgm_read_word_near(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
#define pgm_read_word_far(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))
#define PSTR(x) x
#define swap(a, b) {int16_t buf = a; a = b; b = buf;} // Used by avr

#elif defined(__SAM3X8E__) // Everything changed here, this is all used for the due
#include <Arduino.h>

// existing code
#define PROGMEM
#define prog_uchar const unsigned char
#define pgm_read_byte(x) (*((char *)x))
#define pgm_read_word(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
#define pgm_read_byte_near(x) (*((char *)x))
#define pgm_read_byte_far(x) (*((char *)x))
#define pgm_read_word_near(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
#define pgm_read_word_far(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))
#define PSTR(x) x

// Cloned these from AVR, could define only once, but find this more understandable.
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);

// Not sure why they are needed, but without them it doesn't work :)
#define cport(port, data) port &= data
#define sport(port, data) port |= data

// Important to leave this define alone, unless you found a way to use the same "swap" on avr and arm (arm has 3 params)
#define dueSwap 1
#define swap(type, i, j) {type t = i; i = j; j = t;}

#define fontbyte(x) cfont.font[x]
#define pgm_read_word(data) *data
#define pgm_read_byte(data) *data
#define bitmapdatatype unsigned short*
#define regtype volatile uint32_t
#define regsize uint32_t
#else
#define PROGMEM
#define prog_uchar byte
Expand All @@ -62,7 +95,7 @@
#define regsize uint16_t
#endif

#define swap(a, b) {int16_t buf = a; a = b; b = buf;}


#define BITMASK_FONT 1
#define ANTIALIASED_FONT 2
Expand Down
93 changes: 77 additions & 16 deletions Pixels_PPI16.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,41 @@
* - K. Townsend http://microBuilder.eu (lpc1343codebase Project)
*/

/*
* Added support for Arduino Due including the 1.5.8 IDE
* Currently tested with Arduino Due + TFT320QVT (SSD1289) + TFT Mega Shield V1.1 by Lseeduino (you can also hook it directly to the Due)
*
* Collaborator: CMBSolutions
* Date: December, 20 2014
* Contact: git@cmbsolutions.nl
*/

/*
* Parallel interface 16bit layer
*/

#include "Pixels.h"

#ifdef PIXELS_MAIN
#error Pixels_PPI16.h must be included before Pixels_<CONTROLLER>.h
#error Pixels_PPI16.h must be included before Pixels_<CONTROLLER>.h
#endif

#ifndef PIXELS_PPI16_H
#define PIXELS_PPI16_H

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define DATAPORTH PORTA // 22-29
#define DATAPORTL PORTC // 30-37
#define DATADIRH DDRA
#define DATADIRL DDRC
#define DATAPORTH PORTA // 22-29
#define DATAPORTL PORTC // 30-37
#define DATADIRH DDRA
#define DATADIRL DDRC
#elif defined(__arm__)
// No defines needed
#else
// shortage of pins for non-Mega boards
#define DATAPORTH PORTD // 0-7
#define DATAPORTL PORTB // 8-13
#define DATADIRH DDRD
#define DATADIRL DDRB
// shortage of pins for non-Mega boards
#define DATAPORTH PORTD // 0-7
#define DATAPORTL PORTB // 8-13
#define DATADIRH DDRD
#define DATADIRL DDRB
#endif

class PPI16 {
Expand Down Expand Up @@ -72,29 +83,55 @@ class PPI16 {

void writeCmd(uint8_t b) {
cbi(registerRS, bitmaskRS);
DATAPORTH = 0; DATAPORTL = b; pulse_low(registerWR, bitmaskWR);
#if defined(__arm__)
LCD_Writ_Bus(0x00, b);
#else
DATAPORTH = 0; DATAPORTL = b; pulse_low(registerWR, bitmaskWR);
#endif
}

void writeData(uint8_t data) {
sbi(registerRS, bitmaskRS);
DATAPORTH = 0; DATAPORTL = data; pulse_low(registerWR, bitmaskWR);
}
#if defined(__arm__)
LCD_Writ_Bus(0x00, data);
#else
DATAPORTH = 0; DATAPORTL = data; pulse_low(registerWR, bitmaskWR);
#endif
}

void writeData(uint8_t hi, uint8_t lo) {
sbi(registerRS, bitmaskRS);
DATAPORTH = hi; DATAPORTL = lo; pulse_low(registerWR, bitmaskWR);
}
#if defined(__arm__)
LCD_Writ_Bus(hi, lo);
#else
DATAPORTH = hi; DATAPORTL = lo; pulse_low(registerWR, bitmaskWR);
#endif
}

void writeDataTwice(uint8_t b) {
sbi(registerRS, bitmaskRS);
#if defined(__arm__)
LCD_Writ_Bus(b, b);
#else
DATAPORTH = b; DATAPORTL = b; pulse_low(registerWR, bitmaskWR);
}
#endif
}

void writeCmdData(uint8_t cmd, uint16_t data) {
writeCmd(cmd);
writeData(highByte(data), lowByte(data));
}

// Copy from UTFT Lib.
void _set_direction_registers()
{
REG_PIOA_OER = 0x0000c000; //PA14,PA15 enable
REG_PIOB_OER = 0x04000000; //PB26 enable
REG_PIOD_OER = 0x0000064f; //PD0-3,PD6,PD9-10 enable
REG_PIOA_OER = 0x00000080; //PA7 enable
REG_PIOC_OER = 0x0000003e; //PC1 - PC5 enable
}

public:
/**
* Overrides SPI pins
Expand Down Expand Up @@ -123,13 +160,33 @@ class PPI16 {
inline void registerSelect() {
sbi(registerRS, bitmaskRS);
}


// Modified version from UTFT Lib
inline void LCD_Writ_Bus(char VH, char VL)
{
REG_PIOA_CODR = 0x0000C080;
REG_PIOC_CODR = 0x0000003E;
REG_PIOD_CODR = 0x0000064F;
REG_PIOA_SODR = ((VH & 0x06) << 13) | ((VL & 0x40) << 1);
(VH & 0x01) ? REG_PIOB_SODR = 0x4000000 : REG_PIOB_CODR = 0x4000000;
REG_PIOC_SODR = ((VL & 0x01) << 5) | ((VL & 0x02) << 3) | ((VL & 0x04) << 1) | ((VL & 0x08) >> 1) | ((VL & 0x10) >> 3);
REG_PIOD_SODR = ((VH & 0x78) >> 3) | ((VH & 0x80) >> 1) | ((VL & 0x20) << 5) | ((VL & 0x80) << 2);
pulse_low(registerWR, bitmaskWR);
}
};

void PPI16::initInterface() {


#if defined(__arm__)
_set_direction_registers();
#else
DATADIRH = 0xFF;
DATADIRL = 0xFF;

#endif

registerRS = portOutputRegister(digitalPinToPort(pinRS));
registerWR = portOutputRegister(digitalPinToPort(pinWR));
registerCS = portOutputRegister(digitalPinToPort(pinCS));
Expand All @@ -151,6 +208,10 @@ void PPI16::initInterface() {
pinMode(pinCS,OUTPUT);
pinMode(pinRST,OUTPUT);

#if defined(__arm__)
_set_direction_registers();
#endif

reset();
}
#endif
21 changes: 19 additions & 2 deletions Pixels_SSD1289.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
* - Andreas Schiffler -- aschiffler at ferzkopp dot net (SDL_gfx Project)
* - K. Townsend http://microBuilder.eu (lpc1343codebase Project)
*/

/*
* Added support for Arduino Due including the 1.5.8 IDE
* Currently tested with Arduino Due + TFT320QVT (SSD1289) + TFT Mega Shield V1.1 by Lseeduino (you can also hook it directly to the Due)
*
* Collaborator: CMBSolutions
* Date: December, 20 2014
* Contact: git@cmbsolutions.nl
*/

/*
* Pixels port to SSD1289 controller, PPI16 mode (TFT_320QVT)
Expand Down Expand Up @@ -202,10 +211,18 @@ void Pixels::setRegion(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
}

if (x2 < x1) {
swap(x1, x2);
#if defined(dueSwap)
swap(int16_t, x1, x2);
#else
swap(x1, x2);
#endif
}
if (y2 < y1) {
swap(y1, y2);
#if defined(dueSwap)
swap(int16_t, y1, y2);
#else
swap(y1, y2);
#endif
}
}

Expand Down