From 21ecbd90ebe2a4b6ff68bb12b5439ffc9435997a Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Thu, 6 Apr 2017 16:18:53 -0700 Subject: [PATCH] ANDROID: Treat utilities as its own library Since src/utilities now builds a C/C++ library, other targets which were using symbols from utilities now need to include the correct target dependency. This is mainly for upm_delay* functions. Added utilities-c target to all sensor library CMakeLists.txt which require it. Moved macro for __FILENAME__ from upm_utilities.h to upm_fti.h since ONLY the FTI headers used this. Signed-off-by: Noel Eck --- examples/c++/buzzer.cxx | 1 + examples/c++/lcm1602-i2c.cxx | 9 +++++---- examples/c++/lcm1602-parallel.cxx | 5 +++-- examples/c++/max30100.cxx | 1 + examples/c/lcm1602-i2c.c | 1 + examples/c/lcm1602-parallel.c | 1 + include/upm.h | 1 - include/upm_fti.h | 3 +++ src/apa102/CMakeLists.txt | 2 +- src/apa102/apa102.c | 1 + src/bh1750/bh1750.c | 1 + src/enc03r/enc03r.c | 1 + src/ims/ims.c | 1 + src/m24lr64e/m24lr64e.c | 1 + src/max30100/max30100.c | 1 + src/mq303a/mq303a.c | 1 + src/nunchuck/nunchuck.c | 1 + src/p9813/CMakeLists.txt | 2 +- src/p9813/p9813.c | 5 +++-- src/rsc/rsc.c | 1 + src/servo/es08a.c | 1 + src/servo/es9257.c | 1 + src/tsl2561/tsl2561.c | 1 + src/utilities/upm_utilities.c | 4 ++-- src/utilities/upm_utilities.h | 4 ---- 25 files changed, 34 insertions(+), 17 deletions(-) diff --git a/examples/c++/buzzer.cxx b/examples/c++/buzzer.cxx index 8b127413..411af0f7 100644 --- a/examples/c++/buzzer.cxx +++ b/examples/c++/buzzer.cxx @@ -26,6 +26,7 @@ #include #include #include "buzzer.hpp" +#include "upm_utilities.h" int diff --git a/examples/c++/lcm1602-i2c.cxx b/examples/c++/lcm1602-i2c.cxx index 66ae8f28..e8b9c09d 100644 --- a/examples/c++/lcm1602-i2c.cxx +++ b/examples/c++/lcm1602-i2c.cxx @@ -23,6 +23,7 @@ */ #include "lcm1602.hpp" +#include "upm_utilities.h" int main(int argc, char **argv) @@ -32,16 +33,16 @@ main(int argc, char **argv) lcd->setCursor(0,0); lcd->write("Hello World"); //! [Interesting] - sleep(3); + upm_delay(3); lcd->setCursor(1,2); lcd->write("Hello World"); - sleep(3); + upm_delay(3); lcd->setCursor(2,4); lcd->write("Hello World"); - sleep(3); + upm_delay(3); lcd->setCursor(3,6); lcd->write("Hello World"); - sleep(3); + upm_delay(3); delete lcd; return 0; diff --git a/examples/c++/lcm1602-parallel.cxx b/examples/c++/lcm1602-parallel.cxx index d85ab06f..39754d30 100644 --- a/examples/c++/lcm1602-parallel.cxx +++ b/examples/c++/lcm1602-parallel.cxx @@ -23,7 +23,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include "lcm1602.hpp" +#include "upm_utilities.h" int main(int argc, char **argv) @@ -47,7 +48,7 @@ main(int argc, char **argv) lcd->write("Hello World"); printf("Sleeping for 5 seconds\n"); - sleep(5); + upm_delay(5); delete lcd; //! [Interesting] return 0; diff --git a/examples/c++/max30100.cxx b/examples/c++/max30100.cxx index 42760349..5ed691a5 100644 --- a/examples/c++/max30100.cxx +++ b/examples/c++/max30100.cxx @@ -27,6 +27,7 @@ #include #include "max30100.hpp" +#include "upm_utilities.h" using namespace upm; diff --git a/examples/c/lcm1602-i2c.c b/examples/c/lcm1602-i2c.c index 7951fe6b..5c16d30c 100644 --- a/examples/c/lcm1602-i2c.c +++ b/examples/c/lcm1602-i2c.c @@ -23,6 +23,7 @@ */ #include "lcm1602.h" +#include "upm_utilities.h" int main(int argc, char **argv) { diff --git a/examples/c/lcm1602-parallel.c b/examples/c/lcm1602-parallel.c index 290ac3dc..5b58474e 100644 --- a/examples/c/lcm1602-parallel.c +++ b/examples/c/lcm1602-parallel.c @@ -23,6 +23,7 @@ */ #include "lcm1602.h" +#include "upm_utilities.h" int main(int argc, char **argv) { diff --git a/include/upm.h b/include/upm.h index f5f49c5b..dfe87e4f 100644 --- a/include/upm.h +++ b/include/upm.h @@ -34,7 +34,6 @@ extern "C" { #include #include -#include #define upm_perror(...) perror(args, __VA_ARGS__) diff --git a/include/upm_fti.h b/include/upm_fti.h index 0d907d9a..a6b3fa03 100644 --- a/include/upm_fti.h +++ b/include/upm_fti.h @@ -32,6 +32,9 @@ extern "C" { #endif +/* Get filename w/o path */ +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + /** * The UPM Function Table Interface (FTI) */ diff --git a/src/apa102/CMakeLists.txt b/src/apa102/CMakeLists.txt index eb0726d3..54731a62 100644 --- a/src/apa102/CMakeLists.txt +++ b/src/apa102/CMakeLists.txt @@ -5,4 +5,4 @@ upm_mixed_module_init (NAME apa102 CPP_HDR apa102.hpp CPP_SRC apa102.cxx FTI_SRC apa102_fti.c - REQUIRES mraa) + REQUIRES mraa utilities-c) diff --git a/src/apa102/apa102.c b/src/apa102/apa102.c index 4366dbd7..3443cb1a 100644 --- a/src/apa102/apa102.c +++ b/src/apa102/apa102.c @@ -26,6 +26,7 @@ #include #include "apa102.h" +#include "upm_utilities.h" apa102_context apa102_init(int ledcount, int bus, int cs) { diff --git a/src/bh1750/bh1750.c b/src/bh1750/bh1750.c index 5e1d0a6b..a539076a 100644 --- a/src/bh1750/bh1750.c +++ b/src/bh1750/bh1750.c @@ -26,6 +26,7 @@ #include #include "bh1750.h" +#include "upm_utilities.h" bh1750_context bh1750_init(int bus, uint8_t addr, BH1750_OPMODES_T mode) { diff --git a/src/enc03r/enc03r.c b/src/enc03r/enc03r.c index e49dd621..b01a11a0 100644 --- a/src/enc03r/enc03r.c +++ b/src/enc03r/enc03r.c @@ -27,6 +27,7 @@ #include #include "enc03r.h" +#include "upm_utilities.h" enc03r_context enc03r_init(int pin, float aref) { diff --git a/src/ims/ims.c b/src/ims/ims.c index 0096a940..9eecf75a 100644 --- a/src/ims/ims.c +++ b/src/ims/ims.c @@ -26,6 +26,7 @@ #include #include "ims.h" +#include "upm_utilities.h" ims_context* ims_init(int16_t i2c_bus, int16_t i2c_address) { diff --git a/src/m24lr64e/m24lr64e.c b/src/m24lr64e/m24lr64e.c index f464e8a0..3f5d8f6f 100644 --- a/src/m24lr64e/m24lr64e.c +++ b/src/m24lr64e/m24lr64e.c @@ -33,6 +33,7 @@ */ #include "m24lr64e.h" +#include "upm_utilities.h" // forward declarations - these were protected methods in original C++ // code. Might need to expose them? diff --git a/src/max30100/max30100.c b/src/max30100/max30100.c index 5f857949..c9d1f24b 100644 --- a/src/max30100/max30100.c +++ b/src/max30100/max30100.c @@ -28,6 +28,7 @@ #include #include "max30100.h" +#include "upm_utilities.h" max30100_context* max30100_init(int16_t i2c_bus) { diff --git a/src/mq303a/mq303a.c b/src/mq303a/mq303a.c index 604b1cda..f75cfee1 100644 --- a/src/mq303a/mq303a.c +++ b/src/mq303a/mq303a.c @@ -24,6 +24,7 @@ */ #include "mq303a.h" +#include mq303a_context mq303a_init(int pin, int heater_pin) { // make sure MRAA is initialized diff --git a/src/nunchuck/nunchuck.c b/src/nunchuck/nunchuck.c index e8a916cd..0b823299 100644 --- a/src/nunchuck/nunchuck.c +++ b/src/nunchuck/nunchuck.c @@ -28,6 +28,7 @@ #include #include "nunchuck.h" +#include "upm_utilities.h" // This is not changeable #define NUNCHUCK_I2C_ADDR 0x52 diff --git a/src/p9813/CMakeLists.txt b/src/p9813/CMakeLists.txt index 0212e2ab..f8b69f3a 100644 --- a/src/p9813/CMakeLists.txt +++ b/src/p9813/CMakeLists.txt @@ -4,4 +4,4 @@ upm_mixed_module_init (NAME p9813 C_SRC p9813.c CPP_HDR p9813.hpp CPP_SRC p9813.cxx - REQUIRES mraa) + REQUIRES mraa utilities-c) diff --git a/src/p9813/p9813.c b/src/p9813/p9813.c index cc7af954..caaeda3a 100644 --- a/src/p9813/p9813.c +++ b/src/p9813/p9813.c @@ -26,6 +26,7 @@ #include #include "p9813.h" +#include "upm_utilities.h" p9813_context p9813_init(int ledcount, int clk, int data) { @@ -100,9 +101,9 @@ upm_result_t p9813_send_byte(p9813_context dev, uint8_t data) mraa_gpio_write(dev->data, (data & 0x80) >> 7); // Pulse the clock mraa_gpio_write(dev->clk, 1); - usleep(20); + upm_delay_us(20); mraa_gpio_write(dev->clk, 0); - usleep(20); + upm_delay_us(20); // Shift to the next data bit data <<= 1; diff --git a/src/rsc/rsc.c b/src/rsc/rsc.c index f94b36d4..5f4fc9b2 100644 --- a/src/rsc/rsc.c +++ b/src/rsc/rsc.c @@ -22,6 +22,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "rsc.h" +#include "upm_utilities.h" upm_result_t rsc_eeprom_read(rsc_context dev, uint16_t address, uint8_t* buf, int len, uint8_t arglen); diff --git a/src/servo/es08a.c b/src/servo/es08a.c index f62fbdca..bf055fc6 100644 --- a/src/servo/es08a.c +++ b/src/servo/es08a.c @@ -23,6 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "es08a.h" +#include "upm_utilities.h" es08a_context es08a_init(int32_t pin, int32_t min_pulse_width, int32_t max_pulse_width) { diff --git a/src/servo/es9257.c b/src/servo/es9257.c index ca59c3be..4ba2bc7e 100644 --- a/src/servo/es9257.c +++ b/src/servo/es9257.c @@ -23,6 +23,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "es9257.h" +#include "upm_utilities.h" es9257_context es9257_init(int32_t pin, int32_t min_pulse_width, int32_t max_pulse_width) { diff --git a/src/tsl2561/tsl2561.c b/src/tsl2561/tsl2561.c index 700e53fd..700f297f 100644 --- a/src/tsl2561/tsl2561.c +++ b/src/tsl2561/tsl2561.c @@ -28,6 +28,7 @@ */ #include "tsl2561.h" +#include "upm_utilities.h" // forward declaration upm_result_t tsl2561_compute_lux(const tsl2561_context dev, int *int_data); diff --git a/src/utilities/upm_utilities.c b/src/utilities/upm_utilities.c index 952394ef..dbe5355b 100644 --- a/src/utilities/upm_utilities.c +++ b/src/utilities/upm_utilities.c @@ -31,8 +31,8 @@ #endif #include #include -#include -#include +#include "upm_platform.h" +#include "upm_utilities.h" // https://airnow.gov/index.cfm?action=aqibasics.aqi static struct aqi { diff --git a/src/utilities/upm_utilities.h b/src/utilities/upm_utilities.h index 3bb39bd4..eefc5827 100644 --- a/src/utilities/upm_utilities.h +++ b/src/utilities/upm_utilities.h @@ -62,10 +62,6 @@ typedef uint32_t upm_clock_t; #endif /* UPM_PLATFORM_ZEPHYR */ - -/* Get filename w/o path */ -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - /** * Delay for a number of seconds *