hide constants

This commit is contained in:
Kizarm 2025-01-29 09:59:36 +01:00
parent 08c7c57cef
commit 1b0a6412ea
3 changed files with 22 additions and 21 deletions

View file

@ -1,6 +1,7 @@
#include "system.h" #include "system.h"
#include "oneway.h" #include "oneway.h"
#include "adc.h" #include "adc.h"
typedef __SIZE_TYPE__ size_t;
static AdcDma * pInstance = nullptr; 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 ADC1.CTLR2.B.CAL = SET; // Launch the calibration by setting CAL
while (ADC1.CTLR2.B.CAL != RESET); // Wait until CAL=0 while (ADC1.CTLR2.B.CAL != RESET); // Wait until CAL=0
} }
typedef __SIZE_TYPE__ size_t; static inline void AdcPostInit (void) noexcept {
static inline void Dma1Ch1Init (void * ptr) 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 // Configure the peripheral data register address
DMA1.PADDR1.R = reinterpret_cast<size_t> (& ADC1.RDATAR_DR_ACT_DCG); DMA1.PADDR1.R = reinterpret_cast<size_t> (& ADC1.RDATAR_DR_ACT_DCG);
// Configure the memory address // Configure the memory address
DMA1.MADDR1.R = reinterpret_cast<size_t> (ptr); DMA1.MADDR1.R = reinterpret_cast<size_t> (buffer);
// Configure the number of DMA tranfer to be performs on DMA channel 1 // Configure the number of DMA tranfer to be performs on DMA channel 1
DMA1.CNTR1 .R = FULL_LEN; DMA1.CNTR1 .R = FULL_LEN;
// Configure increment, size, interrupts and circular mode // Configure increment, size, interrupts and circular mode
@ -105,15 +114,6 @@ static inline void Dma1Ch1Init (void * ptr) noexcept {
return r.R; 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) { AdcDma::AdcDma() noexcept : pL (buffer), pH (buffer + HALF_LEN), dst (nullptr) {
pInstance = this; pInstance = this;
@ -121,7 +121,7 @@ AdcDma::AdcDma() noexcept : pL (buffer), pH (buffer + HALF_LEN), dst (nullptr) {
Timer3Init (1000u); Timer3Init (1000u);
NVIC.EnableIRQ (DMA1_Channel1_IRQn); NVIC.EnableIRQ (DMA1_Channel1_IRQn);
AdcCalibrate(); AdcCalibrate();
Dma1Ch1Init (buffer); DmaInit ();
AdcPostInit (); AdcPostInit ();
// start timer // start timer
TIM3.CTLR1.B.CEN = SET; TIM3.CTLR1.B.CEN = SET;

View file

@ -3,10 +3,9 @@
#include <stdint.h> #include <stdint.h>
#include "oneway.h" #include "oneway.h"
class AdcDma {
static constexpr unsigned HALF_LEN = 0x80u; static constexpr unsigned HALF_LEN = 0x80u;
static constexpr unsigned FULL_LEN = HALF_LEN * 2u; static constexpr unsigned FULL_LEN = HALF_LEN * 2u;
class AdcDma {
uint16_t * pL; uint16_t * pL;
uint16_t * pH; uint16_t * pH;
uint16_t buffer [FULL_LEN]; uint16_t buffer [FULL_LEN];
@ -15,6 +14,8 @@ class AdcDma {
explicit AdcDma () noexcept; explicit AdcDma () noexcept;
void attach (OneWay<uint16_t> & d) { dst = & d; } void attach (OneWay<uint16_t> & d) { dst = & d; }
void send (const bool b); void send (const bool b);
protected:
void DmaInit ();
}; };
#endif // ADCDMA_H #endif // ADCDMA_H

View file

@ -4,11 +4,11 @@
#include "ws2812b.h" #include "ws2812b.h"
/** /**
*/ */
class SpiClass {
static constexpr unsigned PADDING = 10 * sizeof (Color); static constexpr unsigned PADDING = 10 * sizeof (Color);
static constexpr unsigned LEDS_LEN = NUMLEDS * sizeof (Color); static constexpr unsigned LEDS_LEN = NUMLEDS * sizeof (Color);
static constexpr unsigned FULL_LEN = PADDING + LEDS_LEN; static constexpr unsigned FULL_LEN = PADDING + LEDS_LEN;
class SpiClass {
OneWay<uint8_t> * driver; OneWay<uint8_t> * driver;
uint8_t * const ptrl; uint8_t * const ptrl;
uint8_t * const ptrh; uint8_t * const ptrh;