{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1361","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1361/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1361/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1361/events","html_url":"https://github.com/micropython/micropython/pull/1361","id":92684953,"number":1361,"title":"stmhal: I2S (Inter-IC-Sound) peripheral support for pyb module","user":{"login":"blmorris","id":6295715,"avatar_url":"https://avatars.githubusercontent.com/u/6295715?v=3","gravatar_id":"","url":"https://api.github.com/users/blmorris","html_url":"https://github.com/blmorris","followers_url":"https://api.github.com/users/blmorris/followers","following_url":"https://api.github.com/users/blmorris/following{/other_user}","gists_url":"https://api.github.com/users/blmorris/gists{/gist_id}","starred_url":"https://api.github.com/users/blmorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blmorris/subscriptions","organizations_url":"https://api.github.com/users/blmorris/orgs","repos_url":"https://api.github.com/users/blmorris/repos","events_url":"https://api.github.com/users/blmorris/events{/privacy}","received_events_url":"https://api.github.com/users/blmorris/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-07-02T16:59:03Z","updated_at":"2015-08-25T17:07:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/micropython/micropython/pulls/1361","html_url":"https://github.com/micropython/micropython/pull/1361","diff_url":"https://github.com/micropython/micropython/pull/1361.diff","patch_url":"https://github.com/micropython/micropython/pull/1361.patch"},"body":"This PR is almost certainly not yet suitable for merging; there is still much to do but I would appreciate any feedback regarding style, design, implementation, or even just how to make it more 'pythonic' before I push it much further.\r\nWhile there are still some details to implement, the I2S class in this PR is reasonably complete.\r\n`pyb.I2S()` accepts a list or tuple of pin names to configure an I2S port; this port can then be initialized as either a Master or a Slave.\r\nIt is possible to create a 16-bit (half-word) array and transmit it in Master mode using `i2s.send(arr)`\r\nand see the transfer on a logic analyzer; i2s.recv() also works although without being fed by an external codec there will be no data to read. Slave modes also work (testing them on my own hardware) but require an external codec to provide clock signals.\r\nPlease see comments for detailed usage, but for a quick start the following code should work, the data loopback is implemented by jumping pin X8 (B15, transmit) to X7 (B14, receive).  Note that sometimes the send_recv command needs to be run a few times before it works consistently; I am investigating this.\r\n```python\r\nimport micropython\r\nmicropython.alloc_emergency_exception_buf(100)\r\n\r\nimport pyb, array\r\n\r\npins = ['B13', 'B12', 'B15', 'B14']\r\ni2s = pyb.I2S(pins)\r\ni2s.init(i2s.MASTER)\r\narr = array.array('h')\r\nfor i in range(32):\r\n    arr.append(i + 512)\r\n\r\nb = bytearray(64)\r\ni2s.send_recv(arr, b)\r\n```\r\n\r\nUltimately my goal with this project is to be able to do something like this and have it run in the background, playing audio while other processing can proceed:\r\n```\r\ni2s = pyb.I2S(pins, pyb.I2S.MASTER)\r\naudio_file = open('/sd/my_audio_file.wav', 'rb')\r\nplay_my_audio_file(audio_file, i2s)\r\n```\r\nThere are a few things in the critical path to get this working; specifically the DMA callback functions need to be implemented (I'm trying to figure out how to do this, could use some help ;-) ) and getting the SD Card working with DMA might help too (I'll look into this.)\r\n\r\nThere are several TODO's noted in `i2s.c`, and I expect others to come up as well.\r\n\r\nFinally, I am planning to design a py-skin daughterboard with an I2S codec to help other people use I2S on the pyboard - it shouldn't take me nearly as long to design as this code did ;) Ping me if you are interested in such a board."},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/134672596","html_url":"https://github.com/micropython/micropython/pull/1361#issuecomment-134672596","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1361","id":134672596,"user":{"login":"blmorris","id":6295715,"avatar_url":"https://avatars.githubusercontent.com/u/6295715?v=3","gravatar_id":"","url":"https://api.github.com/users/blmorris","html_url":"https://github.com/blmorris","followers_url":"https://api.github.com/users/blmorris/followers","following_url":"https://api.github.com/users/blmorris/following{/other_user}","gists_url":"https://api.github.com/users/blmorris/gists{/gist_id}","starred_url":"https://api.github.com/users/blmorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blmorris/subscriptions","organizations_url":"https://api.github.com/users/blmorris/orgs","repos_url":"https://api.github.com/users/blmorris/repos","events_url":"https://api.github.com/users/blmorris/events{/privacy}","received_events_url":"https://api.github.com/users/blmorris/received_events","type":"User","site_admin":false},"created_at":"2015-08-25T17:07:50Z","updated_at":"2015-08-25T17:07:50Z","body":"@dpgeorge - Thanks! I'm off to a meeting now, will try this as soon as I get back. This feels like the right answer, the explanation fits what I'm seeing."}}