73 lines
2.3 KiB
C
73 lines
2.3 KiB
C
#include <string.h>
|
|
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "user_epd_impl.h"
|
|
|
|
#define BUSY_MAX_POLLING_TIME 5000 // 5s
|
|
|
|
uint8_t g_epd_busy_irq_flag = 0;
|
|
|
|
extern osSemaphoreId_t g_epd_busy_semphr;
|
|
|
|
depg0213_ret_t _epd_reset_cb(void *handle) {
|
|
SPI_HandleTypeDef *hspi = handle;
|
|
if (hspi->Instance == SPI2) {
|
|
HAL_GPIO_WritePin(SPI2_RES_GPIO_Port, SPI2_RES_Pin, GPIO_PIN_SET);
|
|
HAL_Delay(1);
|
|
HAL_GPIO_WritePin(SPI2_RES_GPIO_Port, SPI2_RES_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(1);
|
|
HAL_GPIO_WritePin(SPI2_RES_GPIO_Port, SPI2_RES_Pin, GPIO_PIN_SET);
|
|
}
|
|
return DEPG0213_OK;
|
|
}
|
|
|
|
depg0213_ret_t _epd_poll_busy(void *handle) {
|
|
SPI_HandleTypeDef *hspi = handle;
|
|
if (hspi->Instance == SPI2) {
|
|
if (osKernelGetState() != osKernelRunning) { // Kernel has not started, use flag polling instead.
|
|
uint32_t tick_start = HAL_GetTick();
|
|
while (!g_epd_busy_irq_flag) {
|
|
if (HAL_GetTick() - tick_start > BUSY_MAX_POLLING_TIME) {
|
|
return DEPG0213_ERROR;
|
|
}
|
|
}
|
|
g_epd_busy_irq_flag = 0;
|
|
} else { // Kernel has started, use semaphore.
|
|
if(osSemaphoreAcquire(g_epd_busy_semphr, BUSY_MAX_POLLING_TIME) != osOK) {
|
|
return DEPG0213_ERROR;
|
|
}
|
|
}
|
|
}
|
|
return DEPG0213_OK;
|
|
}
|
|
|
|
depg0213_ret_t _epd_write_cmd_cb(void *handle, uint8_t *cmd, uint8_t len) {
|
|
SPI_HandleTypeDef *hspi = handle;
|
|
|
|
HAL_StatusTypeDef ret = HAL_OK;
|
|
|
|
if (hspi->Instance == SPI2) {
|
|
HAL_GPIO_WritePin(SPI2_DC_GPIO_Port, SPI2_DC_Pin, GPIO_PIN_RESET);
|
|
ret = HAL_SPI_Transmit(hspi, cmd, 0x01, 1000);
|
|
if (len > 1) {
|
|
HAL_GPIO_WritePin(SPI2_DC_GPIO_Port, SPI2_DC_Pin, GPIO_PIN_SET);
|
|
ret = HAL_SPI_Transmit(hspi, &cmd[1], len - 1, 1000);
|
|
}
|
|
}
|
|
if (ret != HAL_OK) return DEPG0213_ERROR;
|
|
return DEPG0213_OK;
|
|
}
|
|
|
|
depg0213_ret_t _epd_write_data_cb(void *handle, uint8_t *data, uint16_t len) {
|
|
SPI_HandleTypeDef *hspi = handle;
|
|
|
|
HAL_StatusTypeDef ret = HAL_OK;
|
|
|
|
if (hspi->Instance == SPI2) {
|
|
HAL_GPIO_WritePin(SPI2_DC_GPIO_Port, SPI2_DC_Pin, GPIO_PIN_SET);
|
|
ret = HAL_SPI_Transmit(hspi, data, len, 1000);
|
|
}
|
|
if (ret != HAL_OK) return DEPG0213_ERROR;
|
|
return DEPG0213_OK;
|
|
} |