USBHOST

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.
Post Reply
vinayslone
Senior User
Posts: 38
Joined: Tue 2020-11-10 12:34

USBHOST

Post by vinayslone » Thu 2020-12-03 12:18

Hello vlsi team,

Please review my queries !

How to detect programmatically whether usb is connected or not ?
Anyway on boot up of developer board it runs the usbhost driver, but i want in my application like:-
1.) If USB is not connected there should notification.(led blink)

2.) Also i am getting this output when give command playfile, is it normal ?

S:>playfile hello.mp3
playfile hello.mp3
Playing 'HELLO.MP3'
~0503'Hello
~0505'Panu-Kristian Poiksalo
~0504'VSDSP Testing
~0506'

[00:00]Decode finished.
AUXSPLAY: In overflow +22678
S:>AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9617
AUXSPLAY: In overflow +9663
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664
AUXSPLAY: In overflow +9616
AUXSPLAY: In overflow +9664


Thankyou

Hannu
Senior User
Posts: 131
Joined: Mon 2016-05-30 11:54

Re: USBHOST

Post by Hannu » Thu 2020-12-03 15:41

With a quick look at usbhost code, you can detect if USB is detected with something like this code:

Code: Select all

/* Untested, but compiles */
ioresult main(char *params) {
	u_int16 *usbHostLib = LoadLibraryP("usbhost", "U");
	while (RunLoadedFunction(usbHostLib, ENTRY_MAIN, (s_int16)"U") != S_OK){
		GpioSetPin(0x17, 1);/* GPIO1_7 high */
		Delay(2000);
		GpioSetPin(0x17, 0);
		/* USB probe takes about 2 seconds. No delay needed */
	}
	/* Do stuff. USB stick is device U */
	DropLibrary(usbHostLib);
}
The auxplay errors which you are seeing are because you have auxplay loaded in config.txt. Comment it out.
Auxplay copies from stdaudioin to stdaudioout. So you could probably hear everything from line in to to headphones, or whatever auiadc has set to listen.

So the overflows are side effects of playfile for auxplay. First playfile plays the MP3 file and sets DAC's samplerate to match the file and then decodes and plays the file. when the playfile exits the DAC is apparently in lower samplerate than ADC and there are overflows. Tool to set the samplerate and other features of the DAC is auoutput.

A lot of information of audio drivers and audio related tools can be found from: http://www.vlsi.fi/fileadmin/software/V ... _Audio.pdf
And documentation for the shell tools is http://www.vlsi.fi/fileadmin/software/V ... _Shell.pdf

vinayslone
Senior User
Posts: 38
Joined: Tue 2020-11-10 12:34

Re: USBHOST

Post by vinayslone » Thu 2020-12-03 20:42

thankyou for your response hannu,

1.) Can you share how to detect number of files in USB(counting) ?
Already i have gone through the solution code of DIR, but was not able to understand which part of the code to grab for counting of audio files.

I know this lame to ask, but please share something.

2.) How to put vs1005 in sleep mode if nothing is happening on device ?(to save battery power)
3.) How to read voltage using analog pin in VS1005 ?
4.) How to access led's of the VS1005 Developer board ? (i want to test my application actually)

Please resolve above queries !

Thankyou !

Hannu
Senior User
Posts: 131
Joined: Mon 2016-05-30 11:54

Re: USBHOST

Post by Hannu » Fri 2020-12-04 10:33

vinayslone wrote:
Thu 2020-12-03 20:42
thankyou for your response hannu,

1.) Can you share how to detect number of files in USB(counting) ?
Already i have gone through the solution code of DIR, but was not able to understand which part of the code to grab for counting of audio files.
You are quite close the answer. Dir indeed does the counting and you can ask playlist from dir.

Have a look at playdir solution hot it plays current directory.

first you need to to CD to the directory,
allocate index
call DIR ENTRY_1 with the index and the return value is number of audio files and index has file numbers sorted by file name.
then you can fopen with "rb#n" mode where n is the file number in the dir. Then give the file pointer to decoder to play the audio.

I know this lame to ask, but please share something.

2.) How to put vs1005 in sleep mode if nothing is happening on device ?(to save battery power)
poweroff.dl3 But how do you wake?
3.) How to read voltage using analog pin in VS1005 ?
Which one? some SAR pin or sigma delta AD input? It is possible to read VHIGH/2 with SAR
4.) How to access led's of the VS1005 Developer board ? (i want to test my application actually)
GPIO1_7 and GPIO1_8 are the ethernet related leds near the reset button. The led bar is chip selects for different devices on the board.

Most of the time it is much easier to use debug prints than than the led blinks.
Please resolve above queries !

Thankyou !

vinayslone
Senior User
Posts: 38
Joined: Tue 2020-11-10 12:34

Re: USBHOST

Post by vinayslone » Fri 2020-12-04 11:12

Thankyou for your response Hannu,

1.) But how do you wake?
:- we will awake the device by any normal key press.

2.) Which one? some SAR pin or sigma delta AD input?
:- Yes with SAR pin, or you suggest.

2.a) And how to read voltage with SAR ?

Thankyou !

Hannu
Senior User
Posts: 131
Joined: Mon 2016-05-30 11:54

Re: USBHOST

Post by Hannu » Fri 2020-12-04 11:58

Power button startup is good idea.

Using SAR is pretty simple. Have look at datasheet.
PERIP(ANA_CF1) |= ANA_CF1_SAR_ENA to switch SAR power on

then write to SAR_CF source, speed and enable. Wait until enable bit goes down and read the result from SAR_DAT register.

Sar value is 10-bit value on scale of GND to AVDD. You can measure the AVDD which will probably be about 3.6V and then do the math.

Hannu
Senior User
Posts: 131
Joined: Mon 2016-05-30 11:54

Re: USBHOST

Post by Hannu » Mon 2020-12-07 11:20

allocate or declare, DIR doesn't care as long there is some memory available behind the pointer and number of wanted files as first item..

Something like below which would play media in alphabetical order. I just wrote it in here so no guarantee that it even compiles.

Code: Select all

#define WANT_THIS_MANY 33
u_int16 myFiles[WANT_THIS_MANY] = {WANT_THIS_MANY};
#define MY_AUDIO_DIR "D:my_audio"
void foo() {
  // static char filename[] = MY_AUDIO_DIR "/*"; /* Absolute path */
  static char filename[] = "*"; /* filespec of all in current directory */
  static char fnumMode[10];/* rb#nnnnnn should be enough. */
  u_int16 files_in_dir, n;
  FILE *fp;
  /* Be sure shellenv is loaded to memory */
  RunProgram("cd", MY_AUDIO_DIR); //Maybe drive isn't required
  files_in_dir = RunLibraryFunction("DIR", ENTRY_1, (int)myFiles);
  for (n = 0; n < WANT_THIS_MANY; n++) {
    sprintf(fnumMode,"rb#%d", myFiles[n]);
    fp = fopen(filename, fnumMode);
    if (fp) {
      /* PlayFile(fp)... Copy and adapt this from some play* project */
    } else {
      printf("Something bad happened %u, file not open\n", n);
    }
  }
}

vinayslone
Senior User
Posts: 38
Joined: Tue 2020-11-10 12:34

Re: USBHOST

Post by vinayslone » Mon 2020-12-07 18:35

thankyou for your response hannu !

Post Reply