Efficient peripheral configuration library

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For those, who:

  • likes clear source code and efficient compiled code,
  • got tired of messy DDRB = (DDRB & ~(1 << PIN0)) | (1 << PIN1) | (1 << PIN3) ... stuff,
  • not afraid of using C++ for embedded software,

please check out my new library.

 

Usage example:

initializer<
    portB<0>::input_floating,
    portB<1>::input_pullup,
    portB<2>::input_floating,
    portB<3>::output_high,
    portB<4>::output_low,
    portB<5>::output_low,
    portB<6>::input_pullup,
    portB<7>::input_floating
>::perform();

compiles to:

ldi r24, 0x4A
out PORTB, r24
ldi r24, 0x38
out DDRB, r24

Constructive criticism is encouraged.

Have both efficient implementation and comprehensive source code for peripherals configuration with my library: https://github.com/ichthuss/opti_init

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I use assembler so I bypass all the stuff that compiles down to asm anyway... why the aggravation? devil

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. May 12, 2019 - 06:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
I use assembler so I bypass all the stuff that compiles down to asm anyway... why the aggravation? devil

If you're using asm, then you are OK with code that requires some effort to read. No problem with it at all, it's totally OK, and it's a matter of taste anyway. But if one's using C/C++ and can get easy-to-read code for free, why not to have it?

 

GPIO settings is a relatively simple case. If you have an initialization code for some complicated peripheral device with half a dozen registers and bit fields messed across these registers, using my library may change your code from "needs 15-20 minutes of careful reading of datasheets to understand" to "understandable at once". It may be really helpful if someone other reads your code, or if you try to read your own code after a couple of years. And it typically reduces number of mistakes made during development or refactoring.

 

Edit: spelling

Have both efficient implementation and comprehensive source code for peripherals configuration with my library: https://github.com/ichthuss/opti_init

Last Edited: Sun. May 12, 2019 - 05:17 PM