synthetos/Motate

Pull shared code out of platform specific header files

Closed this issue · 3 comments

While taking a look at everything, I noticed that there seems to be a bit of duplication between platforms. For instance, the dummy template Pins class (struct?) is, or at least should be the same across all the platforms. In the header files for the Timers, the enums should always be the same as well. Oh, and don't forget Motate::delay.

EDIT: Oh, right, the enum values are different across platforms. Derp.
EDIT 2: Well, there doesn't actually seem to be much to consolidate in the Timers. Just delay and some timer number constants. That is, unless we pull platform specific code out of those classes into somewhere else... shudders. Next up, Pins.

My suggustion is to pull such things out into the Motate{Pins,Timers,etc...} header files, or at least put it in a shared header somewhere.

...

Now that I've said this, I'll go work on making a PR.

So, I can understand wanting to use some of the xmega specific stuff for the xmega pins. But... Is it possible to take those implementation specifics and put them in the macro? (Talking about PORT_8, comparing between AVR and XMega...) Possibly not using a variable in the class to hold the port proxy?

Will investigate. But not now, and I will need to figure out how to do that... When I do, I can pull out the PORT_8 template, and probably already can pull out the generic pin template.

If you look at the https://github.com/synthetos/Motate/tree/sam4e-port/ you'll see I took your advice. I've been refactoring peripheral-by-peripheral as needed for new ports to have as much common code as I can in the Motate${peripheral}.h, and then the platform-specific code in ${platform}-${peripheral}.[h,cpp] files.

For example, look at MotatePins.h and see how much common-code is there now.

Thanks for the suggestion!

-Rob

Awesome! It's nice to see that I managed to help. :D

... shoot, now I want to port this for bare-metal raspberry pi, as I've been working with attempting to bitbang stuff with that. But I still have no idea how to port motate. Ah well, that's how it goes with projects you love: they never support the devices you have and you have no idea how to port it. xD