aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2016-02-17 20:07:58 -0600
committerDavid Barksdale <amatus@amatus.name>2016-02-17 20:07:58 -0600
commita719f86c6d24e2263ef8d9e8efb1e539257644a4 (patch)
treef7249ca886153184903284e08d431b7b01ce62cb
parentc7cce36c6c395517e1f39bd915f93f26fa52783b (diff)
Talking to EPD now
Work in progress.
-rw-r--r--laser-tag software/epaper.c101
-rwxr-xr-xlaser-tag software/main.c15
2 files changed, 87 insertions, 29 deletions
diff --git a/laser-tag software/epaper.c b/laser-tag software/epaper.c
index d4e7d81..df3e9a1 100644
--- a/laser-tag software/epaper.c
+++ b/laser-tag software/epaper.c
@@ -1,18 +1,18 @@
#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 gpio_output_pin_user_config_t pinCS = {
+ .pinName = GPIO_MAKE_PIN(GPIOD_IDX, 4),
+ .config.outputLogic = 1,
+};
+
static const spi_master_user_config_t spiConfig = {
- .bitsPerSec = 4000000, /* 4 MHz, max is 20 MHz */
+ .bitsPerSec = 2000000, /* 2 MHz, max is 20 MHz */
.polarity = kSpiClockPolarity_ActiveHigh,
.phase = kSpiClockPhase_FirstEdge,
.direction = kSpiMsbFirst,
@@ -21,46 +21,93 @@ static const spi_master_user_config_t spiConfig = {
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], 4, kPortMuxAsGpio);
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);
+ GPIO_DRV_OutputPinInit(&pinCS);
SPI_DRV_MasterInit(1, &spiState);
uint32_t calculatedBaudRate;
SPI_DRV_MasterConfigureBus(1, &spiConfig, &calculatedBaudRate);
}
-void EPD_Draw()
+void EPD_WriteCommandBuffer(uint8_t index, uint8_t *data, size_t length)
+{
+ uint8_t tx[3] = { 0x70, index, 0x72 };
+
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 0);
+ SPI_DRV_MasterTransferBlocking(1, NULL, tx, NULL, 2, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 0);
+ SPI_DRV_MasterTransferBlocking(1, NULL, &tx[2], NULL, 1, 1);
+ SPI_DRV_MasterTransferBlocking(1, NULL, data, NULL, length, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
+}
+
+void EPD_WriteCommandByte(uint8_t index, uint8_t data)
{
- /* 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);
+ EPD_WriteCommandBuffer(index, &data, 1);
+}
+
+uint8_t EPD_ReadCommand(uint8_t index)
+{
+ uint8_t tx[4] = { 0x70, index, 0x73, 0x00 };
+ uint8_t rx[2];
+
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 0);
+ SPI_DRV_MasterTransferBlocking(1, NULL, tx, NULL, 2, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 0);
+ SPI_DRV_MasterTransferBlocking(1, NULL, &tx[2], rx, 2, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
+ return rx[1];
+}
+
+uint8_t EPD_ReadCogID()
+{
+ uint8_t tx[2] = { 0x71, 0x00 };
+ uint8_t rx[2];
+
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 0);
+ SPI_DRV_MasterTransferBlocking(1, NULL, tx, rx, sizeof tx, 1);
+ GPIO_DRV_WritePinOutput(pinCS.pinName, 1);
+ return rx[1];
+}
+
+int EPD_Draw()
+{
+ /* read the COG ID */
+ uint8_t id = EPD_ReadCogID();
+ if ((id & 0x0f) != 0x02) {
+ return -1;
}
+ /* disable OE */
+ EPD_WriteCommandByte(0x02, 0x40);
+
+ /* check breakage */
+ uint8_t broken_panel = EPD_ReadCommand(0x0f);
+ if (0x00 == (0x80 & broken_panel)) {
+ return -2;
+ }
+
+ /* power saving mode */
+ EPD_WriteCommandByte(0x0b, 0x02);
+
/* Shutdown */
GPIO_DRV_WritePinOutput(pinDischarge.pinName, 1);
GPIO_DRV_WritePinOutput(pinDischarge.pinName, 0);
+ return 0;
+}
+
+void EPD_Deinit()
+{
+ SPI_DRV_MasterDeinit(1);
}
/* vim: set expandtab ts=4 sw=4: */
diff --git a/laser-tag software/main.c b/laser-tag software/main.c
index a2dc21d..99b8812 100755
--- a/laser-tag software/main.c
+++ b/laser-tag software/main.c
@@ -237,7 +237,8 @@ static flexio_shifter_config_t g_shifterConfig = {
extern void EPD_Init();
-extern void EPD_Draw();
+extern int EPD_Draw();
+extern void EPD_Deinit();
///////
// Code
@@ -529,7 +530,17 @@ int main (void)
EPD_Init();
/* Draw something */
- EPD_Draw();
+ int ret = EPD_Draw();
+ if (ret == -1) {
+ led(0xff, 0x00, 0x00);
+ } else if (ret == -2) {
+ led(0xff, 0xff, 0x00);
+ } else {
+ led(0x00, 0xff, 0x00);
+ }
+
+ /* Deinit so we can mess around on the bus pirate */
+ EPD_Deinit();
/* We're done, everything else is triggered through interrupts */
for(;;) {