commit 51089aaba1d135494ee3a02ab623f1a0b8250583 Author: t-moe Date: Fri Apr 3 12:02:33 2015 +0200 Refactored Project Structure for use with emulator diff --git a/common/app/app.c b/common/app/app.c new file mode 100644 index 0000000..beaa39c --- /dev/null +++ b/common/app/app.c @@ -0,0 +1,15 @@ +#include "app.h" +#include "tft.h" +#include + +void app_init() { + tft_init(); + + tft_draw_line(10,10,30,40,0b11111); + +} + +void app_process() { +/// printf("hello world\n"); + +} diff --git a/common/app/app.h b/common/app/app.h new file mode 100644 index 0000000..e260cad --- /dev/null +++ b/common/app/app.h @@ -0,0 +1,2 @@ +void app_init(); +void app_process(); diff --git a/common/filesystem/filesystem.h b/common/filesystem/filesystem.h new file mode 100644 index 0000000..e69de29 diff --git a/common/lowlevel/ll_tft.h b/common/lowlevel/ll_tft.h new file mode 100644 index 0000000..e01255c --- /dev/null +++ b/common/lowlevel/ll_tft.h @@ -0,0 +1,14 @@ +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + bool ll_tft_init(); + void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); + +#ifdef __cplusplus +} +#endif + diff --git a/common/tft/tft.c b/common/tft/tft.c new file mode 100644 index 0000000..c3ab120 --- /dev/null +++ b/common/tft/tft.c @@ -0,0 +1,13 @@ +#include "tft.h" +#include "ll_tft.h" + + + +bool tft_init() { + return ll_tft_init(); + +} + +void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { + ll_tft_draw_line(x1,y1,x2,y2,color); +} diff --git a/common/tft/tft.h b/common/tft/tft.h new file mode 100644 index 0000000..be7a5fc --- /dev/null +++ b/common/tft/tft.h @@ -0,0 +1,5 @@ +#include +#include + +bool tft_init(); +void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); diff --git a/common/touch/touch.h b/common/touch/touch.h new file mode 100644 index 0000000..e69de29 diff --git a/emulator/.gitignore b/emulator/.gitignore new file mode 100644 index 0000000..761dc34 --- /dev/null +++ b/emulator/.gitignore @@ -0,0 +1,8 @@ +build +obj +*.user +qt/*.o +qt/*.a +qt/ui_* +qt/moc_* +qt/Makefile diff --git a/emulator/Makefile b/emulator/Makefile new file mode 100644 index 0000000..3ae1bb5 --- /dev/null +++ b/emulator/Makefile @@ -0,0 +1,71 @@ +#Name of the binary/project +TARGET=emulator + +BUILD_DIR=./build +OBJ_DIR=./obj + +QT_DIR=./qt +COMMON_DIR=../common + +#Tools +CC=gcc + +MKDIR=mkdir -p +RM=rm -f +RMDIR=rm -rf + + +COMMON_INC=-I$(COMMON_DIR)/lowlevel -I$(COMMON_DIR)/tft + +CPPFLAGS= -march=x86-64 -mtune=generic -fPIC $(COMMON_INC) +CFLAGS= -O0 -g + +LDFLAGS= -L$(QT_DIR) -lQt5Core -lQt5Gui -lQt5Widgets -lemulatorqt -lm -lstdc++ #--specs=nosys.specs -Wl,--gc-sections + +#Finding Input files +CFILES=$(shell find . -maxdepth 1 -name '*.c') +COMMON_CFILES=$(shell find $(COMMON_DIR) -name '*.c') + +#Generate corresponding obj names +OBJS=$(patsubst ./%,$(OBJ_DIR)/%,$(CFILES:.c=.o)) +COMMON_OBJS=$(patsubst $(COMMON_DIR)/%,$(OBJ_DIR)/%,$(COMMON_CFILES:.c=.o)) + + +#Keep the objects files +.SECONDARY: $(OBJS) + +#Mark targets which are not "file-targets" +.PHONY: all clean qt + +# List of all binaries to build +all: $(BUILD_DIR)/$(TARGET) + +qt: + cd $(QT_DIR) && qmake &&make + +#objects to elf +$(BUILD_DIR)/$(TARGET): $(OBJS) $(COMMON_OBJS) |qt + @echo Linking... + $(MKDIR) $(BUILD_DIR) + $(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) + @echo $(COMMON_OBJS) + +#C files to objects +$(OBJ_DIR)/%.o: %.c + @echo Compiling $<... + $(MKDIR) $(OBJ_DIR) + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + +#common C files to objects +$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c + @echo Compiling Common file $<... + $(MKDIR) $(dir $(patsubst $(COMMON_DIR)/%,$(OBJ_DIR)/%, $<)) + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + + + +#Clean Obj files and builded stuff +clean: + $(RMDIR) $(BUILD_DIR) $(OBJ_DIR) + + diff --git a/emulator/main.c b/emulator/main.c new file mode 100644 index 0000000..0a8e2a6 --- /dev/null +++ b/emulator/main.c @@ -0,0 +1,9 @@ + +extern void qt_init(int argc, char* argv[]); +extern int qt_execute(); + + +int main(int argc, char* argv[]) { + qt_init(argc,argv); + return qt_execute(); +} diff --git a/emulator/qt/emulatorqt.pro b/emulator/qt/emulatorqt.pro new file mode 100644 index 0000000..fa7728f --- /dev/null +++ b/emulator/qt/emulatorqt.pro @@ -0,0 +1,26 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-04-02T22:09:26 +# +#------------------------------------------------- + +QT += widgets gui + +TARGET = emulatorqt +TEMPLATE = lib +CONFIG += staticlib + +SOURCES += \ + mainwindow.cpp \ + main.cpp \ + ll_tft.cpp +HEADERS += \ + mainwindow.h \ + + +INCLUDEPATH+= ../../common/lowlevel/ + + +FORMS += \ + mainwindow.ui + diff --git a/emulator/qt/ll_tft.cpp b/emulator/qt/ll_tft.cpp new file mode 100644 index 0000000..cbaea26 --- /dev/null +++ b/emulator/qt/ll_tft.cpp @@ -0,0 +1,17 @@ +#include "mainwindow.h" +#include +#include "ll_tft.h" + +MainWindow* mainwindow; + +bool ll_tft_init() { + qDebug() << "tft init done"; + mainwindow = new MainWindow(); + mainwindow->show(); + return true; + +} + +void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { + mainwindow->draw_line(x1,y1,x2,y2,color); +} diff --git a/emulator/qt/main.cpp b/emulator/qt/main.cpp new file mode 100644 index 0000000..8bb406c --- /dev/null +++ b/emulator/qt/main.cpp @@ -0,0 +1,31 @@ +#include +#include + + +extern "C" { + void qt_init(int argc, char* argv[]); + int qt_execute(); + void app_init(); + void app_process(); +} + +QApplication* app_ptr; + +void qt_init(int argc, char* argv[]) { + static QApplication app(argc,argv); + app_ptr = &app; + app_init(); +} + +void app_loop() { + while(1) { + app_process(); + QApplication::processEvents(); + } +} + +int qt_execute() { + + QtConcurrent::run(&app_loop); + return app_ptr->exec(); +} diff --git a/emulator/qt/mainwindow.cpp b/emulator/qt/mainwindow.cpp new file mode 100644 index 0000000..c17923b --- /dev/null +++ b/emulator/qt/mainwindow.cpp @@ -0,0 +1,50 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include + +QColor colorFromRGB565(uint16_t color) { + int R8 = (int) floor( (color>>(5+6)) * 255.0 / 31.0 + 0.5); + int G8 = (int) floor( ((color>>5)&0x2F) * 255.0 / 63.0 + 0.5); + int B8 = (int) floor( (color&0x1F) * 255.0 / 31.0 + 0.5); + return QColor::fromRgb(R8,G8,B8); + +} + + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + pixmap(320,240), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + +} + +void MainWindow::draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) +{ + + render_mutex.lock(); + QPainter painter(&(pixmap)); + painter.setPen(colorFromRGB565(color)); + painter.drawLine(x1,y1,x2,y2); + render_mutex.unlock(); +} + +void MainWindow::paintEvent(QPaintEvent *) +{ + render_mutex.lock(); + QPainter painter(this); + + painter.drawPixmap(100,100,pixmap); + painter.setPen(Qt::green); + painter.drawRect(100-1,100-1,320+2,240+2); + render_mutex.unlock(); +} + + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/emulator/qt/mainwindow.h b/emulator/qt/mainwindow.h new file mode 100644 index 0000000..d4313ca --- /dev/null +++ b/emulator/qt/mainwindow.h @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + void draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); +protected: + void paintEvent(QPaintEvent * evt); + + ~MainWindow(); + +private: + QMutex render_mutex; + QPixmap pixmap; + + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/emulator/qt/mainwindow.ui b/emulator/qt/mainwindow.ui new file mode 100644 index 0000000..1316486 --- /dev/null +++ b/emulator/qt/mainwindow.ui @@ -0,0 +1,45 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 10 + 10 + 81 + 22 + + + + PushButton + + + + + + + 0 + 0 + 800 + 19 + + + + + + + +