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!

Files at this revision

API Documentation at this revision

Comitter:
Pokitto
Date:
Wed Dec 25 22:14:28 2019 +0000
Parent:
69:f9f49ff29720
Parent:
68:61a4ccb0a4b6
Child:
71:531419862202
Commit message:
ARMCC v6 fixes

Changed in this revision

--- a/POKITTO_CORE/PokittoButtons.cpp	Wed Dec 25 22:12:01 2019 +0000
+++ b/POKITTO_CORE/PokittoButtons.cpp	Wed Dec 25 22:14:28 2019 +0000
@@ -56,6 +56,9 @@
     #if POK_USE_CONSOLE
     if (console.conscounter) return;
     #endif // POK_USE_CONSOLE
+    #ifdef PROJ_BUTTONS_POLLING_ONLY
+    pollButtons();
+    #endif
     #ifndef POK_SIM
         /** HARDWARE CODE **/
     for (uint8_t thisButton = 0; thisButton < NUM_BTN; thisButton++) {
@@ -199,7 +202,11 @@
     #ifdef POK_SIM
     return simulator.aBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_A];
+    #else
+    return Pokitto::Core::aBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -208,7 +215,11 @@
     #ifdef POK_SIM
     return simulator.bBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_B];
+    #else
+    return Pokitto::Core::bBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -217,7 +228,11 @@
     #ifdef POK_SIM
     c = simulator.cBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     c = Pokitto::heldStates[BTN_C];
+    #else
+    return Pokitto::Core::cBtn();
+    #endif
     #endif // POK_SIM
     return c;
 }
@@ -226,7 +241,11 @@
     #ifdef POK_SIM
     return simulator.leftBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_LEFT];
+    #else
+    return Pokitto::Core::leftBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -234,7 +253,11 @@
     #ifdef POK_SIM
     return simulator.rightBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_RIGHT];
+    #else
+    return Pokitto::Core::rightBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -242,7 +265,11 @@
     #ifdef POK_SIM
     return simulator.upBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_UP];
+    #else
+    return Pokitto::Core::upBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -250,7 +277,11 @@
     #ifdef POK_SIM
     return simulator.downBtn();
     #else
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_DOWN];
+    #else
+    return Pokitto::Core::downBtn();
+    #endif
     #endif // POK_SIM
 }
 
@@ -262,4 +293,3 @@
 
 
 //** EOF **//
-
--- a/POKITTO_CORE/PokittoCore.cpp	Wed Dec 25 22:12:01 2019 +0000
+++ b/POKITTO_CORE/PokittoCore.cpp	Wed Dec 25 22:14:28 2019 +0000
@@ -908,6 +908,10 @@
         sound.updateStream();
     #endif
 
+	#ifdef PROJ_BUTTONS_POLLING_ONLY 
+		buttons.pollButtons();
+	#endif
+
     uint32_t now = getTime();
 	if ((((nextFrameMillis - now)) > timePerFrame) && frameEndMicros) { //if time to render a new frame is reached and the frame end has ran once
 		nextFrameMillis = now + timePerFrame;
--- a/POKITTO_HW/HWButtons.cpp	Wed Dec 25 22:12:01 2019 +0000
+++ b/POKITTO_HW/HWButtons.cpp	Wed Dec 25 22:14:28 2019 +0000
@@ -44,6 +44,7 @@
 
 using namespace mbed;
 
+#ifndef PROJ_BUTTONS_POLLING_ONLY
 InterruptIn ABtn(POK_BTN_A_PIN);
 InterruptIn BBtn(POK_BTN_B_PIN);
 InterruptIn CBtn(POK_BTN_C_PIN);
@@ -51,6 +52,16 @@
 InterruptIn DBtn(POK_BTN_DOWN_PIN);
 InterruptIn LBtn(POK_BTN_LEFT_PIN);
 InterruptIn RBtn(POK_BTN_RIGHT_PIN);
+#else
+DigitalIn ABtn(POK_BTN_A_PIN);
+DigitalIn BBtn(POK_BTN_B_PIN);
+DigitalIn CBtn(POK_BTN_C_PIN);
+DigitalIn UBtn(POK_BTN_UP_PIN);
+DigitalIn DBtn(POK_BTN_DOWN_PIN);
+DigitalIn LBtn(POK_BTN_LEFT_PIN);
+DigitalIn RBtn(POK_BTN_RIGHT_PIN);
+#endif
+
 
 #define BS_IDLE 0
 #define BS_DOWN 1
@@ -88,6 +99,7 @@
     }
 void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; }
 
