From 66285cf2a3951e6c1179d83092373f372b87c67b Mon Sep 17 00:00:00 2001 From: Kizarm Date: Mon, 25 Nov 2024 20:38:00 +0100 Subject: [PATCH] prepare to new hardware --- V203/usb/adc/project_config.h | 15 +++++++++++++++ V203/usb/cdc/project_config.h | 15 +++++++++++++++ V203/usb/ch32v203/adcscope.cpp | 20 ++++++++++---------- V203/usb/ch32v203/cdc_class.cpp | 8 +++++--- V203/usb/common/adcscope.h | 3 ++- V203/usb/scope/firmware/main.cpp | 2 ++ V203/usb/scope/firmware/project_config.h | 14 ++++++++++++++ V203/usb/usart/project_config.h | 15 +++++++++++++++ 8 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 V203/usb/adc/project_config.h create mode 100644 V203/usb/cdc/project_config.h create mode 100644 V203/usb/scope/firmware/project_config.h create mode 100644 V203/usb/usart/project_config.h diff --git a/V203/usb/adc/project_config.h b/V203/usb/adc/project_config.h new file mode 100644 index 0000000..9bdeb8e --- /dev/null +++ b/V203/usb/adc/project_config.h @@ -0,0 +1,15 @@ +#ifndef _PROJECT_CONFIG_H_ +#define _PROJECT_CONFIG_H_ +#define DEVEL_KIT +#ifdef DEVEL_KIT +#define DTR_LED GPIOA,0 +#define DRQ_LED GPIOA,1 +#define LED_ON false +#define LED_OFF true +#else +#define DTR_LED GPIOB,5 +#define DRQ_LED GPIOB,4 +#define LED_ON true +#define LED_OFF false +#endif +#endif // _PROJECT_CONFIG_H_ diff --git a/V203/usb/cdc/project_config.h b/V203/usb/cdc/project_config.h new file mode 100644 index 0000000..9bdeb8e --- /dev/null +++ b/V203/usb/cdc/project_config.h @@ -0,0 +1,15 @@ +#ifndef _PROJECT_CONFIG_H_ +#define _PROJECT_CONFIG_H_ +#define DEVEL_KIT +#ifdef DEVEL_KIT +#define DTR_LED GPIOA,0 +#define DRQ_LED GPIOA,1 +#define LED_ON false +#define LED_OFF true +#else +#define DTR_LED GPIOB,5 +#define DRQ_LED GPIOB,4 +#define LED_ON true +#define LED_OFF false +#endif +#endif // _PROJECT_CONFIG_H_ diff --git a/V203/usb/ch32v203/adcscope.cpp b/V203/usb/ch32v203/adcscope.cpp index d9d02f0..9689970 100644 --- a/V203/usb/ch32v203/adcscope.cpp +++ b/V203/usb/ch32v203/adcscope.cpp @@ -41,7 +41,7 @@ static inline void EnableClock (void) noexcept { r.B.DMA1EN = SET; return r.R; }); - // Enable ADC + GPIOC + // Enable ADC + GPIOA RCC.APB2PCENR.modify([](RCC_Type::APB2PCENR_DEF & r) -> auto { r.B.ADC1EN = SET; r.B.IOPAEN = SET; @@ -49,12 +49,12 @@ static inline void EnableClock (void) noexcept { }); RCC.APB1PCENR.B.TIM3EN = SET; // Enable TIM3 RCC.CFGR0.B.ADCPRE = 3u; // PCLK2 divided by 8 as ADC clock (18 MHz, ! pretaktovano 14 MHz max). - // PIN PA2, PA3 / A2,A3 + // PIN PA0, PA1 / A0,A1 GPIOA.CFGLR.modify([](GPIOA_Type::CFGLR_DEF & r) -> auto { - r.B.MODE2 = 0u; - r.B.CNF2 = 0u; - r.B.MODE3 = 0u; - r.B.CNF3 = 0u; + r.B.MODE0 = 0u; + r.B.CNF0 = 0u; + r.B.MODE1 = 0u; + r.B.CNF1 = 0u; return r.R; }); } @@ -69,8 +69,8 @@ static inline void AdcCalibrate (void) noexcept { RCC.APB2PRSTR.B.ADC1RST = SET; RCC.APB2PRSTR.B.ADC1RST = RESET; // set channels - ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 2u; // CH2 - ADC1.RSQR3__CHANNEL.B.SQ2 = 3u; // CH3 + ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 0u; // CH0 + ADC1.RSQR3__CHANNEL.B.SQ2 = 1u; // CH1 ADC1.RSQR1.B.L = ADC_MAXCHANNELS - 1U; // 2 regular conversion static constexpr unsigned ts = 0u; ADC1.SAMPTR2_CHARGE2.B.SMP2_TKCG2 = ts; @@ -150,7 +150,7 @@ void SampleRing::ReloadTimer(const unsigned int n) { /* *********************************************************************************************/ void AdcClass::drq() { - led << false; + led << LED_ON; DMA1_Type::INTFR_DEF state (DMA1.INTFR); DMA1.INTFCR.R = state.R; // clear all if (state.B.HTIF1 != RESET) { @@ -158,7 +158,7 @@ void AdcClass::drq() { } else if (state.B.TCIF1 != RESET) { ring.write (ptrh); } - led << true; + led << LED_OFF; } extern "C" { [[gnu::interrupt]] extern void DMA1_Channel1_IRQHandler(); diff --git a/V203/usb/ch32v203/cdc_class.cpp b/V203/usb/ch32v203/cdc_class.cpp index ce062f6..15bd127 100644 --- a/V203/usb/ch32v203/cdc_class.cpp +++ b/V203/usb/ch32v203/cdc_class.cpp @@ -1,5 +1,6 @@ #include "cdc_class.h" #include "system.h" +#include "project_config.h" typedef __SIZE_TYPE__ size_t; /* Only one instance of this class ! */ static cdc_class * pInstance = nullptr; @@ -97,11 +98,11 @@ void cdc_class::USBFS_Device_Init( bool sta ) { USBFSD->BASE_CTRL = 0x00; NVIC.DisableIRQ( USBFS_IRQn ); } - dtr << true; + dtr << LED_OFF; } cdc_class::cdc_class() noexcept : BaseLayer(), - CtrlIface(nullptr), dtr (GPIOA, 0), TxRing(), Ready(false), LineCoding() { + CtrlIface(nullptr), dtr (DTR_LED), TxRing(), Ready(false), LineCoding() { pInstance = this; USBFS_DevConfig = 0; USBFS_DevAddr = 0; @@ -246,7 +247,8 @@ union DtrRts { if (CtrlIface) CtrlIface->IOCtrl(USB_USART_SET_DTR_RTS, tmp.bytes, 2); const bool b = USBFS_SetupReqValue & 1; Ready = b; - dtr << !b; + if (b) dtr << LED_ON; + else dtr << LED_OFF; } break; case CDC_SEND_BREAK: diff --git a/V203/usb/common/adcscope.h b/V203/usb/common/adcscope.h index 898b889..ee1c4b8 100644 --- a/V203/usb/common/adcscope.h +++ b/V203/usb/common/adcscope.h @@ -3,6 +3,7 @@ #include #include "samplering.h" #include "gpio.h" +#include "project_config.h" /** @file * @brief A/D převodník. @@ -19,7 +20,7 @@ class AdcClass { public: - AdcClass(SampleRing & r) : ring(r), led(GPIOA, 1), ptrl (buffer), ptrh (buffer + DATA_HALF_LEN) { + AdcClass(SampleRing & r) : ring(r), led(DRQ_LED), ptrl (buffer), ptrh (buffer + DATA_HALF_LEN) { }; /** * @brief Inicializace ADC. diff --git a/V203/usb/scope/firmware/main.cpp b/V203/usb/scope/firmware/main.cpp index 678111b..0571a3f 100644 --- a/V203/usb/scope/firmware/main.cpp +++ b/V203/usb/scope/firmware/main.cpp @@ -17,9 +17,11 @@ static SampleRing ring; static AdcClass adc (ring); static cdc_class cdc; +static GpioClass power(GPIOB, 3); int main () { cdc.init(); + power << true; adc.Init(); ring += cdc; for (;;) { diff --git a/V203/usb/scope/firmware/project_config.h b/V203/usb/scope/firmware/project_config.h new file mode 100644 index 0000000..605c20e --- /dev/null +++ b/V203/usb/scope/firmware/project_config.h @@ -0,0 +1,14 @@ +#ifndef _PROJECT_CONFIG_H_ +#define _PROJECT_CONFIG_H_ +#ifdef DEVEL_KIT +#define DTR_LED GPIOA,0 +#define DRQ_LED GPIOA,1 +#define LED_ON false +#define LED_OFF true +#else +#define DTR_LED GPIOB,5 +#define DRQ_LED GPIOB,4 +#define LED_ON true +#define LED_OFF false +#endif +#endif // _PROJECT_CONFIG_H_ diff --git a/V203/usb/usart/project_config.h b/V203/usb/usart/project_config.h new file mode 100644 index 0000000..9bdeb8e --- /dev/null +++ b/V203/usb/usart/project_config.h @@ -0,0 +1,15 @@ +#ifndef _PROJECT_CONFIG_H_ +#define _PROJECT_CONFIG_H_ +#define DEVEL_KIT +#ifdef DEVEL_KIT +#define DTR_LED GPIOA,0 +#define DRQ_LED GPIOA,1 +#define LED_ON false +#define LED_OFF true +#else +#define DTR_LED GPIOB,5 +#define DRQ_LED GPIOB,4 +#define LED_ON true +#define LED_OFF false +#endif +#endif // _PROJECT_CONFIG_H_