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 Oct 23 16:21:01 2018 +0000
Revision:
63:7d1c08cdde5c
Parent:
31:f4b9b85c7b62
Child:
66:6281a40d73e6
Graphics bug fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 31:f4b9b85c7b62 1 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 2 /*!
Pokitto 31:f4b9b85c7b62 3 @file PokittoItoa.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) 2016, 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 "PokittoItoa.h"
Pokitto 31:f4b9b85c7b62 38 #include <string.h>
Pokitto 31:f4b9b85c7b62 39 #include <stdint.h>
Pokitto 31:f4b9b85c7b62 40
Pokitto 31:f4b9b85c7b62 41
Pokitto 31:f4b9b85c7b62 42 void pokItoa(uint16_t value, char *str, int base)
Pokitto 31:f4b9b85c7b62 43 {
Pokitto 31:f4b9b85c7b62 44 /** pokItoa: convert value n to characters
Pokitto 31:f4b9b85c7b62 45 * Needed to emulate AVR LibC non-standard functions, this is a very fast version of itoa
Pokitto 31:f4b9b85c7b62 46 *
Pokitto 31:f4b9b85c7b62 47 * @param value unsigned integer to be converted
Pokitto 31:f4b9b85c7b62 48 * @param *str pointer to string where function stores the result as characters
Pokitto 31:f4b9b85c7b62 49 * @param base (not implemented in this function, base is always 10)
Pokitto 31:f4b9b85c7b62 50 */
Pokitto 31:f4b9b85c7b62 51
Pokitto 31:f4b9b85c7b62 52 char *p = str;
Pokitto 31:f4b9b85c7b62 53 uint8_t v;
Pokitto 31:f4b9b85c7b62 54 if (value > 499)
Pokitto 31:f4b9b85c7b62 55 {
Pokitto 31:f4b9b85c7b62 56 if (value > 799)
Pokitto 31:f4b9b85c7b62 57 {
Pokitto 31:f4b9b85c7b62 58 if (value > 999)
Pokitto 31:f4b9b85c7b62 59 {
Pokitto 31:f4b9b85c7b62 60 // Treated as a special case as there
Pokitto 31:f4b9b85c7b62 61 // are only 24 values above 999
Pokitto 31:f4b9b85c7b62 62 *p++ = '1';
Pokitto 31:f4b9b85c7b62 63 *p++ = '0';
Pokitto 31:f4b9b85c7b62 64 uint8_t v = value - 1000;
Pokitto 31:f4b9b85c7b62 65
Pokitto 31:f4b9b85c7b62 66 if (v > 19) { *p++ = '2'; v -= 20; }
Pokitto 31:f4b9b85c7b62 67 else if (v > 9) { *p++ = '1'; v -= 10; }
Pokitto 31:f4b9b85c7b62 68 else { *p++ = '0'; }
Pokitto 31:f4b9b85c7b62 69
Pokitto 31:f4b9b85c7b62 70 *p++ = v + '0';
Pokitto 31:f4b9b85c7b62 71 *p = 0;
Pokitto 31:f4b9b85c7b62 72 return;
Pokitto 31:f4b9b85c7b62 73 }
Pokitto 31:f4b9b85c7b62 74
Pokitto 31:f4b9b85c7b62 75 if (value > 899) { *p++ = '9'; v = value - 900; }
Pokitto 31:f4b9b85c7b62 76 else { *p++ = '8'; v = value - 800; }
Pokitto 31:f4b9b85c7b62 77 }
Pokitto 31:f4b9b85c7b62 78 else
Pokitto 31:f4b9b85c7b62 79 {
Pokitto 31:f4b9b85c7b62 80 if (value > 699) { *p++ = '7'; v = value - 700; }
Pokitto 31:f4b9b85c7b62 81 else if (value > 599) { *p++ = '6'; v = value - 600; }
Pokitto 31:f4b9b85c7b62 82 else { *p++ = '5'; v = value - 500; }
Pokitto 31:f4b9b85c7b62 83 }
Pokitto 31:f4b9b85c7b62 84 }
Pokitto 31:f4b9b85c7b62 85 else
Pokitto 31:f4b9b85c7b62 86 {
Pokitto 31:f4b9b85c7b62 87 if (value > 299)
Pokitto 31:f4b9b85c7b62 88 {
Pokitto 31:f4b9b85c7b62 89 if (value > 399) { *p++ = '4'; v = value - 400; }
Pokitto 31:f4b9b85c7b62 90 else { *p++ = '3'; v = value - 300; }
Pokitto 31:f4b9b85c7b62 91 }
Pokitto 31:f4b9b85c7b62 92 else
Pokitto 31:f4b9b85c7b62 93 {
Pokitto 31:f4b9b85c7b62 94 if (value > 199) { *p++ = '2'; v = value - 200; }
Pokitto 31:f4b9b85c7b62 95 else if (value > 99) { *p++ = '1'; v = value - 100; }
Pokitto 31:f4b9b85c7b62 96 else { v = value; }
Pokitto 31:f4b9b85c7b62 97 }
Pokitto 31:f4b9b85c7b62 98 }
Pokitto 31:f4b9b85c7b62 99
Pokitto 31:f4b9b85c7b62 100 if (v > 49)
Pokitto 31:f4b9b85c7b62 101 {
Pokitto 31:f4b9b85c7b62 102 if (v > 69)
Pokitto 31:f4b9b85c7b62 103 {
Pokitto 31:f4b9b85c7b62 104 if (v > 89) { *p++ = '9'; v -= 90; }
Pokitto 31:f4b9b85c7b62 105 else if (v > 79) { *p++ = '8'; v -= 80; }
Pokitto 31:f4b9b85c7b62 106 else { *p++ = '7'; v -= 70; }
Pokitto 31:f4b9b85c7b62 107 }
Pokitto 31:f4b9b85c7b62 108 else
Pokitto 31:f4b9b85c7b62 109 {
Pokitto 31:f4b9b85c7b62 110 if (v > 59) { *p++ = '6'; v -= 60; }
Pokitto 31:f4b9b85c7b62 111 else { *p++ = '5'; v -= 50; }
Pokitto 31:f4b9b85c7b62 112 }
Pokitto 31:f4b9b85c7b62 113 }
Pokitto 31:f4b9b85c7b62 114 else
Pokitto 31:f4b9b85c7b62 115 {
Pokitto 31:f4b9b85c7b62 116 if (v > 19)
Pokitto 31:f4b9b85c7b62 117 {
Pokitto 31:f4b9b85c7b62 118 if (v > 39) { *p++ = '4'; v -= 40; }
Pokitto 31:f4b9b85c7b62 119 else if (v > 29) { *p++ = '3'; v -= 30; }
Pokitto 31:f4b9b85c7b62 120 else { *p++ = '2'; v -= 20; }
Pokitto 31:f4b9b85c7b62 121 }
Pokitto 31:f4b9b85c7b62 122 else
Pokitto 31:f4b9b85c7b62 123 {
Pokitto 31:f4b9b85c7b62 124 if (v > 9) { *p++ = '1'; v -= 10; }
Pokitto 31:f4b9b85c7b62 125 else if (p != str) { *p++ = '0'; }
Pokitto 31:f4b9b85c7b62 126 }
Pokitto 31:f4b9b85c7b62 127 }
Pokitto 31:f4b9b85c7b62 128
Pokitto 31:f4b9b85c7b62 129 *p++ = v + '0';
Pokitto 31:f4b9b85c7b62 130 *p = 0;
Pokitto 31:f4b9b85c7b62 131 }
Pokitto 31:f4b9b85c7b62 132
Pokitto 31:f4b9b85c7b62 133 void pokUtoa(uint16_t value, char *str, int base) {
Pokitto 31:f4b9b85c7b62 134 pokItoa(value,str,base);
Pokitto 31:f4b9b85c7b62 135 }
Pokitto 31:f4b9b85c7b62 136
Pokitto 31:f4b9b85c7b62 137 void pokLtoa(long value, char *str, int base) {
Pokitto 31:f4b9b85c7b62 138 pokItoa(value,str,base);
Pokitto 31:f4b9b85c7b62 139 }
Pokitto 31:f4b9b85c7b62 140
Pokitto 31:f4b9b85c7b62 141