@@ -127,8 +127,12 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
127
127
128
128
void noTone (uint8_t pin)
129
129
{
130
+ bool notInIsr = !isInISR ();
131
+
130
132
if (!_HwPWM->isOwner (_toneToken)) {
131
- LOG_LV1 (" TON" , " Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call...." );
133
+ if (notInIsr) {
134
+ LOG_LV1 (" TON" , " Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call...." );
135
+ }
132
136
return ;
133
137
}
134
138
nrf_pwm_task_trigger (_PWMInstance, NRF_PWM_TASK_STOP);
@@ -137,7 +141,9 @@ void noTone(uint8_t pin)
137
141
NVIC_DisableIRQ (_IntNo);
138
142
_HwPWM->releaseOwnership (_toneToken);
139
143
if (_HwPWM->isOwner (_toneToken)) {
140
- LOG_LV1 (" TON" , " stopped tone, but failed to release ownership of PWM peripheral?" );
144
+ if (notInIsr) {
145
+ LOG_LV1 (" TON" , " stopped tone, but failed to release ownership of PWM peripheral?" );
146
+ }
141
147
return ;
142
148
}
143
149
}
@@ -151,11 +157,8 @@ void PWM2_IRQHandler(void){
151
157
if (!no_stop){
152
158
count_duration--;
153
159
if (count_duration == 0 ) {
154
- nrf_pwm_task_trigger (NRF_PWM2, NRF_PWM_TASK_STOP);
155
- nrf_pwm_disable (NRF_PWM2);
156
- _PWMInstance->PSEL .OUT [0 ] = NRF_PWM_PIN_NOT_CONNECTED;
157
- NVIC_DisableIRQ (PWM2_IRQn);
158
- _HwPWM->releaseOwnership (_toneToken);
160
+ uint8_t pin = _PWMInstance->PSEL .OUT [0 ];
161
+ noTone (pin);
159
162
} else {
160
163
nrf_pwm_task_trigger (NRF_PWM2, NRF_PWM_TASK_SEQSTART0);
161
164
}
0 commit comments