Skip to content
Snippets Groups Projects
Select Git revision
  • 4d7be7df9d41f769a4c783604dc15d88c7dcddaa
  • master default protected
  • color-definitions
  • battery-symbol
  • framebuffer-overlay
  • batt-capacity
  • menu-disp
  • clock-fix
  • personal-state-colors
  • power
  • charge_voltage
  • pybattery
  • koalo/bhi160
  • ch3/splashscreen
  • genofire/ble-rewrite
  • rahix/simple_menu
  • koalo/bhi160-works-but-dirty
  • ios-workarounds
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • renze/hatchery_apps
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
27 results

init.gdb

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    i2c.c 590 B
    #include "modules/log.h"
    #include "modules/modules.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "semphr.h"
    
    #include <errno.h>
    
    static StaticSemaphore_t i2c_mutex_data;
    static SemaphoreHandle_t i2c_mutex;
    
    int i2c_init(void)
    {
    	i2c_mutex = xSemaphoreCreateMutexStatic(&i2c_mutex_data);
    	return 0;
    }
    
    int i2c_lock(void)
    {
    	if (xSemaphoreTake(i2c_mutex, pdMS_TO_TICKS(100)) != pdTRUE) {
    		LOG_WARN("i2c", "Mutex is busy");
    		return -EBUSY;
    	}
    	return 0;
    }
    
    void i2c_unlock(void)
    {
    	if (xSemaphoreGive(i2c_mutex) != pdTRUE) {
    		LOG_ERR("i2c", "Mutex was not acquired correctly");
    	}
    }