Author Topic: EEVacademy #4 - I2C Bit Banging  (Read 10490 times)

0 Members and 1 Guest are viewing this topic.

Offline EEVblogTopic starter

  • Administrator
  • *****
  • Posts: 37740
  • Country: au
    • EEVblog
EEVacademy #4 - I2C Bit Banging
« on: July 22, 2017, 02:33:13 am »
Bit-Banging an I²C port with David.

 
The following users thanked this post: SeanB, Barryg41, rx8pilot, hwj-d, pknoe3lh, kire9999

Offline pknoe3lh

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
  • Trust me I'm an engineer
    • My Homepage
Re: EEVacademy #4 - I2C Bit Banging
« Reply #1 on: July 22, 2017, 08:30:58 am »
Very very nice done  :clap: :clap: :clap:
I really like it!

The speed is right for me. I didn't want to change to another video (it happens a lot if I get bored)

The only think I'm missing is the timing in your code.  :-/O
« Last Edit: July 22, 2017, 10:27:06 am by pknoe3lh »
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: EEVacademy #4 - I2C Bit Banging
« Reply #2 on: July 22, 2017, 03:47:42 pm »
That pace was much better than the SPI talk.  For some stuff I was following pretty well and for other I had to really pay attention.  The coding fast forward was a bit of a blur, but I would probably watch that again with some stop-frame viewing along the way.  Some people will still find it a bit on the pacey side.

All in all - a very useful video ... and a confirmation of a value contributor to the EEVblog video library!
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: EEVacademy #4 - I2C Bit Banging
« Reply #3 on: July 22, 2017, 03:51:46 pm »
Very nice till the coding part. Watching someone add spaghetti code on screen is less watchable than first explain the needed functions and parts, you don't need an editor for that only more of the interactive animations.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: EEVacademy #4 - I2C Bit Banging
« Reply #4 on: July 22, 2017, 03:55:31 pm »
Good point about the code.

Watching somebody build it is a bit of a distraction.  There's a lot that goes on that doesn't add to the result - and can cause confusion.

All you really need is the finished source - and then be taken on a tour of it, followed by something demonstrating the testing.
 

Offline b_force

  • Super Contributor
  • ***
  • Posts: 1381
  • Country: 00
    • One World Concepts
Re: EEVacademy #4 - I2C Bit Banging
« Reply #5 on: July 22, 2017, 04:03:06 pm »
I still think the pace is to fast, I doubt if non-native speakers can follow it.
Feels like you're on a hurry. The viewer barely has time to think about what you just said.

Didn't enjoy it, sorry.
Watched only a couple of minutes of it.

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: EEVacademy #4 - I2C Bit Banging
« Reply #6 on: July 22, 2017, 05:03:29 pm »
I still think the pace is to fast, I doubt if non-native speakers can follow it.
Feels like you're on a hurry. The viewer barely has time to think about what you just said.

This is a very good point.

I'm a well-versed native speaker that has no issue with the pronunciation - and I was not given much time to absorb what was said.  I have little doubt that many non-native speakers would be overly challenged.

Also, I refer to a comment I made on the SPI video - that pauses are useful ... and necessary.  There was an improvement in this video, which was great - but there might be some room for a bit more.



All this needs to be taken with a grain of salt ... you are never going to please everyone.
 

Offline b_force

  • Super Contributor
  • ***
  • Posts: 1381
  • Country: 00
    • One World Concepts
Re: EEVacademy #4 - I2C Bit Banging
« Reply #7 on: July 22, 2017, 07:24:13 pm »
All this needs to be taken with a grain of salt ... you are never going to please everyone.
This is true, but than what is the audience?

For me personally it didn't sound like an explanation/class in something.
It sounded like someone with knowledge, sharing information to someone else with enough knowledge.
And still, I have been in the field long enough, but I still prefer to keep things as simple as possible.
(That was also one of Einsteins strengths, keep things simple)

Offline Craftplorer

  • Contributor
  • Posts: 12
  • Country: de
