[Tinyos-beta-commits] CVS: tinyos-1.x/beta/chips/AD524X AD5241.nc,
NONE, 1.1 AD5241C.nc, NONE, 1.1 AD5242.nc, NONE,
1.1 AD5242C.nc, NONE, 1.1 AD524XM.nc, NONE, 1.1
Joe Polastre
jpolastre at users.sourceforge.net
Mon Jan 31 21:05:12 PST 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/chips/AD524X
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14501
Added Files:
AD5241.nc AD5241C.nc AD5242.nc AD5242C.nc AD524XM.nc
Log Message:
initial checkin of the AD524X series potentiometer drivers
current supports the AD5241 and AD5242 single/dual channel potentiometers
this implementation using the new i2cpacket interface exported by the
msp430 platform. it is provided in beta until the rest of the tree
(ie: mica* platforms) are updated to reflect the new i2cpacket interface
a discussion of the interface change is available from the tinyos-devel
mailing list:
http://mail.millennium.berkeley.edu/mailman/private/tinyos-devel/2005-January/000558.html
--- NEW FILE: AD5241.nc ---
// $Id: AD5241.nc,v 1.1 2005/02/01 05:05:09 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* @author Joe Polastre
* Revision: $Revision: 1.1 $
*
* The AD5241 interface provides commands for using the
* Analog Devices AD5241 single-channel 256-position digitally
* controlled variable resistor device. The AD5241 and AD5242
* share the same I2C bus protocol, but they are kept as seperate
* interfaces to enforce compile time errors
* (ie: trying to use Pot2 on the AD5241 should not be permitted).
*
* The lower 2 bits (AD1 and AD0) must be provided as the address.
* The full address may be provided as well, but all other bits will be
* stripped (addr = addr & 0x03)
*/
interface AD5241 {
/**
* Start the AD5241 device. This sets the SD bit to enable the device
* via the I2C bus. This command does not alter the physical shutdown
* pin of the device. The StdControl interface is responsible for
* the physical shutdown of the device.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t start(uint8_t addr);
/**
* Notification that there was an attempt to set the SD bit.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the bit was actually set, FAIL if the
* device could not be reached or the operation failed
*/
event void startDone(uint8_t addr, result_t result);
/**
* Stop the AD5241 device. This clears the SD bit to enable the device
* via the I2C bus. This command does not alter the physical shutdown
* pin of the device. The StdControl interface is responsible for
* the physical shutdown of the device.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t stop(uint8_t addr);
/**
* Notification that there was an attempt to clear the SD bit.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the bit was actually cleared, FAIL if the
* device could not be reached or the operation failed
*/
event void stopDone(uint8_t addr, result_t result);
/**
* Set the value of the Output 1 (O1) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param high TRUE if O1 should be set, FALSE if it should be cleared
* @return SUCCESS if the request was accepted
*/
command result_t setOutput1(uint8_t addr, bool high);
/**
* Notification that the state of the O1 pin may have changed.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the output O1 was successfully changed
* @return SUCCESS if the request was accepted
*/
event void setOutput1Done(uint8_t addr, result_t result);
/**
* Set the value of the Output 2 (O2) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param high TRUE if O2 should be set, FALSE if it should be cleared
* @return SUCCESS if the request was accepted
*/
command result_t setOutput2(uint8_t addr, bool high);
/**
* Notification that the state of the O2 pin may have changed.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the output O2 was successfully changed
* @return SUCCESS if the request was accepted
*/
event void setOutput2Done(uint8_t addr, result_t result);
/**
* Get the value of the Output 1 (O1) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return TRUE if the bit is set, FALSE otherwise
*/
command bool getOutput1(uint8_t addr);
/**
* Get the value of the Output 2 (O2) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return TRUE if the bit is set, FALSE otherwise
*/
command bool getOutput2(uint8_t addr);
/**
* Set the value of RDAC 1 (potentiometer channel 1)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @return SUCCESS if the request was accepted
*/
command result_t setPot1(uint8_t addr, uint8_t value);
/**
* Notification that RDAC1 may be set to a new value
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param SUCCESS if the value of RDAC1 was changed
*/
event void setPot1Done(uint8_t addr, result_t result);
/**
* Get the value of RDAC 1 (potentiometer channel 1)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t getPot1(uint8_t addr);
/**
* Result of the get operation with the value of the RDAC 1 potentiometer.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @param result SUCCESS if the value was correctly obtained from the
* device. If FAIL is returned, the value is not valid.
*/
event void getPot1Done(uint8_t addr, uint8_t value, result_t result);
}
--- NEW FILE: AD5241C.nc ---
// $Id: AD5241C.nc,v 1.1 2005/02/01 05:05:09 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* @author Joe Polastre
* Revision: $Revision: 1.1 $
*
* AD5241C provides access to primitives for the AD5241
* single-channel digital potentiometer. It provides interface AD5241
* for digital commands to and from the potentiometer. StdControl
* sets the physical hardware pin to turn the device on or off via the
* shutdown pin (if supported by the underlying platform).
*/
configuration AD5241C {
provides {
interface StdControl;
interface AD5241;
}
}
implementation
{
components I2CPacketC, AD524XM;
AD5241 = AD524XM;
StdControl = I2CPacketC;
AD524XM.I2CPacket -> I2CPacketC;
}
--- NEW FILE: AD5242.nc ---
// $Id: AD5242.nc,v 1.1 2005/02/01 05:05:09 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* @author Joe Polastre
* Revision: $Revision: 1.1 $
*
* The AD5242 interface provides commands for using the
* Analog Devices AD5242 dual-channel 256-position digitally
* controlled variable resistor device. The AD5241 and AD5242
* share the same I2C bus protocol, but they are kept as seperate
* interfaces to enforce compile time errors
* (ie: trying to use Pot2 on the AD5241 should not be permitted).
*
* The lower 2 bits (AD1 and AD0) must be provided as the address.
* The full address may be provided as well, but all other bits will be
* stripped (addr = addr & 0x03)
*/
interface AD5242 {
/**
* Start the AD5242 device. This sets the SD bit to enable the device
* via the I2C bus. This command does not alter the physical shutdown
* pin of the device. The StdControl interface is responsible for
* the physical shutdown of the device.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t start(uint8_t addr);
/**
* Notification that there was an attempt to set the SD bit.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the bit was actually set, FAIL if the
* device could not be reached or the operation failed
*/
event void startDone(uint8_t addr, result_t result);
/**
* Stop the AD5242 device. This clears the SD bit to enable the device
* via the I2C bus. This command does not alter the physical shutdown
* pin of the device. The StdControl interface is responsible for
* the physical shutdown of the device.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t stop(uint8_t addr);
/**
* Notification that there was an attempt to clear the SD bit.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the bit was actually cleared, FAIL if the
* device could not be reached or the operation failed
*/
event void stopDone(uint8_t addr, result_t result);
/**
* Set the value of the Output 1 (O1) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param high TRUE if O1 should be set, FALSE if it should be cleared
* @return SUCCESS if the request was accepted
*/
command result_t setOutput1(uint8_t addr, bool high);
/**
* Notification that the state of the O1 pin may have changed.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the output O1 was successfully changed
* @return SUCCESS if the request was accepted
*/
event void setOutput1Done(uint8_t addr, result_t result);
/**
* Set the value of the Output 2 (O2) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param high TRUE if O2 should be set, FALSE if it should be cleared
* @return SUCCESS if the request was accepted
*/
command result_t setOutput2(uint8_t addr, bool high);
/**
* Notification that the state of the O2 pin may have changed.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param result SUCCESS if the output O2 was successfully changed
* @return SUCCESS if the request was accepted
*/
event void setOutput2Done(uint8_t addr, result_t result);
/**
* Get the value of the Output 1 (O1) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return TRUE if the bit is set, FALSE otherwise
*/
command bool getOutput1(uint8_t addr);
/**
* Get the value of the Output 2 (O2) pin.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return TRUE if the bit is set, FALSE otherwise
*/
command bool getOutput2(uint8_t addr);
/**
* Set the value of RDAC 1 (potentiometer channel 1)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @return SUCCESS if the request was accepted
*/
command result_t setPot1(uint8_t addr, uint8_t value);
/**
* Notification that RDAC1 may be set to a new value
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param SUCCESS if the value of RDAC1 was changed
*/
event void setPot1Done(uint8_t addr, result_t result);
/**
* Get the value of RDAC 1 (potentiometer channel 1)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t getPot1(uint8_t addr);
/**
* Result of the get operation with the value of the RDAC 1 potentiometer.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @param result SUCCESS if the value was correctly obtained from the
* device. If FAIL is returned, the value is not valid.
*/
event void getPot1Done(uint8_t addr, uint8_t value, result_t result);
/**
* Set the value of RDAC 2 (potentiometer channel 2)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @return SUCCESS if the request was accepted
*/
command result_t setPot2(uint8_t addr, uint8_t value);
/**
* Notification that RDAC2 may be set to a new value
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param SUCCESS if the value of RDAC1 was changed
*/
event void setPot2Done(uint8_t addr, result_t result);
/**
* Get the value of RDAC 2 (potentiometer channel 2)
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @return SUCCESS if the request was accepted
*/
command result_t getPot2(uint8_t addr);
/**
* Result of the get operation with the value of the RDAC 2 potentiometer.
*
* @param addr Lower 2 bits (AD1,AD0) of the device I2C address
* @param value A 256-bit value corresponding to the wiper position
* @param result SUCCESS if the value was correctly obtained from the
* device. If FAIL is returned, the value is not valid.
*/
event void getPot2Done(uint8_t addr, uint8_t value, result_t result);
}
--- NEW FILE: AD5242C.nc ---
// $Id: AD5242C.nc,v 1.1 2005/02/01 05:05:09 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* @author Joe Polastre
* Revision: $Revision: 1.1 $
*
* AD5242C provides access to primitives for the AD5242
* dual-channel digital potentiometer. It provides interface AD5242
* for digital commands to and from the potentiometer. StdControl
* sets the physical hardware pin to turn the device on or off via the
* shutdown pin (if supported by the underlying platform).
*/
configuration AD5242C {
provides {
interface StdControl;
interface AD5242;
}
}
implementation
{
components I2CPacketC, AD524XM;
AD5242 = AD524XM;
StdControl = I2CPacketC;
AD524XM.I2CPacket -> I2CPacketC;
}
--- NEW FILE: AD524XM.nc ---
// $Id: AD524XM.nc,v 1.1 2005/02/01 05:05:09 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* @author Joe Polastre
* Revision: $Revision: 1.1 $
*
*/
module AD524XM
{
provides {
interface AD5241;
interface AD5242;
}
uses {
interface MSP430I2CPacket as I2CPacket;
}
}
implementation
{
enum {
AD524X_RDAC = 1 << 7,
AD524X_RS = 1 << 6,
AD524X_SD = 1 << 5,
AD524X_O1 = 1 << 4,
AD524X_O2 = 1 << 3
};
enum {
IDLE = 0,
AD5241_START,
AD5241_STOP,
AD5241_WRITE,
AD5241_READ,
AD5241_OUTPUT1,
AD5241_OUTPUT2,
AD5241_POT1,
AD5241_POT2,
AD5241_RPOT1,
AD5241_RPOT2,
AD5242_START,
AD5242_STOP,
AD5242_WRITE,
AD5242_READ,
AD5242_OUTPUT1,
AD5242_OUTPUT2,
AD5242_POT1,
AD5242_POT2,
AD5242_RPOT1,
AD5242_RPOT2,
};
uint8_t data[2];
uint8_t device[4];
uint8_t state = 0;
result_t startWriteCommand(uint8_t _addr, uint8_t _length, uint16_t _data, uint8_t _newstate) {
uint8_t _state = 0;
uint16_t* _data16 = (uint16_t*)data;
atomic {
_state = state;
if (_state == IDLE)
state = _newstate;
}
if (_state == IDLE) {
_data16[0] = _data;
if (!call I2CPacket.writePacket((_addr & 0x03) | 0x2C, _length, data)) {
state = IDLE;
return FAIL;
}
return SUCCESS;
}
return FAIL;
}
result_t startReadCommand(uint8_t _addr, uint8_t _length, uint8_t _newstate) {
uint8_t _state = 0;
atomic {
_state = state;
if (_state == IDLE)
state = _newstate;
}
if (_state == IDLE) {
if (!call I2CPacket.readPacket((_addr & 0x03) | 0x2C, _length, data)) {
state = IDLE;
return FAIL;
}
return SUCCESS;
}
return FAIL;
}
/** START commands **/
command result_t AD5241.start(uint8_t addr) {
atomic device[(int)(addr & 0x03)] &= ~AD524X_SD;
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5241_START);
}
command result_t AD5242.start(uint8_t addr) {
atomic device[(int)(addr & 0x03)] &= ~AD524X_SD;
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5242_START);
}
/** STOP commands **/
command result_t AD5241.stop(uint8_t addr) {
atomic device[(int)(addr & 0x03)] |= AD524X_SD;
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5241_STOP);
}
command result_t AD5242.stop(uint8_t addr) {
atomic device[(int)(addr & 0x03)] |= AD524X_SD;
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5242_STOP);
}
/** OUTPUT 1 **/
command result_t AD5241.setOutput1(uint8_t addr, bool high) {
atomic {
if (high)
device[(int)(addr & 0x03)] |= AD524X_O1;
else
device[(int)(addr & 0x03)] &= ~AD524X_O1;
}
return startWriteCommand(addr, 1, device[(int)addr & 0x03], AD5241_OUTPUT1);
}
command result_t AD5242.setOutput1(uint8_t addr, bool high) {
atomic {
if (high)
device[(int)(addr & 0x03)] |= AD524X_O1;
else
device[(int)(addr & 0x03)] &= ~AD524X_O1;
}
return startWriteCommand(addr, 1, device[(int)addr & 0x03], AD5242_OUTPUT1);
}
command result_t AD5241.getOutput1(uint8_t addr) {
bool _high;
atomic _high = (device[(int)(addr & 0x03)] & AD524X_O1) >> AD524X_O1;
return _high;
}
command result_t AD5242.getOutput1(uint8_t addr) {
bool _high;
atomic _high = (device[(int)(addr & 0x03)] & AD524X_O1) >> AD524X_O1;
return _high;
}
/** OUTPUT 2 **/
command result_t AD5241.setOutput2(uint8_t addr, bool high) {
atomic {
if (high)
device[(int)(addr & 0x03)] |= AD524X_O2;
else
device[(int)(addr & 0x03)] &= ~AD524X_O2;
}
return startWriteCommand(addr, 1, device[(int)addr & 0x03], AD5241_OUTPUT2);
}
command result_t AD5242.setOutput2(uint8_t addr, bool high) {
atomic {
if (high)
device[(int)(addr & 0x03)] |= AD524X_O2;
else
device[(int)(addr & 0x03)] &= ~AD524X_O2;
}
return startWriteCommand(addr, 1, device[(int)addr & 0x03], AD5242_OUTPUT2);
}
command result_t AD5241.getOutput2(uint8_t addr) {
bool _high;
atomic _high = (device[(int)(addr & 0x03)] & AD524X_O2) >> AD524X_O2;
return _high;
}
command result_t AD5242.getOutput2(uint8_t addr) {
bool _high;
atomic _high = (device[(int)(addr & 0x03)] & AD524X_O2) >> AD524X_O2;
return _high;
}
/** POT 1 - set commands**/
command result_t AD5241.setPot1(uint8_t addr, uint8_t value) {
uint16_t _temp;
atomic _temp = (device[(int)addr & 0x03] & ~AD524X_RDAC) | (value << 8);
return startWriteCommand(addr, 2, _temp, AD5241_POT1);
}
command result_t AD5242.setPot1(uint8_t addr, uint8_t value) {
uint16_t _temp;
atomic _temp = (device[(int)addr & 0x03] & ~AD524X_RDAC) | (value << 8);
return startWriteCommand(addr, 2, _temp, AD5242_POT1);
}
/** POT 2 - set commands**/
command result_t AD5242.setPot2(uint8_t addr, uint8_t value) {
uint16_t _temp;
atomic _temp = (device[(int)addr & 0x03] | AD524X_RDAC) | (value << 8);
return startWriteCommand(addr, 2, _temp, AD5242_POT2);
}
/** POT 1 - get commands**/
command result_t AD5241.getPot1(uint8_t addr) {
uint8_t _temp;
atomic _temp = (device[(int)addr & 0x03] & ~AD524X_RDAC);
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5241_RPOT1);
}
command result_t AD5242.getPot1(uint8_t addr) {
uint8_t _temp;
atomic _temp = (device[(int)addr & 0x03] & ~AD524X_RDAC);
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5242_RPOT1);
}
/** POT 2 - get commands**/
command result_t AD5242.getPot2(uint8_t addr) {
uint8_t _temp;
atomic _temp = (device[(int)addr & 0x03] | AD524X_RDAC);
return startWriteCommand(addr, 1, device[(int)(addr & 0x03)], AD5242_RPOT2);
}
event void I2CPacket.readPacketDone(uint16_t _addr, uint8_t _length, uint8_t* _data, result_t _success) {
uint8_t _state;
atomic _state = state;
// check if the buffer is ours
if (data != _data)
return;
switch (_state) {
case AD5241_RPOT1:
state = IDLE;
signal AD5241.getPot1Done(_addr & 0x03, data[0], _success);
break;
case AD5242_RPOT1:
state = IDLE;
signal AD5242.getPot1Done(_addr & 0x03, data[0], _success);
break;
case AD5242_RPOT2:
state = IDLE;
signal AD5242.getPot2Done(_addr & 0x03, data[0], _success);
break;
}
}
event void I2CPacket.writePacketDone(uint16_t _addr, uint8_t _length, uint8_t* _data, result_t _success) {
uint8_t _state;
atomic _state = state;
// check if the buffer is ours
if (data != _data)
return;
switch (_state) {
// AD5241 events
case AD5241_START:
state = IDLE;
signal AD5241.startDone(_addr & 0x03, _success);
break;
case AD5241_STOP:
state = IDLE;
signal AD5241.stopDone(_addr & 0x03, _success);
break;
case AD5241_OUTPUT1:
state = IDLE;
signal AD5241.setOutput1Done(_addr & 0x03, _success);
break;
case AD5241_OUTPUT2:
state = IDLE;
signal AD5241.setOutput2Done(_addr & 0x03, _success);
break;
case AD5241_POT1:
state = IDLE;
signal AD5241.setPot1Done(_addr & 0x03, _success);
break;
case AD5241_RPOT1:
state = IDLE;
startReadCommand(_addr, 1, AD5241_RPOT1);
break;
// AD5242 events
case AD5242_START:
state = IDLE;
signal AD5242.startDone(_addr & 0x03, _success);
break;
case AD5242_STOP:
state = IDLE;
signal AD5242.stopDone(_addr & 0x03, _success);
break;
case AD5242_OUTPUT1:
state = IDLE;
signal AD5242.setOutput1Done(_addr & 0x03, _success);
break;
case AD5242_OUTPUT2:
state = IDLE;
signal AD5242.setOutput2Done(_addr & 0x03, _success);
break;
case AD5242_POT1:
state = IDLE;
signal AD5242.setPot1Done(_addr & 0x03, _success);
break;
case AD5242_POT2:
state = IDLE;
signal AD5242.setPot2Done(_addr & 0x03, _success);
break;
case AD5242_RPOT1:
state = IDLE;
startReadCommand(_addr, 1, AD5242_RPOT1);
break;
case AD5242_RPOT2:
state = IDLE;
startReadCommand(_addr, 1, AD5242_RPOT2);
break;
}
}
default event void AD5241.startDone(uint8_t addr, result_t result) { }
default event void AD5241.stopDone(uint8_t addr, result_t result) { }
default event void AD5241.setOutput1Done(uint8_t addr, result_t result) { }
default event void AD5241.setOutput2Done(uint8_t addr, result_t result) { }
default event void AD5241.setPot1Done(uint8_t addr, result_t result) { }
default event void AD5241.getPot1Done(uint8_t addr, uint8_t value, result_t result) { }
default event void AD5242.startDone(uint8_t addr, result_t result) { }
default event void AD5242.stopDone(uint8_t addr, result_t result) { }
default event void AD5242.setOutput1Done(uint8_t addr, result_t result) { }
default event void AD5242.setOutput2Done(uint8_t addr, result_t result) { }
default event void AD5242.setPot1Done(uint8_t addr, result_t result) { }
default event void AD5242.getPot1Done(uint8_t addr, uint8_t value, result_t result) { }
default event void AD5242.setPot2Done(uint8_t addr, result_t result) { }
default event void AD5242.getPot2Done(uint8_t addr, uint8_t value, result_t result) { }
}
More information about the Tinyos-beta-commits
mailing list