extracted duplicate code into helper function.
This commit is contained in:
parent
6696a45a80
commit
3f1da7ff09
|
@ -46,7 +46,7 @@ bool is_below_target(uint16_t val)
|
|||
return false;
|
||||
}
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
uint16_t sample_adc(uint8_t adc_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
|
@ -54,6 +54,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
return val;
|
||||
}
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
uint16_t val = sample_adc(adc_pin);
|
||||
|
||||
if(is_valid_load(val) && !porta_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||
|
@ -66,12 +73,8 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|||
|
||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
ADC_SetPin(adc_pin);
|
||||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
uint16_t val = sample_adc(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(is_valid_load(val) && !portb_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||
|
|
Loading…
Reference in New Issue