Statistics
| Branch: | Tag: | Revision:

amiro-os / include / amiro / bus / i2c / VI2CDriver.hpp @ d4c6efa9

History | View | Annotate | Download (1.189 KB)

1 58fe0e0b Thomas Schöpping
#ifndef MUXEDI2CDRIVER_HPP_
2
#define MUXEDI2CDRIVER_HPP_
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
  struct I2CTxParams;
14
  struct I2CRxParams;
15
16
  class I2CMultiplexer;
17
18
  /**
19
   * @brief   Virtual I²C Driver
20
   */
21
  class VI2CDriver : public I2CDriver {
22
23
  public:
24
25
    VI2CDriver(I2CMultiplexer *driver, const uint8_t bus_id);
26
    virtual ~VI2CDriver() {}
27
    virtual void start(const ::I2CConfig *config);
28
    virtual void stop();
29
    virtual i2cflags_t getErrors();
30
    virtual msg_t masterTransmit(const I2CTxParams *params, systime_t timeout = TIME_INFINITE);
31
    virtual msg_t masterReceive(const I2CRxParams *params, systime_t timeout = TIME_INFINITE);
32
33
    virtual void acquireBus();
34
    virtual void releaseBus();
35
36
  private:
37
38
    I2CMultiplexer *driver;
39
    uint8_t id;
40
41
#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
42
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
43
    /**
44
    * @brief   Mutex protecting the bus.
45
    */
46
    ::Mutex                     mutex;
47
#elif CH_USE_SEMAPHORES
48
    ::Semaphore                 semaphore;
49
#endif
50
#endif /* I2C_USE_MUTUAL_EXCLUSION */
51
52
  };
53
54
} /* amiro */
55
56
#endif /* MUXEDI2CDRIVER_HPP_ */