diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9b4b430..b39485a 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -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 ".") diff --git a/main/mcu-code.cpp b/main/mcu-code.cpp index c7f4a85..6c074a0 100644 --- a/main/mcu-code.cpp +++ b/main/mcu-code.cpp @@ -1,4 +1,20 @@ +#include + +#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)); } diff --git a/main/peripherals/usb_serial.cpp b/main/peripherals/usb_serial.cpp new file mode 100644 index 0000000..7fec531 --- /dev/null +++ b/main/peripherals/usb_serial.cpp @@ -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; +} \ No newline at end of file diff --git a/main/peripherals/usb_serial.h b/main/peripherals/usb_serial.h new file mode 100644 index 0000000..ca9376a --- /dev/null +++ b/main/peripherals/usb_serial.h @@ -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 + +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