Skip to content

small code improvements  #7

@dambo1993

Description

@dambo1993

Hi - a little advice - you have a lot od #define in code. for example:

void uart0_reinit(uint16_t ubrr_value)
{
	#ifdef USART0_USE_SOFT_RTS
		RTS0_PORT |= (1<<RTS0_IONUM);
	#endif
		
	#ifdef USART0_RS485_MODE
		RS485_CONTROL0_PORT &= ~(1<<RS485_CONTROL0_IONUM); //set low
		RS485_CONTROL0_DDR |= (1<<RS485_CONTROL0_IONUM);
	#endif
		
          // rest of the function
}

you can simply hide #defines by implement static functions:

static void USART0_USE_SOFT_RTS_func(void)
{
	#ifdef USART0_USE_SOFT_RTS
		RTS0_PORT |= (1<<RTS0_IONUM);
	#endif
}
static void USART0_RS485_MODE_on(void)
{
	#ifdef USART0_RS485_MODE
		RS485_CONTROL0_PORT &= ~(1<<RS485_CONTROL0_IONUM); //set low
		RS485_CONTROL0_DDR |= (1<<RS485_CONTROL0_IONUM);
	#endif
}

void uart0_reinit(uint16_t ubrr_value)
{
                USART0_USE_SOFT_RTS_func();
		USART0_RS485_MODE_on();
		
                // rest of the function
}
}

compiler will remove all unused jumps etc - and functions are easier to read. Of course- just in my opinion.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions