aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlaser-tag software/CMakeLists.txt1
-rw-r--r--laser-tag software/epaper.c66
-rwxr-xr-xlaser-tag software/main.c14
3 files changed, 79 insertions, 2 deletions
diff --git a/laser-tag software/CMakeLists.txt b/laser-tag software/CMakeLists.txt
index 86f77de..7203805 100755
--- a/laser-tag software/CMakeLists.txt
+++ b/laser-tag software/CMakeLists.txt
@@ -99,6 +99,7 @@ ADD_EXECUTABLE(hello_world
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/lpuart/fsl_lpuart_irq.c"
"${ProjDirPath}/../KSDK_1.2.0/platform/drivers/src/spi/fsl_spi_irq.c"
"${ProjDirPath}/main.c"
+ "${ProjDirPath}/epaper.c"
)
SET_TARGET_PROPERTIES(hello_world PROPERTIES OUTPUT_NAME "hello_world.elf")
diff --git a/laser-tag software/epaper.c b/laser-tag software/epaper.c
new file mode 100644
index 0000000..d4e7d81
--- /dev/null
+++ b/laser-tag software/epaper.c
@@ -0,0 +1,66 @@
+#include "fsl_gpio_driver.h"
+#include "fsl_spi_master_driver.h"
+
+static const gpio_output_pin_user_config_t pinReset = {
+ .pinName = GPIO_MAKE_PIN(GPIOA_IDX, 20),
+ .config.outputLogic = 0, // XXX
+};
+
+static const gpio_output_pin_user_config_t pinDischarge = {
+ .pinName = GPIO_MAKE_PIN(GPIOA_IDX, 19),
+ .config.outputLogic = 0,
+};
+
+static const spi_master_user_config_t spiConfig = {
+ .bitsPerSec = 4000000, /* 4 MHz, max is 20 MHz */
+ .polarity = kSpiClockPolarity_ActiveHigh,
+ .phase = kSpiClockPhase_FirstEdge,
+ .direction = kSpiMsbFirst,
+ .bitCount = kSpi8BitMode,
+};
+
+static spi_master_state_t spiState;
+
+extern void led(uint8_t red, uint8_t green, uint8_t blue);
+
+void EPD_Init()
+{
+ PORT_HAL_SetMuxMode(g_portBase[GPIOA_IDX], 19, kPortMuxAsGpio);
+ PORT_HAL_SetMuxMode(g_portBase[GPIOA_IDX], 20, kPortMuxAsGpio);
+ PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 4, kPortMuxAlt2);
+ PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 5, kPortMuxAlt2);
+ PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 6, kPortMuxAlt2);
+ PORT_HAL_SetMuxMode(g_portBase[GPIOD_IDX], 7, kPortMuxAlt2);
+ GPIO_DRV_OutputPinInit(&pinReset);
+ GPIO_DRV_OutputPinInit(&pinDischarge);
+ SPI_DRV_MasterInit(1, &spiState);
+ uint32_t calculatedBaudRate;
+ SPI_DRV_MasterConfigureBus(1, &spiConfig, &calculatedBaudRate);
+}
+
+void EPD_Draw()
+{
+ /* Reset */
+ GPIO_DRV_WritePinOutput(pinReset.pinName, 0);
+ int i;
+ for(i = 0; i < 0xffff; ++i);
+ //GPIO_DRV_WritePinOutput(pinReset.pinName, 1);
+
+ uint8_t tx[2], rx[2];
+
+ tx[0] = 0x71;
+ tx[1] = 0x00;
+ SPI_DRV_MasterTransferBlocking(1, NULL, tx, rx, 2, 1);
+ SPI_DRV_MasterTransferBlocking(1, NULL, tx, rx, 2, 1);
+ if ((rx[1] & 0x0f) != 0x02) {
+ led(0xff, 0x00, 0x00);
+ } else {
+ led(0x00, 0xff, 0x00);
+ }
+
+ /* Shutdown */
+ GPIO_DRV_WritePinOutput(pinDischarge.pinName, 1);
+ GPIO_DRV_WritePinOutput(pinDischarge.pinName, 0);
+}
+
+/* vim: set expandtab ts=4 sw=4: */
diff --git a/laser-tag software/main.c b/laser-tag software/main.c
index 53a381e..a2dc21d 100755
--- a/laser-tag software/main.c
+++ b/laser-tag software/main.c
@@ -235,17 +235,21 @@ static flexio_shifter_config_t g_shifterConfig = {
.sstart = kFlexioShifterStartBitDisabledLoadDataOnEnable,
};
+
+extern void EPD_Init();
+extern void EPD_Draw();
+
///////
// Code
static cmp_state_t g_cmpState;
-static dma_channel_t g_dacChan, g_fioChan;
+static dma_channel_t g_fioChan;
static lpuart_state_t g_lpuartState;
static uint8_t rxBuff[1];
static uint32_t shift0_buf[3];
static uint32_t blank_led;
-static void led(uint8_t red, uint8_t green, uint8_t blue)
+void led(uint8_t red, uint8_t green, uint8_t blue)
{
FLEXIO_Type *fiobase = g_flexioBase[0];
uint32_t color = (green << 16) | (red << 8) | blue;
@@ -521,6 +525,12 @@ int main (void)
/* Blank LED just in case, saves power */
led(0x00, 0x00, 0x00);
+ /* Init e-paper display */
+ EPD_Init();
+
+ /* Draw something */
+ EPD_Draw();
+
/* We're done, everything else is triggered through interrupts */
for(;;) {
#ifndef DEBUG