Skip to content

Commit

Permalink
[Telink] Add the functionality for the B91 Mars board (#30469)
Browse files Browse the repository at this point in the history
* [Telink] Add Mars board overlay and real measurment of sht3xd sensor

* [Telink] Add DFU via USB for Mars board

* [Telink] Update the Mars board overlay

* [Telink] Move Sensor Manager files to common part

* [Telink] Add Set Color Temperature Light to Sensor Manager

* [Telink] Add WS2812Device util and update Lighting app for Mars board

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 8, 2024
1 parent 9cc8b4b commit de9d6d2
Show file tree
Hide file tree
Showing 27 changed files with 934 additions and 325 deletions.
12 changes: 11 additions & 1 deletion config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ else()
unset(USB_BOOT_DTC_OVERLAY_FILE)
endif()

if(${TLNK_MARS_BOARD} MATCHES y)
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_mars_boot.overlay")
set(MARS_BOOT_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}_mars_boot.overlay")
else()
unset(MARS_BOOT_DTC_OVERLAY_FILE)
endif()
else()
unset(MARS_CONF_OVERLAY_FILE)
endif()

if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}.overlay")
set(GLOBAL_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BASE_BOARD}.overlay")
else()
Expand Down Expand Up @@ -186,7 +196,7 @@ if (CONFIG_BOOTLOADER_MCUBOOT)
add_custom_target(build_mcuboot ALL
COMMAND
west build -b ${BASE_BOARD} -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr
-- -DOVERLAY_CONFIG=${GLOBAL_BOOTLOADER_CONF_OVERLAY_FILE} -DDTC_OVERLAY_FILE="${GLOBAL_DTC_OVERLAY_FILE};${FLASH_DTC_OVERLAY_FILE};${USB_BOOT_DTC_OVERLAY_FILE}"
-- -DOVERLAY_CONFIG=${GLOBAL_BOOTLOADER_CONF_OVERLAY_FILE} -DDTC_OVERLAY_FILE="${GLOBAL_DTC_OVERLAY_FILE};${FLASH_DTC_OVERLAY_FILE};${USB_BOOT_DTC_OVERLAY_FILE};${MARS_BOOT_DTC_OVERLAY_FILE}"
COMMAND
cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin ${PROJECT_BINARY_DIR}/zephyr.mcuboot.bin
)
Expand Down
5 changes: 5 additions & 0 deletions config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,8 @@ config CHIP_ENABLE_POWER_ON_FACTORY_RESET
Enable power on factory reset sequence. If device power triggered off during
first 5 seconds after power on and this sequence repeated 5 times - factory
reset will be involved.

config CHIP_USE_MARS_SENSOR
bool "Use Mars board sensor"
depends on SOC_SERIES_RISCV_TELINK_B9X && (BOARD_TLSR9518ADK80D || BOARD_TLSR9518ADK80D_RETENTION)
default n
25 changes: 22 additions & 3 deletions examples/air-quality-sensor-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(TELINK_COMMON ${CHIP_ROOT}/examples/platform/telink REALPATH)
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

set(ignoreMe "${TLNK_MARS_BOARD}")

