Skip to content

Commit

Permalink
Merge pull request #5 from xC0000005/More-ADC-Work
Browse files Browse the repository at this point in the history
Switch all enums to be within #defines
  • Loading branch information
victorpv authored Oct 6, 2017
2 parents 9c9f5c9 + 4a14971 commit f881d07
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions Marlin/src/HAL/HAL_STM32F1/HAL_Stm32f1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
// --------------------------------------------------------------------------
// Variables
// --------------------------------------------------------------------------
STM32ADC adc(ADC1);

// --------------------------------------------------------------------------
// Public Variables
Expand Down Expand Up @@ -88,16 +89,30 @@ uint8 adc_pins[] = {

enum TEMP_PINS
{
#if HAS_TEMP_0
TEMP_0,
#endif
#if HAS_TEMP_1
TEMP_1,
#endif
#if HAS_TEMP_2
TEMP_2,
#endif
#if HAS_TEMP_3
TEMP_3,
#endif
#if HAS_TEMP_4
TEMP_4,
#endif
#if HAS_TEMP_BED
TEMP_BED,
FILWIDTH
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
FILWIDTH,
#endif
ADC_PIN_COUNT
};

#define ADC_PIN_COUNT (sizeof(adc_pins)/sizeof(adc_pins[0]))
uint16_t HAL_adc_results[ADC_PIN_COUNT];


Expand Down Expand Up @@ -180,30 +195,44 @@ void HAL_adc_init(void)

void HAL_adc_start_conversion (uint8_t adc_pin) {
TEMP_PINS pin_index = TEMP_0;
if (adc_pin == TEMP_0_PIN){
pin_index = TEMP_0;
}

else if (adc_pin == TEMP_1_PIN) {
switch (adc_pin) {
#if HAS_TEMP_0
case TEMP_0_PIN:
pin_index = TEMP_0;
break;
#endif
#if HAS_TEMP_1
case TEMP_1_PIN:
pin_index = TEMP_1;
}
else if (adc_pin == TEMP_2_PIN) {
break;
#endif
#if HAS_TEMP_2
case TEMP_2_PIN:
pin_index = TEMP_2;
}
else if (adc_pin == TEMP_3_PIN) {
break;
#endif
#if HAS_TEMP_3
case TEMP_3_PIN:
pin_index = TEMP_3;
}
else if (adc_pin == TEMP_4_PIN) {
break;
#endif
#if HAS_TEMP_4
case TEMP_4_PIN:
pin_index = TEMP_4;
}
else if (adc_pin == TEMP_BED_PIN) {
break;
#endif
#if HAS_TEMP_BED
case TEMP_BED_PIN:
pin_index = TEMP_BED;
}
#if ENABLED(FILAMENT_WIDTH_SENSOR)
else if (adc_pin == FILWIDTH_PIN) {
break;
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
case FILWIDTH_PIN:
pin_index = FILWIDTH;
break;
#endif
}
#endif

HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2)& 0x3ff; // shift to get 10 bits only.
}
Expand Down

0 comments on commit f881d07

Please sign in to comment.