mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-18 16:03:22 +08:00
修复mico-sdk错误
This commit is contained in:
@@ -1,108 +1,108 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "mico_platform.h"
|
||||
#include "micokit_ext.h"
|
||||
|
||||
#define micokit_ext_log(M, ...) custom_log("MICOKIT_EXT", M, ##__VA_ARGS__)
|
||||
#define micokit_ext_log_trace() custom_log_trace("MICOKIT_EXT")
|
||||
|
||||
extern void user_key1_clicked_callback(void);
|
||||
extern void user_key1_long_pressed_callback(void);
|
||||
extern void user_key2_clicked_callback(void);
|
||||
extern void user_key2_long_pressed_callback(void);
|
||||
|
||||
//------------------------------------- API ------------------------------------
|
||||
OSStatus user_modules_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; // max char each line
|
||||
#if defined(MICO_EXT_KEY1)||defined(MICO_EXT_KEY2)
|
||||
button_init_t init;
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init DC Motor(GPIO)
|
||||
dc_motor_init();
|
||||
dc_motor_set(0); // off
|
||||
#endif
|
||||
|
||||
// init RGB LED(P9813)
|
||||
rgb_led_init();
|
||||
rgb_led_open(0, 0, 0); // off
|
||||
|
||||
// init OLED
|
||||
OLED_Init();
|
||||
OLED_Clear();
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", MODEL);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_1, oled_show_line);
|
||||
memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1);
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", "MiCO ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, oled_show_line);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Running... ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " ");
|
||||
|
||||
apds9930_sensor_init();
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init Light sensor(ADC)
|
||||
light_sensor_init();
|
||||
|
||||
// init infrared sensor(ADC)
|
||||
infrared_reflective_init();
|
||||
|
||||
// init user key1 && key2
|
||||
#ifdef MICO_EXT_KEY1
|
||||
init.gpio = MICO_EXT_KEY1;
|
||||
init.pressed_func = user_key1_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_1, init);
|
||||
#endif
|
||||
|
||||
#ifdef MICO_EXT_KEY2
|
||||
init.gpio = MICO_EXT_KEY2;
|
||||
init.pressed_func = user_key2_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_2, init);
|
||||
#endif
|
||||
|
||||
err = temp_hum_sensor_init();
|
||||
#endif
|
||||
|
||||
// int32_t temperature;
|
||||
// uint32_t humidity;
|
||||
//
|
||||
// while(1){
|
||||
// err = temp_hum_sensor_read( &temperature, &humidity );
|
||||
// if( err == kNoErr ){
|
||||
// platform_log( "temperature: %d, humidity = %d ", temperature, humidity);
|
||||
// }
|
||||
// sleep(1);
|
||||
// }
|
||||
//exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus micokit_ext_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
err = user_modules_init();
|
||||
|
||||
return err;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "mico_platform.h"
|
||||
#include "micokit_ext.h"
|
||||
|
||||
#define micokit_ext_log(M, ...) custom_log("MICOKIT_EXT", M, ##__VA_ARGS__)
|
||||
#define micokit_ext_log_trace() custom_log_trace("MICOKIT_EXT")
|
||||
|
||||
extern void user_key1_clicked_callback(void);
|
||||
extern void user_key1_long_pressed_callback(void);
|
||||
extern void user_key2_clicked_callback(void);
|
||||
extern void user_key2_long_pressed_callback(void);
|
||||
|
||||
//------------------------------------- API ------------------------------------
|
||||
OSStatus user_modules_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
char oled_show_line[OLED_DISPLAY_MAX_CHAR_PER_ROW+1] = {'\0'}; // max char each line
|
||||
#if defined(MICO_EXT_KEY1)||defined(MICO_EXT_KEY2)
|
||||
button_init_t init;
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init DC Motor(GPIO)
|
||||
dc_motor_init();
|
||||
dc_motor_set(0); // off
|
||||
#endif
|
||||
|
||||
// init RGB LED(P9813)
|
||||
rgb_led_init();
|
||||
rgb_led_open(0, 0, 0); // off
|
||||
|
||||
// init OLED
|
||||
OLED_Init();
|
||||
OLED_Clear();
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", MODEL);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_1, oled_show_line);
|
||||
memset(oled_show_line, '\0', OLED_DISPLAY_MAX_CHAR_PER_ROW+1);
|
||||
snprintf(oled_show_line, OLED_DISPLAY_MAX_CHAR_PER_ROW+1, "%s", "MiCO ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, oled_show_line);
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, " Running... ");
|
||||
OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, " ");
|
||||
|
||||
apds9930_sensor_init();
|
||||
|
||||
#ifndef CONFIG_CPU_MX1290
|
||||
// init Light sensor(ADC)
|
||||
light_sensor_init();
|
||||
|
||||
// init infrared sensor(ADC)
|
||||
infrared_reflective_init();
|
||||
|
||||
// init user key1 && key2
|
||||
#ifdef MICO_EXT_KEY1
|
||||
init.gpio = MICO_EXT_KEY1;
|
||||
init.pressed_func = user_key1_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_1, init);
|
||||
#endif
|
||||
|
||||
#ifdef MICO_EXT_KEY2
|
||||
init.gpio = MICO_EXT_KEY2;
|
||||
init.pressed_func = user_key2_clicked_callback;
|
||||
init.long_pressed_func = NULL;
|
||||
init.long_pressed_timeout = 5000;
|
||||
button_init( IOBUTTON_USER_2, init);
|
||||
#endif
|
||||
|
||||
err = temp_hum_sensor_init();
|
||||
#endif
|
||||
|
||||
// int32_t temperature;
|
||||
// uint32_t humidity;
|
||||
//
|
||||
// while(1){
|
||||
// err = temp_hum_sensor_read( &temperature, &humidity );
|
||||
// if( err == kNoErr ){
|
||||
// platform_log( "temperature: %d, humidity = %d ", temperature, humidity);
|
||||
// }
|
||||
// sleep(1);
|
||||
// }
|
||||
//exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus micokit_ext_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
err = user_modules_init();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_H_
|
||||
#define __MICOKIT_EXT_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
//------------------------- MicoKit-EXT board modules drivers ------------------
|
||||
#include "rgb_led/P9813/rgb_led.h"
|
||||
#include "display/VGM128064/oled.h"
|
||||
#include "motor/dc_motor/dc_motor.h"
|
||||
#include "keypad/gpio_button/button.h"
|
||||
|
||||
#include "sensor/light_adc/light_sensor.h"
|
||||
#include "sensor/APDS9930/APDS9930.h"
|
||||
#include "sensor/infrared_adc/infrared_reflective.h"
|
||||
|
||||
|
||||
#include "motion_sensor.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide driver interface for MiCOKit Ext devices
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICOKIT_EXT_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide device init driver interface for MiCOKit Ext or modules
|
||||
* @{
|
||||
*/
|
||||
|
||||
//--------------------------- MicoKit-EXT board info ---------------------------
|
||||
#define DEV_KIT_MANUFACTURER "MXCHIP"
|
||||
#define DEV_KIT_NAME "MiCOKit3288"
|
||||
|
||||
#define MFG_TEST_MAX_MODULE_NUM 3
|
||||
|
||||
|
||||
/**
|
||||
* @brief MicoKit-EXT board init
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus micokit_ext_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Init modules on MicoKit-EXT board.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus user_modules_init(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif // __MICOKIT_EXT_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 8-May-2015
|
||||
* @brief micokit extension board peripherals operations..
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_H_
|
||||
#define __MICOKIT_EXT_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
//------------------------- MicoKit-EXT board modules drivers ------------------
|
||||
#include "rgb_led/P9813/rgb_led.h"
|
||||
#include "display/VGM128064/oled.h"
|
||||
#include "motor/dc_motor/dc_motor.h"
|
||||
#include "keypad/gpio_button/button.h"
|
||||
|
||||
#include "sensor/light_adc/light_sensor.h"
|
||||
#include "sensor/APDS9930/APDS9930.h"
|
||||
#include "sensor/infrared_adc/infrared_reflective.h"
|
||||
|
||||
|
||||
#include "motion_sensor.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide driver interface for MiCOKit Ext devices
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICOKIT_EXT_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICOKIT_EXT_Driver MiCOKit Ext Driver
|
||||
* @brief Provide device init driver interface for MiCOKit Ext or modules
|
||||
* @{
|
||||
*/
|
||||
|
||||
//--------------------------- MicoKit-EXT board info ---------------------------
|
||||
#define DEV_KIT_MANUFACTURER "MXCHIP"
|
||||
#define DEV_KIT_NAME "MiCOKit3288"
|
||||
|
||||
#define MFG_TEST_MAX_MODULE_NUM 3
|
||||
|
||||
|
||||
/**
|
||||
* @brief MicoKit-EXT board init
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus micokit_ext_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Init modules on MicoKit-EXT board.
|
||||
*
|
||||
* @return kNoErr : on success.
|
||||
* @return kGeneralErr : if an error occurred
|
||||
*/
|
||||
OSStatus user_modules_init(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif // __MICOKIT_EXT_H_
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext_def.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 20-May-2015
|
||||
* @brief micokit extension board peripherals pin defines.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_DEF_H_
|
||||
#define __MICOKIT_EXT_DEF_H_
|
||||
|
||||
//-------------------------- MicoKit-EXT board pin define ----------------------
|
||||
#ifdef CONFIG_CPU_MX1290
|
||||
#define SSD1106_USE_I2C
|
||||
#define OLED_I2C_PORT (Arduino_I2C)
|
||||
#else
|
||||
#define OLED_SPI_PORT (Arduino_SPI)
|
||||
#define OLED_SPI_SCK (Arduino_SCK)
|
||||
#define OLED_SPI_DIN (Arduino_SI)
|
||||
#define OLED_SPI_DC (Arduino_SO)
|
||||
#define OLED_SPI_CS (Arduino_CS)
|
||||
#endif
|
||||
|
||||
#define P9813_PIN_CIN (Arduino_SCL)
|
||||
#define P9813_PIN_DIN (Arduino_SDA)
|
||||
|
||||
#define DC_MOTOR (Arduino_D9)
|
||||
|
||||
#define MICO_EXT_KEY1 (Arduino_D4)
|
||||
#define MICO_EXT_KEY2 (Arduino_D5)
|
||||
|
||||
#define BME280_I2C_DEVICE (Arduino_I2C)
|
||||
#define DHT11_DATA (Arduino_D8)
|
||||
|
||||
#define APDS9930_I2C_DEVICE (Arduino_I2C)
|
||||
|
||||
#define LIGHT_SENSOR_ADC (Arduino_A2)
|
||||
#define INFARAED_REFLECTIVE_ADC (Arduino_A3)
|
||||
|
||||
|
||||
#endif // __MICOKIT_EXT_DEF_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file micokit_ext_def.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 20-May-2015
|
||||
* @brief micokit extension board peripherals pin defines.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MICOKIT_EXT_DEF_H_
|
||||
#define __MICOKIT_EXT_DEF_H_
|
||||
|
||||
//-------------------------- MicoKit-EXT board pin define ----------------------
|
||||
#ifdef CONFIG_CPU_MX1290
|
||||
#define SSD1106_USE_I2C
|
||||
#define OLED_I2C_PORT (Arduino_I2C)
|
||||
#else
|
||||
#define OLED_SPI_PORT (Arduino_SPI)
|
||||
#define OLED_SPI_SCK (Arduino_SCK)
|
||||
#define OLED_SPI_DIN (Arduino_SI)
|
||||
#define OLED_SPI_DC (Arduino_SO)
|
||||
#define OLED_SPI_CS (Arduino_CS)
|
||||
#endif
|
||||
|
||||
#define P9813_PIN_CIN (Arduino_SCL)
|
||||
#define P9813_PIN_DIN (Arduino_SDA)
|
||||
|
||||
#define DC_MOTOR (Arduino_D9)
|
||||
|
||||
#define MICO_EXT_KEY1 (Arduino_D4)
|
||||
#define MICO_EXT_KEY2 (Arduino_D5)
|
||||
|
||||
#define BME280_I2C_DEVICE (Arduino_I2C)
|
||||
#define DHT11_DATA (Arduino_D8)
|
||||
|
||||
#define APDS9930_I2C_DEVICE (Arduino_I2C)
|
||||
|
||||
#define LIGHT_SENSOR_ADC (Arduino_A2)
|
||||
#define INFARAED_REFLECTIVE_ADC (Arduino_A3)
|
||||
|
||||
|
||||
#endif // __MICOKIT_EXT_DEF_H_
|
||||
|
||||
@@ -87,7 +87,7 @@ void mico_notify_WifiScanCompleteHandler( ScanResult *pApList, void * inContext
|
||||
pApList->ApList[0].ssid[10] = '\0'; // truncate first 10 char
|
||||
sprintf( str, "SSID :%10s\r\nPOWER:%10d",
|
||||
pApList->ApList[0].ssid,
|
||||
pApList->ApList[0].ApPower );
|
||||
pApList->ApList[0].rssi );
|
||||
mf_printf_pos( 0, 4, str );
|
||||
scanap_done = true;
|
||||
}
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file motion_sensor.c
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief motion sensor control demo.
|
||||
******************************************************************************
|
||||
*
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/BMA2x2/bma2x2_user.h"
|
||||
#include "sensor/BMG160/bmg160_user.h"
|
||||
#include "sensor/BMM050/bmm050_user.h"
|
||||
#include "motion_sensor.h"
|
||||
|
||||
OSStatus motion_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor init*/
|
||||
err = bma2x2_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor init*/
|
||||
err = bmg160_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor init*/
|
||||
err = bmm050_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_readout(motion_data_t *motion_data)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor data read*/
|
||||
err = bma2x2_data_readout(&motion_data->accel_data.accel_datax,
|
||||
&motion_data->accel_data.accel_datay,
|
||||
&motion_data->accel_data.accel_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor data read*/
|
||||
err = bmg160_data_readout(&motion_data->gyro_data.gyro_datax,
|
||||
&motion_data->gyro_data.gyro_datay,
|
||||
&motion_data->gyro_data.gyro_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor data read*/
|
||||
err = bmm050_data_readout(&motion_data->mag_data.mag_dataz,
|
||||
&motion_data->mag_data.mag_datay,
|
||||
&motion_data->mag_data.mag_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_deinit(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor deinit*/
|
||||
err = bma2x2_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor deinit*/
|
||||
err = bmg160_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor deinit*/
|
||||
err = bmm050_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file motion_sensor.c
|
||||
* @author William Xu
|
||||
* @version V1.0.0
|
||||
* @date 21-May-2015
|
||||
* @brief motion sensor control demo.
|
||||
******************************************************************************
|
||||
*
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/BMA2x2/bma2x2_user.h"
|
||||
#include "sensor/BMG160/bmg160_user.h"
|
||||
#include "sensor/BMM050/bmm050_user.h"
|
||||
#include "motion_sensor.h"
|
||||
|
||||
OSStatus motion_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor init*/
|
||||
err = bma2x2_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor init*/
|
||||
err = bmg160_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor init*/
|
||||
err = bmm050_sensor_init();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_readout(motion_data_t *motion_data)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor data read*/
|
||||
err = bma2x2_data_readout(&motion_data->accel_data.accel_datax,
|
||||
&motion_data->accel_data.accel_datay,
|
||||
&motion_data->accel_data.accel_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor data read*/
|
||||
err = bmg160_data_readout(&motion_data->gyro_data.gyro_datax,
|
||||
&motion_data->gyro_data.gyro_datay,
|
||||
&motion_data->gyro_data.gyro_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor data read*/
|
||||
err = bmm050_data_readout(&motion_data->mag_data.mag_dataz,
|
||||
&motion_data->mag_data.mag_datay,
|
||||
&motion_data->mag_data.mag_dataz);
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus motion_sensor_deinit(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
/*low-g acceleration sensor deinit*/
|
||||
err = bma2x2_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/*triaxial angular rate sensor deinit*/
|
||||
err = bmg160_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
/* triaxial geomagnetic sensor deinit*/
|
||||
err = bmm050_sensor_deinit();
|
||||
require_noerr( err, exit );
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file temp_hum_sensor.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 1-May-2015
|
||||
* @brief user interfaces for temperature && humidity sensor operation,
|
||||
* use DHT11 if bme280 not found.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/DHT11/DHT11.h"
|
||||
#include "sensor/BME280/bme280_user.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
static volatile temp_hum_sensor_type_t temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_NONE;
|
||||
|
||||
/*---------------------------------- function --------------------------------*/
|
||||
|
||||
OSStatus temp_hum_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
|
||||
err = bme280_sensor_init();
|
||||
if(kNoErr != err){ // bme280 not work, use DHT11
|
||||
bme280_sensor_deinit();
|
||||
|
||||
ret = DHT11_Init();
|
||||
if(0 != ret){ // init error
|
||||
err = kNoResourcesErr;
|
||||
}
|
||||
else{
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_DHT11;
|
||||
err = kNoErr;
|
||||
}
|
||||
}
|
||||
else{ // use bme280
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_BME280;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus temp_hum_sensor_read(int32_t *temperature, uint32_t *humidity)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
uint8_t dht11_temp = 0;
|
||||
uint8_t dht11_hum = 0;
|
||||
int32_t bme280_temp = 0;
|
||||
uint32_t bme280_hum = 0;
|
||||
uint32_t bme280_press = 0;
|
||||
|
||||
switch(temp_hum_sensor_type){
|
||||
case MICOKIT_TEMP_HUM_SENSOR_BME280:
|
||||
{
|
||||
err = bme280_data_readout(&bme280_temp, &bme280_press, &bme280_hum);
|
||||
*temperature = bme280_temp/100;
|
||||
*humidity = bme280_hum/1024;
|
||||
break;
|
||||
}
|
||||
case MICOKIT_TEMP_HUM_SENSOR_DHT11:
|
||||
{
|
||||
ret = DHT11_Read_Data(&dht11_temp, &dht11_hum);
|
||||
if(0 != ret || dht11_hum == 0 ){
|
||||
err = kReadErr;
|
||||
}
|
||||
else{
|
||||
*temperature = (int32_t)dht11_temp;
|
||||
*humidity = (uint32_t)dht11_hum;
|
||||
err = kNoErr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
err = kUnsupportedErr;
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file temp_hum_sensor.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 1-May-2015
|
||||
* @brief user interfaces for temperature && humidity sensor operation,
|
||||
* use DHT11 if bme280 not found.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "sensor/DHT11/DHT11.h"
|
||||
#include "sensor/BME280/bme280_user.h"
|
||||
#include "temp_hum_sensor.h"
|
||||
|
||||
static volatile temp_hum_sensor_type_t temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_NONE;
|
||||
|
||||
/*---------------------------------- function --------------------------------*/
|
||||
|
||||
OSStatus temp_hum_sensor_init(void)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
|
||||
err = bme280_sensor_init();
|
||||
if(kNoErr != err){ // bme280 not work, use DHT11
|
||||
bme280_sensor_deinit();
|
||||
|
||||
ret = DHT11_Init();
|
||||
if(0 != ret){ // init error
|
||||
err = kNoResourcesErr;
|
||||
}
|
||||
else{
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_DHT11;
|
||||
err = kNoErr;
|
||||
}
|
||||
}
|
||||
else{ // use bme280
|
||||
temp_hum_sensor_type = MICOKIT_TEMP_HUM_SENSOR_BME280;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
OSStatus temp_hum_sensor_read(int32_t *temperature, uint32_t *humidity)
|
||||
{
|
||||
OSStatus err = kUnknownErr;
|
||||
uint8_t ret = 0;
|
||||
uint8_t dht11_temp = 0;
|
||||
uint8_t dht11_hum = 0;
|
||||
int32_t bme280_temp = 0;
|
||||
uint32_t bme280_hum = 0;
|
||||
uint32_t bme280_press = 0;
|
||||
|
||||
switch(temp_hum_sensor_type){
|
||||
case MICOKIT_TEMP_HUM_SENSOR_BME280:
|
||||
{
|
||||
err = bme280_data_readout(&bme280_temp, &bme280_press, &bme280_hum);
|
||||
*temperature = bme280_temp/100;
|
||||
*humidity = bme280_hum/1024;
|
||||
break;
|
||||
}
|
||||
case MICOKIT_TEMP_HUM_SENSOR_DHT11:
|
||||
{
|
||||
ret = DHT11_Read_Data(&dht11_temp, &dht11_hum);
|
||||
if(0 != ret || dht11_hum == 0 ){
|
||||
err = kReadErr;
|
||||
}
|
||||
else{
|
||||
*temperature = (int32_t)dht11_temp;
|
||||
*humidity = (uint32_t)dht11_hum;
|
||||
err = kNoErr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
err = kUnsupportedErr;
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user