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

Adding SPI Arduino Core Library #13

Open
rcalcover opened this issue Mar 2, 2020 · 5 comments
Open

Adding SPI Arduino Core Library #13

rcalcover opened this issue Mar 2, 2020 · 5 comments

Comments

@rcalcover
Copy link

rcalcover commented Mar 2, 2020

Hi I am trying to add SPI Arduino Core library and contribute in ArduinoFake for the community.
I have followed the contribution guidelines and added SPI the same way as the Print since its quite similar to it. The issue was that I encountered an error that I was stuck on ArduinoFake.h:

                 from test/main.cpp:1:
src/ArduinoFake.h: In member function ‘SPIClassFake* ArduinoFakeContext::SPIClass(SPIClass*)’:
src/ArduinoFake.h:59:52: error: cannot dynamic_cast ‘instance’ (of type ‘class SPIClass*’) to type ‘class SPIClassFakeProxy*’ (source type is not polymorphic)
         if (dynamic_cast<name##FakeProxy*>(instance)) { \
                                                    ^
src/ArduinoFake.h:103:9: note: in expansion of macro ‘_ArduinoFakeInstanceGetter2’
         _ArduinoFakeInstanceGetter2(SPIClass, SPIClass)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ArduinoFake.h:60:59: error: cannot dynamic_cast ‘instance’ (of type ‘class SPIClass*’) to type ‘class SPIClassFakeProxy*’ (source type is not polymorphic)
             return dynamic_cast<name##FakeProxy*>(instance)->get##name##Fake(); \
                                                           ^
src/ArduinoFake.h:103:9: note: in expansion of macro ‘_ArduinoFakeInstanceGetter2’
         _ArduinoFakeInstanceGetter2(SPIClass, SPIClass)

It showed when I added _ArduinoFakeInstanceGetter2(SPIClass, SPIClass) on ArduinoFakeContext.

Maybe because SPI Class has static members? But I have removed the static modifier on the members of SPIClass but it did not fixed the problem.

I have forked your repo to and made a branch to work on here is the link of my rcalcover#1

@FabioBatSilva
Copy link
Owner

Hi @rcalcover.
Thanks for looking into it..

I think you don't need _ArduinoFakeInstanceGetter2(SPIClass, SPIClass) in this case..

Also think that the implementation for SPIClass::begin and other static methods need to change..
Since you don't have access to this you should be using ArduinoFakeInstance(SPIClass)->begin() instead of ArduinoFakeInstance(SPIClass, this)->begin()

@david284
Copy link

david284 commented Mar 9, 2022

Hi Guys,
Has support for SPI been added to ArduinoFake? - the trail above suggested it was being looked at

Trying to setup testing for a project that includes an SPI CAN bus adapter (MCP2515), and the library for this (ACAN2515) obviously includes SPI.h, which currently throws an error
I'm only testing my code, so currently working around it by removing the include to the library & adding my own define for the data structure that's then missing

@nerdyscout
Copy link
Contributor

nerdyscout commented Jan 1, 2023

my SPIFake seems to run now, currently working on adding some tests. last think I can not figure out is to pass SPISettings @FabioBatSilva any hint why this line fails?

@r89m
Copy link

r89m commented Jan 21, 2023

I think you were missing the == operator in SPISettings - I've implemented it below and the tests now pass for me even with the commented out line being run.

class SPISettings {
 private:
  uint32_t clock;
  uint8_t bitOrder;
  uint8_t dataMode;
 public:
  SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock), bitOrder(bitOrder), dataMode(dataMode) {}
  SPISettings() { SPISettings(4000000, MSBFIRST, SPI_MODE0); }
  friend class SPIClass;

  bool operator==(const SPISettings &other) const {
    return (clock == other.clock) && (bitOrder == other.bitOrder) && (dataMode == other.dataMode);
  }
};

nerdyscout added a commit to nerdyscout/ArduinoFake that referenced this issue Jan 22, 2023
@nerdyscout nerdyscout mentioned this issue Jan 22, 2023
@FabioBatSilva
Copy link
Owner

Thanks everyone..

PR #37 got merged, will publish a new version next.

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

No branches or pull requests

5 participants