From 7d313f9f747cf3c98581571df7b92aa9dcb48fd1 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Thu, 20 Feb 2020 22:19:09 +0100 Subject: [PATCH] code re-organized --- .gitignore | 2 +- Makefile | 25 +++++++------ include/board.h | 8 +++++ {interface => include}/driver.h | 0 include/{posix => }/gpio.h | 0 include/{posix => }/i2c.h | 0 include/{ => platform}/posix/board.h | 6 ++-- include/{posix => }/spi.h | 0 sonar-project.properties | 16 +++++++++ src/{ => platform}/posix/gpio.c | 0 src/{ => platform}/posix/i2c.c | 2 +- src/{ => platform}/posix/spi.c | 0 src/st7789.c | 54 ---------------------------- 13 files changed, 43 insertions(+), 70 deletions(-) create mode 100644 include/board.h rename {interface => include}/driver.h (100%) rename include/{posix => }/gpio.h (100%) rename include/{posix => }/i2c.h (100%) rename include/{ => platform}/posix/board.h (98%) rename include/{posix => }/spi.h (100%) create mode 100644 sonar-project.properties rename src/{ => platform}/posix/gpio.c (100%) rename src/{ => platform}/posix/i2c.c (98%) rename src/{ => platform}/posix/spi.c (100%) diff --git a/.gitignore b/.gitignore index f6f63c7..289c8f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ bin/ obj/ - +.scannerwork/ diff --git a/Makefile b/Makefile index 3dc9c35..9815269 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +PLATFORM ?= posix CROSS_COMPILE ?= TARGET_FILE ?= test_c @@ -18,9 +19,8 @@ UNIT_TEST_OBJ_DIR = $(OBJ_DIR)/$(UNIT_TEST_SRC_DIR) PREFIX ?= /usr BIN_INSTALL_DIR = $(PREFIX)/bin -INCLUDES := interface/ INCLUDES += include/ -INCLUDES += include/$(ARCH)/ +INCLUDES += include/platform/$(PLATFORM)/ INCLUDES += $(PREFIX)/include/ INCLUDES += $(EXTRA_INC) @@ -39,12 +39,13 @@ C_FLAGS += -fpic C_FLAGS += -O0 -ggdb3 -Wall CPP_FLAGS += $(addprefix -I, $(INCLUDES)) +CPP_FLAGS += -DPLATFORM=$(PLATFORM) -DPLATFORM_$(PLATFORM) CHECK_FLAGS = $(addprefix -I,$(filter-out $(PREFIX)/include/,$(INCLUDES))) -CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force +CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force --xml --xml-version=2 2> cppcheck-report.xml C_SRCS = $(wildcard $(SRC_DIR)/*.c) -C_SRCS += $(wildcard $(SRC_DIR)/$(ARCH)/*.c) +C_SRCS += $(wildcard $(SRC_DIR)/platform/$(PLATFORM)/*.c) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) UNIT_TEST_SRCS = $(wildcard $(UNIT_TEST_SRC_DIR)/*.c) $(filter-out %main.c,$(CC_SRCS)) @@ -60,7 +61,7 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) debug: @echo $(C_SRCS) @echo $(C_OBJS) - @echo $(ARCH) + @echo $(PLATFORM) @echo $(CPP_FLAGS) all: $(TARGET) @@ -84,6 +85,12 @@ clean: distclean: rm -rf $(OBJ_DIR) $(BIN_DIR) $(COVERAGE_DIR) +.PHONY: check +check: $(C_SRCS) + echo $(C_SRCS) + cppcheck $(CHECK_FLAGS) $(C_SRCS) + + .PHONY: coverage coverage: _cov_genhtml $(eval COVERAGE:=$(shell grep 'lines' .coverage.tmp | egrep -o '[0-9]+.[0-9]+%')) @@ -110,10 +117,6 @@ build_unit_test: $(UNIT_TEST_TARGET) exec_unit_test: $(UNIT_TEST_TARGET) $(UNIT_TEST_TARGET) -.PHONY: check -check: $(CC_SRCS) - $(CHECK) $(CHECK_FLAGS) $(CC_SRCS) - $(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE) @mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR) $(CC) $(C_FLAGS) $(LD_FLAGS) $(UNIT_TEST_OBJS) -o $@ @@ -124,7 +127,7 @@ $(TARGET): $(OBJS) $(THIS_MAKEFILE) .PRECIOUS: $(OBJ_DIR)/%.d $(OBJ_DIR)/%.d: $(SRC_DIR)/%.c - @mkdir -p $(OBJ_DIR)/$(ARCH) + @mkdir -p $(OBJ_DIR)/platform/$(PLATFORM) $(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@) .PRECIOUS: $(UNIT_TEST_OBJ_DIR)/%.d @@ -133,7 +136,7 @@ $(UNIT_TEST_OBJ_DIR)/%.d: $(UNIT_TEST_SRC_DIR)/%.c $(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(CPP_FLAGS) $(patsubst $(UNIT_TEST_OBJ_DIR)/%.d,$(UNIT_TEST_SRC_DIR)/%.c,$@) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d - @mkdir -p $(OBJ_DIR)/$(ARCH) + @mkdir -p $(OBJ_DIR)/platform/$(PLATFORM) $(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@ $(UNIT_TEST_OBJ_DIR)/%.o: $(UNIT_TEST_SRC_DIR)/%.c $(UNIT_TEST_OBJ_DIR)/%.d diff --git a/include/board.h b/include/board.h new file mode 100644 index 0000000..1a0968a --- /dev/null +++ b/include/board.h @@ -0,0 +1,8 @@ +#ifndef __INCLUDE_BOARD_H__ +#define __INCLUDE_BOARD_H__ + +#ifdef PLATFORM_posix +#include "platform/posix/board.h" +#endif + +#endif diff --git a/interface/driver.h b/include/driver.h similarity index 100% rename from interface/driver.h rename to include/driver.h diff --git a/include/posix/gpio.h b/include/gpio.h similarity index 100% rename from include/posix/gpio.h rename to include/gpio.h diff --git a/include/posix/i2c.h b/include/i2c.h similarity index 100% rename from include/posix/i2c.h rename to include/i2c.h diff --git a/include/posix/board.h b/include/platform/posix/board.h similarity index 98% rename from include/posix/board.h rename to include/platform/posix/board.h index f6f3a63..330f05e 100644 --- a/include/posix/board.h +++ b/include/platform/posix/board.h @@ -1,8 +1,8 @@ -#ifndef __BOARD_H__ -#define __BOARD_H__ +#ifndef __INCLUDE_PLATFORM_POSIX_BOARD_H__ +#define __INCLUDE_PLATFORM_POSIX_BOARD_H__ #include "driver.h" -#include "posix/i2c.h" +#include "i2c.h" #include "ssd1306.h" #include "st7789.h" #include "gpio.h" diff --git a/include/posix/spi.h b/include/spi.h similarity index 100% rename from include/posix/spi.h rename to include/spi.h diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..c4c6cec --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,16 @@ +sonar-project.properties + +sonar.projectKey=my:test:project + +sonar.language=c +sonar.sources=src +sonar.cxx.includeDirectories=include + +# defaults to project key +#sonar.projectName=My project +# defaults to 'not provided' +#sonar.projectVersion=1.0 + +sonar.sourceEncoding=UTF-8 + +sonar.host.url=https://sonar.blackfinn.de diff --git a/src/posix/gpio.c b/src/platform/posix/gpio.c similarity index 100% rename from src/posix/gpio.c rename to src/platform/posix/gpio.c diff --git a/src/posix/i2c.c b/src/platform/posix/i2c.c similarity index 98% rename from src/posix/i2c.c rename to src/platform/posix/i2c.c index 283a23c..13fd885 100644 --- a/src/posix/i2c.c +++ b/src/platform/posix/i2c.c @@ -8,7 +8,7 @@ #include #include -#include "posix/i2c.h" +#include "i2c.h" int i2c_open(const struct driver *drv) { diff --git a/src/posix/spi.c b/src/platform/posix/spi.c similarity index 100% rename from src/posix/spi.c rename to src/platform/posix/spi.c diff --git a/src/st7789.c b/src/st7789.c index 7d94d75..1bc6e82 100644 --- a/src/st7789.c +++ b/src/st7789.c @@ -11,13 +11,6 @@ static void send_data_8bit(const struct driver *drv, uint8_t data); static void lcd_init(const struct driver *drv); static void lcd_set_windows(const struct driver *drv, uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end); -#if 0 -static void send_data_16bit(const struct driver *drv, uint16_t data); -static void lcd_clear(const struct driver *drv, uint16_t color); -static void lcd_display(const struct driver *drv, const uint16_t *image); -static void lcd_draw_pixel(const struct driver *drv, uint16_t x, uint16_t y, uint16_t color); -#endif - int st7789_open(const struct driver *drv) { assert(drv != NULL); @@ -221,50 +214,3 @@ static void lcd_set_windows(const struct driver *drv, uint16_t x_start, uint16_t send_cmd(drv, 0X2C); } - -#if 0 -static void send_data_16bit(const struct driver *drv, uint16_t data) -{ - assert(drv != NULL); - - struct st7789 *this = (struct st7789*)(drv->dev); - uint8_t buf[2] = {(data >> 8) & 0xff, data & 0xff}; - drv_write(this->dc, "1", 1); - drv_write(this->spi, (const char* )buf, 2); -} - -static void lcd_clear(const struct driver *drv, uint16_t color) -{ - assert(drv != NULL); - - struct st7789 *this = (struct st7789*)(drv->dev); - uint16_t image[this->height * this->width]; - - color = ((color << 8) & 0xff00) | (color >> 8); - for (uint16_t i = 0; i < this->height * this->width; i++) { - image[i] = color; - } - lcd_set_windows(drv, 0, 0, this->width, this->height); - drv_write(this->dc, "1", 1); - for(uint16_t i = 0; i < this->height; i++) { - drv_write(this->spi, (const char *)&image[i * this->width], this->width * 2); - } -} - -static void lcd_display(const struct driver *drv, const uint16_t *image) -{ - assert(drv != NULL); - struct st7789 *this = (struct st7789*)(drv->dev); - lcd_set_windows(drv, 0, 0, this->width, this->height); - drv_write(this->dc, "1", 1); - for (uint16_t i = 0; i < this->height; i++) { - drv_write(this->spi, (const char *)&image[i * this->width], this->width * 2); - } -} - -static void lcd_draw_pixel(const struct driver *drv, uint16_t x, uint16_t y, uint16_t color) -{ - lcd_set_windows(drv, x, y, x + 1, y + 1); - send_data_16bit(drv, color); -} -#endif