-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from paddatrapper/audio-data
Audio data transfer
- Loading branch information
Showing
15 changed files
with
719 additions
and
1,050 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (C) 2017 Kyle Robbertze <krobbertze@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** \file audiodata.c | ||
* Contains definitions for USB audio communication between the FX2 chip and | ||
* the host | ||
*/ | ||
|
||
#ifdef DEBUG | ||
#include <stdio.h> | ||
#include "debug.h" | ||
#else | ||
#define printf(...) | ||
#endif | ||
|
||
#include <fx2regs.h> | ||
#include <delay.h> | ||
#include <eputils.h> | ||
|
||
#include "audiodata.h" | ||
|
||
#define SYNCDELAY SYNCDELAY4 | ||
|
||
/** | ||
* Returns the configuration. We only have one configuration. | ||
*/ | ||
BYTE handle_get_configuration() { | ||
return 1; | ||
} | ||
|
||
/** | ||
* Sets the configuration. Successful if setting it to cfg 1, otherwise fail | ||
* as the descriptors only provide one configuration. | ||
*/ | ||
BOOL handle_set_configuration(BYTE cfg) { | ||
return cfg==1 ? TRUE : FALSE; | ||
} | ||
|
||
/* The current alternative setting */ | ||
BYTE alt_setting = 0; | ||
/** | ||
* Returns the interface currently in use. | ||
*/ | ||
BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) { | ||
printf("Get Interface\n"); | ||
if (ifc == 0 || ifc == 1) { | ||
*alt_ifc = alt_setting; | ||
return TRUE; | ||
} | ||
return FALSE; | ||
} | ||
|
||
/** | ||
* Sets the interface in use. | ||
* 0,0 - Default control | ||
* 1,0 - Streaming, no endpoint. This is used for when the device is not | ||
* streaming | ||
* 1,1 - Streaming with endpoint 8. | ||
* See TRM section 2.3.7 | ||
* http://www.cypress.com/file/126446/download#G5.1043536 | ||
*/ | ||
BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) { | ||
printf("Set interface %d to alt: %d\n", ifc, alt_ifc); | ||
|
||
if (ifc == 0 && alt_ifc == 0) { | ||
alt_setting = 0; | ||
/* | ||
* Restore endpoints to default condition with valid bit cleared | ||
* (invalid, bulk, out, double) | ||
*/ | ||
EP2CFG = 0x7F; | ||
SYNCDELAY; EP4CFG = 0x7F; | ||
SYNCDELAY; EP6CFG = 0x7F; | ||
SYNCDELAY; EP8CFG = 0x7F; | ||
SYNCDELAY; RESETFIFO(0x02); | ||
return TRUE; | ||
} else if (ifc == 1 && alt_ifc == 0) { | ||
alt_setting = 0; | ||
EP2CFG = 0x7F; | ||
SYNCDELAY; EP4CFG = 0x7F; | ||
SYNCDELAY; EP6CFG = 0x7F; | ||
SYNCDELAY; EP8CFG = 0x7F; | ||
SYNCDELAY; RESETFIFO(0x02); | ||
/* reset toggles */ | ||
SYNCDELAY; RESETTOGGLE(0x82); | ||
return TRUE; | ||
} else if (ifc == 1 && alt_ifc == 1) { | ||
alt_setting = 1; | ||
/* Reset audio streaming endpoint */ | ||
EP8CFG = (bmVALID | bmDIR | bmTYPE0); | ||
SYNCDELAY; EP2CFG = 0x7F; | ||
SYNCDELAY; EP4CFG = 0x7F; | ||
SYNCDELAY; EP6CFG = 0x7F; | ||
SYNCDELAY; RESETFIFO(0x02); | ||
SYNCDELAY; RESETTOGGLE(0x82); | ||
return TRUE; | ||
} | ||
return FALSE; | ||
} | ||
|
||
/** | ||
* Descriptor requests are handled by fx2lib. | ||
*/ | ||
BOOL handle_get_descriptor() { | ||
printf ( "Get Descriptor\n" ); | ||
return FALSE; | ||
} | ||
|
||
/** | ||
* There are no vendor commands to handle | ||
*/ | ||
BOOL handle_vendorcommand(BYTE cmd) { | ||
return FALSE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2017 Kyle Robbertze <krobbertze@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** \file audiodata.h | ||
* Contains definitions for USB audio communication between the FX2 chip and | ||
* the host | ||
*/ | ||
|
||
#ifndef AUDIO_DATA_H | ||
#define AUDIO_DATA_H | ||
|
||
#include <audio.h> | ||
#include <fx2types.h> | ||
|
||
BYTE handle_get_configuration(); | ||
BOOL handle_set_configuration(BYTE cfg); | ||
BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc); | ||
BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc); | ||
BOOL handle_get_descriptor(); | ||
|
||
#endif // AUDIO_DATA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// Copyright (C) 2009-2012 Chris McClelland | ||
// Copyright (C) 2017 Kyle Robbertze <krobbertze@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** \file debug.c | ||
* Implements writing to serial for debugging purposes | ||
*/ | ||
#include <fx2regs.h> | ||
#include "debug.h" | ||
|
||
#define PD3 0xB3 | ||
/* Serial write uses pin D3 */ | ||
__sbit __at PD3 USART; | ||
#define BAUD 32 | ||
|
||
/** | ||
* Initialises the usart interface. It supports output from the FX2 on pin D3 | ||
*/ | ||
void usart_init(void) { | ||
USART = 1; | ||
/* Enable output on pin D3 */ | ||
OED |= bmBIT3; | ||
} | ||
|
||
/** | ||
* Bit banging serial output | ||
*/ | ||
void usart_send_byte(BYTE c) { | ||
(void)c; /* argument passed in DPL */ | ||
__asm | ||
mov a, dpl | ||
mov r1, #9 | ||
clr c | ||
loop: | ||
mov _USART, c | ||
rrc a | ||
mov r0, #BAUD | ||
djnz r0, . | ||
nop | ||
djnz r1, loop | ||
|
||
;; Stop bit | ||
setb _USART | ||
mov r0, #BAUD | ||
djnz r0, . | ||
__endasm; | ||
} | ||
|
||
/** | ||
* Send a byte encoded as hexadecimal | ||
*/ | ||
void usart_send_byte_hex(BYTE byte) { | ||
__xdata BYTE ch; | ||
ch = (byte >> 4) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = byte & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
} | ||
|
||
/** | ||
* Send a word width of data as hexadecimal | ||
*/ | ||
void usart_send_word_hex(WORD word) { | ||
__xdata BYTE ch; | ||
ch = (word >> 12) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 8) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 4) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 0) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
} | ||
|
||
/** | ||
* Send a long word as hexadecimal | ||
*/ | ||
void usart_send_long_hex(DWORD word) { | ||
__xdata BYTE ch; | ||
ch = (word >> 28) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 24) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 20) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 16) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 12) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 8) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 4) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
ch = (word >> 0) & 0x0F; | ||
ch += (ch < 10 ) ? '0' : 'A' - 10; | ||
usart_send_byte(ch); | ||
} | ||
|
||
/** | ||
* Send a string using bit banging output. Either \n or \r will send both | ||
* \n and \r for ease of programming | ||
*/ | ||
void usart_send_string(const char *s) { | ||
while (*s) { | ||
switch (*s) { | ||
case '\r': | ||
case '\n': | ||
usart_send_newline(); | ||
break; | ||
default: | ||
usart_send_byte(*s); | ||
} | ||
*s++; | ||
} | ||
} | ||
|
||
/** | ||
* Ease of use for sending a new line. | ||
*/ | ||
void usart_send_newline(void) { | ||
usart_send_byte('\n'); | ||
usart_send_byte('\r'); | ||
} | ||
|
||
/** | ||
* The function that printf uses to send characters. This allows printf to | ||
* be used for debug messages. | ||
*/ | ||
void putchar(char c) { | ||
switch (c) { | ||
case '\r': | ||
case '\n': | ||
usart_send_newline(); | ||
break; | ||
default: | ||
usart_send_byte(c); | ||
} | ||
} | ||
|
||
/** | ||
* Not implemented | ||
*/ | ||
char getchar(void) { | ||
return '0'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2009-2012 Chris McClelland | ||
// Copyright (C) 2017 Kyle Robbertze <krobbertze@gmail.com> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** \file debug.h | ||
* Details writing to serial for debugging purposes | ||
*/ | ||
|
||
#ifndef DEBUG_H | ||
#define DEBUG_H | ||
|
||
#include <fx2types.h> | ||
|
||
void usart_init(void); | ||
void usart_send_byte(BYTE c); | ||
void usart_send_byte_hex(BYTE byte); | ||
void usart_send_word_hex(WORD word); | ||
void usart_send_long_hex(DWORD word); | ||
void usart_send_string(const char *s); | ||
void usart_send_newline(void); | ||
void putchar(char c); | ||
char getchar(void); | ||
|
||
#endif |
Oops, something went wrong.