Class for making communication easier from code to i2c connected Rohm/Kionix sensors. Maybe could be used later also for abstracting Arduino/mbed os. Code ported from 'C'-library rohm-sensor-hal.

Dependents:   kionix-kx123-hello rohm-bh1790glc-hello simple-sensor-client rohm-SensorShield-example

Fork of rohm-sensor-hal by Rohm

Files at this revision

API Documentation at this revision

Comitter:
MikkoZ
Date:
Tue Apr 12 04:57:59 2016 +0000
Parent:
0:38c206f19bb7
Child:
2:3bb8ae3a8dee
Commit message:
Added support for mbed OS

Added support for mbed OS.
Successfully compiled and tested program for frdm-k64f-gcc/bm1383.

Changed in this revision

module.json Show annotated file Show diff for this revision Revisions of this file
rohm-sensor-hal/rohm_hal.h Show annotated file Show diff for this revision Revisions of this file
source/I2CCommonMbedHardwareLib.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/module.json	Mon Apr 11 08:26:39 2016 +0000
+++ b/module.json	Tue Apr 12 04:57:59 2016 +0000
@@ -1,17 +1,18 @@
-{
-  "name": "rohm-sensor-hal",
-  "version": "0.0.0",
-  "description": "Rohm HAL for sensor driver development",
-  "keywords": [
-    "rohm",
-    "hal"
-  ],
-  "author": "Mikko Koivunen",
-  "repository": {
-    "url": "",
-    "type": "git"
-  },
-  "license": "Apache-2.0",
-  "dependencies": {}
-}
-
+{
+  "name": "rohm-sensor-hal",
+  "version": "0.1.0",
+  "license": "Apache-2.0",
+  "description": "Rohm HAL for sensor driver development",
+  "keywords": [
+    "rohm",
+    "hal"
+  ],
+  "author": "Mikko Koivunen",
+  "repository": {
+    "url": "https://developer.mbed.org/teams/Rohm/code/rohm-sensor-hal",
+    "type": "hg"
+  },
+  "dependencies": {
+    "mbed-drivers": "1.2.0"
+  }
+}
\ No newline at end of file
--- a/rohm-sensor-hal/rohm_hal.h	Mon Apr 11 08:26:39 2016 +0000
+++ b/rohm-sensor-hal/rohm_hal.h	Tue Apr 12 04:57:59 2016 +0000
@@ -17,16 +17,33 @@
 
 /* This file is meant for making same code work on many platforms easier. */
 #ifdef __MBED__
+    /* Mbed Classic */
     #include "mbed.h"               //types
+    #include "I2C.h"                //I2C
 
+    #ifndef uint8_t
+        #define uint8_t int
+    #endif
     #define USE_MBED_HARDWARE_I2C
     extern Serial pc;
     //Serial pc(USBTX, USBRX); done in main.cpp
     #define DEBUG_print(...)    pc.printf(__VA_ARGS__)
     #define DEBUG_printf(...)   pc.printf(__VA_ARGS__)
     #define DEBUG_println(...)  pc.printf(__VA_ARGS__);pc.printf("\r\n")
+#elif defined(YOTTA_MODULE_NAME)
+    /* Mbed OS */
+    #include "mbed-drivers/mbed.h"  //types, Serial, I2C -type, ...
+    #include "mbed-drivers/I2C.h"   //I2C
+
+    #define USE_MBED_HARDWARE_I2C
+    //get_stdio_serial().baud(115200); done in main.cpp
+
+    #define DEBUG_print(...)    printf(__VA_ARGS__)
+    #define DEBUG_printf(...)   printf(__VA_ARGS__)
+    #define DEBUG_println(...)  printf(__VA_ARGS__);printf("\r\n")
 
 #elif __ARDUINO__
+    /* Arduino */
     #include <arduino.h>            //types, Serial
 
     //#define USE_ARDUINO_SOFTWARE_I2C
@@ -38,6 +55,8 @@
     #define DEBUG_printf(a, b, c, ...)  Serial.print(a);Serial.print(b);Serial.print(c)
     #define DEBUG_print()           Serial.print()
     #define DEBUG_println()         Serial.println()
+#else
+    #error "rohm_hal.h: Not valid target."
 #endif
 
 #if 0       //Enable/disable debug prints
--- a/source/I2CCommonMbedHardwareLib.cpp	Mon Apr 11 08:26:39 2016 +0000
+++ b/source/I2CCommonMbedHardwareLib.cpp	Tue Apr 12 04:57:59 2016 +0000
@@ -12,10 +12,9 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-#include "../rohm-sensor-hal/rohm_hal.h"           //types, USE_MBED_HARDWARE_I2C, DEBUG_print*, I2C_SDA, I2C_SCL
+#include "../rohm-sensor-hal/rohm_hal.h"           //types, USE_MBED_HARDWARE_I2C, DEBUG_print*, I2C.h, I2C_SDA, I2C_SCL
 #ifdef USE_MBED_HARDWARE_I2C
 #include "../rohm-sensor-hal/I2CCommon.h"          //prototypes
-#include "I2C.h"                //I2C
 #define I2C_WRITE 0
 #define I2C_READ  1
 I2C i2c(I2C_SDA, I2C_SCL);
@@ -73,4 +72,4 @@
 
 #endif
 
-
+