Re: EEVacademy #4 - I2C Bit Banging
« Reply #8 on: July 22, 2017, 10:15:00 pm »
Hi,
great video and very nice visualization.
I would like to see how you implemented the timings on an actual platform.
Can you post/upload the CCS code from the "Bit Banging SPI" video?
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 3478
  • Country: us
Re: EEVacademy #4 - I2C Bit Banging
« Reply #9 on: July 22, 2017, 10:22:23 pm »
To be absolutely truthful, the first time I saw the title of this thread, I read it as "EE Vasectomy" and wondered "what"?

The video is not bad, but perhaps a less confusing name for us dyslexic types might be better.  On the other hand, my mis-reading was the only reason I opened the thread, so leave it as is.

John
 

Offline kire9999

  • Newbie
  • Posts: 2
  • Country: us
Re: EEVacademy #4 - I2C Bit Banging
« Reply #10 on: July 22, 2017, 10:25:41 pm »
Thank you so much Dave2  :-+  :-+, I really enjoyed your video. BTW, any chance you can share your C++ project of this example?, I'm currently trying to learn C++ and would like to have an example like yours.

Thanks!
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: EEVacademy #4 - I2C Bit Banging
« Reply #11 on: July 22, 2017, 11:30:10 pm »
I still think the pace is to fast, I doubt if non-native speakers can follow it.
Feels like you're on a hurry. The viewer barely has time to think about what you just said.

Didn't enjoy it, sorry.
Watched only a couple of minutes of it.

I have not watched this, but generally speaking,  for a couple of other youtube channels I find the youtube speed  control very useful.  One i play at a faster speed because he has a v.e.r.y s.l.o.w natural speaking cadence with lots of long gaps, speeding up by half or even double speed makes it much more comfortable, one I play slower than normal because the concepts are often hard and she is sometimes just going way too fast for me to keep up, slowing down makes it easier to follow.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: EEVacademy #4 - I2C Bit Banging
« Reply #12 on: July 24, 2017, 05:00:29 am »
Thank you so much Dave2  :-+  :-+, I really enjoyed your video. BTW, any chance you can share your C++ project of this example?, I'm currently trying to learn C++ and would like to have an example like yours.

The link is in the video description:

https://gitlab.com/Sepps/generic-bitbang-library-v1

But looks a bit over-engineered to me. Would be easier for many viewers, if it were a simple Arduino script without all the C++ overhead and without the extra pin class etc., just the bit-banging part, which could be implemented with a few functions in one script. Also in the I2C class the implementation should not be in the header file, but in the cpp file, the Pin class is better. And it should be really demonstrated with real hardware, again, very easy with an Arduino, because then the viewer can reproduce it faster, without needing to learn the intricacies of an IDE (and Visual Studio is a big and complicated IDE, too).
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline b_force

  • Super Contributor
  • ***
  • Posts: 1381
  • Country: 00
    • One World Concepts
Re: EEVacademy #4 - I2C Bit Banging
« Reply #13 on: July 24, 2017, 08:39:24 am »
I still think the pace is to fast, I doubt if non-native speakers can follow it.
Feels like you're on a hurry. The viewer barely has time to think about what you just said.

Didn't enjoy it, sorry.
Watched only a couple of minutes of it.

I have not watched this, but generally speaking,  for a couple of other youtube channels I find the youtube speed  control very useful.  One i play at a faster speed because he has a v.e.r.y s.l.o.w natural speaking cadence with lots of long gaps, speeding up by half or even double speed makes it much more comfortable, one I play slower than normal because the concepts are often hard and she is sometimes just going way too fast for me to keep up, slowing down makes it easier to follow.
The speed control doesn't change the pace.
By that I mean pauses etc that the speaker implements to give the audience time to think about the things just said or to emphasize certain parts.
For that reason you can't expect the audience to do THAT by themselves, simply because they are the ones looking for information.

Second minor thing is that it feels very odd to slow down or speed up.

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #14 on: July 24, 2017, 04:49:48 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: pknoe3lh

Offline pknoe3lh

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
  • Trust me I'm an engineer
    • My Homepage
