@@ -273,14 +273,15 @@ uint8_t HardwarePWM::freeChannelCount(void) const
273
273
// returns true ONLY when (1) no PWM channel has a pin, and (2) the owner token is nullptr
274
274
bool HardwarePWM::takeOwnership (uint32_t token)
275
275
{
276
+ bool const thread_mode = !isInISR ();
276
277
277
278
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)" );
279
280
return false ;
280
281
}
281
282
282
283
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)" );
284
285
return false ;
285
286
}
286
287
@@ -296,23 +297,25 @@ bool HardwarePWM::takeOwnership(uint32_t token)
296
297
// returns true ONLY when (1) no PWM channel has a pin attached, and (2) the owner token matches
297
298
bool HardwarePWM::releaseOwnership (uint32_t token)
298
299
{
300
+ bool const thread_mode = !isInISR ();
301
+
299
302
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)" );
301
304
return false ;
302
305
}
303
306
304
307
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" );
306
309
return false ;
307
310
}
308
311
309
312
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" );
311
314
return false ;
312
315
}
313
316
314
317
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" );
316
319
return false ; // if it's enabled, do not allow ownership to be released, even with no pins in use
317
320
}
318
321
0 commit comments