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 "mikrosdk_version.h"
40 
41 #ifdef __GNUC__
42 #if mikroSDK_GET_VERSION < 20800ul
43 #include "rcu_delays.h"
44 #else
45 #include "delays.h"
46 #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define MP3_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.dreq = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.dcs = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define MP3_WRITE_CMD 0x02
79 #define MP3_READ_CMD 0x03
80 #define MP3_BASE_ADDR 0x00
81 #define MP3_MODE_ADDR 0x00
82 #define MP3_STATUS_ADDR 0x01
83 #define MP3_BASS_ADDR 0x02
84 #define MP3_CLOCKF_ADDR 0x03
85 #define MP3_DECODE_TIME_ADDR 0x04
86 #define MP3_AUDATA_ADDR 0x05
87 #define MP3_WRAM_ADDR 0x06
88 #define MP3_WRAMADDR_ADDR 0x07
89 #define MP3_HDAT0_ADDR 0x08
90 #define MP3_HDAT1_ADDR 0x09
91 #define MP3_AIADDR_ADDR 0x0A
92 #define MP3_VOL_ADDR 0x0B
93 #define MP3_AICTRL0_ADDR 0x0C
94 #define MP3_AICTRL1_ADDR 0x0D
95 #define MP3_AICTRL2_ADDR 0x0E
96 #define MP3_AICTRL3_ADDR 0x0F
97 
103 #define MP3_OK 0
104 #define MP3_ERROR -1
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  // Output pins
120  digital_out_t rst;
121  digital_out_t dcs;
122 
123  // Input pins
124  digital_in_t dreq;
125 
126  // Modules
127  spi_master_t spi;
129  pin_name_t chip_select;
131 } mp3_t;
132 
136 typedef struct
137 {
138  // Communication gpio pins
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
144  // Additional gpio pins
145  pin_name_t dreq;
146  pin_name_t rst;
147  pin_name_t dcs;
148 
149  // static variable
150  uint32_t spi_speed;
151  spi_master_mode_t spi_mode;
152  spi_master_chip_select_polarity_t cs_polarity;
154 } mp3_cfg_t;
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
175 void mp3_cfg_setup ( mp3_cfg_t *cfg );
176 
184 err_t mp3_init ( mp3_t *ctx, mp3_cfg_t *cfg );
185 
189 void mp3_reset( mp3_t *ctx );
190 
196 uint8_t mp3_is_busy( mp3_t *ctx );
197 
204 void mp3_cmd_write( mp3_t *ctx, uint8_t address, uint16_t input );
205 
211 uint16_t mp3_cmd_read( mp3_t *ctx, uint8_t address );
212 
218 err_t mp3_data_write( mp3_t *ctx, uint8_t input );
219 
225 err_t mp3_data_write_32( mp3_t *ctx, uint8_t *input32 );
226 
234 void mp3_set_volume ( mp3_t *ctx, uint8_t vol_left, uint8_t vol_right );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // _MP3_H_
240  // End public_function group
243 
244 // ------------------------------------------------------------------------- END
mp3_cfg_t
Click configuration structure definition.
Definition: mp3.h:137
mp3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mp3.h:152
mp3_cfg_t::mosi
pin_name_t mosi
Definition: mp3.h:140
mp3_cfg_t::spi_speed
uint32_t spi_speed
Definition: mp3.h:150
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:118
mp3_t::dcs
digital_out_t dcs
Definition: mp3.h:121
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:139
mp3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mp3.h:151
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:147
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:142
mp3_cfg_t::rst
pin_name_t rst
Definition: mp3.h:146
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:129
mp3_cfg_t::sck
pin_name_t sck
Definition: mp3.h:141
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:127
mp3_cfg_t::dreq
pin_name_t dreq
Definition: mp3.h:145
mp3_reset
void mp3_reset(mp3_t *ctx)
Functions for reset MP3 module.
mp3_t::rst
digital_out_t rst
Definition: mp3.h:120
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:124