PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Revision:
66:6281a40d73e6
Parent:
58:5f58a2846a20
--- a/POKITTO_CORE/PokittoCookie.cpp	Sat Mar 23 19:22:35 2019 +0000
+++ b/POKITTO_CORE/PokittoCookie.cpp	Sat Mar 23 20:03:34 2019 +0000
@@ -117,13 +117,15 @@
 }
 
 bool Cookie::saveCookie() {
-    if (!_status || !_pointer) initialize(); //reinitialize if needed
-    if (!_status || !_pointer) return false; //return if initialize still failed
+    if (!_status || !_pointer) return false; //return if not initialized
     char* p = _pointer;
     _head=0;
     _block=0;
     _block=findMyNextBlock();
     for (int i=0; i<_datasize; i++) writeQueue(*p++);
+    #if POK_ENABLE_SOUND
+    Pokitto::soundInit(true); //re-init sound
+    #endif
     return true;
 }
 
@@ -151,7 +153,7 @@
 
 int Cookie::exists(const char* idkey) {
     for (int i=0; i< SBMAXKEYS; i++) {
-        #ifndef POK_SIM
+
             if(eeprom_read_byte((uint16_t*)(i*SBKEYSIZE))==idkey[0]) {
                     int total=0;
                     for (int j=0; j<SBKEYSIZE;j++) {
@@ -159,7 +161,7 @@
                     }
                     if (total==SBKEYSIZE) return i; // return the keyslot number where key exists
             }
-        #endif
+
     }
     return SBINVALIDSLOT; //not found
 }
@@ -167,9 +169,9 @@
 int Cookie::getFreeKeytableSlot() {
     int freeslot=SBINVALIDSLOT;
     for (int i=0; i<SBMAXKEYS; i++) {
-    #ifndef POK_SIM
+
     if (eeprom_read_byte((uint16_t*)(i*SBKEYSIZE))==0) {freeslot=i; break;}
-    #endif
+
     }
     return freeslot;
 }
@@ -192,21 +194,21 @@
 
 bool Cookie::isFreeBlock(int n) {
     if (n>=SBMAXBLOCKS) return false;
-    #ifndef POK_SIM
+
     if (!(eeprom_read_byte((uint16_t*)(SBMAXKEYS*SBKEYSIZE+n))&0x80)) return true; //highest bit 0, its free
-    #endif
+
     return false; //its not free
 }
 
 bool Cookie::isMyBlock(int n) {
     if (n>=SBMAXBLOCKS) return false;
     if (isFreeBlock(n)) return false; //"free" blocks can not be "reserved" at the same time!
-    #ifndef POK_SIM
+
     char temp; int address;
     address = (SBMAXKEYS*SBKEYSIZE+n);
     temp = eeprom_read_byte((uint16_t*)address);
     if ((temp&0x7F) ==_keyorder) return true;
-    #endif
+
     return false; //its not your block
 }
 
@@ -214,21 +216,21 @@
     if (n>=SBMAXBLOCKS) return false;
     if (k>=SBMAXKEYS) return false;
     if (isFreeBlock(n)) return false; //"free" blocks can not be "owned" by anyone
-    #ifndef POK_SIM
+
     char temp; int address;
     address = (SBMAXKEYS*SBKEYSIZE+n);
     temp = eeprom_read_byte((uint16_t*)address);
     if ((temp&0x7F) == k) return true;
-    #endif
+
     return false; //its not your block
 }
 
 void Cookie::writeKeyToKeytable(const char* key, int slot) {
     for (int i=0; i<SBKEYSIZE; i++) {
-    #ifndef POK_SIM
+
     if (key[i]) eeprom_write_byte((uint16_t*)(slot*SBKEYSIZE+i),key[i]);
     else eeprom_write_byte((uint16_t*)(slot*SBKEYSIZE+i),0);
-    #endif
+
     }
 }
 
