1

When I took a look at how the arduino libraries were coded I expected to see register names like I/O registers(PINx,DDRx,PORTx) and other such registers with values assigned to them but instead I saw normal C code with functions and a class.

Why isn't there any embedded C in the structure of the library? Am I misunderstanding something very basic? Please help me understand.

asked Aug 23, 2018 at 9:07
0

2 Answers 2

1

If you take a look at the Arduino core library (e.g., the AVR version of wiring.c), you will see lots of low-level register access. That's why the core code is specific to a processor architecture.

Other libraries are built on top of the core API in order to be portable.

answered Aug 23, 2018 at 9:34
2
  • 1
    Then why do people even code using low-level registers when they can just use the core API? Commented Aug 23, 2018 at 10:00
  • 1
    @Roshan: 1. Performance: digitalWrite(), for example, is more than 100 times slower than direct port access. 2. Hardware features: the core only provides access to the most generic stuff, you can fully exploit the hardware capabilities only if you access the hardware directly. Commented Aug 23, 2018 at 10:05
0

Because the Arduino API abstracts those things.

If you put that kind of low-level code into a library the library becomes non-portable. By sticking to the Arduino API (digitalWrite, pinMode, etc) the library can be used on all boards.

answered Aug 23, 2018 at 9:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.