Tabs to spaces.
This commit is contained in:
parent
28daa804b4
commit
3d00faf639
@ -16,46 +16,46 @@
|
|||||||
#include "analog.h"
|
#include "analog.h"
|
||||||
|
|
||||||
uint16_t analog_read(uint8_t pin) {
|
uint16_t analog_read(uint8_t pin) {
|
||||||
|
|
||||||
/* Enable ADC and set prescaler. */
|
/* Enable ADC and set prescaler. */
|
||||||
ADCSRA = _BV(ADEN) | ADC_PRESCALER;
|
ADCSRA = _BV(ADEN) | ADC_PRESCALER;
|
||||||
|
|
||||||
/* Set high speed mode. */
|
/* Set high speed mode. */
|
||||||
ADCSRB |= _BV(ADHSM);
|
ADCSRB |= _BV(ADHSM);
|
||||||
|
|
||||||
/* Set adc reference and select mux. */
|
/* Set adc reference and select mux. */
|
||||||
ADMUX = ADC_REF | (pin & 0b00011111);
|
ADMUX = ADC_REF | (pin & 0b00011111);
|
||||||
|
|
||||||
/* Start conversion. */
|
/* Start conversion. */
|
||||||
ADCSRA |= _BV(ADSC);
|
ADCSRA |= _BV(ADSC);
|
||||||
|
|
||||||
/* Wait until adc has result ready. */
|
/* Wait until adc has result ready. */
|
||||||
loop_until_bit_is_clear(ADCSRA, ADSC);
|
loop_until_bit_is_clear(ADCSRA, ADSC);
|
||||||
|
|
||||||
/* Word! */
|
/* Word! */
|
||||||
return ADCW;
|
return ADCW;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t analog_read_byte(uint8_t pin) {
|
uint8_t analog_read_byte(uint8_t pin) {
|
||||||
|
|
||||||
/* Enable ADC and set prescaler. */
|
/* Enable ADC and set prescaler. */
|
||||||
ADCSRA = _BV(ADEN) | ADC_PRESCALER;
|
ADCSRA = _BV(ADEN) | ADC_PRESCALER;
|
||||||
|
|
||||||
/* Set high speed mode. */
|
/* Set high speed mode. */
|
||||||
ADCSRB |= _BV(ADHSM);
|
ADCSRB |= _BV(ADHSM);
|
||||||
|
|
||||||
/* Set adc reference and select mux. */
|
/* Set adc reference and select mux. */
|
||||||
ADMUX = ADC_REF | (pin & 0b00011111);
|
ADMUX = ADC_REF | (pin & 0b00011111);
|
||||||
|
|
||||||
/* Left adjust the 10 bit result. */
|
/* Left adjust the 10 bit result. */
|
||||||
ADMUX |= (1<<ADLAR);
|
ADMUX |= (1<<ADLAR);
|
||||||
|
|
||||||
/* Start conversion. */
|
/* Start conversion. */
|
||||||
ADCSRA |= _BV(ADSC);
|
ADCSRA |= _BV(ADSC);
|
||||||
|
|
||||||
/* Wait until adc has result ready. */
|
/* Wait until adc has result ready. */
|
||||||
loop_until_bit_is_clear(ADCSRA, ADSC);
|
loop_until_bit_is_clear(ADCSRA, ADSC);
|
||||||
|
|
||||||
/* Hight byte. */
|
/* Hight byte. */
|
||||||
return ADCH;
|
return ADCH;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user