Private
Public Access
2
0

pio: Remove pio headers from MRAA

The Native PIO API provides both the libraries and headers for use with
the Android Things Peripheralanager client.  This commit removes these
from the MRAA repo in favor of the FindAndroidThings.cmake provided by
the Native PIO API.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2017-04-17 11:50:25 -07:00
parent 380d2cf638
commit 3e19a58710
12 changed files with 13 additions and 720 deletions

View File

@@ -1,107 +0,0 @@
/*
* 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 <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
/// @defgroup Gpio Gpio Interface
/// @brief Functions to control GPIO pins.
///
/// These functions can be used to control GPIO.
/// @{
/// Edge trigger types.
typedef enum AGpioEdge {
AGPIO_EDGE_NONE = 0, /**< None */
AGPIO_EDGE_RISING = 1, /**< Rising edge */
AGPIO_EDGE_FALLING = 2, /**< Falling edge */
AGPIO_EDGE_BOTH = 3 /**< Both edges */
} AGpioEdge;
/// GPIO direction types.
typedef enum AGpioDirection {
AGPIO_DIRECTION_IN = 0, /**< Input mode */
AGPIO_DIRECTION_OUT_INITIALLY_HIGH = 1, /**< Output mode, initially high */
AGPIO_DIRECTION_OUT_INITIALLY_LOW = 2 /**< Output mode, initially low */
} AGpioDirection;
/// Possible active types.
typedef enum AGpioActiveType {
AGPIO_ACTIVE_LOW = 0, /**< Active Low */
AGPIO_ACTIVE_HIGH = 1 /**< Active High */
} AGpioActiveType;
typedef struct AGpio AGpio;
/// Sets the GPIO direction to output.
/// @param gpio Pointer to the AGpio struct
/// @param direction One of DIRECTION_IN,
/// DIRECTION_OUT_INITIALLY_HIGH, DIRECTION_OUT_INITIALLY_LOW.
/// @return 0 on success, errno on error.
int AGpio_setDirection(const AGpio* gpio, AGpioDirection direction);
/// Sets the interrupt edge trigger type.
/// @param gpio Pointer to the AGpio struct
/// @param type One of NONE_EDGE, RISING_EDGE, FALLING_EDGE or BOTH_EDGE.
/// @return 0 on success, errno on error.
int AGpio_setEdgeTriggerType(const AGpio* gpio, AGpioEdge type);
/// Sets the GPIOs active low/high status.
/// @param gpio Pointer to the AGpio struct.
/// @param type One of ACTIVE_HIGH, ACTIVE_LOW.
/// @return 0 on success, errno on error.
int AGpio_setActiveType(const AGpio* gpio, AGpioActiveType type);
/// Sets the GPIO value (for output GPIO only).
/// @param gpio Pointer to the AGpio struct.
/// @param value Value to set.
/// @return 0 on success, errno on error.
int AGpio_setValue(const AGpio* gpio, int value);
/// Gets the GPIO value (for input GPIO only).
/// @param gpio Pointer to the AGpio struct.
/// @param value Output pointer to the value of the GPIO.
/// @return 0 on success, errno on error.
int AGpio_getValue(const AGpio* 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.
/// @param gpio Pointer to the AGpio struct.
/// @param fd Output pointer to the file descriptor number.
/// @return 0 on success, errno on error.
int AGpio_getPollingFd(const AGpio* gpio, int* fd);
/// Acknowledges the interrupt and resets the file descriptor.
/// This must be called after each event triggers in order to be able to
/// poll/select for another event.
/// @param fd Polling file descriptor to reset.
/// @return 0 on success, errno on error.
int AGpio_ackInterruptEvent(int fd);
/// Destroys a AGpio struct.
/// @param gpio Pointer to the AGpio struct.
void AGpio_delete(AGpio* gpio);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_GPIO_H_

View File

@@ -1,109 +0,0 @@
/*
* 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 AI2cDevice AI2cDevice;
/// Reads from the device.
/// @param device Pointer to the AI2cDevice struct.
/// @param data Output buffer to write the data to.
/// @param len Number of bytes to read.
/// @return 0 on success, errno on error
int AI2cDevice_read(const AI2cDevice* device, void* data, uint32_t len);
/// Reads a byte from an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to read from.
/// @param val Output pointer to value to read.
/// @return 0 on success, errno on error
int AI2cDevice_readRegByte(const AI2cDevice* device, uint8_t reg, uint8_t* val);
/// Reads a word from an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to read from.
/// @param val Output pointer to value to read.
/// @return 0 on success, errno on error
int AI2cDevice_readRegWord(const AI2cDevice* device,
uint8_t reg,
uint16_t* val);
/// Reads from an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to read from.
/// @param data Output buffer to write the data to.
/// @param len Number of bytes to read.
/// @return 0 on success, errno on error
int AI2cDevice_readRegBuffer(const AI2cDevice* device,
uint8_t reg,
void* data,
uint32_t len);
/// Writes to the device.
/// @param device Pointer to the AI2cDevice struct.
/// @param data Buffer to write.
/// @param len Number of bytes to write.
/// @return 0 on success, errno on error
int AI2cDevice_write(const AI2cDevice* device, const void* data, uint32_t len);
/// Writes a byte to an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to write to.
/// @param val Value to write.
/// @return 0 on success, errno on error
int AI2cDevice_writeRegByte(const AI2cDevice* device, uint8_t reg, uint8_t val);
/// Writes a word to an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to write to.
/// @param val Value to write.
/// @return 0 on success, errno on error
int AI2cDevice_writeRegWord(const AI2cDevice* device,
uint8_t reg,
uint16_t val);
/// Writes to an I2C register.
/// @param device Pointer to the AI2cDevice struct.
/// @param reg Register to write to.
/// @param data Data to write.
/// @param len Number of bytes to write.
/// @return 0 on success, errno on error
int AI2cDevice_writeRegBuffer(const AI2cDevice* device,
uint8_t reg,
const void* data,
uint32_t len);
/// Destroys a AI2cDevice struct.
/// @param device Pointer to the AI2cDevice struct.
void AI2cDevice_delete(AI2cDevice* device);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_I2C_DEVICE_H_

View File

@@ -1,141 +0,0 @@
/*
* Copyright (C) 2015 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_PERIPHERAL_MANAGER_CLIENT_H_
#define SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_
#include <sys/cdefs.h>
#include "peripheralmanager/gpio.h"
#include "peripheralmanager/i2c_device.h"
#include "peripheralmanager/pwm.h"
#include "peripheralmanager/spi_device.h"
#include "peripheralmanager/uart_device.h"
__BEGIN_DECLS
/// @defgroup PeripheralManagerClient Peripheral client functions
/// @brief Functions to access embedded peripherals
/// @{
typedef struct APeripheralManagerClient APeripheralManagerClient;
/// Returns the list of GPIOs.
/// This does not take ownership into account.
/// The list must be freed by the caller.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param num_gpio Output pointer to the number of elements in the list.
/// @return The list of gpios.
char** APeripheralManagerClient_listGpio(const APeripheralManagerClient* client,
int* num_gpio);
/// Opens a GPIO and takes ownership of it.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the GPIO.
/// @param gpio Output pointer to the AGpio struct. Empty on error.
/// @return 0 on success, errno on error.
int APeripheralManagerClient_openGpio(const APeripheralManagerClient* client,
const char* name,
AGpio** gpio);
/// Returns the list of PWMs.
/// This does not take ownership into account.
/// The list must be freed by the caller.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param num_gpio Output pointer to the number of elements in the list.
/// @return The list of pwms.
char** APeripheralManagerClient_listPwm(const APeripheralManagerClient* client,
int* num_pwm);
/// Opens a PWM and takes ownership of it.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the PWM.
/// @param gpio Output pointer to the AGpio struct. Empty on error.
/// @return 0 on success, errno on error.
int APeripheralManagerClient_openPwm(const APeripheralManagerClient* client,
const char* name,
APwm** pwm);
/// Returns the list of SPI buses.
/// This does not take ownership into account.
/// The list must be freed by the caller.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param num_spi_buses Output pointer to the number of elements in the list.
/// @return The list of spi buses.
char** APeripheralManagerClient_listSpiBuses(
const APeripheralManagerClient* client, int* num_spi_buses);
/// Opens a SPI device and takes ownership of it.
/// @oaram client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the SPI device.
/// @param dev Output pointer to the ASpiDevice struct. Empty on error.
/// @return 0 on success, errno on error.
int APeripheralManagerClient_openSpiDevice(
const APeripheralManagerClient* client, const char* name, ASpiDevice** dev);
/// 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 APeripheralManagerClient struct.
/// @param num_i2c_buses Output pointer to the number of elements in the list.
/// @return The list of i2c buses.
char** APeripheralManagerClient_listI2cBuses(
const APeripheralManagerClient* client, int* num_i2c_buses);
/// Opens an I2C device and takes ownership of it.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the I2C bus.
/// @param address Address of the I2C device.
/// @param dev Output pointer to the AI2cDevice struct. Empty on error.
/// @return 0 on success, errno on error
int APeripheralManagerClient_openI2cDevice(
const APeripheralManagerClient* client,
const char* name,
uint32_t address,
AI2cDevice** 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 APeripheralManagerClient struct.
/// @param num_uart_buses Output pointer to the number of elements in the list.
/// @return The list of uart buses.
char** APeripheralManagerClient_listUartDevices(
const APeripheralManagerClient* client, int* num_uart_buses);
/// Opens an UART device and takes ownership of it.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the UART device.
/// @param dev Output pointer to the AUartDevice struct. Empty on error.
/// @return 0 on success, errno on error
int APeripheralManagerClient_openUartDevice(
const APeripheralManagerClient* client,
const char* name,
AUartDevice** dev);
/// Creates a new client.
/// @return A pointer to the created client. nullptr on errors.
APeripheralManagerClient* APeripheralManagerClient_new();
/// Destroys the peripheral manager client.
/// @param client Pointer to the APeripheralManagerClient struct.
void APeripheralManagerClient_delete(APeripheralManagerClient* client);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_

View File

@@ -0,0 +1,39 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "mraa_internal.h"
mraa_platform_t mraa_peripheralman_platform();
void pman_mraa_deinit();
#ifdef __cplusplus
}
#endif

View File

@@ -1,59 +0,0 @@
/*
* 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_PWM_H_
#define SYSTEM_PERIPHERALMANAGER_PWM_H_
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
/// @defgroup Pwm Pwm Interface
/// @brief Functions to control PWM pins.
///
/// These functions can be used to control PWM.
/// @{
typedef struct APwm APwm;
/// Sets the PWM duty cycle.
/// @param gpio Pointer to the APwm struct.
/// @param duty_cycle Double between 0 and 100 inclusive.
/// @return 0 on success, errno on error.
int APwm_setDutyCycle(const APwm* pwm, double duty_cycle);
/// Sets the PWM frequency.
/// @param gpio Pointer to the APwm struct.
/// @param freq Double denoting the frequency in Hz.
/// @return 0 on success, errno on error.
int APwm_setFrequencyHz(const APwm* pwm, double frequency);
/// Enables the PWM.
/// @param gpio Pointer to the APwm struct.
/// @param enabled Non-zero to enable.
/// @return 0 on success, errno on error.
int APwm_setEnabled(const APwm* pwm, int enabled);
/// Destroys a APwm struct.
/// @param pwm Pointer to the APwm struct.
void APwm_delete(APwm* pwm);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_PWM_H_

View File

@@ -1,119 +0,0 @@
/*
* 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_SPI_DEVICE_H_
#define SYSTEM_PERIPHERALMANAGER_SPI_DEVICE_H_
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
/// @defgroup Spi Spi device interface
/// @brief Functions to control an SPI device.
///
/// These functions can be used to control an SPI device.
/// @{
/// Endianness.
typedef enum ASpiBitJustification {
ASPI_LSB_FIRST = 0, /**< Least significant bits first */
ASPI_MSB_FIRST = 1 /**< Most significant bits first */
} ASpiBitJustification;
/// SPI modes (similar to the Linux kernel's modes).
typedef enum ASpiMode {
ASPI_MODE0 = 0, /**< CPHA=0, CPOL=0 */
ASPI_MODE1 = 1, /**< CPHA=1, CPOL=0 */
ASPI_MODE2 = 2, /**< CPHA=0, CPOL=1 */
ASPI_MODE3 = 3 /**< CPHA=1, CPOL=1 */
} ASpiMode;
typedef struct ASpiDevice ASpiDevice;
/// Writes a buffer to the device.
/// @param device Pointer to the ASpiDevice struct.
/// @param data Buffer to write.
/// @param len Length of the buffer.
/// @return 0 on success, errno on error.
int ASpiDevice_writeBuffer(const ASpiDevice* device,
const void* data,
size_t len);
/// Reads a buffer from the device.
/// @param device Pointer to the ASpiDevice struct.
/// @param data Buffer to read into.
/// @param len Length of the buffer.
/// @return 0 on success, errno on error.
int ASpiDevice_readBuffer(const ASpiDevice* device, void* data, size_t len);
/// Transfer data to the device.
/// @param device Pointer to the ASpiDevice struct.
/// @param tx_data Buffer to write.
/// @param rx_data Buffer to read data in. If NULL, no data will be read.
/// @param len Length of the buffers.
/// @return 0 on success, errno on error.
int ASpiDevice_transfer(const ASpiDevice* device,
const void* tx_data,
void* rx_data,
size_t len);
/// Sets the frequency in Hertz.
/// @param device Pointer to the ASpiDevice struct.
/// @param freq_hz Frequency to set.
/// @return 0 on success, errno on error.
int ASpiDevice_setFrequency(const ASpiDevice* device, uint32_t freq_hz);
/// Sets the SPI mode.
/// @param device Pointer to the ASpiDevice struct.
/// @param mode Mode to use. One of SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3.
/// @return 0 on success, errno on error.
int ASpiDevice_setMode(const ASpiDevice* device, ASpiMode mode);
/// Sets the bit justification.
/// @param device Pointer to the ASpiDevice struct.
/// @param bit_justification One of SPI_LSB_FIRST OR SPI_MSB_FIRST.
/// @return 0 on success, errno on error.
int ASpiDevice_setBitJustification(const ASpiDevice* device,
ASpiBitJustification bit_justification);
/// Sets the number of bits per words.
/// @param device Pointer to the ASpiDevice struct.
/// @param bits_per_word Number of bits per word.
/// @return 0 on success, errno on error.
int ASpiDevice_setBitsPerWord(const ASpiDevice* device, uint8_t bits_per_word);
/// Sets the delay to wait after each transfer.
/// @param device Pointer to the ASpiDevice struct.
/// @param delay_usecs Delay in microseconds.
/// @return 0 on success, errno on error.
int ASpiDevice_setDelay(const ASpiDevice* device, uint16_t delay_usecs);
/// Sets the chip select behavior after each transfer.
/// @param device Pointer to the ASpiDevice struct.
/// @param change If set, cs will be active between transfers.
/// @return 0 on success, errno on error.
int ASpiDevice_setCsChange(const ASpiDevice* device, int change);
/// Destroys a ASpiDevice struct.
/// @param device Pointer to the ASpiDevice struct.
void ASpiDevice_delete(ASpiDevice* device);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_SPI_DEVICE_H_

View File

@@ -1,178 +0,0 @@
/*
* 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.
/// @{
/// UART Parity
typedef enum AUartParity {
AUART_PARITY_NONE = 0, /**< No parity */
AUART_PARITY_EVEN = 1, /**< Even parity */
AUART_PARITY_ODD = 2, /**< Odd parity */
AUART_PARITY_MARK = 3, /**< Mark parity, always 1 */
AUART_PARITY_SPACE = 4 /**< Space parity, always 0 */
} AUartParity;
/// Modem control lines.
typedef enum AUartModemControlLine {
AUART_MODEM_CONTROL_LE = 1 << 0, /**< Data set ready/Line enable */
AUART_MODEM_CONTROL_DTR = 1 << 1, /**< Data terminal ready */
AUART_MODEM_CONTROL_RTS = 1 << 2, /**< Request to send */
AUART_MODEM_CONTROL_ST = 1 << 3, /**< Secondary TXD */
AUART_MODEM_CONTROL_SR = 1 << 4, /**< Secondary RXD */
AUART_MODEM_CONTROL_CTS = 1 << 5, /**< Clear to send */
AUART_MODEM_CONTROL_CD = 1 << 6, /**< Data carrier detect */
AUART_MODEM_CONTROL_RI = 1 << 7, /**< Ring */
AUART_MODEM_CONTROL_DSR = 1 << 8 /**< Data set ready */
} AUartModemControlLine;
// Hardware Flow Control
typedef enum AUartHardwareFlowControl {
AUART_HARDWARE_FLOW_CONTROL_NONE = 0, /**< No hardware flow control */
AUART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS = 1 /**< Auto RTS/CTS */
} AUartHardwareFlowControl;
/// Flush queue selection
typedef enum AUartFlushDirection {
AUART_FLUSH_IN = 0, /**< Flushes data received but not read */
AUART_FLUSH_OUT = 1, /**< Flushes data written but not transmitted */
AUART_FLUSH_IN_OUT = 2 /**< Flushes both in and out */
} AUartFlushDirection;
typedef struct AUartDevice AUartDevice;
/// Writes to a UART device.
/// @param device Pointer to the AUartDevice 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 AUartDevice_write(const AUartDevice* device,
const void* data,
uint32_t len,
uint32_t* bytes_written);
/// Reads from a UART device.
/// @param device Pointer to the AUartDevice 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 AUartDevice_read(const AUartDevice* 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 AUartDevice struct.
/// @param baudrate Speed in baud.
/// @return 0 on success, errno on error.
int AUartDevice_setBaudrate(const AUartDevice* device, uint32_t baudrate);
/// Sets number of stop bits for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param stop_bits Number of stop bits. Typically 1 or 2.
/// @return 0 on success, errno on error.
int AUartDevice_setStopBits(const AUartDevice* device, uint32_t stop_bits);
/// Sets the data size of a character for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param data_size Number of bits per character. Typically between 5 and 8.
/// @return 0 on success, errno on error.
int AUartDevice_setDataSize(const AUartDevice* device, uint32_t data_size);
/// Sets the parity mode for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param mode Parity mode.
/// @return 0 on success, errno on error.
int AUartDevice_setParity(const AUartDevice* device, AUartParity mode);
/// Sets the hardware flow control mode for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param mode Flow control mode.
/// @return 0 on success, errno on error.
int AUartDevice_setHardwareFlowControl(const AUartDevice* device,
AUartHardwareFlowControl mode);
/// Sets the modem control bits for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param lines Lines to set. AUartModemControlLine values OR'ed together.
/// @return 0 on success, errno on error.
int AUartDevice_setModemControl(const AUartDevice* device, uint32_t lines);
/// Clears the modem control bits for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param lines Lines to clear. AUartModemControlLine values OR'ed together.
/// @return 0 on success, errno on error.
int AUartDevice_clearModemControl(const AUartDevice* device, uint32_t lines);
/// Sends a break to the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param duration Duration of break transmission in milliseconds. If 0,
/// transmits zero-valued bits for at least 0.25 seconds, and not more
/// than 0.5 seconds.
/// @return 0 on success, errno on error.
int AUartDevice_sendBreak(const AUartDevice* device, uint32_t duration_msecs);
/// Flushes specified queue for the UART device.
/// @param device Pointer to the AUartDevice struct.
/// @param direction Direction to flush.
/// @return 0 on success, errno on error.
int AUartDevice_flush(const AUartDevice* device, AUartFlushDirection direction);
/// Gets a file descriptor to be notified when data can be read.
///
/// You can use this file descriptor to poll on incoming data instead of
/// actively reading for new data.
///
/// @param device Pointer to the AUartDevice struct.
/// @param fd Output pointer to the file descriptor.
/// @return 0 on success, errno on error.
int AUartDevice_getPollingFd(const AUartDevice* device, int* fd);
/// Acknowledges an input event.
///
/// This must be called after receiving an event notification on the polling
/// file descriptor.
/// If you don't acknowledge an event, peripheral manager will assume you are
/// still processing it and you will not receive any more events.
/// If you acknowledge an event before reading the data from the device, you
/// will receive an event immediately as there will still be data available.
///
/// @param fd File descriptor to acknowledge the event on.
/// @return 0 on success, errno on error.
int AUartDevice_ackInputEvent(int fd);
/// Destroys a AUartDevice struct.
/// @param device Pointer to the AUartDevice struct.
void AUartDevice_delete(AUartDevice* device);
/// @}
__END_DECLS
#endif // SYSTEM_PERIPHERALMANAGER_UART_DEVICE_H_