Closed matsujirushi closed 4 years ago
Declare class objects as static/global variables would lead to constructor invocation timing uncontrollable. In this case, the constructor seems not invoked. You could try this way:
class DigitalOut
{
private:
os_hal_gpio_pin _Pin;
public:
DigitalOut(os_hal_gpio_pin pin);
DigitalOut(){};
void Write(int value);
};
DigitalOut::DigitalOut(os_hal_gpio_pin pin)
{
_Pin = pin;
mtk_os_hal_gpio_request(_Pin);
mtk_os_hal_gpio_set_direction(_Pin, OS_HAL_GPIO_DIR_OUTPUT);
}
void DigitalOut::Write(int value)
{
mtk_os_hal_gpio_set_output(_Pin, value ? OS_HAL_GPIO_DATA_HIGH : OS_HAL_GPIO_DATA_LOW);
}
static DigitalOut led;
static void blink_task(void* pParameters)
{
led = DigitalOut(gpio_led_green);
//....
}
Hi Lawrance-san,
In this case, this code looks fine. However, I think the lack of a constructor of static variable call should be addressed in the development environment, not in the code.
Hi Matsuoka-san, Thank you very much for the solution!
Constructor of static variable is not called. Don't you know how to fix it?
https://github.com/matsujirushi/mt3620_m4_software/tree/matsujirushi-issue-22/MT3620_M4_Sample_Code/FreeRTOS/MT3620_RTApp_FreeRTOS_CPP https://github.com/matsujirushi/mt3620_m4_software/commit/728055c951f6987ee87baf0f5f3ba4182377037e