2013-10-14

Olimex Plug & Play, Mix & Match 7 Segment LED incremental testing notes

// *** 7 Segment LED - HC595 Serial in parallel out shift register with output latch ***

#define MAX_HC595_PIN_NUMBER 4 // 2013oct14

portPinArray Hc595SerialInClockPulsePortPinArray = {PORT2, PIN8};
portPinArray Hc595SerialInDataPortPinArray       = {PORT2, PIN9};
portPinArray Hc595OutputLatchEnablePortPinArray  = {PORT2, PIN10};
portPinArray Hc595ReservedPortPinArray           = {PORT2, PIN11};

portPinArrayPointerArray Hc595PortPinArrayPointerArray[MAX_HC595_PIN_NUMBER] = \
  {&Hc595SerialInClockPulsePortPinArray, &Hc595SerialInDataPortPinArray, \
   &Hc595OutputLatchEnablePortPinArray, &Hc595ReservedPortPinArray};


// ***********************************************************************
// Program  - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author   - TL Fong
// Build    - 2013.10.14.03
// Date     - 2013oct14hkt1123
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
//            Olimex EKG board (SHIELD-EKG/EMG Rev B, Bulgaria 2011)
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

#include "test050.h" // main tests

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{
// *** Completed tests ***
// testLedKey01(); // Tested OK 2013oct14

// *** Current tests ***
test7segmentLed01();

// *** End of tests ***
return 0;
}

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// test050.h 2013oct13hkt2206
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "olimex050.h"

void testLedKey01() // tested OK 2013oct13
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as ooutput
blinkLed0501(PortPinArrayP09); // blink led

// *** Olimex test only - setup I/O pins for testing ***
setupOlimexGpio050(); // setup Olimex GPIO pins as output and input

// *** Olimex test only - blink single LED and run all LEDs***
blinkOlimexLed(LED_7, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_6_TIMES); // blink one Led
runOlimexLeds();  // sequentially blink all 8 Leds

// *** Olimex test only - echo key by led ***
echoOlimexKeyByLed(KEY_1, LED_1); // echo Olimex key by led
echoOlimexKeyByLed(KEY_2, LED_2); // echo Olimex key by led
echoOlimexKeyByLed(KEY_1, LED_3); // echo Olimex key by led

// *** For all mcu boards, given mcu board struct, echo key by led ***
echoKeyByLed0504(OlimexLpc1114DevBoardStruct, KEY_1, LED_5); // given mcuboard struct, echo key by led
}

void test7segmentLed01() //
{
        // *** system self diagnostic test - blink LED P09 ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as output
blinkLed0501(PortPinArrayP09); // blink led

// *** setup Hc595 output pins ***
setupAllGpioPinsOutputLow050(Hc595PortPinArrayPointerArray, MAX_HC595_PIN_NUMBER);

// *** Toggle HC595 control pins ***
blinkLed0501(Hc595SerialInClockPulsePortPinArray);
blinkLed0501(Hc595SerialInDataPortPinArray);
blinkLed0501(Hc595OutputLatchEnablePortPinArray);
blinkLed0501(Hc595ReservedPortPinArray);
}

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// config050.h - 2013oct14hk0922
// ***********************************************************************

#include "lpc11xx_syscon.h"
#include "lpc11xx_gpio.h"
#include "lpc11xx_iocon.h"

#ifndef CONFIG_HEADER_SEEN
#define CONFIG_HEADER_SEEN

// *** Logic level ***

#define LOW 0
#define HIGH 1

#define LOW_LEVEL 0
#define HIGH_LEVEL 1

#define LOGIC_LOW_LEVEL 0
#define LOGIC_HIGH_LEVEL 1

typedef int logicLevelValue;

logicLevelValue LogicLevelLow = 0;
logicLevelValue LogicLevelHigh = 1;

// *** GPIO direction ***

#define INPUT_DIRECTION 0
#define OUTPUT_DIRECTION 1

typedef int directionValue;

directionValue InputDirection = 0;
directionValue OutputDirection = 1;

// *** GPIO port number, pin number, port/pin number ***

#define PORT0 0
#define PORT1 1
#define PORT2 2
#define PORT3 3

#define PIN0 0
#define PIN1 1
#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
#define PIN8 8
#define PIN9 9
#define PIN10 10
#define PIN11 11

typedef int portNumber;
portNumber Port0 = 0;
portNumber Port1 = 1;
portNumber Port2 = 2;
portNumber Port3 = 3;