@@ -236,63 +238,63 @@
     answer[8]=0;
     if (n >= SBMAXKEYS) n=SBMAXKEYS-1;
     for (int i=0; i<SBKEYSIZE; i++) {
-        #ifndef POK_SIM
+
         answer[i] = eeprom_read_byte((uint16_t*)(n*SBKEYSIZE+i));
-        #endif
+
     }
 }
 
 char Cookie::getBlockTableEntry(int n) {
     if (n>=SBMAXBLOCKS) return 0x80; // out of bounds will return a reserved block marker
-    #ifndef POK_SIM
+
         return eeprom_read_byte((uint16_t*)(SBKEYSIZE*SBMAXKEYS+n));
-    #endif
-    //return 0x80;
+
+    return 0x80;
 }
 
 void Cookie::readBlock(int n, char* data) {
     for (int i=0; i<SBBLOCKSIZE; i++) {
     data[i]=0;
-    #ifndef POK_SIM
+
         if (n < SBMAXBLOCKS) data[i] = eeprom_read_byte((uint16_t*)(SBKEYSIZE*SBMAXKEYS+SBMAXBLOCKS+n*SBBLOCKSIZE+i));
-    #endif
+
     }
 }
 
 void Cookie::formatKeytable() {
     for (int j=0; j<SBMAXKEYS; j++) {
     for (int i=0; i<SBKEYSIZE; i++) {
-        #ifndef POK_SIM
+
         eeprom_write_byte((uint16_t*)(j*SBKEYSIZE+i),0);
-        #endif
+
     }
     }
 }
 
 void Cookie::freeBlock(int n) {
     if (n >= SBMAXBLOCKS) return; //out of bounds
-    #ifndef POK_SIM
+
         // delete entry from blocktable
         eeprom_write_byte((uint16_t*)(SBKEYSIZE*SBMAXKEYS+n),0);
-    #endif
+
     for (int i=0; i<SBBLOCKSIZE;i++) {
-    #ifndef POK_SIM
+
         // wipe data in the block
         eeprom_write_byte((uint16_t*)(SBKEYSIZE*SBMAXKEYS+SBMAXBLOCKS+n*SBBLOCKSIZE+i),0);
-    #endif
+
     }
 }
 
 bool Cookie::reserveBlock() {
     for (int i=0; i<SBMAXBLOCKS;i++) {
-    #ifndef POK_SIM
+
         // reserve block from blocktable
         if (isFreeBlock(i)) {
                 //free block found, mark it for us in the blocktable
                 eeprom_write_byte((uint16_t*)(SBKEYSIZE*SBMAXKEYS+i),_keyorder | 0x80);
                 return true;
         }
-    #endif
+
     }
     return false; // no free block found
 }
@@ -300,9 +302,9 @@
 void Cookie::eraseKeytableEntry(int n) {
     if (n >= SBMAXKEYS) n=SBMAXKEYS-1;
     for (int i=0; i<SBKEYSIZE; i++) {
-        #ifndef POK_SIM
+
         eeprom_write_byte((uint16_t*)(n*SBKEYSIZE+i),0);
-        #endif
+
     }
 }
 
@@ -331,11 +333,11 @@
 
 char Cookie::readQueue() {
     char data=0;
-    #ifndef POK_SIM
+
     int address;
     address = SBMAXKEYS*SBKEYSIZE+SBMAXBLOCKS+SBBLOCKSIZE*_block+_head%SBBLOCKSIZE;
     data=eeprom_read_byte((uint16_t*)address);
-    #endif
+
     _head++;
     if (_head%SBBLOCKSIZE==0 && _head) {
             _block++;
@@ -345,9 +347,9 @@
 }
 
 void Cookie::writeQueue(char data) {
-    #ifndef POK_SIM
+
     eeprom_write_byte((uint16_t*)(SBMAXKEYS*SBKEYSIZE+SBMAXBLOCKS+SBBLOCKSIZE*_block+_head%SBBLOCKSIZE),data);
-    #endif
+
     _head++;
     if (_head%SBBLOCKSIZE==0 && _head) {
             _block++;