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!
Committer:
Pokitto
Date:
Tue Jan 30 10:41:47 2018 +0000
Revision:
31:f4b9b85c7b62
Sound output improvements added:  louder, clearer, faster!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 31:f4b9b85c7b62 1 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 2 /*!
Pokitto 31:f4b9b85c7b62 3 @file PokittoClock.cpp
Pokitto 31:f4b9b85c7b62 4 @author Jonne Valola
Pokitto 31:f4b9b85c7b62 5
Pokitto 31:f4b9b85c7b62 6 @section LICENSE
Pokitto 31:f4b9b85c7b62 7
Pokitto 31:f4b9b85c7b62 8 Software License Agreement (BSD License)
Pokitto 31:f4b9b85c7b62 9
Pokitto 31:f4b9b85c7b62 10 Copyright (c) 2015, Jonne Valola
Pokitto 31:f4b9b85c7b62 11 All rights reserved.
Pokitto 31:f4b9b85c7b62 12
Pokitto 31:f4b9b85c7b62 13 Redistribution and use in source and binary forms, with or without
Pokitto 31:f4b9b85c7b62 14 modification, are permitted provided that the following conditions are met:
Pokitto 31:f4b9b85c7b62 15 1. Redistributions of source code must retain the above copyright
Pokitto 31:f4b9b85c7b62 16 notice, this list of conditions and the following disclaimer.
Pokitto 31:f4b9b85c7b62 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 31:f4b9b85c7b62 18 notice, this list of conditions and the following disclaimer in the
Pokitto 31:f4b9b85c7b62 19 documentation and/or other materials provided with the distribution.
Pokitto 31:f4b9b85c7b62 20 3. Neither the name of the copyright holders nor the
Pokitto 31:f4b9b85c7b62 21 names of its contributors may be used to endorse or promote products
Pokitto 31:f4b9b85c7b62 22 derived from this software without specific prior written permission.
Pokitto 31:f4b9b85c7b62 23
Pokitto 31:f4b9b85c7b62 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 31:f4b9b85c7b62 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 31:f4b9b85c7b62 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 31:f4b9b85c7b62 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 31:f4b9b85c7b62 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 31:f4b9b85c7b62 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 31:f4b9b85c7b62 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 31:f4b9b85c7b62 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 31:f4b9b85c7b62 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 31:f4b9b85c7b62 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 31:f4b9b85c7b62 34 */
Pokitto 31:f4b9b85c7b62 35 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 36
Pokitto 31:f4b9b85c7b62 37 #include "PokittoCore.h"
Pokitto 31:f4b9b85c7b62 38 #include "pinmap.h"
Pokitto 31:f4b9b85c7b62 39 #include "HWLCD.h"
Pokitto 31:f4b9b85c7b62 40 #include "Pokitto_settings.h"
Pokitto 31:f4b9b85c7b62 41 #include "wait_api.h"
Pokitto 31:f4b9b85c7b62 42
Pokitto 31:f4b9b85c7b62 43 uint32_t pt_count=0;
Pokitto 31:f4b9b85c7b62 44 uint32_t* ptimer;
Pokitto 31:f4b9b85c7b62 45
Pokitto 31:f4b9b85c7b62 46 extern "C" {
Pokitto 31:f4b9b85c7b62 47 void SysTick_Handler(void) {
Pokitto 31:f4b9b85c7b62 48 //interrupt happens when systick has counted down to zero
Pokitto 31:f4b9b85c7b62 49 #if PROJ_GAMEBOY > 0
Pokitto 31:f4b9b85c7b62 50 uint32_t a;
Pokitto 31:f4b9b85c7b62 51 a = *ptimer;
Pokitto 31:f4b9b85c7b62 52 *ptimer = a + 1;
Pokitto 31:f4b9b85c7b62 53 #endif
Pokitto 31:f4b9b85c7b62 54 pt_count+=10; // increment counter
Pokitto 31:f4b9b85c7b62 55 }}
Pokitto 31:f4b9b85c7b62 56
Pokitto 31:f4b9b85c7b62 57 using namespace Pokitto;
Pokitto 31:f4b9b85c7b62 58
Pokitto 31:f4b9b85c7b62 59 uint32_t Core::refreshtime;
Pokitto 31:f4b9b85c7b62 60
Pokitto 31:f4b9b85c7b62 61 void Core::initClock() {
Pokitto 31:f4b9b85c7b62 62 // to get 1000 interrupts per second the reload value should be 48000
Pokitto 31:f4b9b85c7b62 63 #if PROJ_GAMEBOY > 0
Pokitto 31:f4b9b85c7b62 64 ptimer = &pt_count;
Pokitto 31:f4b9b85c7b62 65 SysTick->LOAD = 480000-1;
Pokitto 31:f4b9b85c7b62 66 #else
Pokitto 31:f4b9b85c7b62 67 SysTick->LOAD = 480000-1;
Pokitto 31:f4b9b85c7b62 68 #endif
Pokitto 31:f4b9b85c7b62 69 SysTick->VAL = 0;
Pokitto 31:f4b9b85c7b62 70 SysTick->CTRL = 4 | 2 | 1; //CLKSOURCE=CPU clock | TICKINT | ENABLE
Pokitto 31:f4b9b85c7b62 71 pt_count = 0;
Pokitto 31:f4b9b85c7b62 72 }
Pokitto 31:f4b9b85c7b62 73
Pokitto 31:f4b9b85c7b62 74 uint32_t Core::getTime() {
Pokitto 31:f4b9b85c7b62 75 return pt_count;
Pokitto 31:f4b9b85c7b62 76 }
Pokitto 31:f4b9b85c7b62 77
Pokitto 31:f4b9b85c7b62 78 void Core::wait(uint16_t ms) {
Pokitto 31:f4b9b85c7b62 79 wait_ms(ms);
Pokitto 31:f4b9b85c7b62 80 }
Pokitto 31:f4b9b85c7b62 81
Pokitto 31:f4b9b85c7b62 82