mp32  2.0.0.0
mp32.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 #ifndef MP32_H
36 #define MP32_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define MP32_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
67 
74 #define MP32_RETVAL uint8_t
75 
76 #define MP32_OK 0x00
77 #define MP32_INIT_ERROR 0xFF
78 
84 #define DRV_RX_BUFFER_SIZE 200
85 #define DRV_TX_BUFFER_SIZE 50
86 
92 #define MP32_NUM_CMD_BYTES 8
93 #define MP32_TIMEOUT 1000
94 #define MP32_MAX_VOL 0x1E
95 
101 #define MP32_CMD_START_CODE 0x7E
102 #define MP32_CMD_END_CODE 0xEF
103 #define MP32_VERSION_CODE 0xFF
104 #define MP32_FDBK_CODE_ON 0x01
105 #define MP32_FDBK_CODE_OFF 0x00
106 
112 #define MP32_PLAY_NEXT_SONG 0x01
113 #define MP32_PLAY_PREV_SONG 0x02
114 #define MP32_PLAY_SPEC_TRACK 0x03
115 #define MP32_SET_VOL_UP 0x04
116 #define MP32_SET_VOL_DOWN 0x05
117 #define MP32_SET_VOL_VALUE 0x06
118 #define MP32_SET_EQUALIZER 0x07
119 #define MP32_REP_CURR_TRACK 0x08
120 #define MP32_SET_DEV 0x09
121 #define MP32_ENTER_STDBY_MODE 0x0A
122 #define MP32_RESET 0x0C
123 #define MP32_PLAY 0x0D
124 #define MP32_PAUSE 0x0E
125 #define MP32_PLAY_SONG_SPEC 0x0F
126 #define MP32_SET_ALL_LOOP 0x11
127 #define MP32_PLAY_SONG_MP3 0x12
128 #define MP32_PLAY_SONG_ADV 0x13
129 #define MP32_SET_SONG_NAME 0x14
130 #define MP32_ADD_LOOP_TRACK 0x15
131 #define MP32_STOP 0x16
132 #define MP32_SET_LOOP_FOL 0x17
133 #define MP32_SET_SHUF_ALL 0x18
134 #define MP32_REP_SINGLE 0x19
135 #define MP32_SET_SHUF_FOL 0x28
136 
142 #define MP32_EQ_NORMAL 0x00
143 #define MP32_EQ_POP 0x01
144 #define MP32_EQ_ROCK 0x02
145 #define MP32_EQ_JAZZ 0x03
146 #define MP32_EQ_CLASSIC 0x04
147 #define MP32_EQ_BASS 0x05
148 
154 #define MP32_U_DISK 0x01
155 #define MP32_SDCARD 0x02
156 
162 #define MP32_STOP_LOOP 0x00
163 #define MP32_START_LOOP 0x01
164 
170 #define MP32_DISABLE 0x00
171 #define MP32_ENABLE 0x01
172  // End group macro
175 // --------------------------------------------------------------- PUBLIC TYPES
183 typedef struct
184 {
185  // Output pins
186 
187  digital_out_t rst;
188 
189  // Modules
190 
191  uart_t uart;
192 
193  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
194  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
195 
196 } mp32_t;
197 
201 typedef struct
202 {
203  // Communication gpio pins
204 
205  pin_name_t rx_pin;
206  pin_name_t tx_pin;
207 
208  // Additional gpio pins
209 
210  pin_name_t rst;
211 
212 
213  // static variable
214 
215  uint32_t baud_rate; // Clock speed.
217  uart_data_bits_t data_bit; // Data bits.
218  uart_parity_t parity_bit; // Parity bit.
219  uart_stop_bits_t stop_bit; // Stop bits.
220 
221 } mp32_cfg_t;
222 
226 typedef uint8_t mp32_error_t;
227  // End types group
229 
230 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
231 
237 #ifdef __cplusplus
238 extern "C"{
239 #endif
240 
250 
259 
266 void mp32_generic_write ( mp32_t *ctx, char *data_buf, uint16_t len );
267 
275 int32_t mp32_generic_read ( mp32_t *ctx, char *data_buf, uint16_t max_len );
276 
284 void mp32_hw_reset ( mp32_t *ctx );
285 
296 void mp32_rx_cmd ( mp32_t *ctx, uint8_t *rd_data, uint8_t len );
297 
308 void mp32_tx_cmd ( mp32_t *ctx, uint8_t cmd, uint16_t spec_data );
309 
317 void mp32_sw_reset ( mp32_t *ctx );
318 
327 void mp32_play_specific ( mp32_t *ctx, uint16_t track_index );
328 
336 void mp32_play_mode ( mp32_t *ctx );
337 
345 void mp32_pause_mode ( mp32_t *ctx );
346 
354 void mp32_stop_mode ( mp32_t *ctx );
355 
365 void mp32_set_volume ( mp32_t *ctx, uint8_t perc );
366 
374 void mp32_volume_up ( mp32_t *ctx );
375 
383 void mp32_volume_down ( mp32_t *ctx );
384 
392 void mp32_play_next ( mp32_t *ctx );
393 
402 
412 void mp32_set_eq ( mp32_t *ctx, uint8_t eq );
413 
422 
430 void mp32_set_device ( mp32_t *ctx, uint8_t device );
431 
440 
451 void mp32_play_spec_in_fol ( mp32_t *ctx, uint8_t fol_inx, uint8_t track_inx );
452 
464 void mp32_loop_all ( mp32_t *ctx, uint8_t loop_mode );
465 
474 void mp32_play_fol ( mp32_t *ctx, uint8_t fol_inx );
475 
484 void mp32_loop_fol ( mp32_t *ctx, uint8_t fol_inx );
485 
493 void mp32_random_all ( mp32_t *ctx );
494 
495 // Loop Repeat a current song
507 void mp32_loop ( mp32_t *ctx, uint8_t state );
508 
509 #ifdef __cplusplus
510 }
511 #endif
512 #endif // _MP32_H_
513  // End public_function group
516 
517 // ------------------------------------------------------------------------- END
mp32_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mp32.h:206
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: mp32.h:84
mp32_loop_fol
void mp32_loop_fol(mp32_t *ctx, uint8_t fol_inx)
Loop folder function.
mp32_stop_mode
void mp32_stop_mode(mp32_t *ctx)
Stop mode function.
mp32_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mp32.h:218
mp32_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mp32.h:205
mp32_t::rst
digital_out_t rst
Definition: mp32.h:187
mp32_sw_reset
void mp32_sw_reset(mp32_t *ctx)
Software reset function.
mp32_rx_cmd
void mp32_rx_cmd(mp32_t *ctx, uint8_t *rd_data, uint8_t len)
Received response data function.
mp32_error_t
uint8_t mp32_error_t
Error type.
Definition: mp32.h:226
mp32_cfg_t::rst
pin_name_t rst
Definition: mp32.h:210
mp32_set_device
void mp32_set_device(mp32_t *ctx, uint8_t device)
Set device function.
mp32_t
Click ctx object definition.
Definition: mp32.h:184
mp32_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: mp32.h:219
mp32_play_previous
void mp32_play_previous(mp32_t *ctx)
Play previous command function.
mp32_play_next
void mp32_play_next(mp32_t *ctx)
Play previous command function.
mp32_cfg_t::uart_blocking
bool uart_blocking
Definition: mp32.h:216
mp32_set_eq
void mp32_set_eq(mp32_t *ctx, uint8_t eq)
Set equalizer mode function.
mp32_generic_write
void mp32_generic_write(mp32_t *ctx, char *data_buf, uint16_t len)
Generic write function.
mp32_volume_up
void mp32_volume_up(mp32_t *ctx)
Volume up function.
mp32_hw_reset
void mp32_hw_reset(mp32_t *ctx)
Reset the device function.
mp32_volume_down
void mp32_volume_down(mp32_t *ctx)
Play next command function.
mp32_t::uart
uart_t uart
Definition: mp32.h:191
mp32_cfg_t::baud_rate
uint32_t baud_rate
Definition: mp32.h:215
mp32_play_spec_in_fol
void mp32_play_spec_in_fol(mp32_t *ctx, uint8_t fol_inx, uint8_t track_inx)
Specify a certain folder and play tracks inside function.
mp32_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mp32.h:217
mp32_loop
void mp32_loop(mp32_t *ctx, uint8_t state)
Repeat a current song function.
mp32_repeat_current
void mp32_repeat_current(mp32_t *ctx)
Repeat current mode function.
mp32_generic_read
int32_t mp32_generic_read(mp32_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: mp32.h:85
mp32_cfg_setup
void mp32_cfg_setup(mp32_cfg_t *cfg)
Config Object Initialization function.
mp32_play_mode
void mp32_play_mode(mp32_t *ctx)
Play mode function.
mp32_pause_mode
void mp32_pause_mode(mp32_t *ctx)
Pause mode function.
mp32_init
MP32_RETVAL mp32_init(mp32_t *ctx, mp32_cfg_t *cfg)
Initialization function.
mp32_loop_all
void mp32_loop_all(mp32_t *ctx, uint8_t loop_mode)
Play specific in loop mode function.
MP32_RETVAL
#define MP32_RETVAL
Definition: mp32.h:74
mp32_play_specific
void mp32_play_specific(mp32_t *ctx, uint16_t track_index)
Play specific function.
mp32_random_all
void mp32_random_all(mp32_t *ctx)
Random Play function.
mp32_play_fol
void mp32_play_fol(mp32_t *ctx, uint8_t fol_inx)
Play folder function.
mp32_tx_cmd
void mp32_tx_cmd(mp32_t *ctx, uint8_t cmd, uint16_t spec_data)
Write command function.
mp32_set_volume
void mp32_set_volume(mp32_t *ctx, uint8_t perc)
Set Volume function.
mp32_set_low_power_mode
void mp32_set_low_power_mode(mp32_t *ctx)
Set Low power mode function.
mp32_cfg_t
Click configuration structure definition.
Definition: mp32.h:202