Skip to content

Commit

Permalink
[Telink] LEDs & Buttons DTS improvements (#27034)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
s07641069 and andy31415 authored Jun 3, 2023
1 parent 5711d2f commit b552c54
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 144 deletions.
4 changes: 1 addition & 3 deletions examples/all-clusters-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1
4 changes: 1 addition & 3 deletions examples/all-clusters-minimal-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 0
#define APP_SET_DEVICE_INFO_PROVIDER 0
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1
#define APP_USE_IDENTIFY_PWM 0 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 0
6 changes: 1 addition & 5 deletions examples/bridge-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"

#define LIGHTING_PWM_SPEC_RGB_BLUE PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0))
#define APP_USE_IDENTIFY_PWM 1
2 changes: 1 addition & 1 deletion examples/bridge-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

namespace {
const struct pwm_dt_spec sPwmRgbSpecBlueLed = LIGHTING_PWM_SPEC_RGB_BLUE;
const struct pwm_dt_spec sPwmRgbSpecBlueLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
} // namespace

AppTask AppTask::sAppTask;
Expand Down
6 changes: 1 addition & 5 deletions examples/contact-sensor-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@
#define APP_USE_THREAD_START_BUTTON 0
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"

#define CONTACT_STATE_LED 6
#define APP_USE_IDENTIFY_PWM 1
2 changes: 1 addition & 1 deletion examples/contact-sensor-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CHIP_ERROR AppTask::Init(void)
InitCommonParts();

#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED
sContactSensorLED.Init(CONTACT_STATE_LED);
sContactSensorLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios));
sContactSensorLED.Set(ContactSensorMgr().IsContactClosed());
#endif

Expand Down
4 changes: 1 addition & 3 deletions examples/light-switch-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1
10 changes: 1 addition & 9 deletions examples/lighting-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1

// Lighting LED config
#define USE_RGB_PWM 0

#define LIGHTING_PWM_SPEC_RGB_BLUE PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0))
#if USE_RGB_PWM
#define LIGHTING_PWM_SPEC_RGB_GREEN PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1))
#define LIGHTING_PWM_SPEC_RGB_RED PWM_DT_SPEC_GET(DT_ALIAS(pwm_led2))
#endif
6 changes: 3 additions & 3 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL);

namespace {
const struct pwm_dt_spec sPwmRgbSpecBlueLed = LIGHTING_PWM_SPEC_RGB_BLUE;
const struct pwm_dt_spec sPwmRgbSpecBlueLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
#if USE_RGB_PWM
const struct pwm_dt_spec sPwmRgbSpecGreenLed = LIGHTING_PWM_SPEC_RGB_GREEN;
const struct pwm_dt_spec sPwmRgbSpecRedLed = LIGHTING_PWM_SPEC_RGB_RED;
const struct pwm_dt_spec sPwmRgbSpecGreenLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
const struct pwm_dt_spec sPwmRgbSpecRedLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led2));

uint8_t sBrightness;
PWMDevice::Action_t sColorAction = PWMDevice::INVALID_ACTION;
Expand Down
6 changes: 1 addition & 5 deletions examples/lock-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"

#define LOCK_STATE_LED 6
#define APP_USE_IDENTIFY_PWM 1
2 changes: 1 addition & 1 deletion examples/lock-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CHIP_ERROR AppTask::Init(void)
InitCommonParts();

#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED
sLockLED.Init(LOCK_STATE_LED);
sLockLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios));
sLockLED.Set(BoltLockMgr().IsLocked());
#endif

Expand Down
4 changes: 1 addition & 3 deletions examples/ota-requestor-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1
39 changes: 0 additions & 39 deletions examples/platform/telink/common/include/AppConfigCommon.h

This file was deleted.

21 changes: 10 additions & 11 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ constexpr int kFactoryResetTriggerCntr = 3;
constexpr int kAppEventQueueSize = 10;

#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE
const struct gpio_dt_spec sFactoryResetButtonDt = BUTTON_FACTORY_RESET;
const struct gpio_dt_spec sBleStartButtonDt = BUTTON_BLE_START;
const struct gpio_dt_spec sFactoryResetButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_1), gpios);
const struct gpio_dt_spec sBleStartButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_2), gpios);
#if APP_USE_THREAD_START_BUTTON
const struct gpio_dt_spec sThreadStartButtonDt = BUTTON_THREAD_START;
const struct gpio_dt_spec sThreadStartButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_3), gpios);
#endif
#if APP_USE_EXAMPLE_START_BUTTON
const struct gpio_dt_spec sExampleActionButtonDt = BUTTON_EXAMPLE_ACTION;
const struct gpio_dt_spec sExampleActionButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_4), gpios);
#endif
#else
const struct gpio_dt_spec sButtonCol1Dt = BUTTON_COL_1;
const struct gpio_dt_spec sButtonCol2Dt = BUTTON_COL_2;
const struct gpio_dt_spec sButtonRow1Dt = BUTTON_ROW_1;
const struct gpio_dt_spec sButtonRow2Dt = BUTTON_ROW_2;
const struct gpio_dt_spec sButtonCol1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col1), gpios);
const struct gpio_dt_spec sButtonCol2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col2), gpios);
const struct gpio_dt_spec sButtonRow1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row1), gpios);
const struct gpio_dt_spec sButtonRow2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row2), gpios);
#endif

