Replace tabs with spaces

This commit is contained in:
Lexi / Zoe 2021-04-03 18:44:22 +02:00
parent fccd19dbf4
commit 28be3c4e8b
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
5 changed files with 242 additions and 242 deletions

View file

@ -6,88 +6,88 @@
// Initialize UART
void uartInit() {
// Set Baud register
UBRRH = UBRRH_VALUE;
UBRRL = UBRRL_VALUE;
// Set Baud register
UBRRH = UBRRH_VALUE;
UBRRL = UBRRL_VALUE;
// Reset status register
UCSRA = 0x00;
// Reset status register
UCSRA = 0x00;
#if USE_2X
// U2X mode necessary
UCSRA |= (1 << U2X);
// U2X mode necessary
UCSRA |= (1 << U2X);
#else
// U2X mode not necessary
UCSRA &= ~(1 << U2X);
// U2X mode not necessary
UCSRA &= ~(1 << U2X);
#endif
// Enable transmitter and receiver
UCSRB |= (1 << TXEN) | (1 << RXEN);
// Enable transmitter and receiver
UCSRB |= (1 << TXEN) | (1 << RXEN);
// Set frame format (8 bit)
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0);
// Set frame format (8 bit)
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0);
}
// Transmit a single character
void uartPutChar(unsigned char data) {
// Block until controller is ready to send
while (!(UCSRA & (1 << UDRE))) {
}
// Block until controller is ready to send
while (!(UCSRA & (1 << UDRE))) {
}
// Write character to UART data register
UDR = data;
// Write character to UART data register
UDR = data;
}
// Transmit a string
void uartPutString(char* data) {
// Write characters until \0 is reached
while (*data) {
uartPutChar(*data++);
}
// Write characters until \0 is reached
while (*data) {
uartPutChar(*data++);
}
}
// Receive a single character (blocking)
unsigned char uartGetChar() {
// Block until a character has been received
while (!(UCSRA & (1 << RXC))) {
}
// Block until a character has been received
while (!(UCSRA & (1 << RXC))) {
}
// Get character and return
return UDR;
// Get character and return
return UDR;
}
// Receive a string until \n (blocking)
uint8_t uartGetLine(char* buffer, uint8_t maxLength) {
uint8_t readChars = 0;
unsigned char nextChar;
uint8_t readChars = 0;
unsigned char nextChar;
// Read a maximum of maxLength-1 characters (-1 because we need one char for '\0')
while (readChars < maxLength - 1) {
// Get next character
nextChar = uartGetChar();
// Read a maximum of maxLength-1 characters (-1 because we need one char for '\0')
while (readChars < maxLength - 1) {
// Get next character
nextChar = uartGetChar();
// Skip trailing \n and \r
if (nextChar == '\n' || nextChar == '\r') {
if (readChars == 0) {
// Skip trailing \n and \r
continue;
}
else {
// End line (do not append the \r or \n to the buffer)
break;
}
}
// Skip trailing \n and \r
if (nextChar == '\n' || nextChar == '\r') {
if (readChars == 0) {
// Skip trailing \n and \r
continue;
}
else {
// End line (do not append the \r or \n to the buffer)
break;
}
}
// Write character to buffer
*buffer++ = nextChar;
// Write character to buffer
*buffer++ = nextChar;
// Increment counter
readChars++;
}
// Increment counter
readChars++;
}
// Write a terminating '\0' byte
*buffer++ = '\0';
// Write a terminating '\0' byte
*buffer++ = '\0';
// Return number of read bytes (excluding the \0)
return readChars;
// Return number of read bytes (excluding the \0)
return readChars;
}