adc.h 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //adc.h
  2. #ifndef _ADC_H
  3. #define _ADC_H
  4. #include <inttypes.h>
  5. #include "config.h"
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif //defined(__cplusplus)
  9. /*
  10. http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
  11. */
  12. #define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
  13. #define BX_(x) ((x) - (((x)>>1)&0x77777777) - (((x)>>2)&0x33333333) - (((x)>>3)&0x11111111))
  14. #define ADC_PIN_IDX(pin) BITCOUNT(ADC_CHAN_MSK & ((1 << (pin)) - 1))
  15. #if BITCOUNT(ADC_CHAN_MSK) != ADC_CHAN_CNT
  16. # error "ADC_CHAN_MSK oes not match ADC_CHAN_CNT"
  17. #endif
  18. extern uint8_t adc_state;
  19. extern uint8_t adc_count;
  20. extern uint16_t adc_values[ADC_CHAN_CNT];
  21. extern uint16_t adc_sim_mask;
  22. extern void adc_init(void);
  23. extern void adc_reset(void);
  24. extern void adc_setmux(uint8_t ch);
  25. extern uint8_t adc_chan(uint8_t index);
  26. extern void adc_cycle(void);
  27. #if defined(__cplusplus)
  28. }
  29. #endif //defined(__cplusplus)
  30. #endif //_ADC_H