64 lines
1.8 KiB
C
64 lines
1.8 KiB
C
#include "epd_impl.h"
|
|
|
|
#include "cmsis_os.h"
|
|
#include "main.h"
|
|
#include "stm32h7xx_hal.h"
|
|
|
|
extern SPI_HandleTypeDef hspi1;
|
|
|
|
static osSemaphoreId_t s_spi_semphr;
|
|
|
|
int epd_impl_init(void) {
|
|
s_spi_semphr = osSemaphoreNew(1, 0, NULL);
|
|
return 0;
|
|
}
|
|
|
|
epd_ret_t epd_impl_reset_cb(void *handle) {
|
|
HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, GPIO_PIN_SET);
|
|
osDelay(10);
|
|
HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, GPIO_PIN_RESET);
|
|
osDelay(10);
|
|
HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, GPIO_PIN_SET);
|
|
osDelay(10);
|
|
|
|
return EPD_OK;
|
|
}
|
|
|
|
epd_ret_t epd_impl_write_cmd_cb(void *handle, uint8_t *cmd, uint32_t len) {
|
|
HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_RESET);
|
|
HAL_StatusTypeDef ret;
|
|
#if EPD_IMPL_CMD_DC_CHANGE_AT_PARAM
|
|
ret = HAL_SPI_Transmit(&hspi1, cmd, 0x01, 1000);
|
|
if (ret != HAL_OK) return EPD_FAIL;
|
|
if(len > 1) {
|
|
HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET);
|
|
ret = HAL_SPI_Transmit_DMA(&hspi1, &cmd[1], len - 1);
|
|
if(ret != HAL_OK) return EPD_FAIL;
|
|
osSemaphoreAcquire(s_spi_semphr, osWaitForever);
|
|
}
|
|
#else
|
|
ret = HAL_SPI_Transmit_DMA(&hspi1, cmd, len);
|
|
if(ret != HAL_OK) return EPD_FAIL;
|
|
osSemaphoreAcquire(s_spi_semphr, osWaitForever);
|
|
#endif
|
|
|
|
return EPD_OK;
|
|
}
|
|
|
|
epd_ret_t epd_impl_write_data_cb(void *handle, uint8_t *data, uint32_t len) {
|
|
HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET);
|
|
HAL_StatusTypeDef ret = HAL_SPI_Transmit_DMA(&hspi1, data, len);
|
|
if (ret != HAL_OK) {
|
|
return EPD_FAIL;
|
|
}
|
|
|
|
osSemaphoreAcquire(s_spi_semphr, osWaitForever);
|
|
|
|
return EPD_OK;
|
|
}
|
|
|
|
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
|
|
if (hspi->Instance == SPI1) {
|
|
osSemaphoreRelease(s_spi_semphr);
|
|
}
|
|
} |