Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)

Dependents:   DISCO-F746NG_USB_Host

Fork of KL46Z-USBHost by Norimasa Okamoto

Revision:
10:40c7f6788902
Parent:
9:7f9f64cf5ded
--- a/USBHost/mymap.h	Mon Feb 03 13:00:16 2014 +0000
+++ b/USBHost/mymap.h	Wed Feb 05 13:34:37 2014 +0000
@@ -3,51 +3,63 @@
 template<class K,class T>
 class mymap {
     struct mypair {
-        K key;
-        T value;
+        K first;
+        T second;
     };
 public:
     mymap() {
         m_size = 0;
-        m_limit = 4;
-        m_buf = new mypair[m_limit];
     }
-    void put(K key, T value) {
-        int i = find(key);
-        if (i == (-1)) {
-            if (m_size >= m_limit) {
-                int new_limit = m_limit + 4;
-                mypair* new_buf = new mypair[new_limit];
-                for(int i = 0; i < m_size; i++) {
-                    new_buf[i] = m_buf[i];
-                }
-                delete[] m_buf;
-                m_buf = new_buf;
-                m_limit = new_limit;
-            }
-            i = m_size++;
-            m_buf[i].key = key;
+    T& operator[](const K& key) {
+        int it;
+        if (count(key) == 0) {
+            it = insert(key, 0);
+        } else {
+            it = find(key);
         }
-        m_buf[i].value = value;
-    }
-    T get(K key) {
-        int i = find(key);
-        return (i == -1) ? NULL : m_buf[i].value;
+        return m_buf[it].second;
     }
     bool empty() { return m_size == 0 ? true : false; }
     int size() { return m_size; }
     void clear() { m_size = 0; }
+    int count(K key) {
+        for(int i = 0; i < m_size; i++) {
+            if (m_buf[i].first == key) {
+                return 1;
+            }
+        }
+        return 0;
+    }
 
 private:
     int find(K key) {
         for(int i = 0; i < m_size; i++) {
-            if (m_buf[i].key == key) {
+            if (m_buf[i].first == key) {
                 return i;
             }
         }
         return -1;
     }
-    int m_limit;
+    int insert(K key, T value) {
+        int it = find(key);
+        if (it != -1) {
+            m_buf[it].second = value;
+            return it;
+        }
+        mypair* new_buf = new mypair[m_size+1];
+        if (m_size > 0) {
+            for(int i = 0; i < m_size; i++) {
+                new_buf[i] = m_buf[i];
+            }
+            delete[] m_buf;
+        }
+        m_buf = new_buf;
+        it = m_size++;
+        m_buf[it].first = key;
+        m_buf[it].second = value;
+        return it;
+    }
+
     int m_size;
     mypair *m_buf;
 };