amiro-os / include / amiro / bus / i2c / I2CMultiplexer.hpp @ 81b48c66
History | View | Annotate | Download (1.07 KB)
1 | 58fe0e0b | Thomas Schöpping | #ifndef AI2CMULTIPLEXER
|
---|---|---|---|
2 | #define AI2CMULTIPLEXER
|
||
3 | |||
4 | #include <ch.hpp> |
||
5 | #include <hal.h> |
||
6 | #include <amiro/bus/i2c/I2CDriver.hpp> |
||
7 | |||
8 | /**
|
||
9 | * @brief AMiRo
|
||
10 | */
|
||
11 | namespace amiro {
|
||
12 | |||
13 | /**
|
||
14 | * @brief I²C Bus Multiplexer
|
||
15 | */
|
||
16 | class I2CMultiplexer { |
||
17 | |||
18 | public:
|
||
19 | |||
20 | I2CMultiplexer(I2CDriver *driver); |
||
21 | virtual ~I2CMultiplexer() = 0; |
||
22 | |||
23 | virtual i2cflags_t getErrors();
|
||
24 | virtual msg_t masterTransmit(const I2CTxParams *params, systime_t timeout = TIME_INFINITE); |
||
25 | virtual msg_t masterReceive(const I2CRxParams *params, systime_t timeout = TIME_INFINITE); |
||
26 | |||
27 | virtual void acquireBus(); |
||
28 | virtual void releaseBus(); |
||
29 | |||
30 | virtual msg_t select(const uint8_t bus_id) = 0; |
||
31 | virtual msg_t deselect() = 0; |
||
32 | |||
33 | private:
|
||
34 | |||
35 | I2CDriver *driver; |
||
36 | |||
37 | #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
|
||
38 | #if CH_USE_MUTEXES || defined(__DOXYGEN__)
|
||
39 | /**
|
||
40 | * @brief Mutex protecting the bus.
|
||
41 | */
|
||
42 | ::Mutex mutex; |
||
43 | #elif CH_USE_SEMAPHORES
|
||
44 | ::Semaphore semaphore; |
||
45 | #endif
|
||
46 | #endif /* I2C_USE_MUTUAL_EXCLUSION */ |
||
47 | |||
48 | }; |
||
49 | |||
50 | } /* amiro */
|
||
51 | |||
52 | #endif /* AI2CMULTIPLEXER */ |