You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. /*
  2. Copyright 2017 Balz Guenat
  3. based on work by Jun Wako <wakojun@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "ad5258.h"
  16. #include "i2c_master.h"
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //
  19. // AD5258 I2C digital potentiometer
  20. // http://www.analog.com/media/en/technical-documentation/data-sheets/AD5258.pdf
  21. //
  22. #define AD5258_I2C_ADDRESS 0x30
  23. #define AD5258_INST_RDAC 0x00
  24. #define AD5258_INST_EEPROM 0x20
  25. void ad5258_init(void) {
  26. i2c_init();
  27. }
  28. uint8_t ad5258_read_rdac(void) {
  29. // read RDAC register
  30. uint8_t ret = 0;
  31. i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &ret, 1, 100);
  32. return ret;
  33. }
  34. uint8_t ad5258_read_eeprom(void) {
  35. uint8_t ret = 0;
  36. i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_EEPROM, &ret, 1, 100);
  37. return ret;
  38. }
  39. void ad5258_write_rdac(uint8_t rdac) {
  40. // write RDAC register:
  41. uint8_t data = rdac & 0x3F;
  42. i2c_write_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &data, 1, 100);
  43. }