2022-04-25 07:13:41 +02:00
|
|
|
#include "../configuration.h"
|
|
|
|
|
|
2023-07-03 16:34:32 +02:00
|
|
|
#ifdef RAK_4631
|
2022-04-25 07:13:41 +02:00
|
|
|
#include "../main.h"
|
|
|
|
|
#include <SPI.h>
|
|
|
|
|
|
|
|
|
|
void d_writeCommand(uint8_t c)
|
|
|
|
|
{
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
2023-01-21 14:34:29 +01:00
|
|
|
if (PIN_EINK_DC >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_DC, LOW);
|
|
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_CS, LOW);
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.transfer(c);
|
2023-01-21 14:34:29 +01:00
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_CS, HIGH);
|
|
|
|
|
if (PIN_EINK_DC >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_DC, HIGH);
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.endTransaction();
|
2022-04-25 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void d_writeData(uint8_t d)
|
|
|
|
|
{
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
2023-01-21 14:34:29 +01:00
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_CS, LOW);
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.transfer(d);
|
2023-01-21 14:34:29 +01:00
|
|
|
if (PIN_EINK_CS >= 0)
|
|
|
|
|
digitalWrite(PIN_EINK_CS, HIGH);
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.endTransaction();
|
2022-04-25 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long d_waitWhileBusy(uint16_t busy_time)
|
|
|
|
|
{
|
2023-01-21 14:34:29 +01: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 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void scanEInkDevice(void)
|
|
|
|
|
{
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.begin();
|
2022-04-25 07:13:41 +02:00
|
|
|
d_writeCommand(0x22);
|
|
|
|
|
d_writeData(0x83);
|
|
|
|
|
d_writeCommand(0x20);
|
|
|
|
|
eink_found = (d_waitWhileBusy(150) > 0) ? true : false;
|
2023-01-21 14:34:29 +01:00
|
|
|
if (eink_found)
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("EInk display found");
|
2022-04-25 07:13:41 +02:00
|
|
|
else
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("EInk display not found");
|
2025-02-14 19:53:22 +01:00
|
|
|
SPI.end();
|
2022-04-25 07:13:41 +02:00
|
|
|
}
|
2023-07-03 16:34:32 +02:00
|
|
|
#endif
|