Skip to content
Snippets Groups Projects
Select Git revision
  • 52409cb35af8c09a319386c2098bf02fb1b65fd8
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • 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
  • bootloader-v1
  • v0.0
36 results

gpio.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    gpio.c 3.51 KiB
    #include "epicardium.h"
    #include "gpio.h"
    #include "max32665.h"
    #include "mxc_sys.h"
    #include "adc.h"
    #include "mxc_errors.h"
    #include "modules/log.h"
    #include "modules/modules.h"
    
    /*
     * Despite what the schematic (currently, 2019-08-18) says these are the correct
     * pins for wristband GPIO 1-4 (not 0-3 as the schematic states)
     */
    gpio_cfg_t gpio_configs[] = {
    	[EPIC_GPIO_WRISTBAND_1] = { PORT_0,
    				    PIN_21,
    				    GPIO_FUNC_OUT,
    				    GPIO_PAD_NONE },
    	[EPIC_GPIO_WRISTBAND_2] = { PORT_0,
    				    PIN_22,
    				    GPIO_FUNC_OUT,
    				    GPIO_PAD_NONE },
    	[EPIC_GPIO_WRISTBAND_3] = { PORT_0,
    				    PIN_29,
    				    GPIO_FUNC_OUT,
    				    GPIO_PAD_NONE },
    	[EPIC_GPIO_WRISTBAND_4] = { PORT_0,
    				    PIN_20,
    				    GPIO_FUNC_OUT,
    				    GPIO_PAD_NONE },
    	[EPIC_GPIO_IR_LED] = { PORT_0, PIN_23, GPIO_FUNC_OUT, GPIO_PAD_NONE },
    };
    
    static int s_adc_channels[] = {
    	[EPIC_GPIO_WRISTBAND_1] = ADC_CH_5,
    	[EPIC_GPIO_WRISTBAND_2] = ADC_CH_6,
    	/* on P0.29, there is no ADC available
    	 * see GPIO matrix in MAX32665-MAX32668.pdf,
    	 * pages 32,33
    	 */
    	[EPIC_GPIO_WRISTBAND_3] = -1,
    	[EPIC_GPIO_WRISTBAND_4] = ADC_CH_4,
    	[EPIC_GPIO_IR_LED]      = ADC_CH_7,
    };
    
    int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
    {
    	if (pin < EPIC_GPIO_WRISTBAND_1 || pin > EPIC_GPIO_IR_LED)
    		return -EINVAL;
    
    	gpio_cfg_t *cfg = &gpio_configs[pin];
    
    	if (mode & EPIC_GPIO_MODE_ADC) {
    		if (s_adc_channels[pin] == -1) {
    			LOG_WARN("gpio", "ADC not available on pin %d", pin);
    			return -EINVAL;
    		}
    		cfg->func = GPIO_FUNC_ALT1;
    		if (mode & EPIC_GPIO_MODE_OUT) {
    			return -EINVAL;
    		}
    	} else if (mode & EPIC_GPIO_MODE_IN) {
    		cfg->func = GPIO_FUNC_IN;
    		if (mode & EPIC_GPIO_MODE_OUT) {
    			return -EINVAL;
    		}
    	} else if (mode & EPIC_GPIO_MODE_OUT) {
    		cfg->func = GPIO_FUNC_OUT;
    		if (mode & EPIC_GPIO_MODE_IN) {
    			return -EINVAL;