From 6ea2502228519b7a0668be0b1ec0d91ef74e4f06 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Mon, 29 Feb 2016 17:40:25 -0800 Subject: Define the developer interface for GPIO. This CL defines the C API that will be used by developers. Bug: 26778811 Change-Id: I1d5d3e3232f058eb573df49a02ee9f3da1e9e9ce --- include/peripheralmanager/errors.h | 30 +++++ include/peripheralmanager/gpio.h | 122 +++++++++++++++++++++ .../peripheralmanager/peripheral_manager_client.h | 75 +++++++++---- 3 files changed, 206 insertions(+), 21 deletions(-) create mode 100644 include/peripheralmanager/errors.h create mode 100644 include/peripheralmanager/gpio.h (limited to 'include') diff --git a/include/peripheralmanager/errors.h b/include/peripheralmanager/errors.h new file mode 100644 index 0000000..d0019ce --- /dev/null +++ b/include/peripheralmanager/errors.h @@ -0,0 +1,30 @@ +/* + * 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_ERRORS_H_ +#define SYSTEM_PERIPHERALMANAGER_ERRORS_H_ + +#include + +enum peripheral_error_t { + PERIPHERAL_IO_OK, + PERIPHERAL_IO_UNKNOWN_DEVICE, + PERIPHERAL_IO_DEVICE_IN_USE, + PERIPHERAL_IO_FUNCTION_NOT_IMPLEMENTED, + PERIPHERAL_IO_UNKNOWN_ERROR, +}; + +#endif // SYSTEM_PERIPHERALMANAGER_ERRORS_H_ diff --git a/include/peripheralmanager/gpio.h b/include/peripheralmanager/gpio.h new file mode 100644 index 0000000..883d15e --- /dev/null +++ b/include/peripheralmanager/gpio.h @@ -0,0 +1,122 @@ +/* + * 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_GPIO_H_ +#define SYSTEM_PERIPHERALMANAGER_GPIO_H_ + +#include +#include + +__BEGIN_DECLS + +// Edge trigger types. +enum { + NONE_EDGE, + RISING_EDGE, + FALLING_EDGE, + BOTH_EDGE, +}; + +// GPIO direction types. +enum { + DIRECTION_IN, + DIRECTION_OUT_INITIALLY_HIGH, + DIRECTION_OUT_INITIALLY_LOW, +}; + +// Possible active types. +enum { + ACTIVE_LOW, + ACTIVE_HIGH, +}; + +typedef struct BGpio BGpio; + +// Sets the GPIO direction to output. +// +// The physical initial value may be different from the logical value based +// on the active low status +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// direction: One of DIRECTION_IN, DIRECTION_OUT_INITIALLY_HIGH, +// DIRECTION_OUT_INITIALLY_LOW. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_setDirection(const BGpio* gpio, int direction); + +// Sets the interrupt edge trigger type. +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// type: One of NONE_EDGE, RISING_EDGE, FALLING_EDGE or BOTH_EDGE. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_setEdgeTriggerType(const BGpio* gpio, int type); + +// Sets the GPIO’s active low/high status. +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// type: One of ACTIVE_HIGH, ACTIVE_LOW. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_setActiveType(const BGpio* gpio, int type); + +// Sets the GPIO value (for output GPIO only). +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// value: Value to set. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_setValue(const BGpio* gpio, int value); + +// Gets the GPIO value (for input GPIO only). +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// value: Output pointer to the value of the GPIO. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_getValue(const BGpio* gpio, int* value); + +// Returns a file descriptor that can be used to poll on new data. +// +// Can be passed to select/epoll to wait for data to become available. +// +// Arguments: +// gpio: Pointer to the BGpio struct. +// fd: Output pointer to the file descriptor number. +// +// Returns: +// Error code (one of peripheral_error_t). +int BGpio_getPollFd(const BGpio* gpio, int* fd); + +// Destroys a BGpio struct. +// +// Arguments: +// gpio: Pointer to the BGpio struct. +void BGpio_delete(BGpio* gpio); + +__END_DECLS + +#endif // SYSTEM_PERIPHERALMANAGER_GPIO_H_ diff --git a/include/peripheralmanager/peripheral_manager_client.h b/include/peripheralmanager/peripheral_manager_client.h index 9eabb8c..48273ca 100644 --- a/include/peripheralmanager/peripheral_manager_client.h +++ b/include/peripheralmanager/peripheral_manager_client.h @@ -17,34 +17,67 @@ #ifndef SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_ #define SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_ -#include -#include +#include -namespace android { +#include "peripheralmanager/errors.h" +#include "peripheralmanager/gpio.h" -namespace os { -class IPeripheralManager; -} +__BEGIN_DECLS -// Used to communicate with the peripheral manager. -class PeripheralManagerClient { - public: - PeripheralManagerClient(); - ~PeripheralManagerClient(); +typedef struct BPeripheralManagerClient BPeripheralManagerClient; - // Initializes the object, returning true on success. Must be called before - // any other methods. - bool Init(); +// Returns the list of GPIOs. +// +// This does not take ownership into account. +// The list must be freed by the caller. +// +// Arguments: +// client: Pointer to the BPeripheralManagerClient struct. +// num_gpio: Output pointer to the number of element in the list. +// +// Returns: +// The list of gpios. +char** BPeripheralManagerClient_listGpio(const BPeripheralManagerClient* client, + int* num_gpio); - // Dummy method to test IPC - int AddInts(int a, int b); +// Returns the list of available GPIOs. +// +// The list must be freed by the caller. +// +// Arguments: +// client: Pointer to the BPeripheralManagerClient struct. +// num_buses: Output pointer to the number of element in the list. +// +// Returns: +// The list of buses. +char** BPeripheralManagerClient_listAvailableGpio( + const BPeripheralManagerClient* client, int* num_gpio); - private: - sp pmanager_; +// Opens a GPIO and takes ownership of it. +// +// Arguments: +// client: Pointer to the BPeripheralManagerClient struct. +// name: Name of the GPIO. +// gpio: Output pointer to the BGpio struct. Empty on error. +// +// Returns: +// Error code (one of peripheral_error_t). +int BPeripheralManagerClient_openGpio(const BPeripheralManagerClient* client, + const char* name, + BGpio** gpio); - DISALLOW_COPY_AND_ASSIGN(PeripheralManagerClient); -}; +// Creates a new client. +// +// Returns: +// A pointer to the created client. nullptr on errors. +BPeripheralManagerClient* BPeripheralManagerClient_new(); -} // namespace android +// Destroys the peripheral manager client. +// +// Arguments: +// client: Pointer to the BPeripheralManagerClient struct. +void BPeripheralManagerClient_delete(BPeripheralManagerClient* client); + +__END_DECLS #endif // SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_ -- cgit v1.2.3