Skip to content

Commit de5bda2

Browse files
committed
K66 test
1 parent 74bfea6 commit de5bda2

File tree

3 files changed

+601
-27
lines changed

3 files changed

+601
-27
lines changed

SSD_13XX.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void SSD_13XX::begin(bool avoidSPIinit)
225225
digitalWriteFast(_cs,HIGH);
226226
#endif
227227
enableDataStream();
228-
#elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
228+
#elif defined(__MK20DX128__) || defined(__MK20DX256__)//Teensy 3.0 -> 3.2
229229
if ((_mosi == 11 || _mosi == 7) && (_sclk == 13 || _sclk == 14)) {
230230
SPI.setMOSI(_mosi);
231231
SPI.setSCK(_sclk);
@@ -243,6 +243,42 @@ void SSD_13XX::begin(bool avoidSPIinit)
243243
bitSet(_initError,1);
244244
return;
245245
}
246+
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)//Teensy 3.4 -> 3.5
247+
if ((_mosi == 11 || _mosi == 7) && (_sclk == 13 || _sclk == 14)) {
248+
// ------------ SPI0 ---------------
249+
_useSPI = 0;
250+
SPI.setMOSI(_mosi);
251+
SPI.setSCK(_sclk);
252+
if (!avoidSPIinit) SPI.begin();
253+
if (SPI.pinIsChipSelect(_cs, _dc)) {
254+
pcs_data = SPI.setCS(_cs);
255+
pcs_command = pcs_data | SPI.setCS(_dc);
256+
} else {
257+
bitSet(_initError,1);
258+
return;
259+
}
260+
} else if (_mosi == 0 && _sclk == 32) {
261+
// ------------ SPI1 ---------------
262+
// [hint], instead assign CS I'm assigning DC that will be much busy
263+
// CS will be handled separately by startTransition and command/data_last
264+
_useSPI = 1;
265+
SPI1.setMOSI(_mosi);
266+
SPI1.setSCK(_sclk);
267+
pinMode(_cs, OUTPUT);
268+
disableCS();
269+
if (!avoidSPIinit) SPI1.begin();
270+
if (SPI1.pinIsChipSelect(_dc)) {
271+
pcs_data = 0;
272+
pcs_command = pcs_data | SPI1.setCS(_dc);
273+
} else {
274+
bitSet(_initError,1);
275+
return;
276+
}
277+
// TODO SPI2 --------------------------
278+
} else {
279+
bitSet(_initError,0);
280+
return;
281+
}
246282
#elif defined(ESP8266)//(arm) XTENSA ESP8266
247283
pinMode(_dc, OUTPUT);
248284
pinMode(_cs, OUTPUT);

SSD_13XX.h

Lines changed: 162 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
SSD_13XX - A fast SPI driver for several Solomon Systech SSD13xx series driver
3-
Version: 1.0r3, beta release
3+
Version: 1.0r3, beta release (K64/K66 testing)
44
55
https://github.com/sumotoy/SSD_13XX
66
@@ -236,7 +236,9 @@ class SSD_13XX : public Print {
236236
volatile int16_t _width, _height, _cursorX, _cursorY;
237237
volatile bool _filled;
238238
volatile uint8_t _remapReg;
239-
239+
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
240+
uint8_t _useSPI;
241+
#endif
240242
/* ========================================================================
241243
Low Level SPI Routines
242244
========================================================================*/
@@ -416,76 +418,210 @@ class SSD_13XX : public Print {
416418
uint8_t pcs_data, pcs_command;
417419
uint8_t _mosi, _sclk;
418420
uint8_t _cs,_dc;
419-
421+
420422
void startTransaction(void)
421423
__attribute__((always_inline)) {
422-
SPI.beginTransaction(SSD_13XXSPI);
424+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
425+
SPI.beginTransaction(SSD_13XXSPI);
426+
#else
427+
if (_useSPI == 0){
428+
SPI.beginTransaction(SSD_13XXSPI);
429+
} else if (_useSPI == 1){
430+
SPI1.beginTransaction(SSD_13XXSPI);
431+
digitalWriteFast(_cs,LOW);
432+
}
433+
#endif
423434
}
424435

425436
void endTransaction(void)
426437
__attribute__((always_inline)) {
427-
SPI.endTransaction();
438+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
439+
SPI.endTransaction();
440+
#else
441+
if (_useSPI == 0){
442+
SPI.endTransaction();
443+
} else if (_useSPI == 1){
444+
SPI1.endTransaction();
445+
}
446+
#endif
447+
}
448+
449+
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
450+
void disableCS(void)
451+
__attribute__((always_inline)) {
452+
if (_useSPI > 0) digitalWriteFast(_cs,HIGH);
428453
}
454+
#endif
429455

430456
//Here's Paul Stoffregen SPI FIFO magic in action...
431457
void waitFifoNotFull(void) {
432458
uint32_t sr;
433459
uint32_t tmp __attribute__((unused));
460+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
434461
do {
435462
sr = KINETISK_SPI0.SR;
436463
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR; // drain RX FIFO
437464
} while ((sr & (15 << 12)) > (3 << 12));
465+
#else
466+
if (_useSPI == 0){
467+
do {
468+
sr = KINETISK_SPI0.SR;
469+
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR; // drain RX FIFO
470+
} while ((sr & (15 << 12)) > (3 << 12));
471+
} else if (_useSPI == 1){
472+
do {
473+
sr = KINETISK_SPI1.SR;
474+
if (sr & 0xF0) tmp = KINETISK_SPI1.POPR; // drain RX FIFO
475+
} while ((sr & (15 << 12)) > (0 << 12));
476+
}
477+
#endif
438478
}
439479

440480
void waitTransmitComplete(uint32_t mcr) __attribute__((always_inline)) {
441481
uint32_t tmp __attribute__((unused));
442-
while (1) {
443-
uint32_t sr = KINETISK_SPI0.SR;
444-
if (sr & SPI_SR_EOQF) break; // wait for last transmit
445-
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR;
446-
}
447-
KINETISK_SPI0.SR = SPI_SR_EOQF;
448-
SPI0_MCR = mcr;
449-
while (KINETISK_SPI0.SR & 0xF0) {tmp = KINETISK_SPI0.POPR;}
482+
uint32_t sr = 0;
483+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
484+
while (1) {
485+
sr = KINETISK_SPI0.SR;
486+
if (sr & SPI_SR_EOQF) break; // wait for last transmit
487+
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR;
488+
}
489+
KINETISK_SPI0.SR = SPI_SR_EOQF;
490+
SPI0_MCR = mcr;
491+
while (KINETISK_SPI0.SR & 0xF0) {tmp = KINETISK_SPI0.POPR;}
492+
#else
493+
if (_useSPI == 0){
494+
while (1) {
495+
sr = KINETISK_SPI0.SR;
496+
if (sr & SPI_SR_EOQF) break; // wait for last transmit
497+
if (sr & 0xF0) tmp = KINETISK_SPI0.POPR;
498+
}
499+
KINETISK_SPI0.SR = SPI_SR_EOQF;
500+
SPI0_MCR = mcr;
501+
while (KINETISK_SPI0.SR & 0xF0) {tmp = KINETISK_SPI0.POPR;}
502+
} else if (_useSPI == 1){
503+
while (1) {
504+
sr = KINETISK_SPI1.SR;
505+
if (sr & SPI_SR_EOQF) break; // wait for last transmit
506+
if (sr & 0xF0) tmp = KINETISK_SPI1.POPR;
507+
}
508+
KINETISK_SPI1.SR = SPI_SR_EOQF;
509+
SPI1_MCR = mcr;
510+
while (KINETISK_SPI1.SR & 0xF0) {tmp = KINETISK_SPI1.POPR;}
511+
}
512+
#endif
450513
}
451514

452515
void writecommand_cont(const uint8_t c) __attribute__((always_inline)) {
453-
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
516+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
517+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
518+
#else
519+
if (_useSPI == 0){
520+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
521+
} else if (_useSPI == 1){
522+
KINETISK_SPI1.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
523+
}
524+
#endif
454525
waitFifoNotFull();
455526
}
456-
457-
void writecommand16_cont(uint16_t c) __attribute__((always_inline)) {
458-
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
527+
528+
void writecommand16_cont(const uint8_t c) __attribute__((always_inline)) {
529+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
530+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
531+
#else
532+
if (_useSPI == 0){
533+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
534+
} else if (_useSPI == 1){
535+
KINETISK_SPI1.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
536+
}
537+
#endif
459538
waitFifoNotFull();
460539
}
461540

462541
void writedata8_cont(uint8_t d) __attribute__((always_inline)) {
463-
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
542+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
543+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
544+
#else
545+
if (_useSPI == 0){
546+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
547+
} else if (_useSPI == 1){
548+
KINETISK_SPI1.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
549+
}
550+
#endif
464551
waitFifoNotFull();
465552
}
466553

467554
void writedata16_cont(uint16_t d) __attribute__((always_inline)) {
468-
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
555+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
556+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
557+
#else
558+
if (_useSPI == 0){
559+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
560+
} else if (_useSPI == 1){
561+
KINETISK_SPI1.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_CONT;
562+
}
563+
#endif
469564
waitFifoNotFull();
470565
}
471566

472567
void writecommand_last(const uint8_t c) __attribute__((always_inline)) {
473-
uint32_t mcr = SPI0_MCR;
474-
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
568+
uint32_t mcr = 0;
569+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
570+
mcr = SPI0_MCR;
571+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
572+
#else
573+
if (_useSPI == 0){
574+
mcr = SPI0_MCR;
575+
KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
576+
} else if (_useSPI == 1){
577+
mcr = SPI1_MCR;
578+
KINETISK_SPI1.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
579+
}
580+
#endif
475581
waitTransmitComplete(mcr);
582+
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
583+
disableCS();
584+
#endif
476585
}
477586

478-
479587
void writedata8_last(uint8_t c) __attribute__((always_inline)) {
480-
uint32_t mcr = SPI0_MCR;
481-
KINETISK_SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
588+
uint32_t mcr = 0;
589+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
590+
mcr = SPI0_MCR;
591+
KINETISK_SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
592+
#else
593+
if (_useSPI == 0){
594+
mcr = SPI0_MCR;
595+
KINETISK_SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
596+
} else if (_useSPI == 1){
597+
mcr = SPI1_MCR;
598+
KINETISK_SPI1.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_EOQ;
599+
}
600+
#endif
482601
waitTransmitComplete(mcr);
602+
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
603+
disableCS();
604+
#endif
483605
}
484606

485607
void writedata16_last(uint16_t d) __attribute__((always_inline)) {
486-
uint32_t mcr = SPI0_MCR;
487-
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_EOQ;
608+
uint32_t mcr = 0;
609+
#if defined(__MK20DX128__) || defined(__MK20DX256__)
610+
mcr = SPI0_MCR;
611+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_EOQ;
612+
#else
613+
if (_useSPI == 0){
614+
mcr = SPI0_MCR;
615+
KINETISK_SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_EOQ;
616+
} else if (_useSPI == 1){
617+
mcr = SPI1_MCR;
618+
KINETISK_SPI1.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1) | SPI_PUSHR_EOQ;
619+
}
620+
#endif
488621
waitTransmitComplete(mcr);
622+
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
623+
disableCS();
624+
#endif
489625
}
490626

491627
/* ----------------- ARM (XTENSA ESP8266) ------------------------*/

0 commit comments

Comments
 (0)