#include "ygg_lock.h" #include static SemaphoreHandle_t s_i2c_mutex = NULL; static SemaphoreHandle_t s_lvgl_mutex = NULL; void ygg_lock_init(void) { if (s_i2c_mutex == NULL) { s_i2c_mutex = xSemaphoreCreateMutex(); } if (s_lvgl_mutex == NULL) { s_lvgl_mutex = xSemaphoreCreateMutex(); } } bool ygg_i2c_lock_take(TickType_t timeout) { if (s_i2c_mutex == NULL) { return false; } return xSemaphoreTake(s_i2c_mutex, timeout) == pdTRUE; } void ygg_i2c_lock_give(void) { if (s_i2c_mutex != NULL) { xSemaphoreGive(s_i2c_mutex); } } bool ygg_lvgl_lock_take(TickType_t timeout) { if (s_lvgl_mutex == NULL) { return false; } return xSemaphoreTake(s_lvgl_mutex, timeout) == pdTRUE; } void ygg_lvgl_lock_give(void) { if (s_lvgl_mutex != NULL) { xSemaphoreGive(s_lvgl_mutex); } }