Compare commits

..

No commits in common. "1b0a6412eab0994c8d33d4fd919fe05fe8b1694b" and "235fde6cdfae089775d4ba99991ca8f51a75f27c" have entirely different histories.

4 changed files with 25 additions and 36 deletions

View file

@ -1,7 +1,6 @@
#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;
@ -10,17 +9,10 @@ extern "C" {
} }
void DMA1_Channel1_IRQHandler( void ) { void DMA1_Channel1_IRQHandler( void ) {
DMA1_Type::INTFR_DEF state (DMA1.INTFR); DMA1_Type::INTFR_DEF state (DMA1.INTFR);
if (state.B.GIF1 != RESET) { // Zřejmě zbytečné, ale pokud používám víc DMA DMA1.INTFCR.R = state.R; // clear all
DMA1.INTFCR.B.CGIF1 = SET; // kanálů, pak to tak má být. if (!pInstance) return;
} else return; // Událost nevznikla pro kanál 1. if (state.B.HTIF1 != RESET) pInstance->send (false);
if (state.B.HTIF1 != RESET) { else if (state.B.TCIF1 != RESET) pInstance->send (true);
DMA1.INTFCR.B.CHTIF1 = SET;
if (pInstance) pInstance->send (false);
}
if (state.B.TCIF1 != RESET) {
DMA1.INTFCR.B.CTCIF1 = SET;
if (pInstance) pInstance->send (true);
}
} }
static inline void EnableClock (void) noexcept { static inline void EnableClock (void) noexcept {
@ -82,20 +74,12 @@ 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
} }
static inline void AdcPostInit (void) noexcept { typedef __SIZE_TYPE__ size_t;
ADC1.CTLR2.modify([](ADC1_Type::CTLR2_DEF & r) -> auto { static inline void Dma1Ch1Init (void * ptr) noexcept {
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> (buffer); DMA1.MADDR1.R = reinterpret_cast<size_t> (ptr);
// 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
@ -114,6 +98,15 @@ inline void AdcDma::DmaInit () {
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 +114,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();
DmaInit (); Dma1Ch1Init (buffer);
AdcPostInit (); AdcPostInit ();
// start timer // start timer
TIM3.CTLR1.B.CEN = SET; TIM3.CTLR1.B.CEN = SET;

View file

@ -3,9 +3,10 @@
#include <stdint.h> #include <stdint.h>
#include "oneway.h" #include "oneway.h"
static constexpr unsigned HALF_LEN = 0x80u;
static constexpr unsigned FULL_LEN = HALF_LEN * 2u;
class AdcDma { class AdcDma {
static constexpr unsigned HALF_LEN = 0x80u;
static constexpr unsigned FULL_LEN = HALF_LEN * 2u;
uint16_t * pL; uint16_t * pL;
uint16_t * pH; uint16_t * pH;
uint16_t buffer [FULL_LEN]; uint16_t buffer [FULL_LEN];
@ -13,9 +14,7 @@ class AdcDma {
public: public:
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

@ -41,9 +41,6 @@ static void InitPins () noexcept {
void SpiClass::drq() { void SpiClass::drq() {
if (!driver) return; if (!driver) return;
DMA1_Type::INTFR_DEF state (DMA1.INTFR); DMA1_Type::INTFR_DEF state (DMA1.INTFR);
if (state.B.GIF3 != RESET) { // Zřejmě zbytečné, ale pokud používám víc DMA
DMA1.INTFCR.B.CGIF3 = SET; // kanálů, pak to tak má být.
} else return; // Událost nevznikla pro kanál 1.
/*if (state.B.HTIF3) { /*if (state.B.HTIF3) {
DMA1.INTFCR.B.CHTIF3 = SET; // clear half DMA1.INTFCR.B.CHTIF3 = SET; // clear half
} */ } */

View file

@ -4,15 +4,15 @@
#include "ws2812b.h" #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 { 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<uint8_t> * driver; OneWay<uint8_t> * driver;
uint8_t * const ptrl; uint8_t * const ptrl;
uint8_t * const ptrh; uint8_t * const ptrh;
uint8_t buffer [FULL_LEN]; uint8_t buffer [FULL_LEN];
public: public:
explicit SpiClass (OneWay<uint8_t> & base) noexcept; explicit SpiClass (OneWay<uint8_t> & base) noexcept;
void Init (); void Init ();