Example of using the SOMO-14D and the created libraries.

Dependencies:   MessageQueue SOMO14D includes mbed

Application

This application uses SOMO-14D and STM32F030R8 nucleo board for testing the audio module.

A microcontroller is used to act as a serial commander between the Computer and the audio module.

Simple commands are used to proceed and make actions like:

  • play
  • pause
  • stop and low power pode
  • previous song
  • next song
  • volume up
  • volume down

Check the wikis of this application and the library wiki for more reference.

Committer:
issaiass
Date:
Fri Mar 13 01:13:35 2015 +0000
Revision:
0:b9c385255fc8
Child:
1:e666958b0e85
SOMO14D version 1 application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
issaiass 0:b9c385255fc8 1 /*
issaiass 0:b9c385255fc8 2 *******************************************************************************
issaiass 0:b9c385255fc8 3 * CERES CONTROLS
issaiass 0:b9c385255fc8 4 * PANAMA, REPULIC OF PANAMA
issaiass 0:b9c385255fc8 5 *
issaiass 0:b9c385255fc8 6 * File : main.cpp
issaiass 0:b9c385255fc8 7 * Programmer(s) : Rangel Alvarado
issaiass 0:b9c385255fc8 8 * Language : ANSI-C
issaiass 0:b9c385255fc8 9 * Description : Main file for SOMO-14D (version 1) terminal controller.
issaiass 0:b9c385255fc8 10 *
issaiass 0:b9c385255fc8 11 * Note : The SOMO-14D is a tiny Audio-Sound module that can
issaiass 0:b9c385255fc8 12 * play back pre-stored audio files such as voice and music
issaiass 0:b9c385255fc8 13 * from a micro-SD memory card.
issaiass 0:b9c385255fc8 14 *
issaiass 0:b9c385255fc8 15 * Warning : Tested only on a STM32F030R8 mbed board.
issaiass 0:b9c385255fc8 16 * Software must have to do a call on
issaiass 0:b9c385255fc8 17 * - MsgRxISR()
issaiass 0:b9c385255fc8 18 * - SOMO14DISR()
issaiass 0:b9c385255fc8 19 *
issaiass 0:b9c385255fc8 20 * Usage : 1 - Open a terminal program like CoolTerm in 9600,8N1
issaiass 0:b9c385255fc8 21 * 2 - Use only the following commands
issaiass 0:b9c385255fc8 22 * List of available commands:
issaiass 0:b9c385255fc8 23 * p play the current song
issaiass 0:b9c385255fc8 24 * h hold the current song
issaiass 0:b9c385255fc8 25 * n play the next song in the queue
issaiass 0:b9c385255fc8 26 * r play the previous song in the queue
issaiass 0:b9c385255fc8 27 * a <num> set audio to a specific song, 511 > num > 0
issaiass 0:b9c385255fc8 28 * i.e. num = 0010
issaiass 0:b9c385255fc8 29 * + set volume up, max 8 levels
issaiass 0:b9c385255fc8 30 * - set volume down, max 8 levels
issaiass 0:b9c385255fc8 31 *
issaiass 0:b9c385255fc8 32 * ----------------------------------------------------------------------------
issaiass 0:b9c385255fc8 33 * HISTORY
issaiass 0:b9c385255fc8 34 * DD MM AA
issaiass 0:b9c385255fc8 35 * 09 03 15 Created.
issaiass 0:b9c385255fc8 36 * 09 03 15 Modified.
issaiass 0:b9c385255fc8 37 * 12 03 15 Import to mbed platform.
issaiass 0:b9c385255fc8 38 *******************************************************************************
issaiass 0:b9c385255fc8 39 */
issaiass 0:b9c385255fc8 40
issaiass 0:b9c385255fc8 41 /*
issaiass 0:b9c385255fc8 42 *******************************************************************************
issaiass 0:b9c385255fc8 43 * INCLUDE FILES
issaiass 0:b9c385255fc8 44 *******************************************************************************
issaiass 0:b9c385255fc8 45 */
issaiass 0:b9c385255fc8 46
issaiass 0:b9c385255fc8 47 #include "includes.h" /* Include all header files */
issaiass 0:b9c385255fc8 48
issaiass 0:b9c385255fc8 49
issaiass 0:b9c385255fc8 50 /*
issaiass 0:b9c385255fc8 51 *******************************************************************************
issaiass 0:b9c385255fc8 52 * CONSTANTS AND MACROS
issaiass 0:b9c385255fc8 53 *******************************************************************************
issaiass 0:b9c385255fc8 54 */
issaiass 0:b9c385255fc8 55
issaiass 0:b9c385255fc8 56 enum SOMO_ACTION {PLAY = 'p', HOLD = 'h',/* The list of available commands */
issaiass 0:b9c385255fc8 57 STOP = 's', NEXT = 'n',
issaiass 0:b9c385255fc8 58 PREV = 'r', STAU = 'a',
issaiass 0:b9c385255fc8 59 VOLUP = '+', VOLDN = '-'
issaiass 0:b9c385255fc8 60 };
issaiass 0:b9c385255fc8 61
issaiass 0:b9c385255fc8 62
issaiass 0:b9c385255fc8 63 /*
issaiass 0:b9c385255fc8 64 *******************************************************************************
issaiass 0:b9c385255fc8 65 * FUNCTION PROTOTYPES
issaiass 0:b9c385255fc8 66 *******************************************************************************
issaiass 0:b9c385255fc8 67 */
issaiass 0:b9c385255fc8 68
issaiass 0:b9c385255fc8 69 void SOMOManageAction(INT8U nbytes); /* Check will action be performed */
issaiass 0:b9c385255fc8 70 void SOMO14DISR(void); /* Interrupt routine of busy pin */
issaiass 0:b9c385255fc8 71 void MsgRxISR(void); /* Interrupt routine of rx char */
issaiass 0:b9c385255fc8 72
issaiass 0:b9c385255fc8 73
issaiass 0:b9c385255fc8 74 /*
issaiass 0:b9c385255fc8 75 *******************************************************************************
issaiass 0:b9c385255fc8 76 * MAIN FUNCTION
issaiass 0:b9c385255fc8 77 *******************************************************************************
issaiass 0:b9c385255fc8 78 */
issaiass 0:b9c385255fc8 79
issaiass 0:b9c385255fc8 80 int main() {
issaiass 0:b9c385255fc8 81 INT8U action; /* Variable for action command */
issaiass 0:b9c385255fc8 82
issaiass 0:b9c385255fc8 83
issaiass 0:b9c385255fc8 84
issaiass 0:b9c385255fc8 85 action = 0; /* Set action initially to 0 */
issaiass 0:b9c385255fc8 86 SOMO14DInit(SOMO14DISR); /* Set up the sound module pins */
issaiass 0:b9c385255fc8 87 MsgBufInit(); /* Initialize the buffer */
issaiass 0:b9c385255fc8 88 MsgRxISRCfg(MsgRxISR); /* Attach Rx IRQ function */
issaiass 0:b9c385255fc8 89 MsgPutLine((INT8U *)"SOMO Waiting for commands\r"); /* Hello Message */
issaiass 0:b9c385255fc8 90 MsgPut('>'); /* Waiting a command sign */
issaiass 0:b9c385255fc8 91 while(1) { /* Repeat forever */
issaiass 0:b9c385255fc8 92 if (!MsgRxBufEmpty()) { /* If there is something Received */
issaiass 0:b9c385255fc8 93 action = MsgGetChar(); /* Get the action */
issaiass 0:b9c385255fc8 94 SOMOManageAction(action); /* Check which action to perform */
issaiass 0:b9c385255fc8 95 }
issaiass 0:b9c385255fc8 96 }
issaiass 0:b9c385255fc8 97 }
issaiass 0:b9c385255fc8 98
issaiass 0:b9c385255fc8 99
issaiass 0:b9c385255fc8 100 /*
issaiass 0:b9c385255fc8 101 *******************************************************************************
issaiass 0:b9c385255fc8 102 *
issaiass 0:b9c385255fc8 103 * MANAGE AN ACTION ON THE SOUND MODULE AND RETURN A MESSAGE
issaiass 0:b9c385255fc8 104 *
issaiass 0:b9c385255fc8 105 * Description : Check before a received character which action to perform
issaiass 0:b9c385255fc8 106 * Arguments : None
issaiass 0:b9c385255fc8 107 * Return : None
issaiass 0:b9c385255fc8 108 * Note(s) : None
issaiass 0:b9c385255fc8 109 *******************************************************************************
issaiass 0:b9c385255fc8 110 */
issaiass 0:b9c385255fc8 111
issaiass 0:b9c385255fc8 112 void SOMOManageAction(INT8U action) {
issaiass 0:b9c385255fc8 113 INT8U msg[4]; /* Buffer the audio no. */
issaiass 0:b9c385255fc8 114 INT8U n; /* Iterator */
issaiass 0:b9c385255fc8 115 static INT16U song; /* Current song to 0 */
issaiass 0:b9c385255fc8 116 static INT8U vol = 7; /* Volume to max */
issaiass 0:b9c385255fc8 117
issaiass 0:b9c385255fc8 118
issaiass 0:b9c385255fc8 119 switch (action) { /* Manage action */
issaiass 0:b9c385255fc8 120 case PLAY: /* Play the current song */
issaiass 0:b9c385255fc8 121 SOMO14DSetAudio(song); /* Set the current song and play it*/
issaiass 0:b9c385255fc8 122 MsgPutLine((INT8U *)"PLAY\r>"); /* Execution message */
issaiass 0:b9c385255fc8 123 break; /* Terminate action */
issaiass 0:b9c385255fc8 124 case HOLD: /* Hold/Release the current song */
issaiass 0:b9c385255fc8 125 SOMO14DPause(); /* Pause/Play the song */
issaiass 0:b9c385255fc8 126 MsgPutLine((INT8U *)"HOLD\r>"); /* Execution message */
issaiass 0:b9c385255fc8 127 break; /* Terminate action */
issaiass 0:b9c385255fc8 128 case STOP: /* Stop the song */
issaiass 0:b9c385255fc8 129 SOMO14DStop(); /* Quit playing the song */
issaiass 0:b9c385255fc8 130 MsgPutLine((INT8U *)"STOP\r>"); /* Execution message */
issaiass 0:b9c385255fc8 131 break; /* Terminate action */
issaiass 0:b9c385255fc8 132 case NEXT: /* Play the next song */
issaiass 0:b9c385255fc8 133 SOMO14DSetAudio(++song); /* Increment song and play */
issaiass 0:b9c385255fc8 134 MsgPutLine((INT8U *)"NEXT SONG\r>"); /* Execution message */
issaiass 0:b9c385255fc8 135 break; /* Terminate action */
issaiass 0:b9c385255fc8 136 case PREV: /* Play the previous song */
issaiass 0:b9c385255fc8 137 SOMO14DSetAudio(--song); /* Decrement song and play */
issaiass 0:b9c385255fc8 138 MsgPutLine((INT8U *)"PREVIOUS SONG\r>"); /* Execution message */
issaiass 0:b9c385255fc8 139 break; /* Terminate action */
issaiass 0:b9c385255fc8 140 case STAU: /* Set the audio */
issaiass 0:b9c385255fc8 141 MsgPutLine((INT8U *)"SET AUDIO TO: "); /* Step 1 message */
issaiass 0:b9c385255fc8 142 for(n = 0; n < 4; n++) { /* Repeat for 4 numbers */
issaiass 0:b9c385255fc8 143 while(MsgRxBufEmpty()) { /* Wait if is empty */
issaiass 0:b9c385255fc8 144 ;
issaiass 0:b9c385255fc8 145 }
issaiass 0:b9c385255fc8 146 msg[n] = MsgGetChar(); /* Hold the current no. in buffer */
issaiass 0:b9c385255fc8 147 MsgPut(msg[n]); /* Print the received char */
issaiass 0:b9c385255fc8 148 }
issaiass 0:b9c385255fc8 149 MsgPutLine((INT8U *)".ad4\r>"); /* Print an extra string (format) */
issaiass 0:b9c385255fc8 150 song = atoi((const char *)msg); /* Convert ASCII to number */
issaiass 0:b9c385255fc8 151 SOMO14DSetAudio(song); /* Play the song */
issaiass 0:b9c385255fc8 152 break; /* Terminate action */
issaiass 0:b9c385255fc8 153 case VOLUP: /* Increase volume */
issaiass 0:b9c385255fc8 154 SOMO14DSetVol(&(++vol)); /* Alter reference, increment vol */
issaiass 0:b9c385255fc8 155 MsgPutLine((INT8U *)"VOLUME "); /* Execution message */
issaiass 0:b9c385255fc8 156 MsgPut(vol + '0'); /* ASCII representation of numbers */
issaiass 0:b9c385255fc8 157 MsgPutLine((INT8U *)"\r>"); /* Print a command line */
issaiass 0:b9c385255fc8 158 break; /* Terminate action */
issaiass 0:b9c385255fc8 159 case VOLDN: /* Decrease volume */
issaiass 0:b9c385255fc8 160 SOMO14DSetVol(&(--vol)); /* Alter reference, decrement vol */
issaiass 0:b9c385255fc8 161 MsgPutLine((INT8U *)"VOLUME "); /* Execution message */
issaiass 0:b9c385255fc8 162 MsgPut(vol + '0'); /* ASCII representation of numbers */
issaiass 0:b9c385255fc8 163 MsgPutLine((INT8U *)"\r>"); /* Print a command line */
issaiass 0:b9c385255fc8 164 break; /* Terminate action */
issaiass 0:b9c385255fc8 165 default: /* Not a command? Print the help */
issaiass 0:b9c385255fc8 166 MsgPutLine((INT8U *)"NOT A COMMAND\r>");
issaiass 0:b9c385255fc8 167 MsgPutLine((INT8U *)"List of available commands:\r");
issaiass 0:b9c385255fc8 168 MsgPutLine((INT8U *)"p play the current song\r");
issaiass 0:b9c385255fc8 169 MsgPutLine((INT8U *)"h hold the current song\r");
issaiass 0:b9c385255fc8 170 MsgPutLine((INT8U *)"n play the next song in the queue\r");
issaiass 0:b9c385255fc8 171 MsgPutLine((INT8U *)"r play the previous song in the queue\r");
issaiass 0:b9c385255fc8 172 MsgPutLine((INT8U *)"a <num> set audio to a specific song, 511 > num > 0\r");
issaiass 0:b9c385255fc8 173 MsgPutLine((INT8U *)"+ set volume up, max 8 levels\r");
issaiass 0:b9c385255fc8 174 MsgPutLine((INT8U *)"- set volume down, max 8 levels\r>");
issaiass 0:b9c385255fc8 175 break; /* Terminate action */
issaiass 0:b9c385255fc8 176 }
issaiass 0:b9c385255fc8 177 }
issaiass 0:b9c385255fc8 178
issaiass 0:b9c385255fc8 179
issaiass 0:b9c385255fc8 180 /*
issaiass 0:b9c385255fc8 181 *******************************************************************************
issaiass 0:b9c385255fc8 182 *
issaiass 0:b9c385255fc8 183 * RX INTERRUPT SUBROUTINE REQUEST
issaiass 0:b9c385255fc8 184 *
issaiass 0:b9c385255fc8 185 * Description : Get the received character and insert it into the buffer
issaiass 0:b9c385255fc8 186 * Arguments : None
issaiass 0:b9c385255fc8 187 * Return : None
issaiass 0:b9c385255fc8 188 * Note(s) : None
issaiass 0:b9c385255fc8 189 *******************************************************************************
issaiass 0:b9c385255fc8 190 */
issaiass 0:b9c385255fc8 191
issaiass 0:b9c385255fc8 192 void MsgRxISR(void) {
issaiass 0:b9c385255fc8 193 MsgPutRxChar(MsgGet()); /* Put a byte on the buffer */
issaiass 0:b9c385255fc8 194 }
issaiass 0:b9c385255fc8 195
issaiass 0:b9c385255fc8 196
issaiass 0:b9c385255fc8 197 /*
issaiass 0:b9c385255fc8 198 *******************************************************************************
issaiass 0:b9c385255fc8 199 *
issaiass 0:b9c385255fc8 200 * SOMO14D INTERRUPT SUBROUTINE REQUEST ATTACH
issaiass 0:b9c385255fc8 201 *
issaiass 0:b9c385255fc8 202 * Description : Interrupt request when Busy pins goes from HIGH to LOW
issaiass 0:b9c385255fc8 203 * Arguments : None
issaiass 0:b9c385255fc8 204 * Return : None
issaiass 0:b9c385255fc8 205 * Notes : Busy pin is active low triggered.
issaiass 0:b9c385255fc8 206 *******************************************************************************
issaiass 0:b9c385255fc8 207 */
issaiass 0:b9c385255fc8 208
issaiass 0:b9c385255fc8 209 void SOMO14DISR(void) {
issaiass 0:b9c385255fc8 210 MsgPutLine((INT8U *)"Audio finish\r>"); /* Message on interrupt request */
issaiass 0:b9c385255fc8 211 }