uart: bunch of small changes to make C api work
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Thomas Ingleby
parent
b02f8b4d50
commit
19cad5cf24
@@ -76,18 +76,6 @@ mraa_result_t mraa_uart_set_timeout(mraa_uart_context dev, int read, int write,
|
|||||||
*/
|
*/
|
||||||
char* mraa_uart_get_dev_path(mraa_uart_context dev);
|
char* mraa_uart_get_dev_path(mraa_uart_context dev);
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the TTY device associated with a UART context, and set up the
|
|
||||||
* terminal modes and baud rate. The TTY is setup for a 'raw'
|
|
||||||
* mode. 81N, no echo or special character handling, such as flow
|
|
||||||
* control or line editing semantics.
|
|
||||||
*
|
|
||||||
* @param dev uart context
|
|
||||||
* @param baud desired baud rate
|
|
||||||
* @return mraa_result_t
|
|
||||||
*/
|
|
||||||
mraa_result_t mraa_uart_open_dev(mraa_uart_context dev, unsigned int baud);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a mraa_uart_context
|
* Destroy a mraa_uart_context
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ class Uart
|
|||||||
*/
|
*/
|
||||||
~Uart()
|
~Uart()
|
||||||
{
|
{
|
||||||
stopDevice();
|
mraa_uart_stop(m_uart);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,57 +74,30 @@ class Uart
|
|||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the TTY device associated with a UART context, and set up the
|
|
||||||
* terminal modes and baud rate. The TTY is setup for a 'raw'
|
|
||||||
* mode. 81N, no echo or special character handling, such as flow
|
|
||||||
* control or line editing semantics.
|
|
||||||
*
|
|
||||||
* @param baud desired baud rate
|
|
||||||
* @return mraa_result_t
|
|
||||||
*/
|
|
||||||
mraa_result_t
|
|
||||||
openDevice(unsigned int baud)
|
|
||||||
{
|
|
||||||
return mraa_uart_open_dev(m_uart, baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close a device previously opened with mraa_uart_open_dev().
|
|
||||||
*
|
|
||||||
* @param dev uart context
|
|
||||||
* @return mraa_result_t
|
|
||||||
*/
|
|
||||||
mraa_result_t
|
|
||||||
stopDevice()
|
|
||||||
{
|
|
||||||
return mraa_uart_stop(m_uart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read bytes from the device into a buffer
|
* Read bytes from the device into a buffer
|
||||||
*
|
*
|
||||||
* @param buf buffer pointer
|
* @param data buffer pointer
|
||||||
* @param len maximum size of buffer
|
* @param length maximum size of buffer
|
||||||
* @return the number of bytes read, or -1 if an error occurred
|
* @return the number of bytes read, or -1 if an error occurred
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
read(char* buf, size_t len)
|
read(char* data, int length)
|
||||||
{
|
{
|
||||||
return mraa_uart_read(m_uart, buf, len);
|
return mraa_uart_read(m_uart, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write bytes in buffer to a device
|
* Write bytes in buffer to a device
|
||||||
*
|
*
|
||||||
* @param buf buffer pointer
|
* @param data buffer pointer
|
||||||
* @param len maximum size of buffer
|
* @param length maximum size of buffer
|
||||||
* @return the number of bytes written, or -1 if an error occurred
|
* @return the number of bytes written, or -1 if an error occurred
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
write(char* buf, size_t len)
|
write(char* data, int length)
|
||||||
{
|
{
|
||||||
return mraa_uart_write(m_uart, buf, len);
|
return mraa_uart_write(m_uart, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -198,8 +198,9 @@ mraa_uart_init_raw(int index)
|
|||||||
struct termios termio;
|
struct termios termio;
|
||||||
|
|
||||||
// get current modes
|
// get current modes
|
||||||
if (!tcgetattr(dev->fd, &termio)) {
|
if (tcgetattr(dev->fd, &termio)) {
|
||||||
syslog(LOG_ERR, "uart: tcgetattr() failed");
|
syslog(LOG_ERR, "uart: tcgetattr() failed");
|
||||||
|
close(dev->fd);
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -209,7 +210,8 @@ mraa_uart_init_raw(int index)
|
|||||||
// cfmakeraw is not POSIX!
|
// cfmakeraw is not POSIX!
|
||||||
cfmakeraw(&termio);
|
cfmakeraw(&termio);
|
||||||
|
|
||||||
if (!mraa_uart_set_baudrate(dev, 9600)) {
|
if (mraa_uart_set_baudrate(dev, 9600) != MRAA_SUCCESS) {
|
||||||
|
close(dev->fd);
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -259,7 +261,7 @@ mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct termios termio;
|
struct termios termio;
|
||||||
if (!tcgetattr(dev->fd, &termio)) {
|
if (tcgetattr(dev->fd, &termio)) {
|
||||||
syslog(LOG_ERR, "uart: tcgetattr() failed");
|
syslog(LOG_ERR, "uart: tcgetattr() failed");
|
||||||
return MRAA_ERROR_INVALID_HANDLE;
|
return MRAA_ERROR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user