This commit is contained in:
Markus Koch 2021-02-24 20:57:00 +01:00
parent cac80f1c65
commit 5e93258f5e
6 changed files with 33 additions and 15 deletions

View File

@ -30,7 +30,7 @@ void adc_init()
// Set up timer // Set up timer
TIM_TimeBaseInitTypeDef Timer_InitStruct; TIM_TimeBaseInitTypeDef Timer_InitStruct;
TIM_TimeBaseStructInit(&Timer_InitStruct); TIM_TimeBaseStructInit(&Timer_InitStruct);
Timer_InitStruct.TIM_Prescaler = 0; Timer_InitStruct.TIM_Prescaler = 0x0;
Timer_InitStruct.TIM_CounterMode = TIM_CounterMode_Up; Timer_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
Timer_InitStruct.TIM_Period = (ADC_F_TIM / ADC_SAMPLE_RATE); Timer_InitStruct.TIM_Period = (ADC_F_TIM / ADC_SAMPLE_RATE);
Timer_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1; Timer_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
@ -136,11 +136,15 @@ void adc_init()
} }
void DMA2_Stream0_IRQHandler() void DMA2_Stream0_IRQHandler()
{ {
int sample; int sample;
DMA_ClearFlag(ADC_RX_DMA_STREAM, DMA_FLAG_TCIF0); DMA_ClearFlag(ADC_RX_DMA_STREAM, DMA_FLAG_TCIF0);
//printf("[DMA-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]); //printf("[DMA-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
sample = 2048 - ((adc_buffer[0] + adc_buffer[1]) / 2); //sample = 2048 - ((adc_buffer[0] + adc_buffer[1]) / 2);
sample = 2048 - adc_buffer[0];
//printf("ADC0: %4d, ADC1: %4d, SMP: %4d\r\n",
// adc_buffer[0], adc_buffer[1], sample);
GotSample(sample); GotSample(sample);
} }
@ -155,5 +159,12 @@ void TIM5_IRQHandler()
{ {
TIM_ClearFlag(TIM5, TIM_FLAG_CC1); TIM_ClearFlag(TIM5, TIM_FLAG_CC1);
// I would really like to this in HW via events, but somehow it's broken... // I would really like to this in HW via events, but somehow it's broken...
/*static int s=0;
s=!s;
if (s) {
LED_ON2;
} else {
LED_OFF2;
}*/
ADC_SoftwareStartConv(ADC1); ADC_SoftwareStartConv(ADC1);
} }

View File

@ -2,7 +2,7 @@
#define _ADC_H #define _ADC_H
#define ADC_F_TIM 50000000 #define ADC_F_TIM 50000000
#define ADC_SAMPLE_RATE 44130 #define ADC_SAMPLE_RATE (40000)
#define ADC_RX_DMA_CHANNEL DMA_Channel_0 #define ADC_RX_DMA_CHANNEL DMA_Channel_0

View File

@ -4,7 +4,7 @@
#define CCEMBEDDED #define CCEMBEDDED
#define NUM_LIN_LEDS 60 #define NUM_LIN_LEDS 60
#define USE_NUM_LIN_LEDS 60 #define USE_NUM_LIN_LEDS 60
#define DFREQ 44130 #define DFREQ (40000)
#endif #endif

View File

@ -168,7 +168,8 @@ void ConfigureUART()
void ConfigureLED() void ConfigureLED()
{ {
ConfigureGPIO( LEDPIN, INOUT_OUT ); ConfigureGPIO(LEDPIN, INOUT_OUT);
ConfigureGPIO(LEDPIN2, INOUT_OUT);
} }
uint8_t GetGPIOFromString( const char * str ) uint8_t GetGPIOFromString( const char * str )

View File

@ -51,6 +51,7 @@ void ConfigureGPIO( gpio gpio, int parameters );
#define LEDPIN 0x18 #define LEDPIN 0x18
#elif defined( STM32F40_41xxx ) #elif defined( STM32F40_41xxx )
#define LEDPIN (16+14) #define LEDPIN (16+14)
#define LEDPIN2 (16+13)
#endif #endif
void ConfigureUART(); void ConfigureUART();
@ -60,6 +61,9 @@ void ConfigureLED();
#define LED_ON GPIOOn(LEDPIN) #define LED_ON GPIOOn(LEDPIN)
#define LED_OFF GPIOOff(LEDPIN) #define LED_OFF GPIOOff(LEDPIN)
#define LED_ON2 GPIOOn(LEDPIN2)
#define LED_OFF2 GPIOOff(LEDPIN2)
#endif #endif

View File

@ -31,6 +31,12 @@ void GotSample( int samp )
sampbuff[last_samp_pos] = samp; sampbuff[last_samp_pos] = samp;
last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE); last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE);
samples++; samples++;
if (samp > 128) {
LED_ON2;
} else {
LED_OFF2;
}
} }
//Call this once we've stacked together one full colorchord frame. //Call this once we've stacked together one full colorchord frame.
@ -40,8 +46,8 @@ void NewFrame()
int i; int i;
HandleFrameInfo(); HandleFrameInfo();
// UpdateLinearLEDs(); UpdateLinearLEDs();
UpdateAllSameLEDs(); //UpdateAllSameLEDs();
SendSPI2812( ledOut, NUM_LIN_LEDS ); SendSPI2812( ledOut, NUM_LIN_LEDS );
} }
@ -116,14 +122,10 @@ int main(void)
SysTick_Config( RCC_Clocks.HCLK_Frequency / 100); SysTick_Config( RCC_Clocks.HCLK_Frequency / 100);
float fv = RCC_Clocks.HCLK_Frequency / 1000000.0f; float fv = RCC_Clocks.HCLK_Frequency / 1000000.0f;
// We can use printf to print back through the debugging interface, but that's slow and
// it also takes up a bunch of space. No printf = no space wasted in printf.
// printf( "Operating at %.3fMHz\n", fv );
ConfigureUART(); ConfigureUART();
InitColorChord(); InitColorChord();
Configure_PA0(); Configure_PA0();
//InitMP45DT02();
InitSPI2812(); InitSPI2812();
adc_init(); adc_init();
@ -132,8 +134,8 @@ int main(void)
int this_samp = 0; int this_samp = 0;
int wf = 0; int wf = 0;
LED_ON; LED_ON;
LED_ON2;
int c = 1; int c = 1;
while (1) { while (1) {
@ -150,7 +152,7 @@ int main(void)
break; break;
} }
LED_OFF2;
SendSPI2812(ledOut, NUM_LIN_LEDS); SendSPI2812(ledOut, NUM_LIN_LEDS);
while(1) while(1)
{ {
@ -158,7 +160,7 @@ int main(void)
{ {
LED_OFF; //Use led on the board to show us how much CPU we're using. (You can also probe PB15) LED_OFF; //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
PushSample32( sampbuff[this_samp]/2 ); //Can't put in full volume. PushSample32( sampbuff[this_samp] ); //Can't put in full volume. (here was /2)
this_samp = (this_samp+1)%CIRCBUFSIZE; this_samp = (this_samp+1)%CIRCBUFSIZE;