def aa_i2c_write_read (aardvark, slave_addr, flags, out_data, in_data):
"""usage: (int return, u16 num_written, u08[] in_data, u16 num_read) = aa_i2c_write_read(Aardvark aardvark, u16 slave_addr, AardvarkI2cFlags flags, u08[] out_data, u08[] in_data)
All arrays can be passed into the API as an ArrayType object or as
a tuple (array, length), where array is an ArrayType object and
length is an integer. The user-specified length would then serve
as the length argument to the API funtion (please refer to the
product datasheet). If only the array is provided, the array's
intrinsic length is used as the argument to the underlying API
function.
Additionally, for arrays that are filled by the API function, an
integer can be passed in place of the array argument and the API
will automatically create an array of that length. All output
arrays, whether passed in or generated, are passed back in the
returned tuple."""
if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY
# out_data pre-processing
(out_data, out_num_bytes) = isinstance(out_data, ArrayType) and (out_data, len(out_data)) or (out_data[0], min(len(out_data[0]), int(out_data[1])))
if out_data.typecode != 'B':
raise TypeError("type for 'out_data' must be array('B')")
# in_data pre-processing
__in_data = isinstance(in_data, int)
if __in_data:
(in_data, in_num_bytes) = (array_u08(in_data), in_data)
else:
(in_data, in_num_bytes) = isinstance(in_data, ArrayType) and (in_data, len(in_data)) or (in_data[0], min(len(in_data[0]), int(in_data[1])))
if in_data.typecode != 'B':
raise TypeError("type for 'in_data' must be array('B')")
# Call API function
(_ret_, num_written, num_read) = api.py_aa_i2c_write_read(aardvark, slave_addr, flags, out_num_bytes, out_data, in_num_bytes, in_data)
# in_data post-processing
if __in_data: del in_data[max(0, min(num_read, len(in_data))):]
return (_ret_, num_written, in_data, num_read)
# Enable/Disable the Aardvark as an I2C slave device
aardvark_py.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录