/**
 * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
 * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
 * @cliArgs --device "MSPM0L130X" --package "VQFN-32(RHB)" --part "Default" --product "mspm0_sdk@1.30.00.03"
 * @versions {"tool":"1.19.0+3426"}
 */

/**
 * Import the modules used in this configuration.
 */
const ADC12   = scripting.addModule("/ti/driverlib/ADC12", {}, false);
const ADC121  = ADC12.addInstance();
const GPIO    = scripting.addModule("/ti/driverlib/GPIO", {}, false);
const GPIO1   = GPIO.addInstance();
const GPIO2   = GPIO.addInstance();
const GPIO3   = GPIO.addInstance();
const GPIO4   = GPIO.addInstance();
const SYSCTL  = scripting.addModule("/ti/driverlib/SYSCTL");
const SYSTICK = scripting.addModule("/ti/driverlib/SYSTICK");
const TIMER   = scripting.addModule("/ti/driverlib/TIMER", {}, false);
const TIMER1  = TIMER.addInstance();
const UART    = scripting.addModule("/ti/driverlib/UART", {}, false);
const UART1   = UART.addInstance();

/**
 * Write custom configuration values to the imported modules.
 */
const gate7  = system.clockTree["MFPCLKGATE"];
gate7.enable = true;

ADC121.$name                             = "ADC_VOLTAGE";
ADC121.repeatMode                        = true;
ADC121.adcMem0_name                      = "ADC_CH0";
ADC121.interruptPriority                 = "0";
ADC121.sampClkSrc                        = "DL_ADC12_CLOCK_ULPCLK";
ADC121.sampleTime0                       = "2us";
ADC121.sampClkDiv                        = "DL_ADC12_CLOCK_DIVIDE_8";
ADC121.configureDMA                      = true;
ADC121.enabledDMATriggers                = ["DL_ADC12_DMA_MEM0_RESULT_LOADED"];
ADC121.sampCnt                           = 1;
ADC121.adcMem0chansel                    = "DL_ADC12_INPUT_CHAN_2";
ADC121.DMA_CHANNEL.$name                 = "DMA_CH0";
ADC121.DMA_CHANNEL.addressMode           = "f2b";
ADC121.DMA_CHANNEL.srcLength             = "HALF_WORD";
ADC121.DMA_CHANNEL.dstLength             = "HALF_WORD";
ADC121.DMA_CHANNEL.configureTransferSize = true;
ADC121.DMA_CHANNEL.transferMode          = "FULL_CH_REPEAT_SINGLE";
ADC121.DMA_CHANNEL.interruptPriority     = "1";
ADC121.DMA_CHANNEL.transferSize          = 40;
ADC121.adcPin2Config.$name               = "ti_driverlib_gpio_GPIOPinGeneric0";

const Board = scripting.addModule("/ti/driverlib/Board", {}, false);

GPIO1.$name                         = "Gray_Address";
GPIO1.associatedPins.create(3);
GPIO1.associatedPins[0].$name       = "P0";
GPIO1.associatedPins[0].pin.$assign = "PA15";
GPIO1.associatedPins[1].$name       = "P1";
GPIO1.associatedPins[1].pin.$assign = "PA14";
GPIO1.associatedPins[2].$name       = "P2";
GPIO1.associatedPins[2].pin.$assign = "PA13";

GPIO2.$name                         = "MOTOR";
GPIO2.associatedPins.create(4);
GPIO2.associatedPins[0].$name       = "A1";
GPIO2.associatedPins[0].pin.$assign = "PA6";
GPIO2.associatedPins[1].$name       = "A2";
GPIO2.associatedPins[1].pin.$assign = "PA7";
GPIO2.associatedPins[2].$name       = "B1";
GPIO2.associatedPins[2].pin.$assign = "PA8";
GPIO2.associatedPins[3].$name       = "B2";
GPIO2.associatedPins[3].pin.$assign = "PA9";

GPIO3.$name                              = "KEY";
GPIO3.associatedPins.create(2);
GPIO3.associatedPins[0].direction        = "INPUT";
GPIO3.associatedPins[0].$name            = "IN1";
GPIO3.associatedPins[0].polarity         = "FALL";
GPIO3.associatedPins[0].internalResistor = "PULL_UP";
GPIO3.associatedPins[0].interruptEn      = true;
GPIO3.associatedPins[0].pin.$assign      = "PA18";
GPIO3.associatedPins[1].$name            = "IN2";
GPIO3.associatedPins[1].direction        = "INPUT";
GPIO3.associatedPins[1].interruptEn      = true;
GPIO3.associatedPins[1].polarity         = "FALL";
GPIO3.associatedPins[1].internalResistor = "PULL_UP";
GPIO3.associatedPins[1].pin.$assign      = "PA17/OPA1.IN0-";

GPIO4.$name                         = "LED";
GPIO4.associatedPins.create(2);
GPIO4.associatedPins[0].$name       = "Key";
GPIO4.associatedPins[0].pin.$assign = "PA16";
GPIO4.associatedPins[1].$name       = "Err";
GPIO4.associatedPins[1].pin.$assign = "PA12";

SYSCTL.MFCLKEn     = true;
SYSCTL.clockTreeEn = true;

SYSTICK.periodEnable      = true;
SYSTICK.period            = 32000;
SYSTICK.interruptEnable   = true;
SYSTICK.systickEnable     = true;
SYSTICK.interruptPriority = "1";

TIMER1.$name             = "TIMER_0";
TIMER1.timerMode         = "PERIODIC";
TIMER1.interrupts        = ["ZERO"];
TIMER1.interruptPriority = "0";
TIMER1.timerPeriod       = "50 us";

UART1.$name                    = "UART_0";
UART1.peripheral.rxPin.$assign = "PA22";
UART1.peripheral.txPin.$assign = "PA23";
UART1.txPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric3";
UART1.rxPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric4";

/**
 * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
 * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
 * re-solve from scratch.
 */
ADC121.peripheral.$suggestSolution             = "ADC0";
ADC121.peripheral.adcPin2.$suggestSolution     = "PA25";
ADC121.DMA_CHANNEL.peripheral.$suggestSolution = "DMA_CH0";
Board.peripheral.$suggestSolution              = "DEBUGSS";
Board.peripheral.swclkPin.$suggestSolution     = "PA20";
Board.peripheral.swdioPin.$suggestSolution     = "PA19";
TIMER1.peripheral.$suggestSolution             = "TIMG0";
UART1.peripheral.$suggestSolution              = "UART0";
