Skip to content
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

Support for Raspberry RP2040 #123

Open
ahorn42 opened this issue May 21, 2023 · 3 comments
Open

Support for Raspberry RP2040 #123

ahorn42 opened this issue May 21, 2023 · 3 comments

Comments

@ahorn42
Copy link

ahorn42 commented May 21, 2023

Hello,

has someone already tried to run OneWireHub on a Raspberry RP2040 like device? Funnily these µC are cheaper than most 1-wire devices, and I would like to use some RP2040 to fake a bunch of DS2450.

After renaming MEM_SIZE to MEMORY_SIZE (or something else, as MEM_SIZE seems to be a macro in the RP2040 arduino wrapper) I got the code compiling, but I could not get it working, so that the emulated 1-wire devices could be read from another µC.

I already found the platform.h file but I am not sure, how to adapt this to RP2040 and also I have no clue, if this is really the issue. Any ideas how to go on?

best regards,
ahorn

@ahorn42
Copy link
Author

ahorn42 commented May 21, 2023

Just found the calibrate_by_bus_timing script and it seems to work now with IPL = 25 :)

Unfortunately I still don't understand what the other values mean that were configured in platform.h

#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*((base)+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*((base)+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*((base)+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*((base)+2)) |= (mask))
using io_reg_t = uint8_t; // define special datatype for register-access

Above is the sample for AVR, I kind of have an idea what it should do, but I think I need some further hints how to adapt this to the RP2040 ;)

@orgua
Copy link
Owner

orgua commented May 22, 2023

That's mostly Atmel-related lowlevel-stuff to access pins that was needed to allow the fast overdrive-mode of Onewire. Maybe it's time to remove all that error-prone platform-glue and use arduino-commands by default.
I will order a RP2040 and look into either porting the lib or advance to pure-arduino as a major v3-step

@hattesen
Copy link

@orgua, it sounds great that you plan to look at supporting the RP2040 in OneWireHub.

Ideally an RP2040 implementation should make use of the RP2040 PIO (an IO coprocessor), which allows implementation of serial protocols with single cycle (@125MHz) precision timing, leaving the application/device implementation free of bit-banging code, timing critical sections and avoiding having to disable interrupts.

If taking on the PIO is too much for the initial port to RP2040, if you define an API with a sufficiently high abstraction level (addressing and sending bytes), it would be reasonably easy for someone to add a PIO implementation later (via a pull request).

Here are a few inspirational resources I have collected that all implement a 1-wire protocol master using the RP2040 PIO for the time-critical serial encoding/decoding:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants