4D Systems Sound Module Library
Dependents: STM32F030R8_SOMO-14D
SOMO-14D
The SOMO-14D is a tiny Audio-Sound module that can play back pre-stored audio files such as voice and music from a micro-SD memory card. The module supports 4-bit ADPCM audio files with sample rates from 6Khz up to 32Khz. By using the freely available software tool, any WAVE(.wav) or MP3(.mp3) file can be easily converted to the ADPCM(.ad4) format which can then be can be saved to a micro-SD memory card. The compact 14pin drop-in-module takes up very minimal board space and is ideal for any application that requires embedded audio.
The SERIAL-MODE provides a simple 2-wire interface to any micro-controller via its DATA and CLK lines. Audio operations such as PLAY, PAUSE,STOP and VOLUME control functions are all available to the host micro via simple serial commands.
SOMO-14D Library
The SOMO library handles all basic functions that access the hardware to set the commands that ensure SERIAL-MODE interfacing.
Some of the functions can make control of: - Initialization - Activity - Command
Initialization Function
- void SOMO14DInit(void (*pfunc)(void));
Activity Function
- INT8U SOMO14DisBusy(void);
Commanding Functions
- void SOMO14DSerialOut(INT16U SOMO14Duint16);
- void SOMO14DPause(void);
- void SOMO14DStop(void);
- void SOMO14DSetVol(INT8U *SOMO14DVol);
- void SOMO14DSetAudio(INT16U SOMO14DAudioFileNo);
For check the function by capability please check the "functions" wiki
Revision 0:41f21e0cf86f, committed 2015-03-13
- Comitter:
- issaiass
- Date:
- Fri Mar 13 01:12:55 2015 +0000
- Child:
- 1:803045697299
- Commit message:
- SOund MOdule from 4D Systems Library
Changed in this revision
SOMO14D.cpp | Show annotated file Show diff for this revision Revisions of this file |
SOMO14D.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SOMO14D.cpp Fri Mar 13 01:12:55 2015 +0000 @@ -0,0 +1,192 @@ +/* +******************************************************************************* +* CERES CONTROLS +* PANAMA, REPULIC OF PANAMA +* +* File : SOMO14D.h +* Programmer(s) : Rangel Alvarado +* Language : ANSI-C +* Description : SOMO14D is an acronym of SOund MOdule 1 4D SYSTEMS INC. +* The file manage all functions of the SOMO. +* +* Note : Dependancies of mbed libraries... +* - InterruptIn +* - DigitalOut +* +* ---------------------------------------------------------------------------- +* HISTORY +* DD MM AA +* 09 03 15 Created. +* 09 03 15 Modified. +* 12 03 15 Import to mbed platform. +******************************************************************************* +*/ + +/* +******************************************************************************* +* INCLUDE FILES +******************************************************************************* +*/ + +#include "includes.h" /* Main include file */ + +InterruptIn SOMO14DBusy(SOMO_BUSY_PIN); /* BUSY signal. Active HIGH output. */ +DigitalOut SOMO14DData(SOMO_DATA_PIN); /* Serial DATA input from host MCU */ +DigitalOut SOMO14DClk(SOMO_CLK_PIN); /* Serial Clock input from host MCU */ +DigitalOut SOMO14DReset(SOMO_RESET_PIN);/* Master Reset. Active LOW trigger. */ + +/* +******************************************************************************* +* +* SOMO14D IS BUSY +* +* Description : Check if a function is executing by the module +* Arguments : None +* Return : TRUE if the module is holding an action +* FALSE if the module is in waiting state +* Notes : Busy pin is active low triggered. +******************************************************************************* +*/ + +INT8U SOMO14DisBusy(void) { + if(SOMO14DBusy.read()) { /* If input is HIGH */ + return TRUE; /* SOMO is doing something */ + } + return FALSE; /* SOMO is on low power mode */ +} + +/* +******************************************************************************* +* +* INITIALIZE THE SOUND MODULE +* +* Description : Initial setup for the module and signals +* Arguments : pfunc pointer to function of an ISR +* Return : None +* Notes : Activity pins are in idle state +******************************************************************************* +*/ + +void SOMO14DInit(void (*pfunc)(void)) { + SOMO14DBusy.disable_irq(); /* disble busy pin interrupt */ + SOMO14DReset = HIGH; /* Reset the SOMO */ + SOMO14DClk = HIGH; /* Hold line up */ + SOMO14DData = HIGH; /* Hold data up */ + SOMO14DBusy.fall(pfunc); /* Attach an ISR */ + SOMO14DBusy.mode(PullUp); /* Pull up this pin */ + SOMO14DBusy.enable_irq(); /* Enable the pin IRQ */ +} + +/* +******************************************************************************* +* +* SOUND MODULE SERIAL OUT COMMAND +* +* Description : Send the command, left to right, first is B15, last B0. +* Arguments : SOMO14Duint16 16-bit command that makes an action +* Return : None +* Notes : None +******************************************************************************* +*/ + +void SOMO14DSerialOut(INT16U SOMO14Duint16) { + INT16U bit; /* Handles bit variable */ + INT8U i; /* Iterator */ + + + SOMO14DClk = LOW; /* CLK = 0 */ + wait(SOMO_WAIT_BIT); /* Waits between bits */ + for (i = 0; i < 16; i++) { /* Extract the 16 bits */ + bit = (SOMO14Duint16 & (0x8000 >> i)); /* get a bit */ + if (bit) { /* if flagged */ + SOMO14DData = HIGH; /* DATA = 1 */ + } else { /* Otherwise */ + SOMO14DData = LOW; /* DATA = 0 */ + } + wait(SOMO_WAIT_BIT); /* Waits between bits */ + SOMO14DClk = HIGH; /* CLK = 1 */ + wait(SOMO_WAIT_BIT); /* Waits between bits */ + SOMO14DClk = LOW; /* CLK = 0 */ + } + wait(SOMO_WAIT_IDLE); /* Idle State */ + SOMO14DClk = HIGH; /* Return clock to idle */ +} + + +/* +******************************************************************************* +* +* PAUSE THE SOUND MODULE +* +* Description : Hold or release signal for the sound module (pause/play) +* Arguments : None +* Return : None +* Notes : None +******************************************************************************* +*/ + +void SOMO14DPause(void) { + SOMO14DSerialOut(SOMO_PAUSE_CMD_OFFSET); /* Send Pause Command */ +} + +/* +******************************************************************************* +* +* STOP THE SOUND MODULE +* +* Description : Send a stop signal and goes to low consumption mode +* Arguments : None +* Return : None +* Notes : None +******************************************************************************* +*/ + +void SOMO14DStop() { + SOMO14DSerialOut(SOMO_STOP_CMD_OFFSET); /* Send Stop Command */ +} + +/* +******************************************************************************* +* +* SET A VOLUME LEVEL ON THE SOUND MODULE +* +* Description : Send a stop signal and goes to low consumption mode +* Arguments : None +* Return : None +* Notes : None +******************************************************************************* +*/ + +void SOMO14DSetVol(INT8U *SOMO14DVol) { + INT16U vol; /* Volume local variable */ + + + if (*SOMO14DVol == SOMO_VOL_UNF) { /* If volume is underflowed */ + *SOMO14DVol = SOMO_VOL_MIN; /* Set the volume to mute */ + } + if (*SOMO14DVol > SOMO_VOL_MAX) { /* If volume is maximum */ + *SOMO14DVol = SOMO_VOL_MAX; /* Stay on maximum */ + } + vol = SOMO_VOL_CMD_OFFSET + *SOMO14DVol; /* Set volume level */ + SOMO14DSerialOut(vol); /* Send volume command */ +} + + +/* +******************************************************************************* +* +* SET AN AUDIO FILE ON THE PLAYLIST +* +* Description : Send a stop signal and goes to low consumption mode +* Arguments : SOMO14DAudioFileNo audio file to play +* Return : None +* Notes : 0 = Min, 511 = Max. Total = 512 files. +******************************************************************************* +*/ + +void SOMO14DSetAudio(INT16U SOMO14DAudioFileNo) { + if (SOMO14DAudioFileNo > SOMO_SONG_CMD_MAX) {/* If file is over max */ + SOMO14DAudioFileNo = SOMO_SONG_CMD_MAX; /* Trunk to max */ + } + SOMO14DSerialOut(SOMO14DAudioFileNo); /* Fetch the file and play */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SOMO14D.h Fri Mar 13 01:12:55 2015 +0000 @@ -0,0 +1,62 @@ +/* +******************************************************************************* +* CERES CONTROLS +* PANAMA, REPULIC OF PANAMA +* +* File : SOMO14D.h +* Programmer(s) : Rangel Alvarado +* Language : ANSI-C +* Description : SOMO14D is an acronym of SOund MOdule 1 4D SYSTEMS INC. +* The file mlist all public functions which can be called on +* your application. +* +* Note : Dependancies of mbed libraries... +* - InterruptIn +* - DigitalOut +* +* ---------------------------------------------------------------------------- +* HISTORY +* DD MM AA +* 09 03 15 Created. +* 09 03 15 Modified. +* 12 03 15 Import to mbed platform. +******************************************************************************* +*/ + + +/* +******************************************************************************* +* CONSTANTS AND MACROS +******************************************************************************* +*/ + +#define SOMO_BUSY_PIN PC_0 /* BUSY signal. Active HIGH output. */ +#define SOMO_DATA_PIN PC_1 /* Serial DATA input from host MCU */ +#define SOMO_CLK_PIN PC_2 /* Serial Clock input from host MCU */ +#define SOMO_RESET_PIN PC_3 /* Master Reset. Active LOW trigger. */ +#define SOMO_WAIT_BIT 0.01 /* Wait between bits, base = 1 sec. */ +#define SOMO_WAIT_IDLE 0.05 /* Wait between idle, base = 1 sec. */ + + +#define SOMO_SONG_CMD_MAX 0x01FF /* 0x0000 = first; 0x01FF = last */ +#define SOMO_VOL_CMD_OFFSET 0xFFF0 /* 0xFFF0 = Vol 0; 0xFFF7 = Vol 7 */ +#define SOMO_PAUSE_CMD_OFFSET 0xFFFE /* Hold or pause/play command */ +#define SOMO_STOP_CMD_OFFSET 0xFFFF /* Stop audio command */ +#define SOMO_VOL_UNF 0xFF /* Volume underflow (app specific) */ +#define SOMO_VOL_MIN 0 /* Volume minimun */ +#define SOMO_VOL_MAX 7 /* Volume maximum */ + + +/* +******************************************************************************* +* FUNCTION PROTOTYPES +******************************************************************************* +*/ + +INT8U SOMO14DisBusy(void); /* Check if SOMO is doing something */ +void SOMO14DInit(void (*pfunc)(void)); /* Initialize the sound module */ +void SOMO14DSerialOut(INT16U SOMO14Duint16); /* Serial out command */ +void SOMO14DPause(void); /* Hold the current song */ +void SOMO14DStop(void); /* Stop audio and go to sleep mode */ +void SOMO14DSetVol(INT8U *SOMO14DVol); /* Increase/Decrease the volume */ +void SOMO14DSetAudio(INT16U SOMO14DAudioFileNo); /* Set audio file */