ESP32S2_Cal_Demo/main/app_task_epd.c

68 lines
2.4 KiB
C

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_log.h"
#include "app_lib_epd_impl.h"
static uint8_t *frame_data[2];
static const char *TAG = "TASK_EPD";
extern const unsigned char pixiv_82311703_p0_4indexed[];
extern const unsigned char pixiv_57852730_p0_4indexed[];
#define ARRAY_EVEN_BYTES(arr, i) ((arr[2 * i] & 0x01) << 4U) | ((arr[2 * i] & 0x04) << 3U) | ((arr[2 * i] & 0x10) << 2U) | ((arr[2 * i] & 0x40) << 1U) | \
((arr[2 * i + 1] & 0x01)) | ((arr[2 * i + 1] & 0x04) >> 1U) | ((arr[2 * i + 1] & 0x10) >> 2U) | ((arr[2 * i + 1] & 0x40) >> 3U)
#define ARRAY_ODD_BYTES(arr, i) ((arr[2 * i] & 0x02) << 3U) | ((arr[2 * i] & 0x08) << 2U) | ((arr[2 * i] & 0x20) << 1U) | ((arr[2 * i] & 0x80)) | \
((arr[2 * i + 1] & 0x02) >> 1U) | ((arr[2 * i + 1] & 0x08) >> 2U) | ((arr[2 * i + 1] & 0x20) >> 3U) | ((arr[2 * i + 1] & 0x80) >> 4U)
TaskHandle_t xTaskEPDExampleHandle = NULL;
void vTaskEPDExample(void *pvParameters) {
ESP_LOGI(TAG, "EPD task started.");
frame_data[0] = malloc(15000);
frame_data[1] = malloc(15000);
if(frame_data[0] == NULL || frame_data[1] == NULL) {
ESP_LOGE(TAG, "Failed to allocate memory on heap.");
vTaskSuspend(NULL);
}
app_lib_epd_impl_t epd_impl = {0};
gd_epd_042_t epd = {
.cb = {
.write_data_cb = (gd_epd_042_ret_t (*)(void *, uint8_t *, uint32_t))app_lib_epd_impl_write_data,
.write_cmd_cb = (gd_epd_042_ret_t (*)(void *, uint8_t *, uint8_t))app_lib_epd_impl_write_cmd,
.poll_busy_cb = (gd_epd_042_ret_t (*)(void *))app_lib_epd_impl_poll_busy,
.reset_cb = (gd_epd_042_ret_t (*)(void *))app_lib_epd_impl_reset,
.delay_ms_cb = (gd_epd_042_ret_t (*)(void *, uint32_t))app_lib_epd_delay_ms
},
.user_data = &epd_impl
};
app_lib_epd_impl_init(&epd_impl);
gd_epd_042_init(&epd);
for(uint32_t i = 0; i < 15000; i++) {
frame_data[0][i] = ARRAY_ODD_BYTES(pixiv_57852730_p0_4indexed, i);
frame_data[1][i] = ARRAY_EVEN_BYTES(pixiv_57852730_p0_4indexed, i);
}
ESP_LOGI(TAG, "EPD frame constructed.");
gd_epd_042_load(&epd, frame_data[0], frame_data[1]);
gd_epd_042_update(&epd);
gd_epd_042_deepsleep(&epd);
ESP_LOGI(TAG, "EPD task finished.");
for(;;) {
vTaskSuspend(NULL);
}
}