typedef int pinNumber;
pinNumber Pin0  =  0;
pinNumber Pin1  =  1;
pinNumber Pin2  =  2;
pinNumber Pin3  =  3;
pinNumber Pin4  =  4;
pinNumber Pin5  =  5;
pinNumber Pin6  =  6;
pinNumber Pin7  =  7;
pinNumber Pin8  =  8;
pinNumber Pin9  =  9;
pinNumber Pin10 = 10;
pinNumber Pin11 = 11;

typedef const int portPinNumber;

portPinNumber Pio05  = 5;
portPinNumber Pio08  = 8;
portPinNumber Pio09  = 9;

portPinNumber Rpio11 = 11;
portPinNumber Rpio12 = 12;
portPinNumber Pio19  = 19;
portPinNumber Rpio18 = 18;
portPinNumber Pio110  = 110;

// *** LED, key, 7-segment LED digit number ***

typedef const int deviceNumber;

#define LED1 1
#define LED2 2
#define LED3 3
#define LED4 4
#define LED5 5
#define LED6 6
#define LED7 7
#define LED8 8

#define LED_1 1
#define LED_2 2
#define LED_3 3
#define LED_4 4
#define LED_5 5
#define LED_6 6
#define LED_7 7
#define LED_8 8

#define KEY_1 1
#define KEY_2 2
#define KEY_3 3
#define KEY_4 4
#define KEY_5 5

#define MAX_DEVICE_NUMBER 5
#define MAX_LED_NUMBER    5
#define MAX_KEY_NUMBER    5
#define MAX_PWM_NUMBER    5

#define DIGIT_0 0
#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 3
#define DIGIT_4 4
#define DIGIT_5 5
#define DIGIT_6 6
#define DIGIT_7 7
#define DIGIT_8 8
#define DIGIT_9 9

// *** Port pin array and port pin array pinters ***

#define PORT_INDEX 0
#define PIN_INDEX 1

typedef int portPinArray[2];

typedef portPinArray *portPinArrayPointerArray[MAX_DEVICE_NUMBER];

// *** Mcu board struct ***

typedef struct
 {
portPinArrayPointerArray *LedPortPinArrayPointerArray;
portPinArrayPointerArray *KeyPortPinArrayPointerArray;
 } mcuBoardStruct;

// *** Generic port pin array ***

portPinArray PortPinArrayP04 = {PORT0, PIN4};
portPinArray PortPinArrayP05 = {PORT0, PIN5};
portPinArray PortPinArrayP09 = {PORT0, PIN9};
portPinArray PortPinArrayP14 = {PORT1, PIN4}; // KEY2
portPinArray PortPinArrayP24 = {PORT2, PIN4};
portPinArray PortPinArrayP25 = {PORT2, PIN5}; // USB D- do NOT use
portPinArray PortPinArrayP26 = {PORT2, PIN6}; // USB D+ do NOT use
portPinArray PortPinArrayP27 = {PORT2, PIN7};
portPinArray PortPinArrayP29 = {PORT2, PIN9}; // KEY1
portPinArray PortPinArrayP30 = {PORT3, PIN0}; // LED1
portPinArray PortPinArrayP34 = {PORT3, PIN4}; // replacing P24
portPinArray PortPinArrayP35 = {PORT3, PIN5}; // replacing P25

// *** Olimex LED port pin array ***

#define MAX_OLIMEX_LED_PIN_NUMBER 8 // 2013oct11

#define SCLK_INDEX 0
#define DIN_INDEX 1
#define LATCH_INDEX 2

int SizeOfPortPinArrayPointer = sizeof(PortPinArrayP04);

portPinArray OlimexBoardLedPortPinArray1 = {PORT3, PIN0}; // LED 0 2013oct11
portPinArray OlimexBoardLedPortPinArray2 = {PORT3, PIN1}; // LED 1 2013oct11
portPinArray OlimexBoardLedPortPinArray3 = {PORT3, PIN2}; // LED 2 2013oct11
portPinArray OlimexBoardLedPortPinArray4 = {PORT3, PIN3}; // LED 3 2013oct11
portPinArray OlimexBoardLedPortPinArray5 = {PORT3, PIN4}; // LED 4 2013oct11
portPinArray OlimexBoardLedPortPinArray6 = {PORT3, PIN5}; // LED 5 2013oct11
portPinArray OlimexBoardLedPortPinArray7 = {PORT2, PIN6}; // LED 6 2013oct11
portPinArray OlimexBoardLedPortPinArray8 = {PORT2, PIN7}; // LED 7 2013oct11

