| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include <cmsis_os.h> | 7 #include <cmsis_os.h> |
| 8 extern "C" { | 8 extern "C" { |
| 9 #include <lcd_log.h> | 9 #include <lcd_log.h> |
| 10 } | 10 } |
| 11 #include <stm32746g_discovery.h> | 11 #include <stm32746g_discovery.h> |
| 12 #include <stm32746g_discovery_lcd.h> | 12 #include <stm32746g_discovery_lcd.h> |
| 13 | 13 |
| 14 #include "include/fletch_api.h" | 14 #include "include/dartino_api.h" |
| 15 #include "include/static_ffi.h" | 15 #include "include/static_ffi.h" |
| 16 | 16 |
| 17 #include "platforms/stm/disco_fletch/src/fletch_entry.h" | 17 #include "platforms/stm/disco_dartino/src/dartino_entry.h" |
| 18 #include "platforms/stm/disco_fletch/src/page_allocator.h" | 18 #include "platforms/stm/disco_dartino/src/page_allocator.h" |
| 19 #include "platforms/stm/disco_fletch/src/uart.h" | 19 #include "platforms/stm/disco_dartino/src/uart.h" |
| 20 #include "src/shared/utils.h" | 20 #include "src/shared/utils.h" |
| 21 | 21 |
| 22 extern unsigned char _binary_snapshot_start; | 22 extern unsigned char _binary_snapshot_start; |
| 23 extern unsigned char _binary_snapshot_end; | 23 extern unsigned char _binary_snapshot_end; |
| 24 extern unsigned char _binary_snapshot_size; | 24 extern unsigned char _binary_snapshot_size; |
| 25 | 25 |
| 26 extern PageAllocator* page_allocator; | 26 extern PageAllocator* page_allocator; |
| 27 | 27 |
| 28 Uart* uart; | 28 Uart* uart; |
| 29 | 29 |
| 30 extern "C" size_t UartRead(uint8_t* buffer, size_t count) { | 30 extern "C" size_t UartRead(uint8_t* buffer, size_t count) { |
| 31 return uart->Read(buffer, count); | 31 return uart->Read(buffer, count); |
| 32 } | 32 } |
| 33 | 33 |
| 34 extern "C" size_t UartWrite(uint8_t* buffer, size_t count) { | 34 extern "C" size_t UartWrite(uint8_t* buffer, size_t count) { |
| 35 return uart->Write(buffer, count); | 35 return uart->Write(buffer, count); |
| 36 } | 36 } |
| 37 | 37 |
| 38 extern "C" void LCDDrawLine( | 38 extern "C" void LCDDrawLine( |
| 39 uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) { | 39 uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) { |
| 40 // BSP_LCD_DrawLine takes uint16_t arguments. | 40 // BSP_LCD_DrawLine takes uint16_t arguments. |
| 41 BSP_LCD_DrawLine(x1, y1, x2, y2); | 41 BSP_LCD_DrawLine(x1, y1, x2, y2); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Implementation of write used from syscalls.c to redirect all printf | 44 // Implementation of write used from syscalls.c to redirect all printf |
| 45 // calls to the print interceptors. | 45 // calls to the print interceptors. |
| 46 extern "C" int Write(int file, char *ptr, int len) { | 46 extern "C" int Write(int file, char *ptr, int len) { |
| 47 for (int i = 0; i < len; i++) { | 47 for (int i = 0; i < len; i++) { |
| 48 if (file == 2) { | 48 if (file == 2) { |
| 49 fletch::Print::Error("%c", *ptr++); | 49 dartino::Print::Error("%c", *ptr++); |
| 50 } else { | 50 } else { |
| 51 fletch::Print::Out("%c", *ptr++); | 51 dartino::Print::Out("%c", *ptr++); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 return len; | 54 return len; |
| 55 } | 55 } |
| 56 | 56 |
| 57 FLETCH_EXPORT_TABLE_BEGIN | 57 DARTINO_EXPORT_TABLE_BEGIN |
| 58 FLETCH_EXPORT_TABLE_ENTRY("uart_read", UartRead) | 58 DARTINO_EXPORT_TABLE_ENTRY("uart_read", UartRead) |
| 59 FLETCH_EXPORT_TABLE_ENTRY("uart_write", UartWrite) | 59 DARTINO_EXPORT_TABLE_ENTRY("uart_write", UartWrite) |
| 60 FLETCH_EXPORT_TABLE_ENTRY("lcd_height", BSP_LCD_GetYSize) | 60 DARTINO_EXPORT_TABLE_ENTRY("lcd_height", BSP_LCD_GetYSize) |
| 61 FLETCH_EXPORT_TABLE_ENTRY("lcd_width", BSP_LCD_GetXSize) | 61 DARTINO_EXPORT_TABLE_ENTRY("lcd_width", BSP_LCD_GetXSize) |
| 62 FLETCH_EXPORT_TABLE_ENTRY("lcd_clear", BSP_LCD_Clear) | 62 DARTINO_EXPORT_TABLE_ENTRY("lcd_clear", BSP_LCD_Clear) |
| 63 FLETCH_EXPORT_TABLE_ENTRY("lcd_draw_line", LCDDrawLine) | 63 DARTINO_EXPORT_TABLE_ENTRY("lcd_draw_line", LCDDrawLine) |
| 64 FLETCH_EXPORT_TABLE_ENTRY("lcd_set_foreground_color", BSP_LCD_SetTextColor) | 64 DARTINO_EXPORT_TABLE_ENTRY("lcd_set_foreground_color", BSP_LCD_SetTextColor) |
| 65 FLETCH_EXPORT_TABLE_ENTRY("lcd_set_background_color", BSP_LCD_SetBackColor) | 65 DARTINO_EXPORT_TABLE_ENTRY("lcd_set_background_color", BSP_LCD_SetBackColor) |
| 66 FLETCH_EXPORT_TABLE_ENTRY("lcd_display_string", BSP_LCD_DisplayStringAt) | 66 DARTINO_EXPORT_TABLE_ENTRY("lcd_display_string", BSP_LCD_DisplayStringAt) |
| 67 FLETCH_EXPORT_TABLE_END | 67 DARTINO_EXPORT_TABLE_END |
| 68 | 68 |
| 69 // Run fletch on the linked in snapshot. | 69 // Run dartino on the linked in snapshot. |
| 70 void StartFletch(void const * argument) { | 70 void StartDartino(void const * argument) { |
| 71 fletch::Print::Out("Setup fletch\n"); | 71 dartino::Print::Out("Setup dartino\n"); |
| 72 FletchSetup(); | 72 DartinoSetup(); |
| 73 fletch::Print::Out("Reading fletch snapshot\n"); | 73 dartino::Print::Out("Reading dartino snapshot\n"); |
| 74 unsigned char *snapshot = &_binary_snapshot_start; | 74 unsigned char *snapshot = &_binary_snapshot_start; |
| 75 int snapshot_size = reinterpret_cast<int>(&_binary_snapshot_size); | 75 int snapshot_size = reinterpret_cast<int>(&_binary_snapshot_size); |
| 76 FletchProgram program = FletchLoadSnapshot(snapshot, snapshot_size); | 76 DartinoProgram program = DartinoLoadSnapshot(snapshot, snapshot_size); |
| 77 fletch::Print::Out("Run fletch program\n"); | 77 dartino::Print::Out("Run dartino program\n"); |
| 78 FletchRunMain(program); | 78 DartinoRunMain(program); |
| 79 fletch::Print::Out("Fletch program exited\n"); | 79 dartino::Print::Out("Dartino program exited\n"); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void UartPrintIntercepter(const char* message, int out, void* data) { | 82 void UartPrintIntercepter(const char* message, int out, void* data) { |
| 83 int len = strlen(message); | 83 int len = strlen(message); |
| 84 for (int i = 0; i < len; i++) { | 84 for (int i = 0; i < len; i++) { |
| 85 if (message[i] == '\n') { | 85 if (message[i] == '\n') { |
| 86 uart->Write(reinterpret_cast<const uint8_t*>("\r"), 1); | 86 uart->Write(reinterpret_cast<const uint8_t*>("\r"), 1); |
| 87 } | 87 } |
| 88 uart->Write(reinterpret_cast<const uint8_t*>(message + i), 1); | 88 uart->Write(reinterpret_cast<const uint8_t*>(message + i), 1); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 // LCDLogPutchar is defined by the STM LCD log utility | 92 // LCDLogPutchar is defined by the STM LCD log utility |
| 93 // (Utilities/Log/lcd_log.c) by means of the macro definitions of | 93 // (Utilities/Log/lcd_log.c) by means of the macro definitions of |
| 94 // LCD_LOG_PUTCHAR in lcd_log_conf.h. | 94 // LCD_LOG_PUTCHAR in lcd_log_conf.h. |
| 95 extern "C" int LCDLogPutchar(int ch); | 95 extern "C" int LCDLogPutchar(int ch); |
| 96 void LCDPrintIntercepter(const char* message, int out, void* data) { | 96 void LCDPrintIntercepter(const char* message, int out, void* data) { |
| 97 int len = strlen(message); | 97 int len = strlen(message); |
| 98 if (out == 3) { | 98 if (out == 3) { |
| 99 LCD_LineColor = LCD_COLOR_RED; | 99 LCD_LineColor = LCD_COLOR_RED; |
| 100 } else { | 100 } else { |
| 101 LCD_LineColor = LCD_COLOR_BLACK; | 101 LCD_LineColor = LCD_COLOR_BLACK; |
| 102 } | 102 } |
| 103 for (int i = 0; i < len; i++) { | 103 for (int i = 0; i < len; i++) { |
| 104 LCDLogPutchar(message[i]); | 104 LCDLogPutchar(message[i]); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Main task entry point from FreeRTOS. | 108 // Main task entry point from FreeRTOS. |
| 109 void FletchEntry(void const * argument) { | 109 void DartinoEntry(void const * argument) { |
| 110 // Add an arena of the 8Mb of external memory. | 110 // Add an arena of the 8Mb of external memory. |
| 111 uint32_t ext_mem_arena = | 111 uint32_t ext_mem_arena = |
| 112 page_allocator->AddArena("ExtMem", 0xc0000000, 0x800000); | 112 page_allocator->AddArena("ExtMem", 0xc0000000, 0x800000); |
| 113 | 113 |
| 114 // Initialize the LCD. | 114 // Initialize the LCD. |
| 115 size_t fb_bytes = (RK043FN48H_WIDTH * RK043FN48H_HEIGHT * 2); | 115 size_t fb_bytes = (RK043FN48H_WIDTH * RK043FN48H_HEIGHT * 2); |
| 116 size_t fb_pages = page_allocator->PagesForBytes(fb_bytes); | 116 size_t fb_pages = page_allocator->PagesForBytes(fb_bytes); |
| 117 void* fb = page_allocator->AllocatePages(fb_pages, ext_mem_arena); | 117 void* fb = page_allocator->AllocatePages(fb_pages, ext_mem_arena); |
| 118 BSP_LCD_Init(); | 118 BSP_LCD_Init(); |
| 119 BSP_LCD_LayerDefaultInit(1, reinterpret_cast<uint32_t>(fb)); | 119 BSP_LCD_LayerDefaultInit(1, reinterpret_cast<uint32_t>(fb)); |
| 120 BSP_LCD_SelectLayer(1); | 120 BSP_LCD_SelectLayer(1); |
| 121 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); | 121 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
| 122 | 122 |
| 123 // Initialize LCD Log module. | 123 // Initialize LCD Log module. |
| 124 LCD_LOG_Init(); | 124 LCD_LOG_Init(); |
| 125 LCD_LOG_SetHeader(reinterpret_cast<uint8_t*>(const_cast<char*>("Fletch"))); | 125 LCD_LOG_SetHeader(reinterpret_cast<uint8_t*>(const_cast<char*>("Dartino"))); |
| 126 LCD_LOG_SetFooter(reinterpret_cast<uint8_t*>(const_cast<char*>( | 126 LCD_LOG_SetFooter(reinterpret_cast<uint8_t*>(const_cast<char*>( |
| 127 "STM32746G-Discovery"))); | 127 "STM32746G-Discovery"))); |
| 128 FletchRegisterPrintInterceptor(LCDPrintIntercepter, NULL); | 128 DartinoRegisterPrintInterceptor(LCDPrintIntercepter, NULL); |
| 129 | 129 |
| 130 // For now always start the UART. | 130 // For now always start the UART. |
| 131 uart = new Uart(); | 131 uart = new Uart(); |
| 132 uart->Start(); | 132 uart->Start(); |
| 133 | 133 |
| 134 FletchRegisterPrintInterceptor(UartPrintIntercepter, NULL); | 134 DartinoRegisterPrintInterceptor(UartPrintIntercepter, NULL); |
| 135 | 135 |
| 136 // Always disable standard out, as this will cause infinite | 136 // Always disable standard out, as this will cause infinite |
| 137 // recursion in the syscalls.c handling of write. | 137 // recursion in the syscalls.c handling of write. |
| 138 fletch::Print::DisableStandardOutput(); | 138 dartino::Print::DisableStandardOutput(); |
| 139 | 139 |
| 140 StartFletch(argument); | 140 StartDartino(argument); |
| 141 | 141 |
| 142 // No more to do right now. | 142 // No more to do right now. |
| 143 for (;;) { | 143 for (;;) { |
| 144 osDelay(1); | 144 osDelay(1); |
| 145 } | 145 } |
| 146 } | 146 } |
| OLD | NEW |