#include "SHAL.h"

int main() {

    SHAL_init();

    /*
    PIN(A11).setPinMode(PinMode::ALTERNATE_FUNCTION_MODE);
    PIN(A11).setAlternateFunction(GPIO_Alternate_Function::AF2);
    SHAL_TIM1.configurePWM(SHAL_Timer_Channel::CH4, 1000, 8000, 4000);
    SHAL_TIM1.start();
    */

    PIN(A11).setPinMode(PinMode::OUTPUT_MODE);

    //PIN(B4).setPinMode(PinMode::OUTPUT_MODE);
    //PIN(B4).setHigh();

    RCC->AHBENR |= RCC_AHBENR_GPIOBEN;

    /* Small delay to ensure clock is stable (optional but safe) */
    for (volatile int i = 0; i < 1000; i++);

    /* 2. Set PB4 as general purpose output */
    // MODER: 2 bits per pin → pin 4 → bits [9:8]
    GPIOB->MODER &= ~(3U << (4 * 2));   // Clear mode bits
    GPIOB->MODER |=  (1U << (4 * 2));   // Set as output (01)

    /* 3. Set PB4 HIGH */
    GPIOB->BSRR = (1U << 4);  // Atomic set

    PIN(A11).setHigh();

    while (true) {


        PIN(A11).toggle();
        SHAL_delay_us(10);
        PIN(A11).toggle();

    }
}