satnogs-rotator-firmware
Loading...
Searching...
No Matches
libraries
i2c_mux.h
Go to the documentation of this file.
1
10
#ifndef I2C_MUX_H_
11
#define I2C_MUX_H_
12
13
#include <Arduino.h>
14
#include <Wire.h>
15
16
#define I2C_FREQ 100000
17
18
/**************************************************************************/
28
/**************************************************************************/
29
class
i2c_mux
{
30
public
:
31
32
i2c_mux
(uint8_t
id
, uint8_t ch0, uint8_t ch1) {
33
_id
= id;
34
_ch0
= ch0;
35
_ch1
= ch1;
36
}
37
38
/**************************************************************************/
42
/**************************************************************************/
43
void
init
() {
44
Wire.begin();
45
Wire.setClock(
I2C_FREQ
);
46
}
47
48
/**************************************************************************/
54
/**************************************************************************/
55
void
set_channel
(uint8_t ch) {
56
if
(ch ==
_ch0
) {
57
Wire.beginTransmission(
_id
);
58
Wire.write(
_ch0
);
59
Wire.endTransmission();
60
}
else
if
(ch ==
_ch1
) {
61
Wire.beginTransmission(
_id
);
62
Wire.write(
_ch1
);
63
Wire.endTransmission();
64
}
65
}
66
67
private
:
68
uint8_t
_id
,
_ch0
,
_ch1
;
69
};
70
71
#endif
/* I2C_MUX_H_ */
i2c_mux
Class that functions for interacting with I2C 1-of-2 multiplexer.
Definition
i2c_mux.h:29
i2c_mux::init
void init()
Initialize the I2C bus.
Definition
i2c_mux.h:43
i2c_mux::_ch1
uint8_t _ch1
Definition
i2c_mux.h:68
i2c_mux::i2c_mux
i2c_mux(uint8_t id, uint8_t ch0, uint8_t ch1)
Definition
i2c_mux.h:32
i2c_mux::_ch0
uint8_t _ch0
Definition
i2c_mux.h:68
i2c_mux::_id
uint8_t _id
Definition
i2c_mux.h:68
i2c_mux::set_channel
void set_channel(uint8_t ch)
Change the channel.
Definition
i2c_mux.h:55
I2C_FREQ
#define I2C_FREQ
Definition
i2c_mux.h:16
Generated by
1.12.0