@@ -67,13 +67,11 @@ class TonePwmConfig {
67
67
boolean is_initialized; // < defaults to uninitialized
68
68
69
69
public:
70
- bool EnsurePwmPeripheralOwnership (void );
71
- bool InitializeFromPulseCountAndTimePeriod (uint64_t pulse_count, uint16_t time_period);
72
- bool ApplyConfiguration (uint32_t pin);
73
- bool StartPlayback (void );
74
- bool StopPlayback (bool releaseOwnership = false );
75
- bool ApplyConfigurationAndStartPlayback (uint32_t pin);
76
- uint64_t CalculateExpectedPulseCount (void );
70
+ bool ensurePwmPeripheralOwnership (void );
71
+ bool initializeFromPulseCountAndTimePeriod (uint64_t pulse_count, uint16_t time_period);
72
+ bool applyConfiguration (uint32_t pin);
73
+ bool startPlayback (void );
74
+ bool stopPlayback (bool releaseOwnership = false );
77
75
};
78
76
TonePwmConfig _pwm_config;
79
77
@@ -205,15 +203,15 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
205
203
uint64_t pulse_count = _calculate_pulse_count (frequency, duration);
206
204
uint16_t time_period = _calculate_time_period (frequency);
207
205
208
- if (!_pwm_config.EnsurePwmPeripheralOwnership ()) {
206
+ if (!_pwm_config.ensurePwmPeripheralOwnership ()) {
209
207
LOG_LV1 (" TON" , " Unable to acquire PWM peripheral" );
210
- } else if (!_pwm_config.StopPlayback ()) {
208
+ } else if (!_pwm_config.stopPlayback ()) {
211
209
LOG_LV1 (" TON" , " Unable to stop playback" );
212
- } else if (!_pwm_config.InitializeFromPulseCountAndTimePeriod (pulse_count, time_period)) {
210
+ } else if (!_pwm_config.initializeFromPulseCountAndTimePeriod (pulse_count, time_period)) {
213
211
LOG_LV1 (" TON" , " Failed calculating configuration" );
214
- } else if (!_pwm_config.ApplyConfiguration (pin)) {
212
+ } else if (!_pwm_config.applyConfiguration (pin)) {
215
213
LOG_LV1 (" TON" , " Failed applying configuration" );
216
- } else if (!_pwm_config.StartPlayback ()) {
214
+ } else if (!_pwm_config.startPlayback ()) {
217
215
LOG_LV1 (" TON" , " Failed attempting to start PWM peripheral" );
218
216
} else {
219
217
// LOG_LV2("TON", "Started playback of tone at frequency %d duration %ld", frequency, duration);
@@ -224,10 +222,10 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
224
222
void noTone (uint8_t pin)
225
223
{
226
224
( void )pin; // avoid unreferenced parameter compiler warning
227
- _pwm_config.StopPlayback (true ); // release ownership of PWM peripheral
225
+ _pwm_config.stopPlayback (true ); // release ownership of PWM peripheral
228
226
}
229
227
230
- bool TonePwmConfig::EnsurePwmPeripheralOwnership (void ) {
228
+ bool TonePwmConfig::ensurePwmPeripheralOwnership (void ) {
231
229
if (!_HwPWM->isOwner (TonePwmConfig::toneToken) && !_HwPWM->takeOwnership (TonePwmConfig::toneToken)) {
232
230
LOG_LV1 (" TON" , " unable to allocate PWM2 to Tone" );
233
231
return false ;
@@ -265,7 +263,7 @@ bool TonePwmConfig::EnsurePwmPeripheralOwnership(void) {
265
263
// COUNT += (start at SEQ0) ? (SEQ0.CNT * (SEQ0.REFRESH+1) : 0;
266
264
// COUNT += 1; // final SEQ1 emits single pulse
267
265
//
268
- bool TonePwmConfig::InitializeFromPulseCountAndTimePeriod (uint64_t pulse_count_x, uint16_t time_period) {
266
+ bool TonePwmConfig::initializeFromPulseCountAndTimePeriod (uint64_t pulse_count_x, uint16_t time_period) {
269
267
270
268
if (_bits_used (pulse_count_x) > 37 ) {
271
269
LOG_LV1 (" TON" , " pulse count is limited to 37 bit long value" );
@@ -339,17 +337,17 @@ bool TonePwmConfig::InitializeFromPulseCountAndTimePeriod(uint64_t pulse_count_x
339
337
this ->is_initialized = true ;
340
338
return true ;
341
339
}
342
- bool TonePwmConfig::ApplyConfiguration (uint32_t pin) {
340
+ bool TonePwmConfig::applyConfiguration (uint32_t pin) {
343
341
if (!this ->is_initialized ) {
344
342
return false ;
345
343
}
346
344
if (pin >= PINS_COUNT) {
347
345
return false ;
348
346
}
349
- if (!this ->EnsurePwmPeripheralOwnership ()) {
347
+ if (!this ->ensurePwmPeripheralOwnership ()) {
350
348
return false ;
351
349
}
352
- this ->StopPlayback (false );
350
+ this ->stopPlayback (false );
353
351
354
352
this ->arduino_pin = pin;
355
353
this ->nrf_pin = g_ADigitalPinMap[pin];
@@ -394,19 +392,19 @@ bool TonePwmConfig::ApplyConfiguration(uint32_t pin) {
394
392
nrf_pwm_event_clear (_PWMInstance, NRF_PWM_EVENT_LOOPSDONE);
395
393
return true ;
396
394
}
397
- bool TonePwmConfig::StartPlayback (void ) {
395
+ bool TonePwmConfig::startPlayback (void ) {
398
396
if (!this ->is_initialized ) {
399
397
LOG_LV1 (" TON" , " Cannot start playback without first initializing" );
400
398
return false ;
401
399
}
402
- if (!this ->EnsurePwmPeripheralOwnership ()) {
400
+ if (!this ->ensurePwmPeripheralOwnership ()) {
403
401
LOG_LV1 (" TON" , " PWM peripheral not available for playback" );
404
402
return false ;
405
403
}
406
404
nrf_pwm_task_trigger (_PWMInstance, this ->task_to_start );
407
405
return true ;
408
406
}
409
- bool TonePwmConfig::StopPlayback (bool releaseOwnership) {
407
+ bool TonePwmConfig::stopPlayback (bool releaseOwnership) {
410
408
411
409
bool notInIsr = !isInISR ();
412
410
0 commit comments