Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small code improvements #7

Open
dambo1993 opened this issue Mar 10, 2019 · 0 comments
Open

small code improvements #7

dambo1993 opened this issue Mar 10, 2019 · 0 comments

Comments

@dambo1993
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants