Compare commits

...

2 commits

Author SHA1 Message Date
Kizarm
66285cf2a3 prepare to new hardware 2024-11-25 20:38:00 +01:00
Kizarm
503e90b95a change display 2024-11-17 17:12:36 +01:00
10 changed files with 100 additions and 20 deletions

View file

@ -0,0 +1,15 @@
#ifndef _PROJECT_CONFIG_H_
#define _PROJECT_CONFIG_H_
#define DEVEL_KIT
#ifdef DEVEL_KIT
#define DTR_LED GPIOA,0
#define DRQ_LED GPIOA,1
#define LED_ON false
#define LED_OFF true
#else
#define DTR_LED GPIOB,5
#define DRQ_LED GPIOB,4
#define LED_ON true
#define LED_OFF false
#endif
#endif // _PROJECT_CONFIG_H_

View file

@ -0,0 +1,15 @@
#ifndef _PROJECT_CONFIG_H_
#define _PROJECT_CONFIG_H_
#define DEVEL_KIT
#ifdef DEVEL_KIT
#define DTR_LED GPIOA,0
#define DRQ_LED GPIOA,1
#define LED_ON false
#define LED_OFF true
#else
#define DTR_LED GPIOB,5
#define DRQ_LED GPIOB,4
#define LED_ON true
#define LED_OFF false
#endif
#endif // _PROJECT_CONFIG_H_

View file

