upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
tca9548a.hpp
1 /*
2  * Author: Gerard Vidal <gerard.vidal@ens-lyon.fr>
3  * Copyright (c) 2017 IFE-ENS-Lyon
4  * Author: Keelan Lightfoot <keelanlightfoot@gmail.com>
5  * Copyright (c) 2015 Intel Corporation.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #pragma once
28 
29 #include <iostream>
30 #include <string>
31 #include "mraa.hpp"
32 #include "mraa/i2c.hpp"
33 
34 #define TCA9548A_I2C_BUS 0
35 #define TCA9548A_DEFAULT_ADDR 0x70
36 #define TCA9548A_NO_PORTS 0x00
37 #define TCA9548A_ALL_PORTS 0xFF
38 
39 #define TCA9548A_MIN_PORT 0
40 #define TCA9548A_MAX_PORT 7
41 
42 namespace upm {
95  class TCA9548A {
96 
97  public:
105  typedef enum {
106  DISABLED = 0,
107  ENABLED = 1
109 
117  typedef enum {
118  EXCLUSIVE = 0,
119  INCLUSIVE = 1
121 
122 
128  TCA9548A (int bus, uint8_t address = 0x70);
129 
133  ~TCA9548A();
134 
138  std::string name() {
139  return m_name;
140  }
141 
147  bool getPort(int port);
148 
161  void setPort(int port, TCA9548A_PORT_STATE state,
162  TCA9548A_PORT_MODE mode);
163 
167  void disableAllPorts();
168 
174  void enableAllPorts();
175 
176  private:
177  /* Disable implicit copy and assignment operators */
178  TCA9548A(const TCA9548A&) = delete;
179  TCA9548A &operator=(const TCA9548A&) = delete;
180 
181  std::string m_name;
182 
183  mraa::I2c* i2c;
184 
185  uint8_t getPortConfig();
186  void setPortConfig(uint8_t config);
187  bool validPort(int port);
188  };
189 }
~TCA9548A()
Definition: tca9548a.cxx:59
std::string name()
Definition: tca9548a.hpp:138
void setPort(int port, TCA9548A_PORT_STATE state, TCA9548A_PORT_MODE mode)
Definition: tca9548a.cxx:80
bool getPort(int port)
Definition: tca9548a.cxx:65
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void disableAllPorts()
Definition: tca9548a.cxx:108
TCA9548A_PORT_STATE
boolean enum containing port state
Definition: tca9548a.hpp:105
TCA9548A_PORT_MODE
boolean enum containing port access mode
Definition: tca9548a.hpp:117
TCA9548A(int bus, uint8_t address=0x70)
Definition: tca9548a.cxx:38
API TCA9548A Multiplexer Breakout.
Definition: tca9548a.hpp:95
void enableAllPorts()
Definition: tca9548a.cxx:114