Cleanup and refactoring of the STM32w port

This is a general cleanup of things like code style issues and code structure of the STM32w port to make it more like the rest of Contiki is structured.
This commit is contained in:
Adam Dunkels 2013-03-15 16:14:09 +01:00
parent 12b3d02ba1
commit a5046e83c7
118 changed files with 4470 additions and 4281 deletions

View file

@ -1,3 +1,8 @@
/**
* \addtogroup mb851-platform
*
* @{
*/
/*
* Copyright (c) 2010, STMicroelectronics.
* All rights reserved.
@ -27,18 +32,13 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This file is part of the Contiki OS
*
*/
/*---------------------------------------------------------------------------*/
/**
* \file
* Accelerometer.
* Accelerometer driver.
* \author
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
*/
/*---------------------------------------------------------------------------*/
#include "dev/acc-sensor.h"
#include "mems.h"
@ -46,82 +46,79 @@
#define FALSE 0
#define TRUE 1
/*---------------------------------------------------------------------------*/
static int
active(void)
{
int8u reg;
if(!i2c_read_reg (kLIS3L02DQ_SLAVE_ADDR,CTRL_REG1, &reg, 1))
uint8_t reg;
if(!i2c_read_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, &reg, 1)) {
return FALSE;
return (reg & 0x40) ? TRUE : FALSE ;
}
return (reg & 0x40) ? TRUE : FALSE;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
int8s i2c_data = 0;
int8u reg_addr;
switch(type) {
case ACC_X_AXIS:
reg_addr = OUTX_H;
break;
case ACC_Y_AXIS:
reg_addr = OUTY_H;
break;
case ACC_Z_AXIS:
reg_addr = OUTZ_H;
break;
default:
return 0;
}
i2c_read_reg(kLIS3L02DQ_SLAVE_ADDR, reg_addr, (int8u *)&i2c_data, 1);
if(MEMS_GetFullScale()==ACC_HIGH_RANGE){
return ((int16s)i2c_data)*HIGH_RANGE_SENSITIVITY;
}
else {
return ((int16s)i2c_data)*LOW_RANGE_SENSITIVITY;
int8_t i2c_data = 0;
uint8_t reg_addr;
switch (type) {
case ACC_X_AXIS:
reg_addr = OUTX_H;
break;
case ACC_Y_AXIS:
reg_addr = OUTY_H;
break;
case ACC_Z_AXIS:
reg_addr = OUTZ_H;
break;
default:
return 0;
}
i2c_read_reg(KLIS3L02DQ_SLAVE_ADDR, reg_addr, (uint8_t *) &i2c_data, 1);
if(mems_get_fullscale() == ACC_HIGH_RANGE) {
return ((int16_t) i2c_data) * HIGH_RANGE_SENSITIVITY;
} else {
return ((int16_t) i2c_data) * LOW_RANGE_SENSITIVITY;
}
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
return Mems_Init();
case SENSORS_ACTIVE:
if(value){
if(MEMS_On()){
clock_wait(8);
return 1;
}
return 0;
}
else
return MEMS_Off();
case ACC_RANGE:
return MEMS_SetFullScale((boolean)value);
case ACC_HPF:
if(value < ACC_HPF_DISABLE){
return i2c_write_reg(kLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, (1<<4) | (int8u)value);
}
else {
return i2c_write_reg(kLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, 0x00);
switch (type) {
case SENSORS_HW_INIT:
return mems_init();
case SENSORS_ACTIVE:
if(value) {
if(mems_on()) {
clock_wait(8);
return 1;
}
return 0;
} else {
return mems_off();
}
case ACC_RANGE:
return mems_set_fullscale((boolean) value);
case ACC_HPF:
if(value < ACC_HPF_DISABLE) {
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2,
(1 << 4) | (uint8_t) value);
} else {
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, 0x00);
}
}
return 0;
}
@ -129,18 +126,12 @@ configure(int type, int value)
static int
status(int type)
{
switch(type) {
switch (type) {
case SENSORS_READY:
return active();
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(acc_sensor, ACC_SENSOR,
value, configure, status);
SENSORS_SENSOR(acc_sensor, ACC_SENSOR, value, configure, status);
/** @} */