aboutsummaryrefslogtreecommitdiff
path: root/laser-tag software/epaper.c
diff options
context:
space:
mode:
Diffstat (limited to 'laser-tag software/epaper.c')
-rw-r--r--laser-tag software/epaper.c62
1 files changed, 29 insertions, 33 deletions
diff --git a/laser-tag software/epaper.c b/laser-tag software/epaper.c
index a1c6391..fb4d8ef 100644
--- a/laser-tag software/epaper.c
+++ b/laser-tag software/epaper.c
@@ -1,6 +1,6 @@
#include "epaper.h"
#include "fsl_gpio_driver.h"
-#include "fsl_spi_dma_master_driver.h"
+#include "fsl_spi_master_driver.h"
typedef enum { /* Image pixel -> Display pixel */
EPD_compensate, /* B -> W, W -> B (Current Image) */
@@ -19,7 +19,7 @@ static const gpio_output_pin_user_config_t pinCS = {
.config.outputLogic = 1,
};
-static const spi_dma_master_user_config_t spiConfig = {
+static const spi_master_user_config_t spiConfig = {
.bitsPerSec = 2000000, /* 2 MHz, max is 20 MHz */
.polarity = kSpiClockPolarity_ActiveHigh,
.phase = kSpiClockPhase_FirstEdge,
@@ -35,8 +35,7 @@ static const int LINES_PER_DISPLAY = 128;
static const int BYTES_PER_SCAN = 128 / 4 / 2;
static const int BYTES_PER_LINE = 232 / 8;
-static spi_dma_master_state_t spiState;
-static uint32_t dma_timeout;
+static spi_master_state_t spiState;
void EPD_Init()
{
@@ -50,31 +49,26 @@ void EPD_Init()
GPIO_DRV_OutputPinInit(&pinCS);
}
-void EPD_Tick()
-{
- if (!dma_timeout) {
- return;
- }
- if (dma_timeout == 1) {
- SPI_DRV_DmaMasterAbortTransfer(1);
- return;
- }
- dma_timeout--;
- return;
-}
-
-spi_status_t SPI_Transfer(const uint8_t *tx, uint8_t *rx, size_t count)
+static spi_status_t SPI_Transfer(const uint8_t *tx, uint8_t *rx, size_t count)
{
spi_status_t rc;
- dma_timeout = (count + 127) / 128 + 1;
- rc = SPI_DRV_DmaMasterTransferBlocking(1, NULL, tx, rx, count,
- kSpiDmaWaitForever);
- dma_timeout = 0;
+ rc = SPI_DRV_MasterTransfer(1, NULL, tx, rx, count);
+ if (rc != kStatus_SPI_Success) {
+ return rc;
+ }
+ int i, timeout = (count + 127) / 128 + 1;
+ for (i = 0; i < timeout; ++i) {
+ rc = SPI_DRV_MasterGetTransferStatus(1, NULL);
+ if (rc == kStatus_SPI_Success) {
+ return rc;
+ }
+ }
return rc;
}
-void EPD_WriteCommandBuffer(uint8_t index, const uint8_t *data, size_t length)
+static void EPD_WriteCommandBuffer(uint8_t index, const uint8_t *data,
+ size_t length)
{
uint8_t tx[3] = { 0x70, index, 0x72 };
@@ -87,12 +81,12 @@ void EPD_WriteCommandBuffer(uint8_t index, const uint8_t *data, size_t length)
GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
}
-void EPD_WriteCommandByte(uint8_t index, uint8_t data)
+static void EPD_WriteCommandByte(uint8_t index, uint8_t data)
{
EPD_WriteCommandBuffer(index, &data, 1);
}
-uint8_t EPD_ReadCommand(uint8_t index)
+static uint8_t EPD_ReadCommand(uint8_t index)
{
uint8_t tx[4] = { 0x70, index, 0x73, 0x00 };
uint8_t rx[2];
@@ -106,7 +100,7 @@ uint8_t EPD_ReadCommand(uint8_t index)
return rx[1];
}
-uint8_t EPD_ReadCogID()
+static uint8_t EPD_ReadCogID()
{
uint8_t tx[2] = { 0x71, 0x00 };
uint8_t rx[2];
@@ -117,7 +111,7 @@ uint8_t EPD_ReadCogID()
return rx[1];
}
-void EPD_Delay(uint32_t ms)
+static void EPD_Delay(uint32_t ms)
{
for (; ms > 0; --ms) {
/* XXX This is really stupid */
@@ -126,7 +120,8 @@ void EPD_Delay(uint32_t ms)
}
}
-void EPD_line(int line, const uint8_t *data, uint8_t fixed_value, EPD_stage stage)
+static void EPD_line(int line, const uint8_t *data, uint8_t fixed_value,
+ EPD_stage stage)
{
size_t len = BYTES_PER_SCAN * 2 + BYTES_PER_LINE * 2 + 1;
uint8_t buf[len], *p = buf;
@@ -189,7 +184,7 @@ void EPD_line(int line, const uint8_t *data, uint8_t fixed_value, EPD_stage stag
EPD_WriteCommandByte(0x02, 0x07);
}
-void EPD_frame(const uint8_t *data, uint8_t fixed_value, EPD_stage stage)
+static void EPD_frame(const uint8_t *data, uint8_t fixed_value, EPD_stage stage)
{
int i;
if (data) {
@@ -203,7 +198,8 @@ void EPD_frame(const uint8_t *data, uint8_t fixed_value, EPD_stage stage)
}
}
-void EPD_frame_repeat(const uint8_t *data, uint8_t fixed_value, EPD_stage stage)
+static void EPD_frame_repeat(const uint8_t *data, uint8_t fixed_value,
+ EPD_stage stage)
{
/* TODO this needs to repeat for about 630ms */
int i;
@@ -217,9 +213,9 @@ int EPD_Draw(const uint8_t *old_image, const uint8_t *new_image)
int rc = 0;
/* Configure DMA channel */
- SPI_DRV_DmaMasterInit(1, &spiState);
+ SPI_DRV_MasterInit(1, &spiState);
uint32_t calculatedBaudRate;
- SPI_DRV_DmaMasterConfigureBus(1, &spiConfig, &calculatedBaudRate);
+ SPI_DRV_MasterConfigureBus(1, &spiConfig, &calculatedBaudRate);
/* read the COG ID */
uint8_t id = EPD_ReadCogID();
@@ -333,7 +329,7 @@ int EPD_Draw(const uint8_t *old_image, const uint8_t *new_image)
GPIO_DRV_WritePinOutput(pinDischarge.pinName, 0);
out:
- SPI_DRV_DmaMasterDeinit(1);
+ SPI_DRV_MasterDeinit(1);
return rc;
}