diff options
author | Bertrand SIMONNET <bsimonnet@google.com> | 2016-04-26 17:01:19 -0700 |
---|---|---|
committer | Bertrand SIMONNET <bsimonnet@google.com> | 2016-05-24 14:38:26 -0700 |
commit | 9670f0eedd5a342db97a5d263a924b9ae2eda4fe (patch) | |
tree | fbf4e20c20520c0ac513fd8700b55e37f356674a /include | |
parent | 453101d9460390d8e0ea62cda645f6a2f5b29a61 (diff) | |
download | peripheralmanager-9670f0eedd5a342db97a5d263a924b9ae2eda4fe.tar.gz |
Implement the client side UART interface.
This CL adds the C APIs to act on UART devices as well as unit tests and
an example.
Bug: 27898961
Change-Id: I23f627d69fb3440fec53bded20bd3b408c9ed591
Diffstat (limited to 'include')
-rw-r--r-- | include/peripheralmanager/peripheral_manager_client.h | 25 | ||||
-rw-r--r-- | include/peripheralmanager/uart_device.h | 70 |
2 files changed, 93 insertions, 2 deletions
diff --git a/include/peripheralmanager/peripheral_manager_client.h b/include/peripheralmanager/peripheral_manager_client.h index 5fdc5ff..51821b0 100644 --- a/include/peripheralmanager/peripheral_manager_client.h +++ b/include/peripheralmanager/peripheral_manager_client.h @@ -23,6 +23,7 @@ #include "peripheralmanager/i2c_device.h" #include "peripheralmanager/led.h" #include "peripheralmanager/spi_device.h" +#include "peripheralmanager/uart_device.h" __BEGIN_DECLS @@ -97,8 +98,9 @@ char** BPeripheralManagerClient_listI2cBuses( 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 client Pointer to the BPeripheralManagerClient struct. +/// @param name Name of the I2C bus. +/// @param address Address of the I2C device. /// @param dev Output pointer to the BI2cDevice struct. Empty on error. /// @return 0 on success, errno on error int BPeripheralManagerClient_openI2cDevice( @@ -107,6 +109,25 @@ int BPeripheralManagerClient_openI2cDevice( uint32_t address, BI2cDevice** dev); +/// Returns the list of UART 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_uart_buses Output pointer to the number of element in the list. +/// @return The list of uart buses. +char** BPeripheralManagerClient_listUartDevices( + const BPeripheralManagerClient* client, int* num_uart_buses); + +/// Opens an UART device and takes ownership of it. +/// @param client Pointer to the BPeripheralManagerClient struct. +/// @param name Name of the UART device. +/// @param dev Output pointer to the BUartDevice struct. Empty on error. +/// @return 0 on success, errno on error +int BPeripheralManagerClient_openUartDevice( + const BPeripheralManagerClient* client, + const char* name, + BUartDevice** dev); + /// Creates a new client. /// @return A pointer to the created client. nullptr on errors. BPeripheralManagerClient* BPeripheralManagerClient_new(); diff --git a/include/peripheralmanager/uart_device.h b/include/peripheralmanager/uart_device.h new file mode 100644 index 0000000..057a068 --- /dev/null +++ b/include/peripheralmanager/uart_device.h @@ -0,0 +1,70 @@ +/* + * 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_UART_DEVICE_H_ +#define SYSTEM_PERIPHERALMANAGER_UART_DEVICE_H_ + +#include <sys/cdefs.h> +#include <sys/types.h> + +__BEGIN_DECLS + +/// @defgroup Uart Uart device interface +/// @brief Functions to control an UART device. +/// +/// These functions can be used to control an UART device. +/// @{ + +typedef struct BUartDevice BUartDevice; + +/// Writes to a UART device. +/// @param device Pointer to the BUartDevice struct. +/// @param data Data to write. +/// @param len Size of the data to write. +/// @param bytes_written Output pointer to the number of bytes written. +/// @return 0 on success, errno on error. +int BUartDevice_write(const BUartDevice* device, + const void* data, + uint32_t len, + uint32_t* bytes_written); + +/// Reads from a UART device. +/// @param device Pointer to the BUartDevice struct. +/// @param data Buffer to read the data into. +/// @param len Number of bytes to read. +/// @param bytes_read Output pointer to the number of bytes read. +/// @return 0 on success, errno on error. +int BUartDevice_read(const BUartDevice* device, + void* data, + uint32_t len, + uint32_t* bytes_read); + +/// Sets the input and output speed of a UART device. +/// @param device Pointer to the BUartDevice struct. +/// @param device Uart device to configure. +/// @param baudrate Speed in baud. +/// @return 0 on success, errno on error. +int BUartDevice_setBaudrate(const BUartDevice* device, uint32_t baudrate); + +/// Destroys a BUartDevice struct. +/// @param device Pointer to the BUartDevice struct. +void BUartDevice_delete(BUartDevice* device); + +/// @} + +__END_DECLS + +#endif // SYSTEM_PERIPHERALMANAGER_UART_DEVICE_H_ |