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

ADS1256 SPI analog addon #841

Merged
merged 9 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ src/addons/snes_input.cpp
src/addons/inputhistory.cpp
src/addons/tilt.cpp
src/addons/xbonepassthrough.cpp
src/addons/spi_analog_ads1256.cpp
${PROTO_OUTPUT_DIR}/enums.pb.c
${PROTO_OUTPUT_DIR}/config.pb.c
)
Expand All @@ -218,6 +219,7 @@ AnimationStation
CRC32
FlashPROM
ADS1219
ADS1256
PlayerLEDs
NeoPico
OneBitDisplay
Expand Down
53 changes: 53 additions & 0 deletions headers/addons/spi_analog_ads1256.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef SPI_ANALOG_ADS1256_H_
#define SPI_ANALOG_ADS1256_H_

#include <ADS1256.h>
#include <algorithm>

#include "gpaddon.h"

#include "GamepadEnums.h"
#include "peripheralmanager.h"

#ifndef SPI_ANALOG1256_ENABLED
#define SPI_ANALOG1256_ENABLED 0
#endif

#ifndef SPI_ANALOG1256_CS_PIN
#define SPI_ANALOG1256_CS_PIN -1
#endif

#ifndef SPI_ANALOG1256_DRDY_PIN
#define SPI_ANALOG1256_DRDY_PIN -1
#endif

#ifndef SPI_ANALOG1256_BLOCK
#define SPI_ANALOG1256_BLOCK spi0
#endif

#ifndef SPI_ANALOG1256_SPEED
#define SPI_ANALOG1256_SPEED 5000000
#endif

// Analog Module Name
#define SPIAnalog1256Name "SPIAnalogADS1256"

class SPIAnalog1256Input : public GPAddon {
public:
virtual bool available();
virtual void setup(); // Analog Setup
virtual void preprocess() {}
virtual void process(); // Analog Process
virtual std::string name() { return SPIAnalog1256Name; }
private:
uint8_t convert24to8bit(float voltage);
uint16_t convert24to16bit(float voltage);

ADS1256 * ads;
float values[ADS1256_CHANNEL_COUNT]; // Cache for latest read values
bool enableTriggers;
uint8_t readChannelCount; // Number of channels to read from the ADC
float analogMax = ADS1256_MAX_3V;
};

#endif // SPI_ANALOG_ADS1256_H_
Loading