AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/adc/adc.h
static inline void adcch_set_input (struct adc_channel_config *ch_conf,
				      enum adcch_positive_input pos,
				      enum adcch_negative_input neg,
				      uint8_t gain)
  {
    if (pos >= ADCCH_POS_TEMPSENSE)
      {
	/* Configure for internal input. */
	Assert (gain == 1);
	Assert (neg == ADCCH_NEG_NONE);

	ch_conf->ctrl = ADC_CH_INPUTMODE_INTERNAL_gc;
	ch_conf->muxctrl = (pos - ADCCH_POS_TEMPSENSE) << ADC_CH_MUXPOS_gp;
      }
    else if (neg == ADCCH_NEG_NONE)
      {
	/* Configure for single-ended measurement. */
	Assert (gain == 1);

	ch_conf->ctrl = ADC_CH_INPUTMODE_SINGLEENDED_gc;
	ch_conf->muxctrl = pos << ADC_CH_MUXPOS_gp;
      }
    else if (neg <= ADCCH_NEG_PIN3)
      {
	/* Configure for differential measurement.
	 * Pins 0-3 can only be used for negative input if the gain
	 * stage is not used, i.e., unity gain (except XMEGA E).
	 */
#if XMEGA_E
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAINL_gc;
#else
	Assert (gain == 1);
	ch_conf->ctrl = ADC_CH_INPUTMODE_DIFF_gc;
#endif
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  (neg << ADC_CH_MUXNEG_gp);
      }
    else if (neg <= ADCCH_NEG_PIN7)
      {
	/* Configure for differential measurement.
	 * Pins 4-7 can be used for all gain settings,
	 * including unity gain, which is available even if
	 * the gain stage is active.
	 */
#if XMEGA_E
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAINH_gc;
#else
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAIN_gc;
#endif
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  ((neg - ADCCH_NEG_PIN4) << ADC_CH_MUXNEG_gp);
      }
    else
      {
	Assert ((neg == ADCCH_NEG_PAD_GND) ||
		(neg == ADCCH_NEG_INTERNAL_GND));
#if XMEGA_E

	/* Configure for differential measurement through PAD GND or
	 * internal GND.
	 * DIFFWGAINH (INPUTMODE) is not used because it support
	 * only PAD GND.
	 */
	ch_conf->ctrl = ADC_CH_INPUTMODE_DIFFWGAINL_gc |
	  adcch_get_gain_setting (gain);
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  ((neg == ADCCH_NEG_INTERNAL_GND) ?
	   ADC_CH_MUXNEGL_INTGND_gc : ADC_CH_MUXNEGL_GND_gc);
#else

	/* Configure for differential measurement through GND or
	 * internal GND.
	 * The bitmasks for the on-chip GND signals change when
	 * gain is enabled. To avoid unnecessary current consumption,
	 * do not enable gainstage for unity gain unless user explicitly
	 * specifies it with the ADCCH_FORCE_1X_GAINSTAGE macro.
	 */
	if (gain == 1)
	  {
	    ch_conf->ctrl = ADC_CH_INPUTMODE_DIFF_gc;
	    ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	      ((neg == ADCCH_NEG_PAD_GND) ?
	       ADC_CH_MUXNEG_MODE10_GND_gc : ADC_CH_MUXNEG_MODE10_INTGND_gc);
	  }
	else
	  {
	    ch_conf->ctrl = ADC_CH_INPUTMODE_DIFFWGAIN_gc |
	      adcch_get_gain_setting (gain);
	    ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	      ((neg == ADCCH_NEG_INTERNAL_GND) ?
	       ADC_CH_MUXNEG_MODE11_INTGND_gc : ADC_CH_MUXNEG_MODE11_GND_gc);
	  }

#endif
      }
  }
