代码拉取完成,页面将自动刷新
同步操作将从 vtor3478/vtor_elec_module 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "vtor_spi.h"
#ifdef __VTOR_SPI__
void VtorSpi_WriteClk(VtorSpiStruct* spi, char level)
{
spi->writeClk(level);
}
void VtorSpi_WriteMosi(VtorSpiStruct* spi, uint8_t level)
{
spi->writeMosi(level);
}
uint8_t VtorSpi_ReadMiso(VtorSpiStruct* spi)
{
return spi->readMiso();
}
void VtorSpi_WriteCs(VtorSpiStruct* spi, uint8_t level)
{
if(spi->writeCs)
{
spi->writeCs(level);
}
}
void VtorSpi_SetClkRun(VtorSpiStruct* spi)
{
if (VTOR_SPI_POLARITY_LOW == spi->cpol)
{
VtorSpi_WriteClk(spi, GPIO_LEVEL_HIGH);
}
else
{
VtorSpi_WriteClk(spi, GPIO_LEVEL_LOW);
}
}
void VtorSpi_SetClkIdle(VtorSpiStruct* spi)
{
if (VTOR_SPI_POLARITY_LOW == spi->cpol)
{
VtorSpi_WriteClk(spi, GPIO_LEVEL_LOW);
}
else
{
VtorSpi_WriteClk(spi, GPIO_LEVEL_HIGH);
}
}
// o h i l
// h o l i
// o l i h
// l o h i
// https://www.cnblogs.com/gmpy/p/12461461.html
// https://blog.csdn.net/baidu_39594043/article/details/120362744
void VtorSpi_WriteRead(VtorSpiStruct* spi, uint8_t* txBuf, uint8_t* rxBuf, uint16_t len)
{
uint8_t cnt;
uint16_t i;
VtorSpi_WriteCs(spi, GPIO_LEVEL_LOW);
for(i = 0; i < len; i++)
{
uint8_t txByte = 0x55;
uint8_t rxByte = 0xaa;
if (NULL != txBuf)
{
txByte = *txBuf;
txBuf++;
}
for(cnt=0;cnt<8;cnt++)
{
VtorSpi_WriteMosi(spi, txByte & 0x80);
txByte <<= 1;
VtorSpi_Delay(1);
VtorSpi_SetClkRun(spi);
VtorSpi_Delay(1);
VtorSpi_SetClkIdle(spi);
VtorSpi_Delay(1);
rxByte<<=1;
if(VtorSpi_ReadMiso(spi))
{
rxByte |= 0x01;
}
}
if (NULL != rxBuf)
{
*rxBuf = rxByte;
rxBuf++;
}
}
VtorSpi_WriteCs(spi, GPIO_LEVEL_HIGH);
}
#endif // ELEC_MODULE_VTOR_SPI_ENABLED
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。