/// @file platforms.cpp
/// Platform-specific functions and variables

/// Disables pragma messages and warnings
#define FASTLED_INTERNAL
#include "fl/stl/compiler_control.h"
#include "platforms/is_platform.h"

// Removed duplicate weak definition of timer_millis for ATtiny1604.
// The variable is already defined in avr_millis_timer_null_counter.hpp when needed,
// so redefining it here caused multiple-definition linkage errors.

// Provide a single consolidated weak timer_millis symbol for AVR tiny/x-y parts
// whose cores do not export it, satisfying MS_COUNTER binding in led_sysdefs_avr.h.
// This complements avr_millis_timer_null_counter.hpp when that TU is not built.
#if defined(FL_IS_AVR)
#  if defined(FL_IS_AVR_ATTINY_MODERN) || defined(ARDUINO_attinyxy6)
#    ifdef __cplusplus
extern "C" {
#    endif
FL_LINK_WEAK volatile unsigned long timer_millis = 0;
#    ifdef __cplusplus
}
#    endif
#  endif
#endif

// Interrupt handlers cannot be defined in the header.
// They must be defined as C functions, or they won't
// be found (due to name mangling), and thus won't
// override any default weak definition.
#if defined(FL_IS_NRF52)

    #include "platforms/arm/is_arm.h"  // ok platform headers
    #include "platforms/arm/nrf52/led_sysdefs_arm_nrf52.h"  // ok platform headers
    #include "platforms/arm/nrf52/arbiter_nrf52.h"  // ok platform headers

    fl::u32 isrCount;

    FL_EXTERN_C_BEGIN
            // NOTE: Update platforms.cpp in root of FastLED library if this changes        
            #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE0)
                void PWM0_IRQHandler(void) { ++isrCount; PWM_Arbiter<0>::isr_handler(); }
            #endif
            #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE1)
                void PWM1_IRQHandler(void) { ++isrCount; PWM_Arbiter<1>::isr_handler(); }
            #endif
            #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE2)
                void PWM2_IRQHandler(void) { ++isrCount; PWM_Arbiter<2>::isr_handler(); }
            #endif
            #if defined(FASTLED_NRF52_ENABLE_PWM_INSTANCE3)
                void PWM3_IRQHandler(void) { ++isrCount; PWM_Arbiter<3>::isr_handler(); }
            #endif
    FL_EXTERN_C_END

#endif // defined(FL_IS_NRF52)