portPinArrayPointerArray OlimexBoardLedPortPinArrayPointerArray[MAX_OLIMEX_LED_PIN_NUMBER] = \
  {&OlimexBoardLedPortPinArray1, &OlimexBoardLedPortPinArray2, \
  &OlimexBoardLedPortPinArray3, &OlimexBoardLedPortPinArray4, \
  &OlimexBoardLedPortPinArray5, &OlimexBoardLedPortPinArray6, \
  &OlimexBoardLedPortPinArray7, &OlimexBoardLedPortPinArray8};

// *** Olimex Key port pin array ***

#define MAX_OLIMEX_KEY_PIN_NUMBER 2

portPinArray OlimexBoardKeyPortPinArray1 = {PORT2, PIN9};
portPinArray OlimexBoardKeyPortPinArray2 = {PORT1, PIN4};

portPinArrayPointerArray OlimexBoardKeyPortPinArrayPointerArray[MAX_OLIMEX_KEY_PIN_NUMBER] = \
    {&OlimexBoardKeyPortPinArray1, &OlimexBoardKeyPortPinArray2};

// *** Olimex LPC1114 Board Struct ***

mcuBoardStruct OlimexLpc1114DevBoardStruct = {OlimexBoardLedPortPinArrayPointerArray, \
OlimexBoardKeyPortPinArrayPointerArray};


// *** 7 Segment LED - HC595 Serial in parallel out shift register with output latch ***

#define MAX_HC595_PIN_NUMBER 4 // 2013oct14

portPinArray Hc595SerialInClockPulsePortPinArray = {PORT2, PIN8};
portPinArray Hc595SerialInDataPortPinArray       = {PORT2, PIN9};
portPinArray Hc595OutputLatchEnablePortPinArray  = {PORT2, PIN10};
portPinArray Hc595ReservedPortPinArray           = {PORT2, PIN11};

portPinArrayPointerArray Hc595PortPinArrayPointerArray[MAX_HC595_PIN_NUMBER] = \
  {&Hc595SerialInClockPulsePortPinArray, &Hc595SerialInDataPortPinArray, \
   &Hc595OutputLatchEnablePortPinArray, &Hc595ReservedPortPinArray};


#endif /* CONFIG_HEADER_SEEN */

// ***********************************************************************
// * End *
// ***********************************************************************



// ***********************************************************************
// gpio050.h 2013oct14hkt0922
// ***********************************************************************

#ifndef GPIO050_HEADER_SEEN
#define GPIO050_HEADER_SEEN

#include "lpc11xx_syscon.h"
#include "lpc11xx_gpio.h"
#include "lpc11xx_iocon.h"
#include "config050.h"
#include "timer050.h"

// *** GPIO struct pointer ***

typedef GPIO_TypeDef *gpioStructPointerArray[4];
gpioStructPointerArray CmsisGpioStructPointerArray = {LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3};

GPIO_TypeDef *getGpioStructPointer(int portNumber)
{
 GPIO_TypeDef *gpioStructPointer;
 gpioStructPointer =  CmsisGpioStructPointerArray[portNumber];
 return gpioStructPointer;
}

typedef struct
{
 GPIO_TypeDef *GpioStructPointer;
 int PinNumber;
} gpioPortStructPinStruct;

gpioPortStructPinStruct *getGpioPortStructPinStructPointer(portNumber portNumber, \
pinNumber pinNumber) // *** To be tested ***
  {
 gpioPortStructPinStruct *gpioPortStructPinStruct;
 gpioPortStructPinStruct->GpioStructPointer = getGpioStructPointer(portNumber);
 gpioPortStructPinStruct->PinNumber = pinNumber;
 return gpioPortStructPinStruct;
  }

// *** GPIO functions ***

void setGpioDataPinInput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR  &= ~(1 << pinNumber);
}

void setGpioDataPinOutput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR |= (1 << pinNumber);
}

void setGpioDataPinLow(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA &= ~(1 << pinNumber);
}

void setGpioDataPinHigh(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA |= (1 << pinNumber);
}

void setGpioPinDirection(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, directionValue directionValue)
{
 if (directionValue == INPUT_DIRECTION)
  setGpioDataPinInput(gpio_struct_ptr, pinNumber);
 else
  setGpioDataPinOutput(gpio_struct_ptr, pinNumber);
}

void setGpioDataPin(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, logicLevelValue logicLevelValue)
{
 if (logicLevelValue == LOGIC_LOW_LEVEL)
  setGpioDataPinLow(gpio_struct_ptr, pinNumber);
 else
  setGpioDataPinHigh(gpio_struct_ptr, pinNumber);
}

