diff --git a/libraries/DAC8554/.arduino-ci.yml b/libraries/DAC8554/.arduino-ci.yml index ff5659b9..e7cb4633 100644 --- a/libraries/DAC8554/.arduino-ci.yml +++ b/libraries/DAC8554/.arduino-ci.yml @@ -2,6 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 \ No newline at end of file diff --git a/libraries/DAC8554/DAC8554.cpp b/libraries/DAC8554/DAC8554.cpp index 9710223a..286a915a 100644 --- a/libraries/DAC8554/DAC8554.cpp +++ b/libraries/DAC8554/DAC8554.cpp @@ -2,7 +2,7 @@ // FILE: DAC8554.cpp // AUTHOR: Rob Tillaart // PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor -// VERSION: 0.2.3 +// VERSION: 0.2.4 // URL: https://github.com/RobTillaart/DAC8554 // // HISTORY: @@ -10,11 +10,12 @@ // 0.1.2 2020-04-06 minor refactor, readme.md // 0.1.3 2020-06-07 fix library.json // 0.1.4 2020-07-20 fix URL's in demo's; MIT license; minor edits -// 0.2.0 2020-12-18 add arduino-ci + unit test +// 0.2.0 2020-12-18 add Arduino-CI + unit test // 0.2.1 2021-01-10 fix slave select hardware SPI + getValue() + getPowerDownMode(). // fix unit test. // 0.2.2 2021-06-02 compile ESP32 // 0.2.3 2021-08-29 add support for HSPI / VSPI ESP32 ++ +// 0.2.4 2021-12-15 update library.json, license, unit test, minor edits #include "DAC8554.h" @@ -34,7 +35,6 @@ DAC8554::DAC8554(uint8_t slaveSelect, uint8_t address) } -// 0,1,2,4 resp 8550 8551 8552 8554 DAC8554::DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address) { _hwSPI = false; @@ -112,8 +112,8 @@ void DAC8554::setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t selec // // SETVALUE // -// channel = 0,1,2,3 -// value = 0..65535 +// channel = 0, 1, 2, 3 +// value = 0..65535 void DAC8554::bufferValue(uint8_t channel, uint16_t value) { uint8_t configRegister = _address; @@ -134,7 +134,7 @@ void DAC8554::setValue(uint8_t channel, uint16_t value) // channel = 0, 1, 2, 3 depending on type -// returns 0..65535 +// returns 0..65535 uint16_t DAC8554::getValue(uint8_t channel) { return _value[channel]; @@ -155,12 +155,13 @@ void DAC8554::setSingleValue(uint8_t channel, uint16_t value) // // POWERDOWN // -// channel = 0,1,2,3 +// channel = 0, 1, 2, 3 // powerDownMode = -// DAC8554_POWERDOWN_NORMAL 0x00 -// DAC8554_POWERDOWN_1K 0x40 -// DAC8554_POWERDOWN_100K 0x80 -// DAC8554_POWERDOWN_HIGH_IMP 0xC0 +// DAC8554_POWERDOWN_NORMAL 0x00 +// DAC8554_POWERDOWN_1K 0x40 +// DAC8554_POWERDOWN_100K 0x80 +// DAC8554_POWERDOWN_HIGH_IMP 0xC0 +// void DAC8554::bufferPowerDown(uint8_t channel, uint8_t powerDownMode) { _register[channel] = powerDownMode; @@ -278,4 +279,6 @@ void DAC8554::swSPI_transfer(uint8_t value) } } + // -- END OF FILE -- + diff --git a/libraries/DAC8554/DAC8554.h b/libraries/DAC8554/DAC8554.h index bf2a075b..8557ca1d 100644 --- a/libraries/DAC8554/DAC8554.h +++ b/libraries/DAC8554/DAC8554.h @@ -3,7 +3,7 @@ // FILE: DAC8554.h // AUTHOR: Rob Tillaart // PURPOSE: Arduino library for DAC8554 SPI Digital Analog Convertor -// VERSION: 0.2.3 +// VERSION: 0.2.4 // HISTORY: See DAC8554.cpp // URL: https://github.com/RobTillaart/DAC8554 // @@ -11,13 +11,12 @@ #include "Arduino.h" #include "SPI.h" -#define DAC8554_LIB_VERSION (F("0.2.3")) +#define DAC8554_LIB_VERSION (F("0.2.4")) - -#define DAC8554_POWERDOWN_NORMAL 0x00 -#define DAC8554_POWERDOWN_1K 0x40 -#define DAC8554_POWERDOWN_100K 0x80 -#define DAC8554_POWERDOWN_HIGH_IMP 0xC0 +#define DAC8554_POWERDOWN_NORMAL 0x00 +#define DAC8554_POWERDOWN_1K 0x40 +#define DAC8554_POWERDOWN_100K 0x80 +#define DAC8554_POWERDOWN_HIGH_IMP 0xC0 class DAC8554 @@ -31,17 +30,20 @@ public: void begin(); + void bufferValue(uint8_t channel, uint16_t value); void setValue(uint8_t channel, uint16_t value); uint16_t getValue(uint8_t channel); //writes the value to the channel but does not affect buffered ones void setSingleValue(uint8_t channel, uint16_t value); + void bufferPowerDown(uint8_t channel, uint8_t powerDownMode); void setPowerDown(uint8_t channel, uint8_t powerDownMode); uint8_t getPowerDownMode(uint8_t channel); void setSinglePowerDown(uint8_t channel, uint8_t powerDownMode); + // write all buffers to all(up to 4) 8554's channel's void broadcastBuffer(); // write value to all(up to 4) 8554's channel's @@ -49,12 +51,15 @@ public: // write powerDownMode to all 8554's channel's void broadcastPowerDown(uint8_t powerDownMode); + // speed in Hz void setSPIspeed(uint32_t speed); uint32_t getSPIspeed() { return _SPIspeed; }; + bool usesHWSPI() { return _hwSPI; }; + // ESP32 specific #if defined(ESP32) void selectHSPI() { _useHSPI = true; }; @@ -62,6 +67,7 @@ public: bool usesHSPI() { return _useHSPI; }; bool usesVSPI() { return !_useHSPI; }; + // to overrule ESP32 default hardware pins void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select); #endif @@ -83,6 +89,7 @@ private: void writeDevice(uint8_t configRegister, uint16_t value); void swSPI_transfer(uint8_t value); + SPIClass * mySPI; SPISettings _spi_settings; @@ -91,4 +98,6 @@ private: #endif }; + // -- END OF FILE -- + diff --git a/libraries/DAC8554/LICENSE b/libraries/DAC8554/LICENSE index d29d575f..4231b05c 100644 --- a/libraries/DAC8554/LICENSE +++ b/libraries/DAC8554/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2021 Rob Tillaart +Copyright (c) 2017-2022 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 diff --git a/libraries/DAC8554/README.md b/libraries/DAC8554/README.md index b31f03ec..2a184116 100644 --- a/libraries/DAC8554/README.md +++ b/libraries/DAC8554/README.md @@ -7,7 +7,7 @@ # DAC8554 -Arduino library for DAC8554 SPI Digital Analog Convertor +Arduino library for DAC8554 SPI Digital Analog Convertor. ## Description @@ -23,10 +23,12 @@ The DAC8554 is a SPI based 16 bit DAC with four channels. - **DAC8554(uint8_t slaveSelect, uint8_t address = 0)** Constructor for hardware SPI, since 0.2.0 the slaveSelect pin needs to be defined. -- **DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address = 0)** Constructor for the software SPI +- **DAC8554(uint8_t spiData, uint8_t spiClock, uint8_t slaveSelect, uint8_t address = 0)** +Constructor for the software SPI - **void begin()** initializes all pins to default state - **void setValue(uint8_t channel, uint16_t value)** set the value of the channel to 0 - 65535 -- **void setSingleValue(uint8_t channel, uint16_t value)** writes the value to the channel but does not affect buffered ones. TODO - elaborate. +- **void setSingleValue(uint8_t channel, uint16_t value)** writes the value to the channel but +does not affect buffered ones. TODO - elaborate. - **uint16_t getValue(uint8_t channel)** returns the last value written. @@ -52,8 +54,9 @@ BEFORE the **begin()** function. #### experimental -- **void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select)** overrule GPIO pins of ESP32 for hardware SPI. needs to be called -AFTER the **begin()** function. +- **void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select)** +overrule GPIO pins of ESP32 for hardware SPI. +Needs to be called AFTER the **begin()** function. ### Power down @@ -75,13 +78,9 @@ Check datasheet for details. ### Broadcast - **void bufferValue(uint8_t channel, uint16_t value)** prepare a new value for a channel. -- **void broadcastBuffer()** write all buffers to all(up to 4) 8554's channel's -- **void broadcastValue(uint16_t value)** write value to all(up to 4) 8554's channel's -- **void broadcastPowerDown(uint8_t powerDownMode)** write powerDownMode to all 8554's channel's - -## Future - -- testing +- **void broadcastBuffer()** write all buffers to all(up to 4) 8554's channel's. +- **void broadcastValue(uint16_t value)** write value to all(up to 4) 8554's channel's. +- **void broadcastPowerDown(uint8_t powerDownMode)** write powerDownMode to all 8554's channel's. ## Operation @@ -105,3 +104,8 @@ See examples **demo_powerdown.ino** - idem + +## Future + +- testing + diff --git a/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino b/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino index 210e8fb6..759c5a03 100644 --- a/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino +++ b/libraries/DAC8554/examples/DAC8554_broadcast/DAC8554_broadcast.ino @@ -13,6 +13,7 @@ DAC8554 DAC_A(10, 0); DAC8554 DAC_B(11, 1); + void setup() { Serial.begin(115200); @@ -57,4 +58,6 @@ void loop() { } + // -- END OF FILE -- + diff --git a/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino b/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino index 73249e45..080912f3 100644 --- a/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino +++ b/libraries/DAC8554/examples/DAC8554_hw_spi/DAC8554_hw_spi.ino @@ -11,6 +11,7 @@ DAC8554 mydac(10); + void setup() { Serial.begin(115200); @@ -38,7 +39,7 @@ void loop() // minimal sinus for (long i = 0; i < 360; i++ ) { - long s = 32768 + 32768 * sin( i * (PI / 180.0)); + long s = 32767 + 32767 * sin( i * (PI / 180.0)); mydac.setValue(channel, s); int av = analogRead(A0); Serial.print(i); @@ -51,4 +52,6 @@ void loop() if (channel >= 4) channel = 0; } -// -- END OF FILE -- \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino b/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino index 953cd22e..4e634e70 100644 --- a/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino +++ b/libraries/DAC8554/examples/DAC8554_powerdown/DAC8554_powerdown.ino @@ -18,6 +18,7 @@ uint8_t chanB = 1; uint8_t chanC = 2; uint8_t chanD = 3; + void setup() { Serial.begin(115200); @@ -31,6 +32,7 @@ void setup() mydac.setPowerDown(chanD, DAC8554_POWERDOWN_1K); } + void loop() { Serial.println("Start sawtooth"); @@ -58,4 +60,6 @@ void loop() mydac.setPowerDown(chanA, DAC8554_POWERDOWN_NORMAL); } -// END OF FILE \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino b/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino index d9804ceb..17ecc636 100644 --- a/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino +++ b/libraries/DAC8554/examples/DAC8554_same_time_write/DAC8554_same_time_write.ino @@ -15,6 +15,7 @@ DAC8554 mydac(10); uint32_t lastTime = 0; uint16_t state = 0; + void setup() { Serial.begin(115200); @@ -23,6 +24,7 @@ void setup() mydac.begin(); } + void loop() { uint8_t chanA = 0; @@ -55,4 +57,6 @@ void loop() } } -// END OF FILE \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino b/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino index 2a7ba11d..b1934363 100644 --- a/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino +++ b/libraries/DAC8554/examples/DAC8554_sequential_write/DAC8554_sequential_write.ino @@ -16,6 +16,7 @@ DAC8554 mydac(10); uint32_t lastTime = 0; uint16_t state = 0; + void setup() { Serial.begin(115200); @@ -57,4 +58,6 @@ void loop() } } -// END OF FILE \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino b/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino index c577e40d..28a9e096 100644 --- a/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino +++ b/libraries/DAC8554/examples/DAC8554_sw_spi/DAC8554_sw_spi.ino @@ -51,4 +51,6 @@ void loop() } } -// END OF FILE \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/DAC8554/keywords.txt b/libraries/DAC8554/keywords.txt index a4dc7bc2..e20d4e2a 100644 --- a/libraries/DAC8554/keywords.txt +++ b/libraries/DAC8554/keywords.txt @@ -35,6 +35,7 @@ setGPIOpins KEYWORD2 # Constants (LITERAL1) DAC8554_LIB_VERSION LITERAL1 + DAC8554_POWERDOWN_NORMAL LITERAL1 DAC8554_POWERDOWN_1K LITERAL1 DAC8554_POWERDOWN_100K LITERAL1 diff --git a/libraries/DAC8554/library.json b/libraries/DAC8554/library.json index b71a41c5..ad2a1f82 100644 --- a/libraries/DAC8554/library.json +++ b/libraries/DAC8554/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/DAC8554" }, - "version": "0.2.3", + "version": "0.2.4", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "DAC8554.h" } diff --git a/libraries/DAC8554/library.properties b/libraries/DAC8554/library.properties index 1e21a0f6..2251e565 100644 --- a/libraries/DAC8554/library.properties +++ b/libraries/DAC8554/library.properties @@ -1,5 +1,5 @@ name=DAC8554 -version=0.2.3 +version=0.2.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for DAC8554 SPI Digital Analog Convertor diff --git a/libraries/DAC8554/test/unit_test_001.cpp b/libraries/DAC8554/test/unit_test_001.cpp index 4fdd51d3..bb51abd2 100644 --- a/libraries/DAC8554/test/unit_test_001.cpp +++ b/libraries/DAC8554/test/unit_test_001.cpp @@ -30,14 +30,23 @@ unittest_setup() { + fprintf(stderr, "DAC8554_LIB_VERSION: %s\n", (char *) DAC8554_LIB_VERSION); } - unittest_teardown() { } +unittest(test_constants) +{ + assertEqual(0x00, DAC8554_POWERDOWN_NORMAL ); + assertEqual(0x40, DAC8554_POWERDOWN_1K ); + assertEqual(0x80, DAC8554_POWERDOWN_100K ); + assertEqual(0xC0, DAC8554_POWERDOWN_HIGH_IMP); +} + + unittest(test_HW_constructor) { DAC8554 mydac(10); // not used address parameter