Implement mmu2 serial interface
This commit is contained in:
parent
208e620660
commit
db0374896f
|
|
@ -1,14 +1,30 @@
|
||||||
#include "mmu2_serial.h"
|
#include "mmu2_serial.h"
|
||||||
|
#include "uart2.h"
|
||||||
//@@TODO implement for MK3
|
|
||||||
|
|
||||||
namespace MMU2 {
|
namespace MMU2 {
|
||||||
|
|
||||||
void MMU2Serial::begin(uint32_t baud){ }
|
void MMU2Serial::begin(uint32_t baud){
|
||||||
void MMU2Serial::close() { }
|
uart2_init(baud); // @@TODO we may skip the baud rate setting in case of 8bit FW ... could save some bytes...
|
||||||
int MMU2Serial::read() { }
|
}
|
||||||
void MMU2Serial::flush() { }
|
|
||||||
size_t MMU2Serial::write(const uint8_t *buffer, size_t size) { }
|
void MMU2Serial::close() {
|
||||||
|
// @@TODO - probably turn off the UART
|
||||||
|
}
|
||||||
|
|
||||||
|
int MMU2Serial::read() {
|
||||||
|
return fgetc(uart2io);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MMU2Serial::flush() {
|
||||||
|
// @@TODO - clear the output buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MMU2Serial::write(const uint8_t *buffer, size_t size) {
|
||||||
|
while(size--){
|
||||||
|
fputc(*buffer, uart2io);
|
||||||
|
++buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MMU2Serial mmu2Serial;
|
MMU2Serial mmu2Serial;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ int uart2_getchar(_UNUSED FILE *stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
//uart init (io + FILE stream)
|
//uart init (io + FILE stream)
|
||||||
void uart2_init(void)
|
void uart2_init(uint32_t baudRate)
|
||||||
{
|
{
|
||||||
DDRH &= ~0x01;
|
DDRH &= ~0x01;
|
||||||
PORTH |= 0x01;
|
PORTH |= 0x01;
|
||||||
rbuf_ini(uart2_ibuf, sizeof(uart2_ibuf) - 4);
|
rbuf_ini(uart2_ibuf, sizeof(uart2_ibuf) - 4);
|
||||||
UCSR2A |= (1 << U2X2); // baudrate multiplier
|
UCSR2A |= (1 << U2X2); // baudrate multiplier
|
||||||
UBRR2L = UART_BAUD_SELECT(UART2_BAUD, F_CPU); // select baudrate
|
UBRR2L = UART_BAUD_SELECT(baudRate, F_CPU); // select baudrate
|
||||||
UCSR2B = (1 << RXEN2) | (1 << TXEN2); // enable receiver and transmitter
|
UCSR2B = (1 << RXEN2) | (1 << TXEN2); // enable receiver and transmitter
|
||||||
UCSR2B |= (1 << RXCIE2); // enable rx interrupt
|
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
|
fdev_setup_stream(uart2io, uart2_putchar, uart2_getchar, _FDEV_SETUP_WRITE | _FDEV_SETUP_READ); //setup uart2 i/o stream
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ extern FILE _uart2io;
|
||||||
#define uart2io (&_uart2io)
|
#define uart2io (&_uart2io)
|
||||||
|
|
||||||
|
|
||||||
extern void uart2_init(void);
|
extern void uart2_init(uint32_t baudRate);
|
||||||
|
|
||||||
extern int8_t uart2_rx_str_P(const char* str);
|
extern int8_t uart2_rx_str_P(const char* str);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue