]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Drop the pretense of C89, put declarations where they make sense
authorMikko Rasa <tdb@tdb.fi>
Sun, 3 Nov 2013 13:14:44 +0000 (15:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 3 Nov 2013 13:19:38 +0000 (15:19 +0200)
A lot of places already had mixed code and declarations, since that's
what I'm used to in C++.  Might as well use them everywhere and tell
the compiler to use C99 mode.

arducontrol/interface.c
arducontrol/monitor.c
arducontrol/motorola.c
arducontrol/s88.c
common/build.mk
common/lcd.c
s88w/s88w-r.c
s88w/s88w-t.c

index 2c55e2af634eca747a7d207db38235a037c24cd3..014e8e98bcaa0ac5eacbeb061f1a38754e1a2ae5 100644 (file)
@@ -22,11 +22,10 @@ void interface_init(void)
 
 void interface_check(void)
 {
-       uint8_t count;
        if(serial_read_overrun())
                interface_send1(RECEIVE_OVERRUN);
 
-       count = serial_read_available();
+       uint8_t count = serial_read_available();
        if(count>0)
        {
                PORTB |= 0x01;
@@ -47,10 +46,9 @@ void interface_check(void)
 
                if(cmd_read_pos<cmd_length)
                {
-                       uint8_t i;
                        if(cmd_read_pos+count>cmd_length)
                                count = cmd_length-cmd_read_pos;
-                       for(i=0; i<count; ++i)
+                       for(uint8_t i=0; i<count; ++i)
                                cmd_buffer[cmd_read_pos++] = serial_read();
 
                        if(cmd_read_pos>=cmd_length)
@@ -85,10 +83,8 @@ static uint8_t dispatch_command(const uint8_t *cmd, uint8_t length)
 
 void interface_send(const uint8_t *cmd, uint8_t length)
 {
-       uint8_t i;
-
        serial_write(~length);
-       for(i=0; i<length; ++i)
+       for(uint8_t i=0; i<length; ++i)
                serial_write(cmd[i]);
 }
 
index 9b5154dddfcf1d2209b3253436ac9b0ee2289421..7966c3da40eb0e46cac63c4282924b9dc5995c32 100644 (file)
@@ -74,12 +74,11 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length)
 {
        if(cmd_buf[0]==READ_TRACK_CURRENT)
        {
-               uint8_t reply[3];
-
                if(cmd_length!=1)
                        return LENGTH_ERROR;
 
                uint16_t value = track_current_milliamps();
+               uint8_t reply[3];
                reply[0] = TRACK_CURRENT;
                reply[1] = value>>8;
                reply[2] = value;
@@ -101,12 +100,11 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length)
        }
        else if(cmd_buf[0]==READ_INPUT_VOLTAGE)
        {
-               uint8_t reply[3];
-
                if(cmd_length!=1)
                        return LENGTH_ERROR;
 
                uint16_t value = input_voltage_millivolts();
+               uint8_t reply[3];
                reply[0] = INPUT_VOLTAGE;
                reply[1] = value>>8;
                reply[2] = value;
index ff686caf8ac072a00c6cafbc407eacdd77c33cd8..883457ecf52b4bd44b5badccf0ae3f7ec14be826 100644 (file)
@@ -14,14 +14,12 @@ static uint8_t motorola_speed_to_value(uint8_t speed)
 
 static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t value)
 {
-       uint8_t i;
-
        OutputPacket *packet = output_create_packet();
 
        packet->bit_duration = 2;
        packet->length = 18*8;
 
-       for(i=0; i<4; ++i)
+       for(uint8_t i=0; i<4; ++i)
        {
                uint8_t d = addr%3;
                addr /= 3;
@@ -33,7 +31,7 @@ static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t v
        packet->data[8] = (aux ? 0x7F : 0x01);
        packet->data[9] = packet->data[8];
 
-       for(i=0; i<4; ++i)
+       for(uint8_t i=0; i<4; ++i)
        {
                packet->data[10+i*2] = ((value&1) ? 0x7F : 0x01);
                value >>= 1;
@@ -49,11 +47,9 @@ static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t v
 
 static OutputPacket *motorola_old_packet(uint8_t addr, uint8_t aux, uint8_t value)
 {
-       uint8_t i;
-
        OutputPacket *packet = motorola_common_packet(addr, aux, value);
 
-       for(i=0; i<4; ++i)
+       for(uint8_t i=0; i<4; ++i)
                packet->data[11+i*2] = packet->data[10+i*2];
 
        return packet;
@@ -85,12 +81,8 @@ void motorola_locomotive_speed_direction_packet(uint8_t addr, uint8_t aux, uint8
 
 void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_t speed, uint8_t func, uint8_t state)
 {
-       uint8_t i;
-       uint8_t value;
-       OutputPacket *packet;
-
-       value = motorola_speed_to_value(speed);
-       packet = motorola_common_packet(addr, aux, value);
+       uint8_t value = motorola_speed_to_value(speed);
+       OutputPacket *packet = motorola_common_packet(addr, aux, value);
 
        /*
        001 -> 011
@@ -106,7 +98,7 @@ void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_
        if(func==value)
                func = ((value&8) ? 2 : 5) | (func&8);
 
-       for(i=0; i<4; ++i)
+       for(uint8_t i=0; i<4; ++i)
        {
                packet->data[11+i*2] = ((func&1) ? 0x7F : 0x01);
                func >>= 1;
index cfe536734be49a78fa7642193148822120304bcb..142455a13ae551e1cb724e1a6b976e231d35e1ba 100644 (file)
@@ -32,11 +32,10 @@ void s88_check(void)
        if(count>=4 || (count>0 && !s88_read_count))
        {
                uint8_t reply[10];
-               uint8_t i;
 
                reply[0] = S88_DATA;
                reply[1] = s88_out_index;
-               for(i=0; i<count; ++i)
+               for(uint8_t i=0; i<count; ++i)
                        reply[2+i] = ringbuffer_pop(s88_buffer);
                interface_send(reply, 2+count);
                s88_out_index += count;
index c56892eae10fbe8f79423c321683fdc2aac42c75..22d970cd813129f050516132b74677a4c2883643 100644 (file)
@@ -1,7 +1,7 @@
 MCU := atmega328p
 CLOCK := 16000000
 CC := avr-gcc
-CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
+CFLAGS := -Wall -std=c99 -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK) $(patsubst %,-D%,$(FEATURES)) -I../common
 LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU)
 AVRDUDE := avrdude
 OBJCOPY := avr-objcopy
index f4e0387aeccdb5f148c0bbc7b89be943b9d29f17..a7d523febed21df5506d1a608886020170e78ebb 100644 (file)
@@ -60,8 +60,7 @@ static void lcd_clock(void)
 static void lcd_set_data(uint8_t d)
 {
 #ifdef LCD_SHIFTREG
-       uint8_t i;
-       for(i=0; i<8; ++i)
+       for(uint8_t i=0; i<8; ++i)
        {
                PORTB = (PORTB&~0x04)|((d&1)<<2);
                PORTB |= 0x08;
index f94a1be0e0e1038f128c844d5219270d0d6694a8..b508b4fa053b48cfda0bc3cb03a3b18ff676c2f5 100644 (file)
@@ -68,11 +68,9 @@ int main()
 
        while(1)
        {
-               uint8_t i;
-
                check_input();
 
-               i = load_pos;
+               uint8_t i = load_pos;
                if(i!=0xFF)
                {
                        output[i] = latch[i];
@@ -116,11 +114,10 @@ int main()
 
 void check_input()
 {
-       uint8_t c;
        if(!serial_read_available())
                return;
 
-       c = serial_read();
+       uint8_t c = serial_read();
        if(rx_fill==0xFF)
        {
                if(c==':')
@@ -130,16 +127,12 @@ void check_input()
        {
                if(rx_fill>=4)
                {
-                       uint16_t offset;
-                       uint8_t nibbles;
-                       uint8_t i;
-
-                       offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
-                       nibbles = (offset&3);
+                       uint8_t offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]);
+                       uint8_t nibbles = (offset&3);
                        offset >>= 2;
                        if(rx_fill>3+nibbles)
                        {
-                               for(i=0; i<=nibbles; ++i)
+                               for(uint8_t i=0; i<=nibbles; ++i)
                                {
                                        uint16_t j = offset+nibbles-i;
                                        uint8_t shift = 4*(j&1);
@@ -151,7 +144,7 @@ void check_input()
                                if(lcd_enabled)
                                {
                                        lcd_gotoxy(19-offset-nibbles, 0);
-                                       for(i=0; i<=nibbles; ++i)
+                                       for(uint8_t i=0; i<=nibbles; ++i)
                                                lcd_write(rx_buf[3+i]);
                                }
                        }
index 692eac5f6f3e6310c4ba8f8d0fdddb34faf68083..a1ff6aa9f05d467aff9a473f1828a5c3568756d6 100644 (file)
@@ -70,14 +70,13 @@ int main()
 
        while(1)
        {
-               uint8_t i, j;
                uint16_t input = 0;
                uint16_t valid = 0xFFF;
 
-               for(i=0; i<100; ++i)
+               for(uint8_t i=0; i<100; ++i)
                {
                        uint16_t pins = 0;
-                       for(j=0; j<100; ++j)
+                       for(uint8_t j=0; j<100; ++j)
                                pins |= ~((PIND>>2) | ((PINB&0x3F)<<6));
 
                        if(i==0)
@@ -135,13 +134,11 @@ SERIAL_SET_CALLBACK(receive)
 
 void send_state(void)
 {
-       uint8_t i;
-
        serial_write(':');
        serial_write(hexdigit(offset>>8));
        serial_write(hexdigit(offset>>4));
        serial_write(hexdigit(offset|(nibbles-1)));
-       for(i=nibbles; i--;)
+       for(uint8_t i=nibbles; i--;)
                serial_write(hexdigit(state>>(i*4)));
        serial_write('.');