Added usb serial
This commit is contained in:
parent
bcf16d2fb9
commit
871fde8d3b
@ -1,2 +1,2 @@
|
||||
idf_component_register(SRCS "mcu-code.cpp"
|
||||
idf_component_register(SRCS mcu-code.cpp peripherals/usb_serial.cpp peripherals/usb_serial.h
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
@ -1,4 +1,20 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "peripherals/usb_serial.h"
|
||||
|
||||
///
|
||||
/// So i lost all the code from the previous version of this due to messing with git.
|
||||
/// I only have a binary file to flash onto the esp for that
|
||||
/// so this is my attempt at reimplementation asap
|
||||
///
|
||||
/// Nicholas - 23/08/2026 @ 21:36
|
||||
///
|
||||
|
||||
const char* test = "amai zeg";
|
||||
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
|
||||
usb_serial::init();
|
||||
usb_serial::write(test,strlen(test));
|
||||
}
|
||||
|
||||
39
main/peripherals/usb_serial.cpp
Normal file
39
main/peripherals/usb_serial.cpp
Normal file
@ -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;
|
||||
}
|
||||
21
main/peripherals/usb_serial.h
Normal file
21
main/peripherals/usb_serial.h
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user