volume control and led volume display

This commit is contained in:
Hendrik Schutter 2020-12-05 23:50:47 +01:00
parent 594e98673d
commit 7b91a4124c
7 changed files with 299 additions and 73 deletions

143
Main.c
View File

@ -11,6 +11,7 @@ This file contains the main app function and init.
#include "audio.h"
#include "Board_DAC.h"
#include "Welcome.h"
#include "Board_ADC.h"
//25x25 Dot Qr Code, 25bits per line (x)
uint32_t au32QrCode[25] =
@ -45,6 +46,8 @@ uint32_t au32QrCode[25] =
static void vMainInitApp(void);
static void vPrintQr(void);
static bool bCheckButton(void);
static void vUpdateVolume(void);
//static void SysTickHandler(void);
/**
* @fn int main (void)
@ -58,14 +61,23 @@ int main (void)
{
vMainInitApp(); //init app
vPrintQr(); //print Qr
vStartAudio();
LED_On(0);
while(!bCheckButton()) {
ADC_StartConversion();
vUpdateLyrics();
vUpdateVolume();
}
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_Off(5);
LED_Off(6);
LED_Off(7);
LPC_TIM0->TCR = 0; // stop music
}
@ -94,6 +106,9 @@ static void vMainInitApp(void)
LED_Initialize();
Buttons_Initialize();
ADC_Initialize();
}
/**
@ -157,4 +172,130 @@ static bool bCheckButton(void)
return lastState;
}
static void vUpdateVolume(void)
{
if(ADC_ConversionDone() == 0)
{
uint32_t u32ADCValue = ADC_GetValue();
if(u32ADCValue <= 512)
{
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_Off(5);
LED_Off(6);
LED_On(7);
u32Volume = 16;
return;
}
if(u32ADCValue <= 1024)
{
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_Off(5);
LED_On(6);
LED_On(7);
u32Volume = 64;
return;
}
if(u32ADCValue <= 1536)
{
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_Off(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 144;
return;
}
if(u32ADCValue <= 2048)
{
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_Off(3);
LED_On(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 256;
return;
}
if(u32ADCValue <= 2560)
{
LED_Off(0);
LED_Off(1);
LED_Off(2);
LED_On(3);
LED_On(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 400;
return;
}
if(u32ADCValue <= 3072)
{
LED_Off(0);
LED_Off(1);
LED_On(2);
LED_On(3);
LED_On(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 576;
return;
}
if(u32ADCValue <= 3584)
{
LED_Off(0);
LED_On(1);
LED_On(2);
LED_On(3);
LED_On(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 784;
return;
}
if(u32ADCValue <= 4090)
{
LED_On(0);
LED_On(1);
LED_On(2);
LED_On(3);
LED_On(4);
LED_On(5);
LED_On(6);
LED_On(7);
u32Volume = 1023;
return;
}
}
}

View File

@ -17,6 +17,7 @@ This file includes other header files used in this project.
#include "Board_GLCD.h"
#include "Board_LED.h"
#include "Board_Buttons.h"
#include "stdint.h"
//-------------------------------------------------------------------
// defines
@ -34,6 +35,8 @@ This file includes other header files used in this project.
extern GLCD_FONT GLCD_Font_16x24;
extern GLCD_FONT GLCD_Font_6x8; // GLCD Font from GLCD_Fonts.c
extern uint32_t u32Volume;
// project globals
#endif /* __ES2_V5_APP_H */

File diff suppressed because one or more lines are too long

View File

@ -140,13 +140,61 @@
<SetRegEntry>
<Number>0</Number>
<Key>UL2CM3</Key>
<Name>-UAny -O206 -S8 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD10000000 -FCFE0 -FN1 -FF0LPC_IAP_512.FLM -FS00 -FL080000 -FP0($$Device:LPC1768$Flash\LPC_IAP_512.FLM)</Name>
<Name>-UAny -O206 -S8 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD10000000 -FCFE0 -FN1 -FF0LPC_IAP_512.FLM -FS00 -FL080000 -FP0($$Device:LPC1768$Flash\LPC_IAP_512.FLM)</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>75</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>9168</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Welcome\Main.c\75</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>47</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>8822</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\audio.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Welcome\audio.c\47</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>81</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>8980</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\audio.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Welcome\audio.c\81</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>48</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
@ -160,39 +208,19 @@
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>47</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\audio.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>81</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>8200</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\audio.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Welcome\audio.c\81</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>u32SysTicks,0x0A</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>u32Now</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
@ -279,7 +307,7 @@
<GroupNumber>1</GroupNumber>
<FileNumber>3</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\audio.c</PathWithFileName>
@ -323,11 +351,23 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\globals.c</PathWithFileName>
<FilenameWithoutPath>globals.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>::Board Support</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>
@ -343,7 +383,7 @@
<Group>
<GroupName>::CMSIS Driver</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>
@ -351,7 +391,7 @@
<Group>
<GroupName>::Device</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>1</RteFlg>

View File

@ -412,6 +412,11 @@
<FileType>5</FileType>
<FilePath>.\melody.h</FilePath>
</File>
<File>
<FileName>globals.c</FileName>
<FileType>1</FileType>
<FilePath>.\globals.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -462,6 +467,12 @@
</package>
</packages>
<apis>
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="A/D Converter" exclusive="0">
<package name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.6.0"/>
<targetInfos>
<targetInfo name="MCB1760 mit LPC1768"/>
</targetInfos>
</api>
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="Buttons" exclusive="0">
<package license="license.rtf" name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.11.1"/>
<targetInfos>
@ -512,6 +523,12 @@
<targetInfo name="MCB1760 mit LPC1768"/>
</targetInfos>
</component>
<component Capiversion="1.0.0" Cbundle="MCB1700" Cclass="Board Support" Cgroup="A/D Converter" Cvendor="Keil" Cversion="1.0.0" condition="LPC1700 CMSIS PIN">
<package name="LPC1700_DFP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<targetInfos>
<targetInfo name="MCB1760 mit LPC1768"/>
</targetInfos>
</component>
<component Capiversion="1.0.0" Cbundle="MCB1700" Cclass="Board Support" Cgroup="Buttons" Cvendor="Keil" Cversion="1.0.0" condition="LPC1700 CMSIS PIN GPIO">
<package name="LPC1700_DFP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/>
<targetInfos>

View File

@ -13,6 +13,7 @@ This file contains the main app function and init.
#include "Board_GLCD.h"
#include "LPC17xx.h"
#include "melody.h"
#include "Welcome.h"
#define FREQ(x) ((x & 0xffff0000) >> 16)
#define WAVES(x) (x & 0xffff)
@ -39,7 +40,7 @@ bool bPerformAudioStep()
{
if (sAudioState.u16RemainingWaves > 0)
{
DAC_SetValue(512);
DAC_SetValue((u32Volume << 6));
}
else
{

6
globals.c Normal file
View File

@ -0,0 +1,6 @@
#include "stdint.h"
uint32_t u32Volume;