Skip to content

Commit

Permalink
Add Silabs Platform abstraction (#26196)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Feb 13, 2024
1 parent 5bcc8f6 commit 2760199
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ static_library("SiWx917") {
"${silabs_platform_dir}/SilabsConfig.cpp",
"${silabs_platform_dir}/SilabsConfig.h",
"${silabs_platform_dir}/SystemPlatformConfig.h",
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.h",
"${silabs_platform_dir}/platformAbstraction/SilabsPlatformBase.h",
"${silabs_platform_dir}/platformAbstraction/WiseMCU_SPAM.cpp",
"../../FreeRTOS/SystemTimeSupport.cpp",
"../../SingletonConfigurationManager.cpp",
"BLEManagerImpl.cpp",
Expand Down
3 changes: 3 additions & 0 deletions src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static_library("efr32") {
"${silabs_platform_dir}/SilabsConfig.cpp",
"${silabs_platform_dir}/SilabsConfig.h",
"${silabs_platform_dir}/SystemPlatformConfig.h",
"${silabs_platform_dir}/platformAbstraction/GSDK_SPAM.cpp",
"${silabs_platform_dir}/platformAbstraction/SilabsPlatform.h",
"${silabs_platform_dir}/platformAbstraction/SilabsPlatformBase.h",
"../../FreeRTOS/SystemTimeSupport.cpp",
"../../SingletonConfigurationManager.cpp",
"ConfigurationManagerImpl.cpp",
Expand Down
76 changes: 76 additions & 0 deletions src/platform/silabs/platformAbstraction/GSDK_SPAM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 "init_efrPlatform.h"
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

namespace chip {
namespace DeviceLayer {
namespace Silabs {

SilabsPlatform SilabsPlatform::sSilabsPlatformAbstractionManager;

CHIP_ERROR SilabsPlatform::Init(void)
{
init_efrPlatform();
return CHIP_NO_ERROR;
}

#ifdef ENABLE_WSTK_LEDS

#include "sl_simple_led_instances.h"

void SilabsPlatform::InitLed(void)
{
sl_simple_led_init_instances();
}

CHIP_ERROR SilabsPlatform::SetLed(bool state, uint8_t led)
{
if (led >= SL_SIMPLE_LED_COUNT)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}

(state) ? sl_led_turn_on(SL_SIMPLE_LED_INSTANCE(led)) : sl_led_turn_off(SL_SIMPLE_LED_INSTANCE(led));
return CHIP_NO_ERROR;
}

bool SilabsPlatform::GetLedState(uint8_t led)
{
if (led >= SL_SIMPLE_LED_COUNT)
{
return 0;
}

return sl_led_get_state(SL_SIMPLE_LED_INSTANCE(led));
}

CHIP_ERROR SilabsPlatform::ToggleLed(uint8_t led)
{
if (led >= SL_SIMPLE_LED_COUNT)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
sl_led_toggle(SL_SIMPLE_LED_INSTANCE(led));
return CHIP_NO_ERROR;
}
#endif // ENABLE_WSTK_LEDS

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
63 changes: 63 additions & 0 deletions src/platform/silabs/platformAbstraction/SilabsPlatform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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

#include <platform/silabs/platformAbstraction/SilabsPlatformBase.h>
#include <stdint.h>
#include <stdio.h>

namespace chip {
namespace DeviceLayer {
namespace Silabs {

class SilabsPlatform : virtual public SilabsPlatformAbstractionBase
{

public:
// Generic Peripherical methods
CHIP_ERROR Init(void) override;

// LEDS
#ifdef ENABLE_WSTK_LEDS
void InitLed(void) override;
CHIP_ERROR SetLed(bool state, uint8_t led) override;
bool GetLedState(uint8_t led) override;
CHIP_ERROR ToggleLed(uint8_t led) override;
#endif

private:
friend SilabsPlatform & GetPlatform(void);

// To make underlying SDK thread safe
void SilabsPlatformLock(void);
void SilabsPlatformUnlock(void);

SilabsPlatform(){};
virtual ~SilabsPlatform() = default;

static SilabsPlatform sSilabsPlatformAbstractionManager;
};

inline SilabsPlatform & GetPlatform(void)
{
return SilabsPlatform::sSilabsPlatformAbstractionManager;
}

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
56 changes: 56 additions & 0 deletions src/platform/silabs/platformAbstraction/SilabsPlatformBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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

#include <stdint.h>
#include <stdio.h>

#include <lib/core/CHIPError.h>

namespace chip {
namespace DeviceLayer {
namespace Silabs {

class SilabsPlatformAbstractionBase
{

public:
// Generic Peripherical methods
virtual CHIP_ERROR Init(void) = 0;
virtual CHIP_ERROR InitLCD() { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual CHIP_ERROR SetGPIO(uint32_t port, uint32_t pin, bool state) { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual bool GetGPIO(uint32_t port, uint32_t pin) { return false; }

// Buttons

// LEDS
virtual void InitLed(void) {}
virtual CHIP_ERROR SetLed(bool state, uint8_t led) { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual bool GetLedState(uint8_t led) { return 0; }
virtual CHIP_ERROR ToggleLed(uint8_t led) { return CHIP_ERROR_NOT_IMPLEMENTED; }

// BLE Specific Method

protected:
SilabsPlatformAbstractionBase(){};
~SilabsPlatformAbstractionBase(){};
};

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
66 changes: 66 additions & 0 deletions src/platform/silabs/platformAbstraction/WiseMCU_SPAM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 <platform/silabs/platformAbstraction/SilabsPlatform.h>

#include "init_ccpPlatform.h"

// TODO add includes ?
extern "C" void RSI_Board_LED_Set(int, bool);
extern "C" void RSI_Board_LED_Toggle(int);

namespace chip {
namespace DeviceLayer {
namespace Silabs {

SilabsPlatform SilabsPlatform::sSilabsPlatformAbstractionManager;

CHIP_ERROR SilabsPlatform::Init(void)
{
init_ccpPlatform();
}

#ifdef ENABLE_WSTK_LEDS
void SilabsPlatform::InitLed(void)
{
// TODO ?
SilabsPlatformAbstractionBase::InitLed();
}

CHIP_ERROR SilabsPlatform::SetLed(bool state, uint8_t led) override
{
// TODO add range check ?
RSI_Board_LED_Set(led, state);
return CHIP_NO_ERROR;
}

bool SilabsPlatform::GetLedState(uint8_t led)
{
// TODO ?
return SilabsPlatformAbstractionBase::GetLedState(led);
}

CHIP_ERROR SilabsPlatform::ToggleLed(uint8_t led) override
{
// TODO add range check ?
RSI_Board_LED_Toggle(led) return CHIP_NO_ERROR;
}
#endif // ENABLE_WSTK_LEDS

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip

0 comments on commit 2760199

Please sign in to comment.