Microphone input functional and mostly calibrated!
This commit is contained in:
264
Core/Src/main.c
264
Core/Src/main.c
@@ -24,7 +24,7 @@
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include <stdbool.h>
|
||||
//#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
@@ -71,7 +71,7 @@ static void MX_TIM6_Init(void);
|
||||
static void MX_ADC3_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
void updateWS2812BData(void);
|
||||
uint8_t getSoundLevel(void);
|
||||
void LEDDesign_Off(void);
|
||||
void LEDDesign_ColorWhite(void);
|
||||
void LEDDesign_ColorBlue(void);
|
||||
@@ -80,12 +80,20 @@ void LEDDesign_ColorRed(void);
|
||||
void LEDDesign_Crazy(void);
|
||||
void LEDDesign_Smile(void);
|
||||
void LEDDesign_SuperCrazy(void);
|
||||
void updateWS2812BData(void);
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
int _write(int32_t file, uint8_t *ptr, int32_t len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
ITM_SendChar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -123,6 +131,8 @@ int main(void)
|
||||
|
||||
updateWS2812BData();
|
||||
HAL_SPI_Transmit_IT(&hspi4, (uint8_t*) &LEDData, (uint16_t) 66 * 3 * 3);
|
||||
HAL_ADC_Start(&hadc3);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@@ -231,7 +241,7 @@ static void MX_ADC3_Init(void)
|
||||
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
|
||||
hadc3.Init.Resolution = ADC_RESOLUTION_8B;
|
||||
hadc3.Init.ScanConvMode = DISABLE;
|
||||
hadc3.Init.ContinuousConvMode = ENABLE;
|
||||
hadc3.Init.ContinuousConvMode = DISABLE;
|
||||
hadc3.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
@@ -606,116 +616,36 @@ static void MX_GPIO_Init(void)
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
void updateWS2812BData(void){
|
||||
uint8_t byteToConvert;
|
||||
for (uint8_t i = 0; i < 64; ++i) {
|
||||
for (uint8_t j = 0; j < 3; ++j) {
|
||||
byteToConvert = LEDData[i][j];
|
||||
switch((byteToConvert & 0xF0) >> 4){
|
||||
case 0x00:
|
||||
WS2812BConvertedData = 0x00924000;
|
||||
break;
|
||||
case 0x01:
|
||||
WS2812BConvertedData = 0x00926000;
|
||||
break;
|
||||
case 0x02:
|
||||
WS2812BConvertedData = 0x00934000;
|
||||
break;
|
||||
case 0x03:
|
||||
WS2812BConvertedData = 0x00936000;
|
||||
break;
|
||||
case 0x04:
|
||||
WS2812BConvertedData = 0x009A4000;
|
||||
break;
|
||||
case 0x05:
|
||||
WS2812BConvertedData = 0x009A6000;
|
||||
break;
|
||||
case 0x06:
|
||||
WS2812BConvertedData = 0x009B4000;
|
||||
break;
|
||||
case 0x07:
|
||||
WS2812BConvertedData = 0x009B6000;
|
||||
break;
|
||||
case 0x08:
|
||||
WS2812BConvertedData = 0x00D24000;
|
||||
break;
|
||||
case 0x09:
|
||||
WS2812BConvertedData = 0x00D26000;
|
||||
break;
|
||||
case 0x0A:
|
||||
WS2812BConvertedData = 0x00D34000;
|
||||
break;
|
||||
case 0x0B:
|
||||
WS2812BConvertedData = 0x00D36000;
|
||||
break;
|
||||
case 0x0C:
|
||||
WS2812BConvertedData = 0x00DA4000;
|
||||
break;
|
||||
case 0x0D:
|
||||
WS2812BConvertedData = 0x00DA6000;
|
||||
break;
|
||||
case 0x0E:
|
||||
WS2812BConvertedData = 0x00DB4000;
|
||||
break;
|
||||
default: // 0x0F
|
||||
WS2812BConvertedData = 0x00DB6000;
|
||||
uint8_t getSoundLevel(void){
|
||||
// Adjustment / Calibration
|
||||
static uint8_t divisor = 2;
|
||||
static uint8_t postscale_DownShift = 0;
|
||||
static uint8_t prescale_DownShift = 180;
|
||||
static uint8_t multiplier = 3;
|
||||
|
||||
}
|
||||
switch(byteToConvert & 0x0F){
|
||||
case 0x00:
|
||||
WS2812BConvertedData |= 0x00000924;
|
||||
break;
|
||||
case 0x01:
|
||||
WS2812BConvertedData |= 0x00000926;
|
||||
break;
|
||||
case 0x02:
|
||||
WS2812BConvertedData |= 0x00000934;
|
||||
break;
|
||||
case 0x03:
|
||||
WS2812BConvertedData |= 0x00000936;
|
||||
break;
|
||||
case 0x04:
|
||||
WS2812BConvertedData |= 0x000009A4;
|
||||
break;
|
||||
case 0x05:
|
||||
WS2812BConvertedData |= 0x000009A6;
|
||||
break;
|
||||
case 0x06:
|
||||
WS2812BConvertedData |= 0x000009B4;
|
||||
break;
|
||||
case 0x07:
|
||||
WS2812BConvertedData |= 0x000009B6;
|
||||
break;
|
||||
case 0x08:
|
||||
WS2812BConvertedData |= 0x00000D24;
|
||||
break;
|
||||
case 0x09:
|
||||
WS2812BConvertedData |= 0x00000D26;
|
||||
break;
|
||||
case 0x0A:
|
||||
WS2812BConvertedData |= 0x00000D34;
|
||||
break;
|
||||
case 0x0B:
|
||||
WS2812BConvertedData |= 0x00000D36;
|
||||
break;
|
||||
case 0x0C:
|
||||
WS2812BConvertedData |= 0x00000DA4;
|
||||
break;
|
||||
case 0x0D:
|
||||
WS2812BConvertedData |= 0x00000DA6;
|
||||
break;
|
||||
case 0x0E:
|
||||
WS2812BConvertedData |= 0x00000DB4;
|
||||
break;
|
||||
default: // 0x0F
|
||||
WS2812BConvertedData |= 0x00000DB6;
|
||||
static uint16_t averagedDifferences = 0;
|
||||
uint16_t returnValue;
|
||||
uint8_t samples[16];
|
||||
uint16_t sumOfDifferences = 0;
|
||||
|
||||
}
|
||||
LEDData_WS2812B[i][j][0] = (WS2812BConvertedData & 0x00FF0000) >> 16;
|
||||
LEDData_WS2812B[i][j][1] = (WS2812BConvertedData & 0x0000FF00) >> 8;
|
||||
LEDData_WS2812B[i][j][2] = WS2812BConvertedData & 0x000000FF;
|
||||
}
|
||||
for(uint8_t i = 0; i < sizeof(samples); ++i){
|
||||
HAL_Delay(1);
|
||||
HAL_ADC_Start(&hadc3);
|
||||
HAL_ADC_PollForConversion(&hadc3, (uint32_t) 20);
|
||||
samples[i] = HAL_ADC_GetValue(&hadc3);
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < sizeof(samples) - 1; ++i){
|
||||
sumOfDifferences += abs(samples[i] - samples[i + 1]);
|
||||
}
|
||||
|
||||
averagedDifferences += ((int32_t) sumOfDifferences - (int32_t) averagedDifferences) / 4;
|
||||
|
||||
if(averagedDifferences < prescale_DownShift){returnValue = 0;}else{returnValue = averagedDifferences - prescale_DownShift;}
|
||||
returnValue = (returnValue / divisor) * multiplier;
|
||||
if(returnValue < postscale_DownShift){returnValue = 0;}else{returnValue -= postscale_DownShift;}
|
||||
|
||||
if(returnValue >= 0xFF){return 0xFF;} else{return returnValue;}
|
||||
}
|
||||
void LEDDesign_Off(void){
|
||||
for(uint8_t i = 0; i < 64; ++i){
|
||||
@@ -773,6 +703,7 @@ void LEDDesign_Crazy(void){
|
||||
}
|
||||
}
|
||||
void LEDDesign_Smile(void){
|
||||
uint8_t currentSoundLevel = getSoundLevel();
|
||||
LEDData[0][0] = 0x00;
|
||||
LEDData[0][1] = 0x00;
|
||||
LEDData[0][2] = 0x00;
|
||||
@@ -981,6 +912,117 @@ void LEDDesign_SuperCrazy(void){
|
||||
LEDData[i][2] = randomByte;
|
||||
}
|
||||
}
|
||||
void updateWS2812BData(void){
|
||||
uint8_t byteToConvert;
|
||||
for (uint8_t i = 0; i < 64; ++i) {
|
||||
for (uint8_t j = 0; j < 3; ++j) {
|
||||
byteToConvert = LEDData[i][j];
|
||||
switch((byteToConvert & 0xF0) >> 4){
|
||||
case 0x00:
|
||||
WS2812BConvertedData = 0x00924000;
|
||||
break;
|
||||
case 0x01:
|
||||
WS2812BConvertedData = 0x00926000;
|
||||
break;
|
||||
case 0x02:
|
||||
WS2812BConvertedData = 0x00934000;
|
||||
break;
|
||||
case 0x03:
|
||||
WS2812BConvertedData = 0x00936000;
|
||||
break;
|
||||
case 0x04:
|
||||
WS2812BConvertedData = 0x009A4000;
|
||||
break;
|
||||
case 0x05:
|
||||
WS2812BConvertedData = 0x009A6000;
|
||||
break;
|
||||
case 0x06:
|
||||
WS2812BConvertedData = 0x009B4000;
|
||||
break;
|
||||
case 0x07:
|
||||
WS2812BConvertedData = 0x009B6000;
|
||||
break;
|
||||
case 0x08:
|
||||
WS2812BConvertedData = 0x00D24000;
|
||||
break;
|
||||
case 0x09:
|
||||
WS2812BConvertedData = 0x00D26000;
|
||||
break;
|
||||
case 0x0A:
|
||||
WS2812BConvertedData = 0x00D34000;
|
||||
break;
|
||||
case 0x0B:
|
||||
WS2812BConvertedData = 0x00D36000;
|
||||
break;
|
||||
case 0x0C:
|
||||
WS2812BConvertedData = 0x00DA4000;
|
||||
break;
|
||||
case 0x0D:
|
||||
WS2812BConvertedData = 0x00DA6000;
|
||||
break;
|
||||
case 0x0E:
|
||||
WS2812BConvertedData = 0x00DB4000;
|
||||
break;
|
||||
default: // 0x0F
|
||||
WS2812BConvertedData = 0x00DB6000;
|
||||
|
||||
}
|
||||
switch(byteToConvert & 0x0F){
|
||||
case 0x00:
|
||||
WS2812BConvertedData |= 0x00000924;
|
||||
break;
|
||||
case 0x01:
|
||||
WS2812BConvertedData |= 0x00000926;
|
||||
break;
|
||||
case 0x02:
|
||||
WS2812BConvertedData |= 0x00000934;
|
||||
break;
|
||||
case 0x03:
|
||||
WS2812BConvertedData |= 0x00000936;
|
||||
break;
|
||||
case 0x04:
|
||||
WS2812BConvertedData |= 0x000009A4;
|
||||
break;
|
||||
case 0x05:
|
||||
WS2812BConvertedData |= 0x000009A6;
|
||||
break;
|
||||
case 0x06:
|
||||
WS2812BConvertedData |= 0x000009B4;
|
||||
break;
|
||||
case 0x07:
|
||||
WS2812BConvertedData |= 0x000009B6;
|
||||
break;
|
||||
case 0x08:
|
||||
WS2812BConvertedData |= 0x00000D24;
|
||||
break;
|
||||
case 0x09:
|
||||
WS2812BConvertedData |= 0x00000D26;
|
||||
break;
|
||||
case 0x0A:
|
||||
WS2812BConvertedData |= 0x00000D34;
|
||||
break;
|
||||
case 0x0B:
|
||||
WS2812BConvertedData |= 0x00000D36;
|
||||
break;
|
||||
case 0x0C:
|
||||
WS2812BConvertedData |= 0x00000DA4;
|
||||
break;
|
||||
case 0x0D:
|
||||
WS2812BConvertedData |= 0x00000DA6;
|
||||
break;
|
||||
case 0x0E:
|
||||
WS2812BConvertedData |= 0x00000DB4;
|
||||
break;
|
||||
default: // 0x0F
|
||||
WS2812BConvertedData |= 0x00000DB6;
|
||||
|
||||
}
|
||||
LEDData_WS2812B[i][j][0] = (WS2812BConvertedData & 0x00FF0000) >> 16;
|
||||
LEDData_WS2812B[i][j][1] = (WS2812BConvertedData & 0x0000FF00) >> 8;
|
||||
LEDData_WS2812B[i][j][2] = WS2812BConvertedData & 0x000000FF;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,6 +77,6 @@
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList context="reserved-for-future-use"/> "/>
|
||||
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList context="reserved-for-future-use"> <gdbmemoryBlockExpression address="537067481" label="&amp;(samples[1])"/> <gdbmemoryBlockExpression address="537067481" label="&amp;(samples[1])"/> </memoryBlockExpressionList> "/>
|
||||
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
|
||||
</launchConfiguration>
|
||||
|
||||
Binary file not shown.
@@ -1,18 +1,19 @@
|
||||
core_cm4.h:2064:26:ITM_SendChar 16 static,ignoring_inline_asm
|
||||
main.c:87:5:_write 32 static
|
||||
main.c:101:5:main 8 static
|
||||
main.c:179:6:SystemClock_Config 88 static
|
||||
main.c:223:13:MX_ADC3_Init 24 static
|
||||
main.c:273:13:MX_SPI4_Init 8 static
|
||||
main.c:311:13:MX_TIM6_Init 16 static
|
||||
main.c:353:13:MX_GPIO_Init 64 static
|
||||
main.c:616:6:updateWS2812BData 16 static
|
||||
main.c:727:6:LEDDesign_Off 16 static
|
||||
main.c:734:6:LEDDesign_ColorWhite 16 static
|
||||
main.c:741:6:LEDDesign_ColorBlue 16 static
|
||||
main.c:752:6:LEDDesign_ColorGreen 16 static
|
||||
main.c:763:6:LEDDesign_ColorRed 16 static
|
||||
main.c:774:6:LEDDesign_Crazy 32 static
|
||||
main.c:782:6:LEDDesign_Smile 4 static
|
||||
main.c:976:6:LEDDesign_SuperCrazy 24 static
|
||||
main.c:997:6:Error_Handler 4 static
|
||||
main.c:89:5:_write 32 static
|
||||
main.c:103:5:main 8 static
|
||||
main.c:182:6:SystemClock_Config 88 static
|
||||
main.c:226:13:MX_ADC3_Init 24 static
|
||||
main.c:276:13:MX_SPI4_Init 8 static
|
||||
main.c:314:13:MX_TIM6_Init 16 static
|
||||
main.c:356:13:MX_GPIO_Init 64 static
|
||||
main.c:619:9:getSoundLevel 32 static
|
||||
main.c:650:6:LEDDesign_Off 16 static
|
||||
main.c:657:6:LEDDesign_ColorWhite 16 static
|
||||
main.c:664:6:LEDDesign_ColorBlue 16 static
|
||||
main.c:675:6:LEDDesign_ColorGreen 16 static
|
||||
main.c:686:6:LEDDesign_ColorRed 16 static
|
||||
main.c:697:6:LEDDesign_Crazy 32 static
|
||||
main.c:705:6:LEDDesign_Smile 16 static
|
||||
main.c:900:6:LEDDesign_SuperCrazy 24 static
|
||||
main.c:915:6:updateWS2812BData 16 static
|
||||
main.c:1032:6:Error_Handler 4 static
|
||||
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
ADC3.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_4
|
||||
ADC3.ContinuousConvMode=ENABLE
|
||||
ADC3.ContinuousConvMode=DISABLE
|
||||
ADC3.IPParameters=Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,NbrOfConversionFlag,Resolution,ContinuousConvMode
|
||||
ADC3.NbrOfConversionFlag=1
|
||||
ADC3.Rank-3\#ChannelRegularConversion=1
|
||||
|
||||
Reference in New Issue
Block a user