if(${TLNK_MARS_BOARD} MATCHES y)
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.overlay")
set(MARS_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.overlay")
else()
unset(MARS_DTC_OVERLAY_FILE)
endif()
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.conf")
set(MARS_CONF_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.conf")
else()
unset(MARS_CONF_OVERLAY_FILE)
endif()
else()
unset(MARS_CONF_OVERLAY_FILE)
endif()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
set(LOCAL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.overlay")
else()
Expand All @@ -41,14 +58,14 @@ endif()

if(DTC_OVERLAY_FILE)
set(DTC_OVERLAY_FILE
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
CACHE STRING "" FORCE
)
else()
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
endif()

set(CONF_FILE prj.conf)
set(CONF_FILE ${MARS_CONF_OVERLAY_FILE} prj.conf)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
Expand Down Expand Up @@ -78,10 +95,12 @@ target_sources(app PRIVATE
src/ZclCallbacks.cpp
${TELINK_COMMON}/common/src/mainCommon.cpp
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
${TELINK_COMMON}/common/src/SensorManagerCommon.cpp
${TELINK_COMMON}/util/src/LEDWidget.cpp
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${TELINK_COMMON}/util/src/PWMDevice.cpp
${TELINK_COMMON}/util/src/WS2812Device.cpp
${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/src/air-quality-sensor-manager.cpp)

chip_configure_data_model(app
Expand Down
3 changes: 2 additions & 1 deletion examples/air-quality-sensor-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AppTask : public AppTaskCommon

CHIP_ERROR Init(void);

static void AirQualityActionEventHandler(AppEvent * aEvent);
static void AirQualitySensorUpdateTimerTimeoutCallback(k_timer * timer);
static void AirQualitySensorUpdateTimerEventHandler(AppEvent * aEvent);

static AppTask sAppTask;
};
Expand Down
70 changes: 60 additions & 10 deletions examples/air-quality-sensor-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,100 @@
*/

#include "AppTask.h"
#include "SensorManagerCommon.h"
#include <air-quality-sensor-manager.h>

LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

using namespace chip;
using namespace ::chip::app::Clusters;
using namespace ::chip::app::Clusters::AirQuality;

AppTask AppTask::sAppTask;
namespace {
k_timer sAirQualitySensorUpdateTimer;
constexpr uint16_t kAirQualitySensorUpdateTimerPeriod = 10000; // 10s timer period
} // namespace

constexpr EndpointId kAirQualityEndpoint = 1;
AppTask AppTask::sAppTask;

CHIP_ERROR AppTask::Init(void)
{
CHIP_ERROR err;

#if APP_USE_EXAMPLE_START_BUTTON
SetExampleButtonCallbacks(AirQualityActionEventHandler);
SetExampleButtonCallbacks(AirQualitySensorUpdateTimerEventHandler);
#endif
InitCommonParts();

AirQualitySensorManager::InitInstance(kAirQualityEndpoint);
err = SensorMgr().Init();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("Init of the Sensor Manager failed");
return err;
}

// Initialize air quality sensor update timer
k_timer_init(&sAirQualitySensorUpdateTimer, &AppTask::AirQualitySensorUpdateTimerTimeoutCallback, nullptr);
k_timer_user_data_set(&sAirQualitySensorUpdateTimer, this);
k_timer_start(&sAirQualitySensorUpdateTimer, K_MSEC(kAirQualitySensorUpdateTimerPeriod), K_NO_WAIT);

AirQualitySensorManager::InitInstance(kExampleEndpointId);

return CHIP_NO_ERROR;
}

void AppTask::UpdateClusterState(void)
{
CHIP_ERROR ret;
AirQualitySensorManager * mInstance = AirQualitySensorManager::GetInstance();
int16_t temperature;
uint16_t humidity;

ret = SensorMgr().GetTempAndHumMeasurValue(&temperature, &humidity);
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("Update of the Air Quality clusters failed");
return;
}

LOG_INF("Update Air Quality: temperature is (%d*0.01)°C, humidity is %d", temperature, humidity);

// Update AirQuality value
mInstance->OnAirQualityChangeHandler(AirQualityEnum::kModerate);
mInstance->OnAirQualityChangeHandler(AirQualityEnum::kUnknown);

// Update Carbon Dioxide
mInstance->OnCarbonDioxideMeasurementChangeHandler(400);
mInstance->OnCarbonDioxideMeasurementChangeHandler(0);

// Update Temperature value
mInstance->OnTemperatureMeasurementChangeHandler(18);
mInstance->OnTemperatureMeasurementChangeHandler(temperature);

// Update Humidity value
mInstance->OnHumidityMeasurementChangeHandler(60);
mInstance->OnHumidityMeasurementChangeHandler(humidity);
}

void AppTask::AirQualitySensorUpdateTimerTimeoutCallback(k_timer * timer)
{
if (!timer)
{
return;
}

AppEvent event;
event.Type = AppEvent::kEventType_Timer;
event.Handler = AirQualitySensorUpdateTimerEventHandler;
sAppTask.PostEvent(&event);
}

void AppTask::AirQualityActionEventHandler(AppEvent * aEvent)
void AppTask::AirQualitySensorUpdateTimerEventHandler(AppEvent * aEvent)
{
if (aEvent->Type == AppEvent::kEventType_Button)
if ((aEvent->Type == AppEvent::kEventType_Button) || (aEvent->Type == AppEvent::kEventType_Timer))
{
sAppTask.UpdateClusterState();
}

if (aEvent->Type == AppEvent::kEventType_Timer)
{
// Start next timer to measurement the air quality sensor
k_timer_start(&sAirQualitySensorUpdateTimer, K_MSEC(kAirQualitySensorUpdateTimerPeriod), K_NO_WAIT);
}
}
22 changes: 19 additions & 3 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH)

set(ignoreMe "${TLNK_USB_DONGLE}")

if(${TLNK_MARS_BOARD} MATCHES y)
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.overlay")
set(MARS_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.overlay")
else()
unset(MARS_DTC_OVERLAY_FILE)
endif()
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.conf")
set(MARS_CONF_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}_mars.conf")
else()
unset(MARS_CONF_OVERLAY_FILE)
endif()
else()
unset(MARS_CONF_OVERLAY_FILE)
endif()

if(${TLNK_USB_DONGLE} MATCHES y)
if(EXISTS "${CHIP_ROOT}/src/platform/telink/${BOARD}_usb.overlay")
set(USB_DTC_OVERLAY_FILE "${CHIP_ROOT}/src/platform/telink/${BOARD}_usb.overlay")
Expand Down Expand Up @@ -58,14 +73,14 @@ endif()

if(DTC_OVERLAY_FILE)
set(DTC_OVERLAY_FILE
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
CACHE STRING "" FORCE
)
else()
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
endif()

set(CONF_FILE ${USB_CONF_OVERLAY_FILE} prj.conf)
set(CONF_FILE ${USB_CONF_OVERLAY_FILE} ${MARS_CONF_OVERLAY_FILE} prj.conf)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/telink/chip-module)
Expand Down Expand Up @@ -99,6 +114,7 @@ target_sources(app PRIVATE
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${TELINK_COMMON}/util/src/PWMDevice.cpp
${TELINK_COMMON}/util/src/WS2812Device.cpp
${TELINK_COMMON}/util/src/ColorFormat.cpp)

chip_configure_data_model(app
Expand Down
12 changes: 11 additions & 1 deletion examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class AppTask : public AppTaskCommon
#endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */
void SetInitiateAction(PWMDevice::Action_t aAction, int32_t aActor, uint8_t * value);
void UpdateClusterState(void);
PWMDevice & GetPWMDevice(void) { return mPwmRgbBlueLed; }

#ifdef CONFIG_WS2812_STRIP
WS2812Device & GetLightingDevice(void) { return mWS2812Device; }
#else
PWMDevice & GetLightingDevice(void) { return mPwmRgbBlueLed; }
#endif /* CONFIG_WS2812_STRIP */

private:
friend AppTask & GetAppTask(void);
Expand All @@ -47,11 +52,16 @@ class AppTask : public AppTaskCommon
static unsigned int sPowerOnFactoryResetTimerCnt;
static k_timer sPowerOnFactoryResetTimer;
#endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */

#ifdef CONFIG_WS2812_STRIP
WS2812Device mWS2812Device;
#else
PWMDevice mPwmRgbBlueLed;
#if USE_RGB_PWM
PWMDevice mPwmRgbGreenLed;
PWMDevice mPwmRgbRedLed;
#endif
#endif /* CONFIG_WS2812_STRIP */

static AppTask sAppTask;
};
Expand Down
Loading

0 comments on commit de9d6d2

Please sign in to comment.