2022-04-25 05:13:41 +00:00
|
|
|
#include "../configuration.h"
|
|
|
|
|
|
|
|
#ifdef RAK4630
|
|
|
|
#include "../main.h"
|
|
|
|
#include <SPI.h>
|
|
|
|
|
|
|
|
void d_writeCommand(uint8_t c)
|
|
|
|
{
|
2023-01-21 13:34:29 +00:00
|
|
|
SPI1.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
|
|
|
if (PIN_EINK_DC >= 0)
|
|
|
|
digitalWrite(PIN_EINK_DC, LOW);
|
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
digitalWrite(PIN_EINK_CS, LOW);
|
|
|
|
SPI1.transfer(c);
|
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
digitalWrite(PIN_EINK_CS, HIGH);
|
|
|
|
if (PIN_EINK_DC >= 0)
|
|
|
|
digitalWrite(PIN_EINK_DC, HIGH);
|
|
|
|
SPI1.endTransaction();
|
2022-04-25 05:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void d_writeData(uint8_t d)
|
|
|
|
{
|
2023-01-21 13:34:29 +00:00
|
|
|
SPI1.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
digitalWrite(PIN_EINK_CS, LOW);
|
|
|
|
SPI1.transfer(d);
|
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
digitalWrite(PIN_EINK_CS, HIGH);
|
|
|
|
SPI1.endTransaction();
|
2022-04-25 05:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long d_waitWhileBusy(uint16_t busy_time)
|
|
|
|
{
|
2023-01-21 13:34:29 +00:00
|
|
|
if (PIN_EINK_BUSY >= 0) {
|
|
|
|
delay(1); // add some margin to become active
|
|
|
|
unsigned long start = micros();
|
|
|
|
while (1) {
|
|
|
|
if (digitalRead(PIN_EINK_BUSY) != HIGH)
|
|
|
|
break;
|
|
|
|
delay(1);
|
|
|
|
if (digitalRead(PIN_EINK_BUSY) != HIGH)
|
|
|
|
break;
|
|
|
|
if (micros() - start > 10000000)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unsigned long elapsed = micros() - start;
|
|
|
|
(void)start;
|
|
|
|
return elapsed;
|
|
|
|
} else
|
|
|
|
return busy_time;
|
2022-04-25 05:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void scanEInkDevice(void)
|
|
|
|
{
|
|
|
|
SPI1.begin();
|
|
|
|
d_writeCommand(0x22);
|
|
|
|
d_writeData(0x83);
|
|
|
|
d_writeCommand(0x20);
|
|
|
|
eink_found = (d_waitWhileBusy(150) > 0) ? true : false;
|
2023-01-21 13:34:29 +00:00
|
|
|
if (eink_found)
|
|
|
|
LOG_DEBUG("EInk display found\n");
|
2022-04-25 05:13:41 +00:00
|
|
|
else
|
2023-01-21 13:34:29 +00:00
|
|
|
LOG_DEBUG("EInk display not found\n");
|
2022-04-25 05:13:41 +00:00
|
|
|
SPI1.end();
|
|
|
|
}
|
|
|
|
#endif
|