Open ghost opened 6 years ago
Did not use and DuinoPro code (relied on Arduino libraries)
void port_init(void)
{
pinMode(A1, OUTPUT); // M6P1
}
void port_test_set(int value)
{
if (value)
{
digitalWrite(A1, HIGH);
}
else
{
digitalWrite(A1, LOW);
}
}
Worked as expected
Note that removing the port_init
above does not do anything to the functionality of the above code.
Continuing from the basic version (Basic Testing) in the above comments; when the pinMode
setup in port_init()
is replaced as follows:
Pin m6p1(6, 1);
void port_init(void)
{
m6p1.mode(OUTPUT);
}
There is no issue.
But when we replace the digitalWrite
in the set function;
void port_rts_set(int value)
{
if (value)
{
m6p1.write(HIGH);
}
else
{
m6p1.write(LOW);
}
}
No change on the pin can be detected (but during the loop, the on-board LED still flashes, indicating the program is not 'stuck')
In Pin.cpp
: the constructor of the class is as calls the macro _id = moduleSignalToPin(mod, pin)
to determine the mapping
This macro is in pins_arduino.h
:
#define moduleSignalToPin(m, p) (module_pin_to_digital_pin[(m)-1][(p)-1])
module_pin_to_digital_pin
is a 2 dimensional array with 6 columns. It is also defined in pins_arduino.h
The element in module_pin_to_digital_pin
at m=6
and p=1
is: 6. In other words:
_id = moduleSignalToPin(6, 1);
_id = 6;//equivalent to above
_id
attribute in the Pin
instance is used for the functions pinMode(_id)
, digitalWrite(_id)
, etc. and this is incorrect.In Pin.cpp
, replaced all _id
attribute occurrences with A1
(correct pin label for M6P1) and got correct feedback.
Turns out the DuinoPro library has been overloading the Arduino functions digitalWrite
and pinMode
with their own functions in wiring_digital.h
....
Not sure if they handled scope resolution correctly (hence the ::digitalWrite
etc.)
Issue
Can't get the
Module.h
andPin.h
pieces workingWhat I tried
Building on commit bfd7d0070a9568eb76d0be07c03f8a45a82c76eb; toggling Pin 3 on Module 7 (
UART_RTS
) in the mainwhile(1)
body alongside the Board's LEDWhat Happened
The LED stayed on the whole time when the pin toggle function
port_rts_set()
was used in the body. When the function was taken out, the LED blinked as expected