% let Common   = system.getScript("/driverlib/Common.js");
//*****************************************************************************
//
// GPIO Configurations
//
//*****************************************************************************
% let raData = system.resourceAllocation.data
void GPIO_init(){
% if(!Common.isAllocationOff()){
% for (let context of raData.contexts)
% {
%    let module = context.modules.find(x => x.moduleName === '/driverlib/gpio.js')
% if ((module != null) && ((system.context == context.contextName) || (system.context == "CPU1")))
%{
%   for(var i = 0; i < module.instances.length; i++) 
%   {
%      var instance = module.instances[i];
	`instance.allocationName`_init();
%   }
% }
% }
% }
% else {
% var module = Common.getModuleForCore("/driverlib/gpio.js", "CPU1");
%if (module != null)
%{
%   for(var i = 0; i < module.$instances.length; i++) 
%   {
%      var instance = module.$instances[i];
	`instance.$name`_init();
%   }
% }
% }
}
%
% if(Common.isAllocationOff()){
% var module = Common.getModuleForCore("/driverlib/gpio.js", "CPU1");
%if (module != null)
%{
%   for(var i = 0; i < module.$instances.length; i++) {
	% var instance = module.$instances[i];

void `instance.$name`_init(){
	% if (Common.isContextCPU1()){
		% if (instance.analogMode == "GPIO_ANALOG_ENABLED"){
	GPIO_setAnalogMode(`instance.$name`, `instance.analogMode`);
		%} else {
%if(instance.padConfig == "STD")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_`instance.padConfig`);
%}
%else if(instance.padConfig == "PULLUP")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP);
%}
%else if(instance.padConfig == "INVERT")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_INVERT);
%}
%else if(instance.padConfig == "PULLUP_INVERT")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP | GPIO_PIN_TYPE_INVERT);
%}
%else if(instance.padConfig == "OD")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_`instance.padConfig`);
%}
%else if(instance.padConfig == "OD_PULLUP")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_PULLUP);
%}
%else if(instance.padConfig == "OD_INVERT")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_INVERT);
%}
%else if(instance.padConfig == "OD_PULLUP_INVERT")
%{
	GPIO_setPadConfig(`instance.$name`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_PULLUP | GPIO_PIN_TYPE_INVERT);
%}
	GPIO_setQualificationMode(`instance.$name`, `instance.qualMode`);
	GPIO_setControllerCore(`instance.$name`, `instance.controllerCore`);
		%}
%}
%if(system.context == instance.controllerCore.split("_")[2]){
	GPIO_setDirectionMode(`instance.$name`, `instance.direction`);
	% if (instance.writeInitialValue){
	GPIO_writePin(`instance.$name`, `instance.initialValue`);
	% }
%}
}
	%}
%}
%}
% else{
% for (let context of raData.contexts)
% {
%    let module = context.modules.find(x => x.moduleName === '/driverlib/gpio.js')
% if (module != null){
%   for(var i = 0; i < module.instances.length; i++) {
	% var instance = module.instances[i];
	% var instanceArgs = instance.requiredArgs
	% if (Common.isContextCPU1()){

void `instance.allocationName`_init(){
		% if (instanceArgs.analogMode == "GPIO_ANALOG_ENABLED"){
	GPIO_setAnalogMode(`instance.allocationName`, `instanceArgs.analogMode`);
		%} else {
			%if(instanceArgs.padConfig == "STD")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_`instanceArgs.padConfig`);
			%}
			%else if(instanceArgs.padConfig == "PULLUP")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP);
			%}
			%else if(instanceArgs.padConfig == "INVERT")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_INVERT);
			%}
			%else if(instanceArgs.padConfig == "PULLUP_INVERT")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_STD | GPIO_PIN_TYPE_PULLUP | GPIO_PIN_TYPE_INVERT);
			%}
			%else if(instanceArgs.padConfig == "OD")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_`instanceArgs.padConfig`);
			%}
			%else if(instanceArgs.padConfig == "OD_PULLUP")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_PULLUP);
			%}
			%else if(instanceArgs.padConfig == "OD_INVERT")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_INVERT);
			%}
			%else if(instanceArgs.padConfig == "OD_PULLUP_INVERT")
			%{
	GPIO_setPadConfig(`instance.allocationName`, GPIO_PIN_TYPE_OD | GPIO_PIN_TYPE_PULLUP | GPIO_PIN_TYPE_INVERT);
			%}
	GPIO_setQualificationMode(`instance.allocationName`, `instanceArgs.qualMode`);
	GPIO_setControllerCore(`instance.allocationName`, `instanceArgs.controllerCore`);
		%}
	% }
	%if(system.context == context.contextName){
		%if(!Common.isContextCPU1()){

void `instance.allocationName`_init(){
		%}
		% let cpuModule = system.modules["/driverlib/gpio.js"]
			% if(cpuModule){
				%let cpuInstances = cpuModule.$instances
				%let cpuConfig = cpuInstances.find(x => x.$allocation === instance.allocationName)
				%if (cpuConfig){
	GPIO_setDirectionMode(`cpuConfig.$allocation`, `cpuConfig.direction`);
					% if (cpuConfig.writeInitialValue){
	GPIO_writePin(`cpuConfig.$allocation`, `cpuConfig.initialValue`);
					% }
				% }
			%}
}
	%}
	% else if(Common.isContextCPU1()){
}
	%}
%}
%}
%}
%}