@ -41,7 +41,7 @@ static inline void EnableClock (void) noexcept {
r.B.DMA1EN = SET;
return r.R;
});
// Enable ADC + GPIOC
// Enable ADC + GPIOA
RCC.APB2PCENR.modify([](RCC_Type::APB2PCENR_DEF & r) -> auto {
r.B.ADC1EN = SET;
r.B.IOPAEN = SET;
@ -49,12 +49,12 @@ static inline void EnableClock (void) noexcept {
});
RCC.APB1PCENR.B.TIM3EN = SET; // Enable TIM3
RCC.CFGR0.B.ADCPRE = 3u; // PCLK2 divided by 8 as ADC clock (18 MHz, ! pretaktovano 14 MHz max).
// PIN PA2, PA3 / A2,A3
// PIN PA0, PA1 / A0,A1
GPIOA.CFGLR.modify([](GPIOA_Type::CFGLR_DEF & r) -> auto {
r.B.MODE2 = 0u;
r.B.CNF2 = 0u;
r.B.MODE3 = 0u;
r.B.CNF3 = 0u;
r.B.MODE0 = 0u;
r.B.CNF0 = 0u;
r.B.MODE1 = 0u;
r.B.CNF1 = 0u;
return r.R;
});
}
@ -69,8 +69,8 @@ static inline void AdcCalibrate (void) noexcept {
RCC.APB2PRSTR.B.ADC1RST = SET;
RCC.APB2PRSTR.B.ADC1RST = RESET;
// set channels
ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 2u; // CH2
ADC1.RSQR3__CHANNEL.B.SQ2 = 3u; // CH3
ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 0u; // CH0
ADC1.RSQR3__CHANNEL.B.SQ2 = 1u; // CH1
ADC1.RSQR1.B.L = ADC_MAXCHANNELS - 1U; // 2 regular conversion
static constexpr unsigned ts = 0u;
ADC1.SAMPTR2_CHARGE2.B.SMP2_TKCG2 = ts;
@ -150,7 +150,7 @@ void SampleRing::ReloadTimer(const unsigned int n) {
/* *********************************************************************************************/
void AdcClass::drq() {
led << false;
led << LED_ON;
DMA1_Type::INTFR_DEF state (DMA1.INTFR);
DMA1.INTFCR.R = state.R; // clear all
if (state.B.HTIF1 != RESET) {
@ -158,7 +158,7 @@ void AdcClass::drq() {
} else if (state.B.TCIF1 != RESET) {
ring.write (ptrh);
}
led << true;
led << LED_OFF;
}
extern "C" {
[[gnu::interrupt]] extern void DMA1_Channel1_IRQHandler();

View file

@ -1,5 +1,6 @@
#include "cdc_class.h"
#include "system.h"
#include "project_config.h"
typedef __SIZE_TYPE__ size_t;
/* Only one instance of this class ! */
static cdc_class * pInstance = nullptr;
@ -97,11 +98,11 @@ void cdc_class::USBFS_Device_Init( bool sta ) {
USBFSD->BASE_CTRL = 0x00;
NVIC.DisableIRQ( USBFS_IRQn );
}
dtr << true;
dtr << LED_OFF;
}
cdc_class::cdc_class() noexcept : BaseLayer(),
CtrlIface(nullptr), dtr (GPIOA, 0), TxRing(), Ready(false), LineCoding() {
CtrlIface(nullptr), dtr (DTR_LED), TxRing(), Ready(false), LineCoding() {
pInstance = this;
USBFS_DevConfig = 0;
USBFS_DevAddr = 0;
@ -246,7 +247,8 @@ union DtrRts {
if (CtrlIface) CtrlIface->IOCtrl(USB_USART_SET_DTR_RTS, tmp.bytes, 2);
const bool b = USBFS_SetupReqValue & 1;
Ready = b;
dtr << !b;
if (b) dtr << LED_ON;
else dtr << LED_OFF;
} break;
case CDC_SEND_BREAK:

View file

@ -3,6 +3,7 @@
#include <stdint.h>
#include "samplering.h"
#include "gpio.h"
#include "project_config.h"
/** @file
* @brief A/D převodník.
@ -19,7 +20,7 @@
class AdcClass {
public:
AdcClass(SampleRing & r) : ring(r), led(GPIOA, 1), ptrl (buffer), ptrh (buffer + DATA_HALF_LEN) {
AdcClass(SampleRing & r) : ring(r), led(DRQ_LED), ptrl (buffer), ptrh (buffer + DATA_HALF_LEN) {
};
/**
* @brief Inicializace ADC.

View file

@ -17,9 +17,11 @@
static SampleRing ring;
static AdcClass adc (ring);
static cdc_class cdc;
static GpioClass power(GPIOB, 3);
int main () {
cdc.init();
power << true;
adc.Init();
ring += cdc;
for (;;) {

View file

@ -0,0 +1,14 @@
#ifndef _PROJECT_CONFIG_H_
#define _PROJECT_CONFIG_H_
#ifdef DEVEL_KIT
#define DTR_LED GPIOA,0
#define DRQ_LED GPIOA,1
#define LED_ON false
#define LED_OFF true
#else
#define DTR_LED GPIOB,5
#define DRQ_LED GPIOB,4
#define LED_ON true
#define LED_OFF false
#endif
#endif // _PROJECT_CONFIG_H_

View file

@ -11,6 +11,10 @@ static const double TimeBaseSteps [] = {
2.0e-6, 5.0e-6, 1.0e-5, 2.0e-5, 5.0e-5, 1.0e-4, 2.0e-4, 5.0e-4, 1.0e-3,
2.0e-3, 5.0e-3, 1.0e-2, 2.0e-2, 5.0e-2, 1.0e-1, 2.0e-1, 5.0e-1, 1.0,
};
static const int TimeBaseCounts [] = {
0, 0, 0, 0, 0, 0, 0, 0, 10,
5, 2, 1, 1, 1, 1, 1, 1, 1,
};
static const double ChannelsSteps [] = {
0.1, 0.2, 0.5,
1.0, 2.0, 5.0,
@ -41,7 +45,9 @@ DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), pcol(), ACopy(), BCopy()
for (QPointF & e : ChA) { const QPointF p (n++, 0); e = p; }
n = 0;
for (QPointF & e : ChB) { const QPointF p (n++, 0); e = p; }
m_continual = false;
m_continual = false;
m_cont_limit = 0;
m_cont_pass = 0;
}
DisplayWidget::~DisplayWidget() {
}
@ -189,10 +195,9 @@ void DisplayWidget::setTrigger(TrigerSettings * ts) {
void DisplayWidget::DispChannels(QVector<int> cha, QVector<int> chb) {
ACopy = cha;
BCopy = chb;
reloadData();
update();
if (reloadData()) update();
}
void DisplayWidget::reloadData () {
bool DisplayWidget::reloadData () {
const size_t Alen = ACopy.size();
const size_t Blen = BCopy.size();
const size_t Amin = Alen < T_SIZE ? Alen : T_SIZE;
@ -204,7 +209,13 @@ void DisplayWidget::reloadData () {
ChB[m_timeCount] = ptb;
m_timeCount += 1u;
m_timeCount &= T_MASK;
return;
m_cont_pass += 1;
if (m_cont_pass >= m_cont_limit) {
m_cont_pass = 0;
return true;
} else {
return false;
}
}
m_continual = false;
for (unsigned n=0u; n<Amin; n++) {
@ -220,6 +231,7 @@ void DisplayWidget::reloadData () {
x_lenght = l;
reloadMatrix (size());
}
return true;
}
void DisplayWidget::reloadMatrix(const QSize & sz) {
const double xm = sz.width();
@ -232,6 +244,8 @@ void DisplayWidget::reloadMatrix(const QSize & sz) {
}
void DisplayWidget::TimeBaseRange(int n) {
m_timeBase = n;
m_cont_limit = TimeBaseCounts [m_timeBase];
//qDebug("count = %d", m_cont_limit);
reloadMatrix (size());
drawBackground();
update();

View file

@ -46,6 +46,8 @@ class DisplayWidget : public QWidget {
} marker_type;
unsigned m_timeCount;
bool m_continual;
int m_cont_limit;
int m_cont_pass;
public:
explicit DisplayWidget (QWidget * p);
virtual ~DisplayWidget ();
@ -71,7 +73,7 @@ class DisplayWidget : public QWidget {
protected:
void drawCurrent (QPainter & p);
void drawBackground ();
void reloadData ();
bool reloadData ();
void reloadMatrix (const QSize & sz);
};

View file

@ -0,0 +1,15 @@
#ifndef _PROJECT_CONFIG_H_
#define _PROJECT_CONFIG_H_
#define DEVEL_KIT
#ifdef DEVEL_KIT
#define DTR_LED GPIOA,0
#define DRQ_LED GPIOA,1
#define LED_ON false
#define LED_OFF true
#else
#define DTR_LED GPIOB,5
#define DRQ_LED GPIOB,4
#define LED_ON true
#define LED_OFF false
#endif
#endif // _PROJECT_CONFIG_H_