mmarchetti / directio Goto Github PK
View Code? Open in Web Editor NEWFast, simple I/O library for Arduino
License: GNU Lesser General Public License v3.0
Fast, simple I/O library for Arduino
License: GNU Lesser General Public License v3.0
How do I do this using DirectIO?
pinMode(ESP_RESET_PIN, OUTPUT);
digitalWrite(ESP_RESET_PIN, LOW);
delay(50);
digitalWrite(ESP_RESET_PIN, HIGH);
delay(50);
pinMode(ESP_RESET_PIN, INPUT);
base.h file has no include guards (#ifndef xxx #define xxx). I'm not entirely sure this will cause problems because this file doesn't have much in it. But I would add it as a precaution anyway.
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:
Thanks!
Hi
As the title says: the file boards/avr/micro.h is missing.
My workaround was creating a symbolic link to boards/avr/leonardo.h, I suppose it would contain identical code.
Thanks for the nice library and best regards.
Lukas
Hi,
DirectIO no longer compiles under the new avr board definitions v1.6.9 released with IDE 1.6.6
Could you please have a look?
Here is the output for the first example:
`Arduino: 1.6.6 (Windows 8.1), Board: "Arduino/Genuino Uno"
In file included from C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/DirectIO.h:23:0,
from C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO\examples\direct_io\direct_io.ino:1:
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:56:22: error: field initializer is not constant
_define_port(PORT_B, PINB, PORTB, DDRB);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:46:31: note: in definition of macro '_define_port'
static const u16 in = IN_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:56:28: error: field initializer is not constant
_define_port(PORT_B, PINB, PORTB, DDRB);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:47:32: note: in definition of macro '_define_port'
static const u16 out = OUT_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:56:35: error: field initializer is not constant
_define_port(PORT_B, PINB, PORTB, DDRB);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:48:32: note: in definition of macro '_define_port'
static const u16 dir = DIR_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:60:22: error: field initializer is not constant
_define_port(PORT_C, PINC, PORTC, DDRC);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:46:31: note: in definition of macro '_define_port'
static const u16 in = IN_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:60:28: error: field initializer is not constant
_define_port(PORT_C, PINC, PORTC, DDRC);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:47:32: note: in definition of macro '_define_port'
static const u16 out = OUT_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:60:35: error: field initializer is not constant
_define_port(PORT_C, PINC, PORTC, DDRC);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:48:32: note: in definition of macro '_define_port'
static const u16 dir = DIR_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:64:22: error: field initializer is not constant
_define_port(PORT_D, PIND, PORTD, DDRD);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:46:31: note: in definition of macro '_define_port'
static const u16 in = IN_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:64:28: error: field initializer is not constant
_define_port(PORT_D, PIND, PORTD, DDRD);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:47:32: note: in definition of macro '_define_port'
static const u16 out = OUT_REG; \
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:64:35: error: field initializer is not constant
_define_port(PORT_D, PIND, PORTD, DDRD);
^
C:\Users\arkhi_000\Documents\Arduino\libraries\DirectIO/ports.h:48:32: note: in definition of macro '_define_port'
static const u16 dir = DIR_REG; \
^
exit status 1
Error compiling.`
The current port mapping scheme doesn't work on Arduino ARM variants (currently the Due board). The Arduino ARM libraries do a lot of work per I/O transaction, some of which can be moved into initialization as is done here. Also there are clearly opportunities for inlining, which not only eliminates function call overhead but can often eliminate one branch of an if/else entirely by evaluating the condition at compile time.
Hi,
I try to add this library to IDE 1.6.12 on a Mac but I can't. This message is always coming up.
Do you know why? This is the first time that I see this warning.
Arduino: 1.6.12 (Mac OS X), Board: "Arduino/Genuino Uno"
Specified folder/zip file does not contain a valid library
Thx for your help!
Jonathan
Hi i really love the approach you have taken on dynamic sockets.
I noticed that it only works with Socket.IO 1.x.
Are you planning to upgrade it beyond version 2.x?
Could you point on hookups wor such an update?
I could maybe help coding (with my humble knowledge)
regards
Theo
Hi @mmarchetti,
When I use OutputLow syntax it shows this error message:
error: 'OutputLow' does not name a type
I check on DirecIO.h header and didn't saw any implementation of these.
I tried to implement OutputLow class based on Output, and the result was:
I don't know if is in the best implementation, but it works.
How would I pass a pin into a function?
#include <DirectIO.h>
Output<2> pin;
void togglePin(Output pinObject){
pinObject.toggle();
}
Hi all
How to use this library ??
Want to control all port C pins on and off with loop and delay but I am not understanding how with Arduino due
` // Define a 4-bit port starting at port C2.
// This will control C2, C3, C4, C5 (pins 16-19).
OutputPort<PORT_C, 2, 4> my_port;
void setup()
{
my_port.setup();
}
void loop()
{
// Turn on C2 (pin 16), and turn off the rest.
my_port = 0x01;
} `
Thanks in advance
Hello,
I am curious about what would need to be done in order for me to add Teensy 3.2/3.1 support.
I have a Teensy 3.2 I can test with, which has the same underlying hardware as the 3.1 aside from the 3.1 being 3.3v-only.
Kind regards.
Constructor definitions of OutputPin and InputPin classes are not marked as inline.
Definition of write method in OutputPin class is not marked inline.
This causes problems if you want to include this library in some other header file (needed if InputPin or OutputPin objects are composed into another class). Compiler complains about multiple definition errors of these symbols.
In order to fix this, please mark OutputPin class constructor definition, InputPin class constructor definition and OutputPin::write method as inline.
Specifically add "inline" keyword to lines: 185, 196 and 210 of DirectIO.h
DirectIO.h defines _SFR_ASM_COMPAT, which causes register definitions to be integer addresses instead of references to the actual port (e.g. SREG defined as 0x3F instead of *(uint8_t*) 0x3F)
. This breaks some other uses, e.g. the ATOMIC_RESTORESTATE macro in util/atomic.h. DirectIO should restore the normal definitions at the end of its include file.
I'm trying to use OutputPin to declare a pin as output on runtime. But I get error: expected ';' before 'k'
when trying to compile. It seems like a silly syntax error but I don't see how. if I remove k
I get no default constructor exists for class "OutputPin"
Below are my functions and logs
int getThmstAnlgRaw(int analogPin, u8 pwrPin){
OutputPin(pwrPin) k;
int reading = analogRead(analogPin);
return reading;
}
The terminal process "C:\Users\simeon.ramjit\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
> Executing task: C:\Users\simeon.ramjit\.platformio\penv\Scripts\platformio.exe run <
Processing controllino_maxi_automation (platform: atmelavr; board: controllino_maxi_automation; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/controllino_maxi_automation.html
PLATFORM: Atmel AVR (3.0.0) > Controllino Maxi Automation
HARDWARE: ATMEGA2560 16MHz, 8KB RAM, 248KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- framework-arduino-avr 5.1.0
- toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <CONTROLLINO> 3.0.5
| |-- <SPI> 1.0
|-- <DirectIO> 1.2.0
|-- <Blynk> 0.6.7
| |-- <Ethernet> 2.0.0
| | |-- <SPI> 1.0
|-- <Ethernet> 2.0.0
| |-- <SPI> 1.0
|-- <TimerInterrupt> 1.0.2
|-- <SPI> 1.0
Building in release mode
Compiling .pio\build\controllino_maxi_automation\src\main.cpp.o
src\main.cpp: In function 'int getThmstAnlgRaw(int, u8)':
src\main.cpp:166:21: error: expected ';' before 'k'
OutputPin(pwrPin) k;
^
FastLED.io and DirectIO seem to conflict with multiple collisions.
Example:
In file included from C:\EE\microController\arduino-1.8.0\libraries\DirectIO/DirectIO.h:31:0,
from C:\EE\microController\arduino-1.6.9\projects\XXXXX.ino:73:
C:\EE\microController\arduino-1.8.0\libraries\DirectIO/include/pin.h:21:7: error: redefinition of 'class InputPin'
class InputPin {
Hello,
i tried to test the Lib with Platformio and compile the Examble "direct_io_pin.ino"
My version of PlatformIO ist 3.1.0 Core 4.2.1
I use an Arduino DUE an Programming Port tis ist Atmel SAM 4.1.0
'reinterpret_cast<Pio*>(1074662912)' is not a constant expression
L
redifiniton of that thing ? But i don't kow how do fix this.
Thanks for help!
The error in the Terminal Output:
Executing task: C:\Users\admin.platformio\penv\Scripts\platformio.exe run <
Verbose mode can be enabled via -v, --verbose
option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/due.html
PLATFORM: Atmel SAM 4.1.0 > Arduino Due (Programming Port)
HARDWARE: AT91SAM3X8E 84MHz, 96KB RAM, 512KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink, stlink)
PACKAGES:
Hello, I have a strange problem with your library. Whenver the library isn't the first entry on the include list it throws errors.
If I have:
It's fine, but if I have it the other way around I get these errors:
ports.h:48: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:48: error: *' cannot appear in a constant-expression ports.h:48: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:48: error:
' cannot appear in a constant-expression
ports.h:48: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:48: error: _' cannot appear in a constant-expression ports.h:52: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:52: error:
*' cannot appear in a constant-expression
ports.h:52: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:52: error:_' cannot appear in a constant-expression ports.h:52: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:52: error:
' cannot appear in a constant-expression
ports.h:56: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:56: error: *' cannot appear in a constant-expression ports.h:56: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:56: error:
' cannot appear in a constant-expression
ports.h:56: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:56: error: _' cannot appear in a constant-expression ports.h:60: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:60: error:
*' cannot appear in a constant-expression
ports.h:60: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
ports.h:60: error:_' cannot appear in a constant-expression ports.h:60: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression ports.h:60: error:
' cannot appear in a constant-expression
Due to my project's structure it's impossible for me to have your library as first thing included. How can I fix this?
I checked many libraries and like your DirectIO.
It would be great to get support for these chips please.
I am tried to add support for nRF52 serie but fall in tilt looking your technical code.
I have a nRF52830 and nRF52840 to test.
I found:
`
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
25, // D0 is P0.25 (UART TX)
24, // D1 is P0.24 (UART RX
10, // D2 is P0.10 (NFC2)
47, // D3 is P1.15 (LED1)
42, // D4 is P1.10 (LED2)
40, // D5 is P1.08
7, // D6 is P0.07
34, // D7 is P1.02 (Button)
16, // D8 is P0.16 (NeoPixel)
26, // D9 is P0.26
27, // D10 is P0.27
6, // D11 is P0.06
8, // D12 is P0.08
41, // D13 is P1.09
// D14 .. D21 (aka A0 .. A7)
4, // D14 is P0.04 (A0)
5, // D15 is P0.05 (A1)
30, // D16 is P0.30 (A2)
28, // D17 is P0.28 (A3)
2, // D18 is P0.02 (A4)
3, // D19 is P0.03 (A5)
29, // D20 is P0.29 (A6, Battery)
31, // D21 is P0.31 (A7, ARef)
// D22 .. D23 (aka I2C pins)
12, // D22 is P0.12 (SDA)
11, // D23 is P0.11 (SCL)
// D24 .. D26 (aka SPI pins)
15, // D24 is P0.15 (SPI MISO)
13, // D25 is P0.13 (SPI MOSI)
14, // D26 is P0.14 (SPI SCK )
// QSPI pins (not exposed via any header / test point)
19, // D27 is P0.19 (QSPI CLK)
20, // D28 is P0.20 (QSPI CS)
17, // D29 is P0.17 (QSPI Data 0)
22, // D30 is P0.22 (QSPI Data 1)
23, // D31 is P0.23 (QSPI Data 2)
21, // D32 is P0.21 (QSPI Data 3)
// The remaining NFC pin
9, // D33 is P0.09 (NFC1, exposed only via test point on bottom of board)
`
...
and
`
/**
Kind regards.
I really like to use this DirectIO lib.
What I'm try to do is implement it in other libraries, like <LiquidCrystal.h> for example.
Replace digitalWrite() for Output<>. But I got some issues to implement this in cpp.
Anybody already did that? Create an object Class in other Class.
Thanks.
Current OutputPort::write() code:
void write(port_data_t value) {
atomic {
// read-modify-write cycle
port_data_t v = port::port_output_read();
port_data_t shifted = value << start_bit;
v |= shifted & mask;
v &= (shifted | ~mask);
port::port_output_write(v);
}
}
On chips that have an output toggle feature, this can probably be sped up significantly using the clever XOR-based trick that I first saw in the RPi Pico SDK (https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_gpio/include/hardware/gpio.h#L719 )
the new code would not need "atomic", and would look something like:
void write(port_data_t value) {
port_data_t v = port::port_output_read();
port_data_t shifted = value << start_bit;
v ^= shifted;
port::port_output_toggle(v & mask);
}
It would be great to get support for these chips please.
\Arduino\libraries\DirectIO/ports.h:31:20: fatal error: avr/io.h: No such file or directory
#include <avr/io.h>
Currently DirectIO uses a read, flip, write sequence to toggle output pins.
This can be done faster by using the PINx
registers (on some targets?).
See section 14.2.2 of the ATMega328 manual:
14.2.2 Toggling the Pin
Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port.
For use cases where pin numbers are not known at compile time, the InputPin
and OutputPin
classes are used but they are currently wrappers for digitalRead and digitalWrite and share their (slow) performance. It would be faster to cache the port address and bit mask (that digitalRead and digitalWrite currently look up everytime) at the expense of a few bytes of RAM per I/O.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.