+#ifndef PROJ_BUTTONS_POLLING_ONLY
 static inline void ClearPinInt(LPC_PIN_INT_T *pPININT, uint32_t pins)
 {
 	pPININT->IST = pins;
@@ -168,9 +180,12 @@
 
 	ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(6));
 }
+#endif
+
 
 
 void Pokitto::initButtons() {
+  #ifndef PROJ_BUTTONS_POLLING_ONLY
   ABtn.fall(&AReleased);
   ABtn.rise(&APressed);
   BBtn.fall(&BReleased);
@@ -192,31 +207,75 @@
   NVIC_SetVector((IRQn_Type)(PIN_INT4_IRQn), (uint32_t)&PIN_INT4_IRQHandler);
   NVIC_SetVector((IRQn_Type)(PIN_INT5_IRQn), (uint32_t)&PIN_INT5_IRQHandler);
   NVIC_SetVector((IRQn_Type)(PIN_INT6_IRQn), (uint32_t)&PIN_INT6_IRQHandler);
+  #endif
 }
 
 uint8_t Pokitto::Core::aBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_A];
+    #else
+    Pokitto::heldStates[BTN_A]=ABtn.read();
+    return Pokitto::heldStates[BTN_A];
+    #endif
+
 }
 
 uint8_t Pokitto::Core::bBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_B];
+    #else
+    Pokitto::heldStates[BTN_B]=BBtn.read();
+    return Pokitto::heldStates[BTN_B];
+    #endif
 }
 
 uint8_t Pokitto::Core::cBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_C];
+    #else
+    Pokitto::heldStates[BTN_C]=CBtn.read();
+    return Pokitto::heldStates[BTN_C];
+    #endif
 }
 
 uint8_t Pokitto::Core::upBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_UP];
+    #else
+    Pokitto::heldStates[BTN_UP]=UBtn.read();
+    return Pokitto::heldStates[BTN_UP];
+    #endif
 }
 uint8_t Pokitto::Core::downBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_DOWN];
+    #else
+    Pokitto::heldStates[BTN_DOWN]=DBtn.read();
+    return Pokitto::heldStates[BTN_DOWN];
+    #endif
 }
 
 uint8_t Pokitto::Core::leftBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_LEFT];
+    #else
+    Pokitto::heldStates[BTN_LEFT]=LBtn.read();
+    return Pokitto::heldStates[BTN_LEFT];
+    #endif
 }
 uint8_t Pokitto::Core::rightBtn() {
+
+    #ifndef PROJ_BUTTONS_POLLING_ONLY
     return Pokitto::heldStates[BTN_RIGHT];
+    #else
+    Pokitto::heldStates[BTN_RIGHT]=RBtn.read();
+    return Pokitto::heldStates[BTN_RIGHT];
+    #endif
 }
 
--- a/POKITTO_HW/HWSound.cpp	Wed Dec 25 22:12:01 2019 +0000
+++ b/POKITTO_HW/HWSound.cpp	Wed Dec 25 22:14:28 2019 +0000
@@ -50,15 +50,8 @@
 
 Pokitto::Sound __shw;
 
-#ifdef XPERIMENTAL
-DigitalOut e4(EXT4);
-e4=0;
-#endif
-
 using namespace Pokitto;
 
-
-
 #ifndef POK_SIM
 #if POK_ENABLE_SOUND
 pwmout_t* obj = &audiopwm;
@@ -67,7 +60,18 @@
 
 /** Sound Variables **/
 #if (POK_STREAMING_MUSIC > 0)
+
+#if POK_HIGH_RAM == HIGH_RAM_MUSIC
+unsigned char *buffers[4] = {
+    (unsigned char *) 0x20000000,
+    (unsigned char *) 0x20000400,
+    (unsigned char *) 0x20004000,
+    (unsigned char *) 0x20004400
+};
+#else
     unsigned char buffers[4][BUFFER_SIZE];
+#endif
+
     volatile int currentBuffer = 0, oldBuffer = 0;
     volatile int bufindex = 0, vol=1;
     volatile unsigned char * currentPtr;
@@ -256,15 +260,24 @@
     #endif
 }
 
+void Pokitto::soundInit() {
+    soundInit(false);
+}
+
 /** SOUND INIT **/
