simplefoc / Arduino-FOC-drivers

Drivers and support code for SimpleFOC
https://docs.simplefoc.com/drivers_library
MIT License
145 stars 63 forks source link

[FEATURE] Allowing to choose SPI pins #37

Closed sylque closed 7 months ago

sylque commented 7 months ago

This is a duplicate of https://github.com/simplefoc/Arduino-FOC/issues/375

Is your feature request related to a problem? Please describe. On my ESP32, I can choose any GPIO pins for SPI. Unfortunately, it seems SimpleFOCDrivers only allows for the two sets of default SPI pins (HSPI and VSPI), like this:

static SPIClass spi(HSPI);
sensor.init(&spi);

Describe the solution you'd like Either:

MagneticSensorAS5048A g_sensorX(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);

or:

sensor.init(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);

As a side note, is there any reason why half the SPI parameters (namely SPISettings and nCS) are passed in the sensor constructor whereas the other half (SPIClass) is passed in sensor.init()? This makes things hard to grasp.

runger1101001 commented 7 months ago

Hi there,

I think you can already do this:

    SPIClass mySPI(HSPI);
    mySPI.begin(PIN_CLK, PIN_MISO, PIN_MOSI);
    sensor.init(&mySPI);

Please let me know if this solves your problem?

sylque commented 7 months ago

Yes, this should work! I will post the result here.

sylque commented 7 months ago

It works perfectly, thank you very much.

Now I have 3 places with SPI settings instead of two :-) (sensor constructor, sensor.init(), spi.begin())