/** * @brief Forces SPIRIT GPIO_x configured as digital output, to VDD or GND. * @param xGpioX Specifies the GPIO to be configured. * This parameter can be one of following parameters: * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0 * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1 * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2 * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3 * @param xLevel Specifies the level. * This parameter can be: HIGH or LOW. * @retval None. */ void SpiritGpioSetLevel(SpiritGpioPin xGpioX, OutputLevel xLevel) { uint8_t tempRegValue = 0x00; /* Check the parameters */ s_assert_param(IS_SPIRIT_GPIO(xGpioX)); s_assert_param(IS_SPIRIT_GPIO_LEVEL(xLevel)); /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */ g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); tempRegValue &= 0x04; /* Sets the value of the SPIRIT GPIO register according to the specified level */ if(xLevel == HIGH) { tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; } else { tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; } /* Writes the SPIRIT GPIO register */ g_xStatus = SpiritSpiWriteRegisters(xGpioX, 1, &tempRegValue); }
int spirit_gpio_set_outputlevel(FAR struct spirit_library_s *spirit, enum spirit_gpio_pin_e gpio, enum spirit_outputlevel_e level) { uint8_t regval = 0; int ret; /* Check the parameters */ DEBUGASSERT(IS_SPIRIT_GPIO(gpio)); DEBUGASSERT(IS_SPIRIT_GPIO_LEVEL(level)); /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */ ret = spirit_reg_read(spirit, gpio, ®val, 1); if (ret >= 0) { regval &= 0x04; /* Sets the value of the SPIRIT GPIO register according to the * specified level. */ if (level == HIGH) { regval |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; } else { regval |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP; } /* Write to the SPIRIT GPIO register */ ret = spirit_reg_write(spirit, gpio, ®val, 1); } return ret; }