It is modified accordingly to work with sparkfun dmp library under mbed platform
Dependents: MPU9250-dmp-bluepill MPU9250-dmp
Fork of MotionDriver_6_1 by
mdcompat.cpp@3:8f2d21735748, 2017-08-08 (annotated)
- Committer:
- mbedoguz
- Date:
- Tue Aug 08 14:14:26 2017 +0000
- Revision:
- 3:8f2d21735748
- Parent:
- 2:e7e761471df9
- Child:
- 4:f395d9cc57c4
changes are made to sucessfully receive and transmit data by i2c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedoguz | 1:a6c3f8680fe0 | 1 | #include "mdcompat.h" |
mbedoguz | 1:a6c3f8680fe0 | 2 | #include "mbed.h" // must be out of the scope of extern "C" |
mbedoguz | 2:e7e761471df9 | 3 | I2C imu9250(I2C_SDA,I2C_SCL); |
mbedoguz | 1:a6c3f8680fe0 | 4 | |
mbedoguz | 1:a6c3f8680fe0 | 5 | void imu_init(void){ |
mbedoguz | 1:a6c3f8680fe0 | 6 | imu9250.frequency(400000); |
mbedoguz | 1:a6c3f8680fe0 | 7 | } |
mbedoguz | 1:a6c3f8680fe0 | 8 | unsigned short constrain( |
mbedoguz | 1:a6c3f8680fe0 | 9 | unsigned short x, |
mbedoguz | 1:a6c3f8680fe0 | 10 | unsigned short a, |
mbedoguz | 1:a6c3f8680fe0 | 11 | unsigned short b) {unsigned short result; |
mbedoguz | 1:a6c3f8680fe0 | 12 | result= (x<a) ? a:x; |
mbedoguz | 1:a6c3f8680fe0 | 13 | result= (x>b) ? b:x; |
mbedoguz | 1:a6c3f8680fe0 | 14 | return result; |
mbedoguz | 1:a6c3f8680fe0 | 15 | } |
mbedoguz | 1:a6c3f8680fe0 | 16 | |
mbedoguz | 1:a6c3f8680fe0 | 17 | extern "C" { |
mbedoguz | 1:a6c3f8680fe0 | 18 | |
mbedoguz | 1:a6c3f8680fe0 | 19 | int mbed_i2c_write( |
mbedoguz | 1:a6c3f8680fe0 | 20 | unsigned char slave_addr, |
mbedoguz | 1:a6c3f8680fe0 | 21 | unsigned char reg_addr, |
mbedoguz | 1:a6c3f8680fe0 | 22 | unsigned char length, |
mbedoguz | 3:8f2d21735748 | 23 | char const *data) {const char RA[]={reg_addr}; |
mbedoguz | 1:a6c3f8680fe0 | 24 | |
mbedoguz | 3:8f2d21735748 | 25 | imu9250.write((int)slave_addr<<1,RA,1,1);//sending register adress first to indicate which register we are writing and a write register(0) |
mbedoguz | 3:8f2d21735748 | 26 | imu9250.write((int)slave_addr<<1,data,(int)length,0); |
mbedoguz | 1:a6c3f8680fe0 | 27 | |
mbedoguz | 1:a6c3f8680fe0 | 28 | return 0; |
mbedoguz | 1:a6c3f8680fe0 | 29 | } |
mbedoguz | 1:a6c3f8680fe0 | 30 | |
mbedoguz | 1:a6c3f8680fe0 | 31 | int mbed_i2c_read( |
mbedoguz | 1:a6c3f8680fe0 | 32 | unsigned char slave_addr, |
mbedoguz | 1:a6c3f8680fe0 | 33 | unsigned char reg_addr, |
mbedoguz | 1:a6c3f8680fe0 | 34 | unsigned char length, |
mbedoguz | 3:8f2d21735748 | 35 | char *data) {const char RA[]={reg_addr}; |
mbedoguz | 3:8f2d21735748 | 36 | imu9250.write((int)slave_addr<<1,RA, 1, 1); // no stop |
mbedoguz | 3:8f2d21735748 | 37 | imu9250.read((int)slave_addr<<1, data, 1, 0); |
mbedoguz | 2:e7e761471df9 | 38 | return 0; |
mbedoguz | 1:a6c3f8680fe0 | 39 | } |
mbedoguz | 1:a6c3f8680fe0 | 40 | |
mbedoguz | 1:a6c3f8680fe0 | 41 | int delay_ms( |
mbedoguz | 1:a6c3f8680fe0 | 42 | unsigned long num_ms) { |
mbedoguz | 1:a6c3f8680fe0 | 43 | return 0; |
mbedoguz | 1:a6c3f8680fe0 | 44 | } |
mbedoguz | 1:a6c3f8680fe0 | 45 | |
mbedoguz | 1:a6c3f8680fe0 | 46 | int get_ms( |
mbedoguz | 1:a6c3f8680fe0 | 47 | unsigned long *count) { |
mbedoguz | 1:a6c3f8680fe0 | 48 | return 0; |
mbedoguz | 1:a6c3f8680fe0 | 49 | } |
mbedoguz | 1:a6c3f8680fe0 | 50 | |
mbedoguz | 1:a6c3f8680fe0 | 51 | int reg_int_cb( |
mbedoguz | 1:a6c3f8680fe0 | 52 | void (*cb)(void), |
mbedoguz | 1:a6c3f8680fe0 | 53 | unsigned char port, |
mbedoguz | 1:a6c3f8680fe0 | 54 | unsigned char pin) { |
mbedoguz | 1:a6c3f8680fe0 | 55 | return 0; |
mbedoguz | 1:a6c3f8680fe0 | 56 | } |
mbedoguz | 1:a6c3f8680fe0 | 57 | |
mbedoguz | 1:a6c3f8680fe0 | 58 | long labs(long x) { |
mbedoguz | 1:a6c3f8680fe0 | 59 | return x > 0 ? x : -x; |
mbedoguz | 1:a6c3f8680fe0 | 60 | } |
mbedoguz | 1:a6c3f8680fe0 | 61 | |
mbedoguz | 1:a6c3f8680fe0 | 62 | float fabsf(float x) { |
mbedoguz | 1:a6c3f8680fe0 | 63 | return x > 0 ? x : -x; |
mbedoguz | 1:a6c3f8680fe0 | 64 | } |
mbedoguz | 1:a6c3f8680fe0 | 65 | |
mbedoguz | 1:a6c3f8680fe0 | 66 | int min(int a, int b) { |
mbedoguz | 1:a6c3f8680fe0 | 67 | return a > b ? b : a; |
mbedoguz | 1:a6c3f8680fe0 | 68 | } |
mbedoguz | 1:a6c3f8680fe0 | 69 | |
mbedoguz | 1:a6c3f8680fe0 | 70 | }; |