Re: EEVacademy #4 - I2C Bit Banging
« Reply #15 on: July 24, 2017, 04:54:37 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.

Oh nice i didn't know this existed ^^

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: EEVacademy #4 - I2C Bit Banging
« Reply #16 on: July 24, 2017, 04:57:30 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.

A source code comment says it does support it. But it doesn't support multi-master mode.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #17 on: July 25, 2017, 09:56:56 am »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.

Oh nice i didn't know this existed ^^

It's an essential part of the protocol. Not all slaves will respond instantly in hardware, some are software driven. There has to be a mechanism in the protocol to force the master to wait until slaves are ready.

eg. Atmel chips like the Tiny85 don't have full I2C in hardware but they do have a little hardware unit that can detect an I2C START and hold SCL low. This allows the chip to wake up from sleep mode or whatever else it needs to do before responding.

nb. In theory any clock pulse can be stretched by slaves, not just START.
 
The following users thanked this post: pknoe3lh

Offline Mike Warren

  • Supporter
  • ****
  • Posts: 437
  • Country: au
    • Personal Website
Re: EEVacademy #4 - I2C Bit Banging
« Reply #18 on: July 26, 2017, 12:43:47 am »
Is it normal to call this buss "I two C"?

I've called it "I squared C" for the last 100 years. (okay, slight exaggeration).

I do work in a vacuum (no other engineers around me) so I can conceive I might have got it wrong for all these years.
 

Offline Bud

  • Super Contributor
  • ***
  • Posts: 6911
  • Country: ca
Re: EEVacademy #4 - I2C Bit Banging
« Reply #19 on: July 26, 2017, 02:14:28 am »
Did not like the format and overly fast pace, could only handle the first 3 min, then turned off....will not be watching in this format.
Facebook-free life and Rigol-free shack.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #20 on: July 26, 2017, 12:03:46 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.
A source code comment says it does support it. But it doesn't support multi-master mode.
I found the code and it seems to support clock stretching indeed. What I hate about it is that the all the code is in the header file and the cpp file is empty  :palm: IMHO that is very bad coding style. The header file should describe the interface and not contain any code! Where did David learn to program? He should ask his money back  >:D
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline enz

  • Regular Contributor
  • *
  • Posts: 134
  • Country: de
Re: EEVacademy #4 - I2C Bit Banging
« Reply #21 on: July 26, 2017, 12:11:23 pm »

I found the code and it seems to support clock stretching indeed. What I hate about it is that the all the code is in the header file and the cpp file is empty  :palm: IMHO that is very bad coding style. The header file should describe the interface and not contain any code! Where did David learn to program? He should ask his money back  >:D


You know the difference between C source code and a C++ class regarding this issue?
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #22 on: July 26, 2017, 02:30:36 pm »
What I hate about it is that the all the code is in the header file and the cpp file is empty  :palm: IMHO that is very bad coding style. The header file should describe the interface and not contain any code! Where did David learn to program? He should ask his money back  >:D

In 2017 we prefer all the code in the .h file and no .cpp file at all.

Some IDEs even insist on it.
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 7765
  • Country: de
  • A qualified hobbyist ;)
Re: EEVacademy #4 - I2C Bit Banging
« Reply #23 on: July 26, 2017, 03:12:18 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.

A source code comment says it does support it. But it doesn't support multi-master mode.

AFAIK, there are two clock stretching variants, i.e. inter-bit and inter-byte.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8646
  • Country: gb
Re: EEVacademy #4 - I2C Bit Banging
« Reply #24 on: July 26, 2017, 03:17:42 pm »
Is it normal to call this buss "I two C"?

I've called it "I squared C" for the last 100 years. (okay, slight exaggeration).

I do work in a vacuum (no other engineers around me) so I can conceive I might have got it wrong for all these years.
In a vacuum nobody can hear what you call it. Outside a vacuum, "I squared C" was the original official Philips naming, and its still what the great majority of people say.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #25 on: July 26, 2017, 03:41:15 pm »