#if APP_USE_IDENTIFY_PWM
Expand All @@ -78,7 +78,7 @@ constexpr uint32_t kIdentifyFinishOffRateMs = 50;
constexpr uint32_t kIdentifyChannelChangeRateMs = 1000;
constexpr uint32_t kIdentifyBreatheRateMs = 1000;

const struct pwm_dt_spec sPwmIdentifySpecGreenLed = LIGHTING_PWM_SPEC_IDENTIFY_GREEN;
const struct pwm_dt_spec sPwmIdentifySpecGreenLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led3));
#endif

#if APP_SET_NETWORK_COMM_ENDPOINT_SEC
Expand Down Expand Up @@ -247,9 +247,8 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void)

// Initialize status LED
#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED
LEDWidget::InitGpio(LEDS_PORT);
LEDWidget::SetStateUpdateCallback(LEDStateUpdateHandler);
sStatusLED.Init(SYSTEM_STATE_LED);
sStatusLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(system_state_led), gpios));

UpdateStatusLED();
#endif
Expand Down
6 changes: 2 additions & 4 deletions examples/platform/telink/util/include/LEDWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class LEDWidget
public:
typedef void (*LEDWidgetStateUpdateHandler)(LEDWidget * ledWidget);

static void InitGpio(const device * port);
static void SetStateUpdateCallback(LEDWidgetStateUpdateHandler stateUpdateCb);
const static struct device * mPort;
void Init(gpio_pin_t gpioNum);
void Init(gpio_dt_spec gpio);
void Set(bool state);
void Invert(void);
void Blink(uint32_t changeRateMS);
Expand All @@ -39,7 +37,7 @@ class LEDWidget
private:
uint32_t mBlinkOnTimeMS;
uint32_t mBlinkOffTimeMS;
gpio_pin_t mGPIONum;
gpio_dt_spec mGPIO;
bool mState;
k_timer mLedTimer;

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/telink/util/src/ButtonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int Button::Deinit(void)
int ret = 0;

/* Reconfigure output key pin to input */
ret = gpio_pin_configure(mOutput_matrix_pin->port, mOutput_matrix_pin->pin, GPIO_INPUT | GPIO_PULL_DOWN);
ret = gpio_pin_configure_dt(mOutput_matrix_pin, GPIO_INPUT | GPIO_PULL_DOWN);
if (ret < 0)
{
LOG_ERR("Reconfig out pin err: %d", ret);
Expand Down
22 changes: 6 additions & 16 deletions examples/platform/telink/util/src/LEDWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,25 @@

LOG_MODULE_REGISTER(LEDWidget);

const struct device * LEDWidget::mPort = NULL;
static LEDWidget::LEDWidgetStateUpdateHandler sStateUpdateCallback;

void LEDWidget::InitGpio(const device * port)
{
mPort = port;
if (!device_is_ready(mPort))
{
LOG_ERR("%s is not ready\n", mPort->name);
}
}

void LEDWidget::SetStateUpdateCallback(LEDWidgetStateUpdateHandler stateUpdateCb)
{
if (stateUpdateCb)
sStateUpdateCallback = stateUpdateCb;
}

void LEDWidget::Init(gpio_pin_t gpioNum)
void LEDWidget::Init(gpio_dt_spec gpio)
{
mBlinkOnTimeMS = 0;
mBlinkOffTimeMS = 0;
mGPIONum = gpioNum;
mGPIO = gpio;
mState = false;

int ret = gpio_pin_configure(mPort, mGPIONum, GPIO_OUTPUT_ACTIVE);
int ret = gpio_pin_configure_dt(&mGPIO, GPIO_OUTPUT_ACTIVE);
if (ret < 0)
{
LOG_ERR("GPIO pin %d configure - fail. Status%d\n", mGPIONum, ret);
LOG_ERR("GPIO pin %d configure - fail. Status%d\n", mGPIO.pin, ret);
}

k_timer_init(&mLedTimer, &LEDWidget::LedStateTimerHandler, nullptr);
Expand Down Expand Up @@ -99,10 +89,10 @@ void LEDWidget::ScheduleStateChange()
void LEDWidget::DoSet(bool state)
{
mState = state;
int ret = gpio_pin_set(mPort, mGPIONum, state);
int ret = gpio_pin_set_dt(&mGPIO, state);
if (ret < 0)
{
LOG_ERR("GPIO pin %d set -fail. Status: %d\n", mGPIONum, ret);
LOG_ERR("GPIO pin %d set -fail. Status: %d\n", mGPIO.pin, ret);
}
}

Expand Down
5 changes: 1 addition & 4 deletions examples/pump-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1

#include "AppConfigCommon.h"

#define PUMP_STATE_LED 6
// Time it takes in ms for the simulated pump to move from one state to another.
#define PUMP_START_PERIOS_MS 2000
2 changes: 1 addition & 1 deletion examples/pump-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CHIP_ERROR AppTask::Init(void)
InitCommonParts();

#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED
sPumpStateLED.Init(PUMP_STATE_LED);
sPumpStateLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios));
sPumpStateLED.Set(!PumpMgr().IsStopped());
#endif

