Skip to content

Commit

Permalink
Merge pull request #80 from gopher-motorsports/epaper
Browse files Browse the repository at this point in the history
Epaper Rev2
  • Loading branch information
isaiahwild42 committed May 14, 2023
2 parents 4dcee06 + 37fe796 commit e0d83a4
Show file tree
Hide file tree
Showing 22 changed files with 1,060 additions and 285 deletions.
4 changes: 2 additions & 2 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.410374697" name="Floating-point unit" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1282290945" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1874696715" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="NUCLEO-F446RE" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1797452388" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-F446RE || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy || || || USE_HAL_DRIVER | STM32F446xx || || Drivers | Core/Startup | Middlewares | Core || || || ${workspace_loc:/${ProjName}/STM32F446RETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1797452388" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-F446RE || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy || || || USE_HAL_DRIVER | STM32F446xx || || Drivers | Core/Startup | Middlewares | Core || || || ${workspace_loc:/${ProjName}/STM32F446RETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat.201712117" name="Use float with printf from newlib-nano (-u _printf_float)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoprintffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat.1327814524" name="Use float with scanf from newlib-nano (-u _scanf_float)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.nanoscanffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.931742836" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="160" valueType="string"/>
Expand Down Expand Up @@ -121,7 +121,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1981471661" name="Floating-point unit" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1396145952" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.124299689" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="NUCLEO-F446RE" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.727066451" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-F446RE || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy || || || USE_HAL_DRIVER | STM32F446xx || || Drivers | Core/Startup | Middlewares | Core || || || ${workspace_loc:/${ProjName}/STM32F446RETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.727066451" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-F446RE || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Middlewares/Third_Party/FreeRTOS/Source/include | ../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F | ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32F4xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32F4xx/Include | ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS | ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy || || || USE_HAL_DRIVER | STM32F446xx || || Drivers | Core/Startup | Middlewares | Core || || || ${workspace_loc:/${ProjName}/STM32F446RETX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1616314804" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="160" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.750342445" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/BMSF4}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.683202003" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
Expand Down
4 changes: 2 additions & 2 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider-reference id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1408828563282793244" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1431716095077883183" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,7 +16,7 @@
<provider-reference id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1408828563282793244" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1431716095077883183" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
11 changes: 8 additions & 3 deletions Core/Epaper/Inc/epaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
*/
void epdInit();

/*!
@brief Update the data in the BMS display image
@param epapData The epapData struct containing current BMS data
*/
void epdPopulateData(Epaper_Data_S* epapData);

/*!
@brief Clear epaper display
*/
Expand All @@ -37,10 +43,9 @@ void epdClear();
void epdFullRefresh();

/*!
@brief Updates only the data in the BMS display image and performs a partial update
@param bms The BMS struct containing current BMS data
@brief Performs a partial update of the epaper with the current BMS display image stored in memory
*/
void epdPopulateData(Epaper_Data_S* epapData);
void epdPartialRefresh();

/*!
@brief Enable epaper sleep mode
Expand Down
29 changes: 17 additions & 12 deletions Core/Epaper/Inc/epaperUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define ROTATE_180 180
#define ROTATE_270 270

#define DATA_START_X 50
#define DATA_START_X 43
#define DATA_START_Y 63
#define DATA_SEPERATION_X 63
#define DATA_SEPERATION_Y 21
Expand Down Expand Up @@ -72,15 +72,20 @@ typedef enum {
typedef enum {
DATA_VOLTAGE = 0,
DATA_PACK_TEMP,
DATA_BOARD_TEMP
DATA_BOARD_TEMP,
NUM_DATA_TABLE_COL
} DATA_TABLE_COL;

typedef enum {
DATA_AVG = 0,
DATA_MAX,
DATA_MIN
DATA_MIN,
NUM_DATA_TABLE_ROW
} DATA_TABLE_ROW;

#define VOLTAGE_SIG_FIGS 4
#define TEMPERATURE_SIG_FIGS 3

/* ==================================================================== */
/* ============================== STRUCTS============================== */
/* ==================================================================== */
Expand Down Expand Up @@ -128,23 +133,23 @@ void Paint_DrawTableData(float data, DATA_TABLE_COL col, DATA_TABLE_ROW row);

/*!
@brief Update BMS Image with current SOC
@param SOC BMS State of Charge as a percentage
@param SOE BMS State of Charge as a decimal
*/
void Paint_DrawSOC(uint32_t SOC);
void Paint_DrawSOE(float SOE);

/*!
@brief Update BMS Image with state data
*/
void Paint_DrawState();
void Paint_DrawState(char* stateMessage);

/*!
@brief Update BMS Image with fault data
*/
void Paint_DrawFault();

#endif // __EPAPER_UTILS_H



void Paint_DrawFault(char* faultMessage);

/*!
@brief Update BMS Image with current sensor data
*/
void Paint_DrawCurrent(float current);

#endif // __EPAPER_UTILS_H
104 changes: 57 additions & 47 deletions Core/Epaper/Src/epaper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "epaperUtils.h"
#include "bms.h"
#include "utils.h"
#include "soc.h"

/* ==================================================================== */
/* ============================= DEFINES ============================== */
Expand Down Expand Up @@ -52,9 +53,11 @@
/* ========================= LOCAL VARIABLES ========================== */
/* ==================================================================== */

uint8_t blackScreenData[IMAGE_SIZE] = {[0 ... IMAGE_SIZE-1] = 0xff};
uint8_t sendBuffer[8];
uint8_t bmsImage[IMAGE_SIZE];
uint8_t whiteScreenData[IMAGE_SIZE] = {[0 ... IMAGE_SIZE-1] = 0xFF}; // Image of only white pixels
uint8_t sendBuffer[8]; // SPI send buffer
uint8_t bmsImage[IMAGE_SIZE]; // Empty display image for BMS data

// Partial refresh lookup table
uint8_t WF_PARTIAL_LUT[LUT_SIZE] =
{
0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
Expand All @@ -74,6 +77,8 @@ uint8_t WF_PARTIAL_LUT[LUT_SIZE] =
0x0, 0x0, 0x0, 0x0, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x0, 0x0, 0x0, 0x22, 0x17, 0x41, 0xB0, 0x32, 0x36
};

// Full refresh lookup table
uint8_t WS_20_30_LUT[LUT_SIZE] =
{
0x80, 0x66, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0,
Expand Down Expand Up @@ -218,6 +223,7 @@ static void setLookupTable(uint8_t *lut)
{
// Set look up table register - last 6 bytes belong to seperate registers
sendMessage(CMD_WRITE_LUT_REGISTER, lut, LUT_SIZE - 6);

// Wait for busy_release interupt
waitBusyRelease();

Expand Down Expand Up @@ -312,10 +318,13 @@ static void setCursor(uint16_t Xstart, uint16_t Ystart)
}

/*!
@brief Initialize epaper display
@brief Sends the image buffer in RAM to e-Paper and enables display
@param Image Image to display
*/
static void setDefaultSettings()
static void epdDisplay(uint8_t *Image)
{
// Full refresh settings begin

// Set initial pin configuration
setCommandMode();
csOn();
Expand Down Expand Up @@ -355,21 +364,12 @@ static void setDefaultSettings()

// Wait for busy_release interupt
waitBusyRelease();
}


/*!
@brief Sends the image buffer in RAM to e-Paper and enables display
@param Image Image to display
*/
static void epdDisplay(uint8_t *Image)
{
// Reset initial settings
setDefaultSettings();

// Set initial lookup table register
setLookupTable(WS_20_30_LUT);

// Full refresh settings complete

// Write image to Black and White RAM
sendMessage(CMD_WRITE_RAM_BLACK_WHITE, Image, (EPD_WIDTH * EPD_HEIGHT) / 8);

Expand All @@ -386,6 +386,8 @@ static void epdDisplay(uint8_t *Image)
*/
static void epdDisplayPartial(uint8_t *Image)
{
// Partial refresh settings begin

// Reset epaper communication
reset();
enable();
Expand Down Expand Up @@ -417,13 +419,15 @@ static void epdDisplayPartial(uint8_t *Image)
// Active display update sequence
sendCommand(CMD_MASTER_ACTIVATION);

// Wait for Busy* interupt
// Wait for Busy interupt
waitBusyRelease();

// Set window and cursor position
setWindows(0, 0, EPD_WIDTH-1, EPD_HEIGHT-1);
setCursor(0, 0);

// Partial refresh settings reset complete

// Write Black and White image to RAM
sendMessage(CMD_WRITE_RAM_BLACK_WHITE, Image, (EPD_WIDTH * EPD_HEIGHT) / 8);

Expand All @@ -440,19 +444,7 @@ static void epdDisplayPartial(uint8_t *Image)
*/
void epdInit()
{
// // Allocate memory for bms image array
// uint16_t imageSize = ((EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1)) * EPD_HEIGHT;
// if((bmsImage = (uint8_t *)malloc(imageSize)) == NULL) {
// Debug("Failed to apply for black memory...\r\n");
// }

// for(int i = 0; i < 4736; i++)
// {
// bmsImage[i] = 0xFF;
// }

memset(bmsImage, 0xFF, IMAGE_SIZE);

Paint_InitBmsImage(bmsImage);
}

Expand All @@ -461,20 +453,12 @@ void epdInit()
*/
void epdClear()
{
epdDisplay(blackScreenData);
}

/*!
@brief Performs a full update of the epaper with the current BMS display image stored in memory
*/
void epdFullRefresh()
{
epdDisplay(bmsImage);
epdDisplay(whiteScreenData);
}

/*!
@brief Updates only the data in the BMS display image and performs a partial update
@param bms The BMS struct containing current BMS data
@brief Update the data in the BMS display image
@param epapData The epapData struct containing current BMS data
*/
void epdPopulateData(Epaper_Data_S* epapData)
{
Expand All @@ -495,18 +479,44 @@ void epdPopulateData(Epaper_Data_S* epapData)
Paint_DrawTableData(epapData->minBoardTemp, DATA_BOARD_TEMP, DATA_MIN);

// Populate BMS image with current SOC percent
Paint_DrawSOC(25);
const float soc = getSocFromCellVoltage(epapData->minBrickV);
const float soe = getSoeFromSoc(soc);
Paint_DrawSOE(soe);

// Populate BMS image with current State
Paint_DrawState();
// Populate BMS image with current sensor data
Paint_DrawCurrent(epapData->current);

// Populate BMS image with current Fault
Paint_DrawFault();

// Perform a partial refresh of the epaper display
epdDisplayPartial(bmsImage);
if(epapData->numActiveAlerts == 0)
{
Paint_DrawFault("NO FAULT PRESENT :)");
}
else
{
char faultString[64];
sprintf(faultString, "(%lu/%lu) %s", epapData->currAlertIndex, epapData->numActiveAlerts, epapData->alertMessage);
Paint_DrawFault(faultString);
}

// Populate BMS image with current State
Paint_DrawState(epapData->stateMessage);
}

/*!
@brief Performs a full update of the epaper with the current BMS display image stored in memory
*/
void epdFullRefresh()
{
epdDisplay(bmsImage);
}

/*!
@brief Performs a partial update of the epaper with the current BMS display image stored in memory
*/
void epdPartialRefresh()
{
epdDisplayPartial(bmsImage);
}

/*!
@brief Enable epaper sleep mode
Expand Down
Loading

0 comments on commit e0d83a4

Please sign in to comment.