summaryrefslogtreecommitdiff
path: root/color.c
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-21 18:42:49 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-21 18:42:49 +0200
commit063ac23917f608202b337b09fe355d9223493245 (patch)
tree8d45778269529e4d2a0bcbca8cc128c9a15cc0bd /color.c
parentff6ccb57551afe8904254313fb7ed0204fe74d19 (diff)
downloadTraffic-light-063ac23917f608202b337b09fe355d9223493245.tar.xz
Traffic-light-063ac23917f608202b337b09fe355d9223493245.zip
Added intital project
Diffstat (limited to 'color.c')
-rw-r--r--color.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/color.c b/color.c
new file mode 100644
index 0000000..967350f
--- /dev/null
+++ b/color.c
@@ -0,0 +1,44 @@
+#include "color.h"
+#include <stdint.h>
+
+#define LED_RED (1U << 1)
+#define LED_BLUE (1U << 2)
+#define LED_GREEN (1U << 3)
+
+void set_color(uint8_t color) {
+ switch (color) {
+ case RED:
+ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x2);
+ break;
+ case BLUE:
+ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x4);
+ break;
+ case GREEN:
+ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x8);
+ break;
+ case WHITE:
+ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xe);
+ break;
+ }
+}
+
+void toggle_color(uint8_t color) {
+ switch (color) {
+ case RED:
+ GPIO_PORTF_DATA_R ^= LED_RED;
+ break;
+ case BLUE:
+ GPIO_PORTF_DATA_R ^= LED_BLUE;
+ break;
+ case GREEN:
+ GPIO_PORTF_DATA_R ^= LED_GREEN;
+ break;
+ case WHITE:
+ GPIO_PORTF_DATA_R ^= (LED_RED | LED_BLUE | LED_GREEN);
+ break;
+ }
+}
+
+void reset_color() {
+ PORTF &= 0x11;
+}