#pragma once
#include "main.h"
#include "ad9833.h"
#include "mcp41x.h"
#include "ltc2631.h"
#include "ctrl_app_defs.h"

typedef struct
{
    uint32_t frequency;
    uint16_t amplitude;
    int16_t offset;
    uint16_t phase;
    uint8_t duty;
    uint8_t link;
    bool_t enabled;
} pwm_settings_t;

typedef struct
{
    uint32_t frequency;
    uint16_t amplitude;
    int16_t offset;
    uint16_t phase;
    uint8_t wave;
    uint8_t link;
    uint8_t enabled;
} dds_settings_t;

typedef struct
{
    GPIO_TypeDef *port;
    uint16_t pin;
} led_handle_t;

typedef struct FG_handle_s
{
    ad9833_handle_t hdds;
    ltc2631_handle_t hoffs;
    mcp41x_handle_t hampl;
    led_handle_t hled;
} dds_handle_t;

typedef uint8_t timer_handle_t;
typedef struct
{
    timer_handle_t hpwm;
    ltc2631_handle_t hoffs;
    mcp41x_handle_t hampl;
    led_handle_t hled;
} pwm_handle_t;

typedef struct
{
    GEN_type_t const type;
} signal_gen_t;

typedef struct
{
    signal_gen_t *next;
    signal_gen_t *prev;
} link_t;

typedef struct
{
    signal_gen_t super;
    DDS_channel_t const dds_ch;
    dds_settings_t settings;
    dds_handle_t handle;
    link_t link;
} dds_gen_t;

typedef struct
{
    signal_gen_t super;
    PWM_channel_t const pwm_ch;
    pwm_settings_t settings;
    pwm_handle_t handle;
    link_t link;
} pwm_gen_t;

typedef struct
{
    uint8_t freq_focus_digit;
    uint8_t ampl_focus_digit;
    uint8_t offs_focus_digit;
    uint8_t phas_focus_digit;
    uint8_t duty_focus_digit;

    signal_gen_t *curr_gen;

    GEN_channel_t curr_channel;
    STATE_layout_t curr_state_lay;
    STATE_button_t curr_state_btn;

    // uint8_t isChannelChange;
    // uint8_t isGraphChange;
    // uint8_t isValueChange;
    // uint8_t isButtonChange;
    LAY_update_t disp_update;
    uint8_t button_blink;
    uint8_t timer_blink[DISP_BTN_MAX];

    LAY_dispBtn_t last_key;

} APP_data_t;
