]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Use symbolic constants for addressing I/O pins
authorMikko Rasa <tdb@tdb.fi>
Mon, 21 Oct 2013 23:17:59 +0000 (02:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 21 Oct 2013 23:17:59 +0000 (02:17 +0300)
arducontrol/output.c

index c1d51488349359ae9101a9762c2837bf257aebce..4b662960977e9b5762e237b96b8fe7be57ac4960 100644 (file)
@@ -3,6 +3,10 @@
 #include "output.h"
 #include "timer.h"
 
+#define POLARITY PORTD2
+#define ENABLE PORTD3
+#define BIT(x) (1<<(x))
+
 OutputPacket packet;
 uint8_t out_bit;
 uint8_t out_time;
@@ -12,7 +16,7 @@ uint8_t delay_time;
 void output_init()
 {
        DDRD = (DDRD&0xF3)|0x0C;
-       PORTD &= ~0x08;
+       PORTD &= ~BIT(ENABLE);
 
        timer_start_hz(0, 80000, 1);
 }
@@ -27,9 +31,9 @@ void clear_packet()
 void output_set_power(uint8_t p)
 {
        if(p==POWER_ON)
-               PORTD |= 0x08;
+               PORTD |= BIT(ENABLE);
        else
-               PORTD &= ~0x08;
+               PORTD &= ~BIT(ENABLE);
 }
 
 uint8_t output_command()
@@ -57,7 +61,7 @@ static inline void output_tick()
                ++out_bit;
                if(out_bit>=packet.length)
                {
-                       PORTD &= ~0x04;
+                       PORTD &= ~BIT(POLARITY);
                        if(packet.repeat_count>1)
                        {
                                if(packet.repeat_count<0xFF)
@@ -79,9 +83,9 @@ static inline void output_tick()
                                out_data >>= 1;
 
                        if(out_data&1)
-                               PORTD |= 0x04;
+                               PORTD |= BIT(POLARITY);
                        else
-                               PORTD &= ~0x04;
+                               PORTD &= ~BIT(POLARITY);
 
                        out_time = packet.bit_duration;
                }
@@ -96,9 +100,9 @@ static inline void output_tick()
                out_time = packet.bit_duration;
                out_data = packet.data[0];
                if(out_data&1)
-                       PORTD |= 0x04;
+                       PORTD |= BIT(POLARITY);
                else
-                       PORTD &= ~0x04;
+                       PORTD &= ~BIT(POLARITY);
        }
 }