Refactored Project Structure for use with emulator
This commit is contained in:
15
common/app/app.c
Normal file
15
common/app/app.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "app.h"
|
||||
#include "tft.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void app_init() {
|
||||
tft_init();
|
||||
|
||||
tft_draw_line(10,10,30,40,0b11111);
|
||||
|
||||
}
|
||||
|
||||
void app_process() {
|
||||
/// printf("hello world\n");
|
||||
|
||||
}
|
||||
2
common/app/app.h
Normal file
2
common/app/app.h
Normal file
@@ -0,0 +1,2 @@
|
||||
void app_init();
|
||||
void app_process();
|
||||
0
common/filesystem/filesystem.h
Normal file
0
common/filesystem/filesystem.h
Normal file
14
common/lowlevel/ll_tft.h
Normal file
14
common/lowlevel/ll_tft.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#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
|
||||
|
||||
13
common/tft/tft.c
Normal file
13
common/tft/tft.c
Normal file
@@ -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);
|
||||
}
|
||||
5
common/tft/tft.h
Normal file
5
common/tft/tft.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#include<stdbool.h>
|
||||
#include<stdint.h>
|
||||
|
||||
bool tft_init();
|
||||
void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
0
common/touch/touch.h
Normal file
0
common/touch/touch.h
Normal file
8
emulator/.gitignore
vendored
Normal file
8
emulator/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
build
|
||||
obj
|
||||
*.user
|
||||
qt/*.o
|
||||
qt/*.a
|
||||
qt/ui_*
|
||||
qt/moc_*
|
||||
qt/Makefile
|
||||
71
emulator/Makefile
Normal file
71
emulator/Makefile
Normal file
@@ -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)
|
||||
|
||||
|
||||
9
emulator/main.c
Normal file
9
emulator/main.c
Normal file
@@ -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();
|
||||
}
|
||||
26
emulator/qt/emulatorqt.pro
Normal file
26
emulator/qt/emulatorqt.pro
Normal file
@@ -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
|
||||
|
||||
17
emulator/qt/ll_tft.cpp
Normal file
17
emulator/qt/ll_tft.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
#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);
|
||||
}
|
||||
31
emulator/qt/main.cpp
Normal file
31
emulator/qt/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <QApplication>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
50
emulator/qt/mainwindow.cpp
Normal file
50
emulator/qt/mainwindow.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
30
emulator/qt/mainwindow.h
Normal file
30
emulator/qt/mainwindow.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMutex>
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
45
emulator/qt/mainwindow.ui
Normal file
45
emulator/qt/mainwindow.ui
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user