Imported more library files
Not compiling currently
This commit is contained in:
219
Libs/platform/hardware/board/inc/sl_board_control.h
Normal file
219
Libs/platform/hardware/board/inc/sl_board_control.h
Normal file
@@ -0,0 +1,219 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Board Control API
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef SL_BOARD_CONTROL_H
|
||||
#define SL_BOARD_CONTROL_H
|
||||
|
||||
#include "sl_status.h"
|
||||
#include "sl_enum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup board_control Board Control
|
||||
* @brief Functions to control Silicon Labs board features
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/// Board Sensor Type
|
||||
SL_ENUM_GENERIC(sl_board_sensor_t, int) {
|
||||
SL_BOARD_SENSOR_RHT = (1UL << 0UL), ///< Relative Humidity and Temperature Sensor
|
||||
SL_BOARD_SENSOR_LIGHT = (1UL << 1UL), ///< UV Index and Ambient Light Sensor
|
||||
SL_BOARD_SENSOR_PRESSURE = (1UL << 2UL), ///< Barometric Pressure Sensor
|
||||
SL_BOARD_SENSOR_HALL = (1UL << 3UL), ///< Hall Effect Sensor
|
||||
SL_BOARD_SENSOR_GAS = (1UL << 4UL), ///< Gas Sensor
|
||||
SL_BOARD_SENSOR_IMU = (1UL << 5UL), ///< Inertial Measurement Unit (Accelerometer/Gyroscope)
|
||||
SL_BOARD_SENSOR_MICROPHONE = (1UL << 6UL), ///< Microphone
|
||||
};
|
||||
|
||||
/// Board Memory Type
|
||||
SL_ENUM_GENERIC(sl_board_memory_t, int) {
|
||||
SL_BOARD_MEMORY_SDCARD = (1UL << 0UL), ///< SD Card
|
||||
SL_BOARD_MEMORY_QSPI = (1UL << 1UL), ///< Quad SPI Flash
|
||||
};
|
||||
|
||||
/// Board Oscillator Type
|
||||
SL_ENUM_GENERIC(sl_board_oscillator_t, int) {
|
||||
SL_BOARD_OSCILLATOR_TCXO = (1UL << 0UL), ///< TCXO
|
||||
};
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Configure Virtual COM UART.
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK VCOM was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling VCOM failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE VCOM control is not available on this board
|
||||
* @retval SL_STATUS_NOT_SUPPORTED VCOM enabled was not configured
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_configure_vcom(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Enable Virtual COM UART.
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK VCOM was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling VCOM failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE VCOM control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_enable_vcom(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Disable Virtual COM UART.
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK VCOM was successfully disabled
|
||||
* @retval SL_STATUS_FAIL Disabling VCOM failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE VCOM control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_disable_vcom(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Enable a sensor.
|
||||
*
|
||||
* @warning
|
||||
* On boards 4166A, 4184A, and 4184B sensors
|
||||
* - Pressure Sensor, RH/Temp Sensor, and UV/Ambient Light Sensor;
|
||||
* - UV/Ambient Light Sensor, Hall-effect Sensor, and RH/Temp Sensor;
|
||||
* - Ambient Light Sensor, Hall-effect Sensor, and RH/Temp Sensor
|
||||
* respectively, are tied to the same enable pin. Calling the enable function
|
||||
* for only one of these sensors has the side-effect of enabling all three;
|
||||
* and calling the disable function for only one of them has the
|
||||
* side-effect of disabling all three.
|
||||
* The latter scenario seems less than desirable.
|
||||
*
|
||||
* @param[in] sensor Sensor to enable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Sensor was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling sensor failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Sensor control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_enable_sensor(sl_board_sensor_t sensor);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Disable a sensor.
|
||||
*
|
||||
* @warning
|
||||
* On boards 4166A, 4184A, and 4184B sensors
|
||||
* - Pressure Sensor, RH/Temp Sensor, and UV/Ambient Light Sensor;
|
||||
* - UV/Ambient Light Sensor, Hall-effect Sensor, and RH/Temp Sensor;
|
||||
* - Ambient Light Sensor, Hall-effect Sensor, and RH/Temp Sensor
|
||||
* respectively, are tied to the same enable pin. Calling the enable function
|
||||
* for only one of these sensors has the side-effect of enabling all three;
|
||||
* and calling the disable function for only one of them has the
|
||||
* side-effect of disabling all three.
|
||||
* The latter scenario seems less than desirable.
|
||||
*
|
||||
* @param[in] sensor Sensors to disable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Sensor was successfully disabled
|
||||
* @retval SL_STATUS_FAIL Disabling sensor failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Sensor control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_disable_sensor(sl_board_sensor_t sensor);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Enable display.
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Display was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling display failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Display control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_enable_display(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Disable display.
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Display was successfully disabled
|
||||
* @retval SL_STATUS_FAIL Disabling display failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Display control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_disable_display(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Enable memory.
|
||||
*
|
||||
* @param[in] memory Memory to enable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Memory was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling memory failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Memory control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_enable_memory(sl_board_memory_t memory);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Disable memory.
|
||||
*
|
||||
* @param[in] memory Memory to disable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Memory was successfully disabled
|
||||
* @retval SL_STATUS_FAIL Disabling memory failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Memory control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_disable_memory(sl_board_memory_t memory);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Enable an oscillator.
|
||||
*
|
||||
* @param[in] oscillator Oscillator to enable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Oscillator was successfully enabled
|
||||
* @retval SL_STATUS_FAIL Enabling oscillator failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Oscillator control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_enable_oscillator(sl_board_oscillator_t oscillator);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Disable a oscillator.
|
||||
*
|
||||
* @param[in] oscillator Oscillator to disable
|
||||
*
|
||||
* @return Status code
|
||||
* @retval SL_STATUS_OK Oscillator was successfully disabled
|
||||
* @retval SL_STATUS_FAIL Disabling oscillator failed
|
||||
* @retval SL_STATUS_NOT_AVAILABLE Oscillator control is not available on this board
|
||||
******************************************************************************/
|
||||
sl_status_t sl_board_disable_oscillator(sl_board_oscillator_t oscillator);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // SL_BOARD_CONTROL_H
|
||||
65
Libs/platform/hardware/board/inc/sl_board_init.h
Normal file
65
Libs/platform/hardware/board/inc/sl_board_init.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Board Init
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef SL_BOARD_INIT_H
|
||||
#define SL_BOARD_INIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup board_init Board Init
|
||||
* @brief Initialization of Silicon Labs board features
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Initialize board.
|
||||
* @details
|
||||
* Initialize a Silicon Labs board by enabling available and configured board
|
||||
* features, in addition to performing necessary board errata fixes and setting
|
||||
* default pin states.
|
||||
******************************************************************************/
|
||||
void sl_board_init(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief Initialize board features that are required at early boot.
|
||||
* @details
|
||||
* Certain board features such as external oscillators may need to be powered
|
||||
* before core device features, such as the clock tree, are configured.
|
||||
******************************************************************************/
|
||||
void sl_board_preinit(void);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SL_BOARD_INIT_H
|
||||
489
Libs/platform/hardware/board/src/sl_board_control_gpio.c
Normal file
489
Libs/platform/hardware/board/src/sl_board_control_gpio.c
Normal file
@@ -0,0 +1,489 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Board Control API
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "sl_board_control.h"
|
||||
#include "sl_board_control_config.h"
|
||||
#include "em_device.h"
|
||||
#include "sl_assert.h"
|
||||
#include "sl_gpio.h"
|
||||
|
||||
sl_status_t sl_board_configure_vcom(void)
|
||||
{
|
||||
#if defined(SL_BOARD_ENABLE_VCOM) && SL_BOARD_ENABLE_VCOM
|
||||
return sl_board_enable_vcom();
|
||||
#else
|
||||
return SL_STATUS_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
sl_status_t sl_board_enable_vcom(void)
|
||||
{
|
||||
#if defined(SL_BOARD_ENABLE_VCOM_PORT)
|
||||
sl_gpio_t enable_vcom_gpio = {
|
||||
.port = SL_BOARD_ENABLE_VCOM_PORT,
|
||||
.pin = SL_BOARD_ENABLE_VCOM_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&enable_vcom_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
return SL_STATUS_OK;
|
||||
#else
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
sl_status_t sl_board_disable_vcom(void)
|
||||
{
|
||||
#if defined(SL_BOARD_ENABLE_VCOM_PORT)
|
||||
sl_gpio_t disable_vcom_gpio = {
|
||||
.port = SL_BOARD_ENABLE_VCOM_PORT,
|
||||
.pin = SL_BOARD_ENABLE_VCOM_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&disable_vcom_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
return SL_STATUS_OK;
|
||||
#else
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
sl_status_t sl_board_enable_display(void)
|
||||
{
|
||||
#if defined(SL_BOARD_ENABLE_DISPLAY_PORT)
|
||||
sl_gpio_t enable_display_gpio = {
|
||||
.port = SL_BOARD_ENABLE_DISPLAY_PORT,
|
||||
.pin = SL_BOARD_ENABLE_DISPLAY_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&enable_display_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
#if defined(SL_BOARD_SELECT_DISPLAY_PORT)
|
||||
sl_gpio_t select_display_gpio;
|
||||
select_display_gpio.port = SL_BOARD_SELECT_DISPLAY_PORT;
|
||||
select_display_gpio.pin = SL_BOARD_SELECT_DISPLAY_PIN;
|
||||
sl_gpio_set_pin_mode(&select_display_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
#endif
|
||||
return SL_STATUS_OK;
|
||||
#else
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
sl_status_t sl_board_disable_display(void)
|
||||
{
|
||||
#if defined(SL_BOARD_ENABLE_DISPLAY_PORT)
|
||||
sl_gpio_t enable_display_gpio = {
|
||||
.port = SL_BOARD_ENABLE_DISPLAY_PORT,
|
||||
.pin = SL_BOARD_ENABLE_DISPLAY_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&enable_display_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
#if defined(SL_BOARD_SELECT_DISPLAY_PORT)
|
||||
sl_gpio_t select_display_gpio;
|
||||
select_display_gpio.port = SL_BOARD_SELECT_DISPLAY_PORT;
|
||||
select_display_gpio.pin = SL_BOARD_SELECT_DISPLAY_PIN;
|
||||
sl_gpio_set_pin_mode(&select_display_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
#endif
|
||||
return SL_STATUS_OK;
|
||||
#else
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
sl_status_t sl_board_enable_sensor(sl_board_sensor_t sensor)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_RHT_PORT)
|
||||
sl_gpio_t enable_sensor_rht_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_RHT_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_RHT_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_LIGHT_PORT)
|
||||
sl_gpio_t enable_sensor_light_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_LIGHT_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_LIGHT_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT)
|
||||
sl_gpio_t enable_sensor_pressure_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_PRESSURE_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_HALL_PORT)
|
||||
sl_gpio_t enable_sensor_hall_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_HALL_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_HALL_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_GAS_PORT)
|
||||
sl_gpio_t enable_sensor_gas_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_GAS_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_GAS_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_IMU_PORT)
|
||||
sl_gpio_t enable_sensor_imu_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_IMU_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_IMU_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT)
|
||||
sl_gpio_t enable_sensor_microphone_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_MICROPHONE_PIN,
|
||||
};
|
||||
#endif
|
||||
|
||||
switch (sensor) {
|
||||
case SL_BOARD_SENSOR_RHT:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_RHT_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_rht_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_LIGHT:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_LIGHT_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_light_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_PRESSURE:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_pressure_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_HALL:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_HALL_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_hall_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_GAS:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_GAS_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_gas_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_IMU:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_IMU_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_imu_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_MICROPHONE:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_microphone_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_board_disable_sensor(sl_board_sensor_t sensor)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_RHT_PORT)
|
||||
sl_gpio_t enable_sensor_rht_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_RHT_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_RHT_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_LIGHT_PORT)
|
||||
sl_gpio_t enable_sensor_light_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_LIGHT_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_LIGHT_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT)
|
||||
sl_gpio_t enable_sensor_pressure_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_PRESSURE_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_HALL_PORT)
|
||||
sl_gpio_t enable_sensor_hall_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_HALL_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_HALL_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_GAS_PORT)
|
||||
sl_gpio_t enable_sensor_gas_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_GAS_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_GAS_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_IMU_PORT)
|
||||
sl_gpio_t enable_sensor_imu_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_IMU_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_IMU_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT)
|
||||
sl_gpio_t enable_sensor_microphone_gpio = {
|
||||
.port = SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT,
|
||||
.pin = SL_BOARD_ENABLE_SENSOR_MICROPHONE_PIN,
|
||||
};
|
||||
#endif
|
||||
|
||||
switch (sensor) {
|
||||
case SL_BOARD_SENSOR_RHT:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_RHT_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_rht_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_LIGHT:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_LIGHT_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_light_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_PRESSURE:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_PRESSURE_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_pressure_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_HALL:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_HALL_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_hall_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_GAS:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_GAS_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_gas_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_IMU:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_IMU_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_imu_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_SENSOR_MICROPHONE:
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_MICROPHONE_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_sensor_microphone_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_board_enable_memory(sl_board_memory_t memory)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_SDCARD_PORT)
|
||||
sl_gpio_t enable_memory_sdcard_gpio = {
|
||||
.port = SL_BOARD_ENABLE_MEMORY_SDCARD_PORT,
|
||||
.pin = SL_BOARD_ENABLE_MEMORY_SDCARD_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_QSPI_PORT)
|
||||
sl_gpio_t enable_memory_qspi_gpio = {
|
||||
.port = SL_BOARD_ENABLE_MEMORY_QSPI_PORT,
|
||||
.pin = SL_BOARD_ENABLE_MEMORY_QSPI_PIN,
|
||||
};
|
||||
#endif
|
||||
|
||||
switch (memory) {
|
||||
case SL_BOARD_MEMORY_SDCARD:
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_SDCARD_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_memory_sdcard_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_MEMORY_QSPI:
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_QSPI_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_memory_qspi_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_board_disable_memory(sl_board_memory_t memory)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_SDCARD_PORT)
|
||||
sl_gpio_t enable_memory_sdcard_gpio = {
|
||||
.port = SL_BOARD_ENABLE_MEMORY_SDCARD_PORT,
|
||||
.pin = SL_BOARD_ENABLE_MEMORY_SDCARD_PIN,
|
||||
};
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_QSPI_PORT)
|
||||
sl_gpio_t enable_memory_qspi_gpio = {
|
||||
.port = SL_BOARD_ENABLE_MEMORY_QSPI_PORT,
|
||||
.pin = SL_BOARD_ENABLE_MEMORY_QSPI_PIN,
|
||||
};
|
||||
#endif
|
||||
|
||||
switch (memory) {
|
||||
case SL_BOARD_MEMORY_SDCARD:
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_SDCARD_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_memory_sdcard_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SL_BOARD_MEMORY_QSPI:
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_QSPI_PORT)
|
||||
sl_gpio_set_pin_mode(&enable_memory_qspi_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_board_enable_oscillator(sl_board_oscillator_t oscillator)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
switch (oscillator) {
|
||||
case SL_BOARD_OSCILLATOR_TCXO:
|
||||
#if defined(SL_BOARD_ENABLE_OSCILLATOR_TCXO_PORT)
|
||||
sl_gpio_t enable_oscillator_tcxo_gpio = {
|
||||
.port = SL_BOARD_ENABLE_OSCILLATOR_TCXO_PORT,
|
||||
.pin = SL_BOARD_ENABLE_OSCILLATOR_TCXO_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&enable_oscillator_tcxo_gpio, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_board_disable_oscillator(sl_board_oscillator_t oscillator)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_NOT_AVAILABLE;
|
||||
|
||||
switch (oscillator) {
|
||||
case SL_BOARD_OSCILLATOR_TCXO:
|
||||
#if defined(SL_BOARD_ENABLE_OSCILLATOR_TCXO_PORT)
|
||||
sl_gpio_t enable_oscillator_tcxo_gpio = {
|
||||
.port = SL_BOARD_ENABLE_OSCILLATOR_TCXO_PORT,
|
||||
.pin = SL_BOARD_ENABLE_OSCILLATOR_TCXO_PIN,
|
||||
};
|
||||
sl_gpio_set_pin_mode(&enable_oscillator_tcxo_gpio, SL_GPIO_MODE_PUSH_PULL, 0);
|
||||
status = SL_STATUS_OK;
|
||||
#else
|
||||
EFM_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
EFM_ASSERT(false); // Should not happen
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
98
Libs/platform/hardware/board/src/sl_board_init.c
Normal file
98
Libs/platform/hardware/board/src/sl_board_init.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Board Init
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "sl_board_control.h"
|
||||
#include "sl_board_control_config.h"
|
||||
|
||||
#include "sl_clock_manager.h"
|
||||
|
||||
#if defined(SL_COMPONENT_CATALOG_PRESENT)
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_MX25_FLASH_SHUTDOWN_USART_PRESENT) || defined(SL_CATALOG_MX25_FLASH_SHUTDOWN_EUSART_PRESENT)
|
||||
#include "sl_mx25_flash_shutdown.h"
|
||||
#endif
|
||||
|
||||
void sl_board_default_init(void);
|
||||
|
||||
void sl_board_init(void)
|
||||
{
|
||||
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
|
||||
|
||||
// Errata fixes and default pin states
|
||||
sl_board_default_init();
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_RHT) && SL_BOARD_ENABLE_SENSOR_RHT
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_RHT);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_LIGHT) && SL_BOARD_ENABLE_SENSOR_LIGHT
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_LIGHT);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_PRESSURE) && SL_BOARD_ENABLE_SENSOR_PRESSURE
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_PRESSURE);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_HALL) && SL_BOARD_ENABLE_SENSOR_HALL
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_HALL);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_GAS) && SL_BOARD_ENABLE_SENSOR_GAS
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_GAS);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_IMU) && SL_BOARD_ENABLE_SENSOR_IMU
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_IMU);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_SENSOR_MICROPHONE) && SL_BOARD_ENABLE_SENSOR_MICROPHONE
|
||||
sl_board_enable_sensor(SL_BOARD_SENSOR_MICROPHONE);
|
||||
#endif
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_DISPLAY) && SL_BOARD_ENABLE_DISPLAY
|
||||
sl_board_enable_display();
|
||||
#endif
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_SDCARD) && SL_BOARD_ENABLE_MEMORY_SDCARD
|
||||
sl_board_enable_memory(SL_BOARD_MEMORY_SDCARD);
|
||||
#endif
|
||||
#if defined(SL_BOARD_ENABLE_MEMORY_QSPI) && SL_BOARD_ENABLE_MEMORY_QSPI
|
||||
sl_board_enable_memory(SL_BOARD_MEMORY_QSPI);
|
||||
#endif
|
||||
|
||||
#if (defined(SL_CATALOG_MX25_FLASH_SHUTDOWN_USART_PRESENT) || defined(SL_CATALOG_MX25_FLASH_SHUTDOWN_EUSART_PRESENT)) && \
|
||||
defined(SL_BOARD_DISABLE_MEMORY_SPI) && SL_BOARD_DISABLE_MEMORY_SPI
|
||||
sl_mx25_flash_shutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
void sl_board_preinit(void)
|
||||
{
|
||||
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
|
||||
|
||||
#if defined(SL_BOARD_ENABLE_OSCILLATOR_TCXO) && SL_BOARD_ENABLE_OSCILLATOR_TCXO
|
||||
sl_board_enable_oscillator(SL_BOARD_OSCILLATOR_TCXO);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief MX25 flash shutdown
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_MX25_FLASH_SHUTDOWN_H
|
||||
#define SL_MX25_FLASH_SHUTDOWN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "em_device.h"
|
||||
#include "sl_mx25_flash_shutdown_eusart_config.h"
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup mx25_flash_shutdown MX25 SPI Flash Shutdown
|
||||
* @brief Provide a function to put the MX25 SPI flash into deep power down
|
||||
* mode to reduce power consumption.
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* @brief
|
||||
* Put the MX25 SPI flash into deep power down mode.
|
||||
*
|
||||
* This function initializes SPI communication with the MX25 flash and sends
|
||||
* the deep power-down instruction, which sets the device to minimal
|
||||
* power consumption. The SPI communication is disabled to free the USART.
|
||||
******************************************************************************/
|
||||
void sl_mx25_flash_shutdown(void);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // SL_MX25_FLASH_SHUTDOWN_H
|
||||
@@ -0,0 +1,175 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief MX25 flash shutdown
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_clock_manager.h"
|
||||
#include "sl_gpio.h"
|
||||
#include "sl_udelay.h"
|
||||
#include "sl_mx25_flash_shutdown.h"
|
||||
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
#include "em_eusart.h"
|
||||
#else
|
||||
#include "sl_hal_eusart.h"
|
||||
#endif
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
// Fallback to baudrate of 8 MHz if not defined for backwards compatibility
|
||||
#ifndef SL_MX25_FLASH_SHUTDOWN_BAUDRATE
|
||||
#define SL_MX25_FLASH_SHUTDOWN_BAUDRATE 7500000
|
||||
#endif
|
||||
|
||||
// Define usart clock
|
||||
#ifndef SL_MX25_FLASH_SHUTDOWN_SCLK
|
||||
#define MERGE(x, y) x##y
|
||||
#define EUSART_CLOCK(n) MERGE(SL_BUS_CLOCK_EUSART, n)
|
||||
#define SL_MX25_FLASH_SHUTDOWN_SCLK EUSART_CLOCK(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO)
|
||||
#endif
|
||||
|
||||
#ifdef SL_MX25_FLASH_SHUTDOWN_PERIPHERAL
|
||||
static void cs_low(void)
|
||||
{
|
||||
sl_gpio_t mx25_flash_shutdown_cs_gpio = {
|
||||
.port = SL_MX25_FLASH_SHUTDOWN_CS_PORT,
|
||||
.pin = SL_MX25_FLASH_SHUTDOWN_CS_PIN,
|
||||
};
|
||||
sl_gpio_clear_pin(&mx25_flash_shutdown_cs_gpio);
|
||||
}
|
||||
|
||||
static void cs_high(void)
|
||||
{
|
||||
sl_gpio_t mx25_flash_shutdown_cs_gpio = {
|
||||
.port = SL_MX25_FLASH_SHUTDOWN_CS_PORT,
|
||||
.pin = SL_MX25_FLASH_SHUTDOWN_CS_PIN,
|
||||
};
|
||||
sl_gpio_set_pin(&mx25_flash_shutdown_cs_gpio);
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* Puts the MX25 into deep power down mode.
|
||||
******************************************************************************/
|
||||
void sl_mx25_flash_shutdown(void)
|
||||
{
|
||||
#ifdef SL_MX25_FLASH_SHUTDOWN_PERIPHERAL
|
||||
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
// Init flash
|
||||
EUSART_SpiInit_TypeDef init = EUSART_SPI_MASTER_INIT_DEFAULT_HF;
|
||||
EUSART_SpiAdvancedInit_TypeDef advancedInit = EUSART_SPI_ADVANCED_INIT_DEFAULT;
|
||||
|
||||
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
|
||||
sl_clock_manager_enable_bus_clock(SL_MX25_FLASH_SHUTDOWN_SCLK);
|
||||
|
||||
advancedInit.msbFirst = true;
|
||||
advancedInit.autoCsEnable = false;
|
||||
init.bitRate = SL_MX25_FLASH_SHUTDOWN_BAUDRATE;
|
||||
|
||||
init.advancedSettings = &advancedInit;
|
||||
|
||||
EUSART_SpiInit(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL, &init);
|
||||
|
||||
#else
|
||||
// Init flash
|
||||
sl_hal_eusart_spi_config_t init = SL_HAL_EUSART_SPI_MASTER_INIT_DEFAULT_HF;
|
||||
sl_hal_eusart_spi_advanced_config_t advancedInit = SL_HAL_EUSART_SPI_ADVANCED_INIT_DEFAULT;
|
||||
|
||||
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
|
||||
sl_clock_manager_enable_bus_clock(SL_MX25_FLASH_SHUTDOWN_SCLK);
|
||||
|
||||
advancedInit.msb_first = true;
|
||||
advancedInit.auto_cs_enable = false;
|
||||
|
||||
init.advanced_config = &advancedInit;
|
||||
|
||||
sl_hal_eusart_init_spi(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL, &init);
|
||||
sl_hal_eusart_enable(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL);
|
||||
sl_hal_eusart_enable_tx(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL);
|
||||
sl_hal_eusart_enable_rx(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL);
|
||||
#endif
|
||||
|
||||
// IO config
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_TX_PORT, SL_MX25_FLASH_SHUTDOWN_TX_PIN }, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_RX_PORT, SL_MX25_FLASH_SHUTDOWN_RX_PIN }, SL_GPIO_MODE_INPUT, 0);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_SCLK_PORT, SL_MX25_FLASH_SHUTDOWN_SCLK_PIN }, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN }, SL_GPIO_MODE_PUSH_PULL, 1);
|
||||
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].SCLKROUTE = ((SL_MX25_FLASH_SHUTDOWN_SCLK_PORT << _GPIO_EUSART_SCLKROUTE_PORT_SHIFT)
|
||||
| (SL_MX25_FLASH_SHUTDOWN_SCLK_PIN << _GPIO_EUSART_SCLKROUTE_PIN_SHIFT));
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].RXROUTE = ((SL_MX25_FLASH_SHUTDOWN_RX_PORT << _GPIO_EUSART_RXROUTE_PORT_SHIFT)
|
||||
| (SL_MX25_FLASH_SHUTDOWN_RX_PIN << _GPIO_EUSART_RXROUTE_PIN_SHIFT));
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].TXROUTE = ((SL_MX25_FLASH_SHUTDOWN_TX_PORT << _GPIO_EUSART_TXROUTE_PORT_SHIFT)
|
||||
| (SL_MX25_FLASH_SHUTDOWN_TX_PIN << _GPIO_EUSART_TXROUTE_PIN_SHIFT));
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = (GPIO_EUSART_ROUTEEN_RXPEN
|
||||
| GPIO_EUSART_ROUTEEN_TXPEN
|
||||
| GPIO_EUSART_ROUTEEN_SCLKPEN);
|
||||
|
||||
// Wait for flash warm-up
|
||||
sl_udelay_wait(800); // wait for tVSL=800us
|
||||
|
||||
// Wake up flash in case the device is in deep power down mode already.
|
||||
cs_low();
|
||||
sl_udelay_wait(20); // wait for tCRDP=20us
|
||||
cs_high();
|
||||
sl_udelay_wait(35); // wait for tRDP=35us
|
||||
|
||||
// Chip select go low to start a flash command
|
||||
cs_low();
|
||||
|
||||
// Deep Power Down Mode command (0xB9)
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
EUSART_Spi_TxRx(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL, 0xB9);
|
||||
#else
|
||||
sl_hal_eusart_spi_tx_rx(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL, 0xB9);
|
||||
#endif
|
||||
|
||||
// Chip select go high to end a flash command
|
||||
cs_high();
|
||||
|
||||
// Deinit flash
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_TX_PORT, SL_MX25_FLASH_SHUTDOWN_TX_PIN }, SL_GPIO_MODE_DISABLED, 0);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_RX_PORT, SL_MX25_FLASH_SHUTDOWN_RX_PIN }, SL_GPIO_MODE_DISABLED, 0);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_SCLK_PORT, SL_MX25_FLASH_SHUTDOWN_SCLK_PIN }, SL_GPIO_MODE_DISABLED, 1);
|
||||
sl_gpio_set_pin_mode(&(sl_gpio_t) {SL_MX25_FLASH_SHUTDOWN_CS_PORT, SL_MX25_FLASH_SHUTDOWN_CS_PIN }, SL_GPIO_MODE_DISABLED, 1);
|
||||
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
EUSART_Reset(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL);
|
||||
#else
|
||||
sl_hal_eusart_reset(SL_MX25_FLASH_SHUTDOWN_PERIPHERAL);
|
||||
#endif
|
||||
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].ROUTEEN = _GPIO_EUSART_ROUTEEN_RESETVALUE;
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].SCLKROUTE = _GPIO_EUSART_SCLKROUTE_RESETVALUE;
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].RXROUTE = _GPIO_EUSART_RXROUTE_RESETVALUE;
|
||||
GPIO->EUSARTROUTE[SL_MX25_FLASH_SHUTDOWN_PERIPHERAL_NO].TXROUTE = _GPIO_EUSART_TXROUTE_RESETVALUE;
|
||||
|
||||
sl_clock_manager_disable_bus_clock(SL_MX25_FLASH_SHUTDOWN_SCLK);
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user