-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use hardware TWI for the PAT9125 (optical) filament sensor #2814
Conversation
Remove probing from Marlin_main and move it into pat9125_probe so that it can support the various variants.
- Only implement a single syncronous read/write function to read a byte, since that's all we need currently - Implement a compact IR_SENSOR probe for PAT9125 - Saves 242 bytes compared to PAT9125_SWI2C
.. and likely will never was/be.
Both would be technically correct.
Three guesses what prompted this change 🤣 |
On Wed, Sep 09 2020, vintagepc wrote:
Three guesses what prompted this change 🤣
I couldn't sleep well after finding that out, had to fix it ;)
|
Did you end up testing it out by wiring up the hardware SPI sim? IIRC the SPIPeripheral class was written to support both bitbanged and "real" I2C connections and the fake PAT shouldn't care which it is wired to. Edit: for anyone else wondering about the context for this, see |
Took a while, but getting back to this. At least without changes, the sensor doesn't seem to be detected right now. The SCL/SDA irqs do not seem to be generated in this case so the callbacks are never called. |
Ah, ok. If you wouldn't mind tossing up a MK404 issue with a .hex and I'll take a look. It's possible that something is still unimplemented. |
The wiring for the PAT9125 on RAMBo10a boards is not directly connected to the SCL pin and requires the sw mode. Detect this requirement by checking the definition for the SWI2C_SCL pin in the board definition. Remove SWI2C_SCL/SDA from the other boards to use the HW mode.
- Enter a repeated-start for reading data - Write in the same session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have write access to the repo but I approve of this change regardless given its origins 😉
@wavexx @vintagepc is this ready to get merged into MK3? |
I think it is, yes :) All was working as expected in MK404 |
OK, my only complaint is the usage of "digitalWrite()" - can we get rid of this? |
This is what it's doing, seems like it should be possible to just strip out the unnecessary bits and just do the actions we need to set it high:
|
We can use the fastio macros here, can't we? Just fix the SCL and SDA definition in fastio so that it's fastio compatible |
We can remove it, but is it necessary? digitalWrite is already used elsewhere, so we won't save any space AFAIK. It's also not on a hot code path. |
Checking now if using FASTIO can lead to some space savings.. |
Using fastio would actually save 12 bytes :), however I need to add some crummy defines just to make it build: including fastio.h is not enough, which is something that would be nice to fix. #2690 would make sense IMHO If including #2690 makes sense in this release, I could proceed with something less invasive (another copy of CRITICAL_SECTION.. uugh) to be revisited later @DRracer |
Move CRITICAL_SECTION_START/END into fastio.h, where it's needed.
fastio relies on macros for pin definitions, so we cannot use the const declaration in Sd2PinMap or the arduino's definition. Declare SDA/SCL_PIN into pins.h based on the current MCU, which is identical in all our variants. Remove the conflicting/unused declaration in Sd2PinMap.
@DRracer now using fastio! |
The PAT9125 on the MK3 is attached to the hardware SDA/SCL pins, but we're still using a software I2C implementation for some reason.
We add a new configuration option PAT9125_I2C (which is also enabled by default by this PR) to use the hardware TWI module in 400khz fast mode.
We save 170 bytes on the MK3S variant (which still requires probing to detect the current variant) and 268 on the MK3, plus a little bit of latency since despite the code still being synchronous, we can at least avoid having to wait for the stop condition.
PFW-1191