I found the code and it seems to support clock stretching indeed. What I hate about it is that the all the code is in the header file and the cpp file is empty  :palm: IMHO that is very bad coding style. The header file should describe the interface and not contain any code! Where did David learn to program? He should ask his money back  >:D
You know the difference between C source code and a C++ class regarding this issue?
What is the use of having a cpp file if it is empty? Also the cpp file is the one that gets compiled which is why you should put code into the cpp file and the definition in the .h(pp) file. If you look at how the compilation process works then you'd see that a .h file gets concatenated with the .c(pp) file before the c(pp) file gets compiled. Ergo every piece of code inside a .h file gets compiled for each file it is included in. That isn't very efficient!

Another point is that a .h file with a class definition and code combined doesn't make it easy to read which members the class has.
« Last Edit: July 26, 2017, 03:43:11 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #26 on: July 26, 2017, 04:05:13 pm »
Does the proposed code support clock stretching? From what I've seen from the video it doesn't seem to do so. To support clock stretching you'll need to wait until SCL actually goes high on the I/O pin.

A source code comment says it does support it. But it doesn't support multi-master mode.

AFAIK, there are two clock stretching variants, i.e. inter-bit and inter-byte.

It's all the same.

Any time the master releases the clock line a slave is allowed to hold it low and the master must wait for it go high before continuing.
 

Offline niekvs

  • Contributor
  • Posts: 48
Re: EEVacademy #4 - I2C Bit Banging
« Reply #27 on: July 27, 2017, 09:05:11 am »
What I hate about it is that the all the code is in the header file and the cpp file is empty  :palm: IMHO that is very bad coding style. The header file should describe the interface and not contain any code! Where did David learn to program? He should ask his money back  >:D

In 2017 we prefer all the code in the .h file and no .cpp file at all.

Some IDEs even insist on it.

Define "we"? And could you give your reasoning behind this, and why "in 2017" this is preferred, according to you? Which IDE's insist on this? Defining functions in the .h file implicitly inlines them, meaning your object code - should your compiler comply with this hint - gets copies of your functions wherever they are called. Now, this doesn't seem like a very good strategy, particularly in embedded development where space is generally at a premium. It can be done for very short functions, where the overhead of the call is larger than copying the function, or if you're working on some performance-critical part. But in general, function definitions should go in the .cpp file. Also in 2017.

In case you're joking and talking about the Arduino IDE: at least this isn't advertised as "C++", and note that viewers of something called "EEVacademy" may miss your sarcasm and actually implement your 'advice'.
« Last Edit: July 27, 2017, 09:12:28 am by niekvs »
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #28 on: July 27, 2017, 12:38:27 pm »
Define "we"? And could you give your reasoning behind this, and why "in 2017" this is preferred, according to you?

a) Within a compilation unit, I know at least two IDEs that are very unhappy if you include anything that doesn't have a ".h" extension. Apple Xcode and Android Studio. Visual studio also frowns upon it - the autocomplete doesn't suggest anything that doesn't have a ".h" extension if you start typing #include.

b) If there's more than one compilation unit in your project then code like that should be wrapped/abstracted, it shouldn't be exposed everywhere. This means the code will be #included within a compilation unit's ".cpp" file and therefore should be in a header file.

In case you're joking and talking about the Arduino IDE: at least this isn't advertised as "C++", and note that viewers of something called "EEVacademy" may miss your sarcasm and actually implement your 'advice'.

If you're going to use "No True Scotsman" as a preemptive strike then there doesn't seem much point in taking this further.
 

Offline niekvs

  • Contributor
  • Posts: 48
Re: EEVacademy #4 - I2C Bit Banging
« Reply #29 on: July 27, 2017, 01:04:09 pm »

a) Within a compilation unit, I know at least two IDEs that are very unhappy if you include anything that doesn't have a ".h" extension. Apple Xcode and Android Studio. Visual studio also frowns upon it - the autocomplete doesn't suggest anything that doesn't have a ".h" extension if you start typing #include.

b) If there's more than one compilation unit in your project then code like that should be wrapped/abstracted, it shouldn't be exposed everywhere. This means the code will be #included within a compilation unit's ".cpp" file and therefore should be in a header file.


