mmarchetti / DirectIO

Fast, simple I/O library for Arduino
GNU Lesser General Public License v3.0
115 stars 27 forks source link

Using PORT_D for one pin #14

Closed mathgcosta closed 5 years ago

mathgcosta commented 6 years ago

Hi,

I'm using atmega328P-AU standalone (the same used in arduino nano boards) and I would like to know if its possible declare, for example,

Output<2> my_output;

as

OutputPort<PORT_D, 2> my_output;

Or, declare a output pin passing the AVR PORT name, rather than look up equivalent Arduino pin, as reference:

image

Thanks!

mmarchetti commented 6 years ago

You can try using an OutputPort; I'd be interested to know whether a 1-bit port ends up generating the same code. Or you could add a new board type with the associated port-pin mapping in ports.h, which would allow you to use the normal Input and Output classes.

mathgcosta commented 6 years ago

Wow,

Great idea. I'll do that. Thanks a lot.

mathgcosta commented 6 years ago

Hey,

I did this implementation but something is going wrong (the led doesn't blinked and there wasn't compilation error)

Here is your original port.h: image

And here is what I wrote below: image

Can you see some wrong with it?

mmarchetti commented 6 years ago

That looks reasonable, provided it matches your board pinout and you have wired the correct pin.

mathgcosta commented 6 years ago

Yeah,

But doesn't work any output pin on the board, neither blink led nor something else =/ And all wires are correct. The same code using Arduino pins works, that new implementation don't.

mmarchetti commented 6 years ago

Just checking, is ARDUINO_AVR_NANO defined?

mathgcosta commented 6 years ago

You mean, when I compile the code? Like here:

image

On ports.h file I just removed defined (ARDUINO_AVR_NANO) || \ from here image

and added a new #elif defined (ARDUINO_AVR_NANO) statement, as I posted before.

mmarchetti commented 6 years ago

OK, that seems right... just wanted to be sure it was actually defined at compile time so it would use the correct definitions. (you can always verify by putting a #warning statement there). And your code is using pin 32 (Output<32> my_output)?

mathgcosta commented 6 years ago

Hi @mmarchetti. Sorry for delayed answer, I got so stuffs to do last month and so. I'm not using pin32, why? I'll do using #warning and check how it goes.

mmarchetti commented 6 years ago

@mathgcosta, You mentioned a compile error - would you post it here? It would also be good if you can post a code section where you are using the Input or Output class.

mmarchetti commented 5 years ago

Closing this for now, if more details become available we can reopen.