| 657 | } |
| 658 | |
| 659 | int detach_handler(isr_handle_t& handle) FL_NOEXCEPT { |
| 660 | if (!handle.is_valid() || handle.platform_id != SAMD_PLATFORM_ID) { |
| 661 | FL_WARN("detachHandler: invalid handle"); |
| 662 | return -1; // Invalid handle |
| 663 | } |
| 664 | |
| 665 | samd_isr_handle_data* handle_data = static_cast<samd_isr_handle_data*>(handle.platform_handle); |
| 666 | if (!handle_data) { |
| 667 | FL_WARN("detachHandler: null handle data"); |
| 668 | return -1; // Invalid handle |
| 669 | } |
| 670 | |
| 671 | if (handle_data->is_timer) { |
| 672 | // Disable timer interrupt |
| 673 | Tc* timer = handle_data->timer_instance; |
| 674 | if (timer) { |
| 675 | timer->COUNT16.INTENCLR.reg = TC_INTENCLR_MC0; |
| 676 | timer->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE; |
| 677 | tc_wait_sync(timer); |
| 678 | |
| 679 | NVIC_DisableIRQ(handle_data->timer_irq); |
| 680 | free_timer(handle_data->timer_index); |
| 681 | } |
| 682 | } else { |
| 683 | // Disable EIC interrupt |
| 684 | if (handle_data->eic_channel < MAX_EIC_CHANNELS) { |
| 685 | EIC->INTENCLR.reg = (1UL << handle_data->eic_channel); |
| 686 | free_eic_channel(handle_data->eic_channel); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | delete handle_data; // ok bare allocation (C API teardown) |
| 691 | handle.platform_handle = nullptr; |
| 692 | handle.platform_id = 0; |
| 693 | |
| 694 | FL_DBG("Handler detached"); |
| 695 | return 0; // Success |
| 696 | } |
| 697 | |
| 698 | int enable_handler(const isr_handle_t& handle) FL_NOEXCEPT { |
| 699 | if (!handle.is_valid() || handle.platform_id != SAMD_PLATFORM_ID) { |
nothing calls this directly
no test coverage detected