much progress, descriptors and sample rates getting basically working?
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[target.thumbv8m.main-none-eabi]
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
]
|
||||
|
||||
[target.thumbv8m.main-none-eabihf]
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
"-C", "link-arg=-Tdefmt.x",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "thumbv8m.main-none-eabihf"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "debug"
|
||||
+244
-25
@@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "atomic-polyfill"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
@@ -14,7 +23,7 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -23,6 +32,12 @@ version = "0.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
@@ -66,7 +81,8 @@ checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9"
|
||||
dependencies = [
|
||||
"bare-metal",
|
||||
"bitfield",
|
||||
"embedded-hal",
|
||||
"critical-section",
|
||||
"embedded-hal 0.2.7",
|
||||
"volatile-register",
|
||||
]
|
||||
|
||||
@@ -90,6 +106,12 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
@@ -100,6 +122,57 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt"
|
||||
version = "0.3.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0963443817029b2024136fc4dd07a5107eb8f977eaf18fcd1fdeb11306b64ad"
|
||||
dependencies = [
|
||||
"defmt 1.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"defmt-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt-macros"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e"
|
||||
dependencies = [
|
||||
"defmt-parser",
|
||||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt-parser"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt-rtt"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93d5a25c99d89c40f5676bec8cefe0614f17f0f40e916f98e345dae941807f9e"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"defmt 1.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -120,6 +193,12 @@ dependencies = [
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-io"
|
||||
version = "0.7.1"
|
||||
@@ -155,6 +234,15 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
@@ -164,13 +252,26 @@ dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.7.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
|
||||
dependencies = [
|
||||
"atomic-polyfill",
|
||||
"hash32 0.2.1",
|
||||
"rustc_version 0.4.1",
|
||||
"spin",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||
dependencies = [
|
||||
"hash32",
|
||||
"hash32 0.3.1",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
@@ -183,23 +284,47 @@ dependencies = [
|
||||
"generic-array 0.14.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
||||
dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "log-to-defmt"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9454118d78a9089a15d702fbaf413da2fa23f331b8af6c5eed5784a4369173c6"
|
||||
dependencies = [
|
||||
"defmt 0.3.100",
|
||||
"heapless 0.7.17",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lpc55-hal"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41e86e4e491dd3f8e07e7ba6de4aace716459ddefebd05743b2cb67b6a566d3c"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"cipher",
|
||||
"cortex-m",
|
||||
"digest",
|
||||
"embedded-hal",
|
||||
"embedded-hal 0.2.7",
|
||||
"embedded-time",
|
||||
"generic-array 1.3.5",
|
||||
"lpc55-pac",
|
||||
"nb 1.1.0",
|
||||
"rand_core",
|
||||
"usb-device 0.2.9",
|
||||
"usb-device",
|
||||
"vcell",
|
||||
"void",
|
||||
]
|
||||
@@ -215,6 +340,25 @@ dependencies = [
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lpc55s28-evk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cortex-m",
|
||||
"cortex-m-rt",
|
||||
"defmt 1.0.1",
|
||||
"defmt-rtt",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-io",
|
||||
"log-to-defmt",
|
||||
"lpc55-hal",
|
||||
"nb 1.1.0",
|
||||
"panic-halt",
|
||||
"static_cell",
|
||||
"usb-device",
|
||||
"usbd-uac2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "modular-bitfield"
|
||||
version = "0.13.1"
|
||||
@@ -313,12 +457,40 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "panic-halt"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a513e167849a384b7f9b746e517604398518590a9142f4846a32e3c2a4de7b11"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr2"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error2"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
@@ -349,7 +521,16 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
|
||||
dependencies = [
|
||||
"semver 1.0.28",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -358,6 +539,12 @@ version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
@@ -367,12 +554,27 @@ dependencies = [
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.1"
|
||||
@@ -385,6 +587,15 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "static_cell"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0530892bb4fa575ee0da4b86f86c667132a94b74bb72160f58ee5a4afec74c23"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
@@ -396,6 +607,26 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.0"
|
||||
@@ -408,19 +639,14 @@ version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "usb-device"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508"
|
||||
|
||||
[[package]]
|
||||
name = "usb-device"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
|
||||
dependencies = [
|
||||
"heapless",
|
||||
"defmt 0.3.100",
|
||||
"heapless 0.8.0",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
@@ -429,18 +655,11 @@ name = "usbd-uac2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder-embedded-io",
|
||||
"defmt 1.0.1",
|
||||
"embedded-io",
|
||||
"modular-bitfield",
|
||||
"usb-device 0.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usbd_uac2_demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lpc55-hal",
|
||||
"lpc55-pac",
|
||||
"usbd-uac2",
|
||||
"num-traits",
|
||||
"usb-device",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "lpc55s28-evk"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.5"
|
||||
defmt = "1.0.1"
|
||||
defmt-rtt = "1.1.0"
|
||||
embedded-hal = "1.0.0"
|
||||
embedded-io = "0.7.1"
|
||||
log-to-defmt = "0.1.0"
|
||||
lpc55-hal = { version = "0.5.0", path = "../lpc55-hal" }
|
||||
nb = "1.1.0"
|
||||
panic-halt = "1.0.0"
|
||||
static_cell = "2.1.1"
|
||||
usb-device = "0.3"
|
||||
usbd-uac2 = { version = "0.1.0", path = "../..", features = ["defmt"]}
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
debug = true
|
||||
codegen-units = 1
|
||||
@@ -0,0 +1,9 @@
|
||||
[default.general]
|
||||
chip = "LPC55S28JBD100"
|
||||
[default.rtt]
|
||||
enabled = true
|
||||
[default.gdb]
|
||||
enabled = true
|
||||
|
||||
[debug.rtt]
|
||||
enabled = false
|
||||
@@ -0,0 +1,26 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
|
||||
|
||||
/* for use with standard link.x */
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
|
||||
/* would be used with proper link.x */
|
||||
/* needs changes to r0 (initialization code) */
|
||||
/* SRAM0 : ORIGIN = 0x20000000, LENGTH = 64K */
|
||||
/* SRAM1 : ORIGIN = 0x20010000, LENGTH = 64K */
|
||||
/* SRAM2 : ORIGIN = 0x20020000, LENGTH = 64K */
|
||||
/* SRAM3 : ORIGIN = 0x20030000, LENGTH = 64K */
|
||||
|
||||
/* CASPER SRAM regions */
|
||||
/* SRAMX0: ORIGIN = 0x1400_0000, LENGTH = 4K /1* to 0x1400_0FFF *1/ */
|
||||
/* SRAMX1: ORIGIN = 0x1400_4000, LENGTH = 4K /1* to 0x1400_4FFF *1/ */
|
||||
|
||||
/* USB1 SRAM regin */
|
||||
/* USB1_SRAM : ORIGIN = 0x40100000, LENGTH = 16K */
|
||||
|
||||
/* To define our own USB RAM section in one regular */
|
||||
/* RAM, probably easiest to shorten length of RAM */
|
||||
/* above, and use this freed RAM section */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
// extern crate panic_semihosting;
|
||||
extern crate panic_halt;
|
||||
use core::cell::OnceCell;
|
||||
use cortex_m::asm::delay;
|
||||
use cortex_m_rt::entry;
|
||||
use embedded_io::{ErrorType, Write};
|
||||
use nb;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use hal::prelude::*;
|
||||
#[allow(unused_imports)]
|
||||
use lpc55_hal as hal;
|
||||
use lpc55_hal::{
|
||||
drivers::{
|
||||
Serial,
|
||||
pins::{PinId, Pio0_29, Pio0_30},
|
||||
serial::Tx,
|
||||
},
|
||||
peripherals::flexcomm::Usart0,
|
||||
typestates::pin::{
|
||||
flexcomm::{Usart, UsartPins},
|
||||
function::{FC0_RXD_SDA_MOSI_DATA, FC0_TXD_SCL_MISO_WS},
|
||||
state::Special,
|
||||
},
|
||||
};
|
||||
|
||||
use core::convert::Infallible;
|
||||
use defmt;
|
||||
use defmt_rtt as _;
|
||||
use hal::drivers::{Timer, UsbBus, pins};
|
||||
use static_cell::StaticCell;
|
||||
use usb_device::{
|
||||
bus,
|
||||
device::{StringDescriptors, UsbDeviceBuilder, UsbVidPid},
|
||||
endpoint::IsochronousSynchronizationType,
|
||||
};
|
||||
use usbd_uac2::{
|
||||
self, AudioClassConfig, RangeEntry, TerminalConfig, USB_CLASS_AUDIO, UsbAudioClass,
|
||||
UsbAudioClockImpl, UsbSpeed,
|
||||
constants::{FunctionCode, TerminalType},
|
||||
descriptors::{ChannelConfig, ClockSource, ClockType, FormatType1, LockDelay},
|
||||
};
|
||||
|
||||
type SERIAL_RX_PIN = hal::Pin<Pio0_29, Special<FC0_RXD_SDA_MOSI_DATA>>;
|
||||
type SERIAL_TX_PIN = hal::Pin<Pio0_30, Special<FC0_TXD_SCL_MISO_WS>>;
|
||||
type SERIAL_PINS = (SERIAL_TX_PIN, SERIAL_RX_PIN);
|
||||
|
||||
static SERIAL: StaticCell<DefmtUart<Usart0>> = StaticCell::new();
|
||||
|
||||
pub struct DefmtUart<U>(pub Tx<U>)
|
||||
where
|
||||
U: Usart;
|
||||
|
||||
impl<U> ErrorType for DefmtUart<U>
|
||||
where
|
||||
U: Usart,
|
||||
{
|
||||
type Error = Infallible;
|
||||
}
|
||||
impl<U> Write for DefmtUart<U>
|
||||
where
|
||||
U: Usart,
|
||||
{
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
|
||||
buf.iter().map(|c| nb::block!(self.0.write(*c))).last();
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), Self::Error> {
|
||||
// Blocking write, so flush is a no-op
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct Clock {}
|
||||
impl Clock {
|
||||
const RATES: [RangeEntry<u32>; 1] = [RangeEntry::new_fixed(44100)];
|
||||
}
|
||||
impl UsbAudioClockImpl for Clock {
|
||||
const CLOCK_TYPE: usbd_uac2::descriptors::ClockType = ClockType::InternalFixed;
|
||||
const SOF_SYNC: bool = false;
|
||||
fn get_sample_rate(&self) -> core::result::Result<u32, usbd_uac2::UsbAudioClassError> {
|
||||
Ok(Clock::RATES[0].min)
|
||||
}
|
||||
fn get_rates(
|
||||
&self,
|
||||
) -> core::result::Result<&[usbd_uac2::RangeEntry<u32>], usbd_uac2::UsbAudioClassError> {
|
||||
Ok(&Clock::RATES)
|
||||
}
|
||||
}
|
||||
|
||||
struct Audio {}
|
||||
impl<'a, B: bus::UsbBus> UsbAudioClass<'a, B> for Audio {}
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let hal = hal::new();
|
||||
|
||||
let mut anactrl = hal.anactrl;
|
||||
let mut pmc = hal.pmc;
|
||||
let mut syscon = hal.syscon;
|
||||
|
||||
let mut gpio = hal.gpio.enabled(&mut syscon);
|
||||
let mut iocon = hal.iocon.enabled(&mut syscon);
|
||||
|
||||
let mut red_led = pins::Pio1_6::take()
|
||||
.unwrap()
|
||||
.into_gpio_pin(&mut iocon, &mut gpio)
|
||||
.into_output(hal::drivers::pins::Level::Low); // start turned on
|
||||
|
||||
let usb0_vbus_pin = pins::Pio0_22::take()
|
||||
.unwrap()
|
||||
.into_usb0_vbus_pin(&mut iocon);
|
||||
|
||||
let serial_rx_pin = pins::Pio0_29::take()
|
||||
.unwrap()
|
||||
.into_usart0_rx_pin(&mut iocon);
|
||||
let serial_tx_pin = pins::Pio0_30::take()
|
||||
.unwrap()
|
||||
.into_usart0_tx_pin(&mut iocon);
|
||||
|
||||
iocon.disabled(&mut syscon).release(); // save the environment :)
|
||||
|
||||
let clocks = hal::ClockRequirements::default()
|
||||
// .system_frequency(24.mhz())
|
||||
// .system_frequency(72.mhz())
|
||||
.system_frequency(96.MHz())
|
||||
.configure(&mut anactrl, &mut pmc, &mut syscon)
|
||||
.unwrap();
|
||||
let mut _delay_timer = Timer::new(
|
||||
hal.ctimer
|
||||
.0
|
||||
.enabled(&mut syscon, clocks.support_1mhz_fro_token().unwrap()),
|
||||
);
|
||||
|
||||
let usart = hal
|
||||
.flexcomm
|
||||
.0
|
||||
.enabled_as_usart(&mut syscon, &clocks.support_flexcomm_token().unwrap());
|
||||
|
||||
let serial_config = hal::drivers::serial::config::Config::default().speed(115_200.Hz());
|
||||
let serial = Serial::new(usart, (serial_tx_pin, serial_rx_pin), serial_config).split();
|
||||
let serial_tx = DefmtUart(serial.0);
|
||||
|
||||
// defmt_serial::defmt_serial(SERIAL.init(serial_tx));
|
||||
|
||||
let usb_peripheral = hal.usbhs.enabled_as_device(
|
||||
&mut anactrl,
|
||||
&mut pmc,
|
||||
&mut syscon,
|
||||
&mut _delay_timer,
|
||||
clocks.support_usbhs_token().unwrap(),
|
||||
);
|
||||
|
||||
let usb_bus = UsbBus::new(usb_peripheral, usb0_vbus_pin);
|
||||
let clock = Clock {};
|
||||
let audio = Audio {};
|
||||
|
||||
let config = AudioClassConfig::new(UsbSpeed::High, FunctionCode::Other, &clock, &audio)
|
||||
.with_input_config(TerminalConfig::new(
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
FormatType1 {
|
||||
bit_resolution: 24,
|
||||
bytes_per_sample: 4,
|
||||
},
|
||||
TerminalType::ExtLineConnector,
|
||||
ChannelConfig::default_chans(2),
|
||||
IsochronousSynchronizationType::Adaptive,
|
||||
LockDelay::Milliseconds(10),
|
||||
None,
|
||||
))
|
||||
.with_output_config(TerminalConfig::new(
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
FormatType1 {
|
||||
bit_resolution: 24,
|
||||
bytes_per_sample: 4,
|
||||
},
|
||||
TerminalType::ExtLineConnector,
|
||||
ChannelConfig::default_chans(2),
|
||||
IsochronousSynchronizationType::Adaptive,
|
||||
LockDelay::Milliseconds(10),
|
||||
None,
|
||||
));
|
||||
|
||||
let mut uac2 = config.build(&usb_bus).unwrap();
|
||||
|
||||
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x1209, 0xcc1d))
|
||||
.composite_with_iads()
|
||||
.strings(&[StringDescriptors::default()
|
||||
.manufacturer("VE7XEN")
|
||||
.product("Guac")
|
||||
.serial_number("123456789")])
|
||||
.unwrap()
|
||||
.max_packet_size_0(64)
|
||||
.unwrap()
|
||||
.device_class(0xef)
|
||||
.device_sub_class(0x02)
|
||||
.device_protocol(0x01)
|
||||
.build();
|
||||
|
||||
defmt::info!("main loop");
|
||||
let mut need_zlp = false;
|
||||
let mut buf = [0u8; 8];
|
||||
let mut size = 0;
|
||||
let mut buf_in_use = false;
|
||||
loop {
|
||||
// if !usb_dev.poll(&mut []) {
|
||||
// if !usb_dev.poll(&mut [&mut serial]) {
|
||||
if !usb_dev.poll(&mut [&mut uac2]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// let mut buf = [0u8; 512];
|
||||
|
||||
// match serial.read(&mut buf) {
|
||||
// Ok(count) if count > 0 => {
|
||||
// assert!(count == 1);
|
||||
// // hprintln!("received some data on the serial port: {:?}", &buf[..count]).ok();
|
||||
// // cortex_m_semihosting::hprintln!("received:\n{}", core::str::from_utf8(&buf[..count]).unwrap()).ok();
|
||||
// red_led.set_low().ok(); // Turn on
|
||||
|
||||
// // cortex_m_semihosting::hprintln!("read {:?}", &buf[..count]).ok();
|
||||
// cortex_m_semihosting::hprintln!("read {:?}", count).ok();
|
||||
|
||||
// // Echo back in upper case
|
||||
// for c in buf[0..count].iter_mut() {
|
||||
// if (0x61 <= *c && *c <= 0x7a) || (0x41 <= *c && *c <= 0x5a) {
|
||||
// *c ^= 0x20;
|
||||
// }
|
||||
// }
|
||||
|
||||
// let mut write_offset = 0;
|
||||
// while write_offset < count {
|
||||
// match serial.write(&buf[write_offset..count]) {
|
||||
// Ok(len) if len > 0 => {
|
||||
// write_offset += len;
|
||||
// cortex_m_semihosting::hprintln!("wrote {:?}", len).ok();
|
||||
|
||||
// },
|
||||
// _ => {},
|
||||
// }
|
||||
// }
|
||||
|
||||
// // hprintln!("wrote it back").ok();
|
||||
// }
|
||||
// _ => {}
|
||||
// }
|
||||
|
||||
red_led.set_high().ok(); // Turn off
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "usbd_uac2_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
lpc55-hal = "0.5.0"
|
||||
lpc55-pac = "0.5.0"
|
||||
usbd-uac2 = { version = "0.1.0", path = "../.." }
|
||||
@@ -1,20 +0,0 @@
|
||||
use lpc55_pac as pac;
|
||||
use usbd_uac2::{self, UsbSpeed, UsbSpeedProvider};
|
||||
|
||||
struct Lpc55UsbSpeedProvider {}
|
||||
|
||||
impl UsbSpeedProvider for Lpc55UsbSpeedProvider {
|
||||
fn speed(&self) -> usbd_uac2::UsbSpeed {
|
||||
let regs = unsafe { &*pac::USB1::ptr() };
|
||||
match regs.devcmdstat.read().speed().bits() {
|
||||
1 => UsbSpeed::Full,
|
||||
2 => UsbSpeed::High,
|
||||
3 => UsbSpeed::Super,
|
||||
_ => panic!("Unknown USB speed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
Reference in New Issue
Block a user