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

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
5:ea7377f3d1af
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:ea7377f3d1af 1 extern "C" {
Pokitto 5:ea7377f3d1af 2
Pokitto 5:ea7377f3d1af 3 #include "LPC11U6x.h"
Pokitto 5:ea7377f3d1af 4
Pokitto 5:ea7377f3d1af 5 #define WEAK __attribute__ ((weak))
Pokitto 5:ea7377f3d1af 6 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
Pokitto 5:ea7377f3d1af 7 #define AFTER_VECTORS __attribute__ ((section(".after_vectors")))void ResetISR(void);
Pokitto 5:ea7377f3d1af 8
Pokitto 5:ea7377f3d1af 9 extern unsigned int __data_section_table;
Pokitto 5:ea7377f3d1af 10 extern unsigned int __data_section_table_end;
Pokitto 5:ea7377f3d1af 11 extern unsigned int __bss_section_table;
Pokitto 5:ea7377f3d1af 12 extern unsigned int __bss_section_table_end;
Pokitto 5:ea7377f3d1af 13
Pokitto 5:ea7377f3d1af 14
Pokitto 5:ea7377f3d1af 15 extern void __libc_init_array(void);
Pokitto 5:ea7377f3d1af 16 extern int main(void);
Pokitto 5:ea7377f3d1af 17 extern void _vStackTop(void);
Pokitto 5:ea7377f3d1af 18 extern void (* const g_pfnVectors[])(void);
Pokitto 5:ea7377f3d1af 19
Pokitto 5:ea7377f3d1af 20 void ResetISR(void);
Pokitto 5:ea7377f3d1af 21 WEAK void NMI_Handler(void);
Pokitto 5:ea7377f3d1af 22 WEAK void HardFault_Handler(void);
Pokitto 5:ea7377f3d1af 23 WEAK void SVC_Handler(void);
Pokitto 5:ea7377f3d1af 24 WEAK void PendSV_Handler(void);
Pokitto 5:ea7377f3d1af 25 WEAK void SysTick_Handler(void);
Pokitto 5:ea7377f3d1af 26 WEAK void IntDefaultHandler(void);
Pokitto 5:ea7377f3d1af 27
Pokitto 5:ea7377f3d1af 28 void PIN_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 29 void PIN_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 30 void PIN_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 31 void PIN_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 32 void PIN_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 33 void PIN_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 34 void PIN_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 35 void PIN_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 36 void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 37 void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 38 void I2C1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 39 void USART1_4_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 40 void USART2_3_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 41 void SCT0_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 42 void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 43 void I2C0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 44 void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 45 void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 46 void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 47 void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 48 void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 49 void USART0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 50 void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 51 void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 52 void ADCA_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 53 void RTC_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 54 void BOD_WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 55 void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 56 void DMA_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 57 void ADCB_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 58 void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 59
Pokitto 5:ea7377f3d1af 60 __attribute__ ((section(".isr_vector")))
Pokitto 5:ea7377f3d1af 61 void (* const g_pfnVectors[])(void) = {
Pokitto 5:ea7377f3d1af 62 // Core Level - CM0
Pokitto 5:ea7377f3d1af 63 &_vStackTop, // The initial stack pointer
Pokitto 5:ea7377f3d1af 64 ResetISR, // The reset handler
Pokitto 5:ea7377f3d1af 65 NMI_Handler, // The NMI handler
Pokitto 5:ea7377f3d1af 66 HardFault_Handler, // The hard fault handler
Pokitto 5:ea7377f3d1af 67 0, // Reserved
Pokitto 5:ea7377f3d1af 68 0, // Reserved
Pokitto 5:ea7377f3d1af 69 0, // Reserved
Pokitto 5:ea7377f3d1af 70 0, // Reserved
Pokitto 5:ea7377f3d1af 71 0, // Reserved
Pokitto 5:ea7377f3d1af 72 0, // Reserved
Pokitto 5:ea7377f3d1af 73 0, // Reserved
Pokitto 5:ea7377f3d1af 74 SVC_Handler, // SVCall handler
Pokitto 5:ea7377f3d1af 75 0, // Reserved
Pokitto 5:ea7377f3d1af 76 0, // Reserved
Pokitto 5:ea7377f3d1af 77 PendSV_Handler, // The PendSV handler
Pokitto 5:ea7377f3d1af 78 SysTick_Handler, // The SysTick handler
Pokitto 5:ea7377f3d1af 79
Pokitto 5:ea7377f3d1af 80 // Chip Level - LPC11U68
Pokitto 5:ea7377f3d1af 81 PIN_INT0_IRQHandler, // 0 - GPIO pin interrupt 0
Pokitto 5:ea7377f3d1af 82 PIN_INT1_IRQHandler, // 1 - GPIO pin interrupt 1
Pokitto 5:ea7377f3d1af 83 PIN_INT2_IRQHandler, // 2 - GPIO pin interrupt 2
Pokitto 5:ea7377f3d1af 84 PIN_INT3_IRQHandler, // 3 - GPIO pin interrupt 3
Pokitto 5:ea7377f3d1af 85 PIN_INT4_IRQHandler, // 4 - GPIO pin interrupt 4
Pokitto 5:ea7377f3d1af 86 PIN_INT5_IRQHandler, // 5 - GPIO pin interrupt 5
Pokitto 5:ea7377f3d1af 87 PIN_INT6_IRQHandler, // 6 - GPIO pin interrupt 6
Pokitto 5:ea7377f3d1af 88 PIN_INT7_IRQHandler, // 7 - GPIO pin interrupt 7
Pokitto 5:ea7377f3d1af 89 GINT0_IRQHandler, // 8 - GPIO GROUP0 interrupt
Pokitto 5:ea7377f3d1af 90 GINT1_IRQHandler, // 9 - GPIO GROUP1 interrupt
Pokitto 5:ea7377f3d1af 91 I2C1_IRQHandler, // 10 - I2C1
Pokitto 5:ea7377f3d1af 92 USART1_4_IRQHandler, // 11 - combined USART1 & 4 interrupt
Pokitto 5:ea7377f3d1af 93 USART2_3_IRQHandler, // 12 - combined USART2 & 3 interrupt
Pokitto 5:ea7377f3d1af 94 SCT0_1_IRQHandler, // 13 - combined SCT0 and 1 interrupt
Pokitto 5:ea7377f3d1af 95 SSP1_IRQHandler, // 14 - SPI/SSP1 Interrupt
Pokitto 5:ea7377f3d1af 96 I2C0_IRQHandler, // 15 - I2C0
Pokitto 5:ea7377f3d1af 97 TIMER16_0_IRQHandler, // 16 - CT16B0 (16-bit Timer 0)
Pokitto 5:ea7377f3d1af 98 TIMER16_1_IRQHandler, // 17 - CT16B1 (16-bit Timer 1)
Pokitto 5:ea7377f3d1af 99 TIMER32_0_IRQHandler, // 18 - CT32B0 (32-bit Timer 0)
Pokitto 5:ea7377f3d1af 100 TIMER32_1_IRQHandler, // 19 - CT32B1 (32-bit Timer 1)
Pokitto 5:ea7377f3d1af 101 SSP0_IRQHandler, // 20 - SPI/SSP0 Interrupt
Pokitto 5:ea7377f3d1af 102 USART0_IRQHandler, // 21 - USART0
Pokitto 5:ea7377f3d1af 103 USB_IRQHandler, // 22 - USB IRQ
Pokitto 5:ea7377f3d1af 104 USB_FIQHandler, // 23 - USB FIQ
Pokitto 5:ea7377f3d1af 105 ADCA_IRQHandler, // 24 - ADC A(A/D Converter)
Pokitto 5:ea7377f3d1af 106 RTC_IRQHandler, // 25 - Real Time CLock interrpt
Pokitto 5:ea7377f3d1af 107 BOD_WDT_IRQHandler, // 25 - Combined Brownout/Watchdog interrupt
Pokitto 5:ea7377f3d1af 108 FMC_IRQHandler, // 27 - IP2111 Flash Memory Controller
Pokitto 5:ea7377f3d1af 109 DMA_IRQHandler, // 28 - DMA interrupt
Pokitto 5:ea7377f3d1af 110 ADCB_IRQHandler, // 24 - ADC B (A/D Converter)
Pokitto 5:ea7377f3d1af 111 USBWakeup_IRQHandler, // 30 - USB wake-up interrupt
Pokitto 5:ea7377f3d1af 112 0, // 31 - Reserved
Pokitto 5:ea7377f3d1af 113 };
Pokitto 5:ea7377f3d1af 114 /* End Vector */
Pokitto 5:ea7377f3d1af 115
Pokitto 5:ea7377f3d1af 116 AFTER_VECTORS void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
Pokitto 5:ea7377f3d1af 117 unsigned int *pulDest = (unsigned int*) start;
Pokitto 5:ea7377f3d1af 118 unsigned int *pulSrc = (unsigned int*) romstart;
Pokitto 5:ea7377f3d1af 119 unsigned int loop;
Pokitto 5:ea7377f3d1af 120 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = *pulSrc++;
Pokitto 5:ea7377f3d1af 121 }
Pokitto 5:ea7377f3d1af 122
Pokitto 5:ea7377f3d1af 123 AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
Pokitto 5:ea7377f3d1af 124 unsigned int *pulDest = (unsigned int*) start;
Pokitto 5:ea7377f3d1af 125 unsigned int loop;
Pokitto 5:ea7377f3d1af 126 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = 0;
Pokitto 5:ea7377f3d1af 127 }
Pokitto 5:ea7377f3d1af 128
Pokitto 5:ea7377f3d1af 129
Pokitto 5:ea7377f3d1af 130 /* Reset entry point*/
Pokitto 5:ea7377f3d1af 131 extern "C" void software_init_hook(void) __attribute__((weak));
Pokitto 5:ea7377f3d1af 132
Pokitto 5:ea7377f3d1af 133 AFTER_VECTORS void ResetISR(void) {
Pokitto 5:ea7377f3d1af 134 unsigned int LoadAddr, ExeAddr, SectionLen;
Pokitto 5:ea7377f3d1af 135 unsigned int *SectionTableAddr;
Pokitto 5:ea7377f3d1af 136
Pokitto 5:ea7377f3d1af 137 SectionTableAddr = &__data_section_table;
Pokitto 5:ea7377f3d1af 138
Pokitto 5:ea7377f3d1af 139 while (SectionTableAddr < &__data_section_table_end) {
Pokitto 5:ea7377f3d1af 140 LoadAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 141 ExeAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 142 SectionLen = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 143 data_init(LoadAddr, ExeAddr, SectionLen);
Pokitto 5:ea7377f3d1af 144 }
Pokitto 5:ea7377f3d1af 145 while (SectionTableAddr < &__bss_section_table_end) {
Pokitto 5:ea7377f3d1af 146 ExeAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 147 SectionLen = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 148 bss_init(ExeAddr, SectionLen);
Pokitto 5:ea7377f3d1af 149 }
Pokitto 5:ea7377f3d1af 150
Pokitto 5:ea7377f3d1af 151 SystemInit();
Pokitto 5:ea7377f3d1af 152 if (software_init_hook)
Pokitto 5:ea7377f3d1af 153 software_init_hook();
Pokitto 5:ea7377f3d1af 154 else {
Pokitto 5:ea7377f3d1af 155 __libc_init_array();
Pokitto 5:ea7377f3d1af 156 main();
Pokitto 5:ea7377f3d1af 157 }
Pokitto 5:ea7377f3d1af 158 while (1) {;}
Pokitto 5:ea7377f3d1af 159 }
Pokitto 5:ea7377f3d1af 160
Pokitto 5:ea7377f3d1af 161 AFTER_VECTORS void NMI_Handler (void) {}
Pokitto 5:ea7377f3d1af 162 AFTER_VECTORS void HardFault_Handler (void) {}
Pokitto 5:ea7377f3d1af 163 AFTER_VECTORS void MemManage_Handler (void) {}
Pokitto 5:ea7377f3d1af 164 AFTER_VECTORS void BusFault_Handler (void) {}
Pokitto 5:ea7377f3d1af 165 AFTER_VECTORS void UsageFault_Handler(void) {}
Pokitto 5:ea7377f3d1af 166 AFTER_VECTORS void SVC_Handler (void) {}
Pokitto 5:ea7377f3d1af 167 AFTER_VECTORS void DebugMon_Handler (void) {}
Pokitto 5:ea7377f3d1af 168 AFTER_VECTORS void PendSV_Handler (void) {}
Pokitto 5:ea7377f3d1af 169 AFTER_VECTORS void SysTick_Handler (void) {}
Pokitto 5:ea7377f3d1af 170 AFTER_VECTORS void IntDefaultHandler (void) {}
Pokitto 5:ea7377f3d1af 171
Pokitto 5:ea7377f3d1af 172 int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {return 0;}
Pokitto 5:ea7377f3d1af 173 }
Pokitto 5:ea7377f3d1af 174
Pokitto 5:ea7377f3d1af 175 #include <stdlib.h>
Pokitto 5:ea7377f3d1af 176
Pokitto 5:ea7377f3d1af 177 void *operator new(size_t size) {return malloc(size);}
Pokitto 5:ea7377f3d1af 178 void *operator new[](size_t size){return malloc(size);}
Pokitto 5:ea7377f3d1af 179
Pokitto 5:ea7377f3d1af 180 void operator delete(void *p) {free(p);}
Pokitto 5:ea7377f3d1af 181 void operator delete[](void *p) {free(p);}