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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define MP32_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
71
78#define MP32_RETVAL uint8_t
79
80#define MP32_OK 0x00
81#define MP32_INIT_ERROR 0xFF
88#define DRV_RX_BUFFER_SIZE 200
89#define DRV_TX_BUFFER_SIZE 50
96#define MP32_NUM_CMD_BYTES 8
97#define MP32_TIMEOUT 1000
98#define MP32_MAX_VOL 0x1E
105#define MP32_CMD_START_CODE 0x7E
106#define MP32_CMD_END_CODE 0xEF
107#define MP32_VERSION_CODE 0xFF
108#define MP32_FDBK_CODE_ON 0x01
109#define MP32_FDBK_CODE_OFF 0x00
116#define MP32_PLAY_NEXT_SONG 0x01
117#define MP32_PLAY_PREV_SONG 0x02
118#define MP32_PLAY_SPEC_TRACK 0x03
119#define MP32_SET_VOL_UP 0x04
120#define MP32_SET_VOL_DOWN 0x05
121#define MP32_SET_VOL_VALUE 0x06
122#define MP32_SET_EQUALIZER 0x07
123#define MP32_REP_CURR_TRACK 0x08
124#define MP32_SET_DEV 0x09
125#define MP32_ENTER_STDBY_MODE 0x0A
126#define MP32_RESET 0x0C
127#define MP32_PLAY 0x0D
128#define MP32_PAUSE 0x0E
129#define MP32_PLAY_SONG_SPEC 0x0F
130#define MP32_SET_ALL_LOOP 0x11
131#define MP32_PLAY_SONG_MP3 0x12
132#define MP32_PLAY_SONG_ADV 0x13
133#define MP32_SET_SONG_NAME 0x14
134#define MP32_ADD_LOOP_TRACK 0x15
135#define MP32_STOP 0x16
136#define MP32_SET_LOOP_FOL 0x17
137#define MP32_SET_SHUF_ALL 0x18
138#define MP32_REP_SINGLE 0x19
139#define MP32_SET_SHUF_FOL 0x28
146#define MP32_EQ_NORMAL 0x00
147#define MP32_EQ_POP 0x01
148#define MP32_EQ_ROCK 0x02
149#define MP32_EQ_JAZZ 0x03
150#define MP32_EQ_CLASSIC 0x04
151#define MP32_EQ_BASS 0x05
158#define MP32_U_DISK 0x01
159#define MP32_SDCARD 0x02
166#define MP32_STOP_LOOP 0x00
167#define MP32_START_LOOP 0x01
174#define MP32_DISABLE 0x00
175#define MP32_ENABLE 0x01
178 // End group macro
179// --------------------------------------------------------------- PUBLIC TYPES
187typedef struct
188{
189 // Output pins
190
191 digital_out_t rst;
192
193 // Modules
194
195 uart_t uart;
196
197 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
198 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
199
200} mp32_t;
201
205typedef struct
206{
207 // Communication gpio pins
208
209 pin_name_t rx_pin;
210 pin_name_t tx_pin;
211
212 // Additional gpio pins
213
214 pin_name_t rst;
215
216
217 // static variable
218
219 uint32_t baud_rate; // Clock speed.
221 uart_data_bits_t data_bit; // Data bits.
222 uart_parity_t parity_bit; // Parity bit.
223 uart_stop_bits_t stop_bit; // Stop bits.
224
225} mp32_cfg_t;
226
230typedef uint8_t mp32_error_t;
231
232 // End types group
233
234// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
235
241#ifdef __cplusplus
242extern "C"{
243#endif
244
254
263
270void mp32_generic_write ( mp32_t *ctx, char *data_buf, uint16_t len );
271
279int32_t mp32_generic_read ( mp32_t *ctx, char *data_buf, uint16_t max_len );
280
288void mp32_hw_reset ( mp32_t *ctx );
289
300void mp32_rx_cmd ( mp32_t *ctx, uint8_t *rd_data, uint8_t len );
301
312void mp32_tx_cmd ( mp32_t *ctx, uint8_t cmd, uint16_t spec_data );
313
321void mp32_sw_reset ( mp32_t *ctx );
322
331void mp32_play_specific ( mp32_t *ctx, uint16_t track_index );
332
340void mp32_play_mode ( mp32_t *ctx );
341
350
358void mp32_stop_mode ( mp32_t *ctx );
359
369void mp32_set_volume ( mp32_t *ctx, uint8_t perc );
370
378void mp32_volume_up ( mp32_t *ctx );
379
388
396void mp32_play_next ( mp32_t *ctx );
397
406
416void mp32_set_eq ( mp32_t *ctx, uint8_t eq );
417
426
434void mp32_set_device ( mp32_t *ctx, uint8_t device );
435
444
455void mp32_play_spec_in_fol ( mp32_t *ctx, uint8_t fol_inx, uint8_t track_inx );
456
468void mp32_loop_all ( mp32_t *ctx, uint8_t loop_mode );
469
478void mp32_play_fol ( mp32_t *ctx, uint8_t fol_inx );
479
488void mp32_loop_fol ( mp32_t *ctx, uint8_t fol_inx );
489
498
499// Loop Repeat a current song
511void mp32_loop ( mp32_t *ctx, uint8_t state );
512
513#ifdef __cplusplus
514}
515#endif
516#endif // _MP32_H_
517
518 // End public_function group
520
521// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition mp32.h:88
#define DRV_TX_BUFFER_SIZE
Definition mp32.h:89
#define MP32_RETVAL
Definition mp32.h:78
void mp32_play_mode(mp32_t *ctx)
Play mode function.
MP32_RETVAL mp32_init(mp32_t *ctx, mp32_cfg_t *cfg)
Initialization function.
void mp32_tx_cmd(mp32_t *ctx, uint8_t cmd, uint16_t spec_data)
Write command function.
void mp32_loop(mp32_t *ctx, uint8_t state)
Repeat a current song function.
void mp32_play_previous(mp32_t *ctx)
Play previous command function.
void mp32_cfg_setup(mp32_cfg_t *cfg)
Config Object Initialization function.
int32_t mp32_generic_read(mp32_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void mp32_repeat_current(mp32_t *ctx)
Repeat current mode function.
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.
void mp32_set_low_power_mode(mp32_t *ctx)
Set Low power mode function.
void mp32_generic_write(mp32_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void mp32_rx_cmd(mp32_t *ctx, uint8_t *rd_data, uint8_t len)
Received response data function.
void mp32_loop_all(mp32_t *ctx, uint8_t loop_mode)
Play specific in loop mode function.
void mp32_volume_down(mp32_t *ctx)
Play next command function.
void mp32_loop_fol(mp32_t *ctx, uint8_t fol_inx)
Loop folder function.
void mp32_set_device(mp32_t *ctx, uint8_t device)
Set device function.
void mp32_play_next(mp32_t *ctx)
Play previous command function.
void mp32_random_all(mp32_t *ctx)
Random Play function.
void mp32_play_specific(mp32_t *ctx, uint16_t track_index)
Play specific function.
void mp32_pause_mode(mp32_t *ctx)
Pause mode function.
void mp32_stop_mode(mp32_t *ctx)
Stop mode function.
void mp32_set_eq(mp32_t *ctx, uint8_t eq)
Set equalizer mode function.
void mp32_set_volume(mp32_t *ctx, uint8_t perc)
Set Volume function.
void mp32_sw_reset(mp32_t *ctx)
Software reset function.
void mp32_hw_reset(mp32_t *ctx)
Reset the device function.
void mp32_volume_up(mp32_t *ctx)
Volume up function.
void mp32_play_fol(mp32_t *ctx, uint8_t fol_inx)
Play folder function.
uint8_t mp32_error_t
Error type.
Definition mp32.h:230
Click configuration structure definition.
Definition mp32.h:206
uint32_t baud_rate
Definition mp32.h:219
bool uart_blocking
Definition mp32.h:220
uart_data_bits_t data_bit
Definition mp32.h:221
pin_name_t tx_pin
Definition mp32.h:210
pin_name_t rx_pin
Definition mp32.h:209
uart_stop_bits_t stop_bit
Definition mp32.h:223
uart_parity_t parity_bit
Definition mp32.h:222
pin_name_t rst
Definition mp32.h:214
Click ctx object definition.
Definition mp32.h:188
uart_t uart
Definition mp32.h:195
digital_out_t rst
Definition mp32.h:191