All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexaudio.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) James Pearman */
4 /* 2013 */
5 /* All Rights Reserved */
6 /* */
7 /*-----------------------------------------------------------------------------*/
8 /* */
9 /* Module: vexaudio.h */
10 /* Author: James Pearman */
11 /* Created: 25 April 2012 */
12 /* */
13 /* Revisions: */
14 /* V0.20 25 Apr 2012 - Original version for EasyC */
15 /* V1.00 4 July 2013 - Initial release */
16 /* */
17 /*-----------------------------------------------------------------------------*/
18 /* */
19 /* This file is part of ConVEX. */
20 /* */
21 /* The author is supplying this software for use with the VEX cortex */
22 /* control system. ConVEX is free software; you can redistribute it */
23 /* and/or modify it under the terms of the GNU General Public License */
24 /* as published by the Free Software Foundation; either version 3 of */
25 /* the License, or (at your option) any later version. */
26 /* */
27 /* ConVEX is distributed in the hope that it will be useful, */
28 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
29 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
30 /* GNU General Public License for more details. */
31 /* */
32 /* You should have received a copy of the GNU General Public License */
33 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 /* */
35 /* A special exception to the GPL can be applied should you wish to */
36 /* distribute a combined work that includes ConVEX, without being obliged */
37 /* to provide the source code for any proprietary components. */
38 /* See the file exception.txt for full details of how and when the */
39 /* exception can be applied. */
40 /* */
41 /* The author can be contacted on the vex forums as jpearman */
42 /* or electronic mail using jbpearman_at_mac_dot_com */
43 /* Mentor for team 8888 RoboLancers, Pasadena CA. */
44 /* */
45 /*-----------------------------------------------------------------------------*/
46 /* */
47 /* Description: */
48 /* */
49 /* Header file for vex sound functions */
50 /* */
51 /*-----------------------------------------------------------------------------*/
52 /* */
53 
54 #ifndef VEXAUDIO_H_
55 #define VEXAUDIO_H_
56 
57 /*-----------------------------------------------------------------------------*/
58 /** @file vexaudio.h
59  * @brief DAC port driver macros and prototypes
60 *//*---------------------------------------------------------------------------*/
61 
62 // un-comment this to allow per tone amplitude control at the expense of memory
63 //#define VSL_AMP_PER_TONE 1
64 
65 // Public functions
66 void vexAudioPlaySound( int freq, int amplitude, int timems );
67 void vexAudioPlaySoundWait( int freq, int amplitude, int timems );
68 void vexAudioStopSound( void );
69 
70 char *vexAudioPlayRtttl( char *song , int amplitude, int repeat );
71 
72 int vexAudioInitChipToneSong( int len );
73 void vexAudioDeinitChipToneSong( void );
74 void vexAudioStartChipToneSong( int repeat );
75 void vexAudioStopChipToneSong( void );
76 void vexAudioSetNextChipTone( int freq, int amplitude, int timems );
77 void vexAudioDebugChipTone( void );
78 
79 
80 // private functions
81 int vexAudioPlayNextChipTone( void );
82 void VSL_Factorize(int n, int *f1, int *f2);
83 void VSL_CreateSineWave( int amplitude );
84 void VSL_InitTimer( int prescale, int period );
85 void VSL_Init( void );
86 void VSL_Deinit(void);
87 
88 #ifdef VSL_AMP_PER_TONE
89 // version using amplitude per tone - uses more memory
90 typedef struct _vsl_ct {
91  int freq;
92  int amplitude;
93  int timems;
94  } vsl_ct;
95 #else
96 // default - single amplitude for the song
97 typedef struct _vsl_ct {
98  int freq;
99  int timems;
100  } vsl_ct;
101 #endif
102 
103 /** @cond */ // Not for Doxygen
104 #define DEFAULT_AMPLITUDE 64
105 #define MIN_AMPLITUDE 0
106 #define MAX_AMPLITUDE 255
107 
108 // DAC definitions from standard peripheral library
109 #define DAC_Channel_1 ((uint32_t)0x00000000)
110 #define DAC_Channel_2 ((uint32_t)0x00000010)
111 #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
112 #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
113 #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
114 #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
115 #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
116 #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
117 
118 // Timer definitions from standard peripheral library
119 #define TIM_PSCReloadMode_Immediate ((uint16_t)0x0001)
120 #define TIM_TRGOSource_Update ((uint16_t)0x0020)
121 /** @endcond */
122 
123 #endif // VEXAUDIO_H_
124 
125 
126 
127