From 1b0a6412eab0994c8d33d4fd919fe05fe8b1694b Mon Sep 17 00:00:00 2001 From: Kizarm Date: Wed, 29 Jan 2025 09:59:36 +0100 Subject: [PATCH] hide constants --- V203F6P6/termistor/adc.cpp | 26 +++++++++++++------------- V203F6P6/termistor/adc.h | 9 +++++---- V203F6P6/ws2812b/spiclass.h | 8 ++++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/V203F6P6/termistor/adc.cpp b/V203F6P6/termistor/adc.cpp index 6175fd5..f680bfd 100644 --- a/V203F6P6/termistor/adc.cpp +++ b/V203F6P6/termistor/adc.cpp @@ -1,6 +1,7 @@ #include "system.h" #include "oneway.h" #include "adc.h" +typedef __SIZE_TYPE__ size_t; static AdcDma * pInstance = nullptr; @@ -81,12 +82,20 @@ static inline void AdcCalibrate (void) noexcept { ADC1.CTLR2.B.CAL = SET; // Launch the calibration by setting CAL while (ADC1.CTLR2.B.CAL != RESET); // Wait until CAL=0 } -typedef __SIZE_TYPE__ size_t; -static inline void Dma1Ch1Init (void * ptr) noexcept { +static inline void AdcPostInit (void) noexcept { + ADC1.CTLR2.modify([](ADC1_Type::CTLR2_DEF & r) -> auto { + r.B.DMA = SET; + r.B.EXTTRIG = SET; + r.B.EXTSEL = 4u; // TRGO event of timer 3 + r.B.SWSTART = SET; + return r.R; + }); +} +inline void AdcDma::DmaInit () { // Configure the peripheral data register address DMA1.PADDR1.R = reinterpret_cast (& ADC1.RDATAR_DR_ACT_DCG); // Configure the memory address - DMA1.MADDR1.R = reinterpret_cast (ptr); + DMA1.MADDR1.R = reinterpret_cast (buffer); // Configure the number of DMA tranfer to be performs on DMA channel 1 DMA1.CNTR1 .R = FULL_LEN; // Configure increment, size, interrupts and circular mode @@ -105,15 +114,6 @@ static inline void Dma1Ch1Init (void * ptr) noexcept { return r.R; }); } -static inline void AdcPostInit (void) noexcept { - ADC1.CTLR2.modify([](ADC1_Type::CTLR2_DEF & r) -> auto { - r.B.DMA = SET; - r.B.EXTTRIG = SET; - r.B.EXTSEL = 4u; // TRGO event of timer 3 - r.B.SWSTART = SET; - return r.R; - }); -} //////////////////////////////////////////////////////////////////////////////////// AdcDma::AdcDma() noexcept : pL (buffer), pH (buffer + HALF_LEN), dst (nullptr) { pInstance = this; @@ -121,7 +121,7 @@ AdcDma::AdcDma() noexcept : pL (buffer), pH (buffer + HALF_LEN), dst (nullptr) { Timer3Init (1000u); NVIC.EnableIRQ (DMA1_Channel1_IRQn); AdcCalibrate(); - Dma1Ch1Init (buffer); + DmaInit (); AdcPostInit (); // start timer TIM3.CTLR1.B.CEN = SET; diff --git a/V203F6P6/termistor/adc.h b/V203F6P6/termistor/adc.h index a8166e6..a8f714a 100644 --- a/V203F6P6/termistor/adc.h +++ b/V203F6P6/termistor/adc.h @@ -3,10 +3,9 @@ #include #include "oneway.h" -static constexpr unsigned HALF_LEN = 0x80u; -static constexpr unsigned FULL_LEN = HALF_LEN * 2u; - class AdcDma { + static constexpr unsigned HALF_LEN = 0x80u; + static constexpr unsigned FULL_LEN = HALF_LEN * 2u; uint16_t * pL; uint16_t * pH; uint16_t buffer [FULL_LEN]; @@ -14,7 +13,9 @@ class AdcDma { public: explicit AdcDma () noexcept; void attach (OneWay & d) { dst = & d; } - void send (const bool b); + void send (const bool b); + protected: + void DmaInit (); }; #endif // ADCDMA_H diff --git a/V203F6P6/ws2812b/spiclass.h b/V203F6P6/ws2812b/spiclass.h index 52bdcd0..f75e6e5 100644 --- a/V203F6P6/ws2812b/spiclass.h +++ b/V203F6P6/ws2812b/spiclass.h @@ -4,15 +4,15 @@ #include "ws2812b.h" /** */ -static constexpr unsigned PADDING = 10 * sizeof (Color); -static constexpr unsigned LEDS_LEN = NUMLEDS * sizeof (Color); -static constexpr unsigned FULL_LEN = PADDING + LEDS_LEN; class SpiClass { + static constexpr unsigned PADDING = 10 * sizeof (Color); + static constexpr unsigned LEDS_LEN = NUMLEDS * sizeof (Color); + static constexpr unsigned FULL_LEN = PADDING + LEDS_LEN; OneWay * driver; uint8_t * const ptrl; uint8_t * const ptrh; - uint8_t buffer [FULL_LEN]; + uint8_t buffer [FULL_LEN]; public: explicit SpiClass (OneWay & base) noexcept; void Init ();