@@ -127,6 +127,7 @@ const uint8_t LUT_BB_7IN5_V2[]={
127
127
void HAL_SPI_MspInit (SPI_HandleTypeDef * hspi ) {
128
128
GPIO_InitTypeDef GPIO_InitStruct = {0 };
129
129
130
+ __HAL_RCC_GPIOA_CLK_ENABLE ();
130
131
__HAL_RCC_DMA1_CLK_ENABLE ();
131
132
132
133
/**SPI1 GPIO Configuration
@@ -220,7 +221,7 @@ EPD_Status EPD_HWInit(void) {
220
221
221
222
/*Configure GPIO pins : BUSY_Pin*/
222
223
GPIO_InitStruct .Pin = BUSY_Pin ;
223
- GPIO_InitStruct .Mode = GPIO_MODE_IT_FALLING ;
224
+ GPIO_InitStruct .Mode = GPIO_MODE_IT_RISING ;
224
225
GPIO_InitStruct .Pull = GPIO_NOPULL ;
225
226
HAL_GPIO_Init (GPIOB , & GPIO_InitStruct );
226
227
@@ -250,9 +251,11 @@ EPD_Status EPD_HWInit(void) {
250
251
hspi1 .Init .CRCLength = SPI_CRC_LENGTH_DATASIZE ;
251
252
hspi1 .Init .NSSPMode = SPI_NSS_PULSE_DISABLE ;
252
253
254
+ //HAL_SPI_DeInit(&hspi1);
253
255
if (HAL_SPI_Init (& hspi1 ) != HAL_OK )
254
256
status = EPD_ERROR_HW ;
255
257
258
+ HAL_SPI_MspInit (& hspi1 );
256
259
return status ;
257
260
}
258
261
@@ -322,6 +325,12 @@ EPD_Status EPD_SWInit(void) {
322
325
return status ;
323
326
}
324
327
328
+ static void EPD_usDelay (uint32_t val ) {
329
+ volatile uint32_t tmp ;
330
+
331
+ for (tmp = val ; tmp != 0 ; tmp -- );
332
+ }
333
+
325
334
/******************************************************************************
326
335
function : Display hardware reset
327
336
parameter:
@@ -332,10 +341,11 @@ EPD_Status EPD_Reset(void) {
332
341
//vTaskDelay(msToTicks(200));
333
342
DEV_Digital_Write (EPD_RST_PIN , 0 );
334
343
//HAL_Delay(2);
335
- vTaskDelay (msToTicks (100 ));
344
+ //vTaskDelay(msToTicks(100));
345
+ EPD_usDelay (25 ); // ~ 50 µs
336
346
DEV_Digital_Write (EPD_RST_PIN , 1 );
337
347
//HAL_Delay(200);
338
- vTaskDelay (msToTicks (200 ));
348
+ // vTaskDelay(msToTicks(100 ));
339
349
340
350
return EPD_OK ;
341
351
}
@@ -404,12 +414,13 @@ static void EPD_SendBuffer(uint8_t *buffer, uint32_t count) {
404
414
DEV_SPI_WriteBuffer (buffer , count );
405
415
406
416
ulTaskNotifyTake ( pdTRUE , msToTicks (500 )); // timeout to 500ms
417
+ //while (!__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_TXE)); // Wait last char to be sent
407
418
408
419
DEV_Digital_Write (EPD_CS_PIN , 1 );
409
420
}
410
421
411
422
/******************************************************************************
412
- function : Wait until the busy_pin goes LOW
423
+ function : Wait until the busy_pin is LOW
413
424
parameter:
414
425
******************************************************************************/
415
426
static void EPD_WaitUntilIdle (void ) {
@@ -419,26 +430,11 @@ static void EPD_WaitUntilIdle(void) {
419
430
__HAL_GPIO_EXTI_CLEAR_IT (GPIO_PIN_1 );
420
431
epd_thread_handler = xTaskGetCurrentTaskHandle ();
421
432
422
-
423
- // //Debug("e-Paper busy\r\n");
424
- // unsigned char busy;
425
- // do{
426
- // //HAL_Delay(1000);
427
- // //EPD_SendCommand(0x71);
428
- // HAL_Delay(5);
429
- // busy = DEV_Digital_Read(EPD_BUSY_PIN);
430
- // busy =!(busy & 0x01);
431
- // }while(busy);
432
- //
433
- // HAL_Delay(5);
434
- // //Debug("e-Paper busy release\r\n");
435
-
436
- // wait for event, without timeout
437
433
while (!end_busy ) {
438
434
ulNotificationValue = ulTaskNotifyTake ( pdTRUE , msToTicks (100 )); // timeout to 100ms
439
435
if (ulNotificationValue != 1 ) {
440
- //Check if busy is not low
441
- if (! (DEV_Digital_Read (EPD_BUSY_PIN ) & 0x01 ))
436
+ //Check if busy is returned to high state
437
+ if ((DEV_Digital_Read (EPD_BUSY_PIN ) & 0x01 ))
442
438
end_busy = 1 ;
443
439
} else
444
440
end_busy = 1 ;
@@ -481,7 +477,6 @@ function : Turn On Display
481
477
void EPD_RefreshDisplay (void ) {
482
478
EPD_SendCommand (0x12 ); //DISPLAY REFRESH
483
479
//HAL_Delay(100); //!!!The delay here is necessary, 200uS at least!!!
484
- vTaskDelay (msToTicks (200 ));
485
480
EPD_WaitUntilIdle ();
486
481
}
487
482
@@ -531,9 +526,16 @@ void EXTI1_IRQHandler(void) {
531
526
* @brief This function handles DMA1 channel3 global interrupt.
532
527
*/
533
528
void DMA1_Channel3_IRQHandler (void ) {
529
+ HAL_DMA_IRQHandler (hspi1 .hdmatx );
530
+ }
531
+
532
+ void HAL_SPI_TxCpltCallback (SPI_HandleTypeDef * hspi )
533
+ {
534
+ /* Turn LED3 on: Transfer in transmission/reception process is complete */
535
+ //BSP_LED_On(LED3);
536
+ //wTransferState = TRANSFER_COMPLETE;
534
537
BaseType_t xHigherPriorityTaskWoken = pdFALSE ;
535
538
536
- HAL_DMA_IRQHandler (& hdma_spi1_tx );
537
539
if (epd_thread_handler != NULL ) {
538
540
/* Notify the task that an event has been emitted. */
539
541
vTaskNotifyGiveFromISR (epd_thread_handler , & xHigherPriorityTaskWoken );
@@ -542,9 +544,9 @@ void DMA1_Channel3_IRQHandler(void) {
542
544
epd_thread_handler = NULL ;
543
545
544
546
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
545
- should be performed to ensure the interrupt returns directly to the highest
546
- priority task. The macro used for this purpose is dependent on the port in
547
- use and may be called portEND_SWITCHING_ISR(). */
547
+ should be performed to ensure the interrupt returns directly to the highest
548
+ priority task. The macro used for this purpose is dependent on the port in
549
+ use and may be called portEND_SWITCHING_ISR(). */
548
550
portYIELD_FROM_ISR ( xHigherPriorityTaskWoken );
549
551
}
550
552
}
0 commit comments