VS1005 GPIO Access

Discussion about writing software for VS1005 and the VSOS Operating System. Also posts about VS1005-related hardware design and device drivers should be posted here.
DDSchrader
User
Posts: 4
Joined: Mon 2013-09-30 0:50

VS1005 GPIO Access

Post by DDSchrader »

Greetings,

I am working with the VS1005 Developer Board V1.4 and after a day of sorting out issues, I've been able to verify functionality of the board and of VSIDE. The application I am developing for my client is rather simple, a user connects the unit to a PC via USB, uploads one or more mp3 files to the device, then when the device is unplugged from the PC and a power source is connected, it starts playing the uploaded files continuously in a loop. There are only two user controls, Volume Up and Volume Down. There is no display other than a power LED. There is no microcontroller.

My initial questions are:
How do I access the GPIO for the switches (S1 & S2) on the Developer Board in VSOS?
How do I go about controlling the volume levels using a simple push-button interface?

The only information I can find in the various manuals was a warning not to allow an application to control the volume, but no real clue on how to let VSOS do it.

Take it easy on me, I am a hardware engineer, software has become something I have to do, not something I really enjoy like hardware design.

Thanks for the help!

Best wishes.

Dan
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1005 GPIO Access

Post by Panu »

Right. We're actually working on it (the volume control).

You can read the buttons with GpioReadPin(0x00), GpioReadPin(0x01), GpioReadPin(0x02), and GpioReadPin(0x03). Include the file vo_gpio.c in your project, you can copy it from a vsos kernel template.

-Panu
DDSchrader
User
Posts: 4
Joined: Mon 2013-09-30 0:50

Re: VS1005 GPIO Access

Post by DDSchrader »

Panu,

Thank you. I sorted out the GPIO, with a bit of sw debouncing, I can control pause & playback, merely as a test that the IO works. Do you have an idea of when you will have a working volume control solution? This design is for a client, and I will have to use a PGA or other means to control the volume if you are not going to be ready for more that a week or so. I chose this part due to the high level of integration, and the fact that I can use this part and much of the code to fill the needs of several clients and designs, I'd sure hate to kludge in extra hardware for such a basic function as volume control.
I wanted to also point out that in the documentation it warns against setting the volume in applications. I understand this, but in my particular situation, there will only be the one application running, so there should be no need for alarm, correct?

Thanks again!
Dan
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1005 GPIO Access

Post by Panu »

in my particular situation, there will only be the one application running, so there should be no need for alarm, correct?
That's correct. I'll find a way for you to set the volume soon (1-2 days).

-Panu
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1005G Set Master Volume

Post by Panu »

Dear Sir,

Here is a quick-fix method to set the master volume in a VSOS application running in VS1005G.

Code: Select all

#include <vo_stdio.h>
#include <audio.h>

ioresult SetMasterVolumeVS1005G(u_int16 leftHalfDB, u_int16 rightHalfDB) {
	if (*((u_int32*)(0xfffe))!=0xf22ccf6b) {
		return S_ERROR; //We are not running in VS1005G
	}
	// write to playerVolume (VS1005 internal global)
	*((u_int16*)(1431)) = (leftHalfDB << 8) | (rightHalfDB & 0xff);
	SetVolume(); //Call a ROM function that sets the DAC volume from playerVolume
	return S_OK;
}
int main(void) {
	SetMasterVolumeVS1005G(50,50); //Set master volume to -25dB

	// To test that we have updated the master volume, we 
	// now exec to MP3TEST.APP to hear music with the softer volume
	fclose(appFile);
	appFile = fopen("S:MP3TEST.APP","rb");		  
  return S_OK;
}
This code declares the function SetMasterVolumeVS1005G(left, right) which takes as parameters the number of 0.5 decibel steps to attenuate the left and right DAC channels. This sets the DAC_VOL register, so also I2S output is affected when I2S_CF_MODE is 0.

The main function sets -25.0 dB for both left and right DAC channels and then returns to MP3TEST.APP application which plays a test MP3 file. This way you can test the functionality of setting the volume. When MP3TEST.APP is run directly from the VSOS main menu, it plays with normal volume. When started via the VOSetVolume app, it plays with soft volume.

Included is the source code package and necessary files to test the functionality with a VS1005G Developer Board and SD Card.

-Panu
Attachments
VOSetVolume-2013-10-04-11-44-SetMasterVolume1005G.zip
Source Code (VSIDE Solution)
(7.16 KiB) Downloaded 422 times
VolumeTest_SDCard_Files.zip
SD card contents for testing.
(957.88 KiB) Downloaded 479 times
DDSchrader
User
Posts: 4
Joined: Mon 2013-09-30 0:50

Re: VS1005 GPIO Access

Post by DDSchrader »

Panu,

Thank you very much for your efforts! That solved the problem for my client and made us all look good. I was able to use your code to create the two button up-down volume hardware control interface needed for this application. And my complements to you and your staff for this design as there are no audible artifacts during attenuation changes, fantastic! Thanks again for taking care of this for us.

Take care,

Dan
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1005 GPIO Access

Post by Panu »

Thanks, glad to be of help.

Yes, the volume control hardware in VS1005 looks for zero-crossings and times the attenuation change to those points of low amplitude. Glad to hear you like it!

-Panu.
nastja
User
Posts: 4
Joined: Wed 2018-05-09 15:08

Re: VS1005 GPIO Access

Post by nastja »

Hello,
Could you check why code doesn't work?

#include <stdio.h>
//#include "vo_gpio.c"
#include "vo_gpio.h"

void main(void) {
u_int16 GpioReadInputPin(u_int16);
//GpioSetAsInput(0x08);
if (GpioReadInputPin(0x08)) {
puts("Hello, world2!");
}
puts("Hello, world!");
while (1) {
}
}

------------------------------------------------------------
Build failed!

C:\VSIDE\libvs1005g/vo_gpio.h (6) ERROR 0: syntax error
Compilation failed with 1 error and 0 warnings.
C:\VSIDE\bin\make.exe: *** [Emulation-Debug\main.o] Error 1
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1005 GPIO Access

Post by Panu »

Hi!

At least the first #include should be <vo_stdio.h> and not <stdio.h>

Can you change that and try again, see what happens!

-Panu
nastja
User
Posts: 4
Joined: Wed 2018-05-09 15:08

Re: VS1005 GPIO Access

Post by nastja »

Hi!
Now my code is
#include <vo_stdio.h>
......

And mistake
-------------
<stdin> (1) ERROR 0: preprocessing failed
Post Reply