/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef ECXX_PLATFORM_AVR_USB_DRIVER_H
#define ECXX_PLATFORM_AVR_USB_DRIVER_H


#include <eCxx/eCxx_Internal.h>
#include <eCxx/Platform/Common/Application.h>


#ifdef ECXX_AVR_HAVE_HARDWARE_USB


namespace eCxx {


//
// Constants
//
static constexpr uint8_t CDC_ACM_INTRSIZE =  8;
static constexpr uint8_t CDC_ACM_BULKSIZE = 64; // Must be 8, 16, 32, or 64

static constexpr uint8_t CDC_ACM_ENDPOINT[2] = { 1, 4 };
static constexpr uint8_t CDC_RXD_ENDPOINT[2] = { 2, 5 };
static constexpr uint8_t CDC_TXD_ENDPOINT[2] = { 3, 6 };


//
// A simple AVR USB driver
//
extern volatile uint8_t txdFlushTimer[2];

extern void usbStart();
extern void usbStop();

extern bool usbReady();


extern void setVUART0MagicBaudrateCallback(VoidCallback cb);
extern void setVUART0DtrLowCallback(VoidCallback cb);

extern bool setVUARTChangeSettingsCallback(uint8_t idx, VoidCallback cb);
extern bool getVUARTSerialSettings(uint8_t idx, uint32_t& baudrate, uint8_t& charSize, uint8_t& parity, uint8_t& stopBits);

extern uint32_t getVUARTBaudrate(uint8_t idx);
extern uint8_t getVUARTRtsDtrState(uint8_t idx);

#ifdef ECXX_AVR_VUART_DUMP_SETTINGS

extern uint32_t getVUARTWIndexes(uint8_t idx);

#endif


} // namespace eCxx


#endif


#endif
