From 220b4ae3e84e55ea78442e39e506e04907b33929 Mon Sep 17 00:00:00 2001 From: Jelmer Date: Sun, 12 Nov 2023 10:24:36 +0100 Subject: [PATCH] Restructured epd driver interface, support for UC-based tags --- .../hal/Newton_M3_nRF52811/HAL_Newton_M3.h | 1 + .../Newton_M3_nRF52811_22_BWR.h | 2 - .../Newton_M3_nRF52811_29_BWR.h | 2 - .../Newton_M3_nRF52811_43_BWR.h | 1 - .../Newton_M3_nRF52811_60_BWR.h | 2 - .../Newton_M3_nRF52811_75_BWR.h | 2 - ARM_Tag_FW/Newton_M3_nRF52811/include/hal.h | 5 +- .../Newton_M3_nRF52811/include/uc8159.h | 23 -- .../Newton_M3_nRF52811/include/uc8179.h | 24 -- .../include/uc_variant_043.h | 23 -- ARM_Tag_FW/Newton_M3_nRF52811/platformio.ini | 25 ++- ARM_Tag_FW/Newton_M3_nRF52811/src/epd.cpp | 25 +++ .../epd_driver/epd_interface.h} | 24 +- .../src/{ => epd_driver}/ssd1619.cpp | 208 +----------------- .../src/{ => epd_driver}/uc8159.cpp | 2 - .../src/{ => epd_driver}/uc8179.cpp | 2 - .../src/epd_driver/uc_variant_029.cpp | 128 +++++++++++ .../src/{ => epd_driver}/uc_variant_043.cpp | 5 - .../Newton_M3_nRF52811/src/syncedproto.cpp | 33 --- .../Newton_M3_nRF52811/src/userinterface.cpp | 21 +- 20 files changed, 205 insertions(+), 353 deletions(-) delete mode 100644 ARM_Tag_FW/Newton_M3_nRF52811/include/uc8159.h delete mode 100644 ARM_Tag_FW/Newton_M3_nRF52811/include/uc8179.h delete mode 100644 ARM_Tag_FW/Newton_M3_nRF52811/include/uc_variant_043.h create mode 100644 ARM_Tag_FW/Newton_M3_nRF52811/src/epd.cpp rename ARM_Tag_FW/Newton_M3_nRF52811/{include/ssd1619.h => src/epd_driver/epd_interface.h} (62%) rename ARM_Tag_FW/Newton_M3_nRF52811/src/{ => epd_driver}/ssd1619.cpp (50%) rename ARM_Tag_FW/Newton_M3_nRF52811/src/{ => epd_driver}/uc8159.cpp (99%) rename ARM_Tag_FW/Newton_M3_nRF52811/src/{ => epd_driver}/uc8179.cpp (99%) create mode 100644 ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_029.cpp rename ARM_Tag_FW/Newton_M3_nRF52811/src/{ => epd_driver}/uc_variant_043.cpp (97%) diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/HAL_Newton_M3.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/HAL_Newton_M3.h index d15414b5..cd826593 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/HAL_Newton_M3.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/HAL_Newton_M3.h @@ -1,6 +1,7 @@ #include "zigbee.h" #include "epd_spi.h" #include "eeprom_spi.h" +#include "epd_driver/epd_interface.h" #define RADIO_FIRST_CHANNEL (11) // 2.4-GHz channels start at 11 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_22_BWR.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_22_BWR.h index 2b94bcff..168c73f7 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_22_BWR.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_22_BWR.h @@ -12,8 +12,6 @@ // hw types #define HW_TYPE SOLUM_M3_BWR_22 -#include "../include/ssd1619.h" - #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 296 #define SCREEN_XOFFSET 8 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_29_BWR.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_29_BWR.h index 012b2f10..429ca4fa 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_29_BWR.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_29_BWR.h @@ -18,8 +18,6 @@ // hw types #define HW_TYPE SOLUM_M3_BWR_29 -#include "../include/ssd1619.h" - #define SCREEN_WIDTH 168 #define SCREEN_HEIGHT 384 #define SCREEN_XOFFSET 8 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_43_BWR.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_43_BWR.h index be22a036..6ac5f3d0 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_43_BWR.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_43_BWR.h @@ -19,7 +19,6 @@ // hw type #define HW_TYPE SOLUM_M3_BWR_43 -#include "../include/uc_variant_043.h" #define SCREEN_WIDTH 152 #define SCREEN_HEIGHT 522 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_60_BWR.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_60_BWR.h index 4cd8e567..0425d782 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_60_BWR.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_60_BWR.h @@ -18,8 +18,6 @@ // hw type #define HW_TYPE SOLUM_M3_BWR_60 -#include "../include/uc8159.h" - #define SCREEN_WIDTH 600 #define SCREEN_HEIGHT 448 #define SCREEN_XOFFSET 0 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_75_BWR.h b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_75_BWR.h index 9f1d399a..45f77cfa 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_75_BWR.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/hal/Newton_M3_nRF52811/Newton_M3_nRF52811_75_BWR.h @@ -18,8 +18,6 @@ // hw type #define HW_TYPE SOLUM_M3_BWR_75 -#include "../include/uc8179.h" - #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 480 #define SCREEN_XOFFSET 0 diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/include/hal.h b/ARM_Tag_FW/Newton_M3_nRF52811/include/hal.h index d2c56454..383d7487 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/include/hal.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/include/hal.h @@ -2,6 +2,7 @@ #include "../hal/Newton_M3_nRF52811/Newton_M3_nRF52811_22_BWR.h" #include "../hal/Newton_M3_nRF52811/HAL_Newton_M3.h" #endif + #ifdef BUILD_NEWTON_M3_29_BWR #include "../hal/Newton_M3_nRF52811/Newton_M3_nRF52811_29_BWR.h" #include "../hal/Newton_M3_nRF52811/HAL_Newton_M3.h" @@ -12,7 +13,6 @@ #include "../hal/Newton_M3_nRF52811/HAL_Newton_M3.h" #endif - #ifdef BUILD_NEWTON_M3_60_BWR #include "../hal/Newton_M3_nRF52811/Newton_M3_nRF52811_60_BWR.h" #include "../hal/Newton_M3_nRF52811/HAL_Newton_M3.h" @@ -21,5 +21,4 @@ #ifdef BUILD_NEWTON_M3_75_BWR #include "../hal/Newton_M3_nRF52811/Newton_M3_nRF52811_75_BWR.h" #include "../hal/Newton_M3_nRF52811/HAL_Newton_M3.h" -#endif - +#endif \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8159.h b/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8159.h deleted file mode 100644 index c11bd463..00000000 --- a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8159.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _JSCREEN_H_ -#define _JSCREEN_H_ - -#include -#include - -#define EPD_LUT_DEFAULT 0 -#define EPD_LUT_NO_REPEATS 1 -#define EPD_LUT_FAST_NO_REDS 2 -#define EPD_LUT_FAST 3 - -void epdSetup(); -void epdEnterSleep(); - - -void draw(); -void drawNoWait(); - -void epdWaitRdy(); - -void selectLUT(uint8_t lut); - -#endif \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8179.h b/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8179.h deleted file mode 100644 index e8ffefb2..00000000 --- a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc8179.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _JSCREEN_H_ -#define _JSCREEN_H_ - -#include -#include - -#define EPD_LUT_DEFAULT 0 -#define EPD_LUT_NO_REPEATS 1 -#define EPD_LUT_FAST_NO_REDS 2 -#define EPD_LUT_FAST 3 - - -void epdSetup(); -void epdEnterSleep(); - - -void draw(); -void drawNoWait(); -void epdWaitRdy(); - -void selectLUT(uint8_t lut); - - -#endif \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc_variant_043.h b/ARM_Tag_FW/Newton_M3_nRF52811/include/uc_variant_043.h deleted file mode 100644 index c457d7a2..00000000 --- a/ARM_Tag_FW/Newton_M3_nRF52811/include/uc_variant_043.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _JSCREEN_H_ -#define _JSCREEN_H_ - -#include -#include - -#define EPD_LUT_DEFAULT 0 -#define EPD_LUT_NO_REPEATS 1 -#define EPD_LUT_FAST_NO_REDS 2 -#define EPD_LUT_FAST 3 - -void epdSetup(); -void epdEnterSleep(); - -void draw(); -void drawNoWait(); -void drawWithSleep(); -void epdWaitRdy(); - -void selectLUT(uint8_t lut); - - -#endif \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/platformio.ini b/ARM_Tag_FW/Newton_M3_nRF52811/platformio.ini index 9b4a4b5d..71f0e94e 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/platformio.ini +++ b/ARM_Tag_FW/Newton_M3_nRF52811/platformio.ini @@ -20,18 +20,30 @@ extra_scripts = post:preparefiles.py build_flags = ${env.build_flags} -D BUILD_NEWTON_M3_22_BWR + -D EPD_DRIVER=SSD1619 -Tnrf52811_bootloader.ld build_src_filter = - +<*>---+<../hal/Newton_M3_nRF52811/*> + +<*>-+<../hal/Newton_M3_nRF52811/*> [env:Newton_M3_29_BWR] board_build.ldscript = nrf52811_bootloader.ld build_flags = ${env.build_flags} -D BUILD_NEWTON_M3_29_BWR + -D EPD_DRIVER=SSD1619 -Tnrf52811_bootloader.ld build_src_filter = - +<*>---+<../hal/Newton_M3_nRF52811/*> + +<*>-+<../hal/Newton_M3_nRF52811/*> + +[env:Newton_M3_29_VAR1_BWR] + board_build.ldscript = nrf52811_bootloader.ld + build_flags = + ${env.build_flags} + -D BUILD_NEWTON_M3_29_BWR + -D EPD_DRIVER=UCVARIANT029 + -Tnrf52811_bootloader.ld + build_src_filter = + +<*>-+<../hal/Newton_M3_nRF52811/*> [env:Newton_M3_43_BWR] board_build.ldscript = nrf52811_bootloader.ld @@ -39,9 +51,10 @@ extra_scripts = post:preparefiles.py -Wunused-macros ${env.build_flags} -D BUILD_NEWTON_M3_43_BWR + -D EPD_DRIVER=UCVARIANT043 -Tnrf52811_bootloader.ld build_src_filter = - +<*>---+<../hal/Newton_M3_nRF52811/*> + +<*>-+<../hal/Newton_M3_nRF52811/*> [env:Newton_M3_60_BWR] board_build.ldscript = nrf52811_bootloader.ld @@ -49,8 +62,9 @@ extra_scripts = post:preparefiles.py ${env.build_flags} -Tnrf52811_bootloader.ld -D BUILD_NEWTON_M3_60_BWR + -D EPD_DRIVER=UC8159 build_src_filter = - +<*>----+<../hal/Newton_M3_nRF52811/*> + +<*>-+<../hal/Newton_M3_nRF52811/*> [env:Newton_M3_75_BWR] board_build.ldscript = nrf52811_bootloader.ld @@ -58,6 +72,7 @@ extra_scripts = post:preparefiles.py ${env.build_flags} -Tnrf52811_bootloader.ld -D BUILD_NEWTON_M3_75_BWR + -D EPD_DRIVER=UC8179 build_src_filter = - +<*>---+<../hal/Newton_M3_nRF52811/*> + +<*>-+<../hal/Newton_M3_nRF52811/*> diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/epd.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd.cpp new file mode 100644 index 00000000..bc83c9fb --- /dev/null +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd.cpp @@ -0,0 +1,25 @@ +#define SSD1619 0 +#define UCVARIANT029 1 +#define UCVARIANT043 2 +#define UC8159 3 +#define UC8179 4 + +#if EPD_DRIVER == SSD1619 +#include "epd_driver/ssd1619.cpp" +#endif + +#if EPD_DRIVER == UCVARIANT029 +#include "epd_driver/uc_variant_029.cpp" +#endif + +#if EPD_DRIVER == UCVARIANT043 +#include "epd_driver/uc_variant_043.cpp" +#endif + +#if EPD_DRIVER == UC8159 +#include "epd_driver/uc8159.cpp" +#endif + +#if EPD_DRIVER == UC8179 +#include "epd_driver/uc8179.cpp" +#endif diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/include/ssd1619.h b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/epd_interface.h similarity index 62% rename from ARM_Tag_FW/Newton_M3_nRF52811/include/ssd1619.h rename to ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/epd_interface.h index e9976eb4..6b39a648 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/include/ssd1619.h +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/epd_interface.h @@ -1,30 +1,22 @@ -#ifndef _JSCREEN_H_ -#define _JSCREEN_H_ +#ifndef _EPD_IFACE_H_ +#define _EPD_IFACE_H_ #include #include -#define EPD_SSD1619 - -#define epdSend spi_write - -#define EPD_LUT_DEFAULT 0 -#define EPD_LUT_NO_REPEATS 1 -#define EPD_LUT_FAST_NO_REDS 2 -#define EPD_LUT_FAST 3 -#define EPD_LUT_OTA 0x10 - void epdSetup(); void epdEnterSleep(); -extern uint8_t dispLutSize; -extern uint8_t customLUT[]; - void draw(); void drawNoWait(); void drawWithSleep(); void epdWaitRdy(); +#define EPD_LUT_DEFAULT 0 +#define EPD_LUT_NO_REPEATS 1 +#define EPD_LUT_FAST_NO_REDS 2 +#define EPD_LUT_FAST 3 + void selectLUT(uint8_t lut); -#endif +#endif \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/ssd1619.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/ssd1619.cpp similarity index 50% rename from ARM_Tag_FW/Newton_M3_nRF52811/src/ssd1619.cpp rename to ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/ssd1619.cpp index ebfca6e0..90a56c8b 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/ssd1619.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/ssd1619.cpp @@ -1,5 +1,3 @@ -#include "ssd1619.h" - #include #include #include @@ -64,21 +62,8 @@ digitalWrite(EPD_DC, HIGH); \ } while (0) -extern void dump(const uint8_t *a, const uint16_t l); // remove me when done - -static uint8_t currentLut = 0; -uint8_t dispLutSize = 0; // we'll need to expose this in the 'capabilities' flag - static bool isInited = false; -#define LUT_BUFFER_SIZE 256 -static uint8_t waveformbuffer[LUT_BUFFER_SIZE]; -uint8_t customLUT[LUT_BUFFER_SIZE] = {0}; - -struct waveform10 *waveform10 = (struct waveform10 *)waveformbuffer; // holds the LUT/waveform -struct waveform *waveform7 = (struct waveform *)waveformbuffer; // holds the LUT/waveform -struct waveform12 *waveform12 = (struct waveform12 *)waveformbuffer; // holds the LUT/waveform - static void commandReadBegin(uint8_t cmd) { epdSelect(); markCommand(); @@ -147,6 +132,16 @@ void setPosXY(uint16_t x, uint16_t y) { epdWrite(CMD_YSTART_POS, 2, (y)&0xff, (y) >> 8); } + +void selectLUT(uint8_t lut) { + // implement alternative LUTs here. Currently just reset the watchdog to two minutes, + // to ensure it doesn't reset during the much longer bootup procedure + lut += 1; // make the compiler a happy camper + wdt120s(); + return; +} + + void epdEnterSleep() { digitalWrite(EPD_RST, LOW); delay(10); @@ -174,7 +169,6 @@ void epdSetup() { epdWrite(CMD_ACTIVATION, 0); epdBusyWaitFalling(10000); isInited = true; - currentLut = EPD_LUT_DEFAULT; } static uint8_t epdGetStatus() { uint8_t sta; @@ -184,188 +178,6 @@ static uint8_t epdGetStatus() { return sta; } -void loadFixedTempOTPLUT() { - shortCommand1(0x18, 0x48); // external temp sensor - shortCommand2(0x1A, 0x05, 0x00); // < temp register - shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1 (i2C) - shortCommand(CMD_ACTIVATION); - epdBusyWaitFalling(1000); -} -static void writeLut() { - commandBegin(CMD_WRITE_LUT); - if (dispLutSize == 12) { - for (uint8_t i = 0; i < 153; i++) - epdSend(waveformbuffer[i]); - } else { - for (uint8_t i = 0; i < (dispLutSize * 10); i++) - epdSend(waveformbuffer[i]); - } - commandEnd(); -} -static void readLut() { - commandReadBegin(0x33); - for (uint16_t c = 0; c < LUT_BUFFER_SIZE; c++) { - waveformbuffer[c] = epdReadByte(); - } - commandReadEnd(); -} -static uint8_t getLutSize() { - uint8_t ref = 0; - for (uint8_t c = (LUT_BUFFER_SIZE - 4); c > 16; c--) { - uint8_t check = waveformbuffer[c]; - for (uint8_t d = 1; d < 4; d++) { - if (waveformbuffer[c + d] != check) { - ref = c; - goto end; - } - } - } -end:; - return ref + 1; -} -static void lutGroupDisable(uint8_t group) { - switch (dispLutSize) { - case 7: - memset(&(waveform7->group[group]), 0x00, 5); - break; - case 10: - memset(&(waveform10->group[group]), 0x00, 5); - break; - case 12: - memset(&(waveform12->group[group]), 0x00, sizeof(waveform12->group[0])); - break; - } -} -static void lutGroupSpeedup(uint8_t group, uint8_t speed) { - switch (dispLutSize) { - case 7: - for (uint8_t i = 0; i < 4; i++) { - waveform7->group[group].phaselength[i] = 1 + (waveform7->group[group].phaselength[i] / speed); - } - break; - case 10: - for (uint8_t i = 0; i < 4; i++) { - waveform10->group[group].phaselength[i] = 1 + (waveform10->group[group].phaselength[i] / speed); - } - break; - case 12: - waveform12->group[group].tp0a = 1 + (waveform12->group[group].tp0a / speed); - waveform12->group[group].tp0b = 1 + (waveform12->group[group].tp0b / speed); - waveform12->group[group].tp0c = 1 + (waveform12->group[group].tp0c / speed); - waveform12->group[group].tp0d = 1 + (waveform12->group[group].tp0d / speed); - break; - } -} -static void lutGroupRepeat(uint8_t group, uint8_t repeat) { - switch (dispLutSize) { - case 7: - waveform7->group[group].repeat = repeat; - break; - case 10: - waveform10->group[group].repeat = repeat; - break; - case 12: - waveform12->group[group].repeat = repeat; - break; - } -} -static void lutGroupRepeatReduce(uint8_t group, uint8_t factor) { - switch (dispLutSize) { - case 7: - waveform7->group[group].repeat = waveform7->group[group].repeat / factor; - break; - case 10: - waveform10->group[group].repeat = waveform10->group[group].repeat / factor; - break; - case 12: - waveform12->group[group].repeat = waveform12->group[group].repeat / factor; - break; - } -} -void selectLUT(uint8_t lut) { - if (currentLut == lut) { - // return; - } - - // Handling if we received an OTA LUT - if (lut == EPD_LUT_OTA) { - memcpy(waveformbuffer, customLUT, dispLutSize * 10); - writeLut(); - currentLut = lut; - return; - } - - if (currentLut != EPD_LUT_DEFAULT) { - // load the 'default' LUT for the current temperature in the EPD lut register - shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1? - shortCommand(CMD_ACTIVATION); - epdBusyWaitFalling(1000); - } - - currentLut = lut; - - // if we're going to be using the default LUT, we're done here. - if (lut == EPD_LUT_DEFAULT) { - return; - } - - // download the current LUT from the waveform buffer - readLut(); - - if (dispLutSize == 0) { - dispLutSize = getLutSize(); - dispLutSize /= 10; - printf("lut size = %d\n", dispLutSize); - dispLutSize = 12; -#ifdef PRINT_LUT - dump(waveformbuffer, LUT_BUFFER_SIZE); -#endif - memcpy(customLUT, waveformbuffer, LUT_BUFFER_SIZE); - } - - switch (lut) { - default: - case EPD_LUT_NO_REPEATS: - lutGroupDisable(LUTGROUP_NEGATIVE); - lutGroupDisable(LUTGROUP_FASTBLINK); - lutGroupRepeat(LUTGROUP_SLOWBLINK, 0); - lutGroupSpeedup(LUTGROUP_SET, 2); - lutGroupSpeedup(LUTGROUP_IMPROVE_SHARPNESS, 2); - lutGroupRepeatReduce(LUTGROUP_IMPROVE_SHARPNESS, 2); - lutGroupSpeedup(LUTGROUP_IMPROVE_REDS, 2); - lutGroupRepeatReduce(LUTGROUP_IMPROVE_REDS, 2); - lutGroupDisable(LUTGROUP_UNUSED); - break; - case EPD_LUT_FAST_NO_REDS: - lutGroupDisable(LUTGROUP_NEGATIVE); - lutGroupDisable(LUTGROUP_FASTBLINK); - lutGroupDisable(LUTGROUP_SLOWBLINK); - lutGroupSpeedup(LUTGROUP_SET, 2); - lutGroupDisable(LUTGROUP_IMPROVE_REDS); - lutGroupDisable(LUTGROUP_IMPROVE_SHARPNESS); - lutGroupDisable(LUTGROUP_UNUSED); - break; - case EPD_LUT_FAST: - lutGroupDisable(LUTGROUP_NEGATIVE); - lutGroupDisable(LUTGROUP_FASTBLINK); - lutGroupDisable(LUTGROUP_SLOWBLINK); - lutGroupRepeat(LUTGROUP_SET, 1); - lutGroupSpeedup(LUTGROUP_SET, 2); - lutGroupDisable(LUTGROUP_IMPROVE_SHARPNESS); - lutGroupDisable(LUTGROUP_IMPROVE_REDS); - lutGroupDisable(LUTGROUP_UNUSED); - break; - } - - if (dispLutSize == 10) { - lutGroupDisable(LUTGROUP_UNUSED); - lutGroupDisable(LUTGROUP_UNKNOWN); - lutGroupDisable(LUTGROUP_UNUSED3); - lutGroupDisable(LUTGROUP_UNUSED4); - } - writeLut(); -} - void epdWriteDisplayData() { setWindowX(SCREEN_XOFFSET, SCREEN_WIDTH + SCREEN_XOFFSET); setPosXY(SCREEN_XOFFSET, 0); diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc8159.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8159.cpp similarity index 99% rename from ARM_Tag_FW/Newton_M3_nRF52811/src/uc8159.cpp rename to ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8159.cpp index fc481629..f99c6110 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc8159.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8159.cpp @@ -1,5 +1,3 @@ -#include "uc8159.h" - #include #include #include diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc8179.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8179.cpp similarity index 99% rename from ARM_Tag_FW/Newton_M3_nRF52811/src/uc8179.cpp rename to ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8179.cpp index 25ebc264..6f21bbbc 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc8179.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc8179.cpp @@ -1,5 +1,3 @@ -#include "uc8179.h" - #include #include #include diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_029.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_029.cpp new file mode 100644 index 00000000..ca54dfab --- /dev/null +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_029.cpp @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include + +#include "hal.h" +#include "lut.h" +#include "settings.h" +#include "wdt.h" +#include "drawing.h" + +#define EPD_CMD_POWER_OFF 0x02 +#define EPD_CMD_POWER_ON 0x04 +#define EPD_CMD_BOOSTER_SOFT_START 0x06 +#define EPD_CMD_DEEP_SLEEP 0x07 +#define EPD_CMD_DISPLAY_START_TRANSMISSION_DTM1 0x10 +#define EPD_CMD_DISPLAY_REFRESH 0x12 +#define EPD_CMD_DISPLAY_START_TRANSMISSION_DTM2 0x13 +#define EPD_CMD_VCOM_INTERVAL 0x50 +#define EPD_CMD_RESOLUTION_SETTING 0x61 +#define EPD_CMD_UNKNOWN 0xF8 + +void epdEnterSleep() { + epd_cmd(EPD_CMD_POWER_OFF); + epdBusyWaitRising(50000); + epdWrite(EPD_CMD_DEEP_SLEEP, 1, 0xA5); + delay(200); + delay(1); +} + +void epdSetup() { + epdReset(); + epdWrite(0x4D, 1, 0x55); + epdWrite(0xF3, 1, 0x0A); + epdWrite(0x31, 1, 0x00); + epdWrite(0x06, 3, 0xE5, 0x35, 0x3C); + epdWrite(0x50, 1, 0x57); + epdWrite(0x00, 2, 0x03 | 0x04, 0x09); +} + +void epdWriteDisplayData() { + // send a dummy byte. Don't ask me why, it's what she likes. She'll sometimes display garbage on the b/w framebuffer if she doesn't get the dummy byte. + epd_data(0x00); + + // this display expects two entire framebuffers worth of data to be written, one for b/w and one for red + uint8_t* buf[2] = {0, 0}; // this will hold pointers to odd/even data lines + for (uint8_t c = 0; c < 2; c++) { + if (c == 0) epd_cmd(EPD_CMD_DISPLAY_START_TRANSMISSION_DTM1); + if (c == 1) epd_cmd(EPD_CMD_DISPLAY_START_TRANSMISSION_DTM2); + markData(); + epdSelect(); + for (uint16_t curY = 0; curY < SCREEN_HEIGHT; curY += 2) { + // Get 'even' screen line + buf[0] = (uint8_t*)calloc(SCREEN_WIDTH / 8, 1); + drawItem::renderDrawLine(buf[0], curY, c); + if (c == 0) { + for (uint8_t c = 0; c < SCREEN_WIDTH / 8; c++) { + buf[0][c] = ~buf[0][c]; + } + } + + // on the first pass, the second (buf[1]) buffer is unused, so we don't have to wait for it to flush to the display / free it + if (buf[1]) { + // wait for 'odd' display line to finish writing to the screen + epdSPIWait(); + free(buf[1]); + } + + // start transfer of even data line to the screen + epdSPIAsyncWrite(buf[0], (SCREEN_WIDTH / 8)); + + // Get 'odd' screen display line + buf[1] = (uint8_t*)calloc(SCREEN_WIDTH / 8, 1); + drawItem::renderDrawLine(buf[1], curY + 1, c); + if (c == 0) { + for (uint8_t c = 0; c < SCREEN_WIDTH / 8; c++) { + buf[1][c] = ~buf[1][c]; + } + } + + // wait until the 'even' data has finished writing + epdSPIWait(); + free(buf[0]); + + // start transfer of the 'odd' data line + epdSPIAsyncWrite(buf[1], (SCREEN_WIDTH / 8)); + } + // check if this was the first pass. If it was, we'll need to wait until the last display line finished writing + if (c == 0) { + epdSPIWait(); + epdDeselect(); + free(buf[1]); + buf[1] = nullptr; + } + } + // flush the draw list, make sure items don't appear on subsequent screens + drawItem::flushDrawItems(); + + // wait until the last line of display has finished writing and clean our stuff up + epdSPIWait(); + epdDeselect(); + if (buf[1]) free(buf[1]); +} + +void selectLUT(uint8_t lut) { + // implement alternative LUTs here. Currently just reset the watchdog to two minutes, + // to ensure it doesn't reset during the much longer bootup procedure + lut += 1; // make the compiler a happy camper + wdt120s(); + return; +} + +void draw() { + drawNoWait(); + epdBusyWaitRising(50000); +} +void drawNoWait() { + epdWriteDisplayData(); + epd_cmd(EPD_CMD_POWER_ON); + epdBusyWaitRising(200); + epd_cmd(EPD_CMD_DISPLAY_REFRESH); +} + +void epdWaitRdy() { + epdBusyWaitRising(50000); +} \ No newline at end of file diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc_variant_043.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_043.cpp similarity index 97% rename from ARM_Tag_FW/Newton_M3_nRF52811/src/uc_variant_043.cpp rename to ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_043.cpp index 640d3e09..57b931b4 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/uc_variant_043.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/epd_driver/uc_variant_043.cpp @@ -1,5 +1,3 @@ -#include "uc_variant_043.h" - #include #include #include @@ -26,10 +24,7 @@ void epdEnterSleep() { epd_cmd(EPD_CMD_POWER_OFF); - epdBusyWaitRising(50000); epdWrite(EPD_CMD_DEEP_SLEEP, 1, 0xA5); - delay(200); - delay(1); } void epdSetup() { diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/syncedproto.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/syncedproto.cpp index 79abc127..db7388e4 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/syncedproto.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/syncedproto.cpp @@ -900,39 +900,6 @@ bool processAvailDataInfo(struct AvailDataInfo *avail) { return true; break; case DATATYPE_CUSTOM_LUT_OTA: - // Handle data for the NFC IC (if we have it) - - // check if we actually have the capability to do OTA Luts - if (!(capabilities & CAPABILITY_SUPPORTS_CUSTOM_LUTS)) { - // looks like we don't. mark as complete and then bail! - powerUp(INIT_RADIO); - sendXferComplete(); - powerDown(INIT_RADIO); - return true; - } -#ifdef EPD_SSD1619 - printf("OTA LUT received\n"); - if (curDataInfo.dataSize == 0 && !memcmp((const void *)&avail->dataVer, (const void *)&curDataInfo.dataVer, 8)) { - printf("this was the same as the last transfer, disregard\n"); - powerUp(INIT_RADIO); - sendXferComplete(); - powerDown(INIT_RADIO); - return true; - } - curBlock.blockId = 0; - memcpy(&(curBlock.ver), &(avail->dataVer), 8); - curBlock.type = avail->dataType; - memcpy(&curDataInfo, (void *)avail, sizeof(struct AvailDataInfo)); - wdt10s(); - if (getDataBlock(avail->dataSize)) { - curDataInfo.dataSize = 0; // mark as transfer not pending - memcpy(customLUT, sizeof(struct blockData) + blockXferBuffer, dispLutSize * 10); - powerUp(INIT_RADIO); - sendXferComplete(); - powerDown(INIT_RADIO); - return true; - } -#endif return false; break; } diff --git a/ARM_Tag_FW/Newton_M3_nRF52811/src/userinterface.cpp b/ARM_Tag_FW/Newton_M3_nRF52811/src/userinterface.cpp index 410f841a..8bbfb7c1 100644 --- a/ARM_Tag_FW/Newton_M3_nRF52811/src/userinterface.cpp +++ b/ARM_Tag_FW/Newton_M3_nRF52811/src/userinterface.cpp @@ -10,7 +10,7 @@ #include "lut.h" #include "powermgt.h" -#include "proto.h" + #include "settings.h" #include "syncedproto.h" // for APmac / Channel #include "hal.h" @@ -33,21 +33,22 @@ bool noAPShown = false; void addOverlay() { if (currentChannel == 0) { - drawMask(SCREEN_WIDTH - 27, 5, 22, 22, COLOR_BLACK); - drawMask(SCREEN_WIDTH - 27, 5, 22, 22, COLOR_RED); - drawRoundedRectangle(SCREEN_WIDTH - 28, 4, 24, 24, COLOR_RED); - addBufferedImage(SCREEN_WIDTH - 24, 8, COLOR_BLACK, rotation::ROTATE_0, ant, DRAW_NORMAL); - addBufferedImage(SCREEN_WIDTH - 16, 15, COLOR_RED, rotation::ROTATE_0, cross, DRAW_NORMAL); + drawMask(UI_SCREEN_WIDTH - 27, 5, 22, 22, COLOR_BLACK); + drawMask(UI_SCREEN_WIDTH - 27, 5, 22, 22, COLOR_RED); + drawRoundedRectangle(UI_SCREEN_WIDTH - 28, 4, 24, 24, COLOR_RED); + addBufferedImage(UI_SCREEN_WIDTH - 24, 8, COLOR_BLACK, rotation::ROTATE_0, ant, DRAW_NORMAL); + addBufferedImage(UI_SCREEN_WIDTH - 16, 15, COLOR_RED, rotation::ROTATE_0, cross, DRAW_NORMAL); noAPShown = true; } else { noAPShown = false; } + lowBattery = true; if (lowBattery) { - drawMask(SCREEN_WIDTH - 27, SCREEN_HEIGHT - 26, 22, 22, COLOR_BLACK); - drawMask(SCREEN_WIDTH - 27, SCREEN_HEIGHT - 26, 22, 22, COLOR_RED); - drawRoundedRectangle(SCREEN_WIDTH - 28, SCREEN_HEIGHT - 27, 24, 24, COLOR_RED); - addBufferedImage(SCREEN_WIDTH - 24, SCREEN_HEIGHT - 19, COLOR_BLACK, rotation::ROTATE_0, battery, DRAW_NORMAL); + drawMask(UI_SCREEN_WIDTH - 27, UI_SCREEN_HEIGHT - 26, 22, 22, COLOR_BLACK); + drawMask(UI_SCREEN_WIDTH - 27, UI_SCREEN_HEIGHT - 26, 22, 22, COLOR_RED); + drawRoundedRectangle(UI_SCREEN_WIDTH - 28, UI_SCREEN_HEIGHT - 27, 24, 24, COLOR_RED); + addBufferedImage(UI_SCREEN_WIDTH - 24, UI_SCREEN_HEIGHT - 19, COLOR_BLACK, rotation::ROTATE_0, battery, DRAW_NORMAL); lowBatteryShown = true; } else {