Make cppcheck happy
This commit is contained in:
parent
52ebe7e0c4
commit
0ad0a5a1d9
10
Makefile
10
Makefile
@ -37,7 +37,9 @@ C_FLAGS += -fpic
|
||||
|
||||
C_FLAGS += -O0 -g -Wall -Wextra -Werror
|
||||
CPP_FLAGS += $(addprefix -I, $(INCLUDES))
|
||||
CHECK_FLAGS = --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force
|
||||
|
||||
CHECK_FLAGS = $(addprefix -I,$(filter-out $(PREFIX)/include/,$(INCLUDES)))
|
||||
CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force
|
||||
|
||||
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
|
||||
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
|
||||
@ -64,8 +66,8 @@ install: all
|
||||
install -m 0644 inc/* $(INC_INSTALL_DIR)
|
||||
|
||||
uninstall:
|
||||
rm -f $(LIB_INSTALL_DIR)/$(STATIC_LIB)
|
||||
rm -f $(LIB_INSTALL_DIR)/$(DYNAMIC_LIB)
|
||||
rm -f $(LIB_INSTALL_DIR)/$(STATIC_LIB_FILE)
|
||||
rm -f $(LIB_INSTALL_DIR)/$(DYNAMIC_LIB_FILE)
|
||||
rm -f $(addprefix $(INC_INSTALL_DIR)/,$(shell ls inc))
|
||||
rm -rf $(INC_INSTALL_DIR)
|
||||
|
||||
@ -106,7 +108,7 @@ exec_unit_test: $(UNIT_TEST_TARGET)
|
||||
|
||||
.PHONY: check
|
||||
check: $(C_SRCS)
|
||||
$(CHECK) $(CPP_FLAGS) $(CHECK_FLAGS) $(C_SRCS)
|
||||
$(CHECK) $(CHECK_FLAGS) $(C_SRCS)
|
||||
|
||||
$(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE)
|
||||
@mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)
|
||||
|
23
src/i2c.c
23
src/i2c.c
@ -24,6 +24,8 @@ int i2c_open(const struct i2c_bb *i2c)
|
||||
|
||||
res = gpio_open(i2c->sda);
|
||||
res |= gpio_open(i2c->scl);
|
||||
res |= gpio_write(i2c->sda, 1);
|
||||
res |= gpio_write(i2c->scl, 1);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -40,6 +42,7 @@ int i2c_close(const struct i2c_bb *i2c)
|
||||
return res;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int i2c_read(const struct i2c_bb *i2c, uint8_t slave_addr, char *buffer, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -50,7 +53,7 @@ int i2c_read(const struct i2c_bb *i2c, uint8_t slave_addr, char *buffer, unsigne
|
||||
}
|
||||
|
||||
start_condition(i2c);
|
||||
write_byte(i2c, (slave_addr & 0x80));
|
||||
write_byte(i2c, (slave_addr << 1) | 1);
|
||||
for(i = 0; i < len; i++) {
|
||||
buffer[i] = read_byte(i2c, true);
|
||||
}
|
||||
@ -59,6 +62,7 @@ int i2c_read(const struct i2c_bb *i2c, uint8_t slave_addr, char *buffer, unsigne
|
||||
return (int)i;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int i2c_write(const struct i2c_bb *i2c, uint8_t slave_addr, const char *buffer, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -70,7 +74,7 @@ int i2c_write(const struct i2c_bb *i2c, uint8_t slave_addr, const char *buffer,
|
||||
}
|
||||
|
||||
start_condition(i2c);
|
||||
write_byte(i2c, (slave_addr & 0x7F));
|
||||
write_byte(i2c, slave_addr << 1);
|
||||
for(i = 0; i < len; i++) {
|
||||
write_byte(i2c, buffer[i]);
|
||||
}
|
||||
@ -79,8 +83,6 @@ int i2c_write(const struct i2c_bb *i2c, uint8_t slave_addr, const char *buffer,
|
||||
return (int)i;
|
||||
}
|
||||
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
static void start_condition(const struct i2c_bb *i2c)
|
||||
{
|
||||
assert( NULL != i2c);
|
||||
@ -94,7 +96,6 @@ static void start_condition(const struct i2c_bb *i2c)
|
||||
usleep(5);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
static void stop_condition(const struct i2c_bb *i2c)
|
||||
{
|
||||
assert( NULL != i2c);
|
||||
@ -107,7 +108,6 @@ static void stop_condition(const struct i2c_bb *i2c)
|
||||
usleep(5);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
static bool write_byte(const struct i2c_bb *i2c, uint8_t byte)
|
||||
{
|
||||
uint8_t ack, i;
|
||||
@ -124,7 +124,6 @@ static bool write_byte(const struct i2c_bb *i2c, uint8_t byte)
|
||||
return (bool)(ack & 0x01);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
static uint8_t read_byte(const struct i2c_bb *i2c, bool ack)
|
||||
{
|
||||
uint8_t res = 0, i;
|
||||
@ -139,7 +138,7 @@ static uint8_t read_byte(const struct i2c_bb *i2c, bool ack)
|
||||
if(ack) {
|
||||
write_bit(i2c, 0);
|
||||
} else {
|
||||
write_bit(i2c, 0);
|
||||
write_bit(i2c, 1);
|
||||
}
|
||||
|
||||
return res;
|
||||
@ -149,15 +148,15 @@ static void write_bit(const struct i2c_bb *i2c, uint8_t bit)
|
||||
{
|
||||
assert( NULL != i2c);
|
||||
|
||||
if((bit & 0x01) > 0) {
|
||||
if(bit > 0) {
|
||||
gpio_write(i2c->sda, 1);
|
||||
} else {
|
||||
gpio_write(i2c->sda, 1);
|
||||
gpio_write(i2c->sda, 0);
|
||||
}
|
||||
usleep(5);
|
||||
gpio_write(i2c->scl, 1);
|
||||
usleep(5);
|
||||
gpio_write(i2c->scl, 1);
|
||||
gpio_write(i2c->scl, 0);
|
||||
}
|
||||
|
||||
static uint8_t read_bit(const struct i2c_bb *i2c)
|
||||
@ -171,7 +170,7 @@ static uint8_t read_bit(const struct i2c_bb *i2c)
|
||||
gpio_write(i2c->scl, 1);
|
||||
usleep(5);
|
||||
gpio_read(i2c->sda, &res);
|
||||
gpio_write(i2c->scl, 1);
|
||||
gpio_write(i2c->scl, 0);
|
||||
|
||||
return (uint8_t) res;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user