{"action":"created","comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments/214542029","pull_request_review_id":151622148,"id":214542029,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDU0MjAyOQ==","diff_hunk":"@@ -77,86 +66,170 @@ i2c_master_setDC(uint8 SDA, uint8 SCL)\n     } else {\n         I2C_MASTER_SDA_HIGH_SCL_HIGH();\n     }\n-    if(1 == SCL) { //clock stretching\n+    if(1 == SCL) {\n         do {\n-        } while(0 == GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)));\n+            sclLevel = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO));\n+        } while(sclLevel == 0);\n     }\n+    i2c_master_wait(5);\n+#else\n+    uint32 cycles_start;\n+    uint32 cycles_curr;\n+    uint32 this_SDA_SCL_set_mask = (SDA << i2c[id].pinSDA) | (SCL << i2c[id].pinSCL);\n+    uint32 this_SDA_SCL_clear_mask = i2c[id].pin_SDA_SCL_mask ^ this_SDA_SCL_set_mask;\n+    i2c[id].m_nLastSDA = SDA;\n+    i2c[id].m_nLastSCL = SCL;\n+\n+    if(i2c[id].cycles_delay > 0){//\n+        asm volatile(\"rsr %0, ccount\":\"=a\"(cycles_start)); //Cycle count register\n+        do{\n+            asm volatile(\"rsr %0, ccount\":\"=a\"(cycles_curr));\n+        } while (cycles_curr - cycles_start <  i2c[id].cycles_delay);\n+    }\n+    if(16 == i2c[id].pinSCL){ //if GPIO16\n+        WRITE_PERI_REG(RTC_GPIO_OUT,\n+                       (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)GPIO16_RTC_REG_MASK) | (uint32)SCL);\n+        GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, this_SDA_SCL_clear_mask); //SCL is shifted out of mask so no worry\n+        GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, this_SDA_SCL_set_mask);\n+    }\n+    else{\n+        GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, this_SDA_SCL_clear_mask);\n+        GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, this_SDA_SCL_set_mask);\n+        if(1 == SCL) { //clock stretching\n+            //instead of: while(!((gpio_input_get() >> pinSCL) & 1)) {}\n+            asm volatile(\"l_wait:\"\n+                         \"l16ui %0, %[gpio_in_addr], 0;\" //read gpio state into register %0\n+                         \"memw;\"                         //wait for read completion\n+                         \"bnall %0, %[gpio_SCL_mask], l_wait;\" // test if SCL bit not set\n+                         ::[gpio_SCL_mask] \"r\" (i2c[id].pin_SCL_mask),\n+                         [gpio_in_addr] \"r\" (PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS)\n+            );\n+        }\n+    }\n+\n+#endif\n }\n \n /******************************************************************************\n  * FunctionName : i2c_master_getDC\n  * Description  : Internal used function -\n  *                    get i2c SDA bit value\n- * Parameters   : NONE\n+ * Parameters   : bus id\n  * Returns      : uint8 - SDA bit value\n *******************************************************************************/\n LOCAL uint8 ICACHE_FLASH_ATTR\n-i2c_master_getDC(void)\n+i2c_master_getDC(uint16 id)","path":"app/driver/i2c_master.c","position":116,"original_position":141,"commit_id":"142ccde71079df14b15dfa190d90b79745c46f12","original_commit_id":"142ccde71079df14b15dfa190d90b79745c46f12","user":{"login":"TerryE","id":690173,"node_id":"MDQ6VXNlcjY5MDE3Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/690173?v=4","gravatar_id":"","url":"https://api.github.com/users/TerryE","html_url":"https://github.com/TerryE","followers_url":"https://api.github.com/users/TerryE/followers","following_url":"https://api.github.com/users/TerryE/following{/other_user}","gists_url":"https://api.github.com/users/TerryE/gists{/gist_id}","starred_url":"https://api.github.com/users/TerryE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TerryE/subscriptions","organizations_url":"https://api.github.com/users/TerryE/orgs","repos_url":"https://api.github.com/users/TerryE/repos","events_url":"https://api.github.com/users/TerryE/events{/privacy}","received_events_url":"https://api.github.com/users/TerryE/received_events","type":"User","site_admin":false},"body":"Again have you thought of making this a static inline routine?  This is so short that the inline length will be as short as the overhead of  making the out of line call.","created_at":"2018-09-02T14:05:46Z","updated_at":"2018-09-02T14:27:30Z","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/2465#discussion_r214542029","pull_request_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments/214542029"},"html":{"href":"https://github.com/nodemcu/nodemcu-firmware/pull/2465#discussion_r214542029"},"pull_request":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465"}}},"pull_request":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465","id":210298144,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEwMjk4MTQ0","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/2465","diff_url":"https://github.com/nodemcu/nodemcu-firmware/pull/2465.diff","patch_url":"https://github.com/nodemcu/nodemcu-firmware/pull/2465.patch","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/2465","number":2465,"state":"open","locked":false,"title":"I2C sw driver with support of multiple buses, Slow, Fast, FastPlus, and user-defined speed selection","user":{"login":"sonaux","id":6295943,"node_id":"MDQ6VXNlcjYyOTU5NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/6295943?v=4","gravatar_id":"","url":"https://api.github.com/users/sonaux","html_url":"https://github.com/sonaux","followers_url":"https://api.github.com/users/sonaux/followers","following_url":"https://api.github.com/users/sonaux/following{/other_user}","gists_url":"https://api.github.com/users/sonaux/gists{/gist_id}","starred_url":"https://api.github.com/users/sonaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonaux/subscriptions","organizations_url":"https://api.github.com/users/sonaux/orgs","repos_url":"https://api.github.com/users/sonaux/repos","events_url":"https://api.github.com/users/sonaux/events{/privacy}","received_events_url":"https://api.github.com/users/sonaux/received_events","type":"User","site_admin":false},"body":"Fixes #2305.\r\n\r\n- [x] This PR is for the `dev` branch rather than for `master`.\r\n- [x] This PR is compliant with the [other contributing guidelines]\r\n- [x] I have thoroughly tested my contribution.\r\n- [x] The code changes are reflected in the documentation at `docs/en/*`.\r\n\r\nFollowing @TerryE suggestions in #2305 for use of rsr.ccount instruction I was able to get good formula for calculation of delays. \r\nOld delays did not take in account that running code takes some time too, and function i2c_master_writeByte contained extra unneeded (i hope) calls for setDC and delays, so overall speed was 35-40 kHz, not 100.\r\n\r\nI tested module with all I have: good old analog oscilloscope, couple of displays (u8g2.ssd1306_i2c_128x64_noname, u8g2.ssd1306_i2c_128x32_univision), sensor BMP180, chip EEPROM 24LC01B. \r\n\r\nSCL speed is independent of CPU clock speed until 250kHz, where delay reaches zero at CPU80MHz and ~400kHz clock achievable only at CPU160MHz.\r\nAlso I tried to replace gpio_output_set() with assembler code (s16i [gpio_mask], [gpio_addr]...), but only got 300 kHz SCL at CPU80MHz.\r\n","created_at":"2018-08-23T00:15:01Z","updated_at":"2018-09-02T14:27:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4ee28dbc7bba7883bd40f793b69a94ff30659e29","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":149782553,"node_id":"MDU6TGFiZWwxNDk3ODI1NTM=","url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465/commits","review_comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465/comments","review_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/2465/comments","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/142ccde71079df14b15dfa190d90b79745c46f12","head":{"label":"sonaux:i2c_FAST","ref":"i2c_FAST","sha":"142ccde71079df14b15dfa190d90b79745c46f12","user":{"login":"sonaux","id":6295943,"node_id":"MDQ6VXNlcjYyOTU5NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/6295943?v=4","gravatar_id":"","url":"https://api.github.com/users/sonaux","html_url":"https://github.com/sonaux","followers_url":"https://api.github.com/users/sonaux/followers","following_url":"https://api.github.com/users/sonaux/following{/other_user}","gists_url":"https://api.github.com/users/sonaux/gists{/gist_id}","starred_url":"https://api.github.com/users/sonaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonaux/subscriptions","organizations_url":"https://api.github.com/users/sonaux/orgs","repos_url":"https://api.github.com/users/sonaux/repos","events_url":"https://api.github.com/users/sonaux/events{/privacy}","received_events_url":"https://api.github.com/users/sonaux/received_events","type":"User","site_admin":false},"repo":{"id":144667151,"node_id":"MDEwOlJlcG9zaXRvcnkxNDQ2NjcxNTE=","name":"nodemcu-firmware","full_name":"sonaux/nodemcu-firmware","owner":{"login":"sonaux","id":6295943,"node_id":"MDQ6VXNlcjYyOTU5NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/6295943?v=4","gravatar_id":"","url":"https://api.github.com/users/sonaux","html_url":"https://github.com/sonaux","followers_url":"https://api.github.com/users/sonaux/followers","following_url":"https://api.github.com/users/sonaux/following{/other_user}","gists_url":"https://api.github.com/users/sonaux/gists{/gist_id}","starred_url":"https://api.github.com/users/sonaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonaux/subscriptions","organizations_url":"https://api.github.com/users/sonaux/orgs","repos_url":"https://api.github.com/users/sonaux/repos","events_url":"https://api.github.com/users/sonaux/events{/privacy}","received_events_url":"https://api.github.com/users/sonaux/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sonaux/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":true,"url":"https://api.github.com/repos/sonaux/nodemcu-firmware","forks_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/releases{/id}","deployments_url":"https://api.github.com/repos/sonaux/nodemcu-firmware/deployments","created_at":"2018-08-14T04:08:59Z","updated_at":"2018-08-14T04:09:04Z","pushed_at":"2018-09-01T23:24:16Z","git_url":"git://github.com/sonaux/nodemcu-firmware.git","ssh_url":"git@github.com:sonaux/nodemcu-firmware.git","clone_url":"https://github.com/sonaux/nodemcu-firmware.git","svn_url":"https://github.com/sonaux/nodemcu-firmware","homepage":"http://nodemcu.com","size":106543,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nodemcu:dev","ref":"dev","sha":"add0938d819ebc95e28a46f172a8a5a3a8282376","user":{"login":"nodemcu","id":9865736,"node_id":"MDQ6VXNlcjk4NjU3MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/9865736?v=4","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"repo":{"id":26917568,"node_id":"MDEwOlJlcG9zaXRvcnkyNjkxNzU2OA==","name":"nodemcu-firmware","full_name":"nodemcu/nodemcu-firmware","owner":{"login":"nodemcu","id":9865736,"node_id":"MDQ6VXNlcjk4NjU3MzY=","avatar_url":"https://avatars0.githubusercontent.com/u/9865736?v=4","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nodemcu/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":false,"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware","forks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/releases{/id}","deployments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/deployments","created_at":"2014-11-20T15:06:45Z","updated_at":"2018-09-02T14:24:49Z","pushed_at":"2018-09-02T10:31:10Z","git_url":"git://github.com/nodemcu/nodemcu-firmware.git","ssh_url":"git@github.com:nodemcu/nodemcu-firmware.git","clone_url":"https://github.com/nodemcu/nodemcu-firmware.git","svn_url":"https://github.com/nodemcu/nodemcu-firmware","homepage":"http://nodemcu.com","size":106516,"stargazers_count":4691,"watchers_count":4691,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2147,"mirror_url":null,"archived":false,"open_issues_count":202,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":2147,"open_issues":202,"watchers":4691,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465"},"html":{"href":"https://github.com/nodemcu/nodemcu-firmware/pull/2465"},"issue":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/2465"},"comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/2465/comments"},"review_comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465/comments"},"review_comment":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/2465/commits"},"statuses":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/142ccde71079df14b15dfa190d90b79745c46f12"}},"author_association":"NONE"}}
{"actor":{"display_login":"TerryE"}}