Expand Down
5 changes: 1 addition & 4 deletions examples/pump-controller-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1

#include "AppConfigCommon.h"

#define PUMP_STATE_LED 6
// Time it takes in ms for the simulated pump to move from one state to another.
#define PUMP_START_PERIOS_MS 2000
2 changes: 1 addition & 1 deletion examples/pump-controller-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CHIP_ERROR AppTask::Init(void)
InitCommonParts();

#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED
sPumpStateLED.Init(PUMP_STATE_LED);
sPumpStateLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios));
sPumpStateLED.Set(!PumpMgr().IsStopped());
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 0 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 0
4 changes: 1 addition & 3 deletions examples/thermostat/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 1
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define APP_USE_IDENTIFY_PWM 1
8 changes: 1 addition & 7 deletions examples/window-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,4 @@
#define APP_USE_THREAD_START_BUTTON 0
#define APP_SET_DEVICE_INFO_PROVIDER 1
#define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0
#define APP_USE_IDENTIFY_PWM 1 // APP_USE_IDENTIFY_PWM must be defined before including "AppConfigCommon.h"

#include "AppConfigCommon.h"
#define LIGHTING_PWM_SPEC_RGB_BLUE PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0))

// NOTE: pwm_led1 by default DTS is used by PE0, so get an external LED connected to that pin
#define LIGHTING_PWM_SPEC_RGB_GREEN PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1))
#define APP_USE_IDENTIFY_PWM 1
12 changes: 6 additions & 6 deletions examples/window-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ constexpr int kToggleMoveTypeTriggerTimeout = 700;
k_timer sToggleMoveTypeTimer;

#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE
#define OPEN_WINDOW_BUTTON BUTTON_EXAMPLE_ACTION
#define CLOSE_WINDOW_BUTTON BUTTON_THREAD_START
#define OPEN_WINDOW_BUTTON GPIO_DT_SPEC_GET(DT_NODELABEL(key_4), gpios)
#define CLOSE_WINDOW_BUTTON GPIO_DT_SPEC_GET(DT_NODELABEL(key_3), gpios)

const struct gpio_dt_spec sOpenWindowButtonDt = OPEN_WINDOW_BUTTON;
const struct gpio_dt_spec sCloseWindowButtonDt = CLOSE_WINDOW_BUTTON;
#else
const struct gpio_dt_spec sButtonCol1Dt = BUTTON_COL_1;
const struct gpio_dt_spec sButtonCol2Dt = BUTTON_COL_2;
const struct gpio_dt_spec sButtonRow1Dt = BUTTON_ROW_1;
const struct gpio_dt_spec sButtonRow2Dt = BUTTON_ROW_2;
const struct gpio_dt_spec sButtonCol1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col1), gpios);
const struct gpio_dt_spec sButtonCol2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col2), gpios);
const struct gpio_dt_spec sButtonRow1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row1), gpios);
const struct gpio_dt_spec sButtonRow2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row2), gpios);
#endif

Button sOpenButton;
Expand Down
4 changes: 2 additions & 2 deletions examples/window-app/telink/src/WindowCovering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
using namespace chip::app::Clusters::WindowCovering;

static const struct pwm_dt_spec sLiftPwmDevice = LIGHTING_PWM_SPEC_RGB_BLUE;
static const struct pwm_dt_spec sTiltPwmDevice = LIGHTING_PWM_SPEC_RGB_GREEN;
static const struct pwm_dt_spec sLiftPwmDevice = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
static const struct pwm_dt_spec sTiltPwmDevice = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));

static constexpr uint32_t sMoveTimeoutMs{ 200 };
constexpr uint16_t sPercentDelta = 500;
Expand Down
Loading

0 comments on commit b552c54

Please sign in to comment.