29-10-2015, 04:32 PM
I usually define a enum in a project specific H file, to represent a set of signals:
typedef enum {
ADC_VBAT
ADC_FEEDBACK,
ADC_VOLTAGE,
ADC_NUM_SIGNALS
} adc_t ;
And then in the reusable C file, iterate over the configured set of signals. For example, to set the initial value of the averaged signal:
uint8_t i ;
for (i=0U; i < (uint8_t) ADC_NUM_SIGNALS; i++)
{
AdcClearAverage((adc_t) i) ;
}
where AdcClearAverage takes a parameter of type adc_t.
But this now generates warning 10.5 as an unsigned type is being cast to an enum.
What is the correct way to iterate over an enumeration?
typedef enum {
ADC_VBAT
ADC_FEEDBACK,
ADC_VOLTAGE,
ADC_NUM_SIGNALS
} adc_t ;
And then in the reusable C file, iterate over the configured set of signals. For example, to set the initial value of the averaged signal:
uint8_t i ;
for (i=0U; i < (uint8_t) ADC_NUM_SIGNALS; i++)
{
AdcClearAverage((adc_t) i) ;
}
where AdcClearAverage takes a parameter of type adc_t.
But this now generates warning 10.5 as an unsigned type is being cast to an enum.
What is the correct way to iterate over an enumeration?
<t>Dermot</t>