Let user manually use SS_Set and SS_Clr

This commit is contained in:
lxbpxylps@126.com 2021-10-15 23:15:42 +08:00
parent e129b212f5
commit b56448d008
2 changed files with 15 additions and 13 deletions

View File

@ -54,14 +54,21 @@ HAL_StatusTypeDef SoftSPI_Init(SoftSPI_TypeDef *SoftSPIx)
return HAL_OK;
}
void SoftSPI_SetSS(SoftSPI_TypeDef *SoftSPIx)
{
SS_Set;
}
void SoftSPI_ClrSS(SoftSPI_TypeDef *SoftSPIx)
{
SS_Clr;
}
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte)
{
uint8_t data = 0;
uint8_t i;
// Select Device
SS_Clr;
for (i = 0; i < 8; i++)
{
SCLK_Clr;
@ -85,9 +92,6 @@ uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte)
Delay;
}
// Unselect Device
SS_Set;
return data;
}
@ -97,9 +101,6 @@ void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *
uint8_t byte;
uint8_t i, j;
// Select Device
SS_Clr;
for (j = 0; j < len; j++)
{
data = 0;
@ -131,8 +132,6 @@ void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *
pRead[j] = data;
}
// Unselect Device
SS_Set;
}
uint8_t SoftSPI_GPIOx_Pin_Init(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode, uint32_t Pull)

View File

@ -12,8 +12,8 @@
#include "softspi_conf.h"
/**
* @brief SoftSPI Structure definition
*/
* @brief SoftSPI Structure definition
*/
typedef struct
{
GPIO_TypeDef *SCLK_GPIO;
@ -33,6 +33,9 @@ typedef struct
HAL_StatusTypeDef SoftSPI_Init(SoftSPI_TypeDef *SoftSPIx);
void SoftSPI_SetSS(SoftSPI_TypeDef *SoftSPIx);
void SoftSPI_ClrSS(SoftSPI_TypeDef *SoftSPIx);
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte);
void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *pRead, uint32_t len);