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

Minor cleanup of dead UART2 code #4816

Merged
merged 5 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ set(FW_SOURCES
tmc2130.cpp
tone04.c
twi.cpp
uart2.c
uart2.cpp
ultralcd.cpp
util.cpp
xflash.c
Expand Down
85 changes: 0 additions & 85 deletions Firmware/uart2.c

This file was deleted.

50 changes: 50 additions & 0 deletions Firmware/uart2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//uart2.c
#include "uart2.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "rbuf.h"
#include "macros.h"

#define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*8.0)-1.0+0.5)
#define uart2_txready (UCSR2A & (1 << UDRE2))

uint8_t uart2_ibuf[20] = {0, 0};
FILE _uart2io;

static int uart2_putchar(char c, _UNUSED FILE *stream)
{
while (!uart2_txready);

UDR2 = c; // transmit byte

return 0;
}

static int uart2_getchar(_UNUSED FILE *stream)
{
if (rbuf_empty(uart2_ibuf)) return -1;
return rbuf_get(uart2_ibuf);
}

//uart init (io + FILE stream)
void uart2_init(uint32_t baudRate)
{
DDRH &= ~0x01;
PORTH |= 0x01;
rbuf_ini(uart2_ibuf, sizeof(uart2_ibuf) - 4);
UCSR2A |= (1 << U2X2); // baudrate multiplier
UBRR2L = UART_BAUD_SELECT(baudRate, F_CPU); // select baudrate
UCSR2B = (1 << RXEN2) | (1 << TXEN2); // enable receiver and transmitter
UCSR2B |= (1 << RXCIE2); // enable rx interrupt
fdev_setup_stream(uart2io, uart2_putchar, uart2_getchar, _FDEV_SETUP_WRITE | _FDEV_SETUP_READ); //setup uart2 i/o stream
}

ISR(USART2_RX_vect)
{
if (rbuf_put(uart2_ibuf, UDR2) < 0) // put received byte to buffer
{ //rx buffer full
puts_P(PSTR("USART2 rx Full!!!"));
}
}

15 changes: 1 addition & 14 deletions Firmware/uart2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@
#include <inttypes.h>
#include <stdio.h>


#if defined(__cplusplus)
extern "C" {
#endif //defined(__cplusplus)


extern FILE _uart2io;
#define uart2io (&_uart2io)

void uart2_init(uint32_t baudRate);

extern void uart2_init(uint32_t baudRate);

extern int8_t uart2_rx_str_P(const char* str);


#if defined(__cplusplus)
}
#endif //defined(__cplusplus)
#endif //_UART2_H
Loading