/**
 * \brief Set ADC channel input mode, multiplexing and gain
 *
 * Sets up an ADC channel's input mode and multiplexing according to specified
 * input signals, as well as the gain.
 *
 * \param ch_conf Pointer to ADC channel configuration.
 * \param pos Positive input signal.
 * \param neg Negative input signal:
 * \arg \c ADCCH_NEG_NONE for single-ended measurements.
 * \arg \c ADCCH_NEG_PINn , where \c n specifies a pin, for differential
 * measurements.
 * \arg \c ADDCH_x_GND , where \c x specified pad or internal GND, for
 * differential measurements.
 * \param gain Gain factor for measurements:
 * \arg 1 for single-ended or differential with pin 0, 1, 2 or 3, pad or
 * internal GND as negative
 * input.
 * \arg 0 (0.5x), 1, 2, 4, 8, 16, 32 or 64 for differential with pin 4, 5, 6 or
 * 7, pad or internal GND as negative input.
 * \arg ADCCH_FORCE_1X_GAINSTAGE to force the gain stage to be enabled with
 * unity gain for differential measurement.
 *
 * \note The GND signals are not available on all devices. Refer to the device
 * manual for information on available input signals.
 *
 * \note With unity (1x) gain, some input selections may be possible both with
 * and without the gain stage enabled. The driver will default to the
 * configuration without gainstage to keep the current consumption as low as
 * possible unless the user specifies \ref ADCCH_FORCE_1X_GAINSTAGE as \a gain.
 */
\brief Set ADC channel input mode, multiplexing and gain
Sets up an ADC channel's input mode and multiplexing according to specified
input signals, as well as the gain.

\param ch_conf Pointer to ADC channel configuration.
\param pos Positive input signal.
\param neg Negative input signal:
\arg \c ADCCH_NEG_NONE for single-ended measurements.
\arg \c ADCCH_NEG_PINn , where \c n specifies a pin, for differential
measurements.
\arg \c ADDCH_x_GND , where \c x specified pad or internal GND, for
differential measurements.
\param gain Gain factor for measurements:
\arg 1 for single-ended or differential with pin 0, 1, 2 or 3, pad or
internal GND as negative
input.
\arg 0 (0.5x), 1, 2, 4, 8, 16, 32 or 64 for differential with pin 4, 5, 6 or
7, pad or internal GND as negative input.
\arg ADCCH_FORCE_1X_GAINSTAGE to force the gain stage to be enabled with
unity gain for differential measurement.

\note The GND signals are not available on all devices. Refer to the device
manual for information on available input signals.

\note With unity (1x) gain, some input selections may be possible both with
and without the gain stage enabled. The driver will default to the
configuration without gainstage to keep the current consumption as low as
possible unless the user specifies \ref ADCCH_FORCE_1X_GAINSTAGE as \a gain.
\ brief Set ADC channel input mode multiplexing and gain Sets up an ADC channel ' s input mode and multiplexing according to specified input signals as well as the gain . \ param ch_conf Pointer to ADC channel configuration . \ param pos Positive input signal . \ param neg Negative input signal : \ arg \ c ADCCH_NEG_NONE for single - ended measurements . \ arg \ c ADCCH_NEG_PINn where \ c n specifies a pin for differential measurements . \ arg \ c ADDCH_x_GND where \ c x specified pad or internal GND for differential measurements . \ param gain Gain factor for measurements : \ arg 1 for single - ended or differential with pin 0 1 2 or 3 pad or internal GND as negative input . \ arg 0 ( 0 . 5x ) 1 2 4 8 16 32 or 64 for differential with pin 4 5 6 or 7 pad or internal GND as negative input . \ arg ADCCH_FORCE_1X_GAINSTAGE to force the gain stage to be enabled with unity gain for differential measurement . \ note The GND signals are not available on all devices . Refer to the device manual for information on available input signals . \ note With unity ( 1x ) gain some input selections may be possible both with and without the gain stage enabled . The driver will default to the configuration without gainstage to keep the current consumption as low as possible unless the user specifies \ ref ADCCH_FORCE_1X_GAINSTAGE as \ a gain .
static inline void adcch_set_input (struct adc_channel_config *ch_conf,
				      enum adcch_positive_input pos,
				      enum adcch_negative_input neg,
				      uint8_t gain)
  {
    if (pos >= ADCCH_POS_TEMPSENSE)
      {
	Assert (gain == 1);
	Assert (neg == ADCCH_NEG_NONE);
	ch_conf->ctrl = ADC_CH_INPUTMODE_INTERNAL_gc;
	ch_conf->muxctrl = (pos - ADCCH_POS_TEMPSENSE) << ADC_CH_MUXPOS_gp;
      }
    else if (neg == ADCCH_NEG_NONE)
      {
	Assert (gain == 1);
	ch_conf->ctrl = ADC_CH_INPUTMODE_SINGLEENDED_gc;
	ch_conf->muxctrl = pos << ADC_CH_MUXPOS_gp;
      }
    else if (neg <= ADCCH_NEG_PIN3)
      {
#if XMEGA_E
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAINL_gc;
#else
	Assert (gain == 1);
	ch_conf->ctrl = ADC_CH_INPUTMODE_DIFF_gc;
#endif
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  (neg << ADC_CH_MUXNEG_gp);
      }
    else if (neg <= ADCCH_NEG_PIN7)
      {
#if XMEGA_E
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAINH_gc;
#else
	ch_conf->ctrl = adcch_get_gain_setting (gain) |
	  ADC_CH_INPUTMODE_DIFFWGAIN_gc;
#endif
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  ((neg - ADCCH_NEG_PIN4) << ADC_CH_MUXNEG_gp);
      }
    else
      {
	Assert ((neg == ADCCH_NEG_PAD_GND) ||
		(neg == ADCCH_NEG_INTERNAL_GND));
#if XMEGA_E
	ch_conf->ctrl = ADC_CH_INPUTMODE_DIFFWGAINL_gc |
	  adcch_get_gain_setting (gain);
	ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	  ((neg == ADCCH_NEG_INTERNAL_GND) ?
	   ADC_CH_MUXNEGL_INTGND_gc : ADC_CH_MUXNEGL_GND_gc);
#else
	if (gain == 1)
	  {
	    ch_conf->ctrl = ADC_CH_INPUTMODE_DIFF_gc;
	    ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	      ((neg == ADCCH_NEG_PAD_GND) ?
	       ADC_CH_MUXNEG_MODE10_GND_gc : ADC_CH_MUXNEG_MODE10_INTGND_gc);
	  }
	else
	  {
	    ch_conf->ctrl = ADC_CH_INPUTMODE_DIFFWGAIN_gc |
	      adcch_get_gain_setting (gain);
	    ch_conf->muxctrl = (pos << ADC_CH_MUXPOS_gp) |
	      ((neg == ADCCH_NEG_INTERNAL_GND) ?
	       ADC_CH_MUXNEG_MODE11_INTGND_gc : ADC_CH_MUXNEG_MODE11_GND_gc);
	  }
#endif
      }
  }
