Configure LEDs

wip2
Markus Koch 2021-03-02 20:21:18 +01:00
parent 59dcbaf177
commit 18f405aa46
5 changed files with 54 additions and 20 deletions

View File

@ -44,7 +44,7 @@ void adc_init()
TIM_OC1Init (TIM5, &TIM_OCInitStructure);
TIM_SetCompare1(TIM5, 0xFFFF);
TIM_ITConfig(TIM5, TIM_IT_CC1, ENABLE);
// Let's leave the interrupt disabled until we are done configuring everything
TIM_CCxCmd(TIM5, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM5, TIM_Channel_1, TIM_CCx_Enable);
@ -127,14 +127,23 @@ void adc_init()
ADC_DMACmd(ADC1, ENABLE);
}
void adc_start()
{
TIM_ITConfig(TIM5, TIM_IT_CC1, ENABLE);
}
void DMA2_Stream0_IRQHandler()
{
int sample;
int peaking;
DMA_ClearFlag(ADC_RX_DMA_STREAM, DMA_FLAG_TCIF0);
sample = ((adc_buffer[0] + adc_buffer[1]) / 2) - 2048;
peaking = (adc_buffer[0] < -640+2048) || (adc_buffer[0] > 520+2048);
peaking |= (adc_buffer[1] < -640+2048) || (adc_buffer[1] > 520+2048);
GotSample(sample);
GotSample(sample, peaking);
}
// Only for debugging. Currently disabled.

View File

@ -11,5 +11,6 @@
// TODO: Update the IRQ handler in adc.c when updating the stream / channel.
void adc_init();
void adc_start();
#endif

View File

@ -168,7 +168,9 @@ void ConfigureUART()
void ConfigureLED()
{
ConfigureGPIO( LEDPIN, INOUT_OUT );
ConfigureGPIO(LED_RED, INOUT_OUT);
ConfigureGPIO(LED_GREEN, INOUT_OUT);
ConfigureGPIO(LED_BLUE, INOUT_OUT);
}
uint8_t GetGPIOFromString( const char * str )

View File

@ -50,18 +50,20 @@ void ConfigureGPIO( gpio gpio, int parameters );
#ifdef STM32F30X
#define LEDPIN 0x18
#elif defined( STM32F40_41xxx )
#define LEDPIN (16+14)
#define LEDPIN (16+13)
#endif
#define LED_GREEN (LEDPIN+0)
#define LED_BLUE (LEDPIN+1)
#define LED_RED (LEDPIN+2)
void ConfigureUART();
void ConfigureLED();
void JumpToBootloader(void);
#define LED_TOGGLE {GPIOOf(LEDPIN)->ODR^=(1<<((LEDPIN)&0x0f));}
#define LED_ON GPIOOn(LEDPIN)
#define LED_OFF GPIOOff(LEDPIN)
#define LED_ON(p) GPIOOn(p)
#define LED_OFF(p) GPIOOff(p)
#endif

View File

@ -25,12 +25,21 @@ int16_t sampbuff[CIRCBUFSIZE];
volatile int samples;
//This gets called by the ADC/Microphone
void GotSample( int samp )
void GotSample(int samp, int peaking)
{
//printf("[GOT-SMP] %d\r\n", samp);
sampbuff[last_samp_pos] = samp;
last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE);
samples++;
if (peaking) {
LED_ON(LED_RED);
} else if (samp > 128) {
LED_ON(LED_BLUE);
} else {
LED_OFF(LED_BLUE);
// Red LED reset in main loop
}
}
//Call this once we've stacked together one full colorchord frame.
@ -107,10 +116,8 @@ int main(void)
uint32_t i = 0;
RCC_GetClocksFreq( &RCC_Clocks );
ConfigureLED();
LED_OFF;
ConfigureLED();
// SysTick end of count event each 10ms
SysTick_Config( RCC_Clocks.HCLK_Frequency / 100);
@ -129,10 +136,8 @@ int main(void)
int this_samp = 0;
int wf = 0;
LED_ON;
int c = 1;
LED_ON(LED_RED);
while (1) {
for (int a=0; a < NUM_LIN_LEDS; a++) {
ledOut[a*3 + 0] = c/2;
@ -143,17 +148,31 @@ int main(void)
SendSPI2812(ledOut, NUM_LIN_LEDS);
_delay_us(10*1000);
c++;
if (c==64)
if (c==16) {
LED_OFF(LED_RED);
LED_ON(LED_BLUE);
} else if (c==32) {
LED_OFF(LED_BLUE);
LED_ON(LED_GREEN);
} else if (c==48) {
LED_OFF(LED_GREEN);
} else if (c==64) {
break;
}
}
LED_OFF(LED_RED);
LED_OFF(LED_GREEN);
LED_OFF(LED_BLUE);
SendSPI2812(ledOut, NUM_LIN_LEDS);
adc_start();
while(1)
{
if( this_samp != last_samp_pos )
{
LED_OFF; //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
LED_OFF(LED_GREEN); //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
PushSample32( sampbuff[this_samp] ); //Can't put in full volume. (here was /2)
@ -164,10 +183,11 @@ int main(void)
{
NewFrame();
wf = 0;
LED_OFF(LED_RED);
}
LED_ON;
LED_ON(LED_GREEN);
}
LED_ON; //Take up a little more time to make sure we don't miss this.
LED_ON(LED_GREEN); //Take up a little more time to make sure we don't miss this.
}
}