{"action":"created","comment":{"url":"https://api.github.com/repos/apache/mynewt-core/pulls/comments/137366881","pull_request_review_id":61021913,"id":137366881,"diff_hunk":"@@ -0,0 +1,466 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * resarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *  http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+#include <string.h>\n+#include <errno.h>\n+#include <assert.h>\n+\n+#include \"defs/error.h\"\n+#include \"os/os.h\"\n+#include \"sysinit/sysinit.h\"\n+#include \"hal/hal_i2c.h\"\n+#include \"sensor/sensor.h\"\n+#include \"sensor/accel.h\"\n+#include \"sensor/gyro.h\"\n+#include \"mpu6050/mpu6050.h\"\n+#include \"mpu6050_priv.h\"\n+\n+#if MYNEWT_VAL(MPU6050_LOG)\n+#include \"log/log.h\"\n+#endif\n+\n+#if MYNEWT_VAL(MPU6050_STATS)\n+#include \"stats/stats.h\"\n+#endif\n+\n+#if MYNEWT_VAL(MPU6050_STATS)\n+/* Define the stats section and records */\n+STATS_SECT_START(mpu6050_stat_section)\n+    STATS_SECT_ENTRY(read_errors)\n+    STATS_SECT_ENTRY(write_errors)\n+STATS_SECT_END\n+\n+/* Define stat names for querying */\n+STATS_NAME_START(mpu6050_stat_section)\n+    STATS_NAME(mpu6050_stat_section, read_errors)\n+    STATS_NAME(mpu6050_stat_section, write_errors)\n+STATS_NAME_END(mpu6050_stat_section)\n+\n+/* Global variable used to hold stats data */\n+STATS_SECT_DECL(mpu6050_stat_section) g_mpu6050stats;\n+#endif\n+\n+#if MYNEWT_VAL(MPU6050_LOG)\n+#define LOG_MODULE_MPU6050    (6050)\n+#define MPU6050_INFO(...)     LOG_INFO(&_log, LOG_MODULE_MPU6050, __VA_ARGS__)\n+#define MPU6050_ERR(...)      LOG_ERROR(&_log, LOG_MODULE_MPU6050, __VA_ARGS__)\n+static struct log _log;\n+#else\n+#define MPU6050_INFO(...)\n+#define MPU6050_ERR(...)\n+#endif\n+\n+/* Exports for the sensor API */\n+static int mpu6050_sensor_read(struct sensor *, sensor_type_t,\n+        sensor_data_func_t, void *, uint32_t);\n+static int mpu6050_sensor_get_config(struct sensor *, sensor_type_t,\n+        struct sensor_cfg *);\n+\n+static const struct sensor_driver g_mpu6050_sensor_driver = {\n+    mpu6050_sensor_read,\n+    mpu6050_sensor_get_config\n+};\n+\n+/**\n+ * Writes a single byte to the specified register\n+ *\n+ * @param The sensor interface\n+ * @param The I2C address to use\n+ * @param The register address to write to\n+ * @param The value to write\n+ *\n+ * @return 0 on success, non-zero error on failure.\n+ */\n+int\n+mpu6050_write8(struct sensor_itf *itf, uint8_t addr, uint8_t reg,\n+                  uint32_t value)\n+{\n+    int rc;\n+    uint8_t payload[2] = { reg, value & 0xFF };\n+\n+    struct hal_i2c_master_data data_struct = {\n+        .address = addr,\n+        .len = 2,\n+        .buffer = payload\n+    };\n+\n+    rc = hal_i2c_master_write(itf->si_num, &data_struct,\n+                              OS_TICKS_PER_SEC / 10, 1);\n+\n+    if (rc != 0) {\n+        MPU6050_ERR(\"Failed to write to 0x%02X:0x%02X with value 0x%02X\\n\",\n+                       addr, reg, value);\n+#if MYNEWT_VAL(MPU6050_STATS)\n+        STATS_INC(g_mpu6050stats, read_errors);\n+#endif\n+    }\n+\n+    return rc;\n+}\n+\n+/**\n+ * Reads a single byte from the specified register\n+ *\n+ * @param The sensor interface\n+ * @param The I2C address to use\n+ * @param The register address to read from\n+ * @param Pointer to where the register value should be written\n+ *\n+ * @return 0 on success, non-zero error on failure.\n+ */\n+int\n+mpu6050_read8(struct sensor_itf *itf, uint8_t addr, uint8_t reg,\n+                 uint8_t *value)\n+{\n+    int rc;\n+\n+    struct hal_i2c_master_data data_struct = {\n+        .address = addr,\n+        .len = 1,\n+        .buffer = &reg\n+    };\n+\n+    /* Register write */\n+    rc = hal_i2c_master_write(itf->si_num, &data_struct,\n+                              OS_TICKS_PER_SEC / 10, 0);\n+    if (rc != 0) {\n+        MPU6050_ERR(\"I2C access failed at address 0x%02X\\n\", addr);\n+#if MYNEWT_VAL(MPU6050_STATS)\n+        STATS_INC(g_mpu6050stats, write_errors);\n+#endif\n+        return rc;\n+    }\n+\n+    /* Read one byte back */\n+    data_struct.buffer = value;\n+    rc = hal_i2c_master_read(itf->si_num, &data_struct,\n+                             OS_TICKS_PER_SEC / 10, 1);\n+\n+    if (rc != 0) {\n+         MPU6050_ERR(\"Failed to read from 0x%02X:0x%02X\\n\", addr, reg);\n+ #if MYNEWT_VAL(MPU6050_STATS)\n+         STATS_INC(g_mpu6050stats, read_errors);\n+ #endif\n+    }\n+    return rc;\n+}\n+\n+/**\n+ * Reads a six bytes from the specified register\n+ *\n+ * @param The sensor interface\n+ * @param The I2C address to use\n+ * @param The register address to read from\n+ * @param Pointer to where the register value should be written\n+ *\n+ * @return 0 on success, non-zero error on failure.\n+ */\n+int\n+mpu6050_read48(struct sensor_itf *itf, uint8_t addr, uint8_t reg,","path":"hw/drivers/sensors/mpu6050/src/mpu6050.c","position":175,"original_position":175,"commit_id":"78211f95dda9b45087751f6e24da91e0a9393d45","original_commit_id":"78211f95dda9b45087751f6e24da91e0a9393d45","user":{"login":"vrahane","id":7097467,"avatar_url":"https://avatars0.githubusercontent.com/u/7097467?v=4","gravatar_id":"","url":"https://api.github.com/users/vrahane","html_url":"https://github.com/vrahane","followers_url":"https://api.github.com/users/vrahane/followers","following_url":"https://api.github.com/users/vrahane/following{/other_user}","gists_url":"https://api.github.com/users/vrahane/gists{/gist_id}","starred_url":"https://api.github.com/users/vrahane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vrahane/subscriptions","organizations_url":"https://api.github.com/users/vrahane/orgs","repos_url":"https://api.github.com/users/vrahane/repos","events_url":"https://api.github.com/users/vrahane/events{/privacy}","received_events_url":"https://api.github.com/users/vrahane/received_events","type":"User","site_admin":false},"body":"The device I2C interface address is already present in sensor_itf as \"si_addr\". It generally gets set in the bsp for onboard sensors and in the creator for offboard ones. The parameter \"addr\" is not needed. You already set the interface address. All you would have to do here is use the macro \"SENSOR_GET_ITF()\" to get the interface and then use \"si_addr\" field.","created_at":"2017-09-06T19:28:08Z","updated_at":"2017-09-06T19:52:07Z","html_url":"https://github.com/apache/mynewt-core/pull/516#discussion_r137366881","pull_request_url":"https://api.github.com/repos/apache/mynewt-core/pulls/516","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/comments/137366881"},"html":{"href":"https://github.com/apache/mynewt-core/pull/516#discussion_r137366881"},"pull_request":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/516"}}},"pull_request":{"url":"https://api.github.com/repos/apache/mynewt-core/pulls/516","id":138554346,"html_url":"https://github.com/apache/mynewt-core/pull/516","diff_url":"https://github.com/apache/mynewt-core/pull/516.diff","patch_url":"https://github.com/apache/mynewt-core/pull/516.patch","issue_url":"https://api.github.com/repos/apache/mynewt-core/issues/516","number":516,"state":"open","locked":false,"title":"Mpu6050 Accel/Gyro","user":{"login":"vsyn","id":25068581,"avatar_url":"https://avatars0.githubusercontent.com/u/25068581?v=4","gravatar_id":"","url":"https://api.github.com/users/vsyn","html_url":"https://github.com/vsyn","followers_url":"https://api.github.com/users/vsyn/followers","following_url":"https://api.github.com/users/vsyn/following{/other_user}","gists_url":"https://api.github.com/users/vsyn/gists{/gist_id}","starred_url":"https://api.github.com/users/vsyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsyn/subscriptions","organizations_url":"https://api.github.com/users/vsyn/orgs","repos_url":"https://api.github.com/users/vsyn/repos","events_url":"https://api.github.com/users/vsyn/events{/privacy}","received_events_url":"https://api.github.com/users/vsyn/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-08-30T23:59:24Z","updated_at":"2017-09-06T19:52:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"843fd9247d7c547429df3dfb6f746f3205ca0e39","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/mynewt-core/pulls/516/commits","review_comments_url":"https://api.github.com/repos/apache/mynewt-core/pulls/516/comments","review_comment_url":"https://api.github.com/repos/apache/mynewt-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/mynewt-core/issues/516/comments","statuses_url":"https://api.github.com/repos/apache/mynewt-core/statuses/78211f95dda9b45087751f6e24da91e0a9393d45","head":{"label":"vsyn:mpu6050","ref":"mpu6050","sha":"78211f95dda9b45087751f6e24da91e0a9393d45","user":{"login":"vsyn","id":25068581,"avatar_url":"https://avatars0.githubusercontent.com/u/25068581?v=4","gravatar_id":"","url":"https://api.github.com/users/vsyn","html_url":"https://github.com/vsyn","followers_url":"https://api.github.com/users/vsyn/followers","following_url":"https://api.github.com/users/vsyn/following{/other_user}","gists_url":"https://api.github.com/users/vsyn/gists{/gist_id}","starred_url":"https://api.github.com/users/vsyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsyn/subscriptions","organizations_url":"https://api.github.com/users/vsyn/orgs","repos_url":"https://api.github.com/users/vsyn/repos","events_url":"https://api.github.com/users/vsyn/events{/privacy}","received_events_url":"https://api.github.com/users/vsyn/received_events","type":"User","site_admin":false},"repo":{"id":101937312,"name":"mynewt-core","full_name":"vsyn/mynewt-core","owner":{"login":"vsyn","id":25068581,"avatar_url":"https://avatars0.githubusercontent.com/u/25068581?v=4","gravatar_id":"","url":"https://api.github.com/users/vsyn","html_url":"https://github.com/vsyn","followers_url":"https://api.github.com/users/vsyn/followers","following_url":"https://api.github.com/users/vsyn/following{/other_user}","gists_url":"https://api.github.com/users/vsyn/gists{/gist_id}","starred_url":"https://api.github.com/users/vsyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsyn/subscriptions","organizations_url":"https://api.github.com/users/vsyn/orgs","repos_url":"https://api.github.com/users/vsyn/repos","events_url":"https://api.github.com/users/vsyn/events{/privacy}","received_events_url":"https://api.github.com/users/vsyn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vsyn/mynewt-core","description":null,"fork":true,"url":"https://api.github.com/repos/vsyn/mynewt-core","forks_url":"https://api.github.com/repos/vsyn/mynewt-core/forks","keys_url":"https://api.github.com/repos/vsyn/mynewt-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vsyn/mynewt-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vsyn/mynewt-core/teams","hooks_url":"https://api.github.com/repos/vsyn/mynewt-core/hooks","issue_events_url":"https://api.github.com/repos/vsyn/mynewt-core/issues/events{/number}","events_url":"https://api.github.com/repos/vsyn/mynewt-core/events","assignees_url":"https://api.github.com/repos/vsyn/mynewt-core/assignees{/user}","branches_url":"https://api.github.com/repos/vsyn/mynewt-core/branches{/branch}","tags_url":"https://api.github.com/repos/vsyn/mynewt-core/tags","blobs_url":"https://api.github.com/repos/vsyn/mynewt-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vsyn/mynewt-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vsyn/mynewt-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/vsyn/mynewt-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vsyn/mynewt-core/statuses/{sha}","languages_url":"https://api.github.com/repos/vsyn/mynewt-core/languages","stargazers_url":"https://api.github.com/repos/vsyn/mynewt-core/stargazers","contributors_url":"https://api.github.com/repos/vsyn/mynewt-core/contributors","subscribers_url":"https://api.github.com/repos/vsyn/mynewt-core/subscribers","subscription_url":"https://api.github.com/repos/vsyn/mynewt-core/subscription","commits_url":"https://api.github.com/repos/vsyn/mynewt-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/vsyn/mynewt-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/vsyn/mynewt-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/vsyn/mynewt-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/vsyn/mynewt-core/contents/{+path}","compare_url":"https://api.github.com/repos/vsyn/mynewt-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vsyn/mynewt-core/merges","archive_url":"https://api.github.com/repos/vsyn/mynewt-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vsyn/mynewt-core/downloads","issues_url":"https://api.github.com/repos/vsyn/mynewt-core/issues{/number}","pulls_url":"https://api.github.com/repos/vsyn/mynewt-core/pulls{/number}","milestones_url":"https://api.github.com/repos/vsyn/mynewt-core/milestones{/number}","notifications_url":"https://api.github.com/repos/vsyn/mynewt-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vsyn/mynewt-core/labels{/name}","releases_url":"https://api.github.com/repos/vsyn/mynewt-core/releases{/id}","deployments_url":"https://api.github.com/repos/vsyn/mynewt-core/deployments","created_at":"2017-08-30T23:15:25Z","updated_at":"2017-08-30T23:15:44Z","pushed_at":"2017-08-31T00:22:08Z","git_url":"git://github.com/vsyn/mynewt-core.git","ssh_url":"git@github.com:vsyn/mynewt-core.git","clone_url":"https://github.com/vsyn/mynewt-core.git","svn_url":"https://github.com/vsyn/mynewt-core","homepage":"","size":81977,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"40b870ab7d5dcc1fd33ae361931de7796e4b7a42","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":45165993,"name":"mynewt-core","full_name":"apache/mynewt-core","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/mynewt-core","description":null,"fork":false,"url":"https://api.github.com/repos/apache/mynewt-core","forks_url":"https://api.github.com/repos/apache/mynewt-core/forks","keys_url":"https://api.github.com/repos/apache/mynewt-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/mynewt-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/mynewt-core/teams","hooks_url":"https://api.github.com/repos/apache/mynewt-core/hooks","issue_events_url":"https://api.github.com/repos/apache/mynewt-core/issues/events{/number}","events_url":"https://api.github.com/repos/apache/mynewt-core/events","assignees_url":"https://api.github.com/repos/apache/mynewt-core/assignees{/user}","branches_url":"https://api.github.com/repos/apache/mynewt-core/branches{/branch}","tags_url":"https://api.github.com/repos/apache/mynewt-core/tags","blobs_url":"https://api.github.com/repos/apache/mynewt-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/mynewt-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/mynewt-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/mynewt-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/mynewt-core/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/mynewt-core/languages","stargazers_url":"https://api.github.com/repos/apache/mynewt-core/stargazers","contributors_url":"https://api.github.com/repos/apache/mynewt-core/contributors","subscribers_url":"https://api.github.com/repos/apache/mynewt-core/subscribers","subscription_url":"https://api.github.com/repos/apache/mynewt-core/subscription","commits_url":"https://api.github.com/repos/apache/mynewt-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/mynewt-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/mynewt-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/mynewt-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/mynewt-core/contents/{+path}","compare_url":"https://api.github.com/repos/apache/mynewt-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/mynewt-core/merges","archive_url":"https://api.github.com/repos/apache/mynewt-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/mynewt-core/downloads","issues_url":"https://api.github.com/repos/apache/mynewt-core/issues{/number}","pulls_url":"https://api.github.com/repos/apache/mynewt-core/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/mynewt-core/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/mynewt-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/mynewt-core/labels{/name}","releases_url":"https://api.github.com/repos/apache/mynewt-core/releases{/id}","deployments_url":"https://api.github.com/repos/apache/mynewt-core/deployments","created_at":"2015-10-29T07:00:07Z","updated_at":"2017-09-05T18:26:27Z","pushed_at":"2017-09-06T19:09:27Z","git_url":"git://github.com/apache/mynewt-core.git","ssh_url":"git@github.com:apache/mynewt-core.git","clone_url":"https://github.com/apache/mynewt-core.git","svn_url":"https://github.com/apache/mynewt-core","homepage":"","size":82215,"stargazers_count":234,"watchers_count":234,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":119,"mirror_url":null,"open_issues_count":7,"forks":119,"open_issues":7,"watchers":234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/516"},"html":{"href":"https://github.com/apache/mynewt-core/pull/516"},"issue":{"href":"https://api.github.com/repos/apache/mynewt-core/issues/516"},"comments":{"href":"https://api.github.com/repos/apache/mynewt-core/issues/516/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/516/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/mynewt-core/pulls/516/commits"},"statuses":{"href":"https://api.github.com/repos/apache/mynewt-core/statuses/78211f95dda9b45087751f6e24da91e0a9393d45"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"vrahane"}}