moved macros to implementation file, end-of-line normalization, code style

This commit is contained in:
Niclas Finne 2011-11-17 14:44:20 +01:00
parent 013571ed3f
commit 987b57b015
2 changed files with 384 additions and 385 deletions

View File

@ -1,320 +1,330 @@
/* Copyright (c) 2009 ARAGO SYSTEMS /* Copyright (c) 2009 ARAGO SYSTEMS
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of the copyright holders nor the names of * Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
/* #include "dev/sht15.h"
$Id: v 0.1 2011/02/15 tchapelle Exp $
*/ #define DATA_OUT() P3DIR |= BIT7
#include "dev/sht15.h" #define DATA_IN() P3DIR &= ~BIT7
#define DATA_SET() P3OUT |= BIT7; halMcuWaitUs(10)
/*********************************************************************************** #define DATA_CLR() P3OUT &= ~BIT7; halMcuWaitUs(10)
* @fn halMcuWaitUs #define DATA_VAL() (P3IN & BIT7)
*
* @brief Busy wait function. Waits the specified number of microseconds. Use #define SCK_OUT() P5DIR |= BIT4
* assumptions about number of clock cycles needed for the various #define SCK_SET() P5OUT |= BIT4; halMcuWaitUs(10)
* instructions. The duration of one cycle depends on MCLK. In this HAL #define SCK_CLR() P5OUT &= ~BIT4; halMcuWaitUs(10)
* , it is set to 8 MHz, thus 8 cycles per usec.
*
* NB! This function is highly dependent on architecture and compiler! /***********************************************************************************
* * @fn halMcuWaitUs
* @param uint16 usec - number of microseconds delay *
* * @brief Busy wait function. Waits the specified number of microseconds. Use
* @return none * assumptions about number of clock cycles needed for the various
*/ * instructions. The duration of one cycle depends on MCLK. In this HAL
* , it is set to 8 MHz, thus 8 cycles per usec.
/* #pragma optimize=none */ *
void halMcuWaitUs(uint16_t usec) // 5 cycles for calling * NB! This function is highly dependent on architecture and compiler!
{ *
// The least we can wait is 3 usec: * @param uint16 usec - number of microseconds delay
// ~1 usec for call, 1 for first compare and 1 for return *
while(usec > 3) // 2 cycles for compare * @return none
{ // 2 cycles for jump */
nop(); // 1 cycles for nop
nop(); // 1 cycles for nop /* #pragma optimize=none */
nop(); // 1 cycles for nop void
nop(); // 1 cycles for nop halMcuWaitUs(uint16_t usec) /* 5 cycles for calling */
nop(); // 1 cycles for nop {
nop(); // 1 cycles for nop /* The least we can wait is 3 usec: */
nop(); // 1 cycles for nop /* ~1 usec for call, 1 for first compare and 1 for return */
nop(); // 1 cycles for nop while(usec > 3) /* 2 cycles for compare */
usec -= 2; // 1 cycles for optimized decrement { /* 2 cycles for jump */
} nop(); /* 1 cycles for nop */
} // 4 cycles for returning nop(); /* 1 cycles for nop */
nop(); /* 1 cycles for nop */
nop(); /* 1 cycles for nop */
/** nop(); /* 1 cycles for nop */
SHT15/75 Driver nop(); /* 1 cycles for nop */
nop(); /* 1 cycles for nop */
!!! be advise that the SHT15 and SHT75 are not i2C compliant sensors nop(); /* 1 cycles for nop */
they are just designed to not disturb i2C devices on a 2 wire bus usec -= 2; /* 1 cycles for optimized decrement */
this driver allow to drive the sensor with GPIO and delay }
*/ } /* 4 cycles for returning */
/***********************************************************************************
* @fn sht15_send_start /**
* SHT15/75 Driver
* @brief This function perform the start sequence asked by SHT15 and SHT75
* !!! be advise that the SHT15 and SHT75 are not i2C compliant sensors
* they are just designed to not disturb i2C devices on a 2 wire bus
* this driver allow to drive the sensor with GPIO and delay
* @param none */
*
* @return none /***********************************************************************************
*/ * @fn sht15_send_start
void sht15_send_start() *
{ * @brief This function perform the start sequence asked by SHT15 and SHT75
// Sequence is to set data line to 1 then clock line to 1 *
// then set data line to 0, clock line to 0 *
// then set clock line to 1 and data line to 1 *
// ___________ ________ * @param none
// data line : _____/ \___________/ *
// ___________ ____________ * @return none
// clock line : _________/ \___/ */
void
DATA_OUT(); sht15_send_start(void)
DATA_SET(); {
SCK_SET(); /* Sequence is to set data line to 1 then clock line to 1
DATA_CLR(); then set data line to 0, clock line to 0
SCK_CLR(); then set clock line to 1 and data line to 1
SCK_SET(); ___________ ________
DATA_SET(); data line : _____/ \___________/
SCK_CLR(); ___________ ____________
} clock line : _________/ \___/
/*********************************************************************************** */
* @fn sht15_read16()
* DATA_OUT();
* @brief DATA_SET();
* SCK_SET();
* DATA_CLR();
* SCK_CLR();
* @param none SCK_SET();
* DATA_SET();
* @return uint16_t SCK_CLR();
*/ }
uint16_t sht15_read16() /***********************************************************************************
{ * @fn sht15_read16()
uint16_t i; *
DATA_IN(); * @brief
*
SCK_CLR(); *
uint16_t val = 0; *
* @param none
for(i = 0; i < 18; i++) *
{ * @return uint16_t
if((i != 8) && (i != 17)) */
{ uint16_t
SCK_SET(); sht15_read16(void)
if(DATA_VAL()) {
val |= 1; uint16_t i;
DATA_IN();
val <<= 1;
SCK_CLR(); SCK_CLR();
} uint16_t val = 0;
else if(i == 8) // Wait for first ACK from SHT15
{ for(i = 0; i < 18; i++) {
DATA_OUT(); if((i != 8) && (i != 17)) {
SCK_SET();
DATA_CLR(); if(DATA_VAL()) {
val |= 1;
SCK_SET(); }
SCK_CLR();
val <<= 1;
DATA_IN(); SCK_CLR();
} } else if(i == 8) { /* Wait for first ACK from SHT15 */
else if(i == 17) // Wait for second ACK from SHT15 DATA_OUT();
{
DATA_OUT(); DATA_CLR();
DATA_SET(); SCK_SET();
SCK_CLR();
SCK_SET();
SCK_CLR(); DATA_IN();
} } else if(i == 17) { /* Wait for second ACK from SHT15 */
} DATA_OUT();
return val;
} DATA_SET();
/***********************************************************************************
* @fn sht15_write8 SCK_SET();
* SCK_CLR();
* @brief }
* }
* return val;
* }
* @param uint8 val /***********************************************************************************
* * @fn sht15_write8
* @return none *
*/ * @brief
void sht15_write8(uint8_t val) *
{ *
uint16_t i; *
* @param uint8 val
DATA_OUT(); *
* @return none
for(i = 0; i < 8; i++) */
{ void
halMcuWaitUs(4); sht15_write8(uint8_t val)
SCK_CLR(); {
uint16_t i;
if(val & 0x80)
{ DATA_OUT();
DATA_SET();
} for(i = 0; i < 8; i++) {
else halMcuWaitUs(4);
{ SCK_CLR();
DATA_CLR();
} if(val & 0x80) {
val <<= 1; DATA_SET();
} else {
SCK_SET(); DATA_CLR();
} }
val <<= 1;
DATA_IN();
SCK_SET();
SCK_CLR(); }
while(DATA_VAL()); DATA_IN();
SCK_SET(); SCK_CLR();
SCK_CLR();
} while(DATA_VAL());
/***********************************************************************************
* @fn sht15_wait_measure SCK_SET();
* SCK_CLR();
* @brief }
* /***********************************************************************************
* * @fn sht15_wait_measure
* *
* @param none * @brief
* *
* @return none *
*/ *
void sht15_wait_measure() * @param none
{ *
while(DATA_VAL()); * @return none
} */
/*********************************************************************************** void
* @fn sht15_init sht15_wait_measure(void)
* {
* @brief while(DATA_VAL());
* }
* /***********************************************************************************
* * @fn sht15_init
* @param none *
* * @brief
* @return none *
*/ *
void sht15_init() *
{ * @param none
// DATA and SCK lines are I/O *
P3SEL &= ~BIT7; * @return none
P5SEL &= ~BIT4; */
// Set SCK and DATA as output void
DATA_OUT(); sht15_init(void)
SCK_OUT(); {
DATA_SET(); /* DATA and SCK lines are I/O */
SCK_SET(); P3SEL &= ~BIT7;
} P5SEL &= ~BIT4;
/*********************************************************************************** /* Set SCK and DATA as output */
* @fn sht15_measure_temp DATA_OUT();
* SCK_OUT();
* @brief DATA_SET();
* SCK_SET();
* }
* /***********************************************************************************
* @param none * @fn sht15_measure_temp
* *
* @return none * @brief
*/ *
void sht15_measure_temp() *
{ *
sht15_send_start(); * @param none
sht15_write8(3); *
} * @return none
/*********************************************************************************** */
* @fn sht15_measure_hum void
* sht15_measure_temp(void)
* @brief {
* sht15_send_start();
* sht15_write8(3);
* }
* @param none /***********************************************************************************
* * @fn sht15_measure_hum
* @return none *
*/ * @brief
void sht15_measure_hum() *
{ *
sht15_send_start(); *
sht15_write8(5); * @param none
} *
/*********************************************************************************** * @return none
* @fn sht15_read_status */
* void sht15_measure_hum()
* @brief {
* sht15_send_start();
* sht15_write8(5);
* }
* @param none /***********************************************************************************
* * @fn sht15_read_status
* @return none *
*/ * @brief
void sht15_read_status() *
{ *
sht15_send_start(); *
sht15_write8(7); * @param none
} *
/*********************************************************************************** * @return none
* @fn sht15_write_status */
* void
* @brief sht15_read_status()
* {
* sht15_send_start();
* sht15_write8(7);
* @param none }
* /***********************************************************************************
* @return none * @fn sht15_write_status
*/ *
void sht15_write_status() * @brief
{ *
sht15_send_start(); *
sht15_write8(6); *
} * @param none
/*********************************************************************************** *
* @fn sht15_soft_reset * @return none
* */
* @brief void
* sht15_write_status(void)
* {
* sht15_send_start();
* @param none sht15_write8(6);
* }
* @return none /***********************************************************************************
*/ * @fn sht15_soft_reset
void sht15_soft_reset() *
{ * @brief
sht15_send_start(); *
sht15_write8(30); *
} *
* @param none
*
* @return none
*/
void
sht15_soft_reset(void)
{
sht15_send_start();
sht15_write8(30);
}

View File

@ -1,65 +1,54 @@
/* Copyright (c) 2009 ARAGO SYSTEMS /* Copyright (c) 2009 ARAGO SYSTEMS
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of the copyright holders nor the names of * Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
/* /*
$Id: v 0.1 2011/02/15 tchapelle Exp $ $Id: v 0.1 2011/02/15 tchapelle Exp $
*/ */
/** /**
SHT15/75 Driver SHT15/75 Driver
!!! be advise that the SHT15 and SHT75 are not i2C compliant sensors !!! be advise that the SHT15 and SHT75 are not i2C compliant sensors
they are just designed to not disturb i2C devices on a 2 wire bus they are just designed to not disturb i2C devices on a 2 wire bus
this driver allow to drive the sensor with GPIO and delay this driver allow to drive the sensor with GPIO and delay
*/ */
#include "contiki.h" #include "contiki.h"
#define DATA_OUT() P3DIR |= BIT7 /***********************************************************************************
#define DATA_IN() P3DIR &= ~BIT7 * SHT15 functions
#define DATA_SET() P3OUT |= BIT7; halMcuWaitUs(10) */
#define DATA_CLR() P3OUT &= ~BIT7; halMcuWaitUs(10) void sht15_init();
#define DATA_VAL() (P3IN & BIT7) void sht15_measure_temp();
void sht15_measure_hum();
#define SCK_OUT() P5DIR |= BIT4 void sht15_wait_measure();
#define SCK_SET() P5OUT |= BIT4; halMcuWaitUs(10) void sht15_read_status();
#define SCK_CLR() P5OUT &= ~BIT4; halMcuWaitUs(10) void sht15_write_status();
void sht15_soft_reset();
uint16_t sht15_read16();
/*********************************************************************************** void sht15_write8(uint8_t val);
* SHT15 functions
*/
void sht15_init();
void sht15_measure_temp();
void sht15_measure_hum();
void sht15_wait_measure();
void sht15_read_status();
void sht15_write_status();
void sht15_soft_reset();
uint16_t sht15_read16();
void sht15_write8(uint8_t val);