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

Revision:
6:33d25ef353f6
Parent:
5:e1297df8ee0d
Child:
9:5000feb4b46f
--- a/mx_helpers.h	Sun Aug 30 11:59:06 2015 +1000
+++ b/mx_helpers.h	Mon Aug 31 10:29:58 2015 +1000
@@ -51,15 +51,15 @@
 } WORD_VAL;
 
 
-#define GET_U8_AT0(val)  MxHelpers::read_uint8_at_0(val)
-#define GET_U8_AT1(val)  MxHelpers::read_uint8_at_1(val)
-#define GET_U8_AT2(val)  MxHelpers::read_uint8_at_2(val)
-#define GET_U8_AT3(val)  MxHelpers::read_uint8_at_3(val)
+#define GET_U8_AT0(val)  MxHelpers::get_u8_at0(val)
+#define GET_U8_AT1(val)  MxHelpers::get_u8_at1(val)
+#define GET_U8_AT2(val)  MxHelpers::get_u8_at2(val)
+#define GET_U8_AT3(val)  MxHelpers::get_u8_at3(val)
 
-#define SET_U8_AT0(val)  MxHelpers::write_uint8_at_0(val)
-#define SET_U8_AT1(val)  MxHelpers::write_uint8_at_1(val)
-#define SET_U8_AT2(val)  MxHelpers::write_uint8_at_2(val)
-#define SET_U8_AT3(val)  MxHelpers::write_uint8_at_3(val)
+#define SET_U8_AT0(val)  MxHelpers::set_u8_at0(val)
+#define SET_U8_AT1(val)  MxHelpers::set_u8_at1(val)
+#define SET_U8_AT2(val)  MxHelpers::set_u8_at2(val)
+#define SET_U8_AT3(val)  MxHelpers::set_u8_at3(val)
 
 
 class MxHelpers {
@@ -67,7 +67,7 @@
     /** Get first(LSB) 8-bit byte(uint8_t) of given 16-bit Word
      * @return Returns the lower(LSB) byte of given value
      */
-    static inline uint8_t read_uint8_at_0(uint16_t val) {
+    static inline uint8_t get_u8_at0(uint16_t val) {
         return ((uint8_t)((val)&0xFF));
     }
 
@@ -75,7 +75,7 @@
     /** Get second(MSB) 8-bit byte(uint8_t) of given 16-bit Word.
      * @return Returns the upper(MSB) byte of given value
      */
-    static inline uint8_t read_uint8_at_1(uint16_t val) {
+    static inline uint8_t get_u8_at1(uint16_t val) {
         return ((uint8_t)(((val)>>8)&0xFF));
     }
 
@@ -83,7 +83,7 @@
     /** Get first(LSB) 8-bit byte(uint8_t) of given 32-bit Word
      * @return Returns the lower(LSB) byte of given value = byte at bit offset 0 to 7
      */
-    static inline uint8_t read_uint8_at_0(uint32_t val) {
+    static inline uint8_t get_u8_at0(uint32_t val) {
         return ((uint8_t)((val)&0xFF));
     }
 
@@ -91,7 +91,7 @@
     /** Get second 8-bit byte(uint8_t) of given 32-bit Word
      * @return Returns the second byte of given value = byte at bit offset 8 to 15
      */
-    static inline uint8_t read_uint8_at_1(uint32_t val) {
+    static inline uint8_t get_u8_at1(uint32_t val) {
         return ((uint8_t)(((val)>>8)&0xFF));
     }
 
@@ -99,7 +99,7 @@
     /** Get third 8-bit byte(uint8_t) of given 32-bit Word
      * @return Returns the third byte of given value = byte at bit offset 16 to 23
      */
-    static inline uint8_t read_uint8_at_2(uint32_t val) {
+    static inline uint8_t get_u8_at2(uint32_t val) {
         return ((uint8_t)(((val)>>16)&0xFF));
     }
 
@@ -107,7 +107,7 @@
     /** Get forth(MSB) 8-bit byte(uint8_t) of given 32-bit Word
      * @return Returns the MSB byte of given value = byte at bit offset 24 to 31
      */
-    static inline uint8_t read_uint8_at_3(uint32_t val) {
+    static inline uint8_t get_u8_at3(uint32_t val) {
         return ((uint8_t)(((val)>>24)&0xFF));
     }
 
@@ -116,7 +116,7 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_0(uint8_t src, uint16_t dest) {
+    static inline void set_u8_at0(uint8_t src, uint16_t dest) {
         ((uint8_t*)&dest)[0] = src;
     }
 
@@ -125,7 +125,7 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_1(uint8_t src, uint16_t dest) {
+    static inline void set_u8_at1(uint8_t src, uint16_t dest) {
         ((uint8_t*)&dest)[1] = src;
     }
 
@@ -134,7 +134,7 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_0(uint8_t src, uint32_t dest) {
+    static inline void set_u8_at0(uint8_t src, uint32_t dest) {
         ((uint8_t*)&dest)[0] = src;
     }
 
@@ -143,7 +143,7 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_1(uint8_t src, uint32_t dest) {
+    static inline void set_u8_at1(uint8_t src, uint32_t dest) {
         ((uint8_t*)&dest)[1] = src;
     }
 
@@ -152,7 +152,7 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_2(uint8_t src, uint32_t dest) {
+    static inline void set_u8_at2(uint8_t src, uint32_t dest) {
         ((uint8_t*)&dest)[2] = src;
     }
 
@@ -161,11 +161,19 @@
      * @param src Source 8-bit byte to write to destination
      * @param dest Destination
      */
-    static inline void write_uint8_at_3(uint8_t src, uint32_t dest) {
+    static inline void set_u8_at3(uint8_t src, uint32_t dest) {
         ((uint8_t*)&dest)[3] = src;
     }
 
 
+    /** Get the first fractional part of float. For example, will return 5 for 123.56
+     * @return Returns first fractional part of float. For example, will return 5 for 123.56
+     */
+    static inline uint8_t get_frac1(float val) {
+        return (uint8_t)(( val - ((float)((uint32_t)val)) )*10);
+    }
+
+
     /**
      * Converts a "2 character ASCII hex" string to a single packed byte.
      *