*
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* main_cpp.cpp
|
||||
*
|
||||
* Created on: 28 àïð. 2016 ã.
|
||||
* Author: Sergey
|
||||
*/
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "lm_vector.h"
|
||||
#include "lm_vector_intrin.h"
|
||||
#include "lm_matrix.h"
|
||||
#include "lm_matrix_intrin.h"
|
||||
#include "lcd.h"
|
||||
#include "display_fsmc_interface.h"
|
||||
#include "ili9325/ili9325.h"
|
||||
#include "core_cm7.h"
|
||||
#include "../../github/softgl/SoftGL/StaticTexture.h"
|
||||
|
||||
#include "../../github/softgl/SoftGL/BlockRasterizer.h"
|
||||
|
||||
using namespace Stm32PlusPlus::Display;
|
||||
|
||||
static constexpr uint16_t rect_width = 240/2;
|
||||
static constexpr uint16_t rect_height = 320/2;
|
||||
|
||||
typedef Ili9325::Driver<DisplayFsmcInterface> Lcd;
|
||||
extern DMA_HandleTypeDef hdma_memtomem_dma2_stream0;
|
||||
extern SRAM_HandleTypeDef hsram1;
|
||||
|
||||
|
||||
|
||||
//alignas(32) uint16_t frameBuffer[320*240];
|
||||
|
||||
static constexpr size_t sx = 320;
|
||||
static constexpr size_t sy = 240;
|
||||
|
||||
alignas(32) MipChain<sizeof(uint16_t), sx, sy, 0> bb_data;
|
||||
alignas(32) MipChain<sizeof(float), sx, sy, 0> db_data;
|
||||
|
||||
uint16_t* frameBuffer = (uint16_t*)&bb_data.data[0];
|
||||
|
||||
void fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color){
|
||||
for(uint32_t cy = y; cy < (y + height); ++cy){
|
||||
for(uint32_t cx = x; cx < (x + width); ++cx){
|
||||
frameBuffer[cy * 240 + cx] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool xferComplete = false;
|
||||
extern "C" void frameXferCpltCallback(DMA_HandleTypeDef* hdma){
|
||||
xferComplete = true;
|
||||
}
|
||||
/*extern "C" void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma){
|
||||
xferComplete = true;
|
||||
}*/
|
||||
|
||||
uint32_t frameStartTime = 0;
|
||||
void beginLcdUpload(){
|
||||
frameStartTime = HAL_GetTick();
|
||||
//SCB_CleanInvalidateDCache_by_Addr((uint32_t*)DisplayFsmcInterface::dataLocation, sizeof(frameBuffer));
|
||||
SCB_CleanDCache_by_Addr((uint32_t*)&frameBuffer[0], sizeof(frameBuffer));
|
||||
// HAL_SRAM_Write_DMA(&hsram1, (uint32_t*)DisplayFsmcInterface::dataLocation, (uint32_t*)&frameBuffer[0], sizeof(frameBuffer) / 4);
|
||||
HAL_DMA_Start_IT(&hdma_memtomem_dma2_stream0, (uint32_t)&frameBuffer[0], (uint32_t)DisplayFsmcInterface::dataLocation, 320*240 / 2);
|
||||
}
|
||||
|
||||
void waitLcdUpload(){
|
||||
while(!xferComplete){}
|
||||
|
||||
|
||||
|
||||
auto frameTime = HAL_GetTick() - frameStartTime;
|
||||
|
||||
uint32_t frameMaxTime = 1000/128 ;
|
||||
|
||||
if(frameTime < frameMaxTime){
|
||||
HAL_Delay(frameMaxTime - frameTime);
|
||||
}
|
||||
|
||||
xferComplete = false;
|
||||
}
|
||||
|
||||
void clear(uint16_t color){
|
||||
for(size_t i = 0; i < sizeof(frameBuffer) / 2; ++i){
|
||||
frameBuffer[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*struct Color24{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
|
||||
void fromColor16(uint16_t value){
|
||||
b = (value & 0x1f) << 3;
|
||||
g = (value & 0x7e0) >> 3;
|
||||
r = (value & 0xf800) >> 8;
|
||||
}
|
||||
|
||||
uint16_t toColor16(){
|
||||
uint16_t result = b >> 3;
|
||||
result |= ((uint16_t)g >> 2) << 5;
|
||||
result |= ((uint16_t)r >> 3) << 11;
|
||||
return result;
|
||||
}
|
||||
|
||||
static Color24 lerp(Color24 left, Color24 right, uint16_t val, uint16_t maxVal){
|
||||
Color24 result;
|
||||
result.r = (int32_t)left.r + ((int32_t)(right.r - left.r) * (int32_t)val) / (int32_t)maxVal;
|
||||
result.g = (int32_t)left.g + ((int32_t)(right.g - left.g) * (int32_t)val) / (int32_t)maxVal;
|
||||
result.b = (int32_t)left.b + ((int32_t)(right.b - left.b) * (int32_t)val) / (int32_t)maxVal;
|
||||
|
||||
return result;
|
||||
}
|
||||
};*/
|
||||
|
||||
|
||||
void clearGradient(uint16_t color){
|
||||
Color24 c24Zero;
|
||||
c24Zero.r = 0;
|
||||
c24Zero.g = 0;
|
||||
c24Zero.b = 0;
|
||||
|
||||
Color24 c24;
|
||||
c24.fromColor16(color);
|
||||
|
||||
for(int y = 0; y < 320; ++y){
|
||||
auto c1 = Color24::lerp(c24Zero, c24, y, 319).toColor16();
|
||||
for(int x = 0; x < 240; ++x){
|
||||
if(x == 0 || x == 239 || y == 0 || y == 319){
|
||||
frameBuffer[y * 240 + x] = Blue;
|
||||
}else{
|
||||
frameBuffer[y * 240 + x] = c1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void main_cpp(){
|
||||
hdma_memtomem_dma2_stream0.XferCpltCallback = frameXferCpltCallback;
|
||||
DisplayFsmcInterface::init();
|
||||
|
||||
Lcd::init();
|
||||
|
||||
BlockRasterizer rasterizer;
|
||||
//HAL_DMa_
|
||||
|
||||
uint16_t x = 0;
|
||||
uint16_t y = 0;
|
||||
uint16_t tx = 0;
|
||||
uint16_t ty = 0;
|
||||
|
||||
uint32_t check_tick = HAL_GetTick();
|
||||
|
||||
uint32_t frame_id = 0;
|
||||
uint32_t fps = 0;
|
||||
|
||||
bool color = false;
|
||||
|
||||
|
||||
|
||||
for(;;){
|
||||
Lcd::setCursor(0,0);
|
||||
Lcd::beginWriteGram();
|
||||
|
||||
|
||||
//clear(color ? Red : Green);
|
||||
|
||||
clearGradient(Green);
|
||||
|
||||
|
||||
/*for(uint32_t i = 0; i <sizeof(frameBuffer) / 2; ++i){
|
||||
Lcd::write(frameBuffer[i]);
|
||||
}*/
|
||||
|
||||
|
||||
//Lcd::clear(color ? Red : Green);
|
||||
|
||||
if(x == tx){
|
||||
tx = tx == 0 ? 240/2 : 0;
|
||||
}
|
||||
if(y == ty){
|
||||
ty = ty == 0 ? 320/2 : 0;
|
||||
}
|
||||
|
||||
if(tx > x){
|
||||
++x;
|
||||
}else{
|
||||
--x;
|
||||
}
|
||||
|
||||
if(ty > y){
|
||||
++y;
|
||||
}else{
|
||||
--y;
|
||||
}
|
||||
|
||||
fillRect(x,y,rect_width, rect_height, Blue);
|
||||
|
||||
beginLcdUpload();
|
||||
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
frame_id++;
|
||||
uint32_t now_tick = HAL_GetTick();
|
||||
if(now_tick - check_tick >= 1000){
|
||||
check_tick = now_tick;
|
||||
fps = frame_id;
|
||||
frame_id = 0;
|
||||
}
|
||||
waitLcdUpload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* syscalls.c
|
||||
*
|
||||
* Created on: 15 θών 2015 γ.
|
||||
* Author: Sergey
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "stm32f7xx_it.h"
|
||||
|
||||
//extern UART_HandleTypeDef CONSOLE_UART;
|
||||
|
||||
extern int errno;
|
||||
register char * stack_ptr asm("sp");
|
||||
|
||||
caddr_t _sbrk(int incr) {
|
||||
extern char end asm("end");
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == 0)
|
||||
heap_end = &end;
|
||||
|
||||
prev_heap_end = heap_end;
|
||||
if (heap_end + incr > stack_ptr) {
|
||||
errno = ENOMEM;
|
||||
return (caddr_t) -1;
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
return (caddr_t) prev_heap_end;
|
||||
}
|
||||
|
||||
|
||||
#ifndef __errno_r
|
||||
#include <sys/reent.h>
|
||||
#define __errno_r(reent) reent->_errno
|
||||
#endif
|
||||
|
||||
|
||||
int _write_r(struct _reent *r, int file, char * ptr, int len){
|
||||
(void)r;
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
|
||||
#if defined(UART_STDIO)
|
||||
while(1) {
|
||||
HAL_UART_StateTypeDef state = HAL_UART_GetState(&CONSOLE_UART);
|
||||
if((state != HAL_UART_STATE_BUSY_TX) && (state != HAL_UART_STATE_BUSY_TX_RX)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
HAL_UART_Transmit(&CONSOLE_UART, (uint8_t*)ptr, len, HAL_MAX_DELAY);
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
int _read_r(struct _reent *r, int file, char * ptr, int len)
|
||||
{
|
||||
(void)r;
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)len;
|
||||
__errno_r(r) = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _lseek_r(struct _reent *r, int file, int ptr, int dir){
|
||||
(void)r;
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _close_r(struct _reent *r, int file){
|
||||
(void)r;
|
||||
(void)file;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open_r ( struct _reent *ptr, const char *file, int flags, int mode ){
|
||||
int fd = -1;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int _fstat_r(struct _reent *r, int file, struct stat * st){
|
||||
(void)r;
|
||||
(void)file;
|
||||
memset(st, 0, sizeof(*st));
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty_r(struct _reent *r, int fd){
|
||||
(void)r;
|
||||
(void)fd;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill (int a, int b){
|
||||
(void)a;
|
||||
(void)b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _getpid(int a){
|
||||
(void)a;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _exit(int status){
|
||||
for(;;);
|
||||
}
|
||||
Reference in New Issue
Block a user