Selaa lähdekoodia

upm: move to maa 0.2.1 C api

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Brendan Le Foll 10 vuotta sitten
vanhempi
commit
b0684c98a8
3 muutettua tiedostoa jossa 15 lisäystä ja 13 poistoa
  1. 2
    2
      CMakeLists.txt
  2. 11
    9
      src/hmc5883l/hmc5883l.cxx
  3. 2
    2
      src/hmc5883l/hmc5883l.h

+ 2
- 2
CMakeLists.txt Näytä tiedosto

@@ -5,8 +5,8 @@ set (SWIG_EXECUTABLE /usr/bin/swig)
5 5
 find_package (SWIG REQUIRED)
6 6
 include (${SWIG_USE_FILE})
7 7
 
8
-find_package(PkgConfig REQUIRED)
9
-pkg_check_modules(MAA maa>=0.1.1)
8
+find_package (PkgConfig REQUIRED)
9
+pkg_check_modules (MAA maa>=0.2.1)
10 10
 
11 11
 set (CMAKE_SWIG_FLAGS "")
12 12
 

+ 11
- 9
src/hmc5883l/hmc5883l.cxx Näytä tiedosto

@@ -79,17 +79,17 @@ using namespace upm;
79 79
 
80 80
 Hmc5883l::Hmc5883l()
81 81
 {
82
-    i2c = new maa::I2CSlave(26, 27);
82
+    i2c = maa_i2c_init();
83 83
 
84
-    i2c->address(HMC5883L_I2C_ADDR);
84
+    maa_i2c_address(i2c, HMC5883L_I2C_ADDR);
85 85
     rx_tx_buf[0] = HMC5883L_CONF_REG_B;
86 86
     rx_tx_buf[1] = GA_1_3_REG;
87
-    i2c->write(rx_tx_buf, 2);
87
+    maa_i2c_write(i2c, rx_tx_buf, 2);
88 88
 
89
-    i2c->address(HMC5883L_I2C_ADDR);
89
+    maa_i2c_address(i2c, HMC5883L_I2C_ADDR);
90 90
     rx_tx_buf[0] = HMC5883L_MODE_REG;
91 91
     rx_tx_buf[1] = HMC5883L_CONT_MODE;
92
-    i2c->write(rx_tx_buf, 2);
92
+    maa_i2c_write(i2c, rx_tx_buf, 2);
93 93
 
94 94
     Hmc5883l::update();
95 95
 }
@@ -97,11 +97,11 @@ Hmc5883l::Hmc5883l()
97 97
 int
98 98
 Hmc5883l::update(void)
99 99
 {
100
-    i2c->address(HMC5883L_I2C_ADDR);
101
-    i2c->write(HMC5883L_DATA_REG);
100
+    maa_i2c_address(i2c, HMC5883L_I2C_ADDR);
101
+    maa_i2c_write_byte(i2c, HMC5883L_DATA_REG);
102 102
 
103
-    i2c->address(HMC5883L_I2C_ADDR);
104
-    i2c->read(rx_tx_buf, DATA_REG_SIZE);
103
+    maa_i2c_address(i2c, HMC5883L_I2C_ADDR);
104
+    maa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE);
105 105
 
106 106
     // x
107 107
     coor[0] = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
@@ -109,6 +109,8 @@ Hmc5883l::update(void)
109 109
     coor[2] = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ;
110 110
     // y
111 111
     coor[1] = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ;
112
+
113
+    return MAA_SUCCESS;
112 114
 }
113 115
 
114 116
 float

+ 2
- 2
src/hmc5883l/hmc5883l.h Näytä tiedosto

@@ -23,7 +23,7 @@
23 23
  */
24 24
 #pragma once
25 25
 
26
-#include <maa/maa.h>
26
+#include <maa/i2c.h>
27 27
 
28 28
 #define MAX_BUFFER_LENGTH 6
29 29
 
@@ -39,7 +39,7 @@ public:
39 39
 private:
40 40
     int coor[3];
41 41
     char rx_tx_buf[MAX_BUFFER_LENGTH];
42
-    maa::I2CSlave* i2c;
42
+    maa_i2c_context* i2c;
43 43
 };
44 44
 
45 45
 }