diff --git a/.gitignore b/.gitignore index 1f00731..984d393 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o +*.d ssd1306_bin diff --git a/Makefile b/Makefile index 1db20aa..bd8c809 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,25 @@ CC=gcc -CFLAGS=-I ./ +CFLAGS=-I ./ -Wall -Werror LDFLAGS=-static OBJS=main.o ssd1306.o linux_i2c.o BIN=ssd1306_bin -%.o:%.c - $(CC) -c -o $@ $< $(CFLAGS) +default: $(BIN) +.PHONY: default clean + +# Adapted from scottmcpeak.com/autodepend/autodepend.html +-include $(OBJS:.o=.d) +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $*.o + $(CC) -MM $(CFLAGS) $< > $*.d + @cp -f $*.d $*.d.tmp + @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ + sed -e 's/^ *//' -e 's/$$/:/' >> $*.d + @rm -f $*.d.tmp $(BIN):$(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) clean: - rm -f ./*.o $(BIN) + rm -f *.o *.d $(BIN) diff --git a/linux_i2c.c b/linux_i2c.c index fcfa337..be95154 100644 --- a/linux_i2c.c +++ b/linux_i2c.c @@ -52,8 +52,7 @@ uint8_t _i2c_write(uint8_t* ptr, int16_t len) if (file_i2c == 0 || ptr == 0 || len <= 0) return 1; - int32_t rc; - rc = write(file_i2c, ptr, len); + write(file_i2c, ptr, len); return 0; } @@ -63,8 +62,7 @@ uint8_t _i2c_read(uint8_t *ptr, int16_t len) if (file_i2c == 0 || ptr == 0 || len <= 0) return 1; - int32_t rc; - rc = read(file_i2c, ptr, len); + read(file_i2c, ptr, len); return 0; } diff --git a/main.c b/main.c index 1b0ec69..c1ffc2f 100644 --- a/main.c +++ b/main.c @@ -30,9 +30,9 @@ int main(int argc, char **argv) uint8_t i2c_node_address = 0; int x = -1; int y = -1; - uint8_t line[25] = {0}; - uint8_t msg[200] = {0}; - uint8_t oled_type[10] = {0}; + char line[25] = {0}; + char msg[200] = {0}; + char oled_type[10] = {0}; int clear_line = -1; int clear_all = -1; int orientation = -1; diff --git a/ssd1306.c b/ssd1306.c index 2590b7c..a03674a 100644 --- a/ssd1306.c +++ b/ssd1306.c @@ -12,10 +12,9 @@ #include #include -const uint8_t init_oled_type_file[] = "/tmp/.ssd1306_oled_type"; +const char init_oled_type_file[] = "/tmp/.ssd1306_oled_type"; static uint8_t data_buf[1024]; -static int16_t data_len = 0; static uint8_t max_lines = 0; static uint8_t max_columns = 0; static uint8_t global_x = 0; @@ -309,7 +308,7 @@ uint8_t ssd1306_oled_default_config(uint8_t oled_lines, uint8_t oled_columns) return _i2c_write(data_buf, i); } -uint8_t ssd1306_oled_write_line(uint8_t size, uint8_t* ptr) +uint8_t ssd1306_oled_write_line(uint8_t size, char* ptr) { uint16_t i = 0; uint16_t index = 0; @@ -357,16 +356,16 @@ uint8_t ssd1306_oled_write_line(uint8_t size, uint8_t* ptr) return _i2c_write(data_buf, i); } -uint8_t ssd1306_oled_write_string(uint8_t size, uint8_t* ptr) +uint8_t ssd1306_oled_write_string(uint8_t size, char* ptr) { uint8_t rc = 0; if (ptr == 0) return 1; - uint8_t* line = 0; - uint8_t* cr = 0; - uint8_t buf[20]; + char* line = 0; + char* cr = 0; + char buf[20]; line = ptr; do { diff --git a/ssd1306.h b/ssd1306.h index a85d333..cfb3687 100644 --- a/ssd1306.h +++ b/ssd1306.h @@ -75,8 +75,8 @@ uint8_t ssd1306_oled_set_Y(uint8_t y); uint8_t ssd1306_oled_set_XY(uint8_t x, uint8_t y); uint8_t ssd1306_oled_set_rotate(uint8_t degree); uint8_t ssd1306_oled_default_config(uint8_t oled_lines, uint8_t oled_columns); -uint8_t ssd1306_oled_write_line(uint8_t size, uint8_t* ptr); -uint8_t ssd1306_oled_write_string(uint8_t size, uint8_t* ptr); +uint8_t ssd1306_oled_write_line(uint8_t size, char* ptr); +uint8_t ssd1306_oled_write_string(uint8_t size, char* ptr); uint8_t ssd1306_oled_clear_line(uint8_t row); uint8_t ssd1306_oled_clear_screen(); uint8_t ssd1306_oled_save_resolution(uint8_t column, uint8_t row);