maix.peripheral.i2c
maix.peripheral.i2c module
You can use
maix.peripheral.i2c
to access this module with MaixPy
This module is generated from MaixCDK
Module
No module
Enum
AddrSize
item | doc |
---|---|
brief | Address size enum |
values | SEVEN_BIT: 7-bit address mode TEN_BIT: 10-bit address mode |
C++ defination code:
enum AddrSize
{
SEVEN_BIT = 7, // 7-bit address mode
TEN_BIT = 10 // 10-bit address mode
}
Mode
item | doc |
---|---|
brief | I2C mode enum |
values | MASTER: master mode SLAVE: slave mode |
C++ defination code:
enum Mode
{
MASTER = 0x00, // master mode
SLAVE = 0x01 // slave mode
}
Variable
Function
list_devices
item | doc |
---|---|
brief | Get supported i2c bus devices. |
return | i2c bus devices list, int type, is the i2c bus id. |
C++ defination code:
std::vector<int> list_devices()
Class
I2C
item | doc |
---|---|
brief | Peripheral i2c class |
C++ defination code:
class I2C
__init__
item | doc |
---|---|
type | func |
brief | I2C Device constructor\nthis constructor will be export to MaixPy as _maix.example.Example.init |
param | id: direction [in], i2c bus id, int type, e.g. 0, 1, 2 freq: direction [in], i2c clock, int type, default is 100000(100kbit/s), will auto set fast mode if freq > 100000. mode: direction [in], mode of i2c, i2c.Mode.SLAVE or i2c.Mode.MASTER. addr_size: direction [in], address length of i2c, i2c.AddrSize.SEVEN_BIT or i2c.AddrSize.TEN_BIT. |
throw | err::Exception if open i2c device failed. |
static | False |
C++ defination code:
I2C(int id, i2c::Mode mode, int freq = 100000, i2c::AddrSize addr_size = i2c::AddrSize::SEVEN_BIT)
scan
item | doc |
---|---|
type | func |
brief | scan all i2c salve address on the bus |
return | the list of i2c slave address, int list type. |
static | False |
C++ defination code:
std::vector<int> scan()
writeto
item | doc |
---|---|
type | func |
brief | write data to i2c slave |
param | addr: direction [in], i2c slave address, int type data: direction [in], data to write, bytes type. Note: The range of value should be in [0,255]. |
return | if success, return the length of written data, error occurred will return -err::Err. |
static | False |
C++ defination code:
int writeto(int addr, const Bytes &data)
readfrom
item | doc |
---|---|
type | func |
brief | read data from i2c slave |
param | addr: direction [in], i2c slave address, int type len: direction [in], data length to read, int type |
return | the list of data read from i2c slave, bytes type, you should delete it after use in C++. If read failed, return nullptr in C++, None in MaixPy. |
static | False |
C++ defination code:
Bytes* readfrom(int addr, int len)
writeto_mem
item | doc |
---|---|
type | func |
brief | write data to i2c slave's memory address |
param | addr: direction [in], i2c slave address, int type mem_addr: direction [in], memory address want to write, int type. data: direction [in], data to write, bytes type. mem_addr_size: direction [in], memory address size, default is 8. mem_addr_le: direction [in], memory address little endian, default is false, that is send high byte first. |
return | data length written if success, error occurred will return -err::Err. |
static | False |
C++ defination code:
int writeto_mem(int addr, int mem_addr, const Bytes &data, int mem_addr_size = 8, bool mem_addr_le = false)
readfrom_mem
item | doc |
---|---|
type | func |
brief | read data from i2c slave |
param | addr: direction [in], i2c slave address, int type mem_addr: direction [in], memory address want to read, int type. len: direction [in], data length to read, int type mem_addr_size: direction [in], memory address size, default is 8. mem_addr_le: direction [in], memory address little endian, default is false, that is send high byte first. |
return | the list of data read from i2c slave, bytes type, you should delete it after use in C++. If read failed, return nullptr in C++, None in MaixPy. |
static | False |
C++ defination code:
Bytes* readfrom_mem(int addr, int mem_addr, int len, int mem_addr_size = 8, bool mem_addr_le = false)