Skip to content

Commit

Permalink
Refactor SPIDRV_ReInit
Browse files Browse the repository at this point in the history
  • Loading branch information
rosahay-silabs committed May 23, 2023
1 parent 23985b5 commit 80a279e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
19 changes: 0 additions & 19 deletions examples/platform/silabs/efr32/spi_multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,4 @@
#include "em_usart.h"
#include "spi_multiplex.h"

void SPIDRV_ReInit(uint32_t baudrate)
{
if (USART_BaudrateGet(USART0) == baudrate)
{
// USART synced to baudrate already
return;
}
// USART is used in MG24 + WF200 combination
USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT;
usartInit.msbf = true;
usartInit.clockMode = usartClockMode0;
usartInit.baudrate = baudrate;
uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR;
usartInit.databits = (USART_Databits_TypeDef) databits;
usartInit.autoCsEnable = true;

USART_InitSync(USART0, &usartInit);
}

#endif /* EFR32MG24 */
21 changes: 21 additions & 0 deletions examples/platform/silabs/efr32/wf200/efr_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
extern SPIDRV_Handle_t sl_spidrv_exp_handle;
#define SL_SPIDRV_HANDLE sl_spidrv_exp_handle
#elif defined(EFR32MG24)
#include "sl_spidrv_eusart_exp_config.h"
#include "spi_multiplex.h"
#else
#error "Unknown platform"
Expand Down Expand Up @@ -379,6 +380,26 @@ void sl_wfx_host_gpio_init(void)
}

#if defined(EFR32MG24)

void SPIDRV_ReInit(uint32_t baudrate)
{
if (USART_BaudrateGet(MY_USART) == baudrate)
{
// USART synced to baudrate already
return;
}
// USART is used in MG24 + WF200 combination
USART_InitSync_TypeDef usartInit = USART_INITSYNC_DEFAULT;
usartInit.msbf = true;
usartInit.clockMode = usartClockMode0;
usartInit.baudrate = baudrate;
uint32_t databits = SL_SPIDRV_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR;
usartInit.databits = (USART_Databits_TypeDef) databits;
usartInit.autoCsEnable = true;

USART_InitSync(MY_USART, &usartInit);
}

void sl_wfx_host_spiflash_cs_assert(void)
{
GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN);
Expand Down

0 comments on commit 80a279e

Please sign in to comment.