From 65515c7eca0a3ad28d3c4d917a752a73c43112d6 Mon Sep 17 00:00:00 2001 From: Kizarm Date: Sun, 2 Feb 2025 10:22:48 +0100 Subject: [PATCH] termistor output to usb --- V203F6P6/termistor/Makefile | 6 +-- V203F6P6/termistor/main.cpp | 5 ++- V203F6P6/termistor/main.h | 2 +- V203F6P6/termistor/usb_desc.cpp | 80 +++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 V203F6P6/termistor/usb_desc.cpp diff --git a/V203F6P6/termistor/Makefile b/V203F6P6/termistor/Makefile index 73c56a8..e91ab83 100644 --- a/V203F6P6/termistor/Makefile +++ b/V203F6P6/termistor/Makefile @@ -9,15 +9,15 @@ VPATH = . ./$(TARGET) ./common BLD = ./build/ DFLAGS = -d LFLAGS = -g -LDLIBS = +LDLIBS = -L./$(TARGET)/usbd -lusbd BFLAGS = --strip-unneeded CFLAGS = -MMD -Wall -Wno-parentheses -ggdb -fno-exceptions -ffunction-sections -fdata-sections -CFLAGS+= -I. -I./$(TARGET) -I./common +CFLAGS+= -I. -I./$(TARGET) -I./$(TARGET)/usbd -I./common DEL = rm -f # zdrojaky -OBJS = main.o usart.o adc.o hack.o +OBJS = main.o usb_desc.o adc.o hack.o #OBJS += include $(TARGET)/$(TOOL).mk diff --git a/V203F6P6/termistor/main.cpp b/V203F6P6/termistor/main.cpp index 5f15cfb..20e085a 100644 --- a/V203F6P6/termistor/main.cpp +++ b/V203F6P6/termistor/main.cpp @@ -26,6 +26,8 @@ * Ukazuje se, že to sice funguje, ale ADC pak dost kecá - nějak mu tam to zvýšené * napětí proniká. Stačí pak přizemnit Rx procesoru (PA3) přes odpor 1.5 až 2k a problém * zmizí. + * + * 02.02.25 - výstup předělán na USB CDC (protože to jde, ne že by to mělo smysl). **********************************************************************************/ static constexpr Pair measured [] = { // pár hodnota ADC, teplota ve °C { +133.9, 125.000 }, @@ -50,7 +52,7 @@ static constexpr Pair measured [] = { // pár hodnota ADC, teplota ve °C /*********************************************************************************/ static FIFO termring; static const GpioClass led (GPIOB, 8); -static Usart serial (57600); +static cdc_class serial; static RealOut cout; static AdcDma adc; static Average avg (termring); @@ -58,6 +60,7 @@ static const SPLINE spline (measured, false); int main () { led << true; + serial.init(); adc.attach(avg); cout += serial; int passcnt = 0; diff --git a/V203F6P6/termistor/main.h b/V203F6P6/termistor/main.h index 762f70e..bde170c 100644 --- a/V203F6P6/termistor/main.h +++ b/V203F6P6/termistor/main.h @@ -2,7 +2,7 @@ #define MAIN_H_DEF #include "system.h" #include "gpio.h" -#include "usart.h" +#include "cdc_class.h" #include "adc.h" #include "spline.h" static constexpr unsigned FIFOLEN = 8u; diff --git a/V203F6P6/termistor/usb_desc.cpp b/V203F6P6/termistor/usb_desc.cpp new file mode 100644 index 0000000..f73625f --- /dev/null +++ b/V203F6P6/termistor/usb_desc.cpp @@ -0,0 +1,80 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : usb_desc.c + * Author : WCH + * Version : V1.0.0 + * Date : 2022/08/20 + * Description : usb device descriptor,configuration descriptor, + * string descriptors and other descriptors. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "usb_desc.h" + +/* Device Descriptor */ +const uint8_t USBD_DeviceDescriptor[] = +{ + 0x12, // bLength + 0x01, // bDescriptorType (Device) + 0x10, 0x01, // bcdUSB 1.10 + 0x02, // bDeviceClass + 0x00, // bDeviceSubClass + 0x00, // bDeviceProtocol + DEF_USBD_UEP0_SIZE, // bMaxPacketSize0 64 + (uint8_t)DEF_USB_VID, (uint8_t)(DEF_USB_VID >> 8), // idVendor 0x1A86 + (uint8_t)DEF_USB_PID, (uint8_t)(DEF_USB_PID >> 8), // idProduct 0x5537 + DEF_IC_PRG_VER, 0x00, // bcdDevice 0.01 + 0x01, // iManufacturer (String Index) + 0x02, // iProduct (String Index) + 0x03, // iSerialNumber (String Index) + 0x01, // bNumConfigurations 1 +}; + +/* Configuration Descriptor */ +const uint8_t USBD_ConfigDescriptor[] = +{ + /* Configure descriptor */ + 0x09, 0x02, 0x43, 0x00, 0x02, 0x01, 0x00, 0x80, 0x32, + + /* Interface 0 (CDC) descriptor */ + 0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00, + + /* Functional Descriptors */ + 0x05, 0x24, 0x00, 0x10, 0x01, + + /* Length/management descriptor (data class interface 1) */ + 0x05, 0x24, 0x01, 0x00, 0x01, + 0x04, 0x24, 0x02, 0x02, + 0x05, 0x24, 0x06, 0x00, 0x01, + + /* Interrupt upload endpoint descriptor */ + 0x07, 0x05, 0x81, 0x03, (uint8_t)DEF_USBD_ENDP1_SIZE, (uint8_t)( DEF_USBD_ENDP1_SIZE >> 8 ), 0x01, + + /* Interface 1 (data interface) descriptor */ + 0x09, 0x04, 0x01, 0x00, 0x02, 0x0A, 0x00, 0x00, 0x00, + + /* Endpoint descriptor */ + 0x07, 0x05, 0x02, 0x02, (uint8_t)DEF_USBD_ENDP2_SIZE, (uint8_t)( DEF_USBD_ENDP2_SIZE >> 8 ), 0x00, + + /* Endpoint descriptor */ + 0x07, 0x05, 0x83, 0x02, (uint8_t)DEF_USBD_ENDP3_SIZE, (uint8_t)( DEF_USBD_ENDP3_SIZE >> 8 ), 0x00, +}; +#define DEF_STRDESC(p,n) w_text<(sizeof(p)>>1)>n={sizeof(n)-2u,3u,{p}} +template struct w_text { + uint8_t len, typ; + const char16_t str [N]; +}; +static const DEF_STRDESC((u"Kizarm Labs."), str_1); +static const DEF_STRDESC((u"USB Termistor"),str_2); +static const DEF_STRDESC((u"0001"), str_3); +/* Language Descriptor */ +static const uint8_t LangDescr[] = { + 0x04, 0x03, 0x09, 0x04 +}; +const uint8_t * USBD_StringLangID = reinterpret_cast(LangDescr); +const uint8_t * USBD_StringVendor = reinterpret_cast(&str_1); +const uint8_t * USBD_StringProduct = reinterpret_cast(&str_2); +const uint8_t * USBD_StringSerial = reinterpret_cast(&str_3); +