aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLee Campbell <leecam@google.com>2016-03-11 16:28:55 -0800
committerLee Campbell <leecam@google.com>2016-03-15 15:11:22 -0700
commit99867e2357be2b06e676f43a32ece79e2e35581f (patch)
treedaeec2b0901c8ba9e7b266f650ee3f5aa4195359 /include
parent8deeb0f6d253ec82c51c91c426d8f3c3a623d7c2 (diff)
downloadperipheralmanager-99867e2357be2b06e676f43a32ece79e2e35581f.tar.gz
Add I2C manager
Add basic support for I2C. Only Read Register command supported so far. BUG: 26776321 TEST: Testing I2C temp sensor Change-Id: Id4a2e96df489c64b2724ac3995557459f285667c
Diffstat (limited to 'include')
-rw-r--r--include/peripheralmanager/i2c_device.h54
-rw-r--r--include/peripheralmanager/peripheral_manager_client.h22
2 files changed, 76 insertions, 0 deletions
diff --git a/include/peripheralmanager/i2c_device.h b/include/peripheralmanager/i2c_device.h
new file mode 100644
index 0000000..f55de01
--- /dev/null
+++ b/include/peripheralmanager/i2c_device.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSTEM_PERIPHERALMANAGER_I2C_DEVICE_H_
+#define SYSTEM_PERIPHERALMANAGER_I2C_DEVICE_H_
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/// @defgroup I2c I2c device interface
+/// @brief Functions to control an I2C device.
+///
+/// These functions can be used to control an I2C device.
+/// @{
+
+typedef struct BI2cDevice BI2cDevice;
+
+
+/// Reads an I2C register.
+/// @param device Pointer to the BI2cDevice struct.
+/// @param val Output pointer to value to read.
+/// @return 0 on success, errno on error
+int BI2cDevice_readRegByte(const BI2cDevice* device, uint8_t reg, uint8_t* val);
+
+/// Reads an I2C register.
+/// @param device Pointer to the BI2cDevice struct.
+/// @param val Output pointer to value to read.
+/// @return 0 on success, errno on error
+int BI2cDevice_readRegWord(const BI2cDevice* device, uint8_t reg, uint16_t* val);
+
+/// Destroys a BI2cDevice struct.
+/// @param device Pointer to the BI2cDevice struct.
+void BI2cDevice_delete(BI2cDevice* device);
+
+/// @}
+
+__END_DECLS
+
+#endif // SYSTEM_PERIPHERALMANAGER_I2C_DEVICE_H_
diff --git a/include/peripheralmanager/peripheral_manager_client.h b/include/peripheralmanager/peripheral_manager_client.h
index bb76099..8941a4c 100644
--- a/include/peripheralmanager/peripheral_manager_client.h
+++ b/include/peripheralmanager/peripheral_manager_client.h
@@ -20,6 +20,7 @@
#include <sys/cdefs.h>
#include "peripheralmanager/gpio.h"
+#include "peripheralmanager/i2c_device.h"
#include "peripheralmanager/led.h"
#include "peripheralmanager/spi_device.h"
@@ -94,6 +95,27 @@ int BPeripheralManagerClient_openLed(const BPeripheralManagerClient* client,
const char* name,
BLed** led);
+/// Returns the list of I2C buses.
+/// This does not take ownership into account.
+/// The list must be freed by the caller.
+/// @param client Pointer to the BPeripheralManagerClient struct.
+/// @param num_i2c_buses Output pointer to the number of element in the list.
+/// @return The list of i2c buses.
+char** BPeripheralManagerClient_listI2cBuses(
+ const BPeripheralManagerClient* client,
+ int* num_i2c_buses);
+
+/// Opens an I2C device and takes ownership of it.
+/// @oaram client Pointer to the BPeripheralManagerClient struct.
+/// @param name Name of the SPI device.
+/// @param dev Output pointer to the BI2cDevice struct. Empty on error.
+/// @return 0 on success, errno on error
+int BPeripheralManagerClient_openI2cDevice(
+ const BPeripheralManagerClient* client,
+ const char* name,
+ uint32_t address,
+ BI2cDevice** dev);
+
/// Creates a new client.
/// @return A pointer to the created client. nullptr on errors.
BPeripheralManagerClient* BPeripheralManagerClient_new();