Skip to content

Commit

Permalink
update library.json, license, unit test, minor edits (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Dec 15, 2021
1 parent 8f5f09c commit 2c5d82d
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 40 deletions.
25 changes: 14 additions & 11 deletions DAC8554.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
// 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:
// 0.1.0: 2017-12-19 initial version
// 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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -278,4 +279,6 @@ void DAC8554::swSPI_transfer(uint8_t value)
}
}


// -- END OF FILE --

23 changes: 16 additions & 7 deletions DAC8554.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
// 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
//

#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
Expand All @@ -31,37 +30,44 @@ class DAC8554

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
void broadcastValue(uint16_t value);
// 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; };
void selectVSPI() { _useHSPI = false; };
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
Expand All @@ -83,6 +89,7 @@ class DAC8554
void writeDevice(uint8_t configRegister, uint16_t value);
void swSPI_transfer(uint8_t value);


SPIClass * mySPI;
SPISettings _spi_settings;

Expand All @@ -91,4 +98,6 @@ class DAC8554
#endif
};


// -- END OF FILE --

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) 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
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# DAC8554

Arduino library for DAC8554 SPI Digital Analog Convertor
Arduino library for DAC8554 SPI Digital Analog Convertor.


## Description
Expand All @@ -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.


Expand All @@ -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
Expand All @@ -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
Expand All @@ -105,3 +104,8 @@ See examples
**demo_powerdown.ino**
- idem


## Future

- testing

3 changes: 3 additions & 0 deletions examples/DAC8554_broadcast/DAC8554_broadcast.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DAC8554 DAC_A(10, 0);
DAC8554 DAC_B(11, 1);


void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -57,4 +58,6 @@ void loop()
{
}


// -- END OF FILE --

7 changes: 5 additions & 2 deletions examples/DAC8554_hw_spi/DAC8554_hw_spi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

DAC8554 mydac(10);


void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -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);
Expand All @@ -51,4 +52,6 @@ void loop()
if (channel >= 4) channel = 0;
}

// -- END OF FILE --

// -- END OF FILE --

6 changes: 5 additions & 1 deletion examples/DAC8554_powerdown/DAC8554_powerdown.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ uint8_t chanB = 1;
uint8_t chanC = 2;
uint8_t chanD = 3;


void setup()
{
Serial.begin(115200);
Expand All @@ -31,6 +32,7 @@ void setup()
mydac.setPowerDown(chanD, DAC8554_POWERDOWN_1K);
}


void loop()
{
Serial.println("Start sawtooth");
Expand Down Expand Up @@ -58,4 +60,6 @@ void loop()
mydac.setPowerDown(chanA, DAC8554_POWERDOWN_NORMAL);
}

// END OF FILE

// -- END OF FILE --

6 changes: 5 additions & 1 deletion examples/DAC8554_same_time_write/DAC8554_same_time_write.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DAC8554 mydac(10);
uint32_t lastTime = 0;
uint16_t state = 0;


void setup()
{
Serial.begin(115200);
Expand All @@ -23,6 +24,7 @@ void setup()
mydac.begin();
}


void loop()
{
uint8_t chanA = 0;
Expand Down Expand Up @@ -55,4 +57,6 @@ void loop()
}
}

// END OF FILE

// -- END OF FILE --

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DAC8554 mydac(10);
uint32_t lastTime = 0;
uint16_t state = 0;


void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -57,4 +58,6 @@ void loop()
}
}

// END OF FILE

// -- END OF FILE --

4 changes: 3 additions & 1 deletion examples/DAC8554_sw_spi/DAC8554_sw_spi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ void loop()
}
}

// END OF FILE

// -- END OF FILE --

1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ setGPIOpins KEYWORD2

# Constants (LITERAL1)
DAC8554_LIB_VERSION LITERAL1

DAC8554_POWERDOWN_NORMAL LITERAL1
DAC8554_POWERDOWN_1K LITERAL1
DAC8554_POWERDOWN_100K LITERAL1
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/DAC8554"
},
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"frameworks": "arduino",
"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=DAC8554
version=0.2.3
version=0.2.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for DAC8554 SPI Digital Analog Convertor
Expand Down
Loading

0 comments on commit 2c5d82d

Please sign in to comment.