Skip to content
Snippets Groups Projects
Select Git revision
  • dbeec980d99ced2ce0e80ec67a7816bc04fc314c
  • master default protected
  • schneider/ir
  • rahix/user-space-ctx
  • schneider/iaq-python
  • schneider/ble-mini-demo
  • schneider/ble-ecg-stream-visu
  • schneider/mp-exception-print
  • schneider/sleep-display
  • schneider/deepsleep4
  • schneider/deepsleep2
  • schneider/deepsleep
  • schneider/ble-central
  • rahix/bluetooth-app-favorite
  • schneider/v1.17-changelog
  • schneider/ancs
  • schneider/png
  • schneider/freertos-list-debug
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/bonding-fail-if-full
  • schneider/ble-fixes-2020-3
  • v1.18
  • v1.17
  • v1.16
  • v1.15
  • v1.14
  • v1.13
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
41 results

default.nix

Blame
  • pmic.c 6.79 KiB
    #include "epicardium.h"
    #include "modules/modules.h"
    #include "modules/log.h"
    
    #include "card10.h"
    #include "pmic.h"
    #include "MAX77650-Arduino-Library.h"
    
    #include "max32665.h"
    #include "mxc_sys.h"
    #include "mxc_pins.h"
    #include "adc.h"
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "timers.h"
    
    #include <stdio.h>
    #include <string.h>
    
    #define LOCK_WAIT pdMS_TO_TICKS(1000)
    
    /* Task ID for the pmic handler */
    static TaskHandle_t pmic_task_id = NULL;
    
    enum {
    	/* An irq was received, probably the power button */
    	PMIC_NOTIFY_IRQ = 1,
    	/* The timer has ticked and we should check the battery voltage again */
    	PMIC_NOTIFY_MONITOR = 2,
    };
    
    void pmic_interrupt_callback(void *_)
    {
    	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    	if (pmic_task_id != NULL) {
    		xTaskNotifyFromISR(
    			pmic_task_id,
    			PMIC_NOTIFY_IRQ,
    			eSetBits,
    			&xHigherPriorityTaskWoken
    		);
    		portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
    	}
    }
    
    int pmic_read_amux(enum pmic_amux_signal sig, float *result)
    {
    	int ret     = 0;
    	int i2c_ret = 0;
    
    	if (sig > _PMIC_AMUX_MAX) {
    		return -EINVAL;
    	}
    
    	int adc_ret = hwlock_acquire(HWLOCK_ADC, LOCK_WAIT);
    	if (adc_ret < 0) {
    		ret = adc_ret;
    		goto done;
    	}
    	i2c_ret = hwlock_acquire(HWLOCK_I2C, LOCK_WAIT);
    	if (i2c_ret < 0) {
    		ret = i2c_ret;
    		goto done;
    	}
    
    	/* Select the correct channel for this measurement.  */
    	MAX77650_setMUX_SEL(sig);
    
    	/*