/*
 * This file is part of the test project.
 * Copyright 2026 Edward V. Emelianov <edward.emelianoff@gmail.com>.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <stdint.h>

// maximal length of input string (including '\n' and terminating zero)
#define MAX_INPLEN      (128)
// Rx/Tx ring buffer size
#define USARTTXBUFSZ    (512)
#define USARTRXBUFSZ    (512)
// Rx/Tx DMA buffer size
#define USARTTXDMABUFSZ (256)
#define USARTRXDMABUFSZ (256)

// blocking timeout - not more than 5ms
#define USARTBLKTMOUT   (5)
// send buffer each 10ms
#define USARTSENDTMOUT  (10)

typedef union{
    struct{
        uint8_t txerr       : 1; // transmit error
        uint8_t rxovrfl     : 1; // receive buffer overflow
    };
    uint8_t all;
} USART_flags_t;

void usart_setup(uint32_t speed);
int usart_send(const char *str, int len);
char *usart_getline();
int usart_sendstr(const char *str);
USART_flags_t usart_process();
