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-sensor-hal/rohm_hal.h@7:f83fa2f3cfab, 2016-04-12 (annotated)
- Committer:
- MikkoZ
- Date:
- Tue Apr 12 12:55:24 2016 +0000
- Revision:
- 7:f83fa2f3cfab
- Parent:
- 1:4d6dc19a2347
Extra uint8_t definition removed; ; uint8_t definition in rohm_hal.h removed; .hgignore autoupdated by mbed classic ui;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MikkoZ | 0:38c206f19bb7 | 1 | /* Copyright 2016 Rohm Semiconductor |
| MikkoZ | 0:38c206f19bb7 | 2 | |
| MikkoZ | 0:38c206f19bb7 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| MikkoZ | 0:38c206f19bb7 | 4 | you may not use this file except in compliance with the License. |
| MikkoZ | 0:38c206f19bb7 | 5 | You may obtain a copy of the License at |
| MikkoZ | 0:38c206f19bb7 | 6 | |
| MikkoZ | 0:38c206f19bb7 | 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| MikkoZ | 0:38c206f19bb7 | 8 | |
| MikkoZ | 0:38c206f19bb7 | 9 | Unless required by applicable law or agreed to in writing, software |
| MikkoZ | 0:38c206f19bb7 | 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| MikkoZ | 0:38c206f19bb7 | 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| MikkoZ | 0:38c206f19bb7 | 12 | See the License for the specific language governing permissions and |
| MikkoZ | 0:38c206f19bb7 | 13 | limitations under the License. |
| MikkoZ | 0:38c206f19bb7 | 14 | */ |
| MikkoZ | 0:38c206f19bb7 | 15 | #ifndef ROHM_HAL_H |
| MikkoZ | 0:38c206f19bb7 | 16 | #define ROHM_HAL_H |
| MikkoZ | 0:38c206f19bb7 | 17 | |
| MikkoZ | 0:38c206f19bb7 | 18 | /* This file is meant for making same code work on many platforms easier. */ |
| MikkoZ | 0:38c206f19bb7 | 19 | #ifdef __MBED__ |
| MikkoZ | 1:4d6dc19a2347 | 20 | /* Mbed Classic */ |
| MikkoZ | 0:38c206f19bb7 | 21 | #include "mbed.h" //types |
| MikkoZ | 1:4d6dc19a2347 | 22 | #include "I2C.h" //I2C |
| MikkoZ | 0:38c206f19bb7 | 23 | |
| MikkoZ | 0:38c206f19bb7 | 24 | #define USE_MBED_HARDWARE_I2C |
| MikkoZ | 0:38c206f19bb7 | 25 | extern Serial pc; |
| MikkoZ | 0:38c206f19bb7 | 26 | //Serial pc(USBTX, USBRX); done in main.cpp |
| MikkoZ | 0:38c206f19bb7 | 27 | #define DEBUG_print(...) pc.printf(__VA_ARGS__) |
| MikkoZ | 0:38c206f19bb7 | 28 | #define DEBUG_printf(...) pc.printf(__VA_ARGS__) |
| MikkoZ | 0:38c206f19bb7 | 29 | #define DEBUG_println(...) pc.printf(__VA_ARGS__);pc.printf("\r\n") |
| MikkoZ | 1:4d6dc19a2347 | 30 | #elif defined(YOTTA_MODULE_NAME) |
| MikkoZ | 1:4d6dc19a2347 | 31 | /* Mbed OS */ |
| MikkoZ | 1:4d6dc19a2347 | 32 | #include "mbed-drivers/mbed.h" //types, Serial, I2C -type, ... |
| MikkoZ | 1:4d6dc19a2347 | 33 | #include "mbed-drivers/I2C.h" //I2C |
| MikkoZ | 1:4d6dc19a2347 | 34 | |
| MikkoZ | 1:4d6dc19a2347 | 35 | #define USE_MBED_HARDWARE_I2C |
| MikkoZ | 1:4d6dc19a2347 | 36 | //get_stdio_serial().baud(115200); done in main.cpp |
| MikkoZ | 1:4d6dc19a2347 | 37 | |
| MikkoZ | 1:4d6dc19a2347 | 38 | #define DEBUG_print(...) printf(__VA_ARGS__) |
| MikkoZ | 1:4d6dc19a2347 | 39 | #define DEBUG_printf(...) printf(__VA_ARGS__) |
| MikkoZ | 1:4d6dc19a2347 | 40 | #define DEBUG_println(...) printf(__VA_ARGS__);printf("\r\n") |
| MikkoZ | 0:38c206f19bb7 | 41 | |
| MikkoZ | 0:38c206f19bb7 | 42 | #elif __ARDUINO__ |
| MikkoZ | 1:4d6dc19a2347 | 43 | /* Arduino */ |
| MikkoZ | 0:38c206f19bb7 | 44 | #include <arduino.h> //types, Serial |
| MikkoZ | 0:38c206f19bb7 | 45 | |
| MikkoZ | 0:38c206f19bb7 | 46 | //#define USE_ARDUINO_SOFTWARE_I2C |
| MikkoZ | 0:38c206f19bb7 | 47 | #define USE_ARDUINO_HARDWARE_I2C |
| MikkoZ | 0:38c206f19bb7 | 48 | |
| MikkoZ | 0:38c206f19bb7 | 49 | #define DEBUG_printf(a) Serial.print(a) |
| MikkoZ | 0:38c206f19bb7 | 50 | #define DEBUG_printf(a, b) Serial.print(a);Serial.print(b) |
| MikkoZ | 0:38c206f19bb7 | 51 | #define DEBUG_printf(a, b, c) Serial.print(a);Serial.print(b);Serial.print(c) |
| MikkoZ | 0:38c206f19bb7 | 52 | #define DEBUG_printf(a, b, c, ...) Serial.print(a);Serial.print(b);Serial.print(c) |
| MikkoZ | 0:38c206f19bb7 | 53 | #define DEBUG_print() Serial.print() |
| MikkoZ | 0:38c206f19bb7 | 54 | #define DEBUG_println() Serial.println() |
| MikkoZ | 1:4d6dc19a2347 | 55 | #else |
| MikkoZ | 1:4d6dc19a2347 | 56 | #error "rohm_hal.h: Not valid target." |
| MikkoZ | 0:38c206f19bb7 | 57 | #endif |
| MikkoZ | 0:38c206f19bb7 | 58 | |
| MikkoZ | 0:38c206f19bb7 | 59 | #if 0 //Enable/disable debug prints |
| MikkoZ | 0:38c206f19bb7 | 60 | #define DEBUG_print() |
| MikkoZ | 0:38c206f19bb7 | 61 | #define DEBUG_printf() |
| MikkoZ | 0:38c206f19bb7 | 62 | #define DEBUG_println() |
| MikkoZ | 0:38c206f19bb7 | 63 | #endif |
| MikkoZ | 0:38c206f19bb7 | 64 | |
| MikkoZ | 0:38c206f19bb7 | 65 | #endif /* ROHM_HAL_H */ |
