From 40e4cc752bf1e9f6c8ca51b67e280f855a0dc7d3 Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sat, 15 Nov 2014 19:11:36 -0700 Subject: [PATCH 1/7] Fix gpio example. Commit c13df34dfd7 broke the gpio example. The gpio example was passing 0 for the freq which is no longer allowed in SetClock for mpsse modes. --- src/examples/gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/gpio.c b/src/examples/gpio.c index 326b626..70b05c0 100644 --- a/src/examples/gpio.c +++ b/src/examples/gpio.c @@ -7,7 +7,7 @@ int main(void) struct mpsse_context *io = NULL; int i = 0, retval = EXIT_FAILURE; - io = MPSSE(GPIO, 0, 0); + io = MPSSE(GPIO, 1, 0); if(io && io->open) { From ca84acd4c115e9f2b3a67c246f8a094b84b22380 Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sat, 15 Nov 2014 19:17:11 -0700 Subject: [PATCH 2/7] Fix spiflashfast example. The check for data being read would always succeed due to the test looking at the pointer of the data instead of the data pointed being pointed to. Now checks the first element of the data array. --- src/examples/spiflashfast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/spiflashfast.c b/src/examples/spiflashfast.c index 271d655..215f018 100644 --- a/src/examples/spiflashfast.c +++ b/src/examples/spiflashfast.c @@ -27,7 +27,7 @@ int main(void) FastRead(flash, data, SIZE); Stop(flash); - if(data) + if(*data) { fp = fopen(FOUT, "wb"); if(fp) From 4d187fd80ea00bc7b1e8ecf9a78a2616333d020e Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sun, 16 Nov 2014 14:46:49 -0700 Subject: [PATCH 3/7] Add git ignore file. --- .gitignore | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcc1bba --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +*.o +TAGS +tags +cscope.* + +.*.swp +.#* +*.bak +*~ + +/src/Makefile +/src/config.h +/src/config.log +/src/config.status +/src/libmpsse.a +/src/libmpsse.so + +/src/examples/bitbang +/src/examples/ds1305 +/src/examples/gpio +/src/examples/i2ceeprom +/src/examples/spiflash +/src/examples/spiflashfast From b0044aad28191021a98211c4aad773d0f36b97b8 Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sun, 16 Nov 2014 15:41:36 -0700 Subject: [PATCH 4/7] Fix memory leak in spiflash example. --- src/examples/spiflash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/examples/spiflash.c b/src/examples/spiflash.c index 2a86804..3447a4a 100644 --- a/src/examples/spiflash.c +++ b/src/examples/spiflash.c @@ -23,7 +23,7 @@ int main(void) data1 = Read(flash, SIZE); Stop(flash); - if(data) + if(data && data1) { fp = fopen(FOUT, "wb"); if(fp) @@ -35,9 +35,13 @@ int main(void) printf("Dumped %d bytes to %s\n", SIZE, FOUT); retval = EXIT_SUCCESS; } + } + if(data) free(data); - } + + if(data1) + free(data1); } else { From 3db068501bf25f0e0ee307dfe0edb7fb8549b387 Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sun, 16 Nov 2014 14:58:13 -0700 Subject: [PATCH 5/7] Enhance Makefile for examples. Add CFLAGS with '-g -Wall'. Compile and link using headers and library in build dir to allow building the examples without having to install the library. --- src/examples/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/examples/Makefile b/src/examples/Makefile index 1c03853..51ad472 100644 --- a/src/examples/Makefile +++ b/src/examples/Makefile @@ -1,4 +1,8 @@ -LDFLAGS=-lmpsse +CFLAGS = -g -Wall +CFLAGS += -I.. + +LDFLAGS = -L.. +LDFLAGS += -lmpsse all: spiflash spiflashfast i2ceeprom ds1305 gpio bitbang From 5f7f737f4d8fb518d0f7f6fd2092942cfd9bb188 Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sun, 16 Nov 2014 15:18:33 -0700 Subject: [PATCH 6/7] Change bitbang example to drive 8 pins. Loops over 8 pins toggling each pin on then off in turn. --- src/examples/bitbang.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/examples/bitbang.c b/src/examples/bitbang.c index 68e9ec6..d7ff97b 100644 --- a/src/examples/bitbang.c +++ b/src/examples/bitbang.c @@ -1,11 +1,14 @@ #include #include +#include #include int main(void) { struct mpsse_context *io = NULL; - int i = 0, retval = EXIT_FAILURE; + int retval = EXIT_FAILURE; + int i = 0; + int j = 0; io = MPSSE(BITBANG, 0, 0); @@ -13,13 +16,15 @@ int main(void) { for(i=0; i<10; i++) { - PinHigh(io, 0); - printf("Pin 0 is: %d\n", PinState(io, 0, -1)); - sleep(1); - - PinLow(io, 0); - printf("Pin 0 is: %d\n", PinState(io, 0, -1)); - sleep(1); + for (j=0; j<8; j++) + { + PinHigh(io, j); + printf("Pin %d is: %d\n", j, PinState(io, j, -1)); + usleep(100000); + + PinLow(io, j); + printf("Pin %d is: %d\n", j, PinState(io, j, -1)); + } } retval = EXIT_SUCCESS; From 42ee18dea770de27d256ad20a1ea5fe436ff230c Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Sun, 16 Nov 2014 15:27:47 -0700 Subject: [PATCH 7/7] Change gpio exampled to drive 4 bits. Loops over GPIOL0 -> GPIOL3, toggling each on then off in turn. --- src/examples/gpio.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/examples/gpio.c b/src/examples/gpio.c index 70b05c0..47aa87e 100644 --- a/src/examples/gpio.c +++ b/src/examples/gpio.c @@ -1,11 +1,13 @@ #include #include +#include #include int main(void) { struct mpsse_context *io = NULL; int i = 0, retval = EXIT_FAILURE; + int j; io = MPSSE(GPIO, 1, 0); @@ -13,13 +15,15 @@ int main(void) { for(i=0; i<10; i++) { - PinHigh(io, GPIOL0); - printf("GPIOL0 State: %d\n", PinState(io, GPIOL0, -1)); - sleep(1); + for (j=GPIOL0; j <= GPIOL3; j++) + { + PinHigh(io, j); + printf("GPIOL%d State: %d\n", j - GPIOL0, PinState(io, j, -1)); + usleep(100000); - PinLow(io, GPIOL0); - printf("GPIOL0 State: %d\n", PinState(io, GPIOL0, -1)); - sleep(1); + PinLow(io, j); + printf("GPIOL%d State: %d\n", j - GPIOL0, PinState(io, j, -1)); + } } retval = EXIT_SUCCESS;