diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0f8ec0a..c84836f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -20,6 +20,23 @@ "isDefault": true } }, + { + "label": "check", + "type":"shell", + "command": "make check -j4", + "problemMatcher": { + "base": "$gcc", + "owner": "gcc", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ] + }, + "group": { + "kind": "build", + "isDefault": true + } + }, { "label": "clean", "type":"shell", diff --git a/Makefile b/Makefile index 6977947..c687448 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ TARGET_FILE ?= test CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)cpp +CHECK = cppcheck SRC_DIR = src OBJ_DIR = obj @@ -22,6 +23,7 @@ endif LD_FLAGS := C_FLAGS := -O0 -g -Wall -Wextra -Werror CPP_FLAGS := $(addprefix -I, $(INCLUDES)) +CHECK_CLAGS := --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS))) @@ -34,6 +36,10 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) .PHONY: all all: $(TARGET) +.PHONY: check +check: $(C_SRCS) + $(CHECK) $(CPP_FLAGS) $(CHECK_CLAGS) $(C_SRCS) + $(TARGET): $(OBJS) $(THIS_MAKEFILE) @mkdir -p $(BIN_DIR) $(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@ diff --git a/src/gpio.c b/src/gpio.c index c39f8d0..e87b8d8 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -108,12 +108,14 @@ int gpio_read(const struct gpio *gpio, unsigned int *value) int gpio_write(const struct gpio *gpio, unsigned int value) { int res; - unsigned char mask = gpio->ftdi_dev->status_mask; + unsigned char mask; if(NULL == gpio) { return EXIT_FAILURE; } + mask = gpio->ftdi_dev->status_mask; + if(value == 0) { mask &= ~(unsigned char)(gpio->pin); } @@ -135,13 +137,13 @@ int gpio_write(const struct gpio *gpio, unsigned int value) int gpio_toggle(const struct gpio *gpio) { int res; - unsigned char mask = gpio->ftdi_dev->status_mask; + unsigned char mask; if(NULL == gpio) { return EXIT_FAILURE; } - mask ^= (unsigned char)(gpio->pin); + mask = (gpio->ftdi_dev->status_mask) ^ (unsigned char)(gpio->pin); res = ftdi_write_data(gpio->ftdi_dev->ftdi, &mask, 1); if(res < 0) {