-
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.
Add Silabs Platform abstraction (#26196)
- Loading branch information
1 parent
5bcc8f6
commit 2760199
Showing
6 changed files
with
267 additions
and
0 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,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 |
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,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
56
src/platform/silabs/platformAbstraction/SilabsPlatformBase.h
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,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 |
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,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 |