Skip to content

Commit 0205da5

Browse files
committed
remove the local static for seq values for tone
1 parent 3aed8f7 commit 0205da5

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

cores/nRF5/Tone.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,23 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
170170
{
171171
// limit frequency to reasonable audible range
172172
if((frequency < 20) | (frequency > 25000)) {
173-
LOG_LV1("TON", "frequency outside range [20..25000] -- ignoring");
173+
LOG_LV1("Tone", "frequency outside range [20..25000] -- ignoring");
174174
return;
175175
}
176176
uint64_t pulse_count = _calculate_pulse_count(frequency, duration);
177177
uint16_t time_period = _calculate_time_period(frequency);
178178
if (!_pwm_config.ensurePwmPeripheralOwnership()) {
179-
LOG_LV1("TON", "Unable to acquire PWM peripheral");
179+
LOG_LV1("Tone", "Unable to acquire PWM peripheral");
180180
} else if (!_pwm_config.stopPlayback()) {
181-
LOG_LV1("TON", "Unable to stop playback");
181+
LOG_LV1("Tone", "Unable to stop playback");
182182
} else if (!_pwm_config.initializeFromPulseCountAndTimePeriod(pulse_count, time_period)) {
183-
LOG_LV1("TON", "Failed calculating configuration");
183+
LOG_LV1("Tone", "Failed calculating configuration");
184184
} else if (!_pwm_config.applyConfiguration(pin)) {
185-
LOG_LV1("TON", "Failed applying configuration");
185+
LOG_LV1("Tone", "Failed applying configuration");
186186
} else if (!_pwm_config.startPlayback()) {
187-
LOG_LV1("TON", "Failed attempting to start PWM peripheral");
187+
LOG_LV1("Tone", "Failed attempting to start PWM peripheral");
188188
} else {
189-
//LOG_LV2("TON", "Started playback of tone at frequency %d duration %ld", frequency, duration);
189+
//LOG_LV2("Tone", "Started playback of tone at frequency %d duration %ld", frequency, duration);
190190
}
191191
return;
192192
}
@@ -199,7 +199,7 @@ void noTone(uint8_t pin)
199199

200200
bool TonePwmConfig::ensurePwmPeripheralOwnership(void) {
201201
if (!_HwPWM->isOwner(TonePwmConfig::toneToken) && !_HwPWM->takeOwnership(TonePwmConfig::toneToken)) {
202-
LOG_LV1("TON", "unable to allocate PWM2 to Tone");
202+
LOG_LV1("Tone", "unable to allocate PWM2 to Tone");
203203
return false;
204204
}
205205
return true;
@@ -238,7 +238,7 @@ bool TonePwmConfig::ensurePwmPeripheralOwnership(void) {
238238
bool TonePwmConfig::initializeFromPulseCountAndTimePeriod(uint64_t pulse_count_x, uint16_t time_period) {
239239

240240
if (_bits_used(pulse_count_x) > 37) {
241-
LOG_LV1("TON", "pulse count is limited to 37 bit long value");
241+
LOG_LV1("Tone", "pulse count is limited to 37 bit long value");
242242
return false;
243243
}
244244

@@ -332,14 +332,8 @@ bool TonePwmConfig::applyConfiguration(uint32_t pin) {
332332
nrf_pwm_shorts_set(_PWMInstance, this->shorts);
333333
nrf_pwm_int_set(_PWMInstance, 0);
334334

335-
// static sequence value ... This is the value actually used
336-
// during playback ... do NOT modify without semaphore *and*
337-
// having ensured playback has stopped!
338-
static uint16_t seq_values; // static value
339-
seq_values = this->duty_with_polarity;
340-
341-
nrf_pwm_seq_ptr_set(_PWMInstance, 0, &seq_values);
342-
nrf_pwm_seq_ptr_set(_PWMInstance, 1, &seq_values);
335+
nrf_pwm_seq_ptr_set(_PWMInstance, 0, &this->duty_with_polarity);
336+
nrf_pwm_seq_ptr_set(_PWMInstance, 1, &this->duty_with_polarity);
343337
nrf_pwm_seq_cnt_set(_PWMInstance, 0, 1);
344338
nrf_pwm_seq_cnt_set(_PWMInstance, 1, 1);
345339

@@ -361,7 +355,7 @@ bool TonePwmConfig::applyConfiguration(uint32_t pin) {
361355

362356
bool TonePwmConfig::startPlayback(void) {
363357
if (!this->ensurePwmPeripheralOwnership()) {
364-
LOG_LV1("TON", "PWM peripheral not available for playback");
358+
LOG_LV1("Tone", "PWM peripheral not available for playback");
365359
return false;
366360
}
367361
nrf_pwm_task_trigger(_PWMInstance, this->task_to_start);
@@ -371,7 +365,7 @@ bool TonePwmConfig::startPlayback(void) {
371365
bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
372366

373367
if (!_HwPWM->isOwner(TonePwmConfig::toneToken)) {
374-
LOG_LV2("TON", "Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call....");
368+
LOG_LV2("Tone", "Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call....");
375369
return false;
376370
}
377371
// ensure stopped and then disable

0 commit comments

Comments
 (0)