Added usb serial
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by nano on 8/23/26.
|
||||
//
|
||||
|
||||
#include "usb_serial.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "portmacro.h"
|
||||
#include "driver/usb_serial_jtag.h"
|
||||
|
||||
|
||||
void usb_serial::init() {
|
||||
usb_serial_jtag_driver_config_t usb_serial_jtag_config = {
|
||||
.tx_buffer_size = USB_BUFFER_SIZE,
|
||||
.rx_buffer_size = USB_BUFFER_SIZE,
|
||||
};
|
||||
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||
ESP_LOGI("usb_serial", "USB_SERIAL_JTAG init done");
|
||||
|
||||
}
|
||||
|
||||
void usb_serial::write(const char* byte, int len) {
|
||||
usb_serial_jtag_write_bytes(byte,len,20/ portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
int usb_serial::read(char* byte,int len) {
|
||||
int read_length = usb_serial_jtag_read_bytes(byte, len, 20/ portTICK_PERIOD_MS);
|
||||
return read_length;
|
||||
}
|
||||
|
||||
|
||||
void usb_serial::write_byte(char* byte) {
|
||||
usb_serial_jtag_write_bytes(byte,1,20/ portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
int usb_serial::read_byte(char* byte) {
|
||||
int read_length = usb_serial_jtag_read_bytes(byte, 1, 20/ portTICK_PERIOD_MS);
|
||||
return read_length;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by nano on 8/23/26.
|
||||
//
|
||||
|
||||
#ifndef MCU_CODE_USB_SERIAL_H
|
||||
#define MCU_CODE_USB_SERIAL_H
|
||||
|
||||
#define USB_BUFFER_SIZE 1024
|
||||
#include <cstdint>
|
||||
|
||||
namespace usb_serial {
|
||||
static void write(const char* byte, int len);
|
||||
static int read(char* byte,int len);
|
||||
|
||||
static void write_byte(char* byte);
|
||||
static int read_byte(char* byte);
|
||||
static void init();
|
||||
};
|
||||
|
||||
|
||||
#endif //MCU_CODE_USB_SERIAL_H
|
||||
Reference in New Issue
Block a user