android uart apk,UartDeviceDriver

UartDeviceDriver

public

interface

UartDeviceDriver

implements

UartDevicecom.google.android.things.userdriver.pio.UartDeviceDriver

UART user driver.

A UartDeviceDriver must implement all UART functions, but additionally this class provides an

open() function that will be called whenever a process obtains ownership of the UART, to match

the existing close() function.

Summary

Inherited constants

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

interface

int

int

int

int

int

int

int

int

int

int

int

int

int

int

int

int

int

int

int

Public methods

abstract

void

Closes the UART.

default

String

Returns null.

abstract

void

Opens the UART.

abstract

void

Registers an interrupt callback on the UART.

Inherited methods

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

interface

abstract

void

Clear selected modem control lines.

abstract

void

Close and release the device.

abstract

void

flush(int direction)

Flush the specified queue for the device.

default

String

Returns the I/O name.

abstract

int

read(byte[] buffer, int length)

Read data from the device.

default

void

Registers a callback for interrupts.

abstract

void

Registers a callback for interrupts.

abstract

void

sendBreak(int duration_msecs)

Send a break to the device.

abstract

void

Set the device baud rate.

abstract

void

Set the device data size.

abstract

void

Set the hardware flow control mode.

abstract

void

Set selected modem control lines.

abstract

void

setParity(int mode)

Set the device parity mode.

abstract

void

Set the device stop bits.

abstract

void

abstract

int

write(byte[] buffer, int length)

Write data to the device.

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

interface

abstract

void

Closes this stream and releases any system resources associated

with it.

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

interface

abstract

void

Closes this resource, relinquishing any underlying resources.

Public methods

close

void close ()

Closes the UART.

This will be called when the UART is closed by its owner. Any resources that need to

be cleaned up should be done so here.

This method may throw IOException to indicate I/O failure, but will still be considered

closed and may attempt to be re-opened in the future.

Throws

on I/O failure; the driver will still be considered closed.

getName

String getName ()

Returns null.

I/O user drivers can be registered under any name so this returns null by default. Child

classes may override this if other behavior is desired.

Returns

open

void open ()

Opens the UART.

This will be called when ownership of a UART is obtained. The driver should do any

initialization needed to configure the UART for use here.

Throws

on I/O failure; the driver will remain closed.

registerUartDeviceCallback

void registerUartDeviceCallback (Handler handler,

UartDeviceCallback callback)

Registers an interrupt callback on the UART.

Seepublic class UartWithInterruptDriver implements UartDeviceDriver {

// The data-ready signal GPIO.

private Gpio mInterruptGpio;

// Our GPIO interrupt handler.

private InterruptCallback mInterruptCallback;

// Implement other UartDeviceDriver functionality.

// ...

@Override

public void registerUartDeviceCallback(Handler handler, UartDeviceCallback callback)

throws IOException {

// Configure mInterruptGpio to begin listening for interrupts.

mInterruptCallback = new InterruptCallback(callback);

mInterruptGpio.setEdgeTriggerType(Gpio.EDGE_RISING);

mInterruptGpio.registerGpioCallback(handler, mInterruptCallback);

}

@Override

public void unregisterUartDeviceCallback(UartDeviceCallback callback) {

mInterruptGpio.unregisterGpioCallback(mInterruptCallback);

mInterruptGpio.setEdgeTriggerType(Gpio.EDGE_NONE);

mInterruptCallback = null;

}

// Bounces the underlying GPIO callbacks into the registered UART callback.

private class InterruptCallback implements GpioCallback {

private final UartDeviceCallback mUartCallback;

public InterruptCallback(UartDeviceCallback uartCallback) {

mUartCallback = uartCallback;

}

@Override

public boolean onGpioEdge(Gpio gpio) {

return mUartCallback.onUartDeviceDataAvailable(null);

}

@Override

public void onGpioError(Gpio gpio, int error) {

// The underlying interrupt GPIO failed, we won't get any more callbacks.

mUartCallback.onUartDeviceError(null, error);

}

}

}

Parameters

handler

Handler: Handler to optionally run callbacks on. Provided as a convenience if needed,

but it's not required to execute callbacks on this.

callback

UartDeviceCallback: UartDeviceCallback to register; only one will ever be registered at a time.

Throws

if this UART doesn't support interrupts.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值