-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EFR32]Wi-Fi MG24-WF200 Pin Multiplexing and OTA Update support (#23830)
* WF200 SPI multiplexing for LCD,EXT flash and EXP Header changes * Restyled by whitespace * Restyled by clang-format * Adding License for header file Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
7 changed files
with
324 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "spi_multiplex.h" | ||
#include "dmadrv.h" | ||
#include "em_bus.h" | ||
#include "em_cmu.h" | ||
#include "em_gpio.h" | ||
#include "em_ldma.h" | ||
#include "em_usart.h" | ||
|
||
/**************************************************************************** | ||
* @fn void spi_drv_reinit() | ||
* @brief | ||
* Re-Intializes SPI driver to required baudrate | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void spi_drv_reinit(uint32_t baudrate) | ||
{ | ||
// 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_EXP_FRAME_LENGTH - 4U + _USART_FRAME_DATABITS_FOUR; | ||
usartInit.databits = (USART_Databits_TypeDef) databits; | ||
usartInit.autoCsEnable = true; | ||
|
||
USART_InitSync(USART0, &usartInit); | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void set_spi_baudrate() | ||
* @brief | ||
* Setting the appropriate SPI baudrate | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void set_spi_baudrate(peripheraltype_t pr_type) | ||
{ | ||
if (pr_type == LCD) | ||
{ | ||
spi_drv_reinit(LCD_BIT_RATE); | ||
} | ||
else if (pr_type == EXP_HDR) | ||
{ | ||
spi_drv_reinit(EXP_HDR_BIT_RATE); | ||
} | ||
else if (pr_type == EXT_SPIFLASH) | ||
{ | ||
spi_drv_reinit(SPI_FLASH_BIT_RATE); | ||
} | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void spiflash_cs_assert() | ||
* @brief | ||
* Assert SPI flash chip select. | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void spiflash_cs_assert(void) | ||
{ | ||
GPIO_PinOutClear(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void spiflash_cs_deassert() | ||
* @brief | ||
* De-Assert SPI flash chip select. | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void spiflash_cs_deassert(void) | ||
{ | ||
GPIO_PinOutSet(SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN); | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void pre_bootloader_spi_transfer() | ||
* @brief | ||
* Take a semaphore and controlling CS pin for EXP header and SPI flash | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void pre_bootloader_spi_transfer(void) | ||
{ | ||
if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) | ||
{ | ||
return; | ||
} | ||
/* | ||
* CS for Expansion header controlled within GSDK, | ||
* however we need to ensure CS for Expansion header is High/disabled before use of EXT SPI Flash | ||
*/ | ||
sl_wfx_host_spi_cs_deassert(); | ||
/* | ||
* Assert CS pin for EXT SPI Flash | ||
*/ | ||
spiflash_cs_assert(); | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void post_bootloader_spi_transfer() | ||
* @brief | ||
* De-Assert EXT SPI flash CS pin and release semaphore | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void post_bootloader_spi_transfer(void) | ||
{ | ||
/* | ||
* De-Assert CS pin for EXT SPI Flash | ||
*/ | ||
spiflash_cs_deassert(); | ||
xSemaphoreGive(spi_sem_sync_hdl); | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void pre_lcd_spi_transfer() | ||
* @brief | ||
* Take a semaphore and setting LCD baudrate | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void pre_lcd_spi_transfer(void) | ||
{ | ||
if (xSemaphoreTake(spi_sem_sync_hdl, portMAX_DELAY) != pdTRUE) | ||
{ | ||
return; | ||
} | ||
if (pr_type != LCD) | ||
{ | ||
pr_type = LCD; | ||
set_spi_baudrate(pr_type); | ||
} | ||
/*LCD CS is handled as part of LCD gsdk*/ | ||
} | ||
|
||
/**************************************************************************** | ||
* @fn void post_lcd_spi_transfer() | ||
* @brief | ||
* Release semaphore | ||
* @param[in] None | ||
* @return returns void | ||
*****************************************************************************/ | ||
void post_lcd_spi_transfer(void) | ||
{ | ||
xSemaphoreGive(spi_sem_sync_hdl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#include "FreeRTOS.h" | ||
#include "semphr.h" | ||
#include "sl_mx25_flash_shutdown_usart_config.h" | ||
#include "sl_spidrv_exp_config.h" | ||
#include "sl_wfx_host_api.h" | ||
|
||
#define LCD_BIT_RATE 1100000 | ||
#define EXP_HDR_BIT_RATE 16000000 | ||
#define SPI_FLASH_BIT_RATE 16000000 | ||
|
||
typedef enum PERIPHERAL_TYPE | ||
{ | ||
EXP_HDR = 0, | ||
LCD, | ||
EXT_SPIFLASH, | ||
} peripheraltype_t; | ||
|
||
extern SemaphoreHandle_t spi_sem_sync_hdl; | ||
extern peripheraltype_t pr_type; | ||
|
||
void spi_drv_reinit(uint32_t); | ||
void set_spi_baudrate(peripheraltype_t); | ||
|
||
void spiflash_cs_assert(void); | ||
void spiflash_cs_deassert(void); | ||
|
||
void pre_bootloader_spi_transfer(void); | ||
void post_bootloader_spi_transfer(void); | ||
|
||
void pre_lcd_spi_transfer(void); | ||
void post_lcd_spi_transfer(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.