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 )
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
107#define MP3_OK 0
108#define MP3_ERROR -1
111 // End group macro
112// --------------------------------------------------------------- PUBLIC TYPES
121typedef 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
140typedef 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
160 // End types group
161// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162
167#ifdef __cplusplus
168extern "C"{
169#endif
170
180
188err_t mp3_init ( mp3_t *ctx, mp3_cfg_t *cfg );
189
193void mp3_reset( mp3_t *ctx );
194
200uint8_t mp3_is_busy( mp3_t *ctx );
201
208void mp3_cmd_write( mp3_t *ctx, uint8_t address, uint16_t input );
209
215uint16_t mp3_cmd_read( mp3_t *ctx, uint8_t address );
216
222err_t mp3_data_write( mp3_t *ctx, uint8_t input );
223
229err_t mp3_data_write_32( mp3_t *ctx, uint8_t *input32 );
230
238void 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
245 // End public_function group
247
248// ------------------------------------------------------------------------- END
void mp3_cfg_setup(mp3_cfg_t *cfg)
Config Object Initialization function.
err_t mp3_data_write(mp3_t *ctx, uint8_t input)
Function writes one byte ( data ) to MP3.
uint16_t mp3_cmd_read(mp3_t *ctx, uint8_t address)
Function reads command from MP3.
err_t mp3_init(mp3_t *ctx, mp3_cfg_t *cfg)
Initialization function.
void mp3_cmd_write(mp3_t *ctx, uint8_t address, uint16_t input)
Function writes one byte (command) to MP3.
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.
void mp3_reset(mp3_t *ctx)
Functions for reset MP3 module.
err_t mp3_data_write_32(mp3_t *ctx, uint8_t *input32)
Function Write 32 bytes ( data ) to MP3.
uint8_t mp3_is_busy(mp3_t *ctx)
Function that checks whether busy mp3.
Click configuration structure definition.
Definition mp3.h:141
spi_master_chip_select_polarity_t cs_polarity
Definition mp3.h:156
pin_name_t dcs
Definition mp3.h:151
pin_name_t sck
Definition mp3.h:145
spi_master_mode_t spi_mode
Definition mp3.h:155
pin_name_t mosi
Definition mp3.h:144
uint32_t spi_speed
Definition mp3.h:154
pin_name_t dreq
Definition mp3.h:149
pin_name_t miso
Definition mp3.h:143
pin_name_t rst
Definition mp3.h:150
pin_name_t cs
Definition mp3.h:146
Click ctx object definition.
Definition mp3.h:122
spi_master_t spi
Definition mp3.h:131
digital_in_t dreq
Definition mp3.h:128
digital_out_t rst
Definition mp3.h:124
pin_name_t chip_select
Definition mp3.h:133
digital_out_t dcs
Definition mp3.h:125