Hi,
I'm working on a "yet another" adapter board that converts Teensy 4.1 to Arduino Mega 2560 form-factor, with true 5V push-pull signaling. 5V push-pull is done with the circuitry that sits between Teensy 4.1 and the outside world. My goal is to use existing mega shields with teensy 4.1
I would like to override the pinMode, digitalRead, digitalWrite, analogRead, etc. so I can configure the custom circuitry. This will help one to reuse existing Arduino Mega code as much as possible. Without overriding, I have to use custom function names, which is another thing to worry about.
1) Is is possible to modify the digital.c and a few others to achieve this?
2) Asking as a hardware person, is there any danger to enabling overriding? (I see a few other board libraries allow this - not sure if ok to mention names.).
Please DON'T do the modifications yet. First step would be to understand how much of work this will require. If helpful I can also recommend what files and which changes to make.
Thank you,
It will be something along the lines of...
I'm working on a "yet another" adapter board that converts Teensy 4.1 to Arduino Mega 2560 form-factor, with true 5V push-pull signaling. 5V push-pull is done with the circuitry that sits between Teensy 4.1 and the outside world. My goal is to use existing mega shields with teensy 4.1
I would like to override the pinMode, digitalRead, digitalWrite, analogRead, etc. so I can configure the custom circuitry. This will help one to reuse existing Arduino Mega code as much as possible. Without overriding, I have to use custom function names, which is another thing to worry about.
1) Is is possible to modify the digital.c and a few others to achieve this?
2) Asking as a hardware person, is there any danger to enabling overriding? (I see a few other board libraries allow this - not sure if ok to mention names.).
Please DON'T do the modifications yet. First step would be to understand how much of work this will require. If helpful I can also recommend what files and which changes to make.
Thank you,
It will be something along the lines of...
C++:
// extern void pinMode(uint8_t pin, uint8_t mode) __attribute__((weak, alias("__pinMode")));
// extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__((weak, alias("__digitalWrite")));
// extern int digitalRead(uint8_t pin) __attribute__((weak, alias("__digitalRead")));
// extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__((weak, alias("__attachInterrupt")));
// extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void *arg, int mode) __attribute__((weak, alias("__attachInterruptArg")));
// extern void detachInterrupt(uint8_t pin) __attribute__((weak, alias("__detachInterrupt")));
// extern uint16_t analogRead(uint8_t pin) __attribute__((weak, alias("__analogRead")));
// extern uint32_t analogReadMilliVolts(uint8_t pin) __attribute__((weak, alias("__analogReadMilliVolts")));
// extern void analogReadResolution(uint8_t bits) __attribute__((weak, alias("__analogReadResolution")));
// extern void analogSetAttenuation(adc_attenuation_t attenuation) __attribute__((weak, alias("__analogSetAttenuation")));
// extern void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation) __attribute__((weak, alias("__analogSetPinAttenuation")));
// ##################################################
// My custom pinMode()
void pinMode(uint8_t pin, uint8_t mode) {
__pinMode(pin, mode);
Serial.write("pinMode called");
}
Last edited: