Private
Public Access
2
0

peripheralman: Update APIs in accordance with Android Things

Signed-off-by: Sanrio Alvares <sanrio.alvares@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Sanrio Alvares
2017-02-02 05:53:59 -08:00
committed by Noel Eck
parent 1cec6705d1
commit c4555bc4e5
8 changed files with 250 additions and 278 deletions

View File

@@ -29,76 +29,76 @@ __BEGIN_DECLS
/// @{
/// Edge trigger types.
enum {
NONE_EDGE, /**< None */
RISING_EDGE, /**< Rising edge */
FALLING_EDGE, /**< Falling edge */
BOTH_EDGE /**< Both edges */
};
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.
enum {
DIRECTION_IN, /**< Input mode */
DIRECTION_OUT_INITIALLY_HIGH, /**< Output mode, initially set to high */
DIRECTION_OUT_INITIALLY_LOW /**< Output mode, initially set to low */
};
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.
enum {
ACTIVE_LOW, /**< Active Low */
ACTIVE_HIGH /**< Active High */
};
typedef enum AGpioActiveType {
AGPIO_ACTIVE_LOW = 0, /**< Active Low */
AGPIO_ACTIVE_HIGH = 1 /**< Active High */
} AGpioActiveType;
typedef struct BGpio BGpio;
typedef struct AGpio AGpio;
/// Sets the GPIO direction to output.
/// @param gpio Pointer to the BGpio struct
/// @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 BGpio_setDirection(const BGpio* gpio, int direction);
int AGpio_setDirection(const AGpio* gpio, AGpioDirection direction);
/// Sets the interrupt edge trigger type.
/// @param gpio Pointer to the BGpio struct
/// @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 BGpio_setEdgeTriggerType(const BGpio* gpio, int type);
int AGpio_setEdgeTriggerType(const AGpio* gpio, AGpioEdge type);
/// Sets the GPIOs active low/high status.
/// @param gpio Pointer to the BGpio struct.
/// @param gpio Pointer to the AGpio struct.
/// @param type One of ACTIVE_HIGH, ACTIVE_LOW.
/// @return 0 on success, errno on error.
int BGpio_setActiveType(const BGpio* gpio, int type);
int AGpio_setActiveType(const AGpio* gpio, AGpioActiveType type);
/// Sets the GPIO value (for output GPIO only).
/// @param gpio Pointer to the BGpio struct.
/// @param gpio Pointer to the AGpio struct.
/// @param value Value to set.
/// @return 0 on success, errno on error.
int BGpio_setValue(const BGpio* gpio, int value);
int AGpio_setValue(const AGpio* gpio, int value);
/// Gets the GPIO value (for input GPIO only).
/// @param gpio Pointer to the BGpio struct.
/// @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 BGpio_getValue(const BGpio* gpio, int* value);
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 BGpio struct.
/// @param gpio Pointer to the AGpio struct.
/// @param fd Output pointer to the file descriptor number.
/// @return 0 on success, errno on error.
int BGpio_getPollingFd(const BGpio* gpio, int* fd);
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 BGpio_ackInterruptEvent(int fd);
int AGpio_ackInterruptEvent(int fd);
/// Destroys a BGpio struct.
/// @param gpio Pointer to the BGpio struct.
void BGpio_delete(BGpio* gpio);
/// Destroys a AGpio struct.
/// @param gpio Pointer to the AGpio struct.
void AGpio_delete(AGpio* gpio);
/// @}

View File

