62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
#include <string.h>
|
|
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "user_epd_impl.h"
|
|
|
|
|
|
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(10);
|
|
HAL_GPIO_WritePin(SPI2_RES_GPIO_Port, SPI2_RES_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(5);
|
|
HAL_GPIO_WritePin(SPI2_RES_GPIO_Port, SPI2_RES_Pin, GPIO_PIN_SET);
|
|
HAL_Delay(10);
|
|
}
|
|
return DEPG0213_OK;
|
|
}
|
|
|
|
depg0213_ret_t _epd_poll_busy(void *handle) {
|
|
SPI_HandleTypeDef *hspi = handle;
|
|
if(hspi->Instance == SPI2) {
|
|
uint32_t tick_start = HAL_GetTick();
|
|
while (HAL_GPIO_ReadPin(SPI2_BUSY_GPIO_Port, SPI2_BUSY_Pin) == GPIO_PIN_SET) {
|
|
if(HAL_GetTick() - tick_start > 10000) {
|
|
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;
|
|
} |