コード例 #1
0
ファイル: stm32_adc.c プロジェクト: AlexShiLucky/NuttX
int stm32_adc_setup(void)
{
  static bool initialized = false;
  uint8_t channel[1] = {10};
  struct adc_dev_s *adc;
  int rv;

  if (initialized)
    {
      return OK;
    }

  ainfo("INFO: Initializing ADC12_IN10\n");
  stm32_configgpio(GPIO_ADC12_IN10);
  if ((adc = stm32_adcinitialize(1, channel, 1)) == NULL)
    {
      aerr("ERROR: Failed to get adc interface\n");
      return -ENODEV;
    }

  if ((rv = adc_register("/dev/adc0", adc)) < 0)
    {
      aerr("ERROR: adc_register failed: %d\n", rv);
      return rv;
    }

  initialized = true;
  ainfo("INFO: ADC12_IN10 initialized succesfully\n");
  return OK;
}
コード例 #2
0
ファイル: stm32_gsensoradc.c プロジェクト: lodius/nuttx
int board_gsensoradc_setup(void)
{
#ifdef CONFIG_STM32_ADC1
  
  static bool initialized = false;
  struct adc_dev_s *adc;
  int ret;
  int i;

  /* Check if we have already initialized */
  
  if (!initialized){
      /* Configure the pins as analog inputs for the selected channels */

    for (i = 0; i < ADC1_NCHANNELS; i++)
    {
      stm32_configgpio(g_pinlist[i]);
      //stm32_configgpio(g_detect[i]);
    }

      /* Call stm32_adcinitialize() to get an instance of the ADC interface */

    adc = stm32_adcinitialize(1, g_chanlist, ADC1_NCHANNELS);

    if (adc == NULL)
    {
      adbg("ERROR: Failed to get ADC interface\n");
      return -ENODEV;
    }


      /* Register the ADC driver at "/dev/adc0" */

    ret = adc_register("/dev/gsensor", adc);
    if (ret < 0)
    {
      adbg("adc_register failed: %d\n", ret);
      return ret;
    }

      /* Now we are initialized */

    initialized = true;
  }

  return OK;
#else
  return -ENOSYS;
#endif
}
コード例 #3
0
ファイル: px4fmu_adc.c プロジェクト: PX4CAR/Firmware
int adc_devinit(void)
{
	static bool initialized = false;
	struct adc_dev_s *adc[ADC3_NCHANNELS];
	int ret;
	int i;

	/* Check if we have already initialized */

	if (!initialized) {
		char name[11];

		for (i = 0; i < ADC3_NCHANNELS; i++) {
			stm32_configgpio(g_pinlist[i]);
		}

		for (i = 0; i < 1; i++) {
			/* Configure the pins as analog inputs for the selected channels */
			//stm32_configgpio(g_pinlist[i]);

			/* Call stm32_adcinitialize() to get an instance of the ADC interface */
			//multiple channels only supported with dma!
			adc[i] = stm32_adcinitialize(3, (g_chanlist), 4);

			if (adc == NULL) {
				adbg("ERROR: Failed to get ADC interface\n");
				return -ENODEV;
			}


			/* Register the ADC driver at "/dev/adc0" */
			sprintf(name, "/dev/adc%d", i);
			ret = adc_register(name, adc[i]);

			if (ret < 0) {
				adbg("adc_register failed for adc %s: %d\n", name, ret);
				return ret;
			}
		}

		/* Now we are initialized */

		initialized = true;
	}

	return OK;
}
コード例 #4
0
ファイル: stm32_adc.c プロジェクト: AlexShiLucky/NuttX
int stm32_adc_setup(void)
{
  static bool initialized = false;
  FAR struct adc_dev_s *adc;
  int ret;
  int i;

  /* Check if we have already initialized */

  if (!initialized)
    {
      /* DEV1 */
      /* Configure the pins as analog inputs for the selected channels */

      for (i = 0; i < DEV1_NCHANNELS; i++)
        {
          stm32_configgpio(g_pinlist1[i]);
        }

      /* Call stm32_adcinitialize() to get an instance of the ADC interface */

      adc = stm32_adcinitialize(DEV1_PORT, g_chanlist1, DEV1_NCHANNELS);
      if (adc == NULL)
        {
          aerr("ERROR: Failed to get ADC interface 1\n");
          return -ENODEV;
        }

      /* Register the ADC driver at "/dev/adc0" */

      ret = adc_register("/dev/adc0", adc);
      if (ret < 0)
        {
          aerr("ERROR: adc_register /dev/adc0 failed: %d\n", ret);
          return ret;
        }

#ifdef DEV2_PORT

      /* DEV2 */
      /* Configure the pins as analog inputs for the selected channels */

      for (i = 0; i < DEV2_NCHANNELS; i++)
        {
          stm32_configgpio(g_pinlist2[i]);
        }

      /* Call stm32_adcinitialize() to get an instance of the ADC interface */

      adc = stm32_adcinitialize(DEV2_PORT, g_chanlist2, DEV2_NCHANNELS);
      if (adc == NULL)
        {
          aerr("ERROR: Failed to get ADC interface 2\n");
          return -ENODEV;
        }

      /* Register the ADC driver at "/dev/adc1" */

      ret = adc_register("/dev/adc1", adc);
      if (ret < 0)
        {
          aerr("ERROR: adc_register /dev/adc1 failed: %d\n", ret);
          return ret;
        }
#endif

      initialized = true;

    }

  return OK;
}