4 #include "libs/Kernel.h"
5 #include "libs/utils.h"
11 #define max(a,b) (((a) > (b)) ? (a) : (b))
13 class AD5206
: public DigipotBase
{
16 this->spi
= new mbed::SPI(P0_9
,P0_8
,P0_7
); //should be able to set those pins in config
17 cs
.from_string("4.29")->as_output(); //this also should be configurable
19 for (int i
= 0; i
< 6; i
++) currents
[i
] = -1;
22 void set_current( int channel
, float current
)
26 currents
[channel
]= -1;
29 current
= min( max( current
, 0.0L ), 2.0L );
30 char adresses
[6] = { 0x05, 0x03, 0x01, 0x00, 0x02, 0x04 };
31 currents
[channel
] = current
;
33 spi
->write((int)adresses
[channel
]);
34 spi
->write((int)current_to_wiper(current
));
40 //taken from 4pi firmware
41 unsigned char current_to_wiper( float current
){
42 unsigned int count
= int((current
*1000)*100/743); //6.8k resistor and 10k pot
44 return (unsigned char)count
;
47 float get_current(int channel
)
50 return currents
[channel
];