85 lines
2.1 KiB
C
85 lines
2.1 KiB
C
#include "cmsis_os2.h"
|
|
|
|
#include "lvgl.h"
|
|
|
|
#include "user_epd_impl.h"
|
|
|
|
// Defined in main.c
|
|
extern SPI_HandleTypeDef hspi2;
|
|
|
|
// Private function prototypes
|
|
void user_task_flush_epd(void *arguments);
|
|
uint8_t _user_tasks_init_epd(void);
|
|
void _user_tasks_init_lvgl(void);
|
|
|
|
// 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
|
|
}
|
|
};
|
|
|
|
osSemaphoreId_t g_epd_busy_semphr;
|
|
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
|
|
};
|
|
|
|
uint8_t frame_buffer_wb[212 * 104 / 8];
|
|
uint8_t frame_buffer_rd[212 * 104 / 8];
|
|
|
|
void user_tasks_initialize(void) {
|
|
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 4, 0);
|
|
HAL_NVIC_SetPriority(SPI2_IRQn, 4, 0);
|
|
|
|
if(_user_tasks_init_epd()) return;
|
|
_user_tasks_init_lvgl();
|
|
|
|
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);
|
|
}
|
|
|
|
void user_task_flush_epd(void *arguments) {
|
|
for(;;) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
uint8_t _user_tasks_init_epd(void) {
|
|
depg0213_ret_t ret;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
ret = depg0213_epd_deepsleep(&g_epd);
|
|
if(ret != DEPG0213_OK) return -4;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void _user_tasks_init_lvgl(void) {
|
|
lv_init();
|
|
} |