Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others

Revision:
2:cd263c5e86f2
Child:
3:99cb87ee1792
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nz32s.cpp	Sat Aug 29 13:54:00 2015 +1000
@@ -0,0 +1,82 @@
+/**
+ * File:      modtronix_nz32s.cpp
+ *
+ * Author:    Modtronix Engineering - www.modtronix.com
+ *
+ * Description:
+ *
+ * Software License Agreement:
+ * This software has been written or modified by Modtronix Engineering. The code
+ * may be modified and can be used free of charge for commercial and non commercial
+ * applications. If this is modified software, any license conditions from original
+ * software also apply. Any redistribution must include reference to 'Modtronix
+ * Engineering' and web link(www.modtronix.com) in the file header.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
+ * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ */
+#include "mbed.h"
+#include "nz32s.h"
+#include <stdarg.h>
+#include <stdio.h>
+
+
+// DEFINES ////////////////////////////////////////////////////////////////////
+
+
+// GLOBAL VARIABLES ///////////////////////////////////////////////////////////
+
+
+// Function Prototypes ////////////////////////////////////////////////////////
+
+
+// DEBUG ////////////////////////////////////////////////////////////////////
+//IMPORTANT, when enabling debugging, it is very important to note the following:
+//- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below!
+//- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handel debug output
+#define DEBUG_ENABLE            1
+#if (DEBUG_ENABLE==1) && !defined(NDEBUG)
+//Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging
+//    class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}};
+//    static modtronixDebugStream modtronixDebug;
+//    WEAK Stream* pMxDebug = &modtronixDebug;
+#if (MX_DEBUG_IS_POINTER==1)        //More efficient, but only works if pMxDebug is defined in code. Disabled by default!
+        WEAK Stream* pMxDebug = NULL;
+        #define MX_DEBUG  pMxDebug->printf
+    #else
+        WEAK void mxDebug(const char *format, ...) {}
+        #define MX_DEBUG mxDebug
+    #endif
+#else
+    //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
+    #define MX_DEBUG(format, args...) ((void)0)
+#endif
+
+
+
+/**
+ * Reset I2C bus
+ */
+void nz32s_resetI2C(uint8_t busNumber, PinName sda, PinName scl) {
+#if defined(STM32) || defined(STM32L1)
+    i2c_t objI2C;
+
+    if (busNumber == 1) {
+        objI2C.i2c = I2C_1;
+    }
+    else if (busNumber == 2) {
+        objI2C.i2c = I2C_2;
+    }
+
+    objI2C.slave = 0;
+    i2c_init(&objI2C, sda, scl);
+    //i2c_reset(&objI2C);       //i2c_init() above calls i2c_reset()
+    //pc.printf("\r\nI2C1 Reset");
+
+    MX_DEBUG("\r\nI2C1 Reset");
+
+#endif
+}