Skip to content

Commit a19fa06

Browse files
ccli8adbridge
authored andcommitted
Fix pwmout power-down condition
1 parent aefa147 commit a19fa06

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

targets/TARGET_NUVOTON/TARGET_M451/pwmout_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ void pwmout_init(pwmout_t* obj, PinName pin)
9999

100100
((struct nu_pwm_var *) modinit->var)->en_msk |= 1 << chn;
101101

102-
// Mark this module to be inited.
103-
int i = modinit - pwm_modinit_tab;
104-
pwm_modinit_mask |= 1 << i;
102+
if (((struct nu_pwm_var *) modinit->var)->en_msk) {
103+
// Mark this module to be inited.
104+
int i = modinit - pwm_modinit_tab;
105+
pwm_modinit_mask |= 1 << i;
106+
}
105107
}
106108

107109
void pwmout_free(pwmout_t* obj)
@@ -120,9 +122,11 @@ void pwmout_free(pwmout_t* obj)
120122
CLK_DisableModuleClock(modinit->clkidx);
121123
}
122124

123-
// Mark this module to be deinited.
124-
int i = modinit - pwm_modinit_tab;
125-
pwm_modinit_mask &= ~(1 << i);
125+
if (((struct nu_pwm_var *) modinit->var)->en_msk == 0) {
126+
// Mark this module to be deinited.
127+
int i = modinit - pwm_modinit_tab;
128+
pwm_modinit_mask &= ~(1 << i);
129+
}
126130
}
127131

128132
void pwmout_write(pwmout_t* obj, float value)

targets/TARGET_NUVOTON/TARGET_NUC472/pwmout_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ void pwmout_init(pwmout_t* obj, PinName pin)
105105

106106
((struct nu_pwm_var *) modinit->var)->en_msk |= 1 << chn;
107107

108-
// Mark this module to be inited.
109-
int i = modinit - pwm_modinit_tab;
110-
pwm_modinit_mask |= 1 << i;
108+
if (((struct nu_pwm_var *) modinit->var)->en_msk) {
109+
// Mark this module to be inited.
110+
int i = modinit - pwm_modinit_tab;
111+
pwm_modinit_mask |= 1 << i;
112+
}
111113
}
112114

113115
void pwmout_free(pwmout_t* obj)
@@ -143,9 +145,11 @@ void pwmout_free(pwmout_t* obj)
143145
}
144146
}
145147

146-
// Mark this module to be deinited.
147-
int i = modinit - pwm_modinit_tab;
148-
pwm_modinit_mask &= ~(1 << i);
148+
if (((struct nu_pwm_var *) modinit->var)->en_msk == 0) {
149+
// Mark this module to be deinited.
150+
int i = modinit - pwm_modinit_tab;
151+
pwm_modinit_mask &= ~(1 << i);
152+
}
149153
}
150154

151155
void pwmout_write(pwmout_t* obj, float value)

0 commit comments

Comments
 (0)