prepare to new hardware

This commit is contained in:
Kizarm 2024-11-25 20:38:00 +01:00
parent 503e90b95a
commit 66285cf2a3
8 changed files with 78 additions and 14 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; r.B.DMA1EN = SET;
return r.R; return r.R;
}); });
// Enable ADC + GPIOC // Enable ADC + GPIOA
RCC.APB2PCENR.modify([](RCC_Type::APB2PCENR_DEF & r) -> auto { RCC.APB2PCENR.modify([](RCC_Type::APB2PCENR_DEF & r) -> auto {
r.B.ADC1EN = SET; r.B.ADC1EN = SET;
r.B.IOPAEN = SET; r.B.IOPAEN = SET;
@ -49,12 +49,12 @@ static inline void EnableClock (void) noexcept {
}); });
RCC.APB1PCENR.B.TIM3EN = SET; // Enable TIM3 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). 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 { GPIOA.CFGLR.modify([](GPIOA_Type::CFGLR_DEF & r) -> auto {
r.B.MODE2 = 0u; r.B.MODE0 = 0u;
r.B.CNF2 = 0u; r.B.CNF0 = 0u;
r.B.MODE3 = 0u; r.B.MODE1 = 0u;
r.B.CNF3 = 0u; r.B.CNF1 = 0u;
return r.R; return r.R;
}); });
} }
@ -69,8 +69,8 @@ static inline void AdcCalibrate (void) noexcept {
RCC.APB2PRSTR.B.ADC1RST = SET; RCC.APB2PRSTR.B.ADC1RST = SET;
RCC.APB2PRSTR.B.ADC1RST = RESET; RCC.APB2PRSTR.B.ADC1RST = RESET;
// set channels // set channels
ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 2u; // CH2 ADC1.RSQR3__CHANNEL.B.SQ1__CHSEL = 0u; // CH0
ADC1.RSQR3__CHANNEL.B.SQ2 = 3u; // CH3 ADC1.RSQR3__CHANNEL.B.SQ2 = 1u; // CH1
ADC1.RSQR1.B.L = ADC_MAXCHANNELS - 1U; // 2 regular conversion ADC1.RSQR1.B.L = ADC_MAXCHANNELS - 1U; // 2 regular conversion
static constexpr unsigned ts = 0u; static constexpr unsigned ts = 0u;
ADC1.SAMPTR2_CHARGE2.B.SMP2_TKCG2 = ts; ADC1.SAMPTR2_CHARGE2.B.SMP2_TKCG2 = ts;
@ -150,7 +150,7 @@ void SampleRing::ReloadTimer(const unsigned int n) {
/* *********************************************************************************************/ /* *********************************************************************************************/
void AdcClass::drq() { void AdcClass::drq() {
led << false; led << LED_ON;
DMA1_Type::INTFR_DEF state (DMA1.INTFR); DMA1_Type::INTFR_DEF state (DMA1.INTFR);
DMA1.INTFCR.R = state.R; // clear all DMA1.INTFCR.R = state.R; // clear all
if (state.B.HTIF1 != RESET) { if (state.B.HTIF1 != RESET) {
@ -158,7 +158,7 @@ void AdcClass::drq() {
} else if (state.B.TCIF1 != RESET) { } else if (state.B.TCIF1 != RESET) {
ring.write (ptrh); ring.write (ptrh);
} }
led << true; led << LED_OFF;
} }
extern "C" { extern "C" {
[[gnu::interrupt]] extern void DMA1_Channel1_IRQHandler(); [[gnu::interrupt]] extern void DMA1_Channel1_IRQHandler();

View file

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

View file

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include "samplering.h" #include "samplering.h"
#include "gpio.h" #include "gpio.h"
#include "project_config.h"
/** @file /** @file
* @brief A/D převodník. * @brief A/D převodník.
@ -19,7 +20,7 @@
class AdcClass { class AdcClass {
public: 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. * @brief Inicializace ADC.

View file

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

@ -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_