maix::peripheral::spi
maix.peripheral.spi module
This is
maix::peripheral::spi
module of MaixCDK.
All of these elements are in namespacemaix::peripheral::spi
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
Module
No module
Enum
Mode
SPI mode enum
item | describe |
---|---|
values | MASTER: spi master mode SLAVE: spi slave mode |
C++ defination code:
enum Mode { MASTER = 0x0, // spi master mode SLAVE = 0x1, // spi slave mode }
Variable
Function
Class
SPI
Peripheral spi class
C++ defination code:
class SPI
__init__
SPI constructor
item | description |
---|---|
type | func |
param | id: direction [in], spi bus id, int type mode: direction [in], mode of spi, spi.Mode type, spi.Mode.MASTER or spi.Mode.SLAVE. freq: direction [in], freq of spi, int type. Different board support different max freq, for MaixCAM2 is 26000000(26M). polarity: direction [in], polarity of spi, 0 means idle level of clock is low, 1 means high, int type, default is 0. phase: direction [in], phase of spi, 0 means data is captured on the first edge of the SPI clock cycle, 1 means second, int type, default is 0. bits: direction [in], bits of spi, int type, default is 8. hw_cs: direction [in], use hardware CS id, -1 means use default(e.g. for MaixCAM2 SPI2 is CS1), 0 means use CS0, 1 means use CS1 ... soft_cs: direction [in], use soft CS instead of hw_cs, default empty string means not use soft CS control, so you can use hw_cs or control CS pin by your self with GPIO module. if set GPIO name, for example GPIOA19(MaixCAM) or GPIOA2(MaixCAM2), this class will automatically init GPIO object and control soft CS pin when read/write. Attention, you should set GPIO's pinmap first by yourself first. Attention, the driver may still own the hw_cs pin and perform control hw_cs, you can use pinmap to map hw_cs pin to other function to avoid this. cs_active_low: direction [in], CS pin low voltage means activate slave device, default true. hw_cs only support true, soft_cs support both. |
static | False |
C++ defination code:
SPI(int id, spi::Mode mode, int freq, int polarity = 0, int phase = 0, int bits = 8, int hw_cs = -1, std::string soft_cs = "", bool cs_active_low = true)
read
read data from spi
item | description |
---|---|
type | func |
param | length: direction [in], read length, int type |
return | bytes data, Bytes type in C++, bytes type in MaixPy. You need to delete it manually after use in C++. |
static | False |
C++ defination code:
Bytes *read(int length)
read (overload 1)
read data from spi
item | description |
---|---|
type | func |
param | length: direction [in], read length, unsigned int type |
return | bytes data, vector |
static | False |
C++ defination code:
std::vector<unsigned char> read(unsigned int length)
write
write data to spi
item | description |
---|---|
type | func |
param | data: direction [in], data to write, vector the member range of the list is [0,255] |
return | write length, int type, if write failed, return -err::Err code. |
static | False |
C++ defination code:
int write(std::vector<unsigned char> data)
write (overload 1)
write data to spi
item | description |
---|---|
type | func |
param | data: direction [in], data to write, Bytes type in C++, bytes type in MaixPy |
return | write length, int type, if write failed, return -err::Err code. |
static | False |
C++ defination code:
int write(Bytes *data)
write_read
write data to spi and read data from spi at the same time.
item | description |
---|---|
type | func |
param | data: direction [in], data to write, vector read_len: direction [in], read length, int type, should > 0. |
return | read data, vector |
static | False |
C++ defination code:
std::vector<unsigned char> write_read(std::vector<unsigned char> data, int read_len)
write_read (overload 1)
write data to spi and read data from spi at the same time.
item | description |
---|---|
type | func |
param | data: direction [in], data to write, Bytes type in C++, bytes type in MaixPy read_len: direction [in], read length, int type, should > 0. |
return | read data, Bytes type in C++, bytes type in MaixPy. You need to delete it manually after use in C++. |
static | False |
C++ defination code:
Bytes *write_read(Bytes *data, int read_len)
is_busy
get busy status of spi
item | description |
---|---|
type | func |
return | busy status, bool type |
static | False |
C++ defination code:
bool is_busy()