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 
39 #include "drv_digital_out.h"
40 #include "drv_digital_in.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define MP3_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.dreq = MIKROBUS( mikrobus, MIKROBUS_AN ); \
60  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
61  cfg.dcs = MIKROBUS( mikrobus, MIKROBUS_INT )
62 
68 #define MP3_WRITE_CMD 0x02
69 #define MP3_READ_CMD 0x03
70 #define MP3_BASE_ADDR 0x00
71 #define MP3_MODE_ADDR 0x00
72 #define MP3_STATUS_ADDR 0x01
73 #define MP3_BASS_ADDR 0x02
74 #define MP3_CLOCKF_ADDR 0x03
75 #define MP3_DECODE_TIME_ADDR 0x04
76 #define MP3_AUDATA_ADDR 0x05
77 #define MP3_WRAM_ADDR 0x06
78 #define MP3_WRAMADDR_ADDR 0x07
79 #define MP3_HDAT0_ADDR 0x08
80 #define MP3_HDAT1_ADDR 0x09
81 #define MP3_AIADDR_ADDR 0x0A
82 #define MP3_VOL_ADDR 0x0B
83 #define MP3_AICTRL0_ADDR 0x0C
84 #define MP3_AICTRL1_ADDR 0x0D
85 #define MP3_AICTRL2_ADDR 0x0E
86 #define MP3_AICTRL3_ADDR 0x0F
87 
93 #define MP3_OK 0
94 #define MP3_ERROR -1
95  // End group macro
98 // --------------------------------------------------------------- PUBLIC TYPES
107 typedef struct
108 {
109  // Output pins
110  digital_out_t rst;
111  digital_out_t dcs;
112 
113  // Input pins
114  digital_in_t dreq;
115 
116  // Modules
117  spi_master_t spi;
119  pin_name_t chip_select;
121 } mp3_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t miso;
130  pin_name_t mosi;
131  pin_name_t sck;
132  pin_name_t cs;
134  // Additional gpio pins
135  pin_name_t dreq;
136  pin_name_t rst;
137  pin_name_t dcs;
138 
139  // static variable
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
144 } mp3_cfg_t;
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
165 void mp3_cfg_setup ( mp3_cfg_t *cfg );
166 
174 err_t mp3_init ( mp3_t *ctx, mp3_cfg_t *cfg );
175 
179 void mp3_reset( mp3_t *ctx );
180 
186 uint8_t mp3_is_busy( mp3_t *ctx );
187 
194 void mp3_cmd_write( mp3_t *ctx, uint8_t address, uint16_t input );
195 
201 uint16_t mp3_cmd_read( mp3_t *ctx, uint8_t address );
202 
208 err_t mp3_data_write( mp3_t *ctx, uint8_t input );
209 
215 err_t mp3_data_write_32( mp3_t *ctx, uint8_t *input32 );
216 
224 void mp3_set_volume ( mp3_t *ctx, uint8_t vol_left, uint8_t vol_right );
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 #endif // _MP3_H_
230  // End public_function group
233 
234 // ------------------------------------------------------------------------- END
mp3_cfg_t
Click configuration structure definition.
Definition: mp3.h:127
mp3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mp3.h:142
mp3_cfg_t::mosi
pin_name_t mosi
Definition: mp3.h:130
mp3_cfg_t::spi_speed
uint32_t spi_speed
Definition: mp3.h:140
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:108
mp3_t::dcs
digital_out_t dcs
Definition: mp3.h:111
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:129
mp3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mp3.h:141
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:137
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:132
mp3_cfg_t::rst
pin_name_t rst
Definition: mp3.h:136
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:119
mp3_cfg_t::sck
pin_name_t sck
Definition: mp3.h:131
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:117
mp3_cfg_t::dreq
pin_name_t dreq
Definition: mp3.h:135
mp3_reset
void mp3_reset(mp3_t *ctx)
Functions for reset MP3 module.
mp3_t::rst
digital_out_t rst
Definition: mp3.h:110
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:114