maix::peripheral::i2c

maix.peripheral.i2c module

This is maix::peripheral::i2c module of MaixCDK.
All of these elements are in namespace maix::peripheral::i2c.

For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!

Module

No module

Enum

AddrSize

Address size enum

item describe
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

I2C mode enum

item describe
values MASTER: master mode
SLAVE: slave mode

C++ defination code:

enum Mode
    {
        MASTER = 0x00, // master mode
        SLAVE = 0x01   // slave mode
    }

Variable

Function

list_devices

Get supported i2c bus devices.

item description
return i2c bus devices list, int type, is the i2c bus id.

C++ defination code:

std::vector<int> list_devices()

Class

I2C

Peripheral i2c class

C++ defination code:

class I2C

__init__

I2C Device constructor\nthis constructor will be export to MaixPy as _maix.example.Example.init

item description
type func
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

scan all i2c salve address on the bus

item description
type func
param addr: If -1, only scan this addr, or scan from 0x08~0x77, default -1.
return the list of i2c slave address, int list type.
static False

C++ defination code:

std::vector<int> scan(int addr = -1)

writeto

write data to i2c slave

item description
type func
param addr: direction [in], i2c slave address, int type
data: direction [in], data to write, vector type in C++, int list in MaixPy.
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 std::vector<unsigned char> data)

writeto (overload 1)

write data to i2c slave

item description
type func
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)

writeto (overload 2)

write data to i2c slave

item description
type func
param addr: direction [in], i2c slave address, int type
data: direction [in], data to write, uint8_t type.
len: direction [in], data length to write, int type
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 uint8_t *data, int len)

readfrom

read data from i2c slave

item description
type func
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

write data to i2c slave's memory address

item description
type func
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, vector 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 std::vector<unsigned char> data, int mem_addr_size = 8, bool mem_addr_le = false)

writeto_mem (overload 1)

write data to i2c slave's memory address

item description
type func
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)

writeto_mem (overload 2)

write data to i2c slave's memory address

item description
type func
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, uint8_t type.
len: direction [in], data length to write, 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 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 uint8_t *data, int len, int mem_addr_size = 8, bool mem_addr_le = false)

readfrom_mem

read data from i2c slave

item description
type func
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)