@@ -28,79 +28,79 @@ __BEGIN_DECLS
/// These functions can be used to control an I2C device.
/// @{
typedef struct BI2cDevice BI2cDevice;
typedef struct AI2cDevice AI2cDevice;
/// Reads from the device.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_read(const BI2cDevice* device, void* data, uint32_t len);
int AI2cDevice_read(const AI2cDevice* device, void* data, uint32_t len);
/// Reads a byte from an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_readRegByte(const BI2cDevice* device, uint8_t reg, uint8_t* val);
int AI2cDevice_readRegByte(const AI2cDevice* device, uint8_t reg, uint8_t* val);
/// Reads a word from an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_readRegWord(const BI2cDevice* device,
int AI2cDevice_readRegWord(const AI2cDevice* device,
uint8_t reg,
uint16_t* val);
/// Reads from an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_readRegBuffer(const BI2cDevice* device,
int AI2cDevice_readRegBuffer(const AI2cDevice* device,
uint8_t reg,
void* data,
uint32_t len);
/// Writes to the device.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_write(const BI2cDevice* device, const void* data, uint32_t len);
int AI2cDevice_write(const AI2cDevice* device, const void* data, uint32_t len);
/// Writes a byte to an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_writeRegByte(const BI2cDevice* device, uint8_t reg, uint8_t val);
int AI2cDevice_writeRegByte(const AI2cDevice* device, uint8_t reg, uint8_t val);
/// Writes a word to an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_writeRegWord(const BI2cDevice* device,
int AI2cDevice_writeRegWord(const AI2cDevice* device,
uint8_t reg,
uint16_t val);
/// Writes to an I2C register.
/// @param device Pointer to the BI2cDevice struct.
/// @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 BI2cDevice_writeRegBuffer(const BI2cDevice* device,
int AI2cDevice_writeRegBuffer(const AI2cDevice* device,
uint8_t reg,
const void* data,
uint32_t len);
/// Destroys a BI2cDevice struct.
/// @param device Pointer to the BI2cDevice struct.
void BI2cDevice_delete(BI2cDevice* device);
/// Destroys a AI2cDevice struct.
/// @param device Pointer to the AI2cDevice struct.
void AI2cDevice_delete(AI2cDevice* device);
/// @}

View File

@@ -31,112 +31,108 @@ __BEGIN_DECLS
/// @brief Functions to access embedded peripherals
/// @{
typedef struct BPeripheralManagerClient BPeripheralManagerClient;
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 BPeripheralManagerClient struct.
/// @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** BPeripheralManagerClient_listGpio(const BPeripheralManagerClient* client,
char** APeripheralManagerClient_listGpio(const APeripheralManagerClient* client,
int* num_gpio);
/// Opens a GPIO and takes ownership of it.
/// @param client Pointer to the BPeripheralManagerClient struct.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the GPIO.
/// @param gpio Output pointer to the BGpio struct. Empty on error.
/// @param gpio Output pointer to the AGpio struct. Empty on error.
/// @return 0 on success, errno on error.
int BPeripheralManagerClient_openGpio(const BPeripheralManagerClient* client,
int APeripheralManagerClient_openGpio(const APeripheralManagerClient* client,
const char* name,
BGpio** gpio);
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 BPeripheralManagerClient struct.
/// @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** BPeripheralManagerClient_listPwm(const BPeripheralManagerClient* client,
char** APeripheralManagerClient_listPwm(const APeripheralManagerClient* client,
int* num_pwm);
/// Opens a PWM and takes ownership of it.
/// @param client Pointer to the BPeripheralManagerClient struct.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the PWM.
/// @param gpio Output pointer to the BGpio struct. Empty on error.
/// @param gpio Output pointer to the AGpio struct. Empty on error.
/// @return 0 on success, errno on error.
int BPeripheralManagerClient_openPwm(const BPeripheralManagerClient* client,
int APeripheralManagerClient_openPwm(const APeripheralManagerClient* client,
const char* name,
BPwm** pwm);
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 BPeripheralManagerClient struct.
/// @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** BPeripheralManagerClient_listSpiBuses(
const BPeripheralManagerClient* client,
int* num_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 BPeripheralManagerClient struct.
/// @oaram client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the SPI device.
/// @param dev Output pointer to the BSpiDevice struct. Empty on error.
/// @param dev Output pointer to the ASpiDevice struct. Empty on error.
/// @return 0 on success, errno on error.
int BPeripheralManagerClient_openSpiDevice(
const BPeripheralManagerClient* client,
const char* name,
BSpiDevice** dev);
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 BPeripheralManagerClient struct.
/// @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** BPeripheralManagerClient_listI2cBuses(
const BPeripheralManagerClient* client,
int* num_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 BPeripheralManagerClient struct.
/// @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 BI2cDevice struct. Empty on error.
/// @param dev Output pointer to the AI2cDevice struct. Empty on error.
/// @return 0 on success, errno on error
int BPeripheralManagerClient_openI2cDevice(
const BPeripheralManagerClient* client,
int APeripheralManagerClient_openI2cDevice(
const APeripheralManagerClient* client,
const char* name,
uint32_t address,
BI2cDevice** dev);
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 BPeripheralManagerClient struct.
/// @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** BPeripheralManagerClient_listUartDevices(
const BPeripheralManagerClient* client, int* num_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 BPeripheralManagerClient struct.
/// @param client Pointer to the APeripheralManagerClient struct.
/// @param name Name of the UART device.
/// @param dev Output pointer to the BUartDevice struct. Empty on error.
/// @param dev Output pointer to the AUartDevice struct. Empty on error.
/// @return 0 on success, errno on error
int BPeripheralManagerClient_openUartDevice(
const BPeripheralManagerClient* client,
int APeripheralManagerClient_openUartDevice(
const APeripheralManagerClient* client,
const char* name,
BUartDevice** dev);
AUartDevice** dev);
/// Creates a new client.
/// @return A pointer to the created client. nullptr on errors.
BPeripheralManagerClient* BPeripheralManagerClient_new();
APeripheralManagerClient* APeripheralManagerClient_new();
/// Destroys the peripheral manager client.
/// @param client Pointer to the BPeripheralManagerClient struct.
void BPeripheralManagerClient_delete(BPeripheralManagerClient* client);
/// @param client Pointer to the APeripheralManagerClient struct.
void APeripheralManagerClient_delete(APeripheralManagerClient* client);
/// @}

View File

@@ -28,33 +28,29 @@ __BEGIN_DECLS
/// These functions can be used to control PWM.
/// @{
typedef struct BPwm BPwm;
typedef struct APwm APwm;
/// Sets the PWM duty cycle.
/// @param gpio Pointer to the BPwm struct
/// @param gpio Pointer to the APwm struct.
/// @param duty_cycle Double between 0 and 100 inclusive.
/// @return 0 on success, errno on error.
int BPwm_setDutyCycle(const BPwm* pwm, double duty_cycle);
int APwm_setDutyCycle(const APwm* pwm, double duty_cycle);
/// Sets the PWM frequency.
/// @param gpio Pointer to the BPwm struct
/// @param gpio Pointer to the APwm struct.
/// @param freq Double denoting the frequency in Hz.
/// @return 0 on success, errno on error.
int BPwm_setFrequencyHz(const BPwm* pwm, double frequency);
int APwm_setFrequencyHz(const APwm* pwm, double frequency);
/// Enables the PWM.
/// @param gpio Pointer to the BPwm struct
/// @param gpio Pointer to the APwm struct.
/// @param enabled Non-zero to enable.
/// @return 0 on success, errno on error.
int BPwm_enable(const BPwm* pwm);
int APwm_setEnabled(const APwm* pwm, int enabled);
/// Disables the PWM.
/// @param gpio Pointer to the BPwm struct
/// @return 0 on success, errno on error.
int BPwm_disable(const BPwm* pwm);
/// Destroys a BPwm struct.
/// @param pwm Pointer to the BPwm struct.
void BPwm_delete(BPwm* pwm);
/// Destroys a APwm struct.
/// @param pwm Pointer to the APwm struct.
void APwm_delete(APwm* pwm);
/// @}

View File

@@ -29,96 +29,88 @@ __BEGIN_DECLS
/// @{
/// Endianness.
enum {
SPI_LSB_FIRST, /**< Least significant bits first */
SPI_MSB_FIRST /**< Most significant bits first */
};
/// SPI phase modes.
enum {
SPI_CPHA = 0x01, /**< Clock phase */
SPI_CPOL = 0x02 /**< Clock polarity */
};
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).
enum {
SPI_MODE0 = 0, /**< CPHA=0, CPOL=0 */
SPI_MODE1 = SPI_CPHA, /**< CPHA=1, CPOL=0 */
SPI_MODE2 = SPI_CPOL, /**< CPHA=0, CPOL=1 */
SPI_MODE3 = SPI_CPHA + SPI_CPOL /**< CPHA=1, CPOL=1 */
};
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 BSpiDevice BSpiDevice;
typedef struct ASpiDevice ASpiDevice;
/// Writes a buffer to the device.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_writeBuffer(const BSpiDevice* device,
int ASpiDevice_writeBuffer(const ASpiDevice* device,
const void* data,
size_t len);
/// Reads a buffer from the device.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_readBuffer(const BSpiDevice* device,
void* data,
size_t len);
int ASpiDevice_readBuffer(const ASpiDevice* device, void* data, size_t len);
/// Transfer data to the device.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_transfer(const BSpiDevice* device,
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 BSpiDevice struct.
/// @param device Pointer to the ASpiDevice struct.
/// @param freq_hz Frequency to set.
/// @return 0 on success, errno on error.
int BSpiDevice_setFrequency(const BSpiDevice* device, uint32_t freq_hz);
int ASpiDevice_setFrequency(const ASpiDevice* device, uint32_t freq_hz);
/// Sets the SPI mode.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_setMode(const BSpiDevice* device, int mode);
int ASpiDevice_setMode(const ASpiDevice* device, ASpiMode mode);
/// Sets the bit justification.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_setBitJustification(const BSpiDevice* device,
int bit_justification);
int ASpiDevice_setBitJustification(const ASpiDevice* device,
ASpiBitJustification bit_justification);
/// Sets the number of bits per words.
/// @param device Pointer to the BSpiDevice struct.
/// @param device Pointer to the ASpiDevice struct.
/// @param bits_per_word Number of bits per word.
/// @return 0 on success, errno on error.
int BSpiDevice_setBitsPerWord(const BSpiDevice* device, uint8_t bits_per_word);
int ASpiDevice_setBitsPerWord(const ASpiDevice* device, uint8_t bits_per_word);
/// Sets the delay to wait after each transfer.
/// @param device Pointer to the BSpiDevice struct.
/// @param device Pointer to the ASpiDevice struct.
/// @param delay_usecs Delay in microseconds.
/// @return 0 on success, errno on error.
int BSpiDevice_setDelay(const BSpiDevice* device, uint16_t delay_usecs);
int ASpiDevice_setDelay(const ASpiDevice* device, uint16_t delay_usecs);
/// Sets the chip select behavior after each transfer.
/// @param device Pointer to the BSpiDevice struct.
/// @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 BSpiDevice_setCsChange(const BSpiDevice* device, int change);
int ASpiDevice_setCsChange(const ASpiDevice* device, int change);
/// Destroys a BSpiDevice struct.
/// @param device Pointer to the BSpiDevice struct.
void BSpiDevice_delete(BSpiDevice* device);
/// Destroys a ASpiDevice struct.
/// @param device Pointer to the ASpiDevice struct.
void ASpiDevice_delete(ASpiDevice* device);
/// @}

View File

@@ -19,8 +19,6 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
__BEGIN_DECLS
@@ -31,133 +29,130 @@ __BEGIN_DECLS
/// @{
/// UART Parity
enum UartParity {
UART_PARITY_NONE, /**< No parity */
UART_PARITY_EVEN, /**< Even parity */
UART_PARITY_ODD, /**< Odd parity */
UART_PARITY_MARK, /**< Mark parity, always 1 */
UART_PARITY_SPACE /**< Space parity, always 0 */
};
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 Bits
enum UartModemControlBits {
UART_MC_LE = TIOCM_LE, /**< Data set ready/Line enable */
UART_MC_DTR = TIOCM_DTR, /**< Data terminal ready */
UART_MC_RTS = TIOCM_RTS, /**< Request to send */
UART_MC_ST = TIOCM_ST, /**< Secondary TXD */
UART_MC_SR = TIOCM_SR, /**< Secondary RXD */
UART_MC_CTS = TIOCM_CTS, /**< Clear to send */
UART_MC_CD = TIOCM_CAR, /**< Data carrier detect */
UART_MC_RI = TIOCM_RI, /**< Ring */
UART_MC_DSR = TIOCM_DSR /**< Data set ready */
};
/// 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
enum UartHardwareFlowControlType {
UART_HW_FLOW_NONE, /**< No hardware flow control */
UART_HW_FLOW_AUTO_RTSCTS /**< Auto RTS/CTS */
};
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
enum UartFlushQueueSelection {
UART_FLUSH_IN = TCIFLUSH, /**< Flushes data received but not read */
UART_FLUSH_OUT = TCOFLUSH, /**< Flushes data written but not transmitted */
UART_FLUSH_IN_OUT = TCIOFLUSH /**< Flushes both in and out */
};
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 BUartDevice BUartDevice;
typedef struct AUartDevice AUartDevice;
/// Writes to a UART device.
/// @param device Pointer to the BUartDevice struct.
/// @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 BUartDevice_write(const BUartDevice* device,
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 BUartDevice struct.
/// @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 BUartDevice_read(const BUartDevice* device,
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 BUartDevice struct.
/// @param device Pointer to the AUartDevice struct.
/// @param baudrate Speed in baud.
/// @return 0 on success, errno on error.
int BUartDevice_setBaudrate(const BUartDevice* device, uint32_t baudrate);
int AUartDevice_setBaudrate(const AUartDevice* device, uint32_t baudrate);
/// Sets number of stop bits for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @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 BUartDevice_setStopBits(const BUartDevice* device, uint32_t stop_bits);
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 BUartDevice struct.
/// @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 BUartDevice_setDataSize(const BUartDevice* device, uint32_t data_size);
int AUartDevice_setDataSize(const AUartDevice* device, uint32_t data_size);
/// Sets the parity mode for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @param mode Parity mode. One of UART_PARITY_NONE, UART_PARITY_EVEN,
/// UART_PARITY_ODD, UART_PARITY_MARK, UART_PARITY_SPACE.
/// @param device Pointer to the AUartDevice struct.
/// @param mode Parity mode.
/// @return 0 on success, errno on error.
int BUartDevice_setParity(const BUartDevice* device, uint32_t mode);
int AUartDevice_setParity(const AUartDevice* device, AUartParity mode);
/// Sets the hardware flow control mode for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @param mode Flow control mode. Either UART_HW_FLOW_NONE or
/// UART_HW_FLOW_AUTO_RTSCTS.
/// @param device Pointer to the AUartDevice struct.
/// @param mode Flow control mode.
/// @return 0 on success, errno on error.
int BUartDevice_setHardwareFlowControl(const BUartDevice* device,
uint32_t mode);
int AUartDevice_setHardwareFlowControl(const AUartDevice* device,
AUartHardwareFlowControl mode);
/// Sets the modem control bits for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @param bits Modem control bits to set.
/// @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 BUartDevice_setModemControl(const BUartDevice* device, uint32_t bits);
int AUartDevice_setModemControl(const AUartDevice* device, uint32_t lines);
/// Clears the modem control bits for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @param bits Modem control bits to clear.
/// @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 BUartDevice_clearModemControl(const BUartDevice* device, uint32_t bits);
int AUartDevice_clearModemControl(const AUartDevice* device, uint32_t lines);
/// Sends a break to the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @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 BUartDevice_sendBreak(const BUartDevice* device, uint32_t duration_msecs);
int AUartDevice_sendBreak(const AUartDevice* device, uint32_t duration_msecs);
/// Flushes specified queue for the UART device.
/// @param device Pointer to the BUartDevice struct.
/// @param queue Queue to flush. One of UART_FLUSH_IN, UART_FLUSH_OUT,
/// UART_FLUSH_IN_OUT.
/// @param device Pointer to the AUartDevice struct.
/// @param direction Direction to flush.
/// @return 0 on success, errno on error.
int BUartDevice_flush(const BUartDevice* device, uint32_t queue);
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 BUartDevice struct.
/// @param device Pointer to the AUartDevice struct.
/// @param fd Output pointer to the file descriptor.
/// @return 0 on success, errno on error.
int BUartDevice_getPollingFd(const BUartDevice* device, int* fd);
int AUartDevice_getPollingFd(const AUartDevice* device, int* fd);
/// Acknowledges an input event.
///
@@ -170,11 +165,11 @@ int BUartDevice_getPollingFd(const BUartDevice* device, int* fd);
///
/// @param fd File descriptor to acknowledge the event on.
/// @return 0 on success, errno on error.
int BUartDevice_ackInputEvent(int fd);
int AUartDevice_ackInputEvent(int fd);
/// Destroys a BUartDevice struct.
/// @param device Pointer to the BUartDevice struct.
void BUartDevice_delete(BUartDevice* device);
/// Destroys a AUartDevice struct.
/// @param device Pointer to the AUartDevice struct.
void AUartDevice_delete(AUartDevice* device);
/// @}