-void Pokitto::soundInit() {
+void Pokitto::soundInit(uint8_t reinit) {
+    #ifdef XPERIMENTAL
+    mbed::DigitalOut expr4(EXT4);
+    expr4=0;
+    #endif
     #if POK_ENABLE_SOUND > 0
     uint32_t timerFreq;
     #if POK_USE_PWM
-
+    if (!reinit) {
     pwmout_init(&audiopwm,POK_AUD_PIN);
     pwmout_period_us(&audiopwm,POK_AUD_PWM_US); //was 31us
     pwmout_write(&audiopwm,0.1f);
+    }
     #endif
 
     //#if POK_GBSOUND > 0
@@ -385,10 +398,23 @@
         #else
         streamstep = 1;
         #endif // POK_STREAMFREQ_HALVE
+        #ifndef PROJ_SDFS_STREAMING
+        	streamon=1; // force enable stream
+        #endif
         streamstep &= streamon; // streamon is used to toggle SD music streaming on and off
         if (streamstep) {
             output = (*currentPtr++);
-            if(streamvol && streamon) {
+	    if( Pokitto::Sound::sfxDataPtr != Pokitto::Sound::sfxEndPtr ){
+			#ifdef PROJ_SDFS_STREAMING
+				int32_t s = (int32_t(output) + int32_t(*Pokitto::Sound::sfxDataPtr++)) - 128;
+			#else
+				int32_t s = (127 + int32_t(*Pokitto::Sound::sfxDataPtr++)) - 128;
+			#endif
+			if( s < 0 ) s = 0;
+			else if( s > 255 ) s = 255;
+			output = s;
+	    	}
+    	if(streamvol && streamon) {
                 output >>= 3-streamvol;
                 streambyte = output;
             } else {
@@ -414,10 +440,18 @@
                 updatePlayback();
         }
         /** oscillators update **/
-        osc1.count += osc1.cinc + (osc1.pitchbend >> 4); // counts to 65535 and overflows to zero WAS 8 !
-        osc2.count += osc2.cinc + (osc2.pitchbend >> 4); // counts to 65535 and overflows to zero
-        osc3.count += osc3.cinc + (osc3.pitchbend >> 4); // counts to 65535 and overflows to zero
+        osc1.count += osc1.cinc + (osc1.pitchbend); // counts to 65535 and overflows to zero WAS 8 !
+        osc2.count += osc2.cinc + (osc2.pitchbend); // counts to 65535 and overflows to zero
+        osc3.count += osc3.cinc + (osc3.pitchbend); // counts to 65535 and overflows to zero
+        #if POK_ALT_MIXING > 0 // heaviest cpu load, recalculate envelopes on each cycle
+        uint32_t o = 0;
+        Marr[3]();
+        Marr[2]();
+        Marr[1]();
+        if (tick==0) Marr[0]();
+        #else
         Marr[tick](); // call mixing function
+        #endif // ALT_MIXING
         --tick;
 
         /** mixing oscillator output **/
--- a/POKITTO_HW/HWSound.h	Wed Dec 25 22:12:01 2019 +0000
+++ b/POKITTO_HW/HWSound.h	Wed Dec 25 22:14:28 2019 +0000
@@ -40,9 +40,13 @@
 #include "Pokitto_settings.h"
 
 #define SPEAKER 3
-#define BUFFER_SIZE 512*4 //*8 //*8 // 512 // was 512 (works really well with crabator) was 256
-
-#define SBUFSIZE 512*4
+#if POK_HIGH_RAM == HIGH_RAM_MUSIC
+	#define BUFFER_SIZE 256*4
+	#define SBUFSIZE 256*4
+#else
+	#define BUFFER_SIZE 512*4 //*8 //*8 // 512 // was 512 (works really well with crabator) was 256
+	#define SBUFSIZE 512*4
+#endif
 
 #if POK_BOARDREV == 1
  /** 2-layer board rev 1.3 **/
@@ -121,8 +125,8 @@
 extern uint8_t streambyte, streamon, HWvolume;
 
 extern float pwm2; //virtual pwm output
-
 extern void soundInit();
+extern void soundInit(uint8_t);
 extern void dac_write(uint8_t value);
 extern uint8_t ampIsOn();
 extern void ampEnable(uint8_t v);
@@ -149,7 +153,11 @@
 extern void pokSoundBufferedIRQ();
 
 #if POK_STREAMING_MUSIC > 0
+#if POK_HIGH_RAM == HIGH_RAM_MUSIC
+    extern unsigned char *buffers[];
+#else
     extern unsigned char buffers[][BUFFER_SIZE];
+#endif
     extern volatile int currentBuffer, oldBuffer;
     extern volatile int bufindex, vol;
     extern volatile unsigned char * currentPtr;