You said "In 2017 we prefer all the code in the .h file and no .cpp file at all.". Your above points say something very different, regarding some IDEs being unhappy about including files with extensions other than '.h'. Sure, you generally #include header files (.h), not source files (.cpp). Are you saying that because you cannot include '.cpp' files, you have to put your function definitions in the '.h' file? I'm afraid I'm not following. Do you have experience with C++?

To expand on why you include .h files and not .cpp files, it relates to defining and declaring: you can define (non-static) functions or variables only once, but you can declare them more than once. So, you put the definitions in the .cpp file, and the declarations in the .h file. So that, when you include header files (possibly more than once), you don't break this rule.
« Last Edit: July 27, 2017, 01:24:50 pm by niekvs »
 

Offline jm_araujo

  • Regular Contributor
  • *
  • Posts: 72
  • Country: pt
Re: EEVacademy #4 - I2C Bit Banging
« Reply #30 on: July 27, 2017, 01:56:50 pm »
David in the 'SPI.h' on the repository left only the declarations, the definitions are in 'SPI.cpp'.
At least it could be agreed that there's no coding style consistency.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #31 on: July 27, 2017, 06:42:34 pm »
a) Within a compilation unit, I know at least two IDEs that are very unhappy if you include anything that doesn't have a ".h" extension. Apple Xcode and Android Studio. Visual studio also frowns upon it - the autocomplete doesn't suggest anything that doesn't have a ".h" extension if you start typing #include.

b) If there's more than one compilation unit in your project then code like that should be wrapped/abstracted, it shouldn't be exposed everywhere. This means the code will be #included within a compilation unit's ".cpp" file and therefore should be in a header file.
I think you got a few things mixed up here! IDE's not wanting to include anything else than .h files doesn't mean code should be in .h files. If you want to use code from a.c in b.c you should link a.o and b.o into a_and_b_linked.bin and not try to include a.c into b.c. I know some programmers do the latter but it is very bad coding practise.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: pknoe3lh

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: EEVacademy #4 - I2C Bit Banging
« Reply #32 on: July 27, 2017, 10:54:48 pm »
Saw this:
"// yes, yes, yes, this is windows specific and silly"

 ;D  :-+

(remember YT comment?)  ;)
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #33 on: July 28, 2017, 09:23:55 am »
I think you got a few things mixed up here!

Nope.

IDE's not wanting to include anything else than .h files doesn't mean code should be in .h files. If you want to use code from a.c in b.c you should link a.o and b.o into a_and_b_linked.bin and not try to include a.c into b.c. I know some programmers do the latter but it is very bad coding practise.

For libraries like this one it's much easier to copy a .h file over and #include it in the main file than it is to copy two files over and start messing around with the linker. This is especially true when you need to work on multiple platforms and would need to mess around with the linker multiple times.

Leave the "separate interface and implementation" for big, long-term development, not little projects where you just want to pull a few libraries together as fast as possible. I'll take a big #include ".h" file over "download 50 files along with an out-of-date makefile and try to turn then into a working .lib file" any day of the week.

 

Offline niekvs

  • Contributor
  • Posts: 48
Re: EEVacademy #4 - I2C Bit Banging
« Reply #34 on: July 28, 2017, 10:48:53 am »
I think you got a few things mixed up here!

Nope.

IDE's not wanting to include anything else than .h files doesn't mean code should be in .h files. If you want to use code from a.c in b.c you should link a.o and b.o into a_and_b_linked.bin and not try to include a.c into b.c. I know some programmers do the latter but it is very bad coding practise.

For libraries like this one it's much easier to copy a .h file over and #include it in the main file than it is to copy two files over and start messing around with the linker. This is especially true when you need to work on multiple platforms and would need to mess around with the linker multiple times.

Leave the "separate interface and implementation" for big, long-term development, not little projects where you just want to pull a few libraries together as fast as possible. I'll take a big #include ".h" file over "download 50 files along with an out-of-date makefile and try to turn then into a working .lib file" any day of the week.

