{"id":17053095,"url":"https://github.com/bschwind/rp2040-i2s","last_synced_at":"2025-03-23T05:23:19.615Z","repository":{"id":223878185,"uuid":"759405250","full_name":"bschwind/rp2040-i2s","owner":"bschwind","description":"Read and write to I2S devices like MEMS microphones or DACs, on the RP2040 microcontroller.","archived":false,"fork":false,"pushed_at":"2025-03-20T15:31:29.000Z","size":34,"stargazers_count":13,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T16:35:38.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bschwind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-18T14:05:24.000Z","updated_at":"2025-03-08T03:16:05.000Z","dependencies_parsed_at":"2024-02-22T15:26:54.529Z","dependency_job_id":"8953b7f4-21e2-4ba3-aa3a-a0bf6604ab64","html_url":"https://github.com/bschwind/rp2040-i2s","commit_stats":null,"previous_names":["bschwind/rp2040-i2s"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bschwind%2Frp2040-i2s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bschwind%2Frp2040-i2s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bschwind%2Frp2040-i2s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bschwind%2Frp2040-i2s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bschwind","download_url":"https://codeload.github.com/bschwind/rp2040-i2s/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245058649,"owners_count":20554151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T10:11:20.445Z","updated_at":"2025-03-23T05:23:19.609Z","avatar_url":"https://github.com/bschwind.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rp2040-i2s\n\nRead and write to I2S devices like MEMS microphones or DACs, on the RP2040 microcontroller.\n\n## Usage\n\n### I2S Output\n\n```rust\nlet mut pac = pac::Peripherals::take().unwrap();\nlet _core = pac::CorePeripherals::take().unwrap();\n\nlet mut watchdog = Watchdog::new(pac.WATCHDOG);\n\n// Start Clocks\n// Found with: https://github.com/bschwind/rp2040-clock-calculator\nlet desired_system_clock = 61440000.Hz();\n\n// Exercise for the reader\nlet clocks = set_system_clock_exact(\n    desired_system_clock,\n    pac.XOSC,\n    pac.CLOCKS,\n    pac.PLL_SYS,\n    pac.PLL_USB,\n    \u0026mut pac.RESETS,\n    \u0026mut watchdog,\n)\n.unwrap();\n\nlet sio = rp2040_hal::Sio::new(pac.SIO);\n\nlet pins =\n    rp2040_hal::gpio::Pins::new(pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, \u0026mut pac.RESETS);\n\n// PIO Globals\nlet (mut pio0, sm0, _, _, _) = pac.PIO0.split(\u0026mut pac.RESETS);\n\n// I2S output\nlet dac_output = I2SOutput::new(\u0026mut pio0, sm0, pins.gpio6, pins.gpio7, pins.gpio8).unwrap();\n\nlet (dac_sm, _dac_fifo_rx, dac_fifo_tx) = dac_output.split();\n\n// Write your audio samples to `dac_fifo_tx` in your favorite way (direct read or DMA transfer).\n```\n\n### I2S Input\n\n```rust\nlet mut pac = pac::Peripherals::take().unwrap();\nlet _core = pac::CorePeripherals::take().unwrap();\n\nlet mut watchdog = Watchdog::new(pac.WATCHDOG);\n\n// Start Clocks\n// Found with: https://github.com/bschwind/rp2040-clock-calculator\nlet desired_system_clock = 61440000.Hz();\n\n// Exercise for the reader\nlet clocks = set_system_clock_exact(\n    desired_system_clock,\n    pac.XOSC,\n    pac.CLOCKS,\n    pac.PLL_SYS,\n    pac.PLL_USB,\n    \u0026mut pac.RESETS,\n    \u0026mut watchdog,\n)\n.unwrap();\n\nlet sio = rp2040_hal::Sio::new(pac.SIO);\n\nlet pins =\n    rp2040_hal::gpio::Pins::new(pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, \u0026mut pac.RESETS);\n\n// PIO Globals\nlet (mut pio0, _, sm1, _, _) = pac.PIO0.split(\u0026mut pac.RESETS);\n\n// I2S input\nlet mic_input = I2SInput::new(\u0026mut pio0, sm1, pins.gpio10, pins.gpio11, pins.gpio12).unwrap();\n\nlet (mic_sm, mic_fifo_rx, _mic_fifo_tx) = mic_input.split();\n\n// Read mic audio samples from `mic_fifo_rx` in your favorite way (direct read or DMA transfer).\n```\n\n### I2S Multi-Input\n\nOne PIO state machine can generate bit clock and word clock signals, while other PIO state\nmachines can synchronize with the clock generator PIO and just read IS2 data at the proper\ntiming. This reduces the number of pins required when interfacing with multiple microphones.\n\n```rust\nlet mut pac = pac::Peripherals::take().unwrap();\nlet _core = pac::CorePeripherals::take().unwrap();\n\nlet mut watchdog = Watchdog::new(pac.WATCHDOG);\n\n// Start Clocks\n// Found with: https://github.com/bschwind/rp2040-clock-calculator\nlet desired_system_clock = 61440000.Hz();\n\n// Exercise for the reader\nlet clocks = set_system_clock_exact(\n    desired_system_clock,\n    pac.XOSC,\n    pac.CLOCKS,\n    pac.PLL_SYS,\n    pac.PLL_USB,\n    \u0026mut pac.RESETS,\n    \u0026mut watchdog,\n)\n.unwrap();\n\nlet sio = rp2040_hal::Sio::new(pac.SIO);\n\nlet pins =\n    rp2040_hal::gpio::Pins::new(pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, \u0026mut pac.RESETS);\n\n// PIO Globals\nlet (mut pio0, _, sm1, sm2, _) = pac.PIO0.split(\u0026mut pac.RESETS);\n\n// I2S input\nlet mic_1_input = I2SInput::new(\u0026mut pio0, sm1, pins.gpio10, pins.gpio11, pins.gpio12).unwrap();\nlet mic_2_input = I2SInput::new_data_only(\u0026mut pio0, sm2, pins.gpio15).unwrap();\n\nlet (mic_1_sm, mic_1_fifo_rx, _mic_1_fifo_tx) = mic_1_input.split();\nlet (mic_2_sm, mic_2_fifo_rx, _mic_2_fifo_tx) = mic_2_input.split();\n\n// Synchronize both PIO state machines so they start at the exact same time and\n// execute their instructions in lockstep.\nmic_sm.with(mic_2_sm).sync().start();\n\n// Receive mic data from `mic_1_fifo_rx` and `mic_2_fifo_rx`.\n```\n\n## Code Format\n\nThe formatting options currently use nightly-only options.\n\n```\n$ cargo +nightly fmt\n```\n\n## Code Linting\n\n```\n$ cargo clippy --all-targets -- -D warnings\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbschwind%2Frp2040-i2s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbschwind%2Frp2040-i2s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbschwind%2Frp2040-i2s/lists"}