+) 新加对SPI参数改动的能力
This commit is contained in:
parent
87af325c53
commit
8dc807662a
@ -58,6 +58,7 @@ public:
|
||||
bool spi_closeDevice(); // 关闭设备
|
||||
bool spi_Write(QByteArray &sendData); // SPI写数据
|
||||
BOOL spi_Read(QByteArray &revData); // SPI读数据
|
||||
bool spi_Init(int devIndex, int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits);
|
||||
|
||||
/*************变量定义*************/
|
||||
mDRV_Spi_Infors m_DRV_Spi_Infors; //Spi驱动相关信息
|
||||
|
||||
@ -79,7 +79,6 @@ bool DRV_Spi::spi_openDevice(ULONG SpiI2cGpioDevIndex)
|
||||
// 设置当前打开设备的索引号
|
||||
this->m_DRV_Spi_Infors.opendDevIndex = SpiI2cGpioDevIndex;
|
||||
return true;
|
||||
// CH347InitSpi();
|
||||
}
|
||||
|
||||
//关闭设备
|
||||
@ -113,7 +112,7 @@ bool DRV_Spi::spi_Write(QByteArray &sendData)
|
||||
// 调用底层串口发送函数发送数据
|
||||
RetVal = CH347SPI_Write(this->m_DRV_Spi_Infors.opendDevIndex, SPI_WRITE_CS, OutLen, SPI_WRITE_BLOCK_SIZE, (UCHAR *)OutBuf);
|
||||
// 日志窗口输出调试信息
|
||||
DbgPrint("frame:%d,Spi_Write %dBytes %s.",sendData.at(14), OutLen,RetVal?"succ":"failure");
|
||||
DbgPrint("Spi_Write %dBytes %s.", OutLen,RetVal?"succ":"failure");
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
@ -139,3 +138,31 @@ BOOL DRV_Spi::spi_Read(QByteArray &revData)
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
bool DRV_Spi::spi_Init(int devIndex, int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits) {
|
||||
mSpiCfgS spiCon;
|
||||
BOOL rv = FALSE;
|
||||
rv = CH347SPI_GetCfg(devIndex, &spiCon);
|
||||
DbgPrint("CH347SPI_GetCfg %s.", rv ? "succ" : "failure");
|
||||
if (rv == FALSE)
|
||||
return false;
|
||||
spiCon.iMode = mode;
|
||||
spiCon.iClock = clock;
|
||||
spiCon.iByteOrder = byteOrder;
|
||||
spiCon.iSpiOutDefaultData = 0xFF;
|
||||
spiCon.iChipSelect = 0x80;
|
||||
spiCon.CS1Polarity = CS1Pol;
|
||||
spiCon.CS2Polarity = CS2Pol;
|
||||
spiCon.iIsAutoDeativeCS = 0;
|
||||
spiCon.iActiveDelay = 0;
|
||||
spiCon.iDelayDeactive = 0;
|
||||
rv = CH347SPI_Init(devIndex, &spiCon);
|
||||
DbgPrint("CH347SPI_Init %s.", rv ? "succ" : "failure");
|
||||
if (rv == FALSE)
|
||||
return false;
|
||||
rv = CH347SPI_SetDataBits(devIndex, dataBits);
|
||||
DbgPrint("CH347SPI_SetDataBits %s.", rv ? "succ" : "failure");
|
||||
if (rv == FALSE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user