//
// WARNING: DO NOT EDIT THIS FILE
//   This file has been generated from the target's JSON hardware description
//

#include "stm32_gpio.h"

static const stm32_adc_input_t _ADC_inputs[] = {
  {
    // LH
    // ADC_INPUT_STICK,
    nullptr,
    0,
    0,
    0 // normal
  },
  {
    // LV
    // ADC_INPUT_STICK,
    nullptr,
    0,
    1,
    1 // inverted
  },
  {
    // RV
    // ADC_INPUT_STICK,
    nullptr,
    0,
    2,
    0 // normal
  },
  {
    // RH
    // ADC_INPUT_STICK,
    nullptr,
    0,
    3,
    1 // inverted
  },
  {
    // P1
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    4,
    1 // inverted
  },
  {
    // P2
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    5,
    0 // normal
  },
  {
    // P3
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    6,
    1 // inverted
  },
  {
    // SL1
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    7,
    0 // normal
  },
  {
    // SL2
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    8,
    1 // inverted
  },
  {
    // SL3
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    11,
    1 // inverted
  },
  {
    // SL4
    // ADC_INPUT_FLEX,
    nullptr,
    0,
    10,
    1 // inverted
  },
  {
    // JSx
    // ADC_INPUT_FLEX,
    GPIOF,
    LL_GPIO_PIN_8,
    6,
    0 // normal
  },
  {
    // JSy
    // ADC_INPUT_FLEX,
    GPIOF,
    LL_GPIO_PIN_9,
    7,
    0 // normal
  },
  {
    // VBAT
    // ADC_INPUT_VBAT,
    nullptr,
    0,
    9,
    0 // normal
  },
  {
    // RTC_BAT
    // ADC_INPUT_RTC_BAT,
    nullptr,
    0,
    LL_ADC_CHANNEL_VBAT,
    0 // normal
  },
};

static const uint8_t _ADC_SPI_channels[] = {
    0, // LH
    1, // LV
    2, // RV
    3, // RH
    4, // P1
    5, // P2
    6, // P3
    7, // SL1
    8, // SL2
    9, // SL3
    10, // SL4
    13, // VBAT
};

static const uint8_t _ADC_MAIN_channels[] = {
    11, // JSx
    12, // JSy
};

static const uint8_t _ADC_EXT_channels[] = {
    14, // RTC_BAT
};

static const stm32_adc_t _ADC_adc[] = {
  {
    ADC3,
    DMA2,
    LL_DMA_CHANNEL_2,
    LL_DMA_STREAM_0,
    DMA2_Stream0_IRQn,
    _ADC_MAIN_channels,
    0,
    2,
    LL_ADC_SAMPLINGTIME_56CYCLES
  },
  {
    ADC1,
    nullptr,
    0,
    0,
    (IRQn_Type)-1,
    _ADC_EXT_channels,
    2,
    1,
    LL_ADC_SAMPLINGTIME_56CYCLES
  },
};

static const stm32_spi_adc_t _ADC_spi[] = {
  {
    .spi = {
      SPI4,
      GPIO_PIN(GPIOE, 2),
      GPIO_PIN(GPIOE, 5),
      GPIO_PIN(GPIOE, 6),
      GPIO_PIN(GPIOE, 4),
    },
    _ADC_SPI_channels,
    12
  },
};

extern "C" void DMA2_Stream0_IRQHandler (void)
{
  stm32_hal_adc_dma_isr(&_ADC_adc[0]);
}

extern "C" void ADC_IRQHandler()
{
  stm32_hal_adc_isr(&_ADC_adc[0]);
  stm32_hal_adc_isr(&_ADC_adc[1]);
 
}

#if defined(STM32H7)
extern "C" void ADC3_IRQHandler()
{
  stm32_hal_adc_isr(&_ADC_adc[0]);
  stm32_hal_adc_isr(&_ADC_adc[1]);
 
}
#endif

static const uint32_t _ADC_GPIOF_pins[] = {
    LL_GPIO_PIN_8,
    LL_GPIO_PIN_9,
};

static const stm32_adc_gpio_t _ADC_GPIOs[] = {
  { GPIOF, _ADC_GPIOF_pins, 2 },
};
