From e1cc12eb27d8124e51654e99d164f49ac75c9d70 Mon Sep 17 00:00:00 2001 From: Fabian Blatz Date: Fri, 24 May 2024 05:47:32 +0200 Subject: [PATCH] feat(pxp): add zephyr support (#6159) --- src/draw/nxp/pxp/lv_pxp_osa.c | 60 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/draw/nxp/pxp/lv_pxp_osa.c b/src/draw/nxp/pxp/lv_pxp_osa.c index 539cefe50..e5d3d55a6 100644 --- a/src/draw/nxp/pxp/lv_pxp_osa.c +++ b/src/draw/nxp/pxp/lv_pxp_osa.c @@ -25,6 +25,11 @@ #include "semphr.h" #endif +#if defined(__ZEPHYR__) + #include + #include +#endif + /********************* * DEFINES *********************/ @@ -61,8 +66,8 @@ static void _pxp_wait(void); * STATIC VARIABLES **********************/ -#if defined(SDK_OS_FREE_RTOS) - static SemaphoreHandle_t xPXPIdleSemaphore; +#if LV_USE_OS + static lv_thread_sync_t pxp_sync; #endif static volatile bool ucPXPIdle; @@ -83,26 +88,23 @@ static pxp_cfg_t _pxp_default_cfg = { void PXP_IRQHandler(void) { -#if defined(SDK_OS_FREE_RTOS) - BaseType_t xHigherPriorityTaskWoken = pdFALSE; -#endif - if(kPXP_CompleteFlag & PXP_GetStatusFlags(PXP_ID)) { PXP_ClearStatusFlags(PXP_ID, kPXP_CompleteFlag); -#if defined(SDK_OS_FREE_RTOS) - xSemaphoreGiveFromISR(xPXPIdleSemaphore, &xHigherPriorityTaskWoken); - - /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch - should be performed to ensure the interrupt returns directly to the highest - priority task. The macro used for this purpose is dependent on the port in - use and may be called portEND_SWITCHING_ISR(). */ - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +#if LV_USE_OS + lv_thread_sync_signal(&pxp_sync); #else ucPXPIdle = true; #endif } } +#if defined(__ZEPHYR__) +static void PXP_ZephyrIRQHandler(void *) +{ + PXP_IRQHandler(); +} +#endif + pxp_cfg_t * pxp_get_default_cfg(void) { return &_pxp_default_cfg; @@ -114,22 +116,32 @@ pxp_cfg_t * pxp_get_default_cfg(void) static void _pxp_interrupt_init(void) { -#if defined(SDK_OS_FREE_RTOS) - xPXPIdleSemaphore = xSemaphoreCreateBinary(); - PXP_ASSERT_MSG(xPXPIdleSemaphore, "xSemaphoreCreateBinary failed!"); +#if LV_USE_OS + if(lv_thread_sync_init(&pxp_sync) != LV_RESULT_OK) { + PXP_ASSERT_MSG(false, "Failed to init thread_sync."); + } +#endif +#if defined(SDK_OS_FREE_RTOS) NVIC_SetPriority(PXP_IRQ_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1); + NVIC_EnableIRQ(PXP_IRQ_ID); +#elif defined(__ZEPHYR__) + IRQ_CONNECT(DT_IRQN(DT_NODELABEL(pxp)), CONFIG_LV_Z_PXP_INTERRUPT_PRIORITY, PXP_ZephyrIRQHandler, NULL, 0); + irq_enable(DT_IRQN(DT_NODELABEL(pxp))); #endif ucPXPIdle = true; - - NVIC_EnableIRQ(PXP_IRQ_ID); } static void _pxp_interrupt_deinit(void) { - NVIC_DisableIRQ(PXP_IRQ_ID); #if defined(SDK_OS_FREE_RTOS) - vSemaphoreDelete(xPXPIdleSemaphore); + NVIC_DisableIRQ(PXP_IRQ_ID); +#elif defined(__ZEPHYR__) + irq_disable(DT_IRQN(DT_NODELABEL(pxp))); +#endif + +#if LV_USE_OS + lv_thread_sync_delete(&pxp_sync); #endif } @@ -149,12 +161,10 @@ static void _pxp_run(void) */ static void _pxp_wait(void) { -#if defined(SDK_OS_FREE_RTOS) - /* Return if PXP was never started, otherwise the semaphore will lock forever. */ if(ucPXPIdle == true) return; - - if(xSemaphoreTake(xPXPIdleSemaphore, portMAX_DELAY) == pdTRUE) +#if LV_USE_OS + if(lv_thread_sync_wait(&pxp_sync) == LV_RESULT_OK) ucPXPIdle = true; #else while(ucPXPIdle == false) {