PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
5:7e5c566b1760
fixed 4color refreshRegion code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:7e5c566b1760 1 /* mbed Microcontroller Library
Pokitto 5:7e5c566b1760 2 * Copyright (c) 2006-2013 ARM Limited
Pokitto 5:7e5c566b1760 3 *
Pokitto 5:7e5c566b1760 4 * Licensed under the Apache License, Version 2.0 (the "License");
Pokitto 5:7e5c566b1760 5 * you may not use this file except in compliance with the License.
Pokitto 5:7e5c566b1760 6 * You may obtain a copy of the License at
Pokitto 5:7e5c566b1760 7 *
Pokitto 5:7e5c566b1760 8 * http://www.apache.org/licenses/LICENSE-2.0
Pokitto 5:7e5c566b1760 9 *
Pokitto 5:7e5c566b1760 10 * Unless required by applicable law or agreed to in writing, software
Pokitto 5:7e5c566b1760 11 * distributed under the License is distributed on an "AS IS" BASIS,
Pokitto 5:7e5c566b1760 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pokitto 5:7e5c566b1760 13 * See the License for the specific language governing permissions and
Pokitto 5:7e5c566b1760 14 * limitations under the License.
Pokitto 5:7e5c566b1760 15 */
Pokitto 5:7e5c566b1760 16 #include "cmsis.h"
Pokitto 5:7e5c566b1760 17 #include "semihost_api.h"
Pokitto 5:7e5c566b1760 18
Pokitto 5:7e5c566b1760 19 #include <stdint.h>
Pokitto 5:7e5c566b1760 20 #include <string.h>
Pokitto 5:7e5c566b1760 21
Pokitto 5:7e5c566b1760 22 #if DEVICE_SEMIHOST
Pokitto 5:7e5c566b1760 23
Pokitto 5:7e5c566b1760 24 // ARM Semihosting Commands
Pokitto 5:7e5c566b1760 25 #define SYS_OPEN (0x1)
Pokitto 5:7e5c566b1760 26 #define SYS_CLOSE (0x2)
Pokitto 5:7e5c566b1760 27 #define SYS_WRITE (0x5)
Pokitto 5:7e5c566b1760 28 #define SYS_READ (0x6)
Pokitto 5:7e5c566b1760 29 #define SYS_ISTTY (0x9)
Pokitto 5:7e5c566b1760 30 #define SYS_SEEK (0xa)
Pokitto 5:7e5c566b1760 31 #define SYS_ENSURE (0xb)
Pokitto 5:7e5c566b1760 32 #define SYS_FLEN (0xc)
Pokitto 5:7e5c566b1760 33 #define SYS_REMOVE (0xe)
Pokitto 5:7e5c566b1760 34 #define SYS_RENAME (0xf)
Pokitto 5:7e5c566b1760 35 #define SYS_EXIT (0x18)
Pokitto 5:7e5c566b1760 36
Pokitto 5:7e5c566b1760 37 // mbed Semihosting Commands
Pokitto 5:7e5c566b1760 38 #define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff
Pokitto 5:7e5c566b1760 39 #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
Pokitto 5:7e5c566b1760 40 #define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1)
Pokitto 5:7e5c566b1760 41 #define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2)
Pokitto 5:7e5c566b1760 42 #define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3)
Pokitto 5:7e5c566b1760 43 #define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4)
Pokitto 5:7e5c566b1760 44 #define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
Pokitto 5:7e5c566b1760 45
Pokitto 5:7e5c566b1760 46 #if DEVICE_LOCALFILESYSTEM
Pokitto 5:7e5c566b1760 47 FILEHANDLE semihost_open(const char* name, int openmode) {
Pokitto 5:7e5c566b1760 48 uint32_t args[3];
Pokitto 5:7e5c566b1760 49 args[0] = (uint32_t)name;
Pokitto 5:7e5c566b1760 50 args[1] = (uint32_t)openmode;
Pokitto 5:7e5c566b1760 51 args[2] = (uint32_t)strlen(name);
Pokitto 5:7e5c566b1760 52 return __semihost(SYS_OPEN, args);
Pokitto 5:7e5c566b1760 53 }
Pokitto 5:7e5c566b1760 54
Pokitto 5:7e5c566b1760 55 int semihost_close(FILEHANDLE fh) {
Pokitto 5:7e5c566b1760 56 return __semihost(SYS_CLOSE, &fh);
Pokitto 5:7e5c566b1760 57 }
Pokitto 5:7e5c566b1760 58
Pokitto 5:7e5c566b1760 59 int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
Pokitto 5:7e5c566b1760 60 if (length == 0) return 0;
Pokitto 5:7e5c566b1760 61
Pokitto 5:7e5c566b1760 62 uint32_t args[3];
Pokitto 5:7e5c566b1760 63 args[0] = (uint32_t)fh;
Pokitto 5:7e5c566b1760 64 args[1] = (uint32_t)buffer;
Pokitto 5:7e5c566b1760 65 args[2] = (uint32_t)length;
Pokitto 5:7e5c566b1760 66 return __semihost(SYS_WRITE, args);
Pokitto 5:7e5c566b1760 67 }
Pokitto 5:7e5c566b1760 68
Pokitto 5:7e5c566b1760 69 int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) {
Pokitto 5:7e5c566b1760 70 uint32_t args[3];
Pokitto 5:7e5c566b1760 71 args[0] = (uint32_t)fh;
Pokitto 5:7e5c566b1760 72 args[1] = (uint32_t)buffer;
Pokitto 5:7e5c566b1760 73 args[2] = (uint32_t)length;
Pokitto 5:7e5c566b1760 74 return __semihost(SYS_READ, args);
Pokitto 5:7e5c566b1760 75 }
Pokitto 5:7e5c566b1760 76
Pokitto 5:7e5c566b1760 77 int semihost_istty(FILEHANDLE fh) {
Pokitto 5:7e5c566b1760 78 return __semihost(SYS_ISTTY, &fh);
Pokitto 5:7e5c566b1760 79 }
Pokitto 5:7e5c566b1760 80
Pokitto 5:7e5c566b1760 81 int semihost_seek(FILEHANDLE fh, long position) {
Pokitto 5:7e5c566b1760 82 uint32_t args[2];
Pokitto 5:7e5c566b1760 83 args[0] = (uint32_t)fh;
Pokitto 5:7e5c566b1760 84 args[1] = (uint32_t)position;
Pokitto 5:7e5c566b1760 85 return __semihost(SYS_SEEK, args);
Pokitto 5:7e5c566b1760 86 }
Pokitto 5:7e5c566b1760 87
Pokitto 5:7e5c566b1760 88 int semihost_ensure(FILEHANDLE fh) {
Pokitto 5:7e5c566b1760 89 return __semihost(SYS_ENSURE, &fh);
Pokitto 5:7e5c566b1760 90 }
Pokitto 5:7e5c566b1760 91
Pokitto 5:7e5c566b1760 92 long semihost_flen(FILEHANDLE fh) {
Pokitto 5:7e5c566b1760 93 return __semihost(SYS_FLEN, &fh);
Pokitto 5:7e5c566b1760 94 }
Pokitto 5:7e5c566b1760 95
Pokitto 5:7e5c566b1760 96 int semihost_remove(const char *name) {
Pokitto 5:7e5c566b1760 97 uint32_t args[2];
Pokitto 5:7e5c566b1760 98 args[0] = (uint32_t)name;
Pokitto 5:7e5c566b1760 99 args[1] = (uint32_t)strlen(name);
Pokitto 5:7e5c566b1760 100 return __semihost(SYS_REMOVE, args);
Pokitto 5:7e5c566b1760 101 }
Pokitto 5:7e5c566b1760 102
Pokitto 5:7e5c566b1760 103 int semihost_rename(const char *old_name, const char *new_name) {
Pokitto 5:7e5c566b1760 104 uint32_t args[4];
Pokitto 5:7e5c566b1760 105 args[0] = (uint32_t)old_name;
Pokitto 5:7e5c566b1760 106 args[1] = (uint32_t)strlen(old_name);
Pokitto 5:7e5c566b1760 107 args[0] = (uint32_t)new_name;
Pokitto 5:7e5c566b1760 108 args[1] = (uint32_t)strlen(new_name);
Pokitto 5:7e5c566b1760 109 return __semihost(SYS_RENAME, args);
Pokitto 5:7e5c566b1760 110 }
Pokitto 5:7e5c566b1760 111 #endif
Pokitto 5:7e5c566b1760 112
Pokitto 5:7e5c566b1760 113 int semihost_exit(void) {
Pokitto 5:7e5c566b1760 114 uint32_t args[4];
Pokitto 5:7e5c566b1760 115 return __semihost(SYS_EXIT, args);
Pokitto 5:7e5c566b1760 116 }
Pokitto 5:7e5c566b1760 117
Pokitto 5:7e5c566b1760 118 int semihost_uid(char *uid) {
Pokitto 5:7e5c566b1760 119 uint32_t args[2];
Pokitto 5:7e5c566b1760 120 args[0] = (uint32_t)uid;
Pokitto 5:7e5c566b1760 121 args[1] = DEVICE_ID_LENGTH + 1;
Pokitto 5:7e5c566b1760 122 return __semihost(USR_UID, &args);
Pokitto 5:7e5c566b1760 123 }
Pokitto 5:7e5c566b1760 124
Pokitto 5:7e5c566b1760 125 int semihost_reset(void) {
Pokitto 5:7e5c566b1760 126 // Does not normally return, however if used with older firmware versions
Pokitto 5:7e5c566b1760 127 // that do not support this call it will return -1.
Pokitto 5:7e5c566b1760 128 return __semihost(USR_RESET, NULL);
Pokitto 5:7e5c566b1760 129 }
Pokitto 5:7e5c566b1760 130
Pokitto 5:7e5c566b1760 131 int semihost_vbus(void) {
Pokitto 5:7e5c566b1760 132 return __semihost(USR_VBUS, NULL);
Pokitto 5:7e5c566b1760 133 }
Pokitto 5:7e5c566b1760 134
Pokitto 5:7e5c566b1760 135 int semihost_powerdown(void) {
Pokitto 5:7e5c566b1760 136 return __semihost(USR_POWERDOWN, NULL);
Pokitto 5:7e5c566b1760 137 }
Pokitto 5:7e5c566b1760 138
Pokitto 5:7e5c566b1760 139 #if DEVICE_DEBUG_AWARENESS
Pokitto 5:7e5c566b1760 140
Pokitto 5:7e5c566b1760 141 int semihost_connected(void) {
Pokitto 5:7e5c566b1760 142 return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
Pokitto 5:7e5c566b1760 143 }
Pokitto 5:7e5c566b1760 144
Pokitto 5:7e5c566b1760 145 #else
Pokitto 5:7e5c566b1760 146 // These processors cannot know if the interface is connect, assume so:
Pokitto 5:7e5c566b1760 147 static int is_debugger_attached = 1;
Pokitto 5:7e5c566b1760 148
Pokitto 5:7e5c566b1760 149 int semihost_connected(void) {
Pokitto 5:7e5c566b1760 150 return is_debugger_attached;
Pokitto 5:7e5c566b1760 151 }
Pokitto 5:7e5c566b1760 152 #endif
Pokitto 5:7e5c566b1760 153
Pokitto 5:7e5c566b1760 154 int semihost_disabledebug(void) {
Pokitto 5:7e5c566b1760 155 #if !(DEVICE_DEBUG_AWARENESS)
Pokitto 5:7e5c566b1760 156 is_debugger_attached = 0;
Pokitto 5:7e5c566b1760 157 #endif
Pokitto 5:7e5c566b1760 158 return __semihost(USR_DISABLEDEBUG, NULL);
Pokitto 5:7e5c566b1760 159 }
Pokitto 5:7e5c566b1760 160
Pokitto 5:7e5c566b1760 161 #endif
Pokitto 5:7e5c566b1760 162