From e304ce76cb2e66b3009cee4386d9de098e09ce94 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Tue, 23 Aug 2022 15:17:50 +0200 Subject: Added a Traffic struct and made the code more generic and easy to maintain --- trafficlight.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'trafficlight.c') diff --git a/trafficlight.c b/trafficlight.c index a004d98..eff06fb 100644 --- a/trafficlight.c +++ b/trafficlight.c @@ -1,11 +1,27 @@ #include "trafficlight.h" + +void set_tf_color(Traffic tf, uint8_t color) { + uint32_t pins = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; + switch (color) { + case RED: + GPIOPinWrite(tf.port, pins, (1 << tf.red)); + break; + case YELLOW: + GPIOPinWrite(tf.port ,pins, (1 << tf.yellow)); + break; + case GREEN: + GPIOPinWrite(tf.port ,pins, (1 << tf.green)); + break; + } +} + void PortInit(uint32_t port, uint32_t clk) { - uint32_t pins = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; + uint32_t pins = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6; SysCtlPeripheralEnable(clk); while(!SysCtlPeripheralReady(clk)) {}; GPIOUnlockPin(port, pins); - GPIOPinTypeGPIOInput(port, GPIO_PIN_0); + // GPIOPinTypeGPIOInput(port, GPIO_PIN_0); GPIOPinTypeGPIOOutput(port, pins); GPIOPadConfigSet (port, GPIO_PIN_0 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); -- cgit v1.2.3