STM32H750VB_EPD/Core/Src/user_tasks.c

85 lines
2.1 KiB
C
Raw Normal View History

2021-01-12 18:59:36 +00:00
#include "cmsis_os2.h"
2021-01-12 16:13:56 +00:00
#include "lvgl.h"
#include "user_epd_impl.h"
// Defined in main.c
extern SPI_HandleTypeDef hspi2;
2021-01-12 18:59:36 +00:00
// Private function prototypes
2021-01-14 15:25:28 +00:00
void user_task_flush_epd(void *arguments);
2021-01-12 18:59:36 +00:00
uint8_t _user_tasks_init_epd(void);
2021-01-12 16:13:56 +00:00
void _user_tasks_init_lvgl(void);
2021-01-12 18:59:36 +00:00
// Globals
depg0213_epd_t g_epd = {
.user_data = &hspi2,
.cb = {
.reset_cb = _epd_reset_cb,
.poll_busy_cb = _epd_poll_busy,
.write_cmd_cb = _epd_write_cmd_cb,
.write_data_cb = _epd_write_data_cb
}
};
2021-01-14 15:25:28 +00:00
2021-01-12 18:59:36 +00:00
osSemaphoreId_t g_epd_busy_semphr;
2021-01-14 15:25:28 +00:00
osSemaphoreId_t g_spi2_semphr;
osThreadId_t g_flush_epd_task_handle;
const osThreadAttr_t g_flush_epd_task_attributes = {
.name = "flushEPD",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 512 * 4
2021-01-14 15:25:28 +00:00
};
uint8_t frame_buffer_wb[212 * 104 / 8];
uint8_t frame_buffer_rd[212 * 104 / 8];
2021-01-12 18:59:36 +00:00
2021-01-12 16:13:56 +00:00
void user_tasks_initialize(void) {
2021-01-14 15:25:28 +00:00
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 4, 0);
HAL_NVIC_SetPriority(SPI2_IRQn, 4, 0);
2021-01-12 18:59:36 +00:00
if(_user_tasks_init_epd()) return;
2021-01-12 16:13:56 +00:00
_user_tasks_init_lvgl();
2021-01-14 15:25:28 +00:00
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_SetPriority(SPI2_IRQn, 6, 0);
g_flush_epd_task_handle = osThreadNew(user_task_flush_epd, NULL, &g_flush_epd_task_attributes);
2021-01-12 16:13:56 +00:00
}
2021-01-12 18:59:36 +00:00
void user_task_flush_epd(void *arguments) {
for(;;) {
2021-01-14 15:25:28 +00:00
memset(frame_buffer_wb, 0xFF, 212 * 104 / 8);
memset(frame_buffer_rd, 0x00, 212 * 104 / 8);
depg0213_epd_load(&g_epd, frame_buffer_wb, frame_buffer_rd);
depg0213_epd_deepsleep(&g_epd);
osDelay(300000);
2021-01-12 16:13:56 +00:00
}
2021-01-12 18:59:36 +00:00
}
uint8_t _user_tasks_init_epd(void) {
depg0213_ret_t ret;
2021-01-14 15:25:28 +00:00
g_epd_busy_semphr = osSemaphoreNew(1U, 0U, NULL); // Max: 1, initial 0, attr NULL
if(g_epd_busy_semphr == NULL) return -1;
g_spi2_semphr = osSemaphoreNew(1U, 0U, NULL);
if(g_spi2_semphr == NULL) return -1;
2021-01-12 18:59:36 +00:00
ret = depg0213_epd_init(&g_epd);
if(ret != DEPG0213_OK) return -2;
ret = depg0213_epd_direction(&g_epd, DEPG0213_HORIZONTAL_INVERSE);
if(ret != DEPG0213_OK) return -3;
2021-01-12 16:13:56 +00:00
2021-01-12 18:59:36 +00:00
ret = depg0213_epd_deepsleep(&g_epd);
if(ret != DEPG0213_OK) return -4;
2021-01-12 16:13:56 +00:00
2021-01-12 18:59:36 +00:00
return 0;
2021-01-12 16:13:56 +00:00
}
void _user_tasks_init_lvgl(void) {
lv_init();
}