diff --git a/softspi.c b/softspi.c index 0b89022..17d6394 100644 --- a/softspi.c +++ b/softspi.c @@ -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) diff --git a/softspi.h b/softspi.h index 2482ba1..e9888cc 100644 --- a/softspi.h +++ b/softspi.h @@ -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);