Hmm.. well, if the act of copying files is the main bottleneck in your project, you may have a point. But as soon as you have to use these files, it will quickly become a problem. For one, as I already mentioned before, your embedded project will quickly need an MCU with a bigger flash size as the implicit inlining can copy your functions wherever they are called from. Also, in case you need to include these files from multiple locations, you may alternatively run into multiple definition linker errors depending on if said .h file has any definitions outside of the class body.

Basically, giving up good coding practices for the sake of 'easy copying' is a really bad idea. What if your project evolves into something bigger: you want to then split up and rewrite all those .h files and add .cpp files? Maybe for hacking some throw-away stuff together it could be ok, but that's about it.

And your main statement about "In 2017 we prefer all the code in the .h file and no .cpp file at all." is just plain wrong, sorry. If you change 'we' to 'I', then it's fine of course :P
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #35 on: July 28, 2017, 08:45:11 pm »
I think you got a few things mixed up here!
Nope.

IDE's not wanting to include anything else than .h files doesn't mean code should be in .h files. If you want to use code from a.c in b.c you should link a.o and b.o into a_and_b_linked.bin and not try to include a.c into b.c. I know some programmers do the latter but it is very bad coding practise.

For libraries like this one it's much easier to copy a .h file over and #include it in the main file than it is to copy two files over and start messing around with the linker. This is especially true when you need to work on multiple platforms and would need to mess around with the linker multiple times.

Leave the "separate interface and implementation" for big, long-term development, not little projects where you just want to pull a few libraries together as fast as possible. I'll take a big #include ".h" file over "download 50 files along with an out-of-date makefile and try to turn then into a working .lib file" any day of the week.
See, you are mixing things up! You can copy the .c files from the 'library' into your project and include the toplevel.h file into your own toplevel.h to make it work.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 16653
  • Country: 00
Re: EEVacademy #4 - I2C Bit Banging
« Reply #36 on: July 28, 2017, 10:12:01 pm »
See, you are mixing things up! You can copy the .c files from the 'library' into your project and include the toplevel.h file into your own toplevel.h to make it work.

It's much easier to not even have a toplevel.h for this sort of work. Just put the 'modules' in .h files and #include them all in main.cpp.



 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: EEVacademy #4 - I2C Bit Banging
« Reply #37 on: July 28, 2017, 11:19:33 pm »
See, you are mixing things up! You can copy the .c files from the 'library' into your project and include the toplevel.h file into your own toplevel.h to make it work.
It's much easier to not even have a toplevel.h for this sort of work. Just put the 'modules' in .h files and #include them all in main.cpp.
It is not easier but you just aren't at the point where you see this way of working is asking for major problems if your projects get bigger. It also shows a severe lack of insight in how a C compiler works and how to leverage the power an IDE provides. You don't need to concatenate/include everything in one file to make life easy. The way you work the compiler has to compile all the code if you make one change. When working on a big project this can take a while.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: EEVacademy #4 - I2C Bit Banging
« Reply #38 on: July 29, 2017, 01:33:30 am »
When I first started programming in a commercial environment, it was using IBM assembler on a mainframe.  (Don't worry Dave, I'm not about to claim you can write applications faster in assembler than you can in higher level languages.  You can't.  You can write tight code, fast code in the smallest possible executable - if you are good enough - but you can't write it more quickly.)

What I will say is that, back then, you HAD to be disciplined to have any chance of a practical solution.  The first company I worked for was a national concern with branches across the country - and their entire company database was held on a single disk pack of 70MB capacity.

These days - you have microprocessors that are insanely cheap and can run rings around what was available back then.  Space is not nearly as much of an issue - and efficiency of code is not as essential as it once was.

The bottom line is - for many applications, you don''t HAVE to be disciplined or efficient ... and in those cases, a less than Fortune 500 "one-up compile" approach is quite adequate.

Where you will get into trouble with a less disciplined approach is where you have a complex system of multiple functional units that get used in varying combinations and/or cross platform.  In environments such as that, a structured, disciplined approach is essential.  Could you imagine version control without it?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf