Extracted duplicated code for ADC. Added new helper functions.
This commit is contained in:
parent
5df1d549bd
commit
1761ea38d9
|
@ -38,7 +38,7 @@ static bool valid_load(uint16_t val)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
static uint16_t sample_adc(uint8_t adc_pin)
|
||||||
{
|
{
|
||||||
ADC_Init(adc_pin);
|
ADC_Init(adc_pin);
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
|
@ -46,6 +46,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
uint16_t val = ADC_ReadValue(adc_pin);
|
uint16_t val = ADC_ReadValue(adc_pin);
|
||||||
|
|
||||||
ADC_Disable();
|
ADC_Disable();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
|
{
|
||||||
|
uint16_t val = sample_adc(adc_pin);
|
||||||
|
|
||||||
if(valid_load(val) && !porta_disabled[adc_pin]){
|
if(valid_load(val) && !porta_disabled[adc_pin]){
|
||||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||||
|
@ -58,12 +65,8 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
|
|
||||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||||
{
|
{
|
||||||
ADC_Init(adc_pin);
|
uint16_t val = sample_adc(adc_pin);
|
||||||
ADC_Enable();
|
|
||||||
ADC_SetPin(adc_pin);
|
|
||||||
uint16_t val = ADC_ReadValue(adc_pin);
|
|
||||||
|
|
||||||
ADC_Disable();
|
|
||||||
if(valid_load(val) && !portb_disabled[adc_pin]){
|
if(valid_load(val) && !portb_disabled[adc_pin]){
|
||||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||||
|
@ -73,3 +76,11 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||||
portb_disabled[adc_pin] = true;
|
portb_disabled[adc_pin] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Load_SoftResetDisabledLoads()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 8; i++){
|
||||||
|
porta_disabled[i] = false;
|
||||||
|
portb_disabled[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue