@@ -320,13 +320,17 @@ void TC8_Handler()
320
320
if (pwm_counter_vals[17 ]) TC_SetRB (TC2, 2 , pwm_counter_vals[17 ]);
321
321
}
322
322
323
+
324
+
325
+
326
+
323
327
// implementation of the hardware_api.cpp
324
328
// ---------------------------------------------------------------------------------------------------------------------------------
325
329
326
330
// function setting the high pwm frequency to the supplied pins
327
331
// - BLDC motor - 3PWM setting
328
332
// - hardware specific
329
- void _configure3PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC) {
333
+ void * _configure3PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC) {
330
334
if (!pwm_frequency || !_isset (pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 50khz
331
335
else pwm_frequency = _constrain (pwm_frequency, 0 , _PWM_FREQUENCY_MAX); // constrain to 50kHz max
332
336
// save the pwm frequency
@@ -337,13 +341,21 @@ void _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const int
337
341
initPWM (pinC, _pwm_frequency);
338
342
// sync the timers if possible
339
343
syncTimers (pinA, pinB, pinC);
344
+
345
+ GenericDriverParams* params = new GenericDriverParams {
346
+ .pins = { pinA, pinB, pinC },
347
+ .pwm_frequency = pwm_frequency
348
+ };
349
+ return params;
340
350
}
341
351
342
352
353
+
354
+
343
355
// Configuring PWM frequency, resolution and alignment
344
356
// - Stepper driver - 2PWM setting
345
357
// - hardware specific
346
- void _configure2PWM (long pwm_frequency, const int pinA, const int pinB) {
358
+ void * _configure2PWM (long pwm_frequency, const int pinA, const int pinB) {
347
359
if (!pwm_frequency || !_isset (pwm_frequency)) pwm_frequency = _PWM_FREQUENCY; // default frequency 50khz
348
360
else pwm_frequency = _constrain (pwm_frequency, 0 , _PWM_FREQUENCY_MAX); // constrain to 50kHz max
349
361
// save the pwm frequency
@@ -353,12 +365,21 @@ void _configure2PWM(long pwm_frequency, const int pinA, const int pinB) {
353
365
initPWM (pinB, _pwm_frequency);
354
366
// sync the timers if possible
355
367
syncTimers (pinA, pinB);
368
+
369
+ GenericDriverParams* params = new GenericDriverParams {
370
+ .pins = { pinA, pinB },
371
+ .pwm_frequency = pwm_frequency
372
+ };
373
+ return params;
356
374
}
357
375
376
+
377
+
378
+
358
379
// function setting the high pwm frequency to the supplied pins
359
380
// - Stepper motor - 4PWM setting
360
381
// - hardware speciffic
361
- void _configure4PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC, const int pinD) {
382
+ void * _configure4PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC, const int pinD) {
362
383
if (!pwm_frequency || !_isset (pwm_frequency)) pwm_frequency = _PWM_FREQUENCY; // default frequency 50khz
363
384
else pwm_frequency = _constrain (pwm_frequency, 0 , _PWM_FREQUENCY_MAX); // constrain to 50kHz max
364
385
// save the pwm frequency
@@ -370,36 +391,52 @@ void _configure4PWM(long pwm_frequency,const int pinA, const int pinB, const int
370
391
initPWM (pinD, _pwm_frequency);
371
392
// sync the timers if possible
372
393
syncTimers (pinA, pinB, pinC, pinD);
394
+
395
+ GenericDriverParams* params = new GenericDriverParams {
396
+ .pins = { pinA, pinB, pinC, pinD },
397
+ .pwm_frequency = pwm_frequency
398
+ };
399
+ return params;
373
400
}
374
401
402
+
403
+
404
+
375
405
// function setting the pwm duty cycle to the hardware
376
406
// - BLDC motor - 3PWM setting
377
407
// - hardware speciffic
378
- void _writeDutyCycle3PWM (float dc_a, float dc_b, float dc_c, int pinA, int pinB, int pinC ){
408
+ void _writeDutyCycle3PWM (float dc_a, float dc_b, float dc_c, void * param ){
379
409
// transform duty cycle from [0,1] to [0,_max_pwm_value]
380
- setPwm (pinA, _max_pwm_value*dc_a);
381
- setPwm (pinB, _max_pwm_value*dc_b);
382
- setPwm (pinC, _max_pwm_value*dc_c);
410
+ GenericDriverParams* p = (GenericDriverParams*)param;
411
+ setPwm (p->pins [0 ], _max_pwm_value*dc_a);
412
+ setPwm (p->pins [1 ], _max_pwm_value*dc_b);
413
+ setPwm (p->pins [2 ], _max_pwm_value*dc_c);
383
414
}
384
415
416
+
417
+
385
418
// function setting the pwm duty cycle to the hardware
386
419
// - Stepper motor - 4PWM setting
387
420
// - hardware speciffic
388
- void _writeDutyCycle4PWM (float dc_1a, float dc_1b, float dc_2a, float dc_2b, int pin1A, int pin1B, int pin2A, int pin2B ){
421
+ void _writeDutyCycle4PWM (float dc_1a, float dc_1b, float dc_2a, float dc_2b, void * param ){
389
422
// transform duty cycle from [0,1] to [0,_max_pwm_value]
390
- setPwm (pin1A, _max_pwm_value*dc_1a);
391
- setPwm (pin1B, _max_pwm_value*dc_1b);
392
- setPwm (pin2A, _max_pwm_value*dc_2a);
393
- setPwm (pin2B, _max_pwm_value*dc_2b);
423
+ GenericDriverParams* p = (GenericDriverParams*)param;
424
+ setPwm (p->pins [0 ], _max_pwm_value*dc_1a);
425
+ setPwm (p->pins [1 ], _max_pwm_value*dc_1b);
426
+ setPwm (p->pins [2 ], _max_pwm_value*dc_2a);
427
+ setPwm (p->pins [3 ], _max_pwm_value*dc_2b);
394
428
}
395
429
430
+
431
+
396
432
// Function setting the duty cycle to the pwm pin (ex. analogWrite())
397
433
// - Stepper driver - 2PWM setting
398
434
// - hardware specific
399
- void _writeDutyCycle2PWM (float dc_a, float dc_b, int pinA, int pinB ){
435
+ void _writeDutyCycle2PWM (float dc_a, float dc_b, void * param ){
400
436
// transform duty cycle from [0,1] to [0,_max_pwm_value]
401
- setPwm (pinA, _max_pwm_value*dc_a);
402
- setPwm (pinB, _max_pwm_value*dc_b);
437
+ GenericDriverParams* p = (GenericDriverParams*)param;
438
+ setPwm (p->pins [0 ], _max_pwm_value*dc_a);
439
+ setPwm (p->pins [1 ], _max_pwm_value*dc_b);
403
440
}
404
441
405
442
0 commit comments