diff --git a/.cproject b/.cproject index 3e82883..fdc9522 100644 --- a/.cproject +++ b/.cproject @@ -25,10 +25,20 @@ + @@ -38,7 +48,9 @@ - + + + @@ -68,10 +80,20 @@ + @@ -92,9 +114,21 @@ - - - + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3df573f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/Debug/ diff --git a/src/gpio.c b/src/gpio.c deleted file mode 100644 index d237c72..0000000 --- a/src/gpio.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * gpio.c - * - * Created on: 29.08.2016 - * Author: wn - */ - - -#include -#include - -#define GPIO_C -#include "gpio.h" -#undef GPIO_C - - - -extern tPinCfg pinCfg[]; - - -void gpioInitPins() { - P1OUT = 0; - P1DIR = 0; - P1REN = 0; - P2OUT = 0; - P2DIR = 0; - P2REN = 0; - - for (tPin p = PINS_FIRST; p < PINS_END; p += 1) { - tPinCfg pin = pinCfg[p]; - if (pin.portId == PORT1) { - if (pin.direction == PIN_OUT) { - P1DIR |= pin.bit; - P1SEL &= ~pin.bit; - P1SEL2 &= ~pin.bit; - gpioSetPin(p, pin.defaultOut); - } else if (pin.direction == PIN_IN) { - P1DIR &= ~pin.bit; - P1SEL &= ~pin.bit; - P1SEL2 &= ~pin.bit; - P1REN &= ~pin.bit; - } else if (pin.direction == PIN_IN_PULLUP) { - P1DIR &= ~pin.bit; - P1SEL &= ~pin.bit; - P1SEL2 &= ~pin.bit; - P1REN |= pin.bit; - P1OUT |= pin.bit; - } - } else if (pin.portId == PORT2) { - if (pin.direction == PIN_OUT) { - P2DIR |= pin.bit; - P2SEL &= ~pin.bit; - P2SEL2 &= ~pin.bit; - gpioSetPin(p, pin.defaultOut); - } else if (pin.direction == PIN_IN) { - P2DIR &= ~pin.bit; - P2SEL &= ~pin.bit; - P2SEL2 &= ~pin.bit; - P2REN &= ~pin.bit; - } else if (pin.direction == PIN_IN_PULLUP) { - P2DIR &= ~pin.bit; - P2SEL &= ~pin.bit; - P2SEL2 &= ~pin.bit; - P2REN |= pin.bit; - P2OUT |= pin.bit; - } - } - } -} - -void gpioSetPin(tPin p, tPinState v) { - tPinCfg pin = pinCfg[p]; - if (v == HIGH) { - if (pin.portId == PORT1) { - P1OUT |= pin.bit; - } else if (pin.portId == PORT2) { - P2OUT |= pin.bit; - } - } else { - if (pin.portId == PORT1) { - P1OUT &= ~pin.bit; - } else if (pin.portId == PORT2) { - P2OUT &= ~pin.bit; - } - } -} - -void gpioTogglePin(tPin p) { - tPinCfg pin = pinCfg[p]; - if (pin.portId == PORT1) { - P1OUT ^= pin.bit; - } else if (pin.portId == PORT2) { - P2OUT ^= pin.bit; - } -} - -tPinState gpioGetPin(tPin p) { - tPinCfg pin = pinCfg[p]; - uint16_t pinValue = 0; - if (pin.portId == PORT1) { - pinValue = P1IN; - } else if (pin.portId == PORT2) { - pinValue = P2IN; - } - return (pinValue & pin.bit) ? HIGH : LOW; -} diff --git a/src/gpio.h b/src/gpio.h deleted file mode 100644 index cf0c114..0000000 --- a/src/gpio.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * gpio.h - * - * Created on: 29.08.2016 - * Author: wn - */ - -#ifndef GPIO_H_ -#define GPIO_H_ - - -#include -#include - - - -typedef enum { - PORT1, - PORT2 -} tPort; - -typedef enum { - LOW, - HIGH, -} tPinState; - -typedef enum { - PIN_OUT, - PIN_IN, - PIN_IN_PULLUP -} tPinDirection; - -typedef struct { - tPort portId; - uint16_t bit; - tPinDirection direction; - tPinState defaultOut; -} tPinCfg; - - -typedef enum { - PINS_FIRST, - SEG_A = PINS_FIRST, - SEG_B, - SEG_C, - SEG_D, - SEG_E, - SEG_F, - SEG_G, - DIGIT_0, - DIGIT_1, - DIGIT_2, - BUTTON_1, - LED_1, - PINS_END -} tPin; - -void gpioInitPins(); -void gpioSetPin(tPin p, tPinState v); -void gpioTogglePin(tPin p); -tPinState gpioGetPin(tPin p); - - - - - -#endif /* GPIO_H_ */ diff --git a/src/gpioCfg.h b/src/gpioCfg.h new file mode 100644 index 0000000..8a52825 --- /dev/null +++ b/src/gpioCfg.h @@ -0,0 +1,31 @@ +/* + * gpioCfg.h + * + * Created on: 18.09.2016 + * Author: wn + */ + +#ifndef GPIOCFG_H_ +#define GPIOCFG_H_ + +#include "gpio.h" + +typedef enum { + PINS_FIRST, + SEG_A = PINS_FIRST, + SEG_B, + SEG_C, + SEG_D, + SEG_E, + SEG_F, + SEG_G, + DIGIT_0, + DIGIT_1, + DIGIT_2, + BUTTON_1, + LED_1, + PINS_END +} tPin; + + +#endif /* GPIOCFG_H_ */