Compare commits
2 commits
235fde6cdf
...
1b0a6412ea
Author | SHA1 | Date | |
---|---|---|---|
|
1b0a6412ea | ||
|
08c7c57cef |
4 changed files with 36 additions and 25 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "system.h"
|
||||
#include "oneway.h"
|
||||
#include "adc.h"
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
|
||||
static AdcDma * pInstance = nullptr;
|
||||
|
||||
|
@ -9,10 +10,17 @@ extern "C" {
|
|||
}
|
||||
void DMA1_Channel1_IRQHandler( void ) {
|
||||
DMA1_Type::INTFR_DEF state (DMA1.INTFR);
|
||||
DMA1.INTFCR.R = state.R; // clear all
|
||||
if (!pInstance) return;
|
||||
if (state.B.HTIF1 != RESET) pInstance->send (false);
|
||||
else if (state.B.TCIF1 != RESET) pInstance->send (true);
|
||||
if (state.B.GIF1 != RESET) { // Zřejmě zbytečné, ale pokud používám víc DMA
|
||||
DMA1.INTFCR.B.CGIF1 = SET; // kanálů, pak to tak má být.
|
||||
} else return; // Událost nevznikla pro kanál 1.
|
||||
if (state.B.HTIF1 != RESET) {
|
||||
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 {
|
||||
|
@ -74,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
|
||||
|
@ -98,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;
|
||||
|
@ -114,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
|
||||
|
|
|
@ -41,6 +41,9 @@ static void InitPins () noexcept {
|
|||
void SpiClass::drq() {
|
||||
if (!driver) return;
|
||||
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) {
|
||||
DMA1.INTFCR.B.CHTIF3 = SET; // clear half
|
||||
} */
|
||||
|
|
|
@ -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