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

No more pinName #28 #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nedseb
Copy link
Contributor

@nedseb nedseb commented Jul 4, 2018

I have removed the PinName on the class Serial and I made It pure abstract. In my opinion, this abstraction does not need to know the notion of Pin so I removed the constructor which do nothing...
This is the option you have chosen for the SPI class and I find it more elegant.

As a bonus, I propose to transform the PinNumber type into an opaque enumeration ;) I'll give you an example of use.

#28

@nedseb nedseb changed the title No more pin name #28 No more pinName #28 Jul 4, 2018
@nedseb
Copy link
Contributor Author

nedseb commented Jul 4, 2018

You can see how I declare my PinNumber strongly typed and adapted to my target :
https://github.com/LabAixBidouille-STM32/codal-stm32-iot-node/blob/880fed2b8253da3ca1d12d732b6c1359e2899e69/model/STM32IotNodeIO.h#L129

Here you can see the modification of codal-mbedos needed for this modification :
LabAixBidouille-STM32-sandbox/codal-mbedos@4cebc9f

@jamesadevine
Copy link
Contributor

@nedseb that's really cool, didn't know you could do that with enum + type 😄

I think it's important we retain a standard constructor for Serial across all targets. It seems that although SPI doesn't have a default constructor, you create (probably) a very similar constructor in your implementation:

STM32IotNodeSPI(codal::Pin &mosi, codal::Pin &miso, codal::Pin &sclk);

So, the benefits to doing what you proposed are:

  • Allows nicer per target constructor specification
  • Since we don't retain the instances in the higher level class, it's pretty nonsensical to require it in a pure virtual class.

The downside is that by dropping constructor specification at the high level, we lose standardisation at the implementation level. For instance, I can now just create an arbitrary constructor that is entirely inconsistent with any constructor created before.

Is this a bad thing? I think some freedoms are good, for instance you can already be really free with the implementation. I'll associate my hesitance to a practical example: PXT common packages rely on a standard constructor for each of our classes, by accepting your commit I think we could venture down a road where there will be many PXT un common packages 😁

@tballmsft @abchatra @riknoll @mmoskal may have more insights.

@nedseb
Copy link
Contributor Author

nedseb commented Jul 10, 2018

@jamesadevine For PinNumber, if you are interested I can make a specific PR.

For the constructor, since there is not polymorphism for constructors, adding a specific one don't constrain the client in any way. In Subclass, we can add as many constructors as we want without any consistence consideration. If we want add constraints for standardizing construction, we must consider a factory (or any other construction patterns) and encapsulate constructors as much as possible....

After I accept the idea that as writer of a model-drivers class we must lead by example and the added constructors could be a model for begining a subclass...

Copy link
Contributor

@mmoskal mmoskal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice for the constructor to take two Pin& arguments - in pxt-common-packages we #define CODAL_SERIAL to be target-specific serial class, but the constructor is assumed to take these two pins. We have ways of using per-target constructors, but it's somewhat more painful - would be nicer to have common constructor signature.

https://github.com/Microsoft/pxt-common-packages/blob/master/libs/serial/serial.cpp#L35

*/
Serial(PinName tx, PinName rx, uint8_t rxBufferSize = CODAL_SERIAL_DEFAULT_BUFFER_SIZE, uint8_t txBufferSize = CODAL_SERIAL_DEFAULT_BUFFER_SIZE)
Serial(Pin tx, Pin rx, uint8_t rxBufferSize = CODAL_SERIAL_DEFAULT_BUFFER_SIZE, uint8_t txBufferSize = CODAL_SERIAL_DEFAULT_BUFFER_SIZE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Pin& ?

*
* @return CODAL_SERIAL_IN_USE if another fiber is currently transmitting or receiving, otherwise DEVICE_OK.
*/
virtual int redirect(PinName tx, PinName rx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it difficult to keep redirect() (I guess with two Pin& arguments)?

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

Successfully merging this pull request may close these issues.

3 participants