55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
#include "cmsis_os.h"
|
|
#include "oled_panel_elw1501aa.h"
|
|
#include "main.h"
|
|
#include "stm32h7xx_hal.h"
|
|
|
|
extern SPI_HandleTypeDef hspi1;
|
|
|
|
static osSemaphoreId_t s_spi_semphr;
|
|
|
|
int ewl_impl_init(void) {
|
|
s_spi_semphr = osSemaphoreNew(1, 0, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
epd_ret_t ewl_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 ewl_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 = HAL_SPI_Transmit_DMA(&hspi1, cmd, len);
|
|
if(ret != HAL_OK) {
|
|
return EPD_FAIL;
|
|
}
|
|
|
|
osSemaphoreAcquire(s_spi_semphr, osWaitForever);
|
|
|
|
return EPD_OK;
|
|
}
|
|
|
|
epd_ret_t ewl_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);
|
|
}
|
|
} |