hide constants
This commit is contained in:
parent
08c7c57cef
commit
1b0a6412ea
3 changed files with 22 additions and 21 deletions
|
@ -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<size_t> (& ADC1.RDATAR_DR_ACT_DCG);
|
||||
// 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
|
||||
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;
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
#include <stdint.h>
|
||||
#include "oneway.h"
|
||||
|
||||
class AdcDma {
|
||||
static constexpr unsigned HALF_LEN = 0x80u;
|
||||
static constexpr unsigned FULL_LEN = HALF_LEN * 2u;
|
||||
|
||||
class AdcDma {
|
||||
uint16_t * pL;
|
||||
uint16_t * pH;
|
||||
uint16_t buffer [FULL_LEN];
|
||||
|
@ -15,6 +14,8 @@ class AdcDma {
|
|||
explicit AdcDma () noexcept;
|
||||
void attach (OneWay<uint16_t> & d) { dst = & d; }
|
||||
void send (const bool b);
|
||||
protected:
|
||||
void DmaInit ();
|
||||
};
|
||||
|
||||
#endif // ADCDMA_H
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
#include "ws2812b.h"
|
||||
/**
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
class SpiClass {
|
||||
OneWay<uint8_t> * driver;
|
||||
uint8_t * const ptrl;
|
||||
uint8_t * const ptrh;
|
||||
|
|
Loading…
Reference in a new issue