arduino / arduino/ArduinoCore-API
Ability to set speed in shiftIn & shiftOut
- Dominant language
- C++
- Stars
- 306
- Forks
- 150
- PR merge metrics
- No merged PRs in 30d
Description
While the clock speeds of various Microcontrollers increase, the speed of the shiftIn and shiftOut also increases. This creates a problem when communicating with slower devices. It could be interesting to add an optional argument to these functions so they reliably work with slower devices. Just like with the SPI hardware library where you can set the maximum SPI speed. https://www.arduino.cc/en/Reference/SPI
I had this problem when I was trying to use the 'normal' library for the HX711 load cell amp with an ESP32.
https://github.com/bogde/HX711/issues/75
The interface could look like this:
```cpp
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val, unsigned long maxSpeed = 0);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, unsigned long maxSpeed = 0);
```
Where a maxSpeed of 0 would mean that it would use the full speed of the microcontroller. Otherwise you could define the speed as frequency (15Mhz -> 15000000) just like in the SPI hardware library.
In this way Arduino would be future-proof without losing backwards compatibility.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the shiftIn and shiftOut declarations shown in the issue and compare the requested maxSpeed semantics with Arduino's SPI hardware library reference. Determine how speed handling can preserve existing calls and address slower devices such as the ESP32/HX711 case; done means the API supports slower communication without breaking backwards compatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100