/** * @brief Returns output value (VDD or GND) of SPIRIT GPIO_x, when it is configured as digital output. * @param xGpioX Specifies the GPIO to be read. * 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 * @retval OutputLevel Logical level of selected GPIO configured as digital output. * This parameter can be: HIGH or LOW. */ OutputLevel SpiritGpioGetLevel(SpiritGpioPin xGpioX) { uint8_t tempRegValue = 0x00; OutputLevel level; /* Check the parameters */ s_assert_param(IS_SPIRIT_GPIO(xGpioX)); /* Reads the SPIRIT_GPIOx register */ g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); /* Mask the GPIO_SELECT field and returns the value according */ tempRegValue &= 0xF8; if(tempRegValue == SPIRIT_GPIO_DIG_OUT_VDD) { level = HIGH; } else { level = LOW; } return level; }
/** * @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); }
enum spirit_outputlevel_e spirit_gpio_get_outputlevel(FAR struct spirit_library_s *spirit, enum spirit_gpio_pin_e gpio) { enum spirit_outputlevel_e level; uint8_t regval = 0; /* Check the parameters */ DEBUGASSERT(IS_SPIRIT_GPIO(gpio)); /* Reads the SPIRIT_GPIOx register */ (void)spirit_reg_read(spirit, gpio, ®val, 1); /* Mask the GPIO_SELECT field and returns the value according */ regval &= 0xf8; if (regval == SPIRIT_GPIO_DIG_OUT_VDD) { level = HIGH; } else { level = LOW; } return level; }
/** * @brief Initializes the SPIRIT GPIOx according to the specified * parameters in the pxGpioInitStruct. * @param pxGpioInitStruct pointer to a SGpioInit structure that * contains the configuration information for the specified SPIRIT GPIO. * @retval None. */ void SpiritGpioInit(SGpioInit* pxGpioInitStruct) { uint8_t tempRegValue = 0x00; /* Check the parameters */ s_assert_param(IS_SPIRIT_GPIO(pxGpioInitStruct->xSpiritGpioPin)); s_assert_param(IS_SPIRIT_GPIO_MODE(pxGpioInitStruct->xSpiritGpioMode)); s_assert_param(IS_SPIRIT_GPIO_IO(pxGpioInitStruct->xSpiritGpioIO)); tempRegValue = ((uint8_t)(pxGpioInitStruct->xSpiritGpioMode) | (uint8_t)(pxGpioInitStruct->xSpiritGpioIO)); g_xStatus = SpiritSpiWriteRegisters(pxGpioInitStruct->xSpiritGpioPin, 1, &tempRegValue); }
int spirit_gpio_initialize(FAR struct spirit_library_s *spirit, FAR const struct spirit_gpio_init_s *gpioinit) { uint8_t regval = 0x00; /* Check the parameters */ DEBUGASSERT(IS_SPIRIT_GPIO(gpioinit->gpiopin)); DEBUGASSERT(IS_SPIRIT_GPIO_MODE(gpioinit->gpiomode)); DEBUGASSERT(IS_SPIRIT_GPIO_IO(gpioinit->gpioio)); regval = ((uint8_t)(gpioinit->gpiomode) | (uint8_t)(gpioinit->gpioio)); return spirit_reg_write(spirit, gpioinit->gpiopin, ®val, 1); }
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; }