Skip to content

Commit 48a7d9e

Browse files
committed
0.1.2 MiniMP3
1 parent eb4b58b commit 48a7d9e

File tree

20 files changed

+1015
-0
lines changed

20 files changed

+1015
-0
lines changed

libraries/MiniMP3/.arduino-ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
# - m4
24+
# - esp32
25+
# - esp8266
26+
# - mega2560
27+
- rpipico
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/MiniMP3/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Change Log MINIMP3
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.2] - 2023-05-01
10+
- refactor & revitalize code
11+
- create changelog.md
12+
- create a repository
13+
- add Stream parameter in constructor
14+
- redo readme.md
15+
16+
17+
## [0.1.1] - 2018-06-12
18+
- added volume, equalizer
19+
20+
## [0.1.0] - 2018-06-11
21+
- initial version (play, stop, reset)

libraries/MiniMP3/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-2023 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/MiniMP3/MiniMP3.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//
2+
// FILE: MiniMP3.cpp
3+
4+
// VERSION: 0.1.2
5+
// PURPOSE: Arduino library for DFRobotics MP3 player and compatibles.
6+
7+
8+
#include "MiniMP3.h"
9+
10+
11+
// CONSTANTS
12+
#define MP3_MAX_VOLUME 30
13+
14+
15+
// COMMANDS
16+
#define MP3_NEXT 0x01
17+
#define MP3_PREV 0x02
18+
#define MP3_PLAY 0x03
19+
#define MP3_VOL_INCR 0x04
20+
#define MP3_VOL_DECR 0x05
21+
#define MP3_VOL_SET 0x06
22+
#define MP3_EQUAL 0x07
23+
#define MP3_PLAYMODE 0x08
24+
#define MP3_PLAYSOURCE 0x09
25+
#define MP3_LOWPOWER 0x0A
26+
#define MP3_POWER 0x0B
27+
#define MP3_RESET 0x0C
28+
#define MP3_PLAYBACK 0x0D
29+
#define MP3_PAUSE 0x0E
30+
#define MP3_PLAY_FOLDER 0x0F
31+
#define MP3_VOL_ADJUST_SET 0x10
32+
#define MP3_REPEAT 0x11
33+
34+
35+
// QUERIES
36+
// not supported (yet)
37+
38+
39+
40+
/////////////////////////////////////////////////////
41+
//
42+
// PUBLIC
43+
//
44+
MINIMP3::MINIMP3(Stream * stream)
45+
{
46+
_stream = stream;
47+
}
48+
49+
50+
/////////////////////////////////////////////////////
51+
//
52+
// PLAY
53+
//
54+
void MINIMP3::play(uint16_t track)
55+
{
56+
command(MP3_PLAY, track);
57+
}
58+
59+
// void MINIMP3::playFolder(uint8_t folder, uint8_t track)
60+
// {
61+
// command(MP3_PLAY_FOLDER, folder, track);
62+
// }
63+
64+
void MINIMP3::next()
65+
{
66+
command(MP3_NEXT);
67+
}
68+
69+
void MINIMP3::prev()
70+
{
71+
command(MP3_PREV);
72+
}
73+
74+
void MINIMP3::stop()
75+
{
76+
command(0x15);
77+
}
78+
79+
80+
/////////////////////////////////////////////////////
81+
//
82+
// CONTROL
83+
//
84+
void MINIMP3::pause()
85+
{
86+
command(MP3_PAUSE);
87+
}
88+
89+
void MINIMP3::reset()
90+
{
91+
command(MP3_RESET);
92+
}
93+
94+
void MINIMP3::lowPower()
95+
{
96+
command(MP3_LOWPOWER);
97+
}
98+
99+
100+
/////////////////////////////////////////////////////
101+
//
102+
// VOLUME
103+
//
104+
void MINIMP3::volume(uint16_t vol)
105+
{
106+
if (vol > MP3_MAX_VOLUME) vol = MP3_MAX_VOLUME;
107+
command(MP3_VOL_SET, 256 + vol);
108+
}
109+
110+
void MINIMP3::volumeUp()
111+
{
112+
command(MP3_VOL_INCR);
113+
}
114+
115+
void MINIMP3::volumeDown()
116+
{
117+
command(MP3_VOL_DECR);
118+
}
119+
120+
121+
/////////////////////////////////////////////////////
122+
//
123+
// EQUALIZER
124+
//
125+
void MINIMP3::equalizer(uint8_t mode)
126+
{
127+
if (mode > 5) mode = MP3_EQ_NORMAL;
128+
command(MP3_EQUAL, mode);
129+
}
130+
131+
132+
133+
/////////////////////////////////////////////////////
134+
//
135+
// PRIVATE
136+
//
137+
void MINIMP3::command(uint8_t cmd, uint16_t arg)
138+
{
139+
uint8_t arg2 = arg & 0xFF;
140+
uint8_t arg1 = arg >> 8;
141+
command(cmd, arg1, arg2);
142+
}
143+
144+
145+
void MINIMP3::command(uint8_t cmd, uint8_t arg1, uint8_t arg2)
146+
{
147+
uint8_t buffer[10] = {0x7E, // Start == $
148+
0xFF, // version
149+
0x06, // length
150+
cmd,
151+
0x00, // 0 = no feedback
152+
arg1, // param 1
153+
arg2, // param 2
154+
0x00, // CheckSumHigh
155+
0x00, // CheckSumLow
156+
0xEF // End Byte
157+
};
158+
159+
uint16_t chksum = 0;
160+
for (int i = 1; i < 7; i++ )
161+
{
162+
chksum += buffer[i];
163+
}
164+
chksum = -chksum;
165+
buffer[7] = (chksum >> 8); // CheckSumHigh
166+
buffer[8] = (chksum & 0xFF); // CheckSumLow
167+
168+
_stream->write(buffer, 10);
169+
}
170+
171+
172+
// -- END OF FILE --
173+

libraries/MiniMP3/MiniMP3.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
//
3+
// FILE: MiniMP3.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.2
6+
// PURPOSE: Arduino library for DFRobotics MP3 player and compatibles.
7+
// URL: https://github.com/RobTillaart/MINIMP3
8+
9+
10+
#include "Arduino.h"
11+
12+
#define MINIMP3_LIB_VERSION (F("0.1.2"))
13+
14+
15+
// EQUALIZER MODI
16+
#define MP3_EQ_NORMAL 0
17+
#define MP3_EQ_POP 1
18+
#define MP3_EQ_ROCK 2
19+
#define MP3_EQ_JAZZ 3
20+
#define MP3_EQ_CLASSIC 4
21+
#define MP3_EQ_BASS 5
22+
23+
24+
// PLAYBACK MODI
25+
// to be implemented
26+
#define MP3_MODE_REPEAT 0
27+
#define MP3_MODE_FREPEAT 1
28+
#define MP3_MODE_SREPEAT 2
29+
#define MP3_MODE_RANDOM 3
30+
31+
32+
// PLAYBACK SOURCE
33+
// to be implemented?
34+
#define MP3_DEVICE_U 0
35+
#define MP3_DEVICE_TF 1
36+
#define MP3_DEVICE_AUX 2
37+
#define MP3_DEVICE_SLEEP 3
38+
#define MP3_DEVICE_FLASH 4
39+
40+
41+
class MINIMP3
42+
{
43+
public:
44+
MINIMP3(Stream * stream = &Serial);
45+
46+
// plays SD:/MP3/####.mp3
47+
void play(uint16_t track);
48+
// void playFolder(uint8_t folder, uint8_t track);
49+
void next();
50+
void prev();
51+
void stop();
52+
void pause();
53+
54+
void reset();
55+
void lowPower();
56+
57+
// volume = 0.. 30
58+
void volume(uint16_t vol = 0);
59+
void volumeUp();
60+
void volumeDown();
61+
62+
// mode = 0..5
63+
void equalizer(uint8_t mode = MP3_EQ_NORMAL);
64+
65+
66+
private:
67+
Stream * _stream;
68+
69+
void command(uint8_t cmd, uint16_t arg = 0x0000);
70+
void command(uint8_t cmd, uint8_t arg1, uint8_t arg2);
71+
};
72+
73+
74+
// -- END OF FILE --
75+

0 commit comments

Comments
 (0)