-
Notifications
You must be signed in to change notification settings - Fork 1
/
analogMux.h
46 lines (33 loc) · 1.07 KB
/
analogMux.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* From https://github.com/rudolfbyker/analog-multiplexer
*/
#ifndef ANALOG_MUX_H
#define ANALOG_MUX_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct AnalogMux8 {
uint8_t selectorPin0; // Least significant bit.
uint8_t selectorPin1;
uint8_t selectorPin2; // Most significant bit.
uint8_t analogPin; // Where we read or write the value.
uint8_t analogPinDirection; // OUTPUT=1, INPUT=0
uint16_t delayAfterSelection; // Delay between selection and using the analog pin to allow the mux to settle.
};
void analogMux8_init(const struct AnalogMux8 *self);
uint32_t analogMux8_selectAndRead(const struct AnalogMux8 *self, uint8_t selector);
void analogMux8_selectAndWrite(const struct AnalogMux8 *self, uint8_t selector, uint32_t value);
void analogMux8_select(const struct AnalogMux8 *self, uint8_t selector);
void createConsecutiveMuxesInArray(
uint8_t firstSelectorPin,
uint8_t firstAnalogPin,
uint8_t analogPinDirection,
uint16_t delayAfterSelection,
uint8_t numMuxes,
struct AnalogMux8 *const muxes
);
#ifdef __cplusplus
}
#endif
#endif