diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-08-23 15:17:50 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-08-23 15:17:50 +0200 |
| commit | e304ce76cb2e66b3009cee4386d9de098e09ce94 (patch) | |
| tree | 73fd498f47eb4c1a47554b4e6168114c1859ba27 /trafficlight.c | |
| parent | 33756429cda89ed7ed2fd97b4ae0ca87e3bf36f1 (diff) | |
| download | Traffic-light-e304ce76cb2e66b3009cee4386d9de098e09ce94.tar.xz Traffic-light-e304ce76cb2e66b3009cee4386d9de098e09ce94.zip | |
Added a Traffic struct and made the code more generic and easy to
maintain
Diffstat (limited to 'trafficlight.c')
| -rw-r--r-- | trafficlight.c | 20 |
1 files changed, 18 insertions, 2 deletions
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); |