logicLevelValue getGpioDataPinValue01(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 logicLevelValue logicLevelValue;

  int GpioDataPinMask = (1 << pinNumber);

  if ((gpio_struct_ptr->DATA  &= GpioDataPinMask) == GpioDataPinMask)
  logicLevelValue = HIGH;
 else
  logicLevelValue = LOW;

  return logicLevelValue;
}

logicLevelValue getGpioDataPinValue(portPinArrayPointerArray inputPortPinArrayPointerArray, int pinNumber)
{
 int portNumber;
 GPIO_TypeDef *gpioStructPointer;
 logicLevelValue logicLevelValue;

  portNumber = getPortNumber01(inputPortPinArrayPointerArray, pinNumber);
 gpioStructPointer = getGpioStructPointer(portNumber);
 pinNumber = getPinNumber01(inputPortPinArrayPointerArray, pinNumber);

  logicLevelValue = getGpioDataPinValue01(gpioStructPointer, pinNumber);

  return logicLevelValue;
}

portNumber getPortNumber(portPinArray portPinArray)
{
 int portNumber;
 portNumber = portPinArray[PORT_INDEX];
 return portNumber;
}

portNumber getPortNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
 int portNumber;
 portNumber = getPortNumber(*portPinArrayPointerArray[deviceNumber - 1]);
 return portNumber;
}

pinNumber getPinNumber(portPinArray portPinArray)
{
 int pinNumber;
 pinNumber = portPinArray[PIN_INDEX];
 return pinNumber;
}

pinNumber getPinNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
 int pinNumber;
 pinNumber = getPinNumber(*portPinArrayPointerArray[deviceNumber - 1]);
 return pinNumber;
}

// *** set up output pin ***

void initializeOutputPin01(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinLow (gpioStructPointer, pinNumber);
  }

void initializeOutputPin01High(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);
  }

void initializeOutputPin01Low(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinLow(gpioStructPointer, pinNumber);
  }

void initializeOneOutputPin(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01(portPinArray);

}

void initializeOneOutputPinHigh(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01High(portPinArray);
}

void initializeAllOutputPins(portPinArrayPointerArray outputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneOutputPin(outputPortPinArrayPointerArray, pinNumber);
  }
}

void initializeAllOutputPinsHigh(portPinArrayPointerArray outputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneOutputPinHigh(outputPortPinArrayPointerArray, pinNumber);
  }
}

// *** setup input pin ***

void initializeInputPin01(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinInput(gpioStructPointer, pinNumber);
}

void initializeOneInputPin(portPinArrayPointerArray outputPortPinArrayPointerArray, \
  deviceNumber deviceNumber)
{
 int portNumber;
 int pinNumber;
 GPIO_TypeDef *gpioStructPointer;

 portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
 gpioStructPointer = getGpioStructPointer(portNumber);
 pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

  setGpioDataPinInput(gpioStructPointer, pinNumber);
  }

void initializeAllInputPins(portPinArrayPointerArray inputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneInputPin(inputPortPinArrayPointerArray, pinNumber);
  }
}

void initializeAllInputPins40(portPinArrayPointerArray inputPortPinArrayPointerArray)
{
int pinNumber;
int maxPinNumber;

maxPinNumber = sizeof(inputPortPinArrayPointerArray) / sizeof(*inputPortPinArrayPointerArray);

for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
{
initializeOneInputPin(inputPortPinArrayPointerArray, pinNumber);
}
}

// *** Set GPIO output pin data value ***

void setGpioDataPinHigh01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;

pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);
}

void setGpioDataPinLow01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;

pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinLow(gpioStructPointer, pinNumber);
}

// *** Functions 050 ***

void setupGpioPinOutputLow050(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setupGpioPinOutput051(gpioStructPointer, pinNumber);
setGpioOutputPinLow051(gpioStructPointer, pinNumber);
  }

void setupGpioPinOutput051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR |= (1 << pinNumber);
}

void setGpioOutputPinHigh051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA |= (1 << pinNumber);
}

void setGpioOutputPinLow051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA &= ~(1 << pinNumber);
}

void setupAllGpioPinsOutputLow050(portPinArrayPointerArray portPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   setupPinOutputLow050(portPinArrayPointerArray, pinNumber);
  }
}

void setupPinOutputLow050(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01Low(portPinArray);
}

void setupGpioPinInput050(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinInput(gpioStructPointer, pinNumber);
}

void setupAllGpioPinsInput050(portPinArrayPointerArray portPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
 setupGpioPinInput051(portPinArrayPointerArray, pinNumber);
  }
}

void setupGpioPinInput051(portPinArrayPointerArray outputPortPinArrayPointerArray, \
 deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

setGpioDataPinInput(gpioStructPointer, pinNumber);
  }

void setupOlimexGpio050()
{
setupAllGpioPinsOutputLow050(OlimexBoardLedPortPinArrayPointerArray, MAX_OLIMEX_LED_PIN_NUMBER);
setupAllGpioPinsInput050(OlimexBoardKeyPortPinArrayPointerArray,  MAX_OLIMEX_KEY_PIN_NUMBER);
}

#endif /* GPIO050_HEADER_SEEN */

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// led050.h 2013oct14hkt0923
// ***********************************************************************

#include "config050.h"
#include "gpio050.h"
#include "timer050.h"

void blinkOneLed050(portPinArray ledPortPinArrayPointer, \
                    int onTime, int offTime, int blinkCount)
{
int count;
for (count = 0; count < blinkCount; count++)
  {
   setGpioDataPinLow01(ledPortPinArrayPointer);
   delayTenthSecond(onTime);
   setGpioDataPinHigh01(ledPortPinArrayPointer);
   delayTenthSecond(offTime);
  }
}

void blinkOneLed0501(portPinArrayPointerArray portPinArrayPointerArray, \
                     deviceNumber ledNumber, int onTime, int offTime, int blinkCount)
{
int count = 0;
portPinArray *ledPortPinArrayPointer;

ledPortPinArrayPointer = portPinArrayPointerArray[ledNumber - 1];

blinkOneLed050(ledPortPinArrayPointer, onTime, offTime, blinkCount);
}

void blinkAllLeds050(portPinArrayPointerArray ledPortPinArrayPointerArray, \
            int maxLedPinNumber, int onTime, int offTime, int repeatCount)
{
int ledNumber;

    for (ledNumber = 1; ledNumber < (maxLedPinNumber + 1); ledNumber++ )
    {
    blinkOneLed0501(ledPortPinArrayPointerArray, ledNumber, \
               onTime, offTime, repeatCount);
    }
}

void runOlimexLeds050(portPinArrayPointerArray ledPortPinArrayPointerArray, \
             int maxLedPinNumber, int onTime, int offTime, \
             int blinkCount, int sequenceCount)
{
setupAllGpioPinsOutputLow050(ledPortPinArrayPointerArray, maxLedPinNumber);

delayTime(ONE_HALF_SECOND);

int count;
for (count = 0; count < sequenceCount; count++)
{
blinkAllLeds050(ledPortPinArrayPointerArray, maxLedPinNumber, onTime, offTime, blinkCount);
}
}

void blinkLed0501(portPinArray ledPortPinArray)
{
// setupGpioPinOutputLow050(ledPortPinArray);

blinkOneLed050(ledPortPinArray, ON_ONE_HALF_SECOND, OFF_ONE_HALF_SECOND, \
     REPEAT_2_TIMES);
}

void echoKeyByLed0504(mcuBoardStruct mcuBoardStruct, int keyNumber, int ledNUmber)
{
setupAllGpioPinsOutputLow050(mcuBoardStruct.LedPortPinArrayPointerArray,  MAX_OLIMEX_LED_PIN_NUMBER);
setupAllGpioPinsInput050(mcuBoardStruct.KeyPortPinArrayPointerArray,  MAX_OLIMEX_KEY_PIN_NUMBER);

echoKeyByLed050(mcuBoardStruct.KeyPortPinArrayPointerArray, \
       mcuBoardStruct.LedPortPinArrayPointerArray, \
       keyNumber, ledNUmber);
}

// *** Olimex only ***

void blinkOlimexLed(int ledNumber, int onTime, int offTime, int blinkCount)
{
blinkOneLed0501(OlimexBoardLedPortPinArrayPointerArray, \
                    ledNumber, onTime, offTime, blinkCount);
}

void runOlimexLeds()
{
runOlimexLeds050(OlimexBoardLedPortPinArrayPointerArray, MAX_OLIMEX_LED_PIN_NUMBER, \
        ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, BLINK_1_TIME, \
        SEQUENCE_2_TIMES);
}

void echoOlimexKeyByLed(int keyNumber, int ledNUmber)
{
setupAllGpioPinsOutputLow050(OlimexBoardLedPortPinArrayPointerArray, MAX_OLIMEX_LED_PIN_NUMBER);
setupAllGpioPinsInput050(OlimexBoardKeyPortPinArrayPointerArray,  MAX_OLIMEX_KEY_PIN_NUMBER);

echoKeyByLed050(OlimexBoardKeyPortPinArrayPointerArray, OlimexBoardLedPortPinArrayPointerArray, \
       keyNumber, ledNUmber);
}


// ***********************************************************************
// End
// ***********************************************************************



No comments:

Post a Comment