/**
 ******************************************************************************
 * This module was written for Afflatus Techtronics - Resource section
 *
 * @author  	: Ashwin
 *
 * Project	: led
 * @file	: main.c
 * @date	: Nov 19, 2011 9:42:24 PM
 *
 * Platform	: STM32F4-Discovery
 * Compiler	: CodeSourcery arm-2011.03-42-arm-none-eabi
 ******************************************************************************
 * @attention
 * This work is licensed under the Creative Commons
 * Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy 
 * of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or
 * send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain
 * View, California, 94041, USA.
 *
 * Copyright (C) 2011 
 * <a href="www.afflatustech.com">Afflatus Techtronics</a>
 * and <a href="www.ashwinvijayakumar.co.nr">Ashwin Vijayakumar</a>
 ******************************************************************************
 * @brief
 * Module Description:
 * (fill in a detailed description of the module’s function here).
 ******************************************************************************
 */

/** Includes section ----------------------------------------------------------
 * Add all #include here.
 * --------------------------------------------------------------------------*/

/** System headers ----------------------------------------------------------*/

/** Local headers -----------------------------------------------------------*/
#include "main.h"
#include "stm32f4_discovery.h"

/** typedef section (File scope) ----------------------------------------------
 * Add typedef's with file scope here.
 * Capitalization: Upper_Camel_Case.
 * Declare typedef's with project scope in main.h.
 * --------------------------------------------------------------------------*/

/** Constants section (File scope) --------------------------------------------
 * Add all constants with file scope here.
 * Capitalization: ALL_CAPS.
 * Note that all constants listed here are limited to this file scope.
 * For project wide scope, declare constants in main.h.
 * --------------------------------------------------------------------------*/

/** Macros section (File scope) -----------------------------------------------
 * Add all macros with file scope here.
 * Capitalization: ALL_CAPS.
 * Note that all macros listed here are limited to this file scope.
 * For project wide scope, declare macros in main.h.
 * --------------------------------------------------------------------------*/

/** Global variables section (File scope) -------------------------------------
 * Add global variables with file scope here. 
 * Capitalization: lower_case.
 * Declare them with 'static' keyword.
 * --------------------------------------------------------------------------*/
static GPIO_InitTypeDef  GPIO_InitStructure;

/** Global variables section (Project scope) ----------------------------------
 * PROJECT SCOPE G-VARIABLES ARE LIKE FORBIDDEN FRUIT. REFRAIN FROM USING THEM, 
 * DECLARE FILE SCOPE G-VARIABLES INSTEAD AND DEFINE GETTER/SETTER METHODS TO 
 * ACCESS THEM.
 * Add global variables with project scope here. 
 * Capitalization: lower_case.
 * Declare them without 'static' keyword.
 * Also declare these variables in main.h with 'extern' keyword.
 * --------------------------------------------------------------------------*/

/** Function prototypes section (File scope) ----------------------------------
 * Add prototypes for all functions with file scope here. 
 * Capitalization: lower_Camel_Case.
 * Declare them with 'static' keyword.
 * For functions with project scope, declare the function prototype in 
 * main.h without 'static' keyword 
 * --------------------------------------------------------------------------*/
static void delay(__IO uint32_t nCount);

/** Getter/setter method section (Project scope) ------------------------------
 * Define getter/setter methods to provide project scope global access to file 
 * scope global variables. (AVOID USING THESE IF YOU HAVE THROUGHPUT ISSUES).
 * Capitalization: get_Camel_Case/is_Camel_Case/set_Camel_Case.
 * Declare the prototype for these functions in main.h.
 * --------------------------------------------------------------------------*/

/**
 *******************************************************************************
 * @name        : int main(void)
 *     @retval  : int: return value description
 *     @param   : none
 * @author      : Ashwin
 * @date        : Nov 19, 2011 10:07:45 PM
 * @brief       : The project execution starts here
 * @note        : restrictions, odd modes
 *******************************************************************************
 */

int
main(void)
{
  /* GPIOD Peripheral clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  while(1)
    {
      GPIO_SetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
      delay(0x0FFFF);
      GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
      delay(0x0FFFF);
    }

  return (0);
}

/** END OF main ******************** Copyright (C) 2011 Afflatus Techtronics */

/**
 ******************************************************************************
 * MOD: For functions with project scope, remove 'static' keyword and declare
 * prototype in main.h
 * ----------------------------------------------------------------------------
 * @name        : delay
 *     @retval  : void
 *     @param   : A 32bit unsigned integer
 * @author      : Ashwin
 * @date        : Nov 19, 2011 10:11:11 PM
 * @brief       : Blocks the code execution for nCount iterations
 * @note        : Note that nCount != machine cycle count, this is a random
 *              : amount of delay. Use hardware timers to get precise delay.
 ******************************************************************************
 */

static void
delay(uint32_t nCount)
{
  while(nCount--)
  {
  }
}

/** END OF delay ******************* Copyright (C) 2011 Afflatus Techtronics */


/** END OF FILE ******************** Copyright (C) 2011 Afflatus Techtronics */
