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