{"action":"created","comment":{"url":"https://api.github.com/repos/Theseus/bulebule/pulls/comments/187811189","pull_request_review_id":119664078,"id":187811189,"diff_hunk":"@@ -0,0 +1,190 @@\n+#include \"mpu.h\"\n+\n+#define BYTE 8\n+#define MPU_CAL_SAMPLE_NUM 100\n+#define MPU_AVERAGE_FACTOR 2\n+#define MPU_COMPLEMENT_2_FACTOR 2\n+#define MPU_CAL_SAMPLE_US 1000\n+\n+#define MPU_READ 0x80\n+#define MPU_SMPLRT_DIV 25\n+#define MPU_CONFIG 26\n+#define MPU_GYRO_CONFIG 27\n+#define MPU_SIGNAL_PATH_RESET 104\n+#define MPU_PWR_MGMT_1 107\n+#define MPU_USER_CTRL 106\n+#define MPU_WHOAMI 117\n+\n+#define MPU_GYRO_ZOUT_H 71\n+#define MPU_GYRO_ZOUT_L 72\n+#define MPU_Z_OFFS_USR_H 23\n+#define MPU_Z_OFFS_USR_L 24\n+\n+#define MPU_MASK_H 0xFF00\n+#define MPU_MASK_L 0x00FF\n+\n+#define MPU_GYRO_SENSITIVITY_2000_DPS 16.4\n+#define MPU_DPS_TO_RADPS (3.14 / 180)\n+\n+static volatile float deg_integ;\n+static volatile int16_t gyro_z_raw;\n+/**\n+ * @brief Read a MPU register.\n+ *\n+ * @param[in] address Register address.\n+ */\n+static uint8_t mpu_read_register(uint8_t address)\n+{\n+\tuint8_t reading;\n+\n+\tgpio_clear(GPIOB, GPIO12);\n+\tspi_send(SPI2, (MPU_READ | address));\n+\tspi_read(SPI2);\n+\tspi_send(SPI2, 0x00);\n+\treading = spi_read(SPI2);\n+\tgpio_set(GPIOB, GPIO12);\n+\n+\treturn reading;\n+}\n+\n+/**\n+ * @brief Write a MPU register with a given value.\n+ *\n+ * @param[in] address Register address.\n+ * @param[in] address Register value.\n+ */\n+static void mpu_write_register(uint8_t address, uint8_t value)\n+{\n+\tgpio_clear(GPIOB, GPIO12);\n+\tspi_send(SPI2, address);\n+\tspi_read(SPI2);\n+\tspi_send(SPI2, value);\n+\tspi_read(SPI2);\n+\tgpio_set(GPIOB, GPIO12);\n+}\n+\n+/**\n+ * @brief Read the WHOAMI register value.\n+ *\n+ * This is a read-only register set to 0x70 after reset.\n+ */\n+uint8_t mpu_who_am_i(void)\n+{\n+\treturn mpu_read_register(MPU_WHOAMI);\n+}\n+\n+/**\n+ * @brief MPU-6500 board setup.\n+ *\n+ * MPU is configured as follows:\n+ *\n+ * - Configure SPI at low speed to write (less than 1MHz)\n+ * - Reset MPU restoring default settings and wait 100 ms\n+ * - Reset signal path and wait 100 ms\n+ * - Set SPI mode, reset I2C Slave module\n+ * - Sample Rate Divider (dix) equal to 0 where: SampleRate = InternalSample /\n+ *   (1 + div)\n+ * - Set DLPF (Dual Low Pass Filter) configuration to 0 with 250 Hz of\n+ *   bandwidth and InternalSample = 8 kHz\n+ * - Configure gyroscope's Z-axis with DLPF, -2000 dps and 16.4 LSB\n+ * - Configure SPI at high speed (less than 20MHz)\n+ * - Wait 100 ms\n+ */\n+void setup_mpu(void)\n+{\n+\tsetup_spi_low_speed();\n+\tmpu_write_register(MPU_PWR_MGMT_1, 0x80);\n+\tsleep_us(100000);\n+\tmpu_write_register(MPU_SIGNAL_PATH_RESET, 0x07);\n+\tsleep_us(100000);\n+\tmpu_write_register(MPU_USER_CTRL, 0x10);\n+\tmpu_write_register(MPU_SMPLRT_DIV, 0x00);\n+\tmpu_write_register(MPU_CONFIG, 0x00);\n+\tmpu_write_register(MPU_GYRO_CONFIG, 0x18);\n+\tsetup_spi_high_speed();\n+\tsleep_us(100000);\n+}\n+\n+/**\n+ * @brief Get gyroscope's Z-axis angular speed in bits per second.\n+ */\n+int16_t get_gyro_z_raw(void)","path":"src/mpu.c","position":111,"original_position":111,"commit_id":"5a4b208a0040b06000e836b054d26e8374b642e2","original_commit_id":"5a4b208a0040b06000e836b054d26e8374b642e2","user":{"login":"Peque","id":526577,"avatar_url":"https://avatars1.githubusercontent.com/u/526577?v=4","gravatar_id":"","url":"https://api.github.com/users/Peque","html_url":"https://github.com/Peque","followers_url":"https://api.github.com/users/Peque/followers","following_url":"https://api.github.com/users/Peque/following{/other_user}","gists_url":"https://api.github.com/users/Peque/gists{/gist_id}","starred_url":"https://api.github.com/users/Peque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Peque/subscriptions","organizations_url":"https://api.github.com/users/Peque/orgs","repos_url":"https://api.github.com/users/Peque/repos","events_url":"https://api.github.com/users/Peque/events{/privacy}","received_events_url":"https://api.github.com/users/Peque/received_events","type":"User","site_admin":false},"body":"`mpu_read_gyro_z()`?","created_at":"2018-05-13T19:36:01Z","updated_at":"2018-05-13T19:46:08Z","html_url":"https://github.com/Theseus/bulebule/pull/277#discussion_r187811189","pull_request_url":"https://api.github.com/repos/Theseus/bulebule/pulls/277","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/comments/187811189"},"html":{"href":"https://github.com/Theseus/bulebule/pull/277#discussion_r187811189"},"pull_request":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/277"}}},"pull_request":{"url":"https://api.github.com/repos/Theseus/bulebule/pulls/277","id":185526608,"html_url":"https://github.com/Theseus/bulebule/pull/277","diff_url":"https://github.com/Theseus/bulebule/pull/277.diff","patch_url":"https://github.com/Theseus/bulebule/pull/277.patch","issue_url":"https://api.github.com/repos/Theseus/bulebule/issues/277","number":277,"state":"open","locked":false,"title":"Gyro configuration","user":{"login":"cua-cua","id":6835191,"avatar_url":"https://avatars1.githubusercontent.com/u/6835191?v=4","gravatar_id":"","url":"https://api.github.com/users/cua-cua","html_url":"https://github.com/cua-cua","followers_url":"https://api.github.com/users/cua-cua/followers","following_url":"https://api.github.com/users/cua-cua/following{/other_user}","gists_url":"https://api.github.com/users/cua-cua/gists{/gist_id}","starred_url":"https://api.github.com/users/cua-cua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cua-cua/subscriptions","organizations_url":"https://api.github.com/users/cua-cua/orgs","repos_url":"https://api.github.com/users/cua-cua/repos","events_url":"https://api.github.com/users/cua-cua/events{/privacy}","received_events_url":"https://api.github.com/users/cua-cua/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-02T18:42:42Z","updated_at":"2018-05-13T19:46:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d7a3b4e42c7d95559319079d18a25ef53eda2f5","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":605047332,"url":"https://api.github.com/repos/Theseus/bulebule/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":665576033,"url":"https://api.github.com/repos/Theseus/bulebule/labels/feature","name":"feature","color":"fbca04","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Theseus/bulebule/pulls/277/commits","review_comments_url":"https://api.github.com/repos/Theseus/bulebule/pulls/277/comments","review_comment_url":"https://api.github.com/repos/Theseus/bulebule/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Theseus/bulebule/issues/277/comments","statuses_url":"https://api.github.com/repos/Theseus/bulebule/statuses/5a4b208a0040b06000e836b054d26e8374b642e2","head":{"label":"cua-cua:mpu","ref":"mpu","sha":"5a4b208a0040b06000e836b054d26e8374b642e2","user":{"login":"cua-cua","id":6835191,"avatar_url":"https://avatars1.githubusercontent.com/u/6835191?v=4","gravatar_id":"","url":"https://api.github.com/users/cua-cua","html_url":"https://github.com/cua-cua","followers_url":"https://api.github.com/users/cua-cua/followers","following_url":"https://api.github.com/users/cua-cua/following{/other_user}","gists_url":"https://api.github.com/users/cua-cua/gists{/gist_id}","starred_url":"https://api.github.com/users/cua-cua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cua-cua/subscriptions","organizations_url":"https://api.github.com/users/cua-cua/orgs","repos_url":"https://api.github.com/users/cua-cua/repos","events_url":"https://api.github.com/users/cua-cua/events{/privacy}","received_events_url":"https://api.github.com/users/cua-cua/received_events","type":"User","site_admin":false},"repo":{"id":94467913,"name":"theseus","full_name":"cua-cua/theseus","owner":{"login":"cua-cua","id":6835191,"avatar_url":"https://avatars1.githubusercontent.com/u/6835191?v=4","gravatar_id":"","url":"https://api.github.com/users/cua-cua","html_url":"https://github.com/cua-cua","followers_url":"https://api.github.com/users/cua-cua/followers","following_url":"https://api.github.com/users/cua-cua/following{/other_user}","gists_url":"https://api.github.com/users/cua-cua/gists{/gist_id}","starred_url":"https://api.github.com/users/cua-cua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cua-cua/subscriptions","organizations_url":"https://api.github.com/users/cua-cua/orgs","repos_url":"https://api.github.com/users/cua-cua/repos","events_url":"https://api.github.com/users/cua-cua/events{/privacy}","received_events_url":"https://api.github.com/users/cua-cua/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cua-cua/theseus","description":null,"fork":true,"url":"https://api.github.com/repos/cua-cua/theseus","forks_url":"https://api.github.com/repos/cua-cua/theseus/forks","keys_url":"https://api.github.com/repos/cua-cua/theseus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cua-cua/theseus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cua-cua/theseus/teams","hooks_url":"https://api.github.com/repos/cua-cua/theseus/hooks","issue_events_url":"https://api.github.com/repos/cua-cua/theseus/issues/events{/number}","events_url":"https://api.github.com/repos/cua-cua/theseus/events","assignees_url":"https://api.github.com/repos/cua-cua/theseus/assignees{/user}","branches_url":"https://api.github.com/repos/cua-cua/theseus/branches{/branch}","tags_url":"https://api.github.com/repos/cua-cua/theseus/tags","blobs_url":"https://api.github.com/repos/cua-cua/theseus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cua-cua/theseus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cua-cua/theseus/git/refs{/sha}","trees_url":"https://api.github.com/repos/cua-cua/theseus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cua-cua/theseus/statuses/{sha}","languages_url":"https://api.github.com/repos/cua-cua/theseus/languages","stargazers_url":"https://api.github.com/repos/cua-cua/theseus/stargazers","contributors_url":"https://api.github.com/repos/cua-cua/theseus/contributors","subscribers_url":"https://api.github.com/repos/cua-cua/theseus/subscribers","subscription_url":"https://api.github.com/repos/cua-cua/theseus/subscription","commits_url":"https://api.github.com/repos/cua-cua/theseus/commits{/sha}","git_commits_url":"https://api.github.com/repos/cua-cua/theseus/git/commits{/sha}","comments_url":"https://api.github.com/repos/cua-cua/theseus/comments{/number}","issue_comment_url":"https://api.github.com/repos/cua-cua/theseus/issues/comments{/number}","contents_url":"https://api.github.com/repos/cua-cua/theseus/contents/{+path}","compare_url":"https://api.github.com/repos/cua-cua/theseus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cua-cua/theseus/merges","archive_url":"https://api.github.com/repos/cua-cua/theseus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cua-cua/theseus/downloads","issues_url":"https://api.github.com/repos/cua-cua/theseus/issues{/number}","pulls_url":"https://api.github.com/repos/cua-cua/theseus/pulls{/number}","milestones_url":"https://api.github.com/repos/cua-cua/theseus/milestones{/number}","notifications_url":"https://api.github.com/repos/cua-cua/theseus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cua-cua/theseus/labels{/name}","releases_url":"https://api.github.com/repos/cua-cua/theseus/releases{/id}","deployments_url":"https://api.github.com/repos/cua-cua/theseus/deployments","created_at":"2017-06-15T18:31:14Z","updated_at":"2018-05-13T13:59:25Z","pushed_at":"2018-05-13T17:30:25Z","git_url":"git://github.com/cua-cua/theseus.git","ssh_url":"git@github.com:cua-cua/theseus.git","clone_url":"https://github.com/cua-cua/theseus.git","svn_url":"https://github.com/cua-cua/theseus","homepage":null,"size":348,"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":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Theseus:master","ref":"master","sha":"9afd1e8bae98125375686d5f1487e6a8ab780b02","user":{"login":"Theseus","id":28692883,"avatar_url":"https://avatars1.githubusercontent.com/u/28692883?v=4","gravatar_id":"","url":"https://api.github.com/users/Theseus","html_url":"https://github.com/Theseus","followers_url":"https://api.github.com/users/Theseus/followers","following_url":"https://api.github.com/users/Theseus/following{/other_user}","gists_url":"https://api.github.com/users/Theseus/gists{/gist_id}","starred_url":"https://api.github.com/users/Theseus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theseus/subscriptions","organizations_url":"https://api.github.com/users/Theseus/orgs","repos_url":"https://api.github.com/users/Theseus/repos","events_url":"https://api.github.com/users/Theseus/events{/privacy}","received_events_url":"https://api.github.com/users/Theseus/received_events","type":"Organization","site_admin":false},"repo":{"id":91276515,"name":"bulebule","full_name":"Theseus/bulebule","owner":{"login":"Theseus","id":28692883,"avatar_url":"https://avatars1.githubusercontent.com/u/28692883?v=4","gravatar_id":"","url":"https://api.github.com/users/Theseus","html_url":"https://github.com/Theseus","followers_url":"https://api.github.com/users/Theseus/followers","following_url":"https://api.github.com/users/Theseus/following{/other_user}","gists_url":"https://api.github.com/users/Theseus/gists{/gist_id}","starred_url":"https://api.github.com/users/Theseus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theseus/subscriptions","organizations_url":"https://api.github.com/users/Theseus/orgs","repos_url":"https://api.github.com/users/Theseus/repos","events_url":"https://api.github.com/users/Theseus/events{/privacy}","received_events_url":"https://api.github.com/users/Theseus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Theseus/bulebule","description":"A maze-solving micromouse robot","fork":false,"url":"https://api.github.com/repos/Theseus/bulebule","forks_url":"https://api.github.com/repos/Theseus/bulebule/forks","keys_url":"https://api.github.com/repos/Theseus/bulebule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Theseus/bulebule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Theseus/bulebule/teams","hooks_url":"https://api.github.com/repos/Theseus/bulebule/hooks","issue_events_url":"https://api.github.com/repos/Theseus/bulebule/issues/events{/number}","events_url":"https://api.github.com/repos/Theseus/bulebule/events","assignees_url":"https://api.github.com/repos/Theseus/bulebule/assignees{/user}","branches_url":"https://api.github.com/repos/Theseus/bulebule/branches{/branch}","tags_url":"https://api.github.com/repos/Theseus/bulebule/tags","blobs_url":"https://api.github.com/repos/Theseus/bulebule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Theseus/bulebule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Theseus/bulebule/git/refs{/sha}","trees_url":"https://api.github.com/repos/Theseus/bulebule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Theseus/bulebule/statuses/{sha}","languages_url":"https://api.github.com/repos/Theseus/bulebule/languages","stargazers_url":"https://api.github.com/repos/Theseus/bulebule/stargazers","contributors_url":"https://api.github.com/repos/Theseus/bulebule/contributors","subscribers_url":"https://api.github.com/repos/Theseus/bulebule/subscribers","subscription_url":"https://api.github.com/repos/Theseus/bulebule/subscription","commits_url":"https://api.github.com/repos/Theseus/bulebule/commits{/sha}","git_commits_url":"https://api.github.com/repos/Theseus/bulebule/git/commits{/sha}","comments_url":"https://api.github.com/repos/Theseus/bulebule/comments{/number}","issue_comment_url":"https://api.github.com/repos/Theseus/bulebule/issues/comments{/number}","contents_url":"https://api.github.com/repos/Theseus/bulebule/contents/{+path}","compare_url":"https://api.github.com/repos/Theseus/bulebule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Theseus/bulebule/merges","archive_url":"https://api.github.com/repos/Theseus/bulebule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Theseus/bulebule/downloads","issues_url":"https://api.github.com/repos/Theseus/bulebule/issues{/number}","pulls_url":"https://api.github.com/repos/Theseus/bulebule/pulls{/number}","milestones_url":"https://api.github.com/repos/Theseus/bulebule/milestones{/number}","notifications_url":"https://api.github.com/repos/Theseus/bulebule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Theseus/bulebule/labels{/name}","releases_url":"https://api.github.com/repos/Theseus/bulebule/releases{/id}","deployments_url":"https://api.github.com/repos/Theseus/bulebule/deployments","created_at":"2017-05-14T22:59:46Z","updated_at":"2018-05-10T23:32:56Z","pushed_at":"2018-05-13T17:30:26Z","git_url":"git://github.com/Theseus/bulebule.git","ssh_url":"git@github.com:Theseus/bulebule.git","clone_url":"https://github.com/Theseus/bulebule.git","svn_url":"https://github.com/Theseus/bulebule","homepage":"https://bulebule.readthedocs.io/","size":328,"stargazers_count":21,"watchers_count":21,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":88,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":5,"open_issues":88,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/277"},"html":{"href":"https://github.com/Theseus/bulebule/pull/277"},"issue":{"href":"https://api.github.com/repos/Theseus/bulebule/issues/277"},"comments":{"href":"https://api.github.com/repos/Theseus/bulebule/issues/277/comments"},"review_comments":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/277/comments"},"review_comment":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Theseus/bulebule/pulls/277/commits"},"statuses":{"href":"https://api.github.com/repos/Theseus/bulebule/statuses/5a4b208a0040b06000e836b054d26e8374b642e2"}},"author_association":"OWNER"}}
{"actor":{"display_login":"Peque"}}