Olimex LPC1114 board testLedKey01() OK
void testLedKey01() // tested OK 2013oct13
{
blinkLed(PortPinArrayP09); // setup GPIO pin as output and blink led
setupOlimexGPIO050(); // setup Olimex GPIO pins as output and input
blinkOlimexLed(LED_5, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_8_TIMES);
// blink olimex Led5
runOlimexLeds(); // sequentially blink all OLimex 8 Leds
echoOlimexKeyByLed(KEY_1, LED_1); // echo Olimex key by led
echoOlimexKeyByLed(KEY_2, LED_2); // echo Olimex key by led
echoKeyByLed(OlimexLpc1114DevBoardStruct, KEY_1, LED_3);
// given mcuboard struct, echo key by led
}
// ***********************************************************************
// Program - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author - TL Fong
// Build - 2013.10.13.04
// Date - 2013oct13hkt2203
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
// 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()
{
testLedKey01();
return 0;
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// test050.h 2013oct13hkt2206
// ***********************************************************************
#include "led050.h"
#include "key050.h"
void testLedKey01() // tested OK 2013oct13
{
blinkLed(PortPinArrayP09); // setup GPIO pin as output and blink led
setupOlimexGPIO050(); // setup Olimex GPIO pins as output and input
blinkOlimexLed(LED_5, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_8_TIMES); // blink olimex Led5
runOlimexLeds(); // sequentially blink all OLimex 8 Leds
echoOlimexKeyByLed(KEY_1, LED_1); // echo Olimex key by led
echoOlimexKeyByLed(KEY_2, LED_2); // echo Olimex key by led
echoKeyByLed(OlimexLpc1114DevBoardStruct, KEY_1, LED_3); // given mcuboard struct, echo key by led
}
void blinkLed(portPinArray ledPortPinArray)
{
setupGpioPinOutputLow050(ledPortPinArray);
blinkOneLed050(ledPortPinArray, ON_ONE_HALF_SECOND, OFF_ONE_HALF_SECOND, \
REPEAT_4_TIMES);
}
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);
}
void echoKeyByLed(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);
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// config050.h - 2013oct13hk2204
// ***********************************************************************
#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 LED_1 1
#define LED_2 2
#define LED_3 3
#define LED_4 4
#define LED_5 5
#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];
// *** 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
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};
// *** 7-segment LED declaration ***
#define SCLK_INDEX 0
#define DIN_INDEX 1
#define LATCH_INDEX 2
// *** WHUT Seven segment LED data and control signals ***
portPinArray WhutBoardSevenSegmentLedPortPinArraySclk = {PORT2, PIN1}; // Serial Clock
portPinArray WhutBoardSevenSegmentLedPortPinArrayDin = {PORT2, PIN3}; // Data in
portPinArray WhutBoardSevenSegmentLedPortPinArrayLatch = {PORT2, PIN0}; // Latch
portPinArray WhutBoardKeyPortPinArray1 = {PORT2, PIN7}; // LCD D4 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray2 = {PORT2, PIN8}; // LCD D5 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray3 = {PORT2, PIN9}; // LCD D6 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray4 = {PORT2, PIN10}; // LCD D7 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray5 = {PORT1, PIN4}; // WakeUp <<<<< 2013aug30
#define MAX_7_SEG_LED_PIN_NUMBER 3
portPinArrayPointerArray WhutBoardSevenSegmentLedPortPinArrayPointerArray[MAX_7_SEG_LED_PIN_NUMBER] = \
{&WhutBoardSevenSegmentLedPortPinArraySclk, &WhutBoardSevenSegmentLedPortPinArrayDin, \
&WhutBoardSevenSegmentLedPortPinArrayLatch};
// *** Mcu board struct ***
typedef struct
{
portPinArrayPointerArray *LedPortPinArrayPointerArray;
portPinArrayPointerArray *KeyPortPinArrayPointerArray;
} mcuBoardStruct;
mcuBoardStruct OlimexLpc1114DevBoardStruct = {OlimexBoardLedPortPinArrayPointerArray, \
OlimexBoardKeyPortPinArrayPointerArray};
#endif /* CONFIG_HEADER_SEEN */
// ***********************************************************************
// * End *
// ***********************************************************************
// ***********************************************************************
// gpio033.h 2013oct13hkt2204
// ***********************************************************************
#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 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++)
{
initializeOneOutputPinHigh(portPinArrayPointerArray, pinNumber);
}
}
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
// ***********************************************************************
// ***********************************************************************
// timer050.h 2013oct13hkt2205
// ***********************************************************************
#ifndef DELAY_HEADER_SEEN
#define DELAY_HEADER_SEEN
// *** Delay constants ***
#define ONE_FIFTH_SECOND 2
#define ONE_HALF_SECOND 5
#define ONE_SECOND 10
#define TWO_SECONDS 20
#define ON_ONE_FIFTH_SECOND 2
#define OFF_ONE_FIFTH_SECOND 2
#define ON_ONE_HALF_SECOND 5
#define OFF_ONE_HALF_SECOND 5
#define ON_ONE_SECOND 10
#define OFF_ONE_SECOND 10
// *** Repeat times ***
#define REPEAT_1_TIME 1
#define REPEAT_2_TIMES 2
#define REPEAT_3_TIMES 3
#define REPEAT_4_TIMES 4
#define REPEAT_5_TIMES 5
#define REPEAT_6_TIMES 6
#define REPEAT_8_TIMES 8
#define REPEAT_10_TIMES 10
#define REPEAT_20_TIMES 20
#define BLINK_0_TIME 0
#define BLINK_1_TIME 1
#define BLINK_2_TIMES 2
#define SEQUENCE_1_TIME 1
#define SEQUENCE_2_TIMES 2
#define SEQUENCE_4_TIMES 4
void delayTenthSecond(int count)
{
int i, j, k;
for (i = 0; i < count; i++)
{
for (j = 0; j < 0x4; j++)
{
for (k = 0; k < 0x000BB00; k++)
{
}
}
}
}
void delayTime(int count)
{
delayTenthSecond(count);
}
// *** system timer number, match register number ***
typedef const int timerNumber;
timerNumber Ct16b0 = 0;
timerNumber Ct16b1 = 1;
timerNumber Ct32b0 = 2;
timerNumber Ct32b1 = 3;
typedef const int matchRegisterNumber;
matchRegisterNumber MatchRegister0 = 0;
matchRegisterNumber MatchRegister1 = 1;
matchRegisterNumber MatchRegister2 = 2;
#endif /* DELAY_HEADER_SEEN */
// ***********************************************************************
// * End *
// ***********************************************************************
// ***********************************************************************
// led050.h 2013oct13hkt2206
// ***********************************************************************
#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);
}
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// key050.h 2013oct13hkt2206
// ***********************************************************************
#include "config050.h"
#include "gpio050.h"
#include "timer050.h"
// *** Get key status ***
logicLevelValue getKeyStatus01(portPinArray keyPortPinArray)
{
logicLevelValue keyStatus;
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;
portNumber = getPortNumber(keyPortPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(keyPortPinArray);
keyStatus = getGpioDataPinValue01(gpioStructPointer, pinNumber);
return keyStatus;
}
logicLevelValue getKeyStatus(portPinArrayPointerArray keyPortPinArrayPointerArray, \
deviceNumber keyNumber)
{
logicLevelValue keyStatus;
int portNumber;
int pinNumber;
GPIO_TypeDef *gpio_struct_ptr;
keyStatus = getGpioDataPinValue(keyPortPinArrayPointerArray, keyNumber);
return keyStatus;
}
// *** Echo key by led ***
void echoKeyByLed02(portPinArray keyPortPinArray, portPinArray ledPortPinArray)
{
int count;
logicLevelValue keyStatus;
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus01(keyPortPinArray);
if (keyStatus == LOW)
{
// blinkLedP09TwoTimes();
blink1Led02(ledPortPinArray, ONE_FIFTH_SECOND, ONE_HALF_SECOND, REPEAT_2_TIMES);
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
void echo1KeyBySingleLed01(portPinArrayPointerArray keyPortPinArrayPointerArray, \
deviceNumber keyNumber, \
portPinArrayPointerArray ledPortPinArrayPointerArray, \
deviceNumber ledNumber, int echoCount)
{
int count;
logicLevelValue keyStatus;
for (count = 0; count < echoCount; count++)
{
delayTime(ONE_SECOND);
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus(keyPortPinArrayPointerArray, keyNumber);
if (keyStatus == LOW)
{
blink1Led(ledNumber);
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
}
void echoOlimex1KeyBySingleLed01(portPinArrayPointerArray keyPortPinArrayPointerArray, \
deviceNumber keyNumber, \
portPinArrayPointerArray ledPortPinArrayPointerArray, \
deviceNumber ledNumber, int echoCount)
{
int count;
logicLevelValue keyStatus;
for (count = 0; count < echoCount; count++)
{
delayTime(ONE_SECOND);
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus(keyPortPinArrayPointerArray, keyNumber);
if (keyStatus == LOW)
{
blinkOlimex1Led(ledNumber);
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
}
void echoOlimex1KeyBySingleLed4201(portPinArrayPointerArray keyPortPinArrayPointerArray, \
deviceNumber keyNumber, \
portPinArrayPointerArray ledPortPinArrayPointerArray, deviceNumber ledNumber)
{
int count;
logicLevelValue keyStatus;
delayTime(ONE_SECOND);
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus(keyPortPinArrayPointerArray, keyNumber);
if (keyStatus == LOW)
{
blinkOneLed050(PortPinArrayP30, ON_ONE_HALF_SECOND, OFF_ONE_HALF_SECOND, \
REPEAT_4_TIMES);
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
/*
void echo1KeyBySingleLed(deviceNumber keyNumber, int ledNumber, int repeatCount)
{
echo1KeyBySingleLed01(*WhutBoardKeyPortPinArrayPointerArray, keyNumber, \
*WhutBoardLedPortPinArrayPointerArray, ledNumber, \
repeatCount);
}
*/
void echoOlimex1KeyBySingleLed(deviceNumber keyNumber, int ledNumber, int repeatCount)
{
echoOlimex1KeyBySingleLed01(*OlimexBoardKeyPortPinArrayPointerArray, keyNumber, \
*OlimexBoardLedPortPinArrayPointerArray, ledNumber, \
repeatCount);
}
void echoOlimex1KeyBySingleLed42(deviceNumber keyNumber, int ledNumber)
{
echoOlimex1KeyBySingleLed4201(*OlimexBoardKeyPortPinArrayPointerArray, keyNumber, \
*OlimexBoardLedPortPinArrayPointerArray, ledNumber);
}
void echoOlimex1KeyBySingleLed43(portPinArrayPointerArray keyPortPinArrayPointerArray, \
portPinArrayPointerArray ledPortPinArrayPointerArray, \
deviceNumber keyNumber, int ledNumber)
{
echoOlimex1KeyBySingleLed4201(keyPortPinArrayPointerArray, keyNumber, \
ledPortPinArrayPointerArray, ledNumber);
}
// *** Echo key by 7 segment LED ***
void echoKeyBy7SegmentLed01(portPinArrayPointerArray keyPortPinArrayPointerArray, \
deviceNumber keyNumber, \
portPinArrayPointerArray sevenSegmentledPortPinArrayPointerArray, \
int digitNumber, int echoCount)
{
int count;
logicLevelValue keyStatus;
for (count = 0; count < echoCount; count++)
{
delayTime(ONE_SECOND);
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus(keyPortPinArrayPointerArray, keyNumber);
if (keyStatus == LOW)
{
blinkDigit(digitNumber, ONE_HALF_SECOND, ONE_HALF_SECOND, REPEAT_2_TIMES);
displayDigitBlank();
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
}
/*
void echoKeyBy7SegmentLed(deviceNumber keyNumber, int digitNumber, int repeatCount)
{
echoKeyBy7SegmentLed01(*WhutBoardKeyPortPinArrayPointerArray, keyNumber, \
*WhutBoardSevenSegmentLedPortPinArrayPointerArray, digitNumber, \
repeatCount);
}
*/
// ***********************************************************************
// Echo Key Tests
// ***********************************************************************
/*
void echoWakeUpKeyByLed() // Echo Wake Up Key 4 times
{
initializeAllInputPins(WhutBoardKeyPortPinArrayPointerArray, MAX_KEY_NUMBER);
echo1KeyBySingleLed(KEY_5, LED_5, REPEAT_4_TIMES);
}
*/
void echoOlimexWakeUpKeyByLed() // 2013oct11
{
initializeAllInputPins(OlimexBoardKeyPortPinArrayPointerArray, MAX_OLIMEX_KEY_PIN_NUMBER);
echoOlimex1KeyBySingleLed(KEY_2, LED_2, REPEAT_4_TIMES);
}
void echoWakeUpKey40() // ***** 2013oct12 *****
{
initializeAllInputPins40(OlimexBoardKeyPortPinArrayPointerArray);
echoOlimex1KeyBySingleLed(KEY_2, LED_2, REPEAT_4_TIMES);
}
void echoWakeUpKey41(portPinArrayPointerArray keyPortPinArrayPointerArray) // ***** 2013oct12 *****
{
initializeAllInputPins40(keyPortPinArrayPointerArray);
echoOlimex1KeyBySingleLed(KEY_2, LED_2, REPEAT_4_TIMES);
}
void echoKeyByLed42(portPinArrayPointerArray keyPortPinArrayPointerArray, int keyNumber, int ledNumber) // ***** 2013oct12 *****
{
initializeAllInputPins40(keyPortPinArrayPointerArray);
echoOlimex1KeyBySingleLed42(keyNumber, ledNumber);
}
void echoKeyByLed43(portPinArrayPointerArray keyPortPinArrayPointerArray, \
portPinArrayPointerArray ledPortPinArrayPointerArray, \
int keyNumber, int ledNumber) // ***** 2013oct12 *****
{
initializeAllInputPins40(keyPortPinArrayPointerArray);
echoOlimex1KeyBySingleLed43(keyPortPinArrayPointerArray, ledPortPinArrayPointerArray, keyNumber, ledNumber);
}
void echoKeyByLed45(mcuBoardStruct mcuBoardStruct, int keyNumber, int ledNumber)
{
initializeAllInputPins40(mcuBoardStruct.KeyPortPinArrayPointerArray);
echoOlimex1KeyBySingleLed43(mcuBoardStruct.KeyPortPinArrayPointerArray, \
mcuBoardStruct.LedPortPinArrayPointerArray, \
keyNumber, ledNumber);
}
void echoBootKeyThreeTimes() // Echo key by LED P0.9 MOSI
{
portPinArray ledPortPinArray = {0, 9};
portPinArray bootPortPinArray = {0, 1};
initializeOutputPin01(ledPortPinArray);
initializeInputPin01(bootPortPinArray);
int count;
for (count = 0; count < 3; count++)
{
echoKeyByLed02(bootPortPinArray, ledPortPinArray);
}
}
void echoMisoKeyByMosiLedTwoTimes()
{
portPinArray mosiPortPinArray = {0, 9};
portPinArray misoPortPinArray = {0, 8};
initializeOutputPin01(mosiPortPinArray);
initializeInputPin01(misoPortPinArray);
int count;
for (count = 0; count < 2; count++)
{
echoKeyByLed02(misoPortPinArray, mosiPortPinArray);
}
}
/*
void echoAllKeysByLed() // Echo All keys twice
{
initializeAllInputPins(WhutBoardKeyPortPinArrayPointerArray, MAX_KEY_NUMBER);
echo1KeyBySingleLed(KEY_1, LED_1, REPEAT_2_TIMES);
echo1KeyBySingleLed(KEY_2, LED_2, REPEAT_2_TIMES);
echo1KeyBySingleLed(KEY_3, LED_3, REPEAT_2_TIMES);
echo1KeyBySingleLed(KEY_4, LED_4, REPEAT_2_TIMES);
echo1KeyBySingleLed(KEY_5, LED_5, REPEAT_2_TIMES);
}
*/
void echoWakeUpKeyByDigit() // Echo Wake Up Key by digit
{
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
echoKeyBy7SegmentLed(KEY_5, LED_5, REPEAT_2_TIMES);
}
void echoAllKeysByDigit() // Echo Wake Up Key by digit
{
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
echoKeyBy7SegmentLed(KEY_1, LED_1, REPEAT_2_TIMES);
echoKeyBy7SegmentLed(KEY_2, LED_2, REPEAT_2_TIMES);
echoKeyBy7SegmentLed(KEY_3, LED_3, REPEAT_2_TIMES);
echoKeyBy7SegmentLed(KEY_4, LED_4, REPEAT_2_TIMES);
echoKeyBy7SegmentLed(KEY_5, LED_5, REPEAT_2_TIMES);
}
// Version 050
void echoKeyByLed050(portPinArrayPointerArray keyPortPinArrayPointerArray, \
portPinArrayPointerArray ledPortPinArrayPointerArray, \
int keyNumber, int ledNumber)
{
int count;
logicLevelValue keyStatus;
delayTime(ONE_HALF_SECOND);
keyStatus = HIGH;
while (keyStatus == HIGH)
{
keyStatus = getKeyStatus(keyPortPinArrayPointerArray, keyNumber);
if (keyStatus == LOW)
{
blinkOneLed0501(ledPortPinArrayPointerArray, ledNumber, \
ON_ONE_FIFTH_SECOND, OFF_ONE_HALF_SECOND, REPEAT_2_TIMES);
delayTime(TWO_SECONDS);
keyStatus = HIGH;
break;
}
}
}
// ***********************************************************************
// End
// ***********************************************************************
No comments:
Post a Comment