Skip to content

Commit f9001e2

Browse files
authored
Merge pull request #2790 from mtkrtk/master
[Renesas RZ/A1H] Allow using PWM and MTU in the same time
2 parents 6521be6 + 5033a47 commit f9001e2

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1H/pwmout_api.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,11 @@ static int MAX_PERIOD[] = {
207207
2000000,
208208
};
209209

210-
typedef enum {
211-
MODE_PWM = 0,
212-
MODE_MTU2
213-
} PWMmode;
214-
215210
typedef enum {
216211
MTU2_PULSE = 0,
217212
MTU2_PERIOD
218213
} MTU2Signal;
219214

220-
static int pwm_mode = MODE_PWM;
221215
static uint16_t init_period_ch1 = 0;
222216
static uint16_t init_period_ch2 = 0;
223217
static uint16_t init_mtu2_period_ch[5] = {0};
@@ -234,7 +228,6 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
234228
/* PWM by MTU2 */
235229
int tmp_pwm;
236230

237-
pwm_mode = MODE_MTU2;
238231
// power on
239232
CPGSTBCR3 &= ~(CPG_STBCR3_BIT_MSTP33);
240233

@@ -269,7 +262,6 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
269262
}
270263
} else {
271264
/* PWM */
272-
pwm_mode = MODE_PWM;
273265
// power on
274266
CPGSTBCR3 &= ~(CPG_STBCR3_BIT_MSTP30);
275267

@@ -306,7 +298,7 @@ void pwmout_write(pwmout_t* obj, float value) {
306298
uint32_t wk_cycle;
307299
uint16_t v;
308300

309-
if (pwm_mode == MODE_MTU2) {
301+
if (obj->pwm >= MTU2_PWM_OFFSET) {
310302
/* PWM by MTU2 */
311303
int tmp_pwm;
312304

@@ -347,7 +339,7 @@ float pwmout_read(pwmout_t* obj) {
347339
uint32_t wk_cycle;
348340
float value;
349341

350-
if (pwm_mode == MODE_MTU2) {
342+
if (obj->pwm >= MTU2_PWM_OFFSET) {
351343
/* PWM by MTU2 */
352344
uint32_t wk_pulse;
353345
int tmp_pwm;
@@ -406,7 +398,7 @@ void pwmout_period_us(pwmout_t* obj, int us) {
406398
uint16_t wk_last_cycle;
407399
int max_us = 0;
408400

409-
if (pwm_mode == MODE_MTU2) {
401+
if (obj->pwm >= MTU2_PWM_OFFSET) {
410402
/* PWM by MTU2 */
411403
int tmp_pwm;
412404
uint16_t tmp_tgra;
@@ -550,7 +542,7 @@ void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
550542
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
551543
float value = 0;
552544

553-
if (pwm_mode == MODE_MTU2) {
545+
if (obj->pwm >= MTU2_PWM_OFFSET) {
554546
/* PWM by MTU2 */
555547
if (mtu2_period_ch[obj->ch] != 0) {
556548
value = (float)us / (float)mtu2_period_ch[obj->ch];

0 commit comments

Comments
 (0)