Skip to content

Commit

Permalink
Improve SPI dependency (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Jan 19, 2024
1 parent 0a7e4a6 commit 6c3cf1b
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 16 deletions.
8 changes: 4 additions & 4 deletions AD520X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: AD520X.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-07-24
// VERSION: 0.4.0
// VERSION: 0.5.0
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers
// (+ AD8400, AD8402, AD8403)
// URL: https://github.com/RobTillaart/AD520X
Expand Down Expand Up @@ -52,9 +52,9 @@ void AD520X::begin(uint8_t value)

if(_hwSPI)
{
_mySPI->end();
_mySPI->begin();
delay(1);
// _mySPI->end();
// _mySPI->begin();
// delay(1);
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions AD520X.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// FILE: AD520X.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-24
// VERSION: 0.4.0
// VERSION: 0.5.0
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers
// (+ AD8400, AD8402, AD8403)
// URL: https://github.com/RobTillaart/AD520X
Expand All @@ -13,20 +13,20 @@
#include "SPI.h"


#define AD520X_LIB_VERSION (F("0.4.0"))
#define AD520X_LIB_VERSION (F("0.5.0"))

#ifndef AD520X_MIDDLE_VALUE
#define AD520X_MIDDLE_VALUE 128
#endif


#if defined(ARDUINO_ARCH_RP2040)
#define __SPI_CLASS__ SPIClassRP2040
#else
#define __SPI_CLASS__ SPIClass
#ifndef __SPI_CLASS__
#if defined(ARDUINO_ARCH_RP2040)
#define __SPI_CLASS__ SPIClassRP2040
#else
#define __SPI_CLASS__ SPIClass
#endif
#endif


class AD520X
{
public:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.5.0] - 2024-01-19
- Fix #23, improve handling SPI dependency.
- add SPIClass guard


## [0.4.0] - 2023-11-26
- refactor constructor interface - breaking changes.
- minimize conditional code. -- create SPI_CLASS macro to solve it.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2023 Rob Tillaart
Copyright (c) 2020-2024 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ The interface is straightforward, one can set a value per channels between 0..25
The library is not yet confirmed to work for **AD8402** (2 channels).
This device has a very similar interface (datasheet comparison) so it should work. If you can confirm the AD8402 works, please let me know.


#### 0.5.0 Breaking change

Version 0.5.0 introduced a breaking change to improve handling the SPI dependency.
The user has to call **SPI.begin()** or equivalent before calling **AD520X.begin()**.
Optionally the user can provide parameters to the **SPI.begin(...)**


#### 0.4.0 breaking change

The version 0.4.0 has breaking changes in the interface.
Expand Down
3 changes: 2 additions & 1 deletion examples/AD5204_demo/AD5204_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uint32_t start, stop;


// select, reset, shutdown, data, clock == SOFTWARE SPI
// AD5206 pot(10, 255, 255, 8, 9);
// AD5206 pot(10, 255, 255, 8, 9);

// select, reset, shutdown, &SPI === HW SPI UNO clock = 13, data = 11
AD5206 pot = AD5206(5, 6, 7, &SPI);
Expand All @@ -23,6 +23,7 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);

SPI.begin();
pot.begin(4);

// test_extremes();
Expand Down
1 change: 1 addition & 0 deletions examples/AD5204_demo_HWSPI/AD5204_demo_HWSPI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void setup()
Serial.print("AD520X_LIB_VERSION:\t");
Serial.println(AD520X_LIB_VERSION);

SPI.begin();
pot.begin(4);

Serial.print("\tusesHWSPI:\t");
Expand Down
1 change: 1 addition & 0 deletions examples/AD5204_demo_stereo/AD5204_demo_stereo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void setup()
Serial.println(AD520X_LIB_VERSION);
Serial.println();

SPI.begin();
pot.begin(4);

// test_sinus();
Expand Down
1 change: 1 addition & 0 deletions examples/AD5204_setPercentage/AD5204_setPercentage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);

SPI.begin();
pot.begin(4);

for (int p = 0; p <= 100; p++)
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AD520X.git"
},
"version": "0.4.0",
"version": "0.5.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AD520X
version=0.4.0
version=0.5.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SPI AD5204 and AD5206 digital potentiometers
Expand Down

0 comments on commit 6c3cf1b

Please sign in to comment.