#include "heat.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"

void heat_init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure = {
        .GPIO_Pin = PIN_HEAT,
        .GPIO_Mode = GPIO_Mode_OUT,
        .GPIO_OType = GPIO_OType_PP,
        .GPIO_Speed = GPIO_Speed_2MHz,
        .GPIO_PuPd = GPIO_PuPd_NOPULL,
    };

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    GPIO_Init(PORT_HEAT, &GPIO_InitStructure);
    heat_off();
}

void heat_on(void)
{
    GPIO_SetBits(PORT_HEAT, PIN_HEAT);
}

void heat_off(void)
{
    GPIO_ResetBits(PORT_HEAT, PIN_HEAT);
}

void heat_toggle(void)
{
    GPIO_ToggleBits(PORT_HEAT, PIN_HEAT);
}

void heat_loop(void)
{
    static uint32_t ms = 0;

    if (system_tick_cnt < (ms + 125)) {
        return;
    }
    ms = system_tick_cnt;

    heat_toggle();
}
