Skip to content

Commit bc354a9

Browse files
committed
busified
1 parent 73b133e commit bc354a9

File tree

2 files changed

+27
-77
lines changed

2 files changed

+27
-77
lines changed

Adafruit_EPD.cpp

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,8 @@
3333
*
3434
*/
3535

36-
#ifdef __AVR__
37-
#include <avr/pgmspace.h>
38-
#elif defined(ESP8266) || defined(ESP32)
39-
#include <pgmspace.h>
40-
#else
41-
#define pgm_read_byte(addr) \
42-
(*(const unsigned char *)(addr)) ///< read bytes from program memory
43-
#endif
44-
45-
#if !defined(__ARM_ARCH) && !defined(ENERGIA) && !defined(ESP8266) && \
46-
!defined(ESP32) && !defined(__arc__)
47-
#include <util/delay.h>
48-
#endif
49-
50-
#include <stdlib.h>
51-
5236
#include "Adafruit_EPD.h"
37+
#include <stdlib.h>
5338

5439
bool Adafruit_EPD::_isInTransaction = false;
5540

@@ -75,21 +60,18 @@ Adafruit_EPD::Adafruit_EPD(int width, int height, int8_t spi_mosi,
7560
_cs_pin = CS;
7661
_reset_pin = RST;
7762
_dc_pin = DC;
78-
_sclk_pin = spi_clock;
79-
_sid_pin = spi_mosi;
8063
_busy_pin = BUSY;
8164
if (SRCS >= 0) {
8265
use_sram = true;
8366
} else {
8467
use_sram = false;
8568
}
86-
hwSPI = false;
8769

8870
spi_dev = new Adafruit_SPIDevice(CS, spi_clock, spi_miso, spi_mosi,
89-
1000000, // frequency
71+
4000000, // frequency
9072
SPI_BITORDER_MSBFIRST, // bit order
91-
SPI_MODE0 // data mode
92-
);
73+
SPI_MODE0 // data mode
74+
);
9375

9476
singleByteTxns = false;
9577
buffer1_size = buffer2_size = 0;
@@ -125,13 +107,12 @@ Adafruit_EPD::Adafruit_EPD(int width, int height, int8_t DC, int8_t RST,
125107
} else {
126108
use_sram = false;
127109
}
128-
hwSPI = true;
129110

130111
spi_dev = new Adafruit_SPIDevice(CS,
131-
1000000, // frequency
112+
4000000, // frequency
132113
SPI_BITORDER_MSBFIRST, // bit order
133-
SPI_MODE0 // data mode
134-
);
114+
SPI_MODE0, // data mode
115+
_spi);
135116

136117
singleByteTxns = false;
137118
buffer1_size = buffer2_size = 0;
@@ -577,35 +558,14 @@ void Adafruit_EPD::EPD_data(uint8_t data) {
577558
uint8_t Adafruit_EPD::SPItransfer(uint8_t d) {
578559
// Serial.print("-> 0x"); Serial.println((byte)d, HEX);
579560

580-
if (hwSPI) {
581-
if (singleByteTxns) {
582-
uint8_t b;
583-
csLow();
584-
b = _spi->transfer(d);
585-
csHigh();
586-
return b;
587-
} else
588-
return _spi->transfer(d);
561+
if (singleByteTxns) {
562+
uint8_t b;
563+
csLow();
564+
b = spi_dev->transfer(d);
565+
csHigh();
566+
return b;
589567
} else {
590-
// TODO: return read data for software SPI
591-
for (uint8_t bit = 0x80; bit; bit >>= 1) {
592-
#ifdef HAVE_PORTREG
593-
*clkport &= ~clkpinmask;
594-
if (d & bit)
595-
*mosiport |= mosipinmask;
596-
else
597-
*mosiport &= ~mosipinmask;
598-
*clkport |= clkpinmask;
599-
#else
600-
digitalWrite(_sclk_pin, LOW);
601-
if (d & bit)
602-
digitalWrite(_sid_pin, HIGH);
603-
else
604-
digitalWrite(_sid_pin, LOW);
605-
digitalWrite(_sclk_pin, HIGH);
606-
#endif
607-
}
608-
return 0;
568+
return spi_dev->transfer(d);
609569
}
610570
}
611571

@@ -622,11 +582,8 @@ void Adafruit_EPD::csHigh() {
622582
digitalWrite(_cs_pin, HIGH);
623583
#endif
624584

625-
#ifdef SPI_HAS_TRANSACTION
626-
_spi->endTransaction();
585+
spi_dev->endTransaction();
627586
_isInTransaction = false;
628-
#endif
629-
630587
}
631588

632589
/**************************************************************************/
@@ -635,20 +592,14 @@ void Adafruit_EPD::csHigh() {
635592
*/
636593
/**************************************************************************/
637594
void Adafruit_EPD::csLow() {
638-
639-
#ifdef SPI_HAS_TRANSACTION
640-
if (!_isInTransaction) {
641-
_spi->beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
642-
_isInTransaction = true;
643-
}
644-
#endif
595+
spi_dev->beginTransaction();
596+
_isInTransaction = true;
645597

646598
#ifdef BUSIO_USE_FAST_PINIO
647599
*csPort &= ~csPinMask;
648600
#else
649601
digitalWrite(_cs_pin, LOW);
650602
#endif
651-
652603
}
653604

654605
/**************************************************************************/

Adafruit_EPD.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
#define RAMBUFSIZE 64 ///< size of the ram buffer
2626

27-
#include <Adafruit_SPIDevice.h>
2827
#include "Adafruit_MCPSRAM.h"
2928
#include <Adafruit_GFX.h>
29+
#include <Adafruit_SPIDevice.h>
3030

3131
/**************************************************************************/
3232
/*!
@@ -115,15 +115,15 @@ class Adafruit_EPD : public Adafruit_GFX {
115115
virtual void powerDown(void) = 0;
116116
void hardwareReset(void);
117117

118-
int8_t _sid_pin, ///< sid pin
119-
_sclk_pin, ///< serial clock pin
120-
_dc_pin, ///< data/command pin
121-
_reset_pin, ///< reset pin
122-
_cs_pin, ///< chip select pin
123-
_busy_pin; ///< busy pin
124-
SPIClass *_spi = NULL; ///< SPI object
125-
Adafruit_SPIDevice *spi_dev = NULL; ///< SPI object
126-
static bool _isInTransaction; ///< true if SPI bus is in trasnfer state
118+
int8_t _sid_pin, ///< sid pin
119+
_sclk_pin, ///< serial clock pin
120+
_dc_pin, ///< data/command pin
121+
_reset_pin, ///< reset pin
122+
_cs_pin, ///< chip select pin
123+
_busy_pin; ///< busy pin
124+
SPIClass *_spi = NULL; ///< SPI object
125+
Adafruit_SPIDevice *spi_dev = NULL; ///< SPI object
126+
static bool _isInTransaction; ///< true if SPI bus is in trasnfer state
127127
bool singleByteTxns; ///< if true CS will go high after every data byte
128128
///< transferred
129129
Adafruit_MCPSRAM sram; ///< the ram chip object if using off-chip ram
@@ -154,7 +154,6 @@ class Adafruit_EPD : public Adafruit_GFX {
154154
bool use_sram; ///< true if we are using an SRAM chip as a framebuffer
155155
bool hwSPI; ///< true if using hardware SPI
156156

157-
158157
#if defined(BUSIO_USE_FAST_PINIO)
159158
BusIO_PortReg *csPort, *dcPort;
160159
BusIO_PortMask csPinMask, dcPinMask;

0 commit comments

Comments
 (0)