mp3  2.0.0.0
mp3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 
36 #ifndef MP3_H
37 #define MP3_H
38 
43 #ifdef PREINIT_SUPPORTED
44 #include "preinit.h"
45 #endif
46 
47 #ifdef MikroCCoreVersion
48  #if MikroCCoreVersion >= 1
49  #include "delays.h"
50  #endif
51 #endif
52 
53 #include "drv_digital_out.h"
54 #include "drv_digital_in.h"
55 #include "drv_spi_master.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define MP3_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg.dreq = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75  cfg.dcs = MIKROBUS( mikrobus, MIKROBUS_INT )
76 
82 #define MP3_WRITE_CMD 0x02
83 #define MP3_READ_CMD 0x03
84 #define MP3_BASE_ADDR 0x00
85 #define MP3_MODE_ADDR 0x00
86 #define MP3_STATUS_ADDR 0x01
87 #define MP3_BASS_ADDR 0x02
88 #define MP3_CLOCKF_ADDR 0x03
89 #define MP3_DECODE_TIME_ADDR 0x04
90 #define MP3_AUDATA_ADDR 0x05
91 #define MP3_WRAM_ADDR 0x06
92 #define MP3_WRAMADDR_ADDR 0x07
93 #define MP3_HDAT0_ADDR 0x08
94 #define MP3_HDAT1_ADDR 0x09
95 #define MP3_AIADDR_ADDR 0x0A
96 #define MP3_VOL_ADDR 0x0B
97 #define MP3_AICTRL0_ADDR 0x0C
98 #define MP3_AICTRL1_ADDR 0x0D
99 #define MP3_AICTRL2_ADDR 0x0E
100 #define MP3_AICTRL3_ADDR 0x0F
101 
107 #define MP3_OK 0
108 #define MP3_ERROR -1
109  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef struct
122 {
123  // Output pins
124  digital_out_t rst;
125  digital_out_t dcs;
126 
127  // Input pins
128  digital_in_t dreq;
129 
130  // Modules
131  spi_master_t spi;
133  pin_name_t chip_select;
135 } mp3_t;
136 
140 typedef struct
141 {
142  // Communication gpio pins
143  pin_name_t miso;
144  pin_name_t mosi;
145  pin_name_t sck;
146  pin_name_t cs;
148  // Additional gpio pins
149  pin_name_t dreq;
150  pin_name_t rst;
151  pin_name_t dcs;
152 
153  // static variable
154  uint32_t spi_speed;
155  spi_master_mode_t spi_mode;
156  spi_master_chip_select_polarity_t cs_polarity;
158 } mp3_cfg_t;
159  // End types group
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
179 void mp3_cfg_setup ( mp3_cfg_t *cfg );
180 
188 err_t mp3_init ( mp3_t *ctx, mp3_cfg_t *cfg );
189 
193 void mp3_reset( mp3_t *ctx );
194 
200 uint8_t mp3_is_busy( mp3_t *ctx );
201 
208 void mp3_cmd_write( mp3_t *ctx, uint8_t address, uint16_t input );
209 
215 uint16_t mp3_cmd_read( mp3_t *ctx, uint8_t address );
216 
222 err_t mp3_data_write( mp3_t *ctx, uint8_t input );
223 
229 err_t mp3_data_write_32( mp3_t *ctx, uint8_t *input32 );
230 
238 void mp3_set_volume ( mp3_t *ctx, uint8_t vol_left, uint8_t vol_right );
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif // _MP3_H_
244  // End public_function group
247 
248 // ------------------------------------------------------------------------- END
mp3_cfg_t
Click configuration structure definition.
Definition: mp3.h:141
mp3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mp3.h:156
mp3_cfg_t::mosi
pin_name_t mosi
Definition: mp3.h:144
mp3_cfg_t::spi_speed
uint32_t spi_speed
Definition: mp3.h:154
mp3_data_write
err_t mp3_data_write(mp3_t *ctx, uint8_t input)
Function writes one byte ( data ) to MP3.
mp3_t
Click ctx object definition.
Definition: mp3.h:122
mp3_t::dcs
digital_out_t dcs
Definition: mp3.h:125
mp3_init
err_t mp3_init(mp3_t *ctx, mp3_cfg_t *cfg)
Initialization function.
mp3_cfg_t::miso
pin_name_t miso
Definition: mp3.h:143
mp3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mp3.h:155
mp3_cmd_write
void mp3_cmd_write(mp3_t *ctx, uint8_t address, uint16_t input)
Function writes one byte (command) to MP3.
mp3_cfg_t::dcs
pin_name_t dcs
Definition: mp3.h:151
mp3_set_volume
void mp3_set_volume(mp3_t *ctx, uint8_t vol_left, uint8_t vol_right)
Function set volume to MP3 click for left and right channels.
mp3_cfg_t::cs
pin_name_t cs
Definition: mp3.h:146
mp3_cfg_t::rst
pin_name_t rst
Definition: mp3.h:150
mp3_cmd_read
uint16_t mp3_cmd_read(mp3_t *ctx, uint8_t address)
Function reads command from MP3.
mp3_t::chip_select
pin_name_t chip_select
Definition: mp3.h:133
mp3_cfg_t::sck
pin_name_t sck
Definition: mp3.h:145
mp3_data_write_32
err_t mp3_data_write_32(mp3_t *ctx, uint8_t *input32)
Function Write 32 bytes ( data ) to MP3.
mp3_t::spi
spi_master_t spi
Definition: mp3.h:131
mp3_cfg_t::dreq
pin_name_t dreq
Definition: mp3.h:149
mp3_reset
void mp3_reset(mp3_t *ctx)
Functions for reset MP3 module.
mp3_t::rst
digital_out_t rst
Definition: mp3.h:124
mp3_is_busy
uint8_t mp3_is_busy(mp3_t *ctx)
Function that checks whether busy mp3.
mp3_cfg_setup
void mp3_cfg_setup(mp3_cfg_t *cfg)
Config Object Initialization function.
mp3_t::dreq
digital_in_t dreq
Definition: mp3.h:128