Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
USB I2S Speaker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quentin Bolsee
USB I2S Speaker
Commits
f38af849
Commit
f38af849
authored
2 months ago
by
Quentin Bolsee
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
9ca41b23
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rp2040-USB-I2S-speaker/rp2040-USB-I2S-speaker.ino
+51
-0
51 additions, 0 deletions
rp2040-USB-I2S-speaker/rp2040-USB-I2S-speaker.ino
with
51 additions
and
0 deletions
rp2040-USB-I2S-speaker/rp2040-USB-I2S-speaker.ino
0 → 100644
+
51
−
0
View file @
f38af849
#include
<Adafruit_TinyUSB.h>
#include
<I2S.h>
#define I2S_CLK 1
#define I2S_FRAME (I2S_CLK+1)
#define I2S_DATA 4
#define SAMPLE_RATE 44100
#define SAMPLE_BITS 16
Adafruit_USBD_Audio
usb
;
I2S
i2s
(
OUTPUT
);
size_t
writeCB
(
const
uint8_t
*
data
,
size_t
len
,
Adafruit_USBD_Audio
&
ref
)
{
int16_t
*
data16
=
(
int16_t
*
)
data
;
size_t
n_written
=
i2s
.
write
(
data
,
len
);
// returns the amount written (and convert to bytes)
return
n_written
*
2
*
sizeof
(
int16_t
);
}
void
setup
()
{
// init USB
if
(
!
TinyUSBDevice
.
isInitialized
())
{
TinyUSBDevice
.
begin
(
0
);
}
Serial
.
begin
(
115200
);
// reconfigure USB
usb
.
setWriteCallback
(
writeCB
);
usb
.
begin
(
SAMPLE_RATE
,
2
,
SAMPLE_BITS
);
if
(
TinyUSBDevice
.
mounted
())
{
TinyUSBDevice
.
detach
();
delay
(
10
);
TinyUSBDevice
.
attach
();
}
// start I2S
i2s
.
setBCLK
(
I2S_CLK
);
i2s
.
setDATA
(
I2S_DATA
);
i2s
.
setBitsPerSample
(
SAMPLE_BITS
);
i2s
.
begin
(
SAMPLE_RATE
);
}
void
loop
()
{
#ifdef TINYUSB_NEED_POLLING_TASK
TinyUSBDevice
.
task
();
#endif
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment