aboutsummaryrefslogtreecommitdiff
path: root/laser-tag software
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2016-07-03 22:11:27 -0500
committerDavid Barksdale <amatus@amatus.name>2016-07-03 22:11:27 -0500
commitc1a714ad3119d16632b6ef6c52b30aaad26d1f5e (patch)
treeac925d142f38f94f81f8b7d07124f4dbbcf2bb33 /laser-tag software
parent58ab4873d12baf0d0ba5862e2f6c84179bceec53 (diff)
Don't bother with DMA since we're busy-waiting
Diffstat (limited to 'laser-tag software')
-rw-r--r--laser-tag software/CMakeLists.txt2
-rw-r--r--laser-tag software/epaper.c62
-rw-r--r--laser-tag software/epaper.h1
-rw-r--r--laser-tag software/main.c6
4 files changed, 30 insertions, 41 deletions
diff --git a/laser-tag software/CMakeLists.txt b/laser-tag software/CMakeLists.txt
index 1861b60..92bc6d1 100644
--- a/laser-tag software/CMakeLists.txt
+++ b/laser-tag software/CMakeLists.txt
@@ -97,7 +97,7 @@ ADD_EXECUTABLE(hello_world
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/flexio/fsl_flexio_irq.c"
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/lptmr/fsl_lptmr_irq.c"
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/lpuart/fsl_lpuart_irq.c"
- "${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/spi/fsl_spi_dma_irq.c"
+ "${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/spi/fsl_spi_irq.c"
"${ProjDirPath}/main.c"
"${ProjDirPath}/epaper.c"
"${ProjDirPath}/text.c"
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;
}
diff --git a/laser-tag software/epaper.h b/laser-tag software/epaper.h
index e72a74d..26e1815 100644
--- a/laser-tag software/epaper.h
+++ b/laser-tag software/epaper.h
@@ -5,6 +5,5 @@
void EPD_Init();
int EPD_Draw(const uint8_t *old_image, const uint8_t *new_image);
-void EPD_Tick();
#endif
diff --git a/laser-tag software/main.c b/laser-tag software/main.c
index de48d95..0dfbac2 100644
--- a/laser-tag software/main.c
+++ b/laser-tag software/main.c
@@ -324,9 +324,6 @@ static void lptmr_call_back(void)
}
blank_led--;
}
-
- /* kick EPD driver every once in a while */
- EPD_Tick();
}
/* Play music using the PIT timer */
@@ -586,9 +583,6 @@ int main (void)
}
blank_led = 30;
- /* Deinit so we can mess around on the bus pirate */
- //EPD_Deinit();
-
/* We're done, everything else is triggered through interrupts */
for(;;) {
if (cue_next_image) {