static inline void adcch_set_input ( struct adc_channel_config * ch_conf , enum adcch_positive_input pos , enum adcch_negative_input neg , uint8_t gain ) { if ( pos >= ADCCH_POS_TEMPSENSE ) { Assert ( gain == 1 ) ; Assert ( neg == ADCCH_NEG_NONE ) ; ch_conf -> ctrl = ADC_CH_INPUTMODE_INTERNAL_gc ; ch_conf -> muxctrl = ( pos - ADCCH_POS_TEMPSENSE ) << ADC_CH_MUXPOS_gp ; } else if ( neg == ADCCH_NEG_NONE ) { Assert ( gain == 1 ) ; ch_conf -> ctrl = ADC_CH_INPUTMODE_SINGLEENDED_gc ; ch_conf -> muxctrl = pos << ADC_CH_MUXPOS_gp ; } else if ( neg <= ADCCH_NEG_PIN3 ) { #if XMEGA_E ch_conf -> ctrl = adcch_get_gain_setting ( gain ) | ADC_CH_INPUTMODE_DIFFWGAINL_gc ; #else Assert ( gain == 1 ) ; ch_conf -> ctrl = ADC_CH_INPUTMODE_DIFF_gc ; #endif ch_conf -> muxctrl = ( pos << ADC_CH_MUXPOS_gp ) | ( neg << ADC_CH_MUXNEG_gp ) ; } else if ( neg <= ADCCH_NEG_PIN7 ) { #if XMEGA_E ch_conf -> ctrl = adcch_get_gain_setting ( gain ) | ADC_CH_INPUTMODE_DIFFWGAINH_gc ; #else ch_conf -> ctrl = adcch_get_gain_setting ( gain ) | ADC_CH_INPUTMODE_DIFFWGAIN_gc ; #endif ch_conf -> muxctrl = ( pos << ADC_CH_MUXPOS_gp ) | ( ( neg - ADCCH_NEG_PIN4 ) << ADC_CH_MUXNEG_gp ) ; } else { Assert ( ( neg == ADCCH_NEG_PAD_GND ) || ( neg == ADCCH_NEG_INTERNAL_GND ) ) ; #if XMEGA_E ch_conf -> ctrl = ADC_CH_INPUTMODE_DIFFWGAINL_gc | adcch_get_gain_setting ( gain ) ; ch_conf -> muxctrl = ( pos << ADC_CH_MUXPOS_gp ) | ( ( neg == ADCCH_NEG_INTERNAL_GND ) ? ADC_CH_MUXNEGL_INTGND_gc : ADC_CH_MUXNEGL_GND_gc ) ; #else if ( gain == 1 ) { ch_conf -> ctrl = ADC_CH_INPUTMODE_DIFF_gc ; ch_conf -> muxctrl = ( pos << ADC_CH_MUXPOS_gp ) | ( ( neg == ADCCH_NEG_PAD_GND ) ? ADC_CH_MUXNEG_MODE10_GND_gc : ADC_CH_MUXNEG_MODE10_INTGND_gc ) ; } else { ch_conf -> ctrl = ADC_CH_INPUTMODE_DIFFWGAIN_gc | adcch_get_gain_setting ( gain ) ; ch_conf -> muxctrl = ( pos << ADC_CH_MUXPOS_gp ) | ( ( neg == ADCCH_NEG_INTERNAL_GND ) ? ADC_CH_MUXNEG_MODE11_INTGND_gc : ADC_CH_MUXNEG_MODE11_GND_gc ) ; } #endif } }
\brief Set ADC channel input mode, multiplexing and gain
 Sets up an ADC channel's input mode and multiplexing according to specified
 input signals, as well as the gain.
\ brief Set ADC channel input mode multiplexing and gain Sets up an ADC channel ' s input mode and multiplexing according to specified input signals as well as the gain .
/* Configure for internal input. */ /* Configure for single-ended measurement. */ /* Configure for differential measurement.
	 * Pins 0-3 can only be used for negative input if the gain
	 * stage is not used, i.e., unity gain (except XMEGA E).
	 */ /* Configure for differential measurement.
	 * Pins 4-7 can be used for all gain settings,
	 * including unity gain, which is available even if
	 * the gain stage is active.
	 */ /* Configure for differential measurement through PAD GND or
	 * internal GND.
	 * DIFFWGAINH (INPUTMODE) is not used because it support
	 * only PAD GND.
	 */ /* Configure for differential measurement through GND or
	 * internal GND.
	 * The bitmasks for the on-chip GND signals change when
	 * gain is enabled. To avoid unnecessary current consumption,
	 * do not enable gainstage for unity gain unless user explicitly
	 * specifies it with the ADCCH_FORCE_1X_GAINSTAGE macro.
	 */