@@ -273,14 +273,15 @@ uint8_t HardwarePWM::freeChannelCount(void) const
273273// returns true ONLY when (1) no PWM channel has a pin, and (2) the owner token is nullptr
274274bool HardwarePWM::takeOwnership (uint32_t token)
275275{
276+ bool const thread_mode = !isInISR ();
276277
277278 if (token == 0 ) {
278- if (! isInISR () ) LOG_LV1 (" HwPWM" , " zero is not a valid ownership token (attempted use in takeOwnership)" );
279+ if (thread_mode ) LOG_LV1 (" HwPWM" , " zero is not a valid ownership token (attempted use in takeOwnership)" );
279280 return false ;
280281 }
281282
282283 if (token == this ->_owner_token ) {
283- if (! isInISR () ) LOG_LV1 (" HwPWM" , " failing to acquire ownership because already owned by requesting token (cannot take ownership twice)" );
284+ if (thread_mode ) LOG_LV1 (" HwPWM" , " failing to acquire ownership because already owned by requesting token (cannot take ownership twice)" );
284285 return false ;
285286 }
286287
@@ -296,23 +297,25 @@ bool HardwarePWM::takeOwnership(uint32_t token)
296297// returns true ONLY when (1) no PWM channel has a pin attached, and (2) the owner token matches
297298bool HardwarePWM::releaseOwnership (uint32_t token)
298299{
300+ bool const thread_mode = !isInISR ();
301+
299302 if (token == 0 ) {
300- if (! isInISR () ) LOG_LV1 (" HwPWM" , " zero is not a valid ownership token (attempted use in releaseOwnership)" );
303+ if (thread_mode ) LOG_LV1 (" HwPWM" , " zero is not a valid ownership token (attempted use in releaseOwnership)" );
301304 return false ;
302305 }
303306
304307 if (!this ->isOwner (token)) {
305- if (! isInISR () ) LOG_LV1 (" HwPWM" , " attempt to release ownership when not the current owner" );
308+ if (thread_mode ) LOG_LV1 (" HwPWM" , " attempt to release ownership when not the current owner" );
306309 return false ;
307310 }
308311
309312 if (this ->usedChannelCount () != 0 ) {
310- if (! isInISR () ) LOG_LV1 (" HwPWM" , " attempt to release ownership when at least on channel is still connected" );
313+ if (thread_mode ) LOG_LV1 (" HwPWM" , " attempt to release ownership when at least on channel is still connected" );
311314 return false ;
312315 }
313316
314317 if (this ->enabled ()) {
315- if (! isInISR () ) LOG_LV1 (" HwPWM" , " attempt to release ownership when PWM peripheral is still enabled" );
318+ if (thread_mode ) LOG_LV1 (" HwPWM" , " attempt to release ownership when PWM peripheral is still enabled" );
316319 return false ; // if it's enabled, do not allow ownership to be released, even with no pins in use
317320 }
318321
0 commit comments