diff --git a/embedded/common/app/algorithm_t.c b/embedded/common/app/algorithm_t.c index eb82366..32d312b 100644 --- a/embedded/common/app/algorithm_t.c +++ b/embedded/common/app/algorithm_t.c @@ -26,6 +26,8 @@ /*--------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S \*--------------------------------------------------------------------*/ +osMutexDef(mutexCritSection); +osMutexId mutex_id; /*--------------------------------------------------------------------*\ | P U B L I C V A R I A B L E S D E F I N I T I O N S @@ -247,8 +249,6 @@ static const OSP_Library_Version_t* version; static ResultHandle_t _outSensorHandles[NUM_ANDROID_SENSOR_TYPE]; // Android Sensors static ResultHandle_t _outPSensorHandles[NUM_PRIVATE_SENSOR_TYPE]; // Private Sensors -static OS_MUT mutexCritSection; - /*--------------------------------------------------------------------*\ | F O R W A R D F U N C T I O N D E C L A R A T I O N S \*--------------------------------------------------------------------*/ @@ -277,12 +277,12 @@ SystemDescriptor_t gSystemDesc = **********************************************************************/ __inline void EnterCriticalSection(void) { - os_mut_wait( mutexCritSection, OS_WAIT_FOREVER ); + osMutexWait(mutex_id,osWaitForever); } __inline void ExitCriticalSection(void) { - os_mut_release( mutexCritSection ); + osMutexRelease(mutex_id); } @@ -760,7 +760,6 @@ static OSP_STATUS_t SensorControlActivate( SensorControl_t *pControl) { MessageBuffer *pSendMsg = NULLP; InputSensor_t sensorType; - InputSensorHandle_t Handle; if ( pControl == NULL ) return OSP_STATUS_NULL_POINTER; @@ -825,6 +824,9 @@ ASF_TASK void AlgorithmTask (ASF_TASK_ARG) OSP_GetLibraryVersion(&version); D1_printf("OSP Version: %s\r\n", version->VersionString); + /* Initialize the mutex */ + mutex_id = osMutexCreate(osMutex(mutexCritSection)); + OSP_Status = OSP_Initialize(&gSystemDesc); ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_Initialize Failed"); OSP_SetCalibrationConfig( 0x1); // disable rotational cal. @@ -909,6 +911,7 @@ ASF_TASK void AlgorithmTask (ASF_TASK_ARG) D1_printf("Alg-FG:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); break; } + ASFDeleteMessage( ALGORITHM_TASK_ID, &rcvMsg ); #ifdef DEBUG_TEST_SENSOR_SUBSCRIPTION // Testing subscribe and unsubscribe sensors DebugTestSensorSubscription(); @@ -952,6 +955,7 @@ ASF_TASK void AlgBackGndTask (ASF_TASK_ARG) D1_printf("Alg-BG:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); break; } + ASFDeleteMessage( ALG_BG_TASK_ID, &rcvMsg ); } } diff --git a/embedded/common/app/cmdhandler_t.c b/embedded/common/app/cmdhandler_t.c index ee4ef6c..80383d8 100644 --- a/embedded/common/app/cmdhandler_t.c +++ b/embedded/common/app/cmdhandler_t.c @@ -77,7 +77,8 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint uint32_t readIdx; uint16_t bytesRead = 0; uint8_t retVal = APP_OK; - uint16_t evtFlags = 0; + osEvent evtFlags; + evtFlags.value.v=0; if ((pBuff == NULL) || (length == 0) || (length > RX_BUFFER_SIZE)) { @@ -91,8 +92,18 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint ((pPort->rxReadIdx + 1) % RX_BUFFER_SIZE)) { /* Wait here for ISR event */ - os_evt_wait_or( UART_CMD_RECEIVE | UART_CRLF_RECEIVE, EVT_WAIT_FOREVER ); - evtFlags = os_evt_get(); + osThreadId myId = osThreadGetId(); + while(1){ + evtFlags = osSignalWait(UART_CMD_RECEIVE,200); + if (evtFlags.status == osEventTimeout){ + evtFlags = osSignalWait(UART_CRLF_RECEIVE,200); + } + if (evtFlags.status == osEventSignal){ + break; + } + } + osSignalClear(myId,UART_CMD_RECEIVE); + osSignalClear(myId,UART_CRLF_RECEIVE); } else { @@ -105,7 +116,7 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint } pBuff[bytesRead++] = pPort->rxBuffer[readIdx]; pPort->rxReadIdx = readIdx; - if ( evtFlags & UART_CRLF_RECEIVE ) + if ( evtFlags.value.signals & UART_CRLF_RECEIVE ) { break; } diff --git a/embedded/common/app/common.h b/embedded/common/app/common.h index 0b3511b..845623a 100644 --- a/embedded/common/app/common.h +++ b/embedded/common/app/common.h @@ -1,251 +1,250 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if !defined (COMMON_H) -#define COMMON_H - -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include -#include "hw_setup.h" -#include "asf_msgstruct.h" -#include "main.h" -#include "osp-types.h" -#include "asf_types.h" -#include "osp-version.h" - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#define OS_WAIT_NEVER 0x00 ///< Zero wait as defined by RTX -#define OS_WAIT_FOREVER 0xFFFF ///< Wait forever as defined by RTX -#define TIMER_SYS_ID 0xC0DEFEEDUL - -/* Critical Section Locks */ -#define OS_SETUP_CRITICAL() int wasMasked -#define OS_ENTER_CRITICAL() wasMasked = __disable_irq() -#define OS_LEAVE_CRITICAL() if (!wasMasked) __enable_irq() - -#ifdef DEBUG_BUILD -#define printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) - -/* Note: The USART enable in the asserts is required because in SensorAcq task we disable - it during sampling and in some rare cases there can be an assert while the UART was - in the disabled state (e.g. ISR doing CreateMessage and asserting) */ -# define ERR_LOG_MSG_SZ 150 -# define ASF_assert( condition ) \ - if (!(condition)) { \ - extern char _errBuff[]; \ - __disable_irq(); \ - AssertIndication(); \ - FlushUart(); \ - snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s]", __MODULE__, \ - __LINE__, #condition); \ - printf("%s\r\n", _errBuff); \ - SysRESET(); \ - } - -# define ASF_assert_var( condition, var1, var2, var3 ) \ - if (!(condition)) { \ - extern char _errBuff[]; \ - __disable_irq(); \ - AssertIndication(); \ - FlushUart(); \ - snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s], 0x%X, 0x%X, 0x%X", \ - __MODULE__, __LINE__, #condition, (uint32_t)var1, (uint32_t)var2, (uint32_t)var3);\ - printf("%s\r\n", _errBuff); \ - SysRESET(); \ - } - -# define ASF_assert_fatal( condition ) \ - if (!(condition)) { \ - extern char _errBuff[]; \ - __disable_irq(); \ - AssertIndication(); \ - FlushUart(); \ - snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT_FATAL: %s(%d) - [%s]", __MODULE__, \ - __LINE__, #condition); \ - printf("%s\r\n", _errBuff); \ - SysRESET(); \ - } - -# define ASF_assert_msg( condition, message ) \ - if (!(condition)) { \ - extern char _errBuff[]; \ - __disable_irq(); \ - AssertIndication(); \ - FlushUart(); \ - snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s], MSG:%.100s", \ - __MODULE__, __LINE__, #condition, message); \ - printf("%s\r\n", _errBuff); \ - SysRESET(); \ - } - -#else -# define ASF_assert( condition ) ((void)0) -# define ASF_assert_var( condition, var1, var2, var3 ) ((void)0) -# define ASF_assert_fatal( condition ) ((void)0) -# define ASF_assert_msg( condition, message ) ((void)0) -#endif //DEBUG_BUILD - -/* Command Parser / UART receive event */ -#define UART_CMD_RECEIVE 0x0020 -#define UART_CRLF_RECEIVE 0x0040 ///< Receive CR or LF character -#define EVT_WAIT_FOREVER 0xFFFF - -#define ASFKillTimer( ptim ) \ - _ASFKillTimer( ptim, __MODULE__, __LINE__ ) -#define ASFTimerExpiry( info ) \ - _ASFTimerExpiry( info, __MODULE__, __LINE__ ) -#define ASFTimerStart( owner, ref, tick, pTimer ) \ - _ASFTimerStart( owner, ref, tick, pTimer, __MODULE__, __LINE__ ) - -/* Defines for MTCK Commands & handlers */ -#define CR 0x0D -#define LF 0x0A - -/*-------------------------------------------------------------------------------------------------*\ - | T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -typedef enum AppResultCodesTag -{ - APP_OK = 0, - APP_ERR = 1 -} AppResult; - -typedef struct AsfTimerTag -{ - TimerId timerId; /**< Id of the timer - internal use */ - TaskId owner; /**< Owner task that created the timer */ - uint16_t ticks; /**< Timeout value in system ticks */ - uint16_t userValue; /**< User defined value */ - uint16_t info; /**< use by AsfTimer module */ - uint32_t sysUse; /**< For use by the system */ -} AsfTimer; - -#define NULL_TIMER {(TimerId)0, (TaskId)0, 0, 0, 0} - -typedef void (*fpDmaEnables_t)(void); -typedef osp_bool_t (*fpInputValidate_t)(uint8_t); - -/* UART driver data structure */ -typedef struct PortInfoTag -{ - uint32_t *pBuffPool; -#ifdef UART_DMA_ENABLE - void *pHead; - void *pTail; - fpDmaEnables_t EnableDMATxRequest; - fpDmaEnables_t EnableDMAxferCompleteInt; - fpDmaEnables_t EnableDMAChannel; - fpInputValidate_t ValidateInput; - uint32_t UartBaseAddress; - DMA_Channel_TypeDef *DMAChannel; -#else - /** Circular transmit buffer: - * txWriteIdx is the next slot to write to - * txReadIdx is the last slot read from - * txWriteIdx == txReadIdx == buffer is full - * txWriteIdx == 1 + txReadIdx == buffer is empty - */ - uint8_t txBuffer[TX_BUFFER_SIZE]; - uint16_t txWriteIdx; /**< Updated by task. */ - uint16_t txReadIdx; /**< Updated by TX ISR. */ -#endif - /** Circular receive buffer: - * rxWriteIdx is the next slot to write to - * rxReadIdx is the last slot read from - * rxWriteIdx == rxReadIdx == buffer is full - * rxWriteIdx == 1 + rxReadIdx == buffer is empty - */ - uint8_t rxBuffer[RX_BUFFER_SIZE]; - uint16_t rxWriteIdx; /**< Updated by RX ISR. */ - uint16_t rxReadIdx; /**< Updated by task. */ - TaskId rcvTask; /**< Task waiting for receive */ - -} PortInfo; - -/* Buffers used by DMA */ -typedef unsigned long Address; -typedef struct PktBufferTag -{ - Address *pNext; - uint32_t bufLen; - Address bufStart; -} PktBuff_t; - -/* Buffer Macros to manage linked list */ -#define M_GetBuffStart(x) (void *)(&(((PktBuff_t*)(x))->bufStart)) -#define M_GetBuffLen(x) (((PktBuff_t*)(x))->bufLen) -#define M_SetBuffLen(x,l) (((PktBuff_t*)(x))->bufLen) = l -#define M_NextBlock(x) (((PktBuff_t*)(x))->pNext) -/* Get the address of the block having the buffer address */ -#define M_GetBuffBlock(p) (void *)((uint8_t*)(p) - offsetof(PktBuff_t, bufStart)) - - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -int _dprintf( uint8_t dbgLvl, const char *fmt, ...); -extern uint32_t g_logging; - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Debug print scheme for different levels: - * 0 - This level must only be used for released code - * 1 - Regular debug messages - * 2 - Extra debug messages -**/ -//New macros -void putLineUART(const char *); -void put_u32(const uint32_t); - -#define D0_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) -#define D1_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) -#define D2_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) -#define Print_LIPS(d,x...) D0_printf("{!" d "!}\r\n",x) - -void _ASFTimerStart( TaskId owner, uint16_t ref, uint16_t tick, AsfTimer *pTimer, char *_file, int _line ); -osp_bool_t ASFTimerStarted ( AsfTimer *pTimer ); -void _ASFKillTimer( AsfTimer *pTimer, char *_file, int _line ); -void _ASFTimerExpiry ( uint16_t info, char *_file, int _line ); -void AsfInitialiseTasks ( void ); - -/* User instrumentation hooks */ -void InstrManagerUserInit( void ); -osp_bool_t InstrManagerUserHandler( MessageBuffer *pMsg ); - -/* Uart Support Functions */ -#ifdef UART_DMA_ENABLE -void *RemoveFromList( PortInfo *pPort ); -void AddToList( PortInfo *pPort, void *pPBuff, uint16_t length ); -#endif - -void SendDataReadyIndication(uint8_t sensorId, uint32_t timeStamp); - -uint32_t GetCurrentTime(void); - -#endif /* COMMON_H */ -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !defined (COMMON_H) +#define COMMON_H + +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include +#include "hw_setup.h" +#include "asf_msgstruct.h" +#include "main.h" +#include "osp-types.h" +#include "asf_types.h" +#include "osp-version.h" + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#define TIMER_SYS_ID 0xC0DEFEEDUL + +/* Critical Section Locks */ +#define OS_SETUP_CRITICAL() int wasMasked +#define OS_ENTER_CRITICAL() wasMasked = __disable_irq() +#define OS_LEAVE_CRITICAL() if (!wasMasked) __enable_irq() + +#ifdef DEBUG_BUILD +#define printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) + +/* Note: The USART enable in the asserts is required because in SensorAcq task we disable + it during sampling and in some rare cases there can be an assert while the UART was + in the disabled state (e.g. ISR doing CreateMessage and asserting) */ +# define ERR_LOG_MSG_SZ 150 +# define ASF_assert( condition ) \ + if (!(condition)) { \ + extern char _errBuff[]; \ + __disable_irq(); \ + AssertIndication(); \ + FlushUart(); \ + snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s]", __MODULE__, \ + __LINE__, #condition); \ + printf("%s\r\n", _errBuff); \ + SysRESET(); \ + } + +# define ASF_assert_var( condition, var1, var2, var3 ) \ + if (!(condition)) { \ + extern char _errBuff[]; \ + __disable_irq(); \ + AssertIndication(); \ + FlushUart(); \ + snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s], 0x%X, 0x%X, 0x%X", \ + __MODULE__, __LINE__, #condition, (uint32_t)var1, (uint32_t)var2, (uint32_t)var3);\ + printf("%s\r\n", _errBuff); \ + SysRESET(); \ + } + +# define ASF_assert_fatal( condition ) \ + if (!(condition)) { \ + extern char _errBuff[]; \ + __disable_irq(); \ + AssertIndication(); \ + FlushUart(); \ + snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT_FATAL: %s(%d) - [%s]", __MODULE__, \ + __LINE__, #condition); \ + printf("%s\r\n", _errBuff); \ + SysRESET(); \ + } + +# define ASF_assert_msg( condition, message ) \ + if (!(condition)) { \ + extern char _errBuff[]; \ + __disable_irq(); \ + AssertIndication(); \ + FlushUart(); \ + snprintf(_errBuff, ERR_LOG_MSG_SZ, "ASSERT: %s(%d) - [%s], MSG:%.100s", \ + __MODULE__, __LINE__, #condition, message); \ + printf("%s\r\n", _errBuff); \ + SysRESET(); \ + } + +#else +# define ASF_assert( condition ) ((void)0) +# define ASF_assert_var( condition, var1, var2, var3 ) ((void)0) +# define ASF_assert_fatal( condition ) ((void)0) +# define ASF_assert_msg( condition, message ) ((void)0) +#endif //DEBUG_BUILD + +/* Command Parser / UART receive event */ +#define UART_CMD_RECEIVE 0x0020 +#define UART_CRLF_RECEIVE 0x0040 ///< Receive CR or LF character +#define EVT_WAIT_FOREVER 0xFFFF + +#define ASFKillTimer( ptim ) \ + _ASFKillTimer( ptim, __MODULE__, __LINE__ ) +#define ASFTimerExpiry( info ) \ + _ASFTimerExpiry( info, __MODULE__, __LINE__ ) +#define ASFTimerStart( owner, ref, tick, pTimer ) \ + _ASFTimerStart( owner, ref, tick, pTimer, __MODULE__, __LINE__ ) + +/* Defines for MTCK Commands & handlers */ +#define CR 0x0D +#define LF 0x0A + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +typedef enum AppResultCodesTag +{ + APP_OK = 0, + APP_ERR = 1 +} AppResult; + +typedef struct AsfTimerTag +{ + osTimerId timerId; /**< Id of the timer - internal use */ + TaskId owner; /**< Owner task that created the timer */ + uint16_t ticks; /**< Timeout value in system ticks */ + uint16_t userValue; /**< User defined value */ + uint16_t info; /**< use by AsfTimer module */ + uint32_t sysUse; /**< For use by the system */ +} AsfTimer; + +#define NULL_TIMER {(TimerId)0, (TaskId)0, 0, 0, 0} + +typedef void (*fpDmaEnables_t)(void); +typedef osp_bool_t (*fpInputValidate_t)(uint8_t); + +/* UART driver data structure */ +typedef struct PortInfoTag +{ + osPoolId pBuffPool; +#ifdef UART_DMA_ENABLE + void *pHead; + void *pTail; + fpDmaEnables_t EnableDMATxRequest; + fpDmaEnables_t EnableDMAxferCompleteInt; + fpDmaEnables_t EnableDMAChannel; + fpInputValidate_t ValidateInput; + uint32_t UartBaseAddress; + DMA_Channel_TypeDef *DMAChannel; +#else + /** Circular transmit buffer: + * txWriteIdx is the next slot to write to + * txReadIdx is the last slot read from + * txWriteIdx == txReadIdx == buffer is full + * txWriteIdx == 1 + txReadIdx == buffer is empty + */ + uint8_t txBuffer[TX_BUFFER_SIZE]; + uint16_t txWriteIdx; /**< Updated by task. */ + uint16_t txReadIdx; /**< Updated by TX ISR. */ +#endif + /** Circular receive buffer: + * rxWriteIdx is the next slot to write to + * rxReadIdx is the last slot read from + * rxWriteIdx == rxReadIdx == buffer is full + * rxWriteIdx == 1 + rxReadIdx == buffer is empty + */ + uint8_t rxBuffer[RX_BUFFER_SIZE]; + uint16_t rxWriteIdx; /**< Updated by RX ISR. */ + uint16_t rxReadIdx; /**< Updated by task. */ + TaskId rcvTask; /**< Task waiting for receive */ + +} PortInfo; + +/* Buffers used by DMA */ +typedef unsigned long Address; +typedef struct PktBufferTag +{ + Address *pNext; + uint32_t bufLen; + Address bufStart; +} PktBuff_t; + +/* Buffer Macros to manage linked list */ +#define M_GetBuffStart(x) (void *)(&(((PktBuff_t*)(x))->bufStart)) +#define M_GetBuffLen(x) (((PktBuff_t*)(x))->bufLen) +#define M_SetBuffLen(x,l) (((PktBuff_t*)(x))->bufLen) = l +#define M_NextBlock(x) (((PktBuff_t*)(x))->pNext) +/* Get the address of the block having the buffer address */ +#define M_GetBuffBlock(p) (void *)((uint8_t*)(p) - offsetof(PktBuff_t, bufStart)) + + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +int _dprintf( uint8_t dbgLvl, const char *fmt, ...); +extern uint32_t g_logging; + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Debug print scheme for different levels: + * 0 - This level must only be used for released code + * 1 - Regular debug messages + * 2 - Extra debug messages +**/ +//New macros +void putLineUART(const char *); +void put_u32(const uint32_t); + +#define D0_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) +#define D1_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) +#define D2_printf( format, ... ) do { char localbuf[128]; snprintf(localbuf, 127, format, ## __VA_ARGS__); putLineUART(localbuf); } while(0) +#define Print_LIPS(d,x...) D0_printf("{!" d "!}\r\n",x) + +void _ASFTimerStart( TaskId owner, uint16_t ref, uint16_t tick, AsfTimer *pTimer, char *_file, int _line ); +osp_bool_t ASFTimerStarted ( AsfTimer *pTimer ); +void _ASFKillTimer( AsfTimer *pTimer, char *_file, int _line ); +void _ASFTimerExpiry ( uint32_t info, char *_file, int _line ); +void ASFTimerCallback(void const *argument); +void AsfInitialiseTasks ( void ); + +/* User instrumentation hooks */ +void InstrManagerUserInit( void ); +osp_bool_t InstrManagerUserHandler( MessageBuffer *pMsg ); + +/* Uart Support Functions */ +#ifdef UART_DMA_ENABLE +void *RemoveFromList( PortInfo *pPort ); +void AddToList( PortInfo *pPort, void *pPBuff, uint16_t length ); +#endif + +void SendDataReadyIndication(uint8_t sensorId, uint32_t timeStamp); + +uint32_t GetCurrentTime(void); + +#endif /* COMMON_H */ +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/app/debugprint.c b/embedded/common/app/debugprint.c index 56e7dc7..20ec56a 100644 --- a/embedded/common/app/debugprint.c +++ b/embedded/common/app/debugprint.c @@ -1,360 +1,366 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "debugprint.h" -#include "asf_taskstruct.h" -#include -#include -#include -#include - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -extern osp_bool_t ValidInputData( uint8_t inByte ); - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -PortInfo gDbgUartPort; //Debug information port - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -/** - * Declare separate pool for debug printf messages - */ -#ifdef UART_DMA_ENABLE -# define DPRINTF_MPOOL_SIZE (DPRINTF_BUFF_SIZE + 8) -_declare_box( gMemPoolDprintf, DPRINTF_MPOOL_SIZE, MAX_DPRINTF_MESSAGES); -#endif - - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -#ifdef UART_DMA_ENABLE -/**************************************************************************************************** - * @fn AddToList - * Adds the buffer to list and starts DMA transfer if this was the first buffer - * - ***************************************************************************************************/ -void AddToList( PortInfo *pPort, void *pPBuff, uint16_t length ) -{ - /* New printf buffers will be added to the list of buffers that will eventually be used for - DMAing out the data */ - int wasMasked; - Address *pTemp; - Address *pObj = M_GetBuffBlock(pPBuff); - M_SetBuffLen(pObj, length); - - wasMasked = __disable_irq(); - if (pPort->pHead == NULL) - { - pPort->pTail = pPort->pHead = pObj; //First DWORD is reserved for list management - M_NextBlock(pObj) = NULL; - - /* Start the first DMA Xfer */ - UartDMAConfiguration( pPort, pPBuff, length ); - - /* Enable UART DMA TX request */ - pPort->EnableDMATxRequest(); - - /* Enable DMA Channel Transfer complete interrupt */ - pPort->EnableDMAxferCompleteInt(); - - /* Enable UART DMA channel */ - pPort->EnableDMAChannel(); - } - else - { - pTemp = pPort->pTail; - pPort->pTail = pObj; - M_NextBlock(pObj) = NULL; - M_NextBlock(pTemp) = pObj; - } - if (!wasMasked) __enable_irq(); -} - - -/**************************************************************************************************** - * @fn RemoveFromList - * Removes head object (in FIFO order) from list and returns pointer to the list object - * - ***************************************************************************************************/ -void *RemoveFromList( PortInfo *pPort ) -{ - /* At this point the DMA has consumed this buffer. It will be removed from the list and the - returned buffer pointer will be used to free the printf buffer. The DMA completion handler - should call this function, free the memory and then use the buffer pointed by the Head pointer */ - void *pTemp; - int wasMasked; - ASF_assert(pPort->pHead != NULL); - wasMasked = __disable_irq(); - pTemp = pPort->pHead; - pPort->pHead = (void *)M_NextBlock(pPort->pHead); //If this is the last element then spHead will now be NULL - /* Here we should check if spHead is NULL and correspondingly set spTail to NULL but since - we probably won't check for spTail == NULL, we skip that step here. */ - if (!wasMasked) __enable_irq(); - return pTemp; -} -#endif - - -/**************************************************************************************************** - * @fn DebugPortInit - * Initializes the Debug Uart port data structure. - * - ***************************************************************************************************/ -void DebugPortInit( void ) -{ -#if 0 - _init_box( gMemPoolDprintf, sizeof(gMemPoolDprintf), DPRINTF_MPOOL_SIZE ); - gDbgUartPort.pBuffPool = gMemPoolDprintf; - gDbgUartPort.rxWriteIdx = 1; - gDbgUartPort.rxReadIdx = 0; - gDbgUartPort.rcvTask = CMD_HNDLR_TASK_ID; -#ifndef UART_DMA_ENABLE - gDbgUartPort.txReadIdx = 0; - gDbgUartPort.txWriteIdx = 1; -#else - gDbgUartPort.pHead = NULL; - gDbgUartPort.pTail = NULL; - gDbgUartPort.DMAChannel = DBG_UART_TX_DMA_Channel; - gDbgUartPort.UartBaseAddress = DBG_UART_DR_Base; - gDbgUartPort.ValidateInput = ValidInputData; - /* Note functions can be empty but not NULL (coz we dont' check for null) */ - gDbgUartPort.EnableDMAChannel = EnableDbgUartDMAChannel; - gDbgUartPort.EnableDMATxRequest = EnableDbgUartDMATxRequest; - gDbgUartPort.EnableDMAxferCompleteInt = EnableDbgUartDMAxferCompleteInt; -#endif -#endif -} - -/**************************************************************************************************** - * @fn RxBytesToBuff - * This function receives bytes into the RX buffer. It is called from the receive ISR - * - * @param byte received byte - * - * @return none - * - ***************************************************************************************************/ -void RxBytesToBuff( PortInfo *pPort, uint8_t byte ) -{ - uint16_t left; - uint16_t readIdx, writeIdx; - - /* Snapshot the two index values for local use. */ - readIdx = pPort->rxReadIdx; - writeIdx = pPort->rxWriteIdx; - - /* Check if enough room in the buffer to store the new data. */ - left = readIdx - writeIdx; - if(readIdx < writeIdx) - { - left += RX_BUFFER_SIZE; - } /* Here, ulLeft should be correct (between 0 and RX_BUFFER_SIZE). */ - -#if 0 - if ((left > 0) && pPort->ValidateInput(byte)) - { - pPort->rxBuffer[writeIdx] = byte; - - /* Check if a task is waiting for it. */ - if (pPort->rcvTask != UNKNOWN_TASK_ID) - { - if (byte == '\r' || byte == '\n') - { - isr_evt_set( UART_CRLF_RECEIVE, asfTaskHandleTable[pPort->rcvTask].handle ); - } - else - { - /* Wake up the task. */ - isr_evt_set( UART_CMD_RECEIVE, asfTaskHandleTable[pPort->rcvTask].handle ); - } - } - - if (writeIdx < RX_BUFFER_SIZE-1) - { - ++writeIdx; - } - else - { - writeIdx = 0; - } - } -#endif - /* Update the port control block values */ - pPort->rxWriteIdx = writeIdx; -} - - -#ifdef UART_DMA_ENABLE -/**************************************************************************************************** - * @fn GetNextBuffer - * Called from DMA TC ISR to request next buffer to process - * - ***************************************************************************************************/ -void *GetNextBuffer( PortInfo *pPort ) -{ - void *pFreeBuff = RemoveFromList( pPort ); - ASF_assert(_free_box( pPort->pBuffPool, pFreeBuff ) == 0); //Free the current consumed buffer - return pPort->pHead; //Return the current head of the list -} -#endif - -/**************************************************************************************************** - * @fn Print_LIPS - * Helper function that prints the LibFM Inline Parseable Serial protocol for external use - * - * @param fmt printf style variable length parameters - * - * @return length of the string printed. - * - ***************************************************************************************************/ -int Print_LIPS( const char *fmt, ... ) -{ - va_list args; - uint16_t i, len = 0; - int8_t *pPrintBuff; - PortInfo *pPort = &gDbgUartPort; - uint16_t maxsize = DPRINTF_BUFF_SIZE - 8 - 4; /*4 for header & footer, 2 for "\r\n", 4 for - checksum value, 1 for ',' & 1 for null termination */ - uint8_t chkSum = 0; -#if defined UART_DMA_ENABLE - int8_t *pNewBuff; -#else - //Not implemented -#endif - - va_start( args, fmt ); - -#if defined UART_DMA_ENABLE - /* Note: Output will be truncated to allowed max size */ - pNewBuff = _alloc_box(pPort->pBuffPool); - ASF_assert( pNewBuff != NULL ); - pPrintBuff = M_GetBuffStart(pNewBuff); - if (pPrintBuff != NULL) - { - pPrintBuff[0] = '{'; - pPrintBuff[1] = '!'; - len = vsnprintf( (char*)&pPrintBuff[2], maxsize, fmt, args ); - - ASF_assert( (len > 0) && (len < maxsize)); //Catch truncation of messages - - /* Checksum is XOR checksum calculated after the first '!' and upto but not inc. the ',' before - the checksum itself */ - for (i = 0; i < len; i++) - { - chkSum ^= pPrintBuff[2+i]; - } - - len += 2; //account for header - - len += snprintf( (char*)&pPrintBuff[len], 11, ",0x%02X,!}\r\n", chkSum ); - /* Add the print buffer to list */ - AddToList( pPort, pPrintBuff, len ); - } - - return len; -#else - return 0; //Not implemented! -#endif -} - - -/**************************************************************************************************** - * @fn _dprintf - * Helper function that replaces printf functionality to dump the printf messages on UART - * - * @param fmt printf style variable length parameters - * - * @return length of the string printed. - * - ***************************************************************************************************/ -int _dprintf( uint8_t dbgLvl, const char *fmt, ... ) -{ - va_list args; - const PortInfo *pPort = &gDbgUartPort; -#ifdef UART_DMA_ENABLE - uint16_t len = 0; - int8_t *pNewBuff, *pPrintBuff; -#else - -#endif - - switch( dbgLvl ) - { -#if (DEBUG_LVL < 1) - case 1: - return 0; -#endif -#if (DEBUG_LVL < 2) - case 2: - return 0; -#endif - - default: - va_start( args, fmt ); - -#ifdef UART_DMA_ENABLE - /* Note: Output will be truncated to allowed max size */ - pNewBuff = _alloc_box(pPort->pBuffPool); - ASF_assert( pNewBuff != NULL ); - if (pNewBuff != NULL) - { - pPrintBuff = M_GetBuffStart(pNewBuff); - len = vsnprintf( (char*)pPrintBuff, DPRINTF_BUFF_SIZE, fmt, args ); - - ASF_assert( len > 0 ); - - /* Add the print buffer to list */ - AddToList( (PortInfo*)pPort, pPrintBuff, len ); - return len; - } - return 0; -#else - return 0; -#endif - } -} - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "debugprint.h" +#include "asf_taskstruct.h" +#include +#include +#include +#include + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +extern osp_bool_t ValidInputData( uint8_t inByte ); + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +PortInfo gDbgUartPort; //Debug information port + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +/** + * Declare separate pool for debug printf messages + */ +#ifdef UART_DMA_ENABLE +# define DPRINTF_MPOOL_SIZE (DPRINTF_BUFF_SIZE + 8) +typedef struct TempStructForPoolDefTag +{ + unsigned char uc_temp_for_pool_def[DPRINTF_MPOOL_SIZE]; //This variable is unused struct +} TempStructForPoolDef; + /* Define memory pool */ +osPoolDef(gMemPoolDprintf, MAX_DPRINTF_MESSAGES, TempStructForPoolDef ); +osPoolId gMemPoolDprintf; +#endif + + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +#ifdef UART_DMA_ENABLE +/**************************************************************************************************** + * @fn AddToList + * Adds the buffer to list and starts DMA transfer if this was the first buffer + * + ***************************************************************************************************/ +void AddToList( PortInfo *pPort, void *pPBuff, uint16_t length ) +{ + /* New printf buffers will be added to the list of buffers that will eventually be used for + DMAing out the data */ + int wasMasked; + Address *pTemp; + Address *pObj = M_GetBuffBlock(pPBuff); + M_SetBuffLen(pObj, length); + + wasMasked = __disable_irq(); + if (pPort->pHead == NULL) + { + pPort->pTail = pPort->pHead = pObj; //First DWORD is reserved for list management + M_NextBlock(pObj) = NULL; + + /* Start the first DMA Xfer */ + UartDMAConfiguration( pPort, pPBuff, length ); + + /* Enable UART DMA TX request */ + pPort->EnableDMATxRequest(); + + /* Enable DMA Channel Transfer complete interrupt */ + pPort->EnableDMAxferCompleteInt(); + + /* Enable UART DMA channel */ + pPort->EnableDMAChannel(); + } + else + { + pTemp = pPort->pTail; + pPort->pTail = pObj; + M_NextBlock(pObj) = NULL; + M_NextBlock(pTemp) = pObj; + } + if (!wasMasked) __enable_irq(); +} + + +/**************************************************************************************************** + * @fn RemoveFromList + * Removes head object (in FIFO order) from list and returns pointer to the list object + * + ***************************************************************************************************/ +void *RemoveFromList( PortInfo *pPort ) +{ + /* At this point the DMA has consumed this buffer. It will be removed from the list and the + returned buffer pointer will be used to free the printf buffer. The DMA completion handler + should call this function, free the memory and then use the buffer pointed by the Head pointer */ + void *pTemp; + int wasMasked; + ASF_assert(pPort->pHead != NULL); + wasMasked = __disable_irq(); + pTemp = pPort->pHead; + pPort->pHead = (void *)M_NextBlock(pPort->pHead); //If this is the last element then spHead will now be NULL + /* Here we should check if spHead is NULL and correspondingly set spTail to NULL but since + we probably won't check for spTail == NULL, we skip that step here. */ + if (!wasMasked) __enable_irq(); + return pTemp; +} +#endif + + +/**************************************************************************************************** + * @fn DebugPortInit + * Initializes the Debug Uart port data structure. + * + ***************************************************************************************************/ +void DebugPortInit( void ) +{ +#if 0 + gMemPoolDprintf = osPoolCreate(osPool(gMemPoolDprintf)); + gDbgUartPort.pBuffPool = gMemPoolDprintf; + gDbgUartPort.rxWriteIdx = 1; + gDbgUartPort.rxReadIdx = 0; + gDbgUartPort.rcvTask = CMD_HNDLR_TASK_ID; +#ifndef UART_DMA_ENABLE + gDbgUartPort.txReadIdx = 0; + gDbgUartPort.txWriteIdx = 1; +#else + gDbgUartPort.pHead = NULL; + gDbgUartPort.pTail = NULL; + gDbgUartPort.DMAChannel = DBG_UART_TX_DMA_Channel; + gDbgUartPort.UartBaseAddress = DBG_UART_DR_Base; + gDbgUartPort.ValidateInput = ValidInputData; + /* Note functions can be empty but not NULL (coz we dont' check for null) */ + gDbgUartPort.EnableDMAChannel = EnableDbgUartDMAChannel; + gDbgUartPort.EnableDMATxRequest = EnableDbgUartDMATxRequest; + gDbgUartPort.EnableDMAxferCompleteInt = EnableDbgUartDMAxferCompleteInt; +#endif +#endif +} + +/**************************************************************************************************** + * @fn RxBytesToBuff + * This function receives bytes into the RX buffer. It is called from the receive ISR + * + * @param byte received byte + * + * @return none + * + ***************************************************************************************************/ +void RxBytesToBuff( PortInfo *pPort, uint8_t byte ) +{ + uint16_t left; + uint16_t readIdx, writeIdx; + + /* Snapshot the two index values for local use. */ + readIdx = pPort->rxReadIdx; + writeIdx = pPort->rxWriteIdx; + + /* Check if enough room in the buffer to store the new data. */ + left = readIdx - writeIdx; + if(readIdx < writeIdx) + { + left += RX_BUFFER_SIZE; + } /* Here, ulLeft should be correct (between 0 and RX_BUFFER_SIZE). */ + +#if 0 + if ((left > 0) && pPort->ValidateInput(byte)) + { + pPort->rxBuffer[writeIdx] = byte; + + /* Check if a task is waiting for it. */ + if (pPort->rcvTask != UNKNOWN_TASK_ID) + { + if (byte == '\r' || byte == '\n') + { + osSignalSet(asfTaskHandleTable[pPort->rcvTask].posThreadId,UART_CRLF_RECEIVE); + } + else + { + /* Wake up the task. */ + osSignalSet(asfTaskHandleTable[pPort->rcvTask].posThreadId,UART_CMD_RECEIVE); + } + } + + if (writeIdx < RX_BUFFER_SIZE-1) + { + ++writeIdx; + } + else + { + writeIdx = 0; + } + } +#endif + /* Update the port control block values */ + pPort->rxWriteIdx = writeIdx; +} + + +#ifdef UART_DMA_ENABLE +/**************************************************************************************************** + * @fn GetNextBuffer + * Called from DMA TC ISR to request next buffer to process + * + ***************************************************************************************************/ +void *GetNextBuffer( PortInfo *pPort ) +{ + void *pFreeBuff = RemoveFromList( pPort ); + ASF_assert(osPoolFree( pPort->pBuffPool, pFreeBuff ) == 0); //Free the current consumed buffer + return pPort->pHead; //Return the current head of the list +} +#endif + +/**************************************************************************************************** + * @fn Print_LIPS + * Helper function that prints the LibFM Inline Parseable Serial protocol for external use + * + * @param fmt printf style variable length parameters + * + * @return length of the string printed. + * + ***************************************************************************************************/ +int Print_LIPS( const char *fmt, ... ) +{ + va_list args; + uint16_t i, len = 0; + int8_t *pPrintBuff; + PortInfo *pPort = &gDbgUartPort; + uint16_t maxsize = DPRINTF_BUFF_SIZE - 8 - 4; /*4 for header & footer, 2 for "\r\n", 4 for + checksum value, 1 for ',' & 1 for null termination */ + uint8_t chkSum = 0; +#if defined UART_DMA_ENABLE + int8_t *pNewBuff; +#else + //Not implemented +#endif + + va_start( args, fmt ); + +#if defined UART_DMA_ENABLE + /* Note: Output will be truncated to allowed max size */ + pNewBuff = osPoolAlloc(pPort->pBuffPool); + ASF_assert( pNewBuff != NULL ); + pPrintBuff = M_GetBuffStart(pNewBuff); + if (pPrintBuff != NULL) + { + pPrintBuff[0] = '{'; + pPrintBuff[1] = '!'; + len = vsnprintf( (char*)&pPrintBuff[2], maxsize, fmt, args ); + + ASF_assert( (len > 0) && (len < maxsize)); //Catch truncation of messages + + /* Checksum is XOR checksum calculated after the first '!' and upto but not inc. the ',' before + the checksum itself */ + for (i = 0; i < len; i++) + { + chkSum ^= pPrintBuff[2+i]; + } + + len += 2; //account for header + + len += snprintf( (char*)&pPrintBuff[len], 11, ",0x%02X,!}\r\n", chkSum ); + /* Add the print buffer to list */ + AddToList( pPort, pPrintBuff, len ); + } + + return len; +#else + return 0; //Not implemented! +#endif +} + + +/**************************************************************************************************** + * @fn _dprintf + * Helper function that replaces printf functionality to dump the printf messages on UART + * + * @param fmt printf style variable length parameters + * + * @return length of the string printed. + * + ***************************************************************************************************/ +int _dprintf( uint8_t dbgLvl, const char *fmt, ... ) +{ + va_list args; + const PortInfo *pPort = &gDbgUartPort; +#ifdef UART_DMA_ENABLE + uint16_t len = 0; + int8_t *pNewBuff, *pPrintBuff; +#else + +#endif + + switch( dbgLvl ) + { +#if (DEBUG_LVL < 1) + case 1: + return 0; +#endif +#if (DEBUG_LVL < 2) + case 2: + return 0; +#endif + + default: + va_start( args, fmt ); + +#ifdef UART_DMA_ENABLE + /* Note: Output will be truncated to allowed max size */ + pNewBuff = osPoolAlloc(pPort->pBuffPool); + ASF_assert( pNewBuff != NULL ); + if (pNewBuff != NULL) + { + pPrintBuff = M_GetBuffStart(pNewBuff); + len = vsnprintf( (char*)pPrintBuff, DPRINTF_BUFF_SIZE, fmt, args ); + + ASF_assert( len > 0 ); + + /* Add the print buffer to list */ + AddToList( (PortInfo*)pPort, pPrintBuff, len ); + return len; + } + return 0; +#else + return 0; +#endif + } +} + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/app/hw_setup.h b/embedded/common/app/hw_setup.h index 11d9697..0cca5a7 100644 --- a/embedded/common/app/hw_setup.h +++ b/embedded/common/app/hw_setup.h @@ -1,70 +1,70 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if !defined (HW_SETUP_H) -#define HW_SETUP_H - -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ - -#ifdef DISCOVERY_L1_BOARD - #include "hw_setup_discovery_l1.h" -#elif STEVAL_MKI109V2 - #include "hw_setup_steval_mki109v2.h" -#elif BOARD_NXP_LPCXPRESS0_54102 - #include "hw_setup_nxp_lpc54102.h" -#else - #error "No sensor development board defined" -#endif - -//#if 1 -//#include "hw_setup_niobe.h" -//#endif - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ -void SystemGPIOConfig( void ); -void SystemInterruptConfig( void ); -void DebugPortInit( void ); -void DebugUARTConfig( uint32_t baud, uint32_t dataLen, uint32_t stopBits, uint32_t parity ); -void RTC_Configuration( void ); -#if 0 -uint8_t GetContext( void ); -#endif - -#endif /* HW_SETUP_H */ -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !defined (HW_SETUP_H) +#define HW_SETUP_H + +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ + +#ifdef DISCOVERY_L1_BOARD + #include "hw_setup_discovery_l1.h" +#elif STEVAL_MKI109V2 + #include "hw_setup_steval_mki109v2.h" +#elif BOARD_NXP_LPCXPRESS0_54102 + #include "hw_setup_nxp_lpc54102.h" +#else + #error "No sensor development board defined" +#endif + +//#if 1 +//#include "hw_setup_niobe.h" +//#endif + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ +void SystemGPIOConfig( void ); +void SystemInterruptConfig( void ); +void DebugPortInit( void ); +void DebugUARTConfig( uint32_t baud, uint32_t dataLen, uint32_t stopBits, uint32_t parity ); +void RTC_Configuration( void ); +#if 0 +uint8_t GetContext( void ); +#endif + +#endif /* HW_SETUP_H */ +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/app/instrmgr_t.c b/embedded/common/app/instrmgr_t.c index 0e5a62d..3dad698 100644 --- a/embedded/common/app/instrmgr_t.c +++ b/embedded/common/app/instrmgr_t.c @@ -33,8 +33,6 @@ extern uint32_t gStackSize; extern const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS]; extern uint32_t gSystemRTCRefTime; -extern struct OS_TCB os_idle_TCB; //RTX internal -extern void *os_active_TCB[]; //RTX internal extern void InitializeTasks( void ); extern uint8_t GetTaskList( uint8_t **pTaskList ); @@ -111,6 +109,7 @@ ASF_TASK void InstrManagerTask( ASF_TASK_ARG ) } } + ASFDeleteMessage( INSTR_MANAGER_TASK_ID, &rcvMsg ); } } diff --git a/embedded/common/app/instrmgr_user.c b/embedded/common/app/instrmgr_user.c index 015335b..ceffe1a 100644 --- a/embedded/common/app/instrmgr_user.c +++ b/embedded/common/app/instrmgr_user.c @@ -1,157 +1,157 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "Common.h" - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -extern uint16_t os_time; //RTX internal - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -RtcClock_t gRtcClockData; - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -static uint32_t sInitialTime; - -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn UpdateRTC - * Updates RTC clock based on the os_time value. os_time is the free running system tick - * counter - * - ***************************************************************************************************/ -static void UpdateRTC( void ) -{ - uint32_t currTime; - - currTime = os_time; - /* Check for rollover */ - if (currTime < sInitialTime) - { - currTime += 65536; //os_time is 16bit - } - - if ((currTime - sInitialTime) >= TICS_PER_SEC) - { - gRtcClockData.seconds += (currTime-sInitialTime)/TICS_PER_SEC; - gRtcClockData.msec = (currTime-sInitialTime)%TICS_PER_SEC * MSEC_PER_TICK; - sInitialTime = os_time; //reset for next iteration - - if (gRtcClockData.seconds >= 60) - { - gRtcClockData.minutes += gRtcClockData.seconds/60; - gRtcClockData.seconds = (gRtcClockData.seconds%60); - } - - if (gRtcClockData.minutes >= 60) - { - gRtcClockData.hours += gRtcClockData.minutes/60; - gRtcClockData.minutes = (gRtcClockData.minutes%60); - } - } - - D2_printf("\r\nTIME: %d:%02d:%02d.%d\r\n", gRtcClockData.hours, gRtcClockData.minutes, - gRtcClockData.seconds, gRtcClockData.msec); -} - - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn InstrManagerUserInit - * This handler is called from the instrumentation task to do application specific - * instrumentation initialization that should happen before the task loop - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -void InstrManagerUserInit( void ) -{ - sInitialTime = os_time; - - // ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, TICS_PER_SEC, &sRtcUpdateTimer ); -} - - -/**************************************************************************************************** - * @fn InstrManagerUserHandler - * This handler is called from the instrumentation task loop to handle application specific - * instrumentation requirements. - * - * @param none - * - * @return true if message was handled by the user, false otherwise - * - ***************************************************************************************************/ -osp_bool_t InstrManagerUserHandler( MessageBuffer *pMsg ) -{ - osp_bool_t msgHandled = false; - - switch (pMsg->msgId) - { - case MSG_TIMER_EXPIRY: //Note: this message is common so we don't mark it handled - switch (pMsg->msg.msgTimerExpiry.userValue) - { - case TIMER_REF_RTC_UPDATE: - UpdateRTC(); - - /* Restart timer for periodic output */ - // ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, TICS_PER_SEC, &sRtcUpdateTimer ); - break; - - default: - break; - } - break; - - default: - break; - } - - return msgHandled; -} - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "Common.h" + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +extern uint16_t os_time; //RTX internal + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +RtcClock_t gRtcClockData; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#define INSTR_MGR_SAMPLE_PERIOD (1000) //This is currently unused +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +static uint32_t sInitialTime; + +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn UpdateRTC + * Updates RTC clock based on the os_time value. os_time is the free running system tick + * counter + * + ***************************************************************************************************/ +static void UpdateRTC( void ) +{ + uint32_t currTime; + + currTime = os_time; + /* Check for rollover */ + if (currTime < sInitialTime) + { + currTime += 65536; //os_time is 16bit + } + + if ((currTime - sInitialTime) >= TICS_PER_SEC) + { + gRtcClockData.seconds += (currTime-sInitialTime)/TICS_PER_SEC; + gRtcClockData.msec = (currTime-sInitialTime)%TICS_PER_SEC * MSEC_PER_TICK; + sInitialTime = os_time; //reset for next iteration + + if (gRtcClockData.seconds >= 60) + { + gRtcClockData.minutes += gRtcClockData.seconds/60; + gRtcClockData.seconds = (gRtcClockData.seconds%60); + } + + if (gRtcClockData.minutes >= 60) + { + gRtcClockData.hours += gRtcClockData.minutes/60; + gRtcClockData.minutes = (gRtcClockData.minutes%60); + } + } + + D2_printf("\r\nTIME: %d:%02d:%02d.%d\r\n", gRtcClockData.hours, gRtcClockData.minutes, + gRtcClockData.seconds, gRtcClockData.msec); +} + + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn InstrManagerUserInit + * This handler is called from the instrumentation task to do application specific + * instrumentation initialization that should happen before the task loop + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +void InstrManagerUserInit( void ) +{ + sInitialTime = os_time; + + // ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, INSTR_MGR_SAMPLE_PERIOD, &sRtcUpdateTimer ); +} + + +/**************************************************************************************************** + * @fn InstrManagerUserHandler + * This handler is called from the instrumentation task loop to handle application specific + * instrumentation requirements. + * + * @param none + * + * @return true if message was handled by the user, false otherwise + * + ***************************************************************************************************/ +osp_bool_t InstrManagerUserHandler( MessageBuffer *pMsg ) +{ + osp_bool_t msgHandled = false; + + switch (pMsg->msgId) + { + case MSG_TIMER_EXPIRY: //Note: this message is common so we don't mark it handled + switch (pMsg->msg.msgTimerExpiry.userValue) + { + case TIMER_REF_RTC_UPDATE: + UpdateRTC(); + + /* Restart timer for periodic output */ + // ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, INSTR_MGR_SAMPLE_PERIOD, &sRtcUpdateTimer ); + break; + + default: + break; + } + break; + + default: + break; + } + + return msgHandled; +} + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/app/osp-api.c b/embedded/common/app/osp-api.c index d158997..fc40b61 100644 --- a/embedded/common/app/osp-api.c +++ b/embedded/common/app/osp-api.c @@ -1,1583 +1,1583 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Enable to use OSP Algs */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "common.h" -#include "osp-api.h" -#include -#include "osp_embeddedalgcalls.h" -#include "osp-version.h" - - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#define RESULT_FLAG_PAUSED (1 << 0) -#define MAX_SENSOR_DESCRIPTORS 8 -#define MAX_RESULT_DESCRIPTORS 5 -#define SENSOR_FG_DATA_Q_SIZE 8 -#define SENSOR_BG_DATA_Q_SIZE 8 -#define MAX_SENSORS_PER_RESULT 5 - -//Sensor flags for internal use -#define SENSOR_FLAG_IN_USE (1 << 0) -#define SENSOR_FLAG_HAVE_CTL_CALLBACK (1 << 1) -#define SENSOR_FLAG_HAVE_CAL_CALLBACK (1 << 2) -#define SENSOR_FLAG_NEEDS_DECIMATION (1 << 3) - -/* Result codes for local functions */ -#ifdef NO_ERROR -#undef NO_ERROR -#endif -#define NO_ERROR 0 - -#ifdef ERROR -#undef ERROR -#endif -#define ERROR -1 - -#define Q32DIFF (32 - QFIXEDPOINTPRECISE) - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Local structure for keeping tab on active sensors and results */ -typedef struct { - SensorDescriptor_t *pSenDesc; - uint16_t Flags; // in-use, etc -} _SenDesc_t; - -typedef struct { - SensorDescriptor_t *pResDesc; - uint16_t Flags; // Paused, etc -} _ResDesc_t; - -typedef struct { - InputSensorHandle_t Handle; // handle for this sensor - TriAxisSensorRawData_t Data; // raw data & time stamp from sensor -} _SensorDataBuffer_t; - -typedef struct { - SensorType_t ResultType; // result type - uint16_t SensorCount; // number of sensors required - SensorType_t Sensors[MAX_SENSORS_PER_RESULT]; // sensor types required for this result -} _ResultResourceMap_t; - -typedef union { - Android_UncalibratedAccelOutputData_t ucAccel; - Android_UncalibratedMagOutputData_t ucMag; - Android_UncalibratedGyroOutputData_t ucGyro; -} AndroidUnCalResult_t; - -/* Common bridge between the different data types for base sensors (Accel/Mag/Gyro) */ -typedef struct { - NTTIME TimeStamp; // time stamp - uint8_t accuracy; - union { - NTEXTENDED extendedData[3]; // processed sensor data - NTPRECISE preciseData[3]; // processed sensor data - } data; -} Common_3AxisResult_t; - - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -static const OSP_Library_Version_t libVersion = { - (OSP_VERSION_MAJOR << 16) | (OSP_VERSION_MINOR << 8) | (OSP_VERSION_PATCH), - OSP_VERSION_STRING -}; - -static uint64_t _SubscribedResults; // bit field of currently subscribed results, bit positions - // same as SensorType_t -// pointer to platform descriptor structure -static SystemDescriptor_t const *_pPlatformDesc = NULL; - -// pointers to sensor data structures, and local flags -static _SenDesc_t _SensorTable[MAX_SENSOR_DESCRIPTORS]; - -// pointers to result data structures, and local flags -static _ResDesc_t _ResultTable[MAX_RESULT_DESCRIPTORS]; - -// Raw sensor data queue for foreground processing -static _SensorDataBuffer_t _SensorFgDataQueue[SENSOR_FG_DATA_Q_SIZE]; -static int16_t _SensorFgDataQCnt; // number of data packets in the queue -static uint16_t _SensorFgDataNqPtr = SENSOR_FG_DATA_Q_SIZE - 1; // where the last data packet was put into the queue -static uint16_t _SensorFgDataDqPtr; // where to remove next data packet from the queue - - -// Raw sensor data queue for background processing -static _SensorDataBuffer_t _SensorBgDataQueue[SENSOR_BG_DATA_Q_SIZE]; -static int16_t _SensorBgDataQCnt; // number of data packets in the queue -static uint16_t _SensorBgDataNqPtr = SENSOR_BG_DATA_Q_SIZE - 1; // where the last data packet was put into the queue -static uint16_t _SensorBgDataDqPtr; // where to remove next data packet from the queue - -static uint32_t _sensorLastForegroundTimeStamp = 0; // keep the last time stamp here, we will use it to check for rollover -static uint32_t _sensorLastForegroundTimeStampExtension = 0; // we will re-create a larger raw time stamp here - -static uint32_t _sensorLastBackgroundTimeStamp = 0; // keep the last time stamp here, we will use it to check for rollover -static uint32_t _sensorLastBackgroundTimeStampExtension = 0; // we will re-create a larger raw time stamp here - -static NTPRECISE _accel_bias[3] = {0, 0, 0}; // bias in sensor ticks -static NTPRECISE _gyro_bias[3] = {0, 0, 0}; // bias in sensor ticks -static NTEXTENDED _mag_bias[3] = {0, 0, 0}; // bias in sensor ticks - -// copy of last data that was sent to the alg. We will -// use this for when the user _polls_ for calibrated sensor data. -static Common_3AxisResult_t _LastAccelCookedData; -static Common_3AxisResult_t _LastMagCookedData; -static Common_3AxisResult_t _LastGyroCookedData; - -// table of result to resource maps. 1 entry for each result that describes which sensor types -// that it needs, which callback routine to use, etc. -static const _ResultResourceMap_t _ResultResourceMap[] = { - {SENSOR_MAGNETIC_FIELD_UNCALIBRATED, 1, {SENSOR_MAGNETIC_FIELD_UNCALIBRATED}}, - {SENSOR_GYROSCOPE_UNCALIBRATED, 1, {SENSOR_GYROSCOPE_UNCALIBRATED}}, - {SENSOR_ACCELEROMETER_UNCALIBRATED, 1, {SENSOR_ACCELEROMETER_UNCALIBRATED}}, - {SENSOR_CONTEXT_DEVICE_MOTION, 2, {SENSOR_MAGNETIC_FIELD_UNCALIBRATED, SENSOR_ACCELEROMETER_UNCALIBRATED}}, - {SENSOR_STEP_COUNTER, 1, {SENSOR_ACCELEROMETER_UNCALIBRATED}} -}; -#define RESOURCE_MAP_COUNT (sizeof(_ResultResourceMap)/sizeof(_ResultResourceMap_t)) - -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ -static osp_status_t NullRoutine(void); -/* callback for entering/exiting a critical section of code (i.e. disable/enable task switch) */ -__weak OSP_CriticalSectionCallback_t EnterCritical = (OSP_CriticalSectionCallback_t)&NullRoutine; -__weak OSP_CriticalSectionCallback_t ExitCritical = (OSP_CriticalSectionCallback_t)&NullRoutine; -static int16_t FindResultTableIndexByType(SensorType_t Type); - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn mult_uint16_uint16 - * Unsigned 16-bit multiply with 32-bit result. - * - ***************************************************************************************************/ -__inline static uint32_t mult_uint16_uint16(uint16_t a, uint16_t b) -{ - return ((uint32_t) a * (uint32_t)b); -} - - -/**************************************************************************************************** - * @fn OnStepResultsReady - * Local callback used for Step Counter results from algorithm - * - ***************************************************************************************************/ -static void OnStepResultsReady( StepDataOSP_t* stepData ) -{ - if(_SubscribedResults & (1 << SENSOR_STEP_COUNTER)) { - int16_t index; - Android_StepCounterOutputData_t callbackData; - - callbackData.StepCount = stepData->numStepsTotal; - callbackData.TimeStamp = stepData->startTime; //!TODO - Double check if start time or stop time - - index = FindResultTableIndexByType(SENSOR_STEP_COUNTER); - _ResultTable[index].pResDesc->pOutputReadyCallback((OutputSensorHandle_t)&_ResultTable[index], - &callbackData); - } -} - - -/**************************************************************************************************** - * @fn OnSignificantMotionResult - * Local callback used for Significant motion results from algorithm - * - ***************************************************************************************************/ -static void OnSignificantMotionResult( NTTIME * eventTime ) -{ - if(_SubscribedResults & (1 << SENSOR_CONTEXT_DEVICE_MOTION)) { - int16_t index; - Android_SignificantMotionOutputData_t callbackData; - - callbackData.significantMotionDetected = true; - callbackData.TimeStamp = *eventTime; - - index = FindResultTableIndexByType(SENSOR_CONTEXT_DEVICE_MOTION); - _ResultTable[index].pResDesc->pOutputReadyCallback((OutputSensorHandle_t)&_ResultTable[index], - &callbackData); - } -} - - -/**************************************************************************************************** - * @fn NullRoutine - * A valid routine that does nothing. It should be used instead of a NULL function pointer - * for unused call backs so that we never try to execute a function pointed to by NULL - * - ***************************************************************************************************/ -static osp_status_t NullRoutine(void) -{ - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn ValidateSystemDescriptor - * Given a pointer to a system descriptor, validate it's contents. Return NO_ERROR if good, - * otherwise return ERROR - * - ***************************************************************************************************/ -static int16_t ValidateSystemDescriptor(SystemDescriptor_t const *pSystemDescriptor) -{ - // test that the ENUMs are in range - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn FindSensorTableIndexByType - * Given a sensor type, return the index into the sensor table - * - ***************************************************************************************************/ -static int16_t FindSensorTableIndexByType(SensorType_t Type) -{ - int16_t i; - - for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { - if(_SensorTable[i].pSenDesc == NULL) - continue; - if(Type == ((SensorDescriptor_t *)(_SensorTable[i].pSenDesc))->SensorType) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindSensorTableIndexByType - * Find 1st available empty sensor table slot, return the index into the sensor table - * - ***************************************************************************************************/ -static int16_t FindEmptySensorTableIndex(void) -{ - int16_t i; - - for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { - if(_SensorTable[i].pSenDesc == NULL) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindSensorTableIndexByHandle - * Given a sensor handle, return the index into the sensor table - * - ***************************************************************************************************/ -static int16_t FindSensorTableIndexByHandle(InputSensorHandle_t Handle) -{ - int16_t i; - - for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { - if(Handle == (InputSensorHandle_t)&_SensorTable[i]) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindResultTableIndexByType - * Given a result type, return the index into the result table - * - ***************************************************************************************************/ -static int16_t FindResultTableIndexByType(SensorType_t Type) -{ - int16_t i; - - for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { - if(_ResultTable[i].pResDesc == NULL) - continue; - if(Type == ((SensorDescriptor_t *)(_ResultTable[i].pResDesc))->SensorType) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindEmptyResultTableIndex - * Find 1st available empty result table slot, return the index into the sensor table - * - ***************************************************************************************************/ -static int16_t FindEmptyResultTableIndex(void) -{ - int16_t i; - - for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { - if(_ResultTable[i].pResDesc == NULL) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindResultTableIndexByHandle - * Given a result handle, return the index into the result table - * - ***************************************************************************************************/ -static int16_t FindResultTableIndexByHandle(OutputSensorHandle_t Handle) -{ - int16_t i; - - for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { - if(Handle == (OutputSensorHandle_t)&_ResultTable[i]) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn FindResourceMapIndexByType - * Given a result type, return the index into the resource map table. If not found, return - * ERROR - * - ***************************************************************************************************/ -static int16_t FindResourceMapIndexByType(SensorType_t ResultType) -{ - int16_t i; - - for (i = 0; i < RESOURCE_MAP_COUNT; i++) { - if (_ResultResourceMap[i].ResultType == ResultType) - return i; - } - return ERROR; -} - - -/**************************************************************************************************** - * @fn ValidateSensorDescriptor - * Given a pointer to a sensor descriptor, validate it's contents - * - ***************************************************************************************************/ -static int16_t ValidateSensorDescriptor(SensorDescriptor_t *pSensorDescriptor) -{ - InputSensorSpecificData_t *pSensSpecific; - osp_bool_t haveGoodCalData = FALSE; - - // test that the ENUMs are in range - if ( pSensorDescriptor->SensorType >= SENSOR_ENUM_COUNT ) - return ERROR; - if ( pSensorDescriptor->DataConvention >= DATA_CONVENTION_ENUM_COUNT ) - return ERROR; - - // if we have sensor specific data, check if its valid - pSensSpecific = pSensorDescriptor->pSensorSpecificData; - if (pSensSpecific != NULL) { - if ( pSensSpecific->AxisMapping[0] >= AXIS_MAP_ENUM_COUNT ) - return ERROR; - if ( pSensSpecific->AxisMapping[1] >= AXIS_MAP_ENUM_COUNT ) - return ERROR; - if ( pSensSpecific->AxisMapping[2] >= AXIS_MAP_ENUM_COUNT ) - return ERROR; - - if (pSensSpecific->pCalibrationData != NULL) { - //!TODO Validate cal data provided - } - } - - // Do any other validation that is required here... - - switch(pSensorDescriptor->SensorType) { - - case SENSOR_ACCELEROMETER_UNCALIBRATED: - break; - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - break; - - case SENSOR_GYROSCOPE_UNCALIBRATED: - break; - - default: - break; - } - - if (haveGoodCalData != TRUE) { - return OSP_STATUS_CAL_NOT_VALID; - } - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn ValidateResultDescriptor - * Given a pointer to a result descriptor, validate it's contents - * - ***************************************************************************************************/ -static int16_t ValidateResultDescriptor(SensorDescriptor_t *pResultDescriptor) -{ - if(pResultDescriptor->SensorType >= SENSOR_ENUM_COUNT ) - return ERROR; - - if(pResultDescriptor->DataConvention >= DATA_CONVENTION_ENUM_COUNT ) - return ERROR; - - if(pResultDescriptor->pOutputReadyCallback == NULL) - return ERROR; - - // Do any other validation that's required - //... - - // Add currently supported output sensor results... - switch (pResultDescriptor->SensorType) { - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - case SENSOR_GYROSCOPE_UNCALIBRATED: - case SENSOR_ACCELEROMETER_UNCALIBRATED: - case SENSOR_STEP_COUNTER: - case SENSOR_CONTEXT_DEVICE_MOTION: - break; - - default: - return ERROR; - - } - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn InvalidateQueuedDataByHandle - * Invalidates the handles for the sensor data in the queue so that the data is discarded - * - ***************************************************************************************************/ -static void InvalidateQueuedDataByHandle(InputSensorHandle_t Handle) -{ - uint16_t i; - - EnterCritical(); - for(i = 0; i < SENSOR_FG_DATA_Q_SIZE; i++ ) { - if(_SensorFgDataQueue[i].Handle == Handle) - _SensorFgDataQueue[i].Handle = NULL; - } - for(i = 0; i < SENSOR_BG_DATA_Q_SIZE; i++ ) { - if(_SensorBgDataQueue[i].Handle == Handle) - _SensorBgDataQueue[i].Handle = NULL; - } - ExitCritical(); -} - - -/**************************************************************************************************** - * @fn TurnOnSensors - * Turns on sensors indicated by sensorsMask (bit mask based on SensorType_t bit position - * - ***************************************************************************************************/ -static int16_t TurnOnSensors(uint32_t sensorsMask) -{ - SensorControl_t SenCtl; - - // Check for control callback - if(_pPlatformDesc->SensorsControl != NULL) { - // send a sensor off command - SenCtl.Handle = NULL; - SenCtl.Command = SENSOR_CONTROL_SENSOR_ON; - SenCtl.Data = sensorsMask; - _pPlatformDesc->SensorsControl(&SenCtl); - } - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn TurnOffSensors - * Turns off sensors indicated by sensorsMask (bit mask based on SensorType_t bit position - * - ***************************************************************************************************/ -static int16_t TurnOffSensors(uint32_t sensorsMask) -{ - SensorControl_t SenCtl; - - // does it have a control callback? - if(_pPlatformDesc->SensorsControl != NULL) { - // send a sensor off command - SenCtl.Handle = NULL; - SenCtl.Command = SENSOR_CONTROL_SENSOR_OFF; - SenCtl.Data = sensorsMask; - _pPlatformDesc->SensorsControl(&SenCtl); - } - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn ActivateResultSensors - * Given a result type, check to be sure that all of the sensors that are needed - * for this result type are available. If any sensor that is needed is available and marked - * as "not in-use", mark it so and send a "turn on" command through the control callback if - * it is available. - * - ***************************************************************************************************/ -static int16_t ActivateResultSensors(SensorType_t ResultType) -{ - int16_t i,j; - int16_t index; - uint32_t sensorsMask = 0; - - // use the result to sensor mapping table to see if all sensors that are needed are registered. - // also check their "in-use" status. If any required sensor is not registered, return ERROR. - - // Find the index of the result type in the resource map table. - for (i = 0; i < RESOURCE_MAP_COUNT; i++) { - if (_ResultResourceMap[i].ResultType == ResultType) { - for(j = 0; j < _ResultResourceMap[i].SensorCount; j++) { - index = FindSensorTableIndexByType(_ResultResourceMap[i].Sensors[j]); - if(index == ERROR) - return ERROR; // sensor is not registered, exit with error - // if this sensor is not active, mark it as such and send a command to it to go active. - if((_SensorTable[index].Flags & SENSOR_FLAG_IN_USE) == 0) { - _SensorTable[index].Flags |= SENSOR_FLAG_IN_USE; // mark sensor as "in use" - // TurnOnSensor(_ResultResourceMap[i].Sensors[j]); - sensorsMask |= (1 << _ResultResourceMap[i].Sensors[j]); - } - } - break; - } - } - - if (sensorsMask) TurnOnSensors(sensorsMask); - - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn DeactivateResultSensors - * Given a result type, deactivate (mark as "not in use") all sensors that were used by - * this result if they are not in use by any another active result. - * - ***************************************************************************************************/ -static int16_t DeactivateResultSensors(SensorType_t ResultType) -{ - int16_t i,j,k,l; - int16_t index; - osp_bool_t NeedSensor; - uint32_t sensorsMask = 0; - - - // use the result to sensor mapping table to see if any sensors that are were used are still in use by another result. - // We will send a control command to turn off the sensor if it supports it. - - // find our result resource table entry - index = FindResourceMapIndexByType(ResultType); - if (index == ERROR) - return ERROR; - - // search active results to see if they use any of the sensors that we used - for(i = 0; i < _ResultResourceMap[index].SensorCount; i++ ) { // for each of our sensors - NeedSensor = FALSE; // assume no other result uses this sensor - for(k = 0; k < MAX_RESULT_DESCRIPTORS; k++) { - if((_ResultTable[k].pResDesc != NULL) && (_ResultTable[k].pResDesc->SensorType != ResultType)) { // search active results (but not ours) - j = FindResourceMapIndexByType(_ResultTable[k].pResDesc->SensorType); - if(j == ERROR) - return ERROR; - for(l = 0; l < _ResultResourceMap[j].SensorCount; l++) { // for each sensor in this active result - if(_ResultResourceMap[j].Sensors[l] == _ResultResourceMap[index].Sensors[i]) { - NeedSensor = TRUE; // found one, stop searching this result - break; - } - } - if(NeedSensor == TRUE) - break; // another result is using this sensor, no need to check more results for this sensor - } - } - if(NeedSensor == FALSE) { - // if we get here, no other result uses this sensor type, mark it "not in use" and send - // a "turn off" command to it, and mark all data in the input queues as stale - j = FindSensorTableIndexByType(_ResultResourceMap[index].Sensors[i]); - _SensorTable[j].Flags &= ~SENSOR_FLAG_IN_USE; // Mark sensor "not in use" - // mark all previously queued data for this sensor type as invalid - InvalidateQueuedDataByHandle((InputSensorHandle_t)&_SensorTable[j]); - sensorsMask |= (1 << _ResultResourceMap[index].Sensors[i]); - } - } - if (sensorsMask) TurnOffSensors(sensorsMask); - return NO_ERROR; -} - - -/**************************************************************************************************** - * @fn UMul32 - * Helper routine for 32-bit saturating multiply. This maybe optimized in assembly if needed - * - ***************************************************************************************************/ -static void UMul32(uint32_t x,uint32_t y, uint32_t * pHigh, uint32_t * pLow) -{ - uint16_t xmsb; - uint16_t ymsb; - uint16_t xlsb; - uint16_t ylsb; - - register uint32_t high; - register uint32_t low; - register uint32_t temp2; - register uint32_t temp; - - - xmsb = x >> 16; - ymsb = y >> 16; - - xlsb = x & 0x0000FFFF; - ylsb = y & 0x0000FFFF; - - high = mult_uint16_uint16(xmsb , ymsb); - - temp = mult_uint16_uint16(ymsb , xlsb); - high += (temp & 0xFFFF0000) >> 16; - - low = temp << 16; - - temp = mult_uint16_uint16(xmsb , ylsb); - high += (temp & 0xFFFF0000) >> 16; - - temp2 = low; - low += temp << 16; - - if (low < temp2) { - ++high; - } - - temp = low; - low += mult_uint16_uint16(xlsb, ylsb); - - if (low < temp) { - ++high; - } - - *pHigh = high; - *pLow = low; -} - - -/**************************************************************************************************** - * @fn GetTimeFromCounter - * Helper routine for time conversion - * - ***************************************************************************************************/ -static osp_bool_t GetTimeFromCounter( - NTTIME * pTime, - TIMECOEFFICIENT counterToTimeConversionFactor, - uint32_t counterHigh, - uint32_t counterLow) -{ - NTTIME ret = 0; - uint32_t high1,low1; - uint32_t high2,low2; - const uint32_t roundfactor = (1 << (Q32DIFF-1)) ; - if (counterToTimeConversionFactor & 0x80000000) { - counterToTimeConversionFactor = ~counterToTimeConversionFactor + 1; - } - - UMul32(counterToTimeConversionFactor, counterLow, &high1, &low1); - UMul32(counterToTimeConversionFactor, counterHigh, &high2, &low2); - - low2 += high1; - if (low2 < high1) { - high2++; - } - - //round things - low1 += roundfactor; - - //check overflow - if (low1 < roundfactor) { - low2++; - if (low2 ==0) { - high2++; - } - } - - //right shift by Q32DIFF to make this into a Q24 number from a Q32 number - low1 >>= Q32DIFF; - low1 |= (low2 << (32 - Q32DIFF) ); - low2 >>= Q32DIFF; - low2 |= (high2 << (32 - Q32DIFF) ); - high2 >>= Q32DIFF; - - if (high2 || low2 & 0x80000000) { - //saturation!!!!! - *pTime = 0x7FFFFFFFFFFFFFFFLL; - return FALSE; - } - - ret = low2; - ret <<= 32; - ret |= low1; - - *pTime = ret; - - return TRUE; -} - - -/**************************************************************************************************** - * @fn ScaleSensorData - * Apply sign extension, offset and scaling to raw sensor data. NOTE: ScaleFactor may - * contain either NTPRECISE or NTEXTENDED number, base of "accuracy". Return value will also - * follow same logic. - * - ***************************************************************************************************/ -static int32_t ScaleSensorData( - int32_t Data, - uint32_t Mask, - int32_t Offset, - int32_t ScaleFactor) -{ - int64_t llTemp; - - // apply offset - Data -= Offset; - - Data &= Mask; // mask off non-used data bits - // sign extend (we assume that the data is in 2s complement format) - if((Data & (~Mask >> 1)) != 0 ) - Data |= ~Mask; - - llTemp = (int64_t) Data * (int64_t) ScaleFactor; // scale the data - - if(llTemp > SATURATE_INT_MAX ) - llTemp = SATURATE_INT_MAX; //if overflow, make max - if(llTemp < SATURATE_INT_MIN ) - llTemp = SATURATE_INT_MIN; //if underflow, make min - return (int32_t)llTemp; //return just the lower 32 bits -} - - -/**************************************************************************************************** - * @fn ConvertSensorData - * Given a pointer to a raw sensor data packet from the input queue of type - * _SensorDataBuffer_t and a pointer to a sensor output data packet of type - * TriAxisSensorCookedData_t, apply translations and conversions into a format per Android - * conventions. Accuracy must be either QFIXEDPOINTPRECISE or QFIXEDPOINTEXTENDED - * - ***************************************************************************************************/ -static int16_t ConvertSensorData( - _SensorDataBuffer_t *pRawData, - Common_3AxisResult_t *pCookedData, - uint8_t accuracy, - uint32_t *sensorTimeStamp, - uint32_t *sensorTimeStampExtension) -{ - uint16_t i; - unsigned char negative; - unsigned char source; - InputSensorSpecificData_t *pInpSensData; - - switch( ((_SenDesc_t *)(pRawData->Handle))->pSenDesc->SensorType ) { - case SENSOR_ACCELEROMETER_UNCALIBRATED: - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - case SENSOR_GYROSCOPE_UNCALIBRATED: - break; - - default: - return ERROR; - } - - // apply axis conversion and data width 1st, then offset, then gain (scaling), finally convert the time stamp. - pCookedData->accuracy = accuracy; - pInpSensData = ((_SenDesc_t *)(pRawData->Handle))->pSenDesc->pSensorSpecificData; - - for (i = 0; i < 3; i++) { - negative = 0; - switch (pInpSensData->AxisMapping[i]) { - - case AXIS_MAP_UNUSED: - switch (accuracy) { - case QFIXEDPOINTPRECISE: - pCookedData->data.preciseData[i] = CONST_PRECISE(0.0f); - break; - case QFIXEDPOINTEXTENDED: - pCookedData->data.extendedData[i] = CONST_EXTENDED(0.0f); - break; - default: - return ERROR; - } - continue; - case AXIS_MAP_NEGATIVE_X: - negative = 1; - case AXIS_MAP_POSITIVE_X: - source = 0; - break; - - case AXIS_MAP_NEGATIVE_Y: - negative = 1; - case AXIS_MAP_POSITIVE_Y: - source = 1; - break; - - case AXIS_MAP_NEGATIVE_Z: - negative = 1; - case AXIS_MAP_POSITIVE_Z: - source = 2; - break; - - default: - return ERROR; - } - - switch (accuracy) { - case QFIXEDPOINTPRECISE: - // mask, sign extend (if needed), apply offset and scale factor - pCookedData->data.preciseData[i] = ScaleSensorData(pRawData->Data.Data[source], - pInpSensData->DataWidthMask, - pInpSensData->ConversionOffset[i], - pInpSensData->ConversionScale[i]); - if (negative) - pCookedData->data.preciseData[i] = -pCookedData->data.preciseData[i]; - - break; - case QFIXEDPOINTEXTENDED: - // mask, sign extend (if needed), apply offset and scale factor - pCookedData->data.extendedData[i] = ScaleSensorData(pRawData->Data.Data[source], - pInpSensData->DataWidthMask, - pInpSensData->ConversionOffset[i], - pInpSensData->ConversionScale[i]); - if (negative) - pCookedData->data.extendedData[i] = -pCookedData->data.extendedData[i]; - break; - default: - return ERROR; - } - } - - // scale time stamp into seconds - // check for user timestamp rollover, if so bump our timestamp extension word - // !!WARNING!!: The time stamp extension scheme will need to be changed if timer capture is used - // for sensor time-stamping. Current scheme will cause time jumps if two sensors are timer-captured - // before & after rollover but the sensor that was captured after rollover is queued before the - // sensor that was captured before timer rollover - - if( ((int32_t)(*sensorTimeStamp) < 0) && ((int32_t)pRawData->Data.TimeStamp >= 0) ) { - (*sensorTimeStampExtension)++; - } - *sensorTimeStamp = pRawData->Data.TimeStamp; - - GetTimeFromCounter(&pCookedData->TimeStamp, _pPlatformDesc->TstampConversionToSeconds, - *sensorTimeStampExtension, *sensorTimeStamp); - return NO_ERROR; -} - -/*-------------------------------------------------------------------------------------------------*\ - | A P I F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn OSP_Initialize - * Does internal initializations that the library requires. - * - * @param pSystemDesc - INPUT pointer to a struct that describes things like time tick conversion - * value - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -osp_status_t OSP_Initialize(const SystemDescriptor_t* pSystemDesc) -{ - _SubscribedResults = 0; // by definition, we are not subscribed to any results - memset(_SensorTable, 0, sizeof(_SensorTable)); // init the sensor table - memset(_ResultTable, 0, sizeof(_ResultTable)); // init the result table also - - if(ValidateSystemDescriptor(pSystemDesc) == ERROR) - return (osp_status_t)OSP_STATUS_DESCRIPTOR_INVALID; - _pPlatformDesc = pSystemDesc; - if((pSystemDesc->EnterCritical != NULL) && (pSystemDesc->ExitCritical != NULL)) { - EnterCritical = pSystemDesc->EnterCritical; - ExitCritical = pSystemDesc->ExitCritical; - } - - OSP_InitializeAlgorithms(); - - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_RegisterInputSensor - * Tells the Open-Sensor-Platform Library what kind of sensor inputs it has to work with. - * - * @param pSensorDescriptor INPUT pointer to data which describes all the details of this sensor - * and its current operating mode; e.g. sensor type, SI unit conversion factor - * @param pReturnedHandle OUTPUT a handle to use when feeding data in via OSP_SetData() - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -__weak osp_status_t OSP_RegisterInputSensor(SensorDescriptor_t *pSensorDescriptor, - InputSensorHandle_t *pReturnedHandle) -{ - int16_t status; - int16_t index; - osp_bool_t haveCalData = FALSE; - - // Find 1st available slot in the sensor descriptor table, insert descriptor pointer, clear flags - // and return pointer to this table entry. If no room in the sensor table, return OSP_STATUS_NO_MORE_HANDLES - // If this sensor type is already registered, return OSP_STATUS_ALREADY_REGISTERED. - if((pSensorDescriptor == NULL) || (pReturnedHandle == NULL)) // just in case - return OSP_STATUS_NULL_POINTER; - - if(FindSensorTableIndexByType(pSensorDescriptor->SensorType) != ERROR) { // is this sensor type already registered? - *pReturnedHandle = NULL; - return OSP_STATUS_ALREADY_REGISTERED; - } - - // we have a new sensor, validate the sensor descriptor here before entering it into our table. - status = ValidateSensorDescriptor(pSensorDescriptor); - - if (status == ERROR) { - return OSP_STATUS_DESCRIPTOR_INVALID; - } else if (status == NO_ERROR) { - haveCalData = TRUE; - } - - haveCalData = haveCalData; //Avoid compiler warning for now! - - // If room in the sensor table, enter it and return the handle, else return OSP_STATUS_NO_MORE_HANDLES - index = FindEmptySensorTableIndex(); - if(index != ERROR) { - _SensorTable[index].pSenDesc = pSensorDescriptor; - _SensorTable[index].Flags = 0; - *pReturnedHandle = (InputSensorHandle_t)&_SensorTable[index]; - } else { - return OSP_STATUS_NO_MORE_HANDLES; - } - - // setup any flags for this sensor - if (pSensorDescriptor->pOptionalWriteCalDataCallback != NULL) // set the flag for the optional sensor calibration changed callback - _SensorTable[index].Flags |= SENSOR_FLAG_HAVE_CAL_CALLBACK; - else - _SensorTable[index].Flags &= ~SENSOR_FLAG_HAVE_CAL_CALLBACK; - - _SensorTable[index].Flags &= ~SENSOR_FLAG_IN_USE; // by definition, this sensor isn't in use yet. - - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_UnregisterInputSensor - * Call to remove an sensor from OSP's known set of inputs. - * - * @param handle INPUT a handle to the input sensor you want to unregister - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -osp_status_t OSP_UnregisterInputSensor(InputSensorHandle_t sensorHandle) -{ - int16_t index; - // Check the sensor table to be sure we have a valid entry, if so we need to check - // to be sure that the sensor type is the same. Clear sensor table entry, and return a NULL - // SensorHandle and the appropriate error code. - // We also need to mark all data for this sensor that is in the input queue as invalid (make handle = NULL). - - index = FindSensorTableIndexByHandle(sensorHandle); - if(index == ERROR) { // test for valid handle - return OSP_STATUS_NOT_REGISTERED; - } - - //Invalidate queued data for this sensor - InvalidateQueuedDataByHandle(sensorHandle); - - // Invalidate the descriptor entry - _SensorTable[index].pSenDesc = NULL; - - - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_SetData - * Queues sensor data which will be processed by OSP_DoForegroundProcessing() and - * OSP_DoBackgroundProcessing() - * - * @param sensorHandle INPUT requires a valid handle as returned by OSP_RegisterInputSensor() - * @param data INPUT pointer to timestamped raw sensor data - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -osp_status_t OSP_SetData(InputSensorHandle_t sensorHandle, TriAxisSensorRawData_t *data) -{ - register osp_status_t FgStatus = 0; - register osp_status_t BgStatus = 0; - - - if (data == NULL) // just in case - return OSP_STATUS_NULL_POINTER; - if(sensorHandle == NULL) // just in case - return OSP_STATUS_INVALID_HANDLE; - if(FindSensorTableIndexByHandle(sensorHandle) == ERROR) - return OSP_STATUS_INVALID_HANDLE; - - if( ((_SenDesc_t *)sensorHandle)->Flags & SENSOR_FLAG_IN_USE ) { // if this sensor is not used by a result, ignore data - - // put sensor data into the foreground queue - FgStatus = OSP_STATUS_QUEUE_FULL; // assume queue full - EnterCritical(); // no interrupts while we diddle the queues - if(_SensorFgDataQCnt < SENSOR_FG_DATA_Q_SIZE) { // check for room in the foreground queue - _SensorFgDataQCnt++; // if so, show one more in the queue - if(++_SensorFgDataNqPtr == SENSOR_FG_DATA_Q_SIZE) { // bump the enqueue pointer and check for pointer wrap, rewind if so - _SensorFgDataNqPtr = 0; - } - FgStatus = OSP_STATUS_OK; // FG queue isn't full - } - _SensorFgDataQueue[_SensorFgDataNqPtr].Handle = sensorHandle; - memcpy(&_SensorFgDataQueue[_SensorFgDataNqPtr].Data, data, sizeof(TriAxisSensorRawData_t)); // put data in queue (room or not) - - // put sensor data into the background queue - BgStatus = OSP_STATUS_QUEUE_FULL; // assume queue full - if(_SensorBgDataQCnt < SENSOR_BG_DATA_Q_SIZE) { // check for room in the background queue - _SensorBgDataQCnt++; // if so, show one more in the queue - if(++_SensorBgDataNqPtr == SENSOR_BG_DATA_Q_SIZE) { // bump the enqueue pointer and check for pointer wrap, rewind if so - _SensorBgDataNqPtr = 0; - } - BgStatus = OSP_STATUS_OK; // FG queue isn't full - } - _SensorBgDataQueue[_SensorBgDataNqPtr].Handle = sensorHandle; - memcpy(&_SensorBgDataQueue[_SensorBgDataNqPtr].Data, data, sizeof(TriAxisSensorRawData_t)); // put data in queue (room or not) - ExitCritical(); - } - - if((FgStatus == OSP_STATUS_QUEUE_FULL) || (BgStatus == OSP_STATUS_QUEUE_FULL)) - return OSP_STATUS_QUEUE_FULL; - else - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_DoForegroundProcessing - * Triggers computation for primary algorithms e.g ROTATION_VECTOR - * - * @param none - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -__weak osp_status_t OSP_DoForegroundProcessing(void) -{ - _SensorDataBuffer_t data; - Common_3AxisResult_t AndoidProcessedData; - AndroidUnCalResult_t AndoidUncalProcessedData; - int16_t index; - Common_3AxisResult_t algConvention; - - // Get next sensor data packet from the queue. If nothing in the queue, return OSP_STATUS_IDLE. - // If we get a data packet that has a sensor handle of NULL, we should drop it and get the next one, - // a NULL handle is an indicator that the data is from a sensor that has been replaced or that the data is stale. - - EnterCritical(); // no interrupts while we diddle the queue - - // ignore any data marked as stale. - while( (_SensorFgDataQueue[_SensorFgDataDqPtr].Handle == NULL) && (_SensorFgDataQCnt != 0) ) { - _SensorFgDataQCnt--; // stale data, show one less in the queue - if(++_SensorFgDataDqPtr == SENSOR_FG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so - _SensorFgDataDqPtr = 0; - } - - // now see if there is any data to process. - if(_SensorFgDataQCnt == 0) { // check for queue empty - ExitCritical(); - return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that - } - - // There is at least 1 data packet in the queue, get it. - memcpy(&data, &_SensorFgDataQueue[_SensorFgDataDqPtr], sizeof(_SensorDataBuffer_t)); // remove data from queue - _SensorFgDataQCnt--; // show one less in the queue - if(++_SensorFgDataDqPtr == SENSOR_FG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so - _SensorFgDataDqPtr = 0; - ExitCritical(); - - // now send the processed data to the appropriate entry points in the alg code. - switch( ((_SenDesc_t*)data.Handle)->pSenDesc->SensorType ) { - - case SENSOR_ACCELEROMETER_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTPRECISE, - &_sensorLastForegroundTimeStamp, - &_sensorLastForegroundTimeStampExtension); - } else { - //!TODO - Other data conventions support not implemented yet - return OSP_STATUS_NOT_IMPLEMENTED; - } - - // Do uncalibrated accel call back here (Android conventions) - if (_SubscribedResults & (1LL << SENSOR_ACCELEROMETER_UNCALIBRATED)) { - index = FindResultTableIndexByType(SENSOR_ACCELEROMETER_UNCALIBRATED); - if (index != ERROR) { - if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { - memcpy(&AndoidUncalProcessedData.ucAccel.X, - AndoidProcessedData.data.preciseData, - (sizeof(NTPRECISE)*3)); - memcpy(&AndoidUncalProcessedData.ucAccel.X_offset, - _accel_bias, (sizeof(NTPRECISE)*3)); - AndoidUncalProcessedData.ucAccel.TimeStamp = AndoidProcessedData.TimeStamp; - - _ResultTable[index].pResDesc->pOutputReadyCallback( - (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucAccel); - } - } else { - return OSP_STATUS_ERROR; - } - } - - // convert to algorithm convention before feeding data to algorithms. - algConvention.accuracy = QFIXEDPOINTPRECISE; - algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) - algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) - algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - memcpy(&_LastAccelCookedData, &algConvention, sizeof(Common_3AxisResult_t)); - - //OSP_SetForegroundAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); - // Send data on to algorithms - OSP_SetAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); - - // Do linear accel and gravity processing if needed - // ... TODO - break; - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTEXTENDED, - &_sensorLastForegroundTimeStamp, - &_sensorLastForegroundTimeStampExtension); - } else { - //!TODO - Other data conventions support not implemented yet - return OSP_STATUS_NOT_IMPLEMENTED; - } - - // Do uncalibrated mag call back here (Android conventions) - if (_SubscribedResults & (1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED)) { - index = FindResultTableIndexByType(SENSOR_MAGNETIC_FIELD_UNCALIBRATED); - if (index != ERROR) { - if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { - memcpy(&AndoidUncalProcessedData.ucMag.X, - AndoidProcessedData.data.extendedData, - (sizeof(NTEXTENDED)*3)); - memcpy(&AndoidUncalProcessedData.ucMag.X_hardIron_offset, - _mag_bias, (sizeof(NTEXTENDED)*3)); - AndoidUncalProcessedData.ucMag.TimeStamp = AndoidProcessedData.TimeStamp; - - _ResultTable[index].pResDesc->pOutputReadyCallback( - (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucMag); - } else { - return OSP_STATUS_ERROR; - } - } - } - - // convert to algorithm convention before feeding data to algs. - algConvention.accuracy = QFIXEDPOINTEXTENDED; - algConvention.data.extendedData[0] = AndoidProcessedData.data.extendedData[1]; // x (ALG) = Y (Android) - algConvention.data.extendedData[1] = -AndoidProcessedData.data.extendedData[0]; // y (ALG) = -X (Android) - algConvention.data.extendedData[2] = AndoidProcessedData.data.extendedData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - memcpy(&_LastMagCookedData, &algConvention, sizeof(Common_3AxisResult_t)); - - //OSP_SetForegroundMagnetometerMeasurement(AndoidProcessedData.TimeStamp, algConvention.data.extendedData); - break; - - case SENSOR_GYROSCOPE_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTPRECISE, - &_sensorLastForegroundTimeStamp, - &_sensorLastForegroundTimeStampExtension); - } else { - //!TODO - Other data conventions support not implemented yet - return OSP_STATUS_NOT_IMPLEMENTED; - } - - // Do uncalibrated mag call back here (Android conventions) - if (_SubscribedResults & (1LL << SENSOR_GYROSCOPE_UNCALIBRATED)) { - index = FindResultTableIndexByType(SENSOR_GYROSCOPE_UNCALIBRATED); - if (index != ERROR) { - if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { - memcpy(&AndoidUncalProcessedData.ucGyro.X, - AndoidProcessedData.data.preciseData, - (sizeof(NTPRECISE)*3)); - memcpy(&AndoidUncalProcessedData.ucGyro.X_drift_offset, - _gyro_bias, (sizeof(NTPRECISE)*3)); - AndoidUncalProcessedData.ucGyro.TimeStamp = AndoidProcessedData.TimeStamp; - - _ResultTable[index].pResDesc->pOutputReadyCallback( - (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucGyro); - } else { - return OSP_STATUS_ERROR; - } - } - } - - // convert to algorithm convention before feeding data to algs. - algConvention.accuracy = QFIXEDPOINTPRECISE; - algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) - algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) - algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - memcpy(&_LastGyroCookedData, &algConvention, sizeof(Common_3AxisResult_t)); - - //OSP_SetForegroundGyroscopeMeasurement(AndoidProcessedData.TimeStamp, algConvention.data.preciseData); - break; - - default: - break; - } - - // all done for now, return OSP_STATUS_IDLE if no more data in the queue, else return OSP_STATUS_OK - - if(_SensorFgDataQCnt == 0) - return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that - else - return OSP_STATUS_OK; // more to process -} - - -/**************************************************************************************************** - * @fn OSP_DoBackgroundProcessing - * Triggers computation for less time critical background algorithms, e.g. sensor calibration - * - * @param none - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -__weak osp_status_t OSP_DoBackgroundProcessing(void) -{ - _SensorDataBuffer_t data; - Common_3AxisResult_t AndoidProcessedData; - //Common_3AxisResult_t algConvention; - - // Get next sensor data packet from the queue. If nothing in the queue, return OSP_STATUS_IDLE. - // If we get a data packet that has a sensor handle of NULL, we should drop it and get the next one, - // a NULL handle is an indicator that the data is from a sensor that has been replaced and that the data is stale. - - EnterCritical(); // no interrupts while we diddle the queue - - // ignore any data marked as stale. - while( (_SensorBgDataQueue[_SensorBgDataDqPtr].Handle == NULL) && (_SensorBgDataQCnt != 0) ) { - _SensorBgDataQCnt--; // stale data, show one less in the queue - if(++_SensorBgDataDqPtr == SENSOR_BG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so - _SensorBgDataDqPtr = 0; - } - - // now see if there is any data to process. - if(_SensorBgDataQCnt == 0) { // check for queue empty - ExitCritical(); - return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that - } - - // There is at least 1 data packet in the queue, get it. - memcpy(&data, &_SensorBgDataQueue[_SensorBgDataDqPtr], sizeof(_SensorDataBuffer_t)); // remove data from queue - _SensorBgDataQCnt--; // show one less in the queue - if(++_SensorBgDataDqPtr == SENSOR_BG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so - _SensorBgDataDqPtr = 0; - - ExitCritical(); - - // now send the processed data to the appropriate entry points in the alg calibration code. - switch( ((_SenDesc_t*)data.Handle)->pSenDesc->SensorType ) { - - case SENSOR_ACCELEROMETER_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTPRECISE, - &_sensorLastBackgroundTimeStamp, - &_sensorLastBackgroundTimeStampExtension); - -#if 0 //Nothing to be done for background processing at this time! - // convert to algorithm convention. - algConvention.accuracy = QFIXEDPOINTPRECISE; - algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) - algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) - algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - //OSP_SetBackgroundAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); -#endif - break; - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTEXTENDED, - &_sensorLastBackgroundTimeStamp, - &_sensorLastBackgroundTimeStampExtension); - -#if 0 //Nothing to be done for background processing at this time! - // convert to algorithm convention. - algConvention.accuracy = QFIXEDPOINTEXTENDED; - algConvention.data.extendedData[0] = AndoidProcessedData.data.extendedData[1]; // x (ALG) = Y (Android) - algConvention.data.extendedData[1] = -AndoidProcessedData.data.extendedData[0]; // y (ALG) = -X (Android) - algConvention.data.extendedData[2] = AndoidProcessedData.data.extendedData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - //OSP_SetBackgroundMagnetometerMeasurement(algConvention.TimeStamp, algConvention.data.extendedData); -#endif - break; - - case SENSOR_GYROSCOPE_UNCALIBRATED: - // Now we have a copy of the data to be processed. We need to apply any and all input conversions. - ConvertSensorData( - &data, - &AndoidProcessedData, - QFIXEDPOINTPRECISE, - &_sensorLastBackgroundTimeStamp, - &_sensorLastBackgroundTimeStampExtension); - -#if 0 //Nothing to be done for background processing at this time! - // convert to algorithm convention. - algConvention.accuracy = QFIXEDPOINTPRECISE; - algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) - algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) - algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) - algConvention.TimeStamp = AndoidProcessedData.TimeStamp; - - //OSP_SetBackgroundGyroscopeMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); -#endif - break; - - default: - break; - } - - // all done for now, return OSP_STATUS_IDLE if no more data in the queue, else return OSP_STATUS_OK - if(_SensorBgDataQCnt == 0) - return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that - else - return OSP_STATUS_OK; // more to process -} - - -/**************************************************************************************************** - * @fn OSP_SubscribeOutputSensor - * Call for each Open-Sensor-Platform result (STEP_COUNT, ROTATION_VECTOR, etc) you want - * computed and output - * - * @param pSensorDescriptor INPUT pointer to data which describes the details of how the fusion - * should be computed: e.g output rate, sensors to use, etc. - * @param pOutputHandle OUTPUT a handle to be used for OSP_UnsubscribeOutputSensor() - * - * @return status as specified in OSP_Types.h. OSP_UNSUPPORTED_FEATURE for results that aren't - * available or licensed - * - ***************************************************************************************************/ -__weak osp_status_t OSP_SubscribeOutputSensor(SensorDescriptor_t *pSensorDescriptor, - OutputSensorHandle_t *pOutputHandle) -{ - int16_t index; - - if((pSensorDescriptor == NULL) || (pOutputHandle == NULL) || - (pSensorDescriptor->pOutputReadyCallback == NULL)) // just in case - return OSP_STATUS_NULL_POINTER; - - if(FindResultTableIndexByType(pSensorDescriptor->SensorType) != ERROR) { // is this result type already subscribed? - *pOutputHandle = NULL; - return OSP_STATUS_ALREADY_SUBSCRIBED; - } - - // we have a new request, validate the result descriptor here before entering it into our table. - - if(ValidateResultDescriptor(pSensorDescriptor) == ERROR) - return OSP_STATUS_DESCRIPTOR_INVALID; - - // Check for room in the result table, if no room, return OSP_STATUS_NO_MORE_HANDLES - - index = FindEmptyResultTableIndex(); - if(index == ERROR) { // if no room in the result table, return the error - *pOutputHandle = NULL; // and set the handle to NULL, so we can check for it later - return OSP_STATUS_NO_MORE_HANDLES; - } - - // check to be sure that we have all sensors registered that we need for this result. If so, mark them as "in use". - // if not, return OSP_STATUS_NOT_REGISTERED, and set the result handle to NULL. - - if(ActivateResultSensors(pSensorDescriptor->SensorType) == ERROR) { - *pOutputHandle = NULL; // and set the handle to NULL, so we can check for it later - return OSP_STATUS_NOT_REGISTERED; - } - - // Setup the alg callbacks, and any thing else that is needed for this result. - switch (pSensorDescriptor->SensorType) { - - case SENSOR_ACCELEROMETER_UNCALIBRATED: - _SubscribedResults |= (1LL << SENSOR_ACCELEROMETER_UNCALIBRATED); - //Note: Calibrated or uncalibrated result is specified in the descriptor flags - //For Uncalibrated result no callback needs to be registered with the algorithms - break; - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - _SubscribedResults |= (1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED); - //Note: Calibrated or uncalibrated result is specified in the descriptor flags - //For Uncalibrated result no callback needs to be registered with the algorithms - break; - - case SENSOR_GYROSCOPE_UNCALIBRATED: - _SubscribedResults |= (1LL << SENSOR_GYROSCOPE_UNCALIBRATED); - //Note: Calibrated or uncalibrated result is specified in the descriptor flags - //For Uncalibrated result no callback needs to be registered with the algorithms - break; - - case SENSOR_CONTEXT_DEVICE_MOTION: - _SubscribedResults |= (1LL << SENSOR_CONTEXT_DEVICE_MOTION); - OSP_RegisterSignificantMotionCallback(OnSignificantMotionResult); - break; - - case SENSOR_STEP_COUNTER: - _SubscribedResults |= (1LL << SENSOR_STEP_COUNTER); - OSP_RegisterStepCallback(OnStepResultsReady); - break; - - default: - return OSP_STATUS_UNKNOWN_REQUEST; - - } - - // Everything is setup, update our result table and return a handle - _ResultTable[index].pResDesc = pSensorDescriptor; - _ResultTable[index].Flags = 0; - *pOutputHandle = (OutputSensorHandle_t *)&_ResultTable[index]; - - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_UnsubscribeOutputSensor - * Stops the chain of computation for a registered result - * - * @param OutputHandle INPUT OutputSensorHandle_t that was received from - * OSP_SubscribeOutputSensor() - * - * @return status as specified in OSP_Types.h. - * - ***************************************************************************************************/ -osp_status_t OSP_UnsubscribeOutputSensor(OutputSensorHandle_t OutputHandle) -{ - int16_t index; - - // Check the result table to be sure that this is a valid handle, if not return OSP_STATUS_INVALID_HANDLE error. - // Also check that the handle points to a currently subscribed result, if not return OSP_STATUS_NOT_SUBSCRIBED. - if(OutputHandle == NULL) // just in case - return OSP_STATUS_INVALID_HANDLE; - index = FindResultTableIndexByHandle(OutputHandle); - if((index == ERROR) || (_ResultTable[index].pResDesc == NULL)) // test for active subscription for this handle - return OSP_STATUS_NOT_SUBSCRIBED; - - // Check to see if any of the other results that are still subscribed needs to use the sensors - // that we used. If not, mark those sensors as unused so that data from them will not be processed. - // All data in the input queues from sensors that we mark as unused should be marked as stale. We - // will also send a "sensor off" if that facility is available. - DeactivateResultSensors(_ResultTable[index].pResDesc->SensorType); - - // Now make sure that we won't call the users callback for this result - switch (_ResultTable[index].pResDesc->SensorType) { - - case SENSOR_ACCELEROMETER_UNCALIBRATED: - _SubscribedResults &= ~(1LL << SENSOR_ACCELEROMETER_UNCALIBRATED); - break; - - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - _SubscribedResults &= ~(1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED); - break; - - case SENSOR_GYROSCOPE_UNCALIBRATED: - _SubscribedResults &= ~(1LL << SENSOR_GYROSCOPE_UNCALIBRATED); - break; - - case SENSOR_CONTEXT_DEVICE_MOTION: - _SubscribedResults &= ~(1LL << SENSOR_CONTEXT_DEVICE_MOTION); - break; - - case SENSOR_STEP_COUNTER: - _SubscribedResults &= ~(1LL << SENSOR_STEP_COUNTER); - break; - - default: - return OSP_STATUS_UNKNOWN_REQUEST; - - } - - // remove result table entry. - _ResultTable[index].pResDesc = NULL; - _ResultTable[index].Flags = 0; - - return OSP_STATUS_OK; -} - - -/**************************************************************************************************** - * @fn OSP_GetVersion - * Provides version number and version string of the library implementation - * - * @param pVersionStruct OUTPUT pointer to a pointer that will receive the version data. - * - * @return status as specified in OSP_Types.h - * - ***************************************************************************************************/ -__weak osp_status_t OSP_GetVersion(const OSP_Library_Version_t **pVersionStruct) -{ - *pVersionStruct = &libVersion; - return OSP_STATUS_OK; -} - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ - +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Enable to use OSP Algs */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "osp-api.h" +#include +#include "osp_embeddedalgcalls.h" +#include "osp-version.h" + + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#define RESULT_FLAG_PAUSED (1 << 0) +#define MAX_SENSOR_DESCRIPTORS 8 +#define MAX_RESULT_DESCRIPTORS 5 +#define SENSOR_FG_DATA_Q_SIZE 8 +#define SENSOR_BG_DATA_Q_SIZE 8 +#define MAX_SENSORS_PER_RESULT 5 + +//Sensor flags for internal use +#define SENSOR_FLAG_IN_USE (1 << 0) +#define SENSOR_FLAG_HAVE_CTL_CALLBACK (1 << 1) +#define SENSOR_FLAG_HAVE_CAL_CALLBACK (1 << 2) +#define SENSOR_FLAG_NEEDS_DECIMATION (1 << 3) + +/* Result codes for local functions */ +#ifdef NO_ERROR +#undef NO_ERROR +#endif +#define NO_ERROR 0 + +#ifdef ERROR +#undef ERROR +#endif +#define ERROR -1 + +#define Q32DIFF (32 - QFIXEDPOINTPRECISE) + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Local structure for keeping tab on active sensors and results */ +typedef struct { + SensorDescriptor_t *pSenDesc; + uint16_t Flags; // in-use, etc +} _SenDesc_t; + +typedef struct { + SensorDescriptor_t *pResDesc; + uint16_t Flags; // Paused, etc +} _ResDesc_t; + +typedef struct { + InputSensorHandle_t Handle; // handle for this sensor + TriAxisSensorRawData_t Data; // raw data & time stamp from sensor +} _SensorDataBuffer_t; + +typedef struct { + SensorType_t ResultType; // result type + uint16_t SensorCount; // number of sensors required + SensorType_t Sensors[MAX_SENSORS_PER_RESULT]; // sensor types required for this result +} _ResultResourceMap_t; + +typedef union { + Android_UncalibratedAccelOutputData_t ucAccel; + Android_UncalibratedMagOutputData_t ucMag; + Android_UncalibratedGyroOutputData_t ucGyro; +} AndroidUnCalResult_t; + +/* Common bridge between the different data types for base sensors (Accel/Mag/Gyro) */ +typedef struct { + NTTIME TimeStamp; // time stamp + uint8_t accuracy; + union { + NTEXTENDED extendedData[3]; // processed sensor data + NTPRECISE preciseData[3]; // processed sensor data + } data; +} Common_3AxisResult_t; + + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +static const OSP_Library_Version_t libVersion = { + (OSP_VERSION_MAJOR << 16) | (OSP_VERSION_MINOR << 8) | (OSP_VERSION_PATCH), + OSP_VERSION_STRING +}; + +static uint64_t _SubscribedResults; // bit field of currently subscribed results, bit positions + // same as SensorType_t +// pointer to platform descriptor structure +static SystemDescriptor_t const *_pPlatformDesc = NULL; + +// pointers to sensor data structures, and local flags +static _SenDesc_t _SensorTable[MAX_SENSOR_DESCRIPTORS]; + +// pointers to result data structures, and local flags +static _ResDesc_t _ResultTable[MAX_RESULT_DESCRIPTORS]; + +// Raw sensor data queue for foreground processing +static _SensorDataBuffer_t _SensorFgDataQueue[SENSOR_FG_DATA_Q_SIZE]; +static int16_t _SensorFgDataQCnt; // number of data packets in the queue +static uint16_t _SensorFgDataNqPtr = SENSOR_FG_DATA_Q_SIZE - 1; // where the last data packet was put into the queue +static uint16_t _SensorFgDataDqPtr; // where to remove next data packet from the queue + + +// Raw sensor data queue for background processing +static _SensorDataBuffer_t _SensorBgDataQueue[SENSOR_BG_DATA_Q_SIZE]; +static int16_t _SensorBgDataQCnt; // number of data packets in the queue +static uint16_t _SensorBgDataNqPtr = SENSOR_BG_DATA_Q_SIZE - 1; // where the last data packet was put into the queue +static uint16_t _SensorBgDataDqPtr; // where to remove next data packet from the queue + +static uint32_t _sensorLastForegroundTimeStamp = 0; // keep the last time stamp here, we will use it to check for rollover +static uint32_t _sensorLastForegroundTimeStampExtension = 0; // we will re-create a larger raw time stamp here + +static uint32_t _sensorLastBackgroundTimeStamp = 0; // keep the last time stamp here, we will use it to check for rollover +static uint32_t _sensorLastBackgroundTimeStampExtension = 0; // we will re-create a larger raw time stamp here + +static NTPRECISE _accel_bias[3] = {0, 0, 0}; // bias in sensor ticks +static NTPRECISE _gyro_bias[3] = {0, 0, 0}; // bias in sensor ticks +static NTEXTENDED _mag_bias[3] = {0, 0, 0}; // bias in sensor ticks + +// copy of last data that was sent to the alg. We will +// use this for when the user _polls_ for calibrated sensor data. +static Common_3AxisResult_t _LastAccelCookedData; +static Common_3AxisResult_t _LastMagCookedData; +static Common_3AxisResult_t _LastGyroCookedData; + +// table of result to resource maps. 1 entry for each result that describes which sensor types +// that it needs, which callback routine to use, etc. +static const _ResultResourceMap_t _ResultResourceMap[] = { + {SENSOR_MAGNETIC_FIELD_UNCALIBRATED, 1, {SENSOR_MAGNETIC_FIELD_UNCALIBRATED}}, + {SENSOR_GYROSCOPE_UNCALIBRATED, 1, {SENSOR_GYROSCOPE_UNCALIBRATED}}, + {SENSOR_ACCELEROMETER_UNCALIBRATED, 1, {SENSOR_ACCELEROMETER_UNCALIBRATED}}, + {SENSOR_CONTEXT_DEVICE_MOTION, 2, {SENSOR_MAGNETIC_FIELD_UNCALIBRATED, SENSOR_ACCELEROMETER_UNCALIBRATED}}, + {SENSOR_STEP_COUNTER, 1, {SENSOR_ACCELEROMETER_UNCALIBRATED}} +}; +#define RESOURCE_MAP_COUNT (sizeof(_ResultResourceMap)/sizeof(_ResultResourceMap_t)) + +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ +static osp_status_t NullRoutine(void); +/* callback for entering/exiting a critical section of code (i.e. disable/enable task switch) */ +__weak OSP_CriticalSectionCallback_t EnterCritical = (OSP_CriticalSectionCallback_t)&NullRoutine; +__weak OSP_CriticalSectionCallback_t ExitCritical = (OSP_CriticalSectionCallback_t)&NullRoutine; +static int16_t FindResultTableIndexByType(SensorType_t Type); + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn mult_uint16_uint16 + * Unsigned 16-bit multiply with 32-bit result. + * + ***************************************************************************************************/ +__inline static uint32_t mult_uint16_uint16(uint16_t a, uint16_t b) +{ + return ((uint32_t) a * (uint32_t)b); +} + + +/**************************************************************************************************** + * @fn OnStepResultsReady + * Local callback used for Step Counter results from algorithm + * + ***************************************************************************************************/ +static void OnStepResultsReady( StepDataOSP_t* stepData ) +{ + if(_SubscribedResults & (1 << SENSOR_STEP_COUNTER)) { + int16_t index; + Android_StepCounterOutputData_t callbackData; + + callbackData.StepCount = stepData->numStepsTotal; + callbackData.TimeStamp = stepData->startTime; //!TODO - Double check if start time or stop time + + index = FindResultTableIndexByType(SENSOR_STEP_COUNTER); + _ResultTable[index].pResDesc->pOutputReadyCallback((OutputSensorHandle_t)&_ResultTable[index], + &callbackData); + } +} + + +/**************************************************************************************************** + * @fn OnSignificantMotionResult + * Local callback used for Significant motion results from algorithm + * + ***************************************************************************************************/ +static void OnSignificantMotionResult( NTTIME * eventTime ) +{ + if(_SubscribedResults & (1 << SENSOR_CONTEXT_DEVICE_MOTION)) { + int16_t index; + Android_SignificantMotionOutputData_t callbackData; + + callbackData.significantMotionDetected = true; + callbackData.TimeStamp = *eventTime; + + index = FindResultTableIndexByType(SENSOR_CONTEXT_DEVICE_MOTION); + _ResultTable[index].pResDesc->pOutputReadyCallback((OutputSensorHandle_t)&_ResultTable[index], + &callbackData); + } +} + + +/**************************************************************************************************** + * @fn NullRoutine + * A valid routine that does nothing. It should be used instead of a NULL function pointer + * for unused call backs so that we never try to execute a function pointed to by NULL + * + ***************************************************************************************************/ +static osp_status_t NullRoutine(void) +{ + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn ValidateSystemDescriptor + * Given a pointer to a system descriptor, validate it's contents. Return NO_ERROR if good, + * otherwise return ERROR + * + ***************************************************************************************************/ +static int16_t ValidateSystemDescriptor(SystemDescriptor_t const *pSystemDescriptor) +{ + // test that the ENUMs are in range + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn FindSensorTableIndexByType + * Given a sensor type, return the index into the sensor table + * + ***************************************************************************************************/ +static int16_t FindSensorTableIndexByType(SensorType_t Type) +{ + int16_t i; + + for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { + if(_SensorTable[i].pSenDesc == NULL) + continue; + if(Type == ((SensorDescriptor_t *)(_SensorTable[i].pSenDesc))->SensorType) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindSensorTableIndexByType + * Find 1st available empty sensor table slot, return the index into the sensor table + * + ***************************************************************************************************/ +static int16_t FindEmptySensorTableIndex(void) +{ + int16_t i; + + for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { + if(_SensorTable[i].pSenDesc == NULL) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindSensorTableIndexByHandle + * Given a sensor handle, return the index into the sensor table + * + ***************************************************************************************************/ +static int16_t FindSensorTableIndexByHandle(InputSensorHandle_t Handle) +{ + int16_t i; + + for(i = 0; i < MAX_SENSOR_DESCRIPTORS; i++) { + if(Handle == (InputSensorHandle_t)&_SensorTable[i]) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindResultTableIndexByType + * Given a result type, return the index into the result table + * + ***************************************************************************************************/ +static int16_t FindResultTableIndexByType(SensorType_t Type) +{ + int16_t i; + + for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { + if(_ResultTable[i].pResDesc == NULL) + continue; + if(Type == ((SensorDescriptor_t *)(_ResultTable[i].pResDesc))->SensorType) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindEmptyResultTableIndex + * Find 1st available empty result table slot, return the index into the sensor table + * + ***************************************************************************************************/ +static int16_t FindEmptyResultTableIndex(void) +{ + int16_t i; + + for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { + if(_ResultTable[i].pResDesc == NULL) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindResultTableIndexByHandle + * Given a result handle, return the index into the result table + * + ***************************************************************************************************/ +static int16_t FindResultTableIndexByHandle(OutputSensorHandle_t Handle) +{ + int16_t i; + + for(i = 0; i < MAX_RESULT_DESCRIPTORS; i++) { + if(Handle == (OutputSensorHandle_t)&_ResultTable[i]) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn FindResourceMapIndexByType + * Given a result type, return the index into the resource map table. If not found, return + * ERROR + * + ***************************************************************************************************/ +static int16_t FindResourceMapIndexByType(SensorType_t ResultType) +{ + int16_t i; + + for (i = 0; i < RESOURCE_MAP_COUNT; i++) { + if (_ResultResourceMap[i].ResultType == ResultType) + return i; + } + return ERROR; +} + + +/**************************************************************************************************** + * @fn ValidateSensorDescriptor + * Given a pointer to a sensor descriptor, validate it's contents + * + ***************************************************************************************************/ +static int16_t ValidateSensorDescriptor(SensorDescriptor_t *pSensorDescriptor) +{ + InputSensorSpecificData_t *pSensSpecific; + osp_bool_t haveGoodCalData = FALSE; + + // test that the ENUMs are in range + if ( pSensorDescriptor->SensorType >= SENSOR_ENUM_COUNT ) + return ERROR; + if ( pSensorDescriptor->DataConvention >= DATA_CONVENTION_ENUM_COUNT ) + return ERROR; + + // if we have sensor specific data, check if its valid + pSensSpecific = pSensorDescriptor->pSensorSpecificData; + if (pSensSpecific != NULL) { + if ( pSensSpecific->AxisMapping[0] >= AXIS_MAP_ENUM_COUNT ) + return ERROR; + if ( pSensSpecific->AxisMapping[1] >= AXIS_MAP_ENUM_COUNT ) + return ERROR; + if ( pSensSpecific->AxisMapping[2] >= AXIS_MAP_ENUM_COUNT ) + return ERROR; + + if (pSensSpecific->pCalibrationData != NULL) { + //!TODO Validate cal data provided + } + } + + // Do any other validation that is required here... + + switch(pSensorDescriptor->SensorType) { + + case SENSOR_ACCELEROMETER_UNCALIBRATED: + break; + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + break; + + case SENSOR_GYROSCOPE_UNCALIBRATED: + break; + + default: + break; + } + + if (haveGoodCalData != TRUE) { + return OSP_STATUS_CAL_NOT_VALID; + } + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn ValidateResultDescriptor + * Given a pointer to a result descriptor, validate it's contents + * + ***************************************************************************************************/ +static int16_t ValidateResultDescriptor(SensorDescriptor_t *pResultDescriptor) +{ + if(pResultDescriptor->SensorType >= SENSOR_ENUM_COUNT ) + return ERROR; + + if(pResultDescriptor->DataConvention >= DATA_CONVENTION_ENUM_COUNT ) + return ERROR; + + if(pResultDescriptor->pOutputReadyCallback == NULL) + return ERROR; + + // Do any other validation that's required + //... + + // Add currently supported output sensor results... + switch (pResultDescriptor->SensorType) { + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + case SENSOR_GYROSCOPE_UNCALIBRATED: + case SENSOR_ACCELEROMETER_UNCALIBRATED: + case SENSOR_STEP_COUNTER: + case SENSOR_CONTEXT_DEVICE_MOTION: + break; + + default: + return ERROR; + + } + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn InvalidateQueuedDataByHandle + * Invalidates the handles for the sensor data in the queue so that the data is discarded + * + ***************************************************************************************************/ +static void InvalidateQueuedDataByHandle(InputSensorHandle_t Handle) +{ + uint16_t i; + + EnterCritical(); + for(i = 0; i < SENSOR_FG_DATA_Q_SIZE; i++ ) { + if(_SensorFgDataQueue[i].Handle == Handle) + _SensorFgDataQueue[i].Handle = NULL; + } + for(i = 0; i < SENSOR_BG_DATA_Q_SIZE; i++ ) { + if(_SensorBgDataQueue[i].Handle == Handle) + _SensorBgDataQueue[i].Handle = NULL; + } + ExitCritical(); +} + + +/**************************************************************************************************** + * @fn TurnOnSensors + * Turns on sensors indicated by sensorsMask (bit mask based on SensorType_t bit position + * + ***************************************************************************************************/ +static int16_t TurnOnSensors(uint32_t sensorsMask) +{ + SensorControl_t SenCtl; + + // Check for control callback + if(_pPlatformDesc->SensorsControl != NULL) { + // send a sensor off command + SenCtl.Handle = NULL; + SenCtl.Command = SENSOR_CONTROL_SENSOR_ON; + SenCtl.Data = sensorsMask; + _pPlatformDesc->SensorsControl(&SenCtl); + } + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn TurnOffSensors + * Turns off sensors indicated by sensorsMask (bit mask based on SensorType_t bit position + * + ***************************************************************************************************/ +static int16_t TurnOffSensors(uint32_t sensorsMask) +{ + SensorControl_t SenCtl; + + // does it have a control callback? + if(_pPlatformDesc->SensorsControl != NULL) { + // send a sensor off command + SenCtl.Handle = NULL; + SenCtl.Command = SENSOR_CONTROL_SENSOR_OFF; + SenCtl.Data = sensorsMask; + _pPlatformDesc->SensorsControl(&SenCtl); + } + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn ActivateResultSensors + * Given a result type, check to be sure that all of the sensors that are needed + * for this result type are available. If any sensor that is needed is available and marked + * as "not in-use", mark it so and send a "turn on" command through the control callback if + * it is available. + * + ***************************************************************************************************/ +static int16_t ActivateResultSensors(SensorType_t ResultType) +{ + int16_t i,j; + int16_t index; + uint32_t sensorsMask = 0; + + // use the result to sensor mapping table to see if all sensors that are needed are registered. + // also check their "in-use" status. If any required sensor is not registered, return ERROR. + + // Find the index of the result type in the resource map table. + for (i = 0; i < RESOURCE_MAP_COUNT; i++) { + if (_ResultResourceMap[i].ResultType == ResultType) { + for(j = 0; j < _ResultResourceMap[i].SensorCount; j++) { + index = FindSensorTableIndexByType(_ResultResourceMap[i].Sensors[j]); + if(index == ERROR) + return ERROR; // sensor is not registered, exit with error + // if this sensor is not active, mark it as such and send a command to it to go active. + if((_SensorTable[index].Flags & SENSOR_FLAG_IN_USE) == 0) { + _SensorTable[index].Flags |= SENSOR_FLAG_IN_USE; // mark sensor as "in use" + // TurnOnSensor(_ResultResourceMap[i].Sensors[j]); + sensorsMask |= (1 << _ResultResourceMap[i].Sensors[j]); + } + } + break; + } + } + + if (sensorsMask) TurnOnSensors(sensorsMask); + + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn DeactivateResultSensors + * Given a result type, deactivate (mark as "not in use") all sensors that were used by + * this result if they are not in use by any another active result. + * + ***************************************************************************************************/ +static int16_t DeactivateResultSensors(SensorType_t ResultType) +{ + int16_t i,j,k,l; + int16_t index; + osp_bool_t NeedSensor; + uint32_t sensorsMask = 0; + + + // use the result to sensor mapping table to see if any sensors that are were used are still in use by another result. + // We will send a control command to turn off the sensor if it supports it. + + // find our result resource table entry + index = FindResourceMapIndexByType(ResultType); + if (index == ERROR) + return ERROR; + + // search active results to see if they use any of the sensors that we used + for(i = 0; i < _ResultResourceMap[index].SensorCount; i++ ) { // for each of our sensors + NeedSensor = FALSE; // assume no other result uses this sensor + for(k = 0; k < MAX_RESULT_DESCRIPTORS; k++) { + if((_ResultTable[k].pResDesc != NULL) && (_ResultTable[k].pResDesc->SensorType != ResultType)) { // search active results (but not ours) + j = FindResourceMapIndexByType(_ResultTable[k].pResDesc->SensorType); + if(j == ERROR) + return ERROR; + for(l = 0; l < _ResultResourceMap[j].SensorCount; l++) { // for each sensor in this active result + if(_ResultResourceMap[j].Sensors[l] == _ResultResourceMap[index].Sensors[i]) { + NeedSensor = TRUE; // found one, stop searching this result + break; + } + } + if(NeedSensor == TRUE) + break; // another result is using this sensor, no need to check more results for this sensor + } + } + if(NeedSensor == FALSE) { + // if we get here, no other result uses this sensor type, mark it "not in use" and send + // a "turn off" command to it, and mark all data in the input queues as stale + j = FindSensorTableIndexByType(_ResultResourceMap[index].Sensors[i]); + _SensorTable[j].Flags &= ~SENSOR_FLAG_IN_USE; // Mark sensor "not in use" + // mark all previously queued data for this sensor type as invalid + InvalidateQueuedDataByHandle((InputSensorHandle_t)&_SensorTable[j]); + sensorsMask |= (1 << _ResultResourceMap[index].Sensors[i]); + } + } + if (sensorsMask) TurnOffSensors(sensorsMask); + return NO_ERROR; +} + + +/**************************************************************************************************** + * @fn UMul32 + * Helper routine for 32-bit saturating multiply. This maybe optimized in assembly if needed + * + ***************************************************************************************************/ +static void UMul32(uint32_t x,uint32_t y, uint32_t * pHigh, uint32_t * pLow) +{ + uint16_t xmsb; + uint16_t ymsb; + uint16_t xlsb; + uint16_t ylsb; + + register uint32_t high; + register uint32_t low; + register uint32_t temp2; + register uint32_t temp; + + + xmsb = x >> 16; + ymsb = y >> 16; + + xlsb = x & 0x0000FFFF; + ylsb = y & 0x0000FFFF; + + high = mult_uint16_uint16(xmsb , ymsb); + + temp = mult_uint16_uint16(ymsb , xlsb); + high += (temp & 0xFFFF0000) >> 16; + + low = temp << 16; + + temp = mult_uint16_uint16(xmsb , ylsb); + high += (temp & 0xFFFF0000) >> 16; + + temp2 = low; + low += temp << 16; + + if (low < temp2) { + ++high; + } + + temp = low; + low += mult_uint16_uint16(xlsb, ylsb); + + if (low < temp) { + ++high; + } + + *pHigh = high; + *pLow = low; +} + + +/**************************************************************************************************** + * @fn GetTimeFromCounter + * Helper routine for time conversion + * + ***************************************************************************************************/ +static osp_bool_t GetTimeFromCounter( + NTTIME * pTime, + TIMECOEFFICIENT counterToTimeConversionFactor, + uint32_t counterHigh, + uint32_t counterLow) +{ + NTTIME ret = 0; + uint32_t high1,low1; + uint32_t high2,low2; + const uint32_t roundfactor = (1 << (Q32DIFF-1)) ; + if (counterToTimeConversionFactor & 0x80000000) { + counterToTimeConversionFactor = ~counterToTimeConversionFactor + 1; + } + + UMul32(counterToTimeConversionFactor, counterLow, &high1, &low1); + UMul32(counterToTimeConversionFactor, counterHigh, &high2, &low2); + + low2 += high1; + if (low2 < high1) { + high2++; + } + + //round things + low1 += roundfactor; + + //check overflow + if (low1 < roundfactor) { + low2++; + if (low2 ==0) { + high2++; + } + } + + //right shift by Q32DIFF to make this into a Q24 number from a Q32 number + low1 >>= Q32DIFF; + low1 |= (low2 << (32 - Q32DIFF) ); + low2 >>= Q32DIFF; + low2 |= (high2 << (32 - Q32DIFF) ); + high2 >>= Q32DIFF; + + if (high2 || low2 & 0x80000000) { + //saturation!!!!! + *pTime = 0x7FFFFFFFFFFFFFFFLL; + return FALSE; + } + + ret = low2; + ret <<= 32; + ret |= low1; + + *pTime = ret; + + return TRUE; +} + + +/**************************************************************************************************** + * @fn ScaleSensorData + * Apply sign extension, offset and scaling to raw sensor data. NOTE: ScaleFactor may + * contain either NTPRECISE or NTEXTENDED number, base of "accuracy". Return value will also + * follow same logic. + * + ***************************************************************************************************/ +static int32_t ScaleSensorData( + int32_t Data, + uint32_t Mask, + int32_t Offset, + int32_t ScaleFactor) +{ + int64_t llTemp; + + // apply offset + Data -= Offset; + + Data &= Mask; // mask off non-used data bits + // sign extend (we assume that the data is in 2s complement format) + if((Data & (~Mask >> 1)) != 0 ) + Data |= ~Mask; + + llTemp = (int64_t) Data * (int64_t) ScaleFactor; // scale the data + + if(llTemp > SATURATE_INT_MAX ) + llTemp = SATURATE_INT_MAX; //if overflow, make max + if(llTemp < SATURATE_INT_MIN ) + llTemp = SATURATE_INT_MIN; //if underflow, make min + return (int32_t)llTemp; //return just the lower 32 bits +} + + +/**************************************************************************************************** + * @fn ConvertSensorData + * Given a pointer to a raw sensor data packet from the input queue of type + * _SensorDataBuffer_t and a pointer to a sensor output data packet of type + * TriAxisSensorCookedData_t, apply translations and conversions into a format per Android + * conventions. Accuracy must be either QFIXEDPOINTPRECISE or QFIXEDPOINTEXTENDED + * + ***************************************************************************************************/ +static int16_t ConvertSensorData( + _SensorDataBuffer_t *pRawData, + Common_3AxisResult_t *pCookedData, + uint8_t accuracy, + uint32_t *sensorTimeStamp, + uint32_t *sensorTimeStampExtension) +{ + uint16_t i; + unsigned char negative; + unsigned char source; + InputSensorSpecificData_t *pInpSensData; + + switch( ((_SenDesc_t *)(pRawData->Handle))->pSenDesc->SensorType ) { + case SENSOR_ACCELEROMETER_UNCALIBRATED: + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + case SENSOR_GYROSCOPE_UNCALIBRATED: + break; + + default: + return ERROR; + } + + // apply axis conversion and data width 1st, then offset, then gain (scaling), finally convert the time stamp. + pCookedData->accuracy = accuracy; + pInpSensData = ((_SenDesc_t *)(pRawData->Handle))->pSenDesc->pSensorSpecificData; + + for (i = 0; i < 3; i++) { + negative = 0; + switch (pInpSensData->AxisMapping[i]) { + + case AXIS_MAP_UNUSED: + switch (accuracy) { + case QFIXEDPOINTPRECISE: + pCookedData->data.preciseData[i] = CONST_PRECISE(0.0f); + break; + case QFIXEDPOINTEXTENDED: + pCookedData->data.extendedData[i] = CONST_EXTENDED(0.0f); + break; + default: + return ERROR; + } + continue; + case AXIS_MAP_NEGATIVE_X: + negative = 1; + case AXIS_MAP_POSITIVE_X: + source = 0; + break; + + case AXIS_MAP_NEGATIVE_Y: + negative = 1; + case AXIS_MAP_POSITIVE_Y: + source = 1; + break; + + case AXIS_MAP_NEGATIVE_Z: + negative = 1; + case AXIS_MAP_POSITIVE_Z: + source = 2; + break; + + default: + return ERROR; + } + + switch (accuracy) { + case QFIXEDPOINTPRECISE: + // mask, sign extend (if needed), apply offset and scale factor + pCookedData->data.preciseData[i] = ScaleSensorData(pRawData->Data.Data[source], + pInpSensData->DataWidthMask, + pInpSensData->ConversionOffset[i], + pInpSensData->ConversionScale[i]); + if (negative) + pCookedData->data.preciseData[i] = -pCookedData->data.preciseData[i]; + + break; + case QFIXEDPOINTEXTENDED: + // mask, sign extend (if needed), apply offset and scale factor + pCookedData->data.extendedData[i] = ScaleSensorData(pRawData->Data.Data[source], + pInpSensData->DataWidthMask, + pInpSensData->ConversionOffset[i], + pInpSensData->ConversionScale[i]); + if (negative) + pCookedData->data.extendedData[i] = -pCookedData->data.extendedData[i]; + break; + default: + return ERROR; + } + } + + // scale time stamp into seconds + // check for user timestamp rollover, if so bump our timestamp extension word + // !!WARNING!!: The time stamp extension scheme will need to be changed if timer capture is used + // for sensor time-stamping. Current scheme will cause time jumps if two sensors are timer-captured + // before & after rollover but the sensor that was captured after rollover is queued before the + // sensor that was captured before timer rollover + + if( ((int32_t)(*sensorTimeStamp) < 0) && ((int32_t)pRawData->Data.TimeStamp >= 0) ) { + (*sensorTimeStampExtension)++; + } + *sensorTimeStamp = pRawData->Data.TimeStamp; + + GetTimeFromCounter(&pCookedData->TimeStamp, _pPlatformDesc->TstampConversionToSeconds, + *sensorTimeStampExtension, *sensorTimeStamp); + return NO_ERROR; +} + +/*-------------------------------------------------------------------------------------------------*\ + | A P I F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn OSP_Initialize + * Does internal initializations that the library requires. + * + * @param pSystemDesc - INPUT pointer to a struct that describes things like time tick conversion + * value + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +osp_status_t OSP_Initialize(const SystemDescriptor_t* pSystemDesc) +{ + _SubscribedResults = 0; // by definition, we are not subscribed to any results + memset(_SensorTable, 0, sizeof(_SensorTable)); // init the sensor table + memset(_ResultTable, 0, sizeof(_ResultTable)); // init the result table also + + if(ValidateSystemDescriptor(pSystemDesc) == ERROR) + return (osp_status_t)OSP_STATUS_DESCRIPTOR_INVALID; + _pPlatformDesc = pSystemDesc; + if((pSystemDesc->EnterCritical != NULL) && (pSystemDesc->ExitCritical != NULL)) { + EnterCritical = pSystemDesc->EnterCritical; + ExitCritical = pSystemDesc->ExitCritical; + } + + OSP_InitializeAlgorithms(); + + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_RegisterInputSensor + * Tells the Open-Sensor-Platform Library what kind of sensor inputs it has to work with. + * + * @param pSensorDescriptor INPUT pointer to data which describes all the details of this sensor + * and its current operating mode; e.g. sensor type, SI unit conversion factor + * @param pReturnedHandle OUTPUT a handle to use when feeding data in via OSP_SetData() + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +__weak osp_status_t OSP_RegisterInputSensor(SensorDescriptor_t *pSensorDescriptor, + InputSensorHandle_t *pReturnedHandle) +{ + int16_t status; + int16_t index; + osp_bool_t haveCalData = FALSE; + + // Find 1st available slot in the sensor descriptor table, insert descriptor pointer, clear flags + // and return pointer to this table entry. If no room in the sensor table, return OSP_STATUS_NO_MORE_HANDLES + // If this sensor type is already registered, return OSP_STATUS_ALREADY_REGISTERED. + if((pSensorDescriptor == NULL) || (pReturnedHandle == NULL)) // just in case + return OSP_STATUS_NULL_POINTER; + + if(FindSensorTableIndexByType(pSensorDescriptor->SensorType) != ERROR) { // is this sensor type already registered? + *pReturnedHandle = NULL; + return OSP_STATUS_ALREADY_REGISTERED; + } + + // we have a new sensor, validate the sensor descriptor here before entering it into our table. + status = ValidateSensorDescriptor(pSensorDescriptor); + + if (status == ERROR) { + return OSP_STATUS_DESCRIPTOR_INVALID; + } else if (status == NO_ERROR) { + haveCalData = TRUE; + } + + haveCalData = haveCalData; //Avoid compiler warning for now! + + // If room in the sensor table, enter it and return the handle, else return OSP_STATUS_NO_MORE_HANDLES + index = FindEmptySensorTableIndex(); + if(index != ERROR) { + _SensorTable[index].pSenDesc = pSensorDescriptor; + _SensorTable[index].Flags = 0; + *pReturnedHandle = (InputSensorHandle_t)&_SensorTable[index]; + } else { + return OSP_STATUS_NO_MORE_HANDLES; + } + + // setup any flags for this sensor + if (pSensorDescriptor->pOptionalWriteCalDataCallback != NULL) // set the flag for the optional sensor calibration changed callback + _SensorTable[index].Flags |= SENSOR_FLAG_HAVE_CAL_CALLBACK; + else + _SensorTable[index].Flags &= ~SENSOR_FLAG_HAVE_CAL_CALLBACK; + + _SensorTable[index].Flags &= ~SENSOR_FLAG_IN_USE; // by definition, this sensor isn't in use yet. + + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_UnregisterInputSensor + * Call to remove an sensor from OSP's known set of inputs. + * + * @param handle INPUT a handle to the input sensor you want to unregister + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +osp_status_t OSP_UnregisterInputSensor(InputSensorHandle_t sensorHandle) +{ + int16_t index; + // Check the sensor table to be sure we have a valid entry, if so we need to check + // to be sure that the sensor type is the same. Clear sensor table entry, and return a NULL + // SensorHandle and the appropriate error code. + // We also need to mark all data for this sensor that is in the input queue as invalid (make handle = NULL). + + index = FindSensorTableIndexByHandle(sensorHandle); + if(index == ERROR) { // test for valid handle + return OSP_STATUS_NOT_REGISTERED; + } + + //Invalidate queued data for this sensor + InvalidateQueuedDataByHandle(sensorHandle); + + // Invalidate the descriptor entry + _SensorTable[index].pSenDesc = NULL; + + + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_SetData + * Queues sensor data which will be processed by OSP_DoForegroundProcessing() and + * OSP_DoBackgroundProcessing() + * + * @param sensorHandle INPUT requires a valid handle as returned by OSP_RegisterInputSensor() + * @param data INPUT pointer to timestamped raw sensor data + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +osp_status_t OSP_SetData(InputSensorHandle_t sensorHandle, TriAxisSensorRawData_t *data) +{ + register osp_status_t FgStatus = 0; + register osp_status_t BgStatus = 0; + + + if (data == NULL) // just in case + return OSP_STATUS_NULL_POINTER; + if(sensorHandle == NULL) // just in case + return OSP_STATUS_INVALID_HANDLE; + if(FindSensorTableIndexByHandle(sensorHandle) == ERROR) + return OSP_STATUS_INVALID_HANDLE; + + if( ((_SenDesc_t *)sensorHandle)->Flags & SENSOR_FLAG_IN_USE ) { // if this sensor is not used by a result, ignore data + + // put sensor data into the foreground queue + FgStatus = OSP_STATUS_QUEUE_FULL; // assume queue full + EnterCritical(); // no interrupts while we diddle the queues + if(_SensorFgDataQCnt < SENSOR_FG_DATA_Q_SIZE) { // check for room in the foreground queue + _SensorFgDataQCnt++; // if so, show one more in the queue + if(++_SensorFgDataNqPtr == SENSOR_FG_DATA_Q_SIZE) { // bump the enqueue pointer and check for pointer wrap, rewind if so + _SensorFgDataNqPtr = 0; + } + FgStatus = OSP_STATUS_OK; // FG queue isn't full + } + _SensorFgDataQueue[_SensorFgDataNqPtr].Handle = sensorHandle; + memcpy(&_SensorFgDataQueue[_SensorFgDataNqPtr].Data, data, sizeof(TriAxisSensorRawData_t)); // put data in queue (room or not) + + // put sensor data into the background queue + BgStatus = OSP_STATUS_QUEUE_FULL; // assume queue full + if(_SensorBgDataQCnt < SENSOR_BG_DATA_Q_SIZE) { // check for room in the background queue + _SensorBgDataQCnt++; // if so, show one more in the queue + if(++_SensorBgDataNqPtr == SENSOR_BG_DATA_Q_SIZE) { // bump the enqueue pointer and check for pointer wrap, rewind if so + _SensorBgDataNqPtr = 0; + } + BgStatus = OSP_STATUS_OK; // FG queue isn't full + } + _SensorBgDataQueue[_SensorBgDataNqPtr].Handle = sensorHandle; + memcpy(&_SensorBgDataQueue[_SensorBgDataNqPtr].Data, data, sizeof(TriAxisSensorRawData_t)); // put data in queue (room or not) + ExitCritical(); + } + + if((FgStatus == OSP_STATUS_QUEUE_FULL) || (BgStatus == OSP_STATUS_QUEUE_FULL)) + return OSP_STATUS_QUEUE_FULL; + else + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_DoForegroundProcessing + * Triggers computation for primary algorithms e.g ROTATION_VECTOR + * + * @param none + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +__weak osp_status_t OSP_DoForegroundProcessing(void) +{ + _SensorDataBuffer_t data; + Common_3AxisResult_t AndoidProcessedData; + AndroidUnCalResult_t AndoidUncalProcessedData; + int16_t index; + Common_3AxisResult_t algConvention; + + // Get next sensor data packet from the queue. If nothing in the queue, return OSP_STATUS_IDLE. + // If we get a data packet that has a sensor handle of NULL, we should drop it and get the next one, + // a NULL handle is an indicator that the data is from a sensor that has been replaced or that the data is stale. + + EnterCritical(); // no interrupts while we diddle the queue + + // ignore any data marked as stale. + while( (_SensorFgDataQueue[_SensorFgDataDqPtr].Handle == NULL) && (_SensorFgDataQCnt != 0) ) { + _SensorFgDataQCnt--; // stale data, show one less in the queue + if(++_SensorFgDataDqPtr == SENSOR_FG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so + _SensorFgDataDqPtr = 0; + } + + // now see if there is any data to process. + if(_SensorFgDataQCnt == 0) { // check for queue empty + ExitCritical(); + return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that + } + + // There is at least 1 data packet in the queue, get it. + memcpy(&data, &_SensorFgDataQueue[_SensorFgDataDqPtr], sizeof(_SensorDataBuffer_t)); // remove data from queue + _SensorFgDataQCnt--; // show one less in the queue + if(++_SensorFgDataDqPtr == SENSOR_FG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so + _SensorFgDataDqPtr = 0; + ExitCritical(); + + // now send the processed data to the appropriate entry points in the alg code. + switch( ((_SenDesc_t*)data.Handle)->pSenDesc->SensorType ) { + + case SENSOR_ACCELEROMETER_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTPRECISE, + &_sensorLastForegroundTimeStamp, + &_sensorLastForegroundTimeStampExtension); + } else { + //!TODO - Other data conventions support not implemented yet + return OSP_STATUS_NOT_IMPLEMENTED; + } + + // Do uncalibrated accel call back here (Android conventions) + if (_SubscribedResults & (1LL << SENSOR_ACCELEROMETER_UNCALIBRATED)) { + index = FindResultTableIndexByType(SENSOR_ACCELEROMETER_UNCALIBRATED); + if (index != ERROR) { + if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { + memcpy(&AndoidUncalProcessedData.ucAccel.X, + AndoidProcessedData.data.preciseData, + (sizeof(NTPRECISE)*3)); + memcpy(&AndoidUncalProcessedData.ucAccel.X_offset, + _accel_bias, (sizeof(NTPRECISE)*3)); + AndoidUncalProcessedData.ucAccel.TimeStamp = AndoidProcessedData.TimeStamp; + + _ResultTable[index].pResDesc->pOutputReadyCallback( + (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucAccel); + } + } else { + return OSP_STATUS_ERROR; + } + } + + // convert to algorithm convention before feeding data to algorithms. + algConvention.accuracy = QFIXEDPOINTPRECISE; + algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) + algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) + algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + memcpy(&_LastAccelCookedData, &algConvention, sizeof(Common_3AxisResult_t)); + + //OSP_SetForegroundAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); + // Send data on to algorithms + OSP_SetAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); + + // Do linear accel and gravity processing if needed + // ... TODO + break; + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTEXTENDED, + &_sensorLastForegroundTimeStamp, + &_sensorLastForegroundTimeStampExtension); + } else { + //!TODO - Other data conventions support not implemented yet + return OSP_STATUS_NOT_IMPLEMENTED; + } + + // Do uncalibrated mag call back here (Android conventions) + if (_SubscribedResults & (1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED)) { + index = FindResultTableIndexByType(SENSOR_MAGNETIC_FIELD_UNCALIBRATED); + if (index != ERROR) { + if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { + memcpy(&AndoidUncalProcessedData.ucMag.X, + AndoidProcessedData.data.extendedData, + (sizeof(NTEXTENDED)*3)); + memcpy(&AndoidUncalProcessedData.ucMag.X_hardIron_offset, + _mag_bias, (sizeof(NTEXTENDED)*3)); + AndoidUncalProcessedData.ucMag.TimeStamp = AndoidProcessedData.TimeStamp; + + _ResultTable[index].pResDesc->pOutputReadyCallback( + (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucMag); + } else { + return OSP_STATUS_ERROR; + } + } + } + + // convert to algorithm convention before feeding data to algs. + algConvention.accuracy = QFIXEDPOINTEXTENDED; + algConvention.data.extendedData[0] = AndoidProcessedData.data.extendedData[1]; // x (ALG) = Y (Android) + algConvention.data.extendedData[1] = -AndoidProcessedData.data.extendedData[0]; // y (ALG) = -X (Android) + algConvention.data.extendedData[2] = AndoidProcessedData.data.extendedData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + memcpy(&_LastMagCookedData, &algConvention, sizeof(Common_3AxisResult_t)); + + //OSP_SetForegroundMagnetometerMeasurement(AndoidProcessedData.TimeStamp, algConvention.data.extendedData); + break; + + case SENSOR_GYROSCOPE_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + if (((_SenDesc_t*)data.Handle)->pSenDesc->DataConvention == DATA_CONVENTION_RAW) { + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTPRECISE, + &_sensorLastForegroundTimeStamp, + &_sensorLastForegroundTimeStampExtension); + } else { + //!TODO - Other data conventions support not implemented yet + return OSP_STATUS_NOT_IMPLEMENTED; + } + + // Do uncalibrated mag call back here (Android conventions) + if (_SubscribedResults & (1LL << SENSOR_GYROSCOPE_UNCALIBRATED)) { + index = FindResultTableIndexByType(SENSOR_GYROSCOPE_UNCALIBRATED); + if (index != ERROR) { + if (_ResultTable[index].pResDesc->DataConvention == DATA_CONVENTION_ANDROID) { + memcpy(&AndoidUncalProcessedData.ucGyro.X, + AndoidProcessedData.data.preciseData, + (sizeof(NTPRECISE)*3)); + memcpy(&AndoidUncalProcessedData.ucGyro.X_drift_offset, + _gyro_bias, (sizeof(NTPRECISE)*3)); + AndoidUncalProcessedData.ucGyro.TimeStamp = AndoidProcessedData.TimeStamp; + + _ResultTable[index].pResDesc->pOutputReadyCallback( + (OutputSensorHandle_t)&_ResultTable[index], &AndoidUncalProcessedData.ucGyro); + } else { + return OSP_STATUS_ERROR; + } + } + } + + // convert to algorithm convention before feeding data to algs. + algConvention.accuracy = QFIXEDPOINTPRECISE; + algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) + algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) + algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + memcpy(&_LastGyroCookedData, &algConvention, sizeof(Common_3AxisResult_t)); + + //OSP_SetForegroundGyroscopeMeasurement(AndoidProcessedData.TimeStamp, algConvention.data.preciseData); + break; + + default: + break; + } + + // all done for now, return OSP_STATUS_IDLE if no more data in the queue, else return OSP_STATUS_OK + + if(_SensorFgDataQCnt == 0) + return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that + else + return OSP_STATUS_OK; // more to process +} + + +/**************************************************************************************************** + * @fn OSP_DoBackgroundProcessing + * Triggers computation for less time critical background algorithms, e.g. sensor calibration + * + * @param none + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +__weak osp_status_t OSP_DoBackgroundProcessing(void) +{ + _SensorDataBuffer_t data; + Common_3AxisResult_t AndoidProcessedData; + //Common_3AxisResult_t algConvention; + + // Get next sensor data packet from the queue. If nothing in the queue, return OSP_STATUS_IDLE. + // If we get a data packet that has a sensor handle of NULL, we should drop it and get the next one, + // a NULL handle is an indicator that the data is from a sensor that has been replaced and that the data is stale. + + EnterCritical(); // no interrupts while we diddle the queue + + // ignore any data marked as stale. + while( (_SensorBgDataQueue[_SensorBgDataDqPtr].Handle == NULL) && (_SensorBgDataQCnt != 0) ) { + _SensorBgDataQCnt--; // stale data, show one less in the queue + if(++_SensorBgDataDqPtr == SENSOR_BG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so + _SensorBgDataDqPtr = 0; + } + + // now see if there is any data to process. + if(_SensorBgDataQCnt == 0) { // check for queue empty + ExitCritical(); + return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that + } + + // There is at least 1 data packet in the queue, get it. + memcpy(&data, &_SensorBgDataQueue[_SensorBgDataDqPtr], sizeof(_SensorDataBuffer_t)); // remove data from queue + _SensorBgDataQCnt--; // show one less in the queue + if(++_SensorBgDataDqPtr == SENSOR_BG_DATA_Q_SIZE) // and check for pointer wrap, rewind if so + _SensorBgDataDqPtr = 0; + + ExitCritical(); + + // now send the processed data to the appropriate entry points in the alg calibration code. + switch( ((_SenDesc_t*)data.Handle)->pSenDesc->SensorType ) { + + case SENSOR_ACCELEROMETER_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTPRECISE, + &_sensorLastBackgroundTimeStamp, + &_sensorLastBackgroundTimeStampExtension); + +#if 0 //Nothing to be done for background processing at this time! + // convert to algorithm convention. + algConvention.accuracy = QFIXEDPOINTPRECISE; + algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) + algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) + algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + //OSP_SetBackgroundAccelerometerMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); +#endif + break; + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTEXTENDED, + &_sensorLastBackgroundTimeStamp, + &_sensorLastBackgroundTimeStampExtension); + +#if 0 //Nothing to be done for background processing at this time! + // convert to algorithm convention. + algConvention.accuracy = QFIXEDPOINTEXTENDED; + algConvention.data.extendedData[0] = AndoidProcessedData.data.extendedData[1]; // x (ALG) = Y (Android) + algConvention.data.extendedData[1] = -AndoidProcessedData.data.extendedData[0]; // y (ALG) = -X (Android) + algConvention.data.extendedData[2] = AndoidProcessedData.data.extendedData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + //OSP_SetBackgroundMagnetometerMeasurement(algConvention.TimeStamp, algConvention.data.extendedData); +#endif + break; + + case SENSOR_GYROSCOPE_UNCALIBRATED: + // Now we have a copy of the data to be processed. We need to apply any and all input conversions. + ConvertSensorData( + &data, + &AndoidProcessedData, + QFIXEDPOINTPRECISE, + &_sensorLastBackgroundTimeStamp, + &_sensorLastBackgroundTimeStampExtension); + +#if 0 //Nothing to be done for background processing at this time! + // convert to algorithm convention. + algConvention.accuracy = QFIXEDPOINTPRECISE; + algConvention.data.preciseData[0] = AndoidProcessedData.data.preciseData[1]; // x (ALG) = Y (Android) + algConvention.data.preciseData[1] = -AndoidProcessedData.data.preciseData[0]; // y (ALG) = -X (Android) + algConvention.data.preciseData[2] = AndoidProcessedData.data.preciseData[2]; // z (ALG) = Z (Android) + algConvention.TimeStamp = AndoidProcessedData.TimeStamp; + + //OSP_SetBackgroundGyroscopeMeasurement(algConvention.TimeStamp, algConvention.data.preciseData); +#endif + break; + + default: + break; + } + + // all done for now, return OSP_STATUS_IDLE if no more data in the queue, else return OSP_STATUS_OK + if(_SensorBgDataQCnt == 0) + return OSP_STATUS_IDLE; // nothing left in the queue, let the caller know that + else + return OSP_STATUS_OK; // more to process +} + + +/**************************************************************************************************** + * @fn OSP_SubscribeOutputSensor + * Call for each Open-Sensor-Platform result (STEP_COUNT, ROTATION_VECTOR, etc) you want + * computed and output + * + * @param pSensorDescriptor INPUT pointer to data which describes the details of how the fusion + * should be computed: e.g output rate, sensors to use, etc. + * @param pOutputHandle OUTPUT a handle to be used for OSP_UnsubscribeOutputSensor() + * + * @return status as specified in OSP_Types.h. OSP_UNSUPPORTED_FEATURE for results that aren't + * available or licensed + * + ***************************************************************************************************/ +__weak osp_status_t OSP_SubscribeOutputSensor(SensorDescriptor_t *pSensorDescriptor, + OutputSensorHandle_t *pOutputHandle) +{ + int16_t index; + + if((pSensorDescriptor == NULL) || (pOutputHandle == NULL) || + (pSensorDescriptor->pOutputReadyCallback == NULL)) // just in case + return OSP_STATUS_NULL_POINTER; + + if(FindResultTableIndexByType(pSensorDescriptor->SensorType) != ERROR) { // is this result type already subscribed? + *pOutputHandle = NULL; + return OSP_STATUS_ALREADY_SUBSCRIBED; + } + + // we have a new request, validate the result descriptor here before entering it into our table. + + if(ValidateResultDescriptor(pSensorDescriptor) == ERROR) + return OSP_STATUS_DESCRIPTOR_INVALID; + + // Check for room in the result table, if no room, return OSP_STATUS_NO_MORE_HANDLES + + index = FindEmptyResultTableIndex(); + if(index == ERROR) { // if no room in the result table, return the error + *pOutputHandle = NULL; // and set the handle to NULL, so we can check for it later + return OSP_STATUS_NO_MORE_HANDLES; + } + + // check to be sure that we have all sensors registered that we need for this result. If so, mark them as "in use". + // if not, return OSP_STATUS_NOT_REGISTERED, and set the result handle to NULL. + + if(ActivateResultSensors(pSensorDescriptor->SensorType) == ERROR) { + *pOutputHandle = NULL; // and set the handle to NULL, so we can check for it later + return OSP_STATUS_NOT_REGISTERED; + } + + // Setup the alg callbacks, and any thing else that is needed for this result. + switch (pSensorDescriptor->SensorType) { + + case SENSOR_ACCELEROMETER_UNCALIBRATED: + _SubscribedResults |= (1LL << SENSOR_ACCELEROMETER_UNCALIBRATED); + //Note: Calibrated or uncalibrated result is specified in the descriptor flags + //For Uncalibrated result no callback needs to be registered with the algorithms + break; + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + _SubscribedResults |= (1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED); + //Note: Calibrated or uncalibrated result is specified in the descriptor flags + //For Uncalibrated result no callback needs to be registered with the algorithms + break; + + case SENSOR_GYROSCOPE_UNCALIBRATED: + _SubscribedResults |= (1LL << SENSOR_GYROSCOPE_UNCALIBRATED); + //Note: Calibrated or uncalibrated result is specified in the descriptor flags + //For Uncalibrated result no callback needs to be registered with the algorithms + break; + + case SENSOR_CONTEXT_DEVICE_MOTION: + _SubscribedResults |= (1LL << SENSOR_CONTEXT_DEVICE_MOTION); + OSP_RegisterSignificantMotionCallback(OnSignificantMotionResult); + break; + + case SENSOR_STEP_COUNTER: + _SubscribedResults |= (1LL << SENSOR_STEP_COUNTER); + OSP_RegisterStepCallback(OnStepResultsReady); + break; + + default: + return OSP_STATUS_UNKNOWN_REQUEST; + + } + + // Everything is setup, update our result table and return a handle + _ResultTable[index].pResDesc = pSensorDescriptor; + _ResultTable[index].Flags = 0; + *pOutputHandle = (OutputSensorHandle_t *)&_ResultTable[index]; + + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_UnsubscribeOutputSensor + * Stops the chain of computation for a registered result + * + * @param OutputHandle INPUT OutputSensorHandle_t that was received from + * OSP_SubscribeOutputSensor() + * + * @return status as specified in OSP_Types.h. + * + ***************************************************************************************************/ +osp_status_t OSP_UnsubscribeOutputSensor(OutputSensorHandle_t OutputHandle) +{ + int16_t index; + + // Check the result table to be sure that this is a valid handle, if not return OSP_STATUS_INVALID_HANDLE error. + // Also check that the handle points to a currently subscribed result, if not return OSP_STATUS_NOT_SUBSCRIBED. + if(OutputHandle == NULL) // just in case + return OSP_STATUS_INVALID_HANDLE; + index = FindResultTableIndexByHandle(OutputHandle); + if((index == ERROR) || (_ResultTable[index].pResDesc == NULL)) // test for active subscription for this handle + return OSP_STATUS_NOT_SUBSCRIBED; + + // Check to see if any of the other results that are still subscribed needs to use the sensors + // that we used. If not, mark those sensors as unused so that data from them will not be processed. + // All data in the input queues from sensors that we mark as unused should be marked as stale. We + // will also send a "sensor off" if that facility is available. + DeactivateResultSensors(_ResultTable[index].pResDesc->SensorType); + + // Now make sure that we won't call the users callback for this result + switch (_ResultTable[index].pResDesc->SensorType) { + + case SENSOR_ACCELEROMETER_UNCALIBRATED: + _SubscribedResults &= ~(1LL << SENSOR_ACCELEROMETER_UNCALIBRATED); + break; + + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + _SubscribedResults &= ~(1LL << SENSOR_MAGNETIC_FIELD_UNCALIBRATED); + break; + + case SENSOR_GYROSCOPE_UNCALIBRATED: + _SubscribedResults &= ~(1LL << SENSOR_GYROSCOPE_UNCALIBRATED); + break; + + case SENSOR_CONTEXT_DEVICE_MOTION: + _SubscribedResults &= ~(1LL << SENSOR_CONTEXT_DEVICE_MOTION); + break; + + case SENSOR_STEP_COUNTER: + _SubscribedResults &= ~(1LL << SENSOR_STEP_COUNTER); + break; + + default: + return OSP_STATUS_UNKNOWN_REQUEST; + + } + + // remove result table entry. + _ResultTable[index].pResDesc = NULL; + _ResultTable[index].Flags = 0; + + return OSP_STATUS_OK; +} + + +/**************************************************************************************************** + * @fn OSP_GetVersion + * Provides version number and version string of the library implementation + * + * @param pVersionStruct OUTPUT pointer to a pointer that will receive the version data. + * + * @return status as specified in OSP_Types.h + * + ***************************************************************************************************/ +__weak osp_status_t OSP_GetVersion(const OSP_Library_Version_t **pVersionStruct) +{ + *pVersionStruct = &libVersion; + return OSP_STATUS_OK; +} + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ + diff --git a/embedded/common/app/sensoracq_t.c b/embedded/common/app/sensoracq_t.c index fbf573b..963eff5 100644 --- a/embedded/common/app/sensoracq_t.c +++ b/embedded/common/app/sensoracq_t.c @@ -51,6 +51,12 @@ void WaitForHostSync(void); static AsfTimer sSensorTimer = NULL_TIMER; #endif static AsfTimer sPressureTimer = NULL_TIMER; + +/* This flag prevents data-ready messeges to be sent until + * Sensor Acquisition task is ready + */ +static uint8_t sTskRdyFlag = 0; + /*-------------------------------------------------------------------*\ | F O R W A R D F U N C T I O N D E C L A R A T I O N S \*-------------------------------------------------------------------*/ @@ -333,18 +339,25 @@ void SensorControlCmdHandler(MsgSensorControlData *pData) void SendDataReadyIndication(uint8_t sensorId, uint32_t timeStamp) { MessageBuffer *pSendMsg = NULLP; - if (ASFCreateMessage(MSG_SENSOR_DATA_RDY, - sizeof(MsgSensorDataRdy), &pSendMsg) == ASF_OK) { - pSendMsg->msg.msgSensorDataRdy.sensorId = sensorId; - pSendMsg->msg.msgSensorDataRdy.timeStamp = timeStamp; - - if ( ASFSendMessage(SENSOR_ACQ_TASK_ID, pSendMsg) != ASF_OK ) { - D0_printf("Error sending sensoracq message for senosr id %d\r\n", sensorId); +/* Do not send a message until sensor acquisition task is ready */ + if (0 != sTskRdyFlag){ + if (ASFCreateMessage(MSG_SENSOR_DATA_RDY, + sizeof(MsgSensorDataRdy), &pSendMsg) == ASF_OK) { + pSendMsg->msg.msgSensorDataRdy.sensorId = sensorId; + pSendMsg->msg.msgSensorDataRdy.timeStamp = timeStamp; + + if ( ASFSendMessage(SENSOR_ACQ_TASK_ID, pSendMsg) != ASF_OK ) { + D0_printf("Error sending sensoracq message for senosr id %d\r\n", sensorId); + } + } else { + D0_printf("Error creating sensoracq message for sensor id %d\r\n", sensorId); } - } else { - D0_printf("Error creating sensoracq message for sensor id %d\r\n", sensorId); } - +/* Mag interrupt needs to be explicitly cleaned after the interrupt is read/ignored */ + else if(sensorId == MAG_INPUT_SENSOR) + { + Mag_ClearDataInt(); + } } /******************************************************************* @@ -370,7 +383,7 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG) volatile uint8_t i; #ifndef WAIT_FOR_HOST_SYNC - os_dly_wait(MSEC_TO_TICS(50)); /* Allow startup time for sensors */ + osDelay(50); #else WaitForHostSync(); //This also allows for startup time for sensors #endif @@ -417,6 +430,8 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG) /* Magnetometer sensor does not re-generate interrupt if its outputs are not read. */ Mag_ClearDataInt(); + /* Indicate sensor init done */ + sTskRdyFlag = 1; while (1) { ASFReceiveMessage(SENSOR_ACQ_TASK_ID, &rcvMsg); @@ -450,6 +465,7 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG) D2_printf("SensorAcqTask:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); break; } + ASFDeleteMessage( SENSOR_ACQ_TASK_ID, &rcvMsg ); } } diff --git a/embedded/common/asf/asf_messages.c b/embedded/common/asf/asf_messages.c index 7bb0ff7..b65b4ef 100644 --- a/embedded/common/asf/asf_messages.c +++ b/embedded/common/asf/asf_messages.c @@ -1,341 +1,322 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "common.h" -#include "asf_taskstruct.h" - -//#undef USE_ALLOC -#define USE_ALLOC 1 -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -extern const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS]; - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#define MESSAGE_BLOCK_SIZE (sizeof(MessageBlock)) - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -uint32_t debugMessageBlockSize = 0; -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/** - * The _declare_box macro declares an array of bytes that can be used as a memory pool for fixed - * block allocation. - */ - -#define TRACK_MSG_POOL 0 -#if USE_ALLOC -_declare_box( mpool, ///< this memory pool will be used to allocate the messages - MESSAGE_BLOCK_SIZE, /**< this is the size of the regular messages. - To avoid variable length, we allocate from this fixed size. If memory usage become issue - we can divide the messages among various pool size that would optimize memory usage */ - MAX_SYSTEM_MESSAGES //< Max (non dprintf) messages in the system - ); -#else -struct _MsgPool { - volatile int32_t status; -#if TRACK_MSG_POOL - char *_file; - int _line; -#endif - uint8_t msg[MESSAGE_BLOCK_SIZE]; -} MsgPool[MAX_SYSTEM_MESSAGES]; - -static void MsgPool_init(struct _MsgPool *p) -{ - int i; - -#if 1 //QLY: initialize pool memory to debug memory overwrite issue - memset(MsgPool, 0xff, sizeof(MsgPool)); - debugMessageBlockSize = sizeof( struct _MsgPool); -#endif - - for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { - p[i].status = 0; - } -} - -static void * MsgPool_get(struct _MsgPool *p, char *_file, int _line) -{ - int i; - __disable_irq(); - for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { - p[i].status += (i+1); - if (p[i].status != (i+1)) { - p[i].status -= (i+1); - } else { - __enable_irq(); -#if TRACK_MSG_POOL - p[i]._file = _file; - p[i]._line = _line; -#endif - return p[i].msg; - } - } - __enable_irq(); - return NULL; -} -static void MsgPool_put(struct _MsgPool *p, void *m) -{ - int i; - for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { - if (p[i].msg == m) { - if (p[i].status == 0) { - //D0_printf("Double free!\n"); - return; - } - p[i].status = 0; -#if TRACK_MSG_POOL - p[i]._file = ""; - p[i]._line = 1; -#endif - return; - } - } - ASF_assert(0); /* Something is wrong! */ -} -#endif -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn ASFDeleteMessage - * This function releases the buffer memory associated with the message contents. The caller - * must call this function after a message's contents have been read to free the memory - * associated with the message. - * - * @param pMbuf Message buffer pointer containing the message to be deleted. - * - * @return none - * - * @see ASFCreateMessage(), ASFSendMessage(), ASFReceiveMessage() - ***************************************************************************************************/ -static void _ASFDeleteMessage ( MessageBuffer **pMbuf, char *_file, int _line ) -{ - MessageBlock *pBlock; - - /** This is where we release the memory allocated when the message was created */ - if (*pMbuf != NULLP) - { - /* Get the block pointer */ - M_GetMsgBlockFromBuffer (pBlock, *pMbuf); -#if USE_ALLOC - ASF_assert( _free_box( mpool, pBlock ) == 0 ); -#else - MsgPool_put(MsgPool, pBlock); -#endif - } - - *pMbuf = NULLP; -} - - - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn ASFMessagingInit - * Initializes the messaging scheme in the system - * - ***************************************************************************************************/ -void ASFMessagingInit( void ) -{ -#if USE_ALLOC - _init_box( mpool, sizeof(mpool), MESSAGE_BLOCK_SIZE ); -#else - MsgPool_init(MsgPool); -#endif -} - - -/**************************************************************************************************** - * @fn ASFCreateMessage - * This function is called to create (allocate) the space for the message type specified. - * This is the first step before the message parameters are filled in and the message is - * sent via the ASFSendMessage() call. - * - * @param msgId Message ID of the message to be created. - * @param msgSize size (in bytes) of the message corresponding to the ID. This is typically the - * sizeof structure corresponding to the message. - * - * @return pMbuf This pointer returns the allocated buffer space for the message type specified. - * - * @see ASFSendMessage(), ASFReceiveMessage() - ***************************************************************************************************/ -AsfResult_t _ASFCreateMessage( MessageId msgId, uint16_t msgSize, MessageBuffer **pMbuf, char *_file, int _line ) -{ - MessageBlock *pBlock; - - /* At this time it is assumed that the memory pool for message allocation has been - created and initialized */ - ASF_assert_var( *pMbuf == NULLP, msgId, 0, 0 ); - -#if USE_ALLOC - pBlock = _alloc_box(mpool); -#else - pBlock = MsgPool_get(MsgPool, _file, _line); -#endif - if (pBlock == NULLP) return ASF_ERR_MSG_BUFF; - - pBlock->header.length = msgSize; - pBlock->rec.msgId = msgId; - - /* Set the user message buffer now */ - *pMbuf = (MessageBuffer *)&pBlock->rec; - return ASF_OK; -} - -uint32_t wtf_msg_cnt = 0; -/**************************************************************************************************** - * @fn ASFSendMessage - * This function is called after a message has been created and the message parameters - * filled in. It sends the message to the destination task queue without blocking. - * - * @param destTask TaskId of the destination task which will receive the message. - * @param pMbuf Message buffer pointer containing the message to send. - * @param cntxt Specify if the message is being sent from ISR or Thread context - * - * @return none - * - * @see ASFCreateMessage(), ASFReceiveMessage() - ***************************************************************************************************/ -AsfResult_t _ASFSendMessage ( TaskId destTask, MessageBuffer *pMbuf, char *_file, int _line ) -{ - MessageBlock *pBlock; - OS_RESULT err; - - /* Check for the usual - null pointers etc. */ - ASF_assert_var( pMbuf != NULLP, pMbuf->msgId, 0, 0 ); - - /* Get the block pointer */ - M_GetMsgBlockFromBuffer (pBlock, pMbuf); - - pBlock->header.destTask = destTask; - - /* Send the message without pending */ - if ( GetContext() != CTX_ISR ) - { - err = os_mbx_send( C_gAsfTaskInitTable[destTask].queue, pMbuf, 0 ); - if (err != OS_R_OK) //Mailbox is not valid or full - { -#if USE_ALLOC - ASF_assert( _free_box( mpool, pBlock ) == 0 ); -#else - MsgPool_put(MsgPool, pBlock); -#endif - return ASF_ERR_Q_FULL; - } - } - else - { - err = isr_mbx_check( C_gAsfTaskInitTable[destTask].queue ); - if (err != 0) { -#if 0 - ASF_assert_var(err != 0, err, pMbuf->msgId, destTask); -#endif - isr_mbx_send( C_gAsfTaskInitTable[destTask].queue, pMbuf ); - } else { - wtf_msg_cnt++; - } - } - return ASF_OK; -} - - -/**************************************************************************************************** - * @fn ASFReceiveMessage - * This function blocks until a message is received on the queue of the calling task. - * - * @param rcvTask TaskId of the receiving task which will receive the message. This id must be - * task's own id. - * - * @param pMbuf Message buffer pointer that will return the message received. Note that the - * pointer to the memory allocated for the message contents is passed in the - * message buffer structure passed in. - * - * @return none - * - * @see ASFCreateMessage(), ASFSendMessage(), ASFDeleteMessage(), ASFReceiveMessagePoll() - ***************************************************************************************************/ -void _ASFReceiveMessage ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ) -{ - OS_RESULT err; - - /* Delete old/previous message to release its buffer */ - _ASFDeleteMessage( pMbuf, _file, _line ); - - /* Wait for receive */ - err = os_mbx_wait( C_gAsfTaskInitTable[rcvTask].queue, (void **)pMbuf, OS_WAIT_FOREVER ); - ASF_assert_var(((err == OS_R_OK) || (err == OS_R_MBX)), err, 0, 0); -} - - -/**************************************************************************************************** - * @fn ASFReceiveMessagePoll - * This function tries to receive a message on the queue of the calling task without blocking. - * - * @param rcvTask TaskId of the receiving task which will receive the message. This id must be - * task's own id. - * - * @param pMbuf Message buffer pointer that will return the message received. Note that the - * pointer to the memory allocated for the message contents is passed in the - * message buffer structure passed in. - * - * @return true if message was received. - * - * @see ASFCreateMessage(), ASFSendMessage(), ASFDeleteMessage(), ASFReceiveMessage() - ***************************************************************************************************/ -osp_bool_t _ASFReceiveMessagePoll ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ) -{ - OS_RESULT err; - - /* Delete old message to release its buffer */ - _ASFDeleteMessage( pMbuf, _file, _line ); - - /* Wait for receive */ - err = os_mbx_wait( C_gAsfTaskInitTable[rcvTask].queue, (void **)pMbuf, OS_WAIT_NEVER ); - if (err == OS_R_TMO) - { - return false; - } - ASF_assert_var(((err == OS_R_OK) || (err == OS_R_MBX)), err, 0, 0); - return true; -} - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "asf_taskstruct.h" + +//#undef USE_ALLOC +#define USE_ALLOC 1 +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +uint32_t debugMessageBlockSize = 0; +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/** + * The _declare_box macro declares an array of bytes that can be used as a memory pool for fixed + * block allocation. + */ + +#define TRACK_MSG_POOL 0 +#if USE_ALLOC +osPoolDef(cmpool, MAX_SYSTEM_MESSAGES, MessageBlock); /* Define memory pool */ +osPoolId cmpool; +#else +struct _MsgPool { + volatile int32_t status; +#if TRACK_MSG_POOL + char *_file; + int _line; +#endif + uint8_t msg[MESSAGE_BLOCK_SIZE]; +} MsgPool[MAX_SYSTEM_MESSAGES]; + +static void MsgPool_init(struct _MsgPool *p) +{ + int i; + +#if 1 //QLY: initialize pool memory to debug memory overwrite issue + memset(MsgPool, 0xff, sizeof(MsgPool)); + debugMessageBlockSize = sizeof( struct _MsgPool); +#endif + + for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { + p[i].status = 0; + } +} + +static void * MsgPool_get(struct _MsgPool *p, char *_file, int _line) +{ + int i; + __disable_irq(); + for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { + p[i].status += (i+1); + if (p[i].status != (i+1)) { + p[i].status -= (i+1); + } else { + __enable_irq(); +#if TRACK_MSG_POOL + p[i]._file = _file; + p[i]._line = _line; +#endif + return p[i].msg; + } + } + __enable_irq(); + return NULL; +} +static void MsgPool_put(struct _MsgPool *p, void *m) +{ + int i; + for (i = 0; i < MAX_SYSTEM_MESSAGES; i++) { + if (p[i].msg == m) { + if (p[i].status == 0) { + //D0_printf("Double free!\n"); + return; + } + p[i].status = 0; +#if TRACK_MSG_POOL + p[i]._file = ""; + p[i]._line = 1; +#endif + return; + } + } + ASF_assert(0); /* Something is wrong! */ +} +#endif +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn ASFDeleteMessage + * This function releases the buffer memory associated with the message contents. The caller + * must call this function after a message's contents have been read to free the memory + * associated with the message. + * + * @param pMbuf Message buffer pointer containing the message to be deleted. + * + * @return none + * + * @see ASFCreateMessage(), ASFSendMessage(), ASFReceiveMessage() + ***************************************************************************************************/ +void _ASFDeleteMessage ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ) +{ + MessageBlock *pBlock; + + /** This is where we release the memory allocated when the message was created */ + if (*pMbuf != NULLP) + { + /* Get the block pointer */ + M_GetMsgBlockFromBuffer (pBlock, *pMbuf); +#if USE_ALLOC + ASF_assert( osPoolFree( cmpool, pBlock ) == osOK); +#else + MsgPool_put(MsgPool, pBlock); +#endif + } + + *pMbuf = NULLP; +} + + + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn ASFMessagingInit + * Initializes the messaging scheme in the system + * + ***************************************************************************************************/ +void ASFMessagingInit( void ) +{ +#if USE_ALLOC + cmpool = osPoolCreate(osPool(cmpool)); +#else + MsgPool_init(MsgPool); +#endif +} + + +/**************************************************************************************************** + * @fn ASFCreateMessage + * This function is called to create (allocate) the space for the message type specified. + * This is the first step before the message parameters are filled in and the message is + * sent via the ASFSendMessage() call. + * + * @param msgId Message ID of the message to be created. + * @param msgSize size (in bytes) of the message corresponding to the ID. This is typically the + * sizeof structure corresponding to the message. + * + * @return pMbuf This pointer returns the allocated buffer space for the message type specified. + * + * @see ASFSendMessage(), ASFReceiveMessage() + ***************************************************************************************************/ +AsfResult_t _ASFCreateMessage( MessageId msgId, uint16_t msgSize, MessageBuffer **pMbuf, char *_file, int _line ) +{ + MessageBlock *pBlock; + + /* At this time it is assumed that the memory pool for message allocation has been + created and initialized */ + ASF_assert_var( *pMbuf == NULLP, msgId, 0, 0 ); + +#if USE_ALLOC + pBlock = osPoolAlloc(cmpool); +#else + pBlock = MsgPool_get(MsgPool, _file, _line); +#endif + if (pBlock == NULLP) return ASF_ERR_MSG_BUFF; + + pBlock->header.length = msgSize; + pBlock->rec.msgId = msgId; + + /* Set the user message buffer now */ + *pMbuf = (MessageBuffer *)&pBlock->rec; + return ASF_OK; +} + +uint32_t wtf_msg_cnt = 0; +/**************************************************************************************************** + * @fn ASFSendMessage + * This function is called after a message has been created and the message parameters + * filled in. It sends the message to the destination task queue without blocking. + * + * @param destTask TaskId of the destination task which will receive the message. + * @param pMbuf Message buffer pointer containing the message to send. + * @param cntxt Specify if the message is being sent from ISR or Thread context + * + * @return none + * + * @see ASFCreateMessage(), ASFReceiveMessage() + ***************************************************************************************************/ +AsfResult_t _ASFSendMessage ( TaskId destTask, MessageBuffer *pMbuf, char *_file, int _line ) +{ + MessageBlock *pBlock; + osStatus os_ret = osErrorOS; + + /* Check for the usual - null pointers etc. */ + ASF_assert_var( pMbuf != NULLP, pMbuf->msgId, 0, 0 ); + + /* Get the block pointer */ + M_GetMsgBlockFromBuffer (pBlock, pMbuf); + + pBlock->header.destTask = destTask; + os_ret = osMailPut(asfTaskHandleTable[destTask].posMailQId,pMbuf); + if(osOK != os_ret) + { +#if USE_ALLOC + ASF_assert( osPoolFree( cmpool, pBlock ) == 0 ); +#else + MsgPool_put(MsgPool, pBlock); +#endif + return ASF_ERR_Q_FULL; + } + return ASF_OK; +} + + +/**************************************************************************************************** + * @fn ASFReceiveMessage + * This function blocks until a message is received on the queue of the calling task. + * + * @param rcvTask TaskId of the receiving task which will receive the message. This id must be + * task's own id. + * + * @param pMbuf Message buffer pointer that will return the message received. Note that the + * pointer to the memory allocated for the message contents is passed in the + * message buffer structure passed in. + * + * @return none + * + * @see ASFCreateMessage(), ASFSendMessage(), ASFDeleteMessage(), ASFReceiveMessagePoll() + ***************************************************************************************************/ +void _ASFReceiveMessage ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ) +{ + osEvent evt; + + /* Delete old/previous message to release its buffer */ + _ASFDeleteMessage( rcvTask, pMbuf, _file, _line ); + + evt = osMailGet(asfTaskHandleTable[rcvTask].posMailQId,osWaitForever); + if (evt.status == osEventMail) + { + *pMbuf = evt.value.p; + } +} + +/**************************************************************************************************** + * @fn ASFReceiveMessagePoll + * This function tries to receive a message on the queue of the calling task without blocking. + * + * @param rcvTask TaskId of the receiving task which will receive the message. This id must be + * task's own id. + * + * @param pMbuf Message buffer pointer that will return the message received. Note that the + * pointer to the memory allocated for the message contents is passed in the + * message buffer structure passed in. + * + * @return true if message was received. + * + * @see ASFCreateMessage(), ASFSendMessage(), ASFDeleteMessage(), ASFReceiveMessage() + ***************************************************************************************************/ +osp_bool_t _ASFReceiveMessagePoll ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ) +{ + osEvent evt; + + /* Delete old message to release its buffer */ + _ASFDeleteMessage( rcvTask, pMbuf, _file, _line ); + + /* Wait for receive */ + evt = osMailGet( asfTaskHandleTable[rcvTask].posMailQId, 0 ); + if (evt.status == osEventTimeout) + { + return false; + } + if (evt.status == osEventMail) + { + *pMbuf = evt.value.p; + } + return true; +} + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/asf/asf_msgstruct.h b/embedded/common/asf/asf_msgstruct.h index 89f22b4..59a2283 100644 --- a/embedded/common/asf/asf_msgstruct.h +++ b/embedded/common/asf/asf_msgstruct.h @@ -58,7 +58,7 @@ typedef struct MsgNoDataTag typedef struct MsgTimerExpiryTag { uint16_t userValue; - TimerId timerId; + osTimerId timerId; } MsgTimerExpiry; @@ -122,8 +122,8 @@ union Message #define ASFReceiveMessagePoll( id, pm ) \ _ASFReceiveMessagePoll( id, pm, __MODULE__, __LINE__ ) -#define ASFDeleteMessage( pm ) \ - _ASFDeleteMessage( pm, __MODULE__, __LINE__ ) +#define ASFDeleteMessage( id, pm ) \ + _ASFDeleteMessage( id, pm, __MODULE__, __LINE__ ) /*-------------------------------------------------------------------------------------------------*\ @@ -179,7 +179,7 @@ void ASFMessagingInit( void ); AsfResult_t _ASFCreateMessage( MessageId msgId, uint16_t msgSize, MessageBuffer **pMbuf, char *_file, int _line ); AsfResult_t _ASFSendMessage ( TaskId destTask, MessageBuffer *pMbuf, char *_file, int _line ); void _ASFReceiveMessage ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ); -void _ASFDeleteMessage ( MessageBuffer **pMbuf, char *_file, int _line ); +void _ASFDeleteMessage ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ); osp_bool_t _ASFReceiveMessagePoll ( TaskId rcvTask, MessageBuffer **pMbuf, char *_file, int _line ); diff --git a/embedded/common/asf/asf_taskdeftype.h b/embedded/common/asf/asf_taskdeftype.h index 9e5ac2d..e91f749 100644 --- a/embedded/common/asf/asf_taskdeftype.h +++ b/embedded/common/asf/asf_taskdeftype.h @@ -1,67 +1,69 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* This file maybe included more than once */ - - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -/* -** ASF_TASK_DEF_TYPE should be defined to be either -** -** ASF_TASK_IDS -** ASF_QUEUE_SETUP -** ASF_STACK_SETUP -** ASF_TASK_SETUP -** ASF_TASK_DECLARE -** -** by the including file -*/ -#define ASF_TASK_IDS 1 -#define ASF_STACK_SETUP 2 -#define ASF_QUEUE_SETUP 3 -#define ASF_TASK_SETUP 4 -#define ASF_TASK_DECLARE 5 - -#define IN_ASF_TASK_DEF - -#if defined (ASF_TASK_STATIC) -# undef ASF_TASK_STATIC -#endif - -/*************************************************************************** - * Include OS specific macros - **************************************************************************/ - -#include "asf_tdefmacros.h" - - -#if !defined (ASF_TASK_STATIC) -# error ASF_TASK_STATIC must be defined -#endif - -#undef ASF_TASK_DEF_TYPE -#undef IN_ASF_TASK_DEF - -#define ASF_TASK __task -#define ASF_TASK_ARG void *argv - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* This file maybe included more than once */ + + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +/* +** ASF_TASK_DEF_TYPE should be defined to be either +** +** ASF_TASK_IDS +** ASF_QUEUE_SETUP +** ASF_STACK_SETUP +** ASF_TASK_SETUP +** ASF_TASK_DECLARE +** +** by the including file +*/ +#define ASF_TASK_IDS 1 +#define ASF_STACK_SETUP 2 +#define ASF_QUEUE_SETUP 3 +#define ASF_TASK_SETUP 4 +#define ASF_TASK_DECLARE 5 +#define ASF_THREAD_SETUP 6 +#define ASF_TIMER_SETUP 7 + +#define IN_ASF_TASK_DEF + +#if defined (ASF_TASK_STATIC) +# undef ASF_TASK_STATIC +#endif + +/*************************************************************************** + * Include OS specific macros + **************************************************************************/ + +#include "asf_tdefmacros.h" + + +#if !defined (ASF_TASK_STATIC) +# error ASF_TASK_STATIC must be defined +#endif + +#undef ASF_TASK_DEF_TYPE +#undef IN_ASF_TASK_DEF + +#define ASF_TASK +#define ASF_TASK_ARG void const *argv + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/asf/asf_taskinit.c b/embedded/common/asf/asf_taskinit.c index d9bb235..d82fa08 100644 --- a/embedded/common/asf/asf_taskinit.c +++ b/embedded/common/asf/asf_taskinit.c @@ -1,198 +1,207 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "common.h" -#include "asf_taskstruct.h" -#include - - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -void ASFMessagingInit( void ); -extern uint8_t GetTaskList( uint8_t **pTaskList ); - - -#define STACK_INCREASE 0 - - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Declare all the thread function prototypes here */ -#define ASF_TASK_DEF_TYPE ASF_TASK_DECLARE -#include "asf_taskdeftype.h" -#include "asf_tasks.h" - -/** - * Declare the task stack - */ -#define ASF_TASK_DEF_TYPE ASF_STACK_SETUP -#include "asf_taskdeftype.h" -#include "asf_tasks.h" - - -/** - * Declare the queues associated with each task - */ -#define ASF_TASK_DEF_TYPE ASF_QUEUE_SETUP -#include "asf_taskdeftype.h" -#include "asf_tasks.h" - - -/** - * This is the task initialization table which details all the information - * pulled from ASF_TASK_STATIC/ ASF_TASK_DYNAMIC that is required to create - * the tasks. - * NOTE: this array is marked as constant so that it is placed in ROM. - */ -#define ASF_TASK_DEF_TYPE ASF_TASK_SETUP -#include "asf_taskdeftype.h" -const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS] = -{ -#include "asf_tasks.h" -}; - -/** - * This table will hold the Task handle (RTX task type)corresponding to - * the TaskId for each task. This is initialized during AsfInitialiseTasks() - */ -AsfTaskHandle asfTaskHandleTable[NUMBER_OF_TASKS]; - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -/* IMPORTANT: The total stack needed must include stack sizes of all tasks that can be created in - a given mode. */ -#define ASF_TASK_DEF_TYPE ASF_TOTAL_STACK_NEEDED -#include "asf_taskdeftype.h" -const uint32_t TotalStkNeeded = -( - 128 /* System overhead */ -#include "asf_tasks.h" -); - -/* Heap Area defined here */ -U64 NewHeap[TotalStkNeeded/8] = {0}; - - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn InitializeTasks - * Called from initial task to spawn the rest of the tasks in the system - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -void InitializeTasks( void ) -{ - uint8_t taskCounter, numTasks; - TaskId tid; - uint8_t *pTaskTable; - uint32_t *pU64Aligned; - - /* Create tasks based on the mode we are in */ - numTasks = GetTaskList( &pTaskTable ); - for (taskCounter = 0; taskCounter < numTasks; taskCounter++) - { - tid = (TaskId)pTaskTable[taskCounter]; - - if (tid != INSTR_MANAGER_TASK_ID) - { - /* Allocate task stack from heap */ - /* NOTE: All mallocs are 8-byte aligned as per ARM stack alignment requirements */ - pU64Aligned = malloc( C_gAsfTaskInitTable[tid].stackSize ); - ASF_assert( pU64Aligned != NULL ); - ASF_assert( ((uint32_t)pU64Aligned & 0x7) == 0 ); //Ensure 64-bit aligned - - asfTaskHandleTable[tid].handle = os_tsk_create_user( C_gAsfTaskInitTable[tid].entryPoint, - C_gAsfTaskInitTable[tid].priority, pU64Aligned, C_gAsfTaskInitTable[tid].stackSize); - ASF_assert( asfTaskHandleTable[tid].handle != 0 ); - asfTaskHandleTable[tid].stkSize = C_gAsfTaskInitTable[tid].stackSize; - asfTaskHandleTable[tid].pStack = pU64Aligned; /* Keep track of our stack pointer */ - } - - /* Initialize the associated queue */ - if (asfTaskHandleTable[tid].handle != 0) - { - os_mbx_init( C_gAsfTaskInitTable[tid].queue, C_gAsfTaskInitTable[tid].queueSize ); - } - } - - /* Initialize the messaging */ - ASFMessagingInit(); - - /* Switch the priority to be lowest now */ - os_tsk_prio_self( C_gAsfTaskInitTable[INSTR_MANAGER_TASK_ID].priority ); -} - - -/**************************************************************************************************** - * @fn AsfInitialiseTasks - * This function creates all the Tasks (via the initialTask) as defined in the - * C_gAsfTaskInitTable and starts the RTX ticking. This function should be the last to be - * called from main() as it will not return. - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -void AsfInitialiseTasks ( void ) -{ - uint32_t *pU64Aligned; - - /* NOTE: All mallocs are 8-byte aligned as per ARM stack alignment requirements */ - pU64Aligned = malloc( C_gAsfTaskInitTable[INSTR_MANAGER_TASK_ID].stackSize ); - ASF_assert( ((uint32_t)pU64Aligned & 0x7) == 0 ); //Ensure 64-bit aligned - - asfTaskHandleTable[INSTR_MANAGER_TASK_ID].handle = 1; //Initial task always gets this OS_ID - asfTaskHandleTable[INSTR_MANAGER_TASK_ID].stkSize = C_gAsfTaskInitTable[INSTR_MANAGER_TASK_ID].stackSize; - asfTaskHandleTable[INSTR_MANAGER_TASK_ID].pStack = pU64Aligned; - - /* Initialize RTX and start initialTask */ - os_sys_init_user( InstrManagerTask, 254, pU64Aligned, C_gAsfTaskInitTable[INSTR_MANAGER_TASK_ID].stackSize ); -} - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "asf_taskstruct.h" +#include +#include "cmsis_os.h" + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +void ASFMessagingInit( void ); +extern uint8_t GetTaskList( uint8_t **pTaskList ); + +#define STACK_INCREASE 0 + + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Declare all the thread function prototypes here */ +#define ASF_TASK_DEF_TYPE ASF_TASK_DECLARE +#include "asf_taskdeftype.h" +#include "asf_tasks.h" + +/** + * Declare the task stack + */ +#define ASF_TASK_DEF_TYPE ASF_STACK_SETUP +#include "asf_taskdeftype.h" +#include "asf_tasks.h" + + +/** + * Declare the queues associated with each task + */ +#define ASF_TASK_DEF_TYPE ASF_QUEUE_SETUP +#include "asf_taskdeftype.h" +#include "asf_tasks.h" + +/** + * Define the CMSIS Thread structure + */ +#define ASF_TASK_DEF_TYPE ASF_THREAD_SETUP +#include "asf_taskdeftype.h" +#include "asf_tasks.h" + +/** + * Define the CMSIS Timer structure + */ +#define ASF_TASK_DEF_TYPE ASF_TIMER_SETUP +#include "asf_taskdeftype.h" +#include "asf_tasks.h" + +/** + * This is the task initialization table which details all the information + * pulled from ASF_TASK_STATIC/ ASF_TASK_DYNAMIC that is required to create + * the tasks. + * NOTE: this array is marked as constant so that it is placed in ROM. + */ +#define ASF_TASK_DEF_TYPE ASF_TASK_SETUP +#include "asf_taskdeftype.h" +const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS] = +{ +#include "asf_tasks.h" +}; + +/** + * This table will hold the Task handle (RTX task type)corresponding to + * the TaskId for each task. This is initialized during AsfInitialiseTasks() + */ +AsfTaskHandle asfTaskHandleTable[NUMBER_OF_TASKS]; + + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +/* IMPORTANT: The total stack needed must include stack sizes of all tasks that can be created in + a given mode. */ +#define ASF_TASK_DEF_TYPE ASF_TOTAL_STACK_NEEDED +#include "asf_taskdeftype.h" +const uint32_t TotalStkNeeded = +( + 128 /* System overhead */ +#include "asf_tasks.h" +); + + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn InitializeTasks + * Called from initial task to spawn the rest of the tasks in the system + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +void InitializeTasks( void ) +{ + uint8_t taskCounter, numTasks; + TaskId tid; + uint8_t *pTaskTable; + + /* Create tasks based on the mode we are in */ + numTasks = GetTaskList( &pTaskTable ); + for (taskCounter = 0; taskCounter < numTasks; taskCounter++) + { + tid = (TaskId)pTaskTable[taskCounter]; + + if (tid != INSTR_MANAGER_TASK_ID) + { + asfTaskHandleTable[tid].posThreadId = osThreadCreate(C_gAsfTaskInitTable[tid].posThreadDef,NULL); + + ASF_assert( asfTaskHandleTable[tid].posThreadId != NULL ); + asfTaskHandleTable[tid].stkSize = C_gAsfTaskInitTable[tid].stackSize; + asfTaskHandleTable[tid].pStack = NULL; /* Keep track of our stack pointer */ + } + + /* Initialize the associated queue */ + if (NULL != asfTaskHandleTable[tid].posThreadId) + { + asfTaskHandleTable[tid].posMailQId = osMailCreate(C_gAsfTaskInitTable[tid].mailQDef,NULL); + } + } + + /* Switch the priority to be lowest now */ + osThreadSetPriority(asfTaskHandleTable[INSTR_MANAGER_TASK_ID].posThreadId,osPriorityLow); +} + + +/**************************************************************************************************** + * @fn AsfInitialiseTasks + * This function creates all the Tasks (via the initialTask) as defined in the + * C_gAsfTaskInitTable and starts the RTX ticking. This function should be the last to be + * called from main() as it will not return. + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +void AsfInitialiseTasks ( void ) +{ + uint8_t taskCounter=0; + TaskId tid; + uint8_t *pTaskTable; + + /* Create tasks based on the mode we are in */ + GetTaskList( &pTaskTable ); + tid = (TaskId)pTaskTable[taskCounter]; + + /* Allocate task stack from heap */ + /* NOTE: All mallocs are 8-byte aligned as per ARM stack alignment requirements */ + /* Initialize the messaging */ + ASFMessagingInit(); + + asfTaskHandleTable[tid].posThreadId = osThreadCreate(C_gAsfTaskInitTable[tid].posThreadDef,NULL); + + ASF_assert( NULL != asfTaskHandleTable[tid].posThreadId ); + + asfTaskHandleTable[tid].stkSize = C_gAsfTaskInitTable[tid].stackSize; + asfTaskHandleTable[tid].pStack = NULL; /* Keep track of our stack pointer */ + + osThreadTerminate(osThreadGetId()); +} + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/asf/asf_tasks.h b/embedded/common/asf/asf_tasks.h index cbffa09..84094ac 100644 --- a/embedded/common/asf/asf_tasks.h +++ b/embedded/common/asf/asf_tasks.h @@ -1,68 +1,68 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* This file maybe included more than once */ - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -/** -** ASF_TASK_STATIC ( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) -** This macro declares a static thread that will be created (along with an -** associated queue) automatically by the ASF startup initialization and -** will persist throughout the lifetime of the application. -** -** Parameters: -** ThreadId - User defined C-Style identifier for the thread. -** E.g. MY_THREAD_ID. This identifier will be used in the -** application to access the thread properties and its -** associated queue. -** EntryFunction - Thread entry function name. -** Priority - Thread priority in the range of 51 through 254. Higher value -** implies higher priority. Values 0 through 50 are reserved and -** should not be used. -** StackSize - Thread stack size in bytes. -** QueueSize - This denotes the maximum number of messages that are allowed -** to be queued for the thread. An optimum value should be -** chosen for this parameter to minimize memory wastage. -** -** Example: ASF_TASK_STATIC ( COMM_THREAD, CommThreadEntry, 55, 1024, 10 ) -** -** Entry Function must be declared in the following manner: -** ASF_TASK MyThreadEntry ( ASF_TASK_ARG ) -** { -** ... -** } -** -*/ -/* Declare all ASF tasks here */ -/* This task creates other tasks and OS resources and must always be present */ -ASF_TASK_STATIC ( INSTR_MANAGER_TASK_ID, InstrManagerTask, 50, 0x800, 4 ) -#if 0 -/* Handles command input from UART */ -ASF_TASK_STATIC ( CMD_HNDLR_TASK_ID, CmdHandlerTask, 92, 0x800, 4 ) -#endif -/* Sensor data handler task */ -ASF_TASK_STATIC ( SENSOR_ACQ_TASK_ID, SensorAcqTask, 95, 0x800, 64 ) - -/* Additional tasks specific to application is defined in App_Tasks.h */ -#include "app_tasks.h" - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* This file maybe included more than once */ + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +/** +** ASF_TASK_STATIC ( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) +** This macro declares a static thread that will be created (along with an +** associated queue) automatically by the ASF startup initialization and +** will persist throughout the lifetime of the application. +** +** Parameters: +** ThreadId - User defined C-Style identifier for the thread. +** E.g. MY_THREAD_ID. This identifier will be used in the +** application to access the thread properties and its +** associated queue. +** EntryFunction - Thread entry function name. +** Priority - Thread priority in the range of 51 through 254. Higher value +** implies higher priority. Values 0 through 50 are reserved and +** should not be used. +** StackSize - Thread stack size in bytes. +** QueueSize - This denotes the maximum number of messages that are allowed +** to be queued for the thread. An optimum value should be +** chosen for this parameter to minimize memory wastage. +** +** Example: ASF_TASK_STATIC ( COMM_THREAD, CommThreadEntry, 55, 1024, 10 ) +** +** Entry Function must be declared in the following manner: +** ASF_TASK MyThreadEntry ( ASF_TASK_ARG ) +** { +** ... +** } +** +*/ +/* Declare all ASF tasks here */ +/* This task creates other tasks and OS resources and must always be present */ +ASF_TASK_STATIC ( INSTR_MANAGER_TASK_ID, InstrManagerTask, osPriorityNormal, 0x200, 4 ) +#if 0 +/* Handles command input from UART */ +ASF_TASK_STATIC ( CMD_HNDLR_TASK_ID, CmdHandlerTask, osPriorityNormal, 0x800, 4 ) +#endif +/* Sensor data handler task */ +ASF_TASK_STATIC ( SENSOR_ACQ_TASK_ID, SensorAcqTask, osPriorityAboveNormal, 0x400, 64 ) + +/* Additional tasks specific to application is defined in App_Tasks.h */ +#include "app_tasks.h" + + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/asf/asf_taskstruct.h b/embedded/common/asf/asf_taskstruct.h index 1de0c65..df560af 100644 --- a/embedded/common/asf/asf_taskstruct.h +++ b/embedded/common/asf/asf_taskstruct.h @@ -26,6 +26,7 @@ #endif #include +#include "cmsis_os.h" /*-------------------------------------------------------------------------------------------------*\ | T Y P E D E F I N I T I O N S @@ -41,12 +42,12 @@ typedef struct AsfTaskInitDefTag TaskId taskId; void (*entryPoint)(); char *tskName; - OS_ID queue; - uint16_t queueSize; uint16_t stackSize; - uint8_t priority; + int8_t priority; char *tidString; /* String equivalent of the TASK_ID enum */ - + const osThreadDef_t * posThreadDef; + const osMailQDef_t *mailQDef; + const osTimerDef_t *timerDef; } AsfTaskInitDef; diff --git a/embedded/common/asf/asf_tdefmacros.h b/embedded/common/asf/asf_tdefmacros.h index c929227..12f026f 100644 --- a/embedded/common/asf/asf_tdefmacros.h +++ b/embedded/common/asf/asf_tdefmacros.h @@ -1,72 +1,82 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* This file maybe included more than once */ - -/* -** ASF_TASK_DEF_TYPE should be defined to be either -** -** ASF_TASK_IDS -** ASF_QUEUE_IDS -** ASF_STACK_SETUP -** ASF_TASK_SETUP -** ASF_TASK_DECLARE -** -** by the including file -*/ - - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#if !defined (IN_ASF_TASK_DEF) -# error This file can only be included in ASF_TaskDefType.h -#endif - -#if ASF_TASK_DEF_TYPE == ASF_TASK_IDS -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) ThreadId, -#endif - -#if ASF_TASK_DEF_TYPE == ASF_STACK_SETUP -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ - const uint32_t ThreadId##_StkSize = StackSize; -#endif - -#if ASF_TASK_DEF_TYPE == ASF_QUEUE_SETUP -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ - os_mbx_declare( Q_##ThreadId, QueueSize ); -#endif - -#if ASF_TASK_DEF_TYPE == ASF_TASK_DECLARE -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ - extern void EntryFunction(void); -#endif - -#if ASF_TASK_DEF_TYPE == ASF_TASK_SETUP -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ - { ThreadId, EntryFunction, #EntryFunction, Q_##ThreadId, sizeof(Q_##ThreadId), StackSize, Priority, #ThreadId }, -#endif - -#if ASF_TASK_DEF_TYPE == ASF_TOTAL_STACK_NEEDED -# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ - +ThreadId##_StkSize -#endif - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* This file maybe included more than once */ + +/* +** ASF_TASK_DEF_TYPE should be defined to be either +** +** ASF_TASK_IDS +** ASF_QUEUE_IDS +** ASF_STACK_SETUP +** ASF_TASK_SETUP +** ASF_TASK_DECLARE +** +** by the including file +*/ + + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#if !defined (IN_ASF_TASK_DEF) +# error This file can only be included in ASF_TaskDefType.h +#endif + +#if ASF_TASK_DEF_TYPE == ASF_TASK_IDS +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) ThreadId, +#endif + +#if ASF_TASK_DEF_TYPE == ASF_STACK_SETUP +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + const uint32_t ThreadId##_StkSize = StackSize; +#endif + +#if ASF_TASK_DEF_TYPE == ASF_QUEUE_SETUP +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + osMailQDef(ThreadId, QueueSize, MessageBlock); +#endif + +#if ASF_TASK_DEF_TYPE == ASF_TASK_DECLARE +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + extern void EntryFunction(void); +#endif + +#if ASF_TASK_DEF_TYPE == ASF_TASK_SETUP +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + { ThreadId, EntryFunction, #EntryFunction, StackSize, Priority, #ThreadId, osThread(EntryFunction),osMailQ(ThreadId),osTimer(ThreadId)}, +#endif + +#if ASF_TASK_DEF_TYPE == ASF_TOTAL_STACK_NEEDED +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + +ThreadId##_StkSize +#endif + +#if ASF_TASK_DEF_TYPE == ASF_THREAD_SETUP +# define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + osThreadDef(EntryFunction,Priority,1,StackSize); +#endif + +#if ASF_TASK_DEF_TYPE == ASF_TIMER_SETUP +#define ASF_TASK_STATIC( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) \ + osTimerDef(ThreadId, ASFTimerCallback); +#endif + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ + diff --git a/embedded/common/asf/asf_timers.c b/embedded/common/asf/asf_timers.c index 14f8ee7..6ec9a4c 100644 --- a/embedded/common/asf/asf_timers.c +++ b/embedded/common/asf/asf_timers.c @@ -1,253 +1,256 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "common.h" - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#ifndef RAM_START -# define RAM_START NVIC_VectTab_RAM -#endif - -#ifndef OS_TIMERCNT - #define OS_TIMERCNT (8) // Make sure this value matches file rtx_conf_cm.c -#endif -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Maintain the list of registered timer currently running */ -static AsfTimer* _asfTimerList[OS_TIMERCNT]; -/* Indicator if this timer module is initialized once */ -static osp_bool_t _asfTimerInitialized = FALSE; - -/*-------------------------------------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - - -/**************************************************************************************************** - * @fn AsfTimerInit - * Perform one time initialization - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -static void AsfTimerInit(void) -{ - if ( _asfTimerInitialized == FALSE ) { - uint16_t i; - for ( i = 0; i < OS_TIMERCNT; i++ ) { - _asfTimerList[i] = NULL; - } - _asfTimerInitialized = TRUE; - } -} - - -static uint16_t AsfTimerAddTimerToList(AsfTimer *pTimer) -{ - uint16_t i; - - for ( i = 0; i < OS_TIMERCNT; i++ ) { - if ( _asfTimerList[i] == NULL ) { - _asfTimerList[i] = pTimer; - return i; - } - } - - /* Trigger assert. Use too many timers. */ - ASF_assert(FALSE); -} - -static AsfTimer* AsfTimerGetTimerFromList( uint16_t info) -{ - if ( info < OS_TIMERCNT ) - return _asfTimerList[info]; - - return (AsfTimer*)NULL; -} - - -static void AsfTimerRemoveTimerFromList(uint16_t info) -{ - if ( info < OS_TIMERCNT ) { - if( _asfTimerList[info] != NULL ) _asfTimerList[info] = NULL; - } -} - -/**************************************************************************************************** - * @fn SendTimerExpiry - * Sends the timer expiry message to the owner of the timer - * - * @param pTimer Pointer to the timer control block - * - * @return none - * - ***************************************************************************************************/ -static void SendTimerExpiry ( AsfTimer *pTimer ) -{ - MessageBuffer *pSendMsg = NULLP; - - ASF_assert( ASFCreateMessage( MSG_TIMER_EXPIRY, sizeof(MsgTimerExpiry), &pSendMsg ) == ASF_OK ); - pSendMsg->msg.msgTimerExpiry.userValue = pTimer->userValue; - pSendMsg->msg.msgTimerExpiry.timerId = pTimer->timerId; - ASF_assert( ASFSendMessage( pTimer->owner, pSendMsg ) == ASF_OK ); -} - - - -/**************************************************************************************************** - * @fn ASFTimerStart - * Creates a new timer in the system with the given attributes. - * - * @param pTimer Pointer to timer control block containing the attributes of the timer to be - * created. - * - * @return none - * - * @see ASFDeleteTimer() - ***************************************************************************************************/ -static void _TimerStart ( AsfTimer *pTimer, char *_file, int _line ) -{ - if ( _asfTimerInitialized == FALSE ) AsfTimerInit(); - - ASF_assert( pTimer != NULLP ); - ASF_assert( pTimer->sysUse != TIMER_SYS_ID ); //In case we are trying to restart a running timer - - // Add this timer to the managed list - pTimer->info = AsfTimerAddTimerToList(pTimer); - pTimer->sysUse = TIMER_SYS_ID; - pTimer->timerId = os_tmr_create( pTimer->ticks, pTimer->info ); - ASF_assert( pTimer->timerId != NULL ); -} - - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn ASFTimerStarted - * Checks if the timer has already been started - * - * @param pTimer Pointer to timer control block containing the attributes of the timer to be - * created. - * - * @return true - Timer already started; false otherwise - * - * @see ASFTimerStart() - ***************************************************************************************************/ -osp_bool_t ASFTimerStarted ( AsfTimer *pTimer ) -{ - return (pTimer->sysUse == TIMER_SYS_ID? true : false); -} - - -/**************************************************************************************************** - * @fn ASFTimerStart - * Creates a timer with given reference and tick value assigned to the owner. - * - * @param owner Task ID of the task that will receive the expiry message - * @param ref Unique reference number for the timer - * @param tick Tick count in OS ticks - * @param pTimer Pointer to timer type - * - * @return none - * - * @see ASFTimerKill() -***************************************************************************************************/ -void _ASFTimerStart( TaskId owner, uint16_t ref, uint16_t tick, AsfTimer *pTimer, char *_file, int _line ) -{ - pTimer->owner = owner; - pTimer->ticks = tick; - pTimer->userValue = ref; - _TimerStart( pTimer, _file, _line ); -} - - -/**************************************************************************************************** - * @fn ASFTimerExpiry - * Handles the timer expiry by sending message to the task that created the timer - * - * @param info pseudo pointer to timer control block of the timer that expired. - * - * @return none - * - * @see ASFKillTimer() - ***************************************************************************************************/ -void _ASFTimerExpiry ( uint16_t info, char *_file, int _line ) -{ - AsfTimer *pTimer; - int wasMasked = __disable_irq(); - pTimer = AsfTimerGetTimerFromList(info); - - //Look for our magic number to be sure we got the right pointer - ASF_assert_var( pTimer->sysUse == TIMER_SYS_ID, pTimer->ticks, pTimer->userValue, pTimer->owner); - SendTimerExpiry( pTimer ); - pTimer->sysUse = (uint32_t)-1; //Timer no longer in use - AsfTimerRemoveTimerFromList(info); - if (!wasMasked) __enable_irq(); -} - - -/**************************************************************************************************** - * @fn ASFKillTimer - * Kills the timer that was created earlier - * - * @param pTimer Pointer to timer control block containing the attributes of the timer to be - * created. - * - * @return none - * - * @see ASFTimerStart() - ***************************************************************************************************/ -void _ASFKillTimer ( AsfTimer *pTimer, char *_file, int _line ) -{ - TimerId ret; - ASF_assert( pTimer != NULLP ); - ret = os_tmr_kill( pTimer->timerId ); - ASF_assert( ret == NULL ); - pTimer->sysUse = (uint32_t)-1; //Timer no longer in use - AsfTimerRemoveTimerFromList(pTimer->info); -} - - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "common.h" +#include "asf_taskstruct.h" +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#ifndef RAM_START +# define RAM_START NVIC_VectTab_RAM +#endif +extern const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS]; + +#ifndef OS_TIMERCNT + #define OS_TIMERCNT (8) // Make sure this value matches file rtx_conf_cm.c +#endif +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Maintain the list of registered timer currently running */ +static AsfTimer* _asfTimerList[OS_TIMERCNT]; +/* Indicator if this timer module is initialized once */ +static osp_bool_t _asfTimerInitialized = FALSE; + +/*-------------------------------------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + + +/**************************************************************************************************** + * @fn AsfTimerInit + * Perform one time initialization + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +static void __attribute__((unused)) AsfTimerInit(void) +{ + if ( _asfTimerInitialized == FALSE ) { + uint16_t i; + for ( i = 0; i < OS_TIMERCNT; i++ ) { + _asfTimerList[i] = NULL; + } + _asfTimerInitialized = TRUE; + } +} + + +static uint16_t AsfTimerAddTimerToList(AsfTimer *pTimer) +{ + uint16_t i; + + for ( i = 0; i < OS_TIMERCNT; i++ ) { + if ( _asfTimerList[i] == NULL ) { + _asfTimerList[i] = pTimer; + return i; + } + } + + /* Trigger assert. Use too many timers. */ + ASF_assert(FALSE); +} + +static AsfTimer* AsfTimerGetTimerFromList( uint16_t info) +{ + if ( info < OS_TIMERCNT ) + return _asfTimerList[info]; + + return (AsfTimer*)NULL; +} + + +static void AsfTimerRemoveTimerFromList(uint16_t info) +{ + if ( info < OS_TIMERCNT ) { + if( _asfTimerList[info] != NULL ) _asfTimerList[info] = NULL; + } +} + +/**************************************************************************************************** + * @fn SendTimerExpiry + * Sends the timer expiry message to the owner of the timer + * + * @param pTimer Pointer to the timer control block + * + * @return none + * + ***************************************************************************************************/ +static void SendTimerExpiry ( AsfTimer *pTimer ) +{ + MessageBuffer *pSendMsg = NULLP; + + ASF_assert( ASFCreateMessage( MSG_TIMER_EXPIRY, sizeof(MsgTimerExpiry), &pSendMsg ) == ASF_OK ); + pSendMsg->msg.msgTimerExpiry.timerId = (osTimerId)pTimer->timerId; + pSendMsg->msg.msgTimerExpiry.userValue = pTimer->userValue; + __enable_irq(); + ASF_assert( ASFSendMessage( pTimer->owner, pSendMsg ) == ASF_OK ); + __disable_irq(); +} + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/**************************************************************************************************** + * @fn ASFTimerStarted + * Checks if the timer has already been started + * + * @param pTimer Pointer to timer control block containing the attributes of the timer to be + * created. + * + * @return true - Timer already started; false otherwise + * + * @see ASFTimerStart() + ***************************************************************************************************/ +osp_bool_t ASFTimerStarted ( AsfTimer *pTimer ) +{ + return (pTimer->sysUse == TIMER_SYS_ID? true : false); +} + + +/**************************************************************************************************** + * @fn ASFTimerStart + * Creates a timer with given reference and tick value assigned to the owner. + * + * @param owner Task ID of the task that will receive the expiry message + * @param ref Unique reference number for the timer + * @param tick Tick count in OS ticks + * @param pTimer Pointer to timer type + * + * @return none + * + * @see ASFTimerKill() +***************************************************************************************************/ +void _ASFTimerStart( TaskId owner, uint16_t ref, uint16_t tick, AsfTimer *pTimer, char *_file, int _line ) +{ + uint16_t index = AsfTimerAddTimerToList(pTimer); // Add this timer to the managed list + + pTimer->owner = owner; + pTimer->ticks = tick; + pTimer->userValue = ref; + if(pTimer->timerId == NULL) + { + pTimer->timerId = osTimerCreate(C_gAsfTaskInitTable[owner].timerDef,osTimerOnce,(void *)index); + } + if (pTimer->timerId) + { + pTimer->sysUse = TIMER_SYS_ID; + osTimerStart(pTimer->timerId, pTimer->ticks); + } + +} + + +/**************************************************************************************************** + * @fn ASFTimerExpiry + * Handles the timer expiry by sending message to the task that created the timer + * + * @param info pseudo pointer to timer control block of the timer that expired. + * + * @return none + * + * @see ASFKillTimer() + ***************************************************************************************************/ +void _ASFTimerExpiry ( uint32_t info, char *_file, int _line ) +{ + AsfTimer *pTimer; + int wasMasked = __disable_irq(); + pTimer = AsfTimerGetTimerFromList(info); + AsfTimerRemoveTimerFromList(info); + + //Look for our magic number to be sure we got the right pointer + ASF_assert_var( pTimer->sysUse == TIMER_SYS_ID, pTimer->ticks, pTimer->userValue, pTimer->owner); + /* Reset timer before starting to process it. + * This is to prevent a race condition, where the processing task restarts a timer before we reset here. + * Timer thread runs on a lower priority then, the processing task + */ + pTimer->sysUse = (uint32_t)-1; //Timer no longer in use + SendTimerExpiry( pTimer ); + if (!wasMasked) __enable_irq(); +} + + +/**************************************************************************************************** + * @fn ASFKillTimer + * Kills the timer that was created earlier + * + * @param pTimer Pointer to timer control block containing the attributes of the timer to be + * created. + * + * @return none + * + * @see ASFTimerStart() + ***************************************************************************************************/ +void _ASFKillTimer ( AsfTimer *pTimer, char *_file, int _line ) +{ + osStatus os_ret = osErrorOS; + ASF_assert( pTimer != NULLP ); + os_ret = osTimerDelete(pTimer->timerId); + ASF_assert( os_ret == osOK ); + pTimer->sysUse = (uint32_t)-1; //Timer no longer in use + AsfTimerRemoveTimerFromList(pTimer->info); +} +/**************************************************************************************************** + * @fn ASFTimerCallback + * Timer callback registered with CMSIS for timer expiry notification + * + * @param argument Param provided to CMSIS for callback, this is the index used to retrieve the task(owner) info. + * + * @return none + * + * @see ASFTimerExpiry() + ***************************************************************************************************/ +void ASFTimerCallback(void const *argument) +{ + ASFTimerExpiry((uint32_t)argument); +} + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/asf/asf_types.h b/embedded/common/asf/asf_types.h index 669eaea..d141b89 100644 --- a/embedded/common/asf/asf_types.h +++ b/embedded/common/asf/asf_types.h @@ -1,70 +1,70 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if !defined (ASF_TYPES_H) -#define ASF_TYPES_H - -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include -#include "rtl.h" - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* - * Task Handle type. This type is OS-dependent. - */ -typedef struct AsfTaskHandleTag { - OS_TID handle; - void *pStack; - uint16_t stkSize; -} AsfTaskHandle; - -/* - * Semaphore ID type. This type is OS-dependent. - */ -typedef OS_SEM* AsfSemIdType; - -/* - * Timer ID type. This type is OS-dependent. - */ -typedef OS_ID TimerId; - - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ - - -#endif /* ASF_TYPES_H */ -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !defined (ASF_TYPES_H) +#define ASF_TYPES_H + +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include +#include "cmsis_os.h" + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* + * Task Handle type. This type is OS-dependent. + */ +typedef struct AsfTaskHandleTag { + osThreadId posThreadId; + osMailQId posMailQId; + void *pStack; + uint16_t stkSize; +} AsfTaskHandle; + +/* + * Semaphore ID type. This type is OS-dependent. + */ +#define AsfSemIdType(sem) osSemaphoreDef(sem) + +/* + * Timer ID type. This type is OS-dependent. + */ +typedef osTimerId TimerId; + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ + + +#endif /* ASF_TYPES_H */ +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/common/modules/sensor-drivers/BMG160.c b/embedded/common/modules/sensor-drivers/BMG160.c index 4a227bc..f339c7b 100644 --- a/embedded/common/modules/sensor-drivers/BMG160.c +++ b/embedded/common/modules/sensor-drivers/BMG160.c @@ -1,7939 +1,7955 @@ -/* - ***************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - *****************************************************************************/ -/* Date: 2013/05/06 - * Revision: 1.4 - * - */ - -/****************************************************************************** -* Copyright (C) 2007 Bosch Sensortec GmbH -* -* API for BMG160 -* -* Usage: Driver for Gyro Sensor -* -******************************************************************************/ -/*****************************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. They - * may only be used within the parameters of the respective valid product data - * sheet. Bosch Sensortec products are provided with the express understanding - * that there is no warranty of fitness for a particular purpose.They are not - * fit for use in life-sustaining, safety or security sensitive systems or any - * system or device that may lead to bodily harm or property damage if the - * system or device malfunctions. In addition, Bosch Sensortec products are not - * fit for use in products which interact with motor vehicle systems.The resale - * and or use of products are at the purchasers own risk and his own - * responsibility. The examination of fitness for the intended use is the sole - * responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party claims, - * including any claims for incidental, or consequential damages, arising from - * any product use not covered by the parameters of the respective valid product - * data sheet or not approved by Bosch Sensortec and reimburse Bosch - * Sensortec for all costs in connection with such claims. - * - * The purchaser must monitor the market for the purchased products, - * particularly with regard to product safety and inform Bosch Sensortec without - * delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary - * from the valid technical specifications of the product series. They are - * therefore not intended or fit for resale to third parties or for use in end - * products. Their sole purpose is internal client testing. The testing of an - * engineering sample may in no way replace the testing of a product series. - * Bosch Sensortec assumes no liability for the use of engineering samples. By - * accepting the engineering samples, the Purchaser agrees to indemnify Bosch - * Sensortec from all claims arising from the use of engineering samples. - * - * Special: - * This software module (hereinafter called "Software") and any information on - * application-sheets (hereinafter called "Information") is provided free of - * charge for the sole purpose to support your application work. The Software - * and Information is subject to the following terms and conditions: - * - * The Software is specifically designed for the exclusive use for Bosch - * Sensortec products by personnel who have special experience and training. - * Do not use this Software if you do not have the proper experience or - * training. - * - * This Software package is provided `` as is `` and without any expressed or - * implied warranties, including without limitation, the implied warranties of - * merchantability and fitness for a particular purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability for - * the functional impairment of this Software in terms of fitness, performance - * and safety. Bosch Sensortec and their representatives and agents shall not be - * liable for any direct or indirect damages or injury, except as otherwise - * stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. Bosch - * Sensortec assumes no responsibility for the consequences of use of such - * Information nor for any infringement of patents or other rights of third - * parties which may result from its use. No license is granted by implication - * or otherwise under any patent or patent rights of Bosch. Specifications - * mentioned in the Information are subject to change without notice. - * - * It is not allowed to deliver the source code of the Software to any third - * party without permission of Bosch Sensortec. - */ -/*****************************************************************************/ -/*! \file BMG160.c - \brief Driver for BMG160 */ -#include "bmg160.h" -#include "sensorhub.h" -#include "common.h" -#include "board.h" -#include "gyro_common.h" -#include "osp-sensors.h" -#include "sensacq_i2c.h" - -static struct bmg160_t *p_bmg160 = NULL; -static struct bmg160_t bmg160; - -static void gyro_get_chip_id(uint8_t *chipId) -{ - if ( p_bmg160 == NULL ) - return; - - /*Read CHIP_ID */ - p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_CHIP_ID_ADDR, chipId, 1); -} - -static void gyro_activate(bool enable) -{ - if (enable) { - bmg160_set_mode(BMG160_MODE_NORMAL); - bmg160_set_int_od(BMG160_INT1, 0); - bmg160_set_int_lvl(BMG160_INT1, 1); - bmg160_set_int_data(BMG160_INT1_DATA, 1); - bmg160_set_latch_int(7); - bmg160_set_data_en(1); - - /* Read to clear device */ - Gyro_ReadData(NULL); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(GYRO_PINT_IRQn); - NVIC_ClearPendingIRQ(GYRO_PINT_IRQn); - } - else { - bmg160_set_data_en(0); - NVIC_DisableIRQ(GYRO_PINT_IRQn); - bmg160_set_mode(BMG160_MODE_FASTPOWERUP); - - NVIC_DisableIRQ(GYRO_PINT_IRQn); - } - - /* ##KW## Optimized register write function? */ -} - -void Gyro_HardwareSetup(osp_bool_t enable) -{ - NVIC_DisableIRQ(GYRO_PINT_IRQn); - NVIC_SetPriority(GYRO_PINT_IRQn, SENSOR_IRQ_PRIORITY); - Chip_GPIO_SetPinDIRInput(LPC_GPIO, GYRO_INT_PORT, GYRO_INT_PIN); - Chip_INMUX_PinIntSel(GYRO_PINT_SEL,GYRO_INT_PORT, GYRO_INT_PIN); - Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH); - Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH); - Chip_SYSCON_EnableWakeup(GYRO_WAKE); -} - -void Gyro_Initialize(void) -{ - bmg160.bus_write = dev_i2c_write; - bmg160.bus_read = dev_i2c_read; - bmg160.delay_msec = dev_i2c_delay; - - bmg160_init(&bmg160); - - /* Reset all registers default setting */ - // QLY: Comment from bosch that doing a software reset cause SDA stay low forever! -// bmg160_set_soft_reset(); -// dev_i2c_delay(200); - - /* Get CHIP ID */ - gyro_get_chip_id( &bmg160.chip_id); - - D0_printf("Gyro Chip ID = 0x%x\r\n", bmg160.chip_id); - - dev_i2c_delay(10); - bmg160_set_mode(BMG160_MODE_NORMAL); - //dev_i2c_delay(10); - /* gyro_SetInterval(pSens,10); */ - bmg160_set_bw(C_BMG160_BW_32Hz_U8X); // BW = 32Hz, ODR = 100Hz - - //dev_i2c_delay(200); - bmg160_set_range_reg(C_BMG160_Zero_U8X); /* Zero = 2000 dps */ - //dev_i2c_delay(200); - - gyro_activate(true); - //dev_i2c_delay(200); - -} - -void Gyro_ConfigDataInt(osp_bool_t enable) -{ - if (enable) { - bmg160_set_mode(BMG160_MODE_NORMAL); - bmg160_set_int_od(BMG160_INT1, 0); - bmg160_set_int_lvl(BMG160_INT1, 1); - bmg160_set_int_data(BMG160_INT1_DATA, 1); - bmg160_set_latch_int(7); - bmg160_set_data_en(1); - - /* Read to clear device */ - Gyro_ClearDataInt(); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(GYRO_PINT_IRQn); - } else { - bmg160_set_data_en(0); - NVIC_DisableIRQ(GYRO_PINT_IRQn); - bmg160_set_mode(BMG160_MODE_FASTPOWERUP); - - //NVIC_DisableIRQ(GYRO_PINT_IRQn); - } - - /* ##KW## Optimized register write function? */ -} - -void Gyro_ClearDataInt(void) -{ - /* Read to clear any pending interrupt */ - Gyro_ReadData(NULL); -} - -void Gyro_ReadData(MsgGyroData *gyroData) -{ - struct bmg160_data_t data; - - /* Uses Bosch library functions for sensor data read */ - /* ##KW## Read counts or diffs? */ - bmg160_get_dataXYZ(&data); - - if (gyroData) { - gyroData->X = (int16_t) data.datax; - gyroData->Y = (int16_t) data.datay; - gyroData->Z = (int16_t) data.dataz; - } -} - -void GYRO_IRQHandler(void) -{ - uint32_t currTime = GetCurrentTime(); -#if 0 - PhysicalSensor_t* pSens = g_phySensors[PHYS_GYRO_ID]; - uint32_t currTime = g_Timer.GetCurrent(); - pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; - pSens->ts_lastSample = currTime; - - pSens->irq_pending++; - Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH); - ResMgr_IRQDone(); -#else - Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH); - SendDataReadyIndication(GYRO_INPUT_SENSOR, currTime); -#endif -} - -/***************************************************************************** -* Description: *//**\brief API Initialization routine -* -* -* -* -* \param bmg160_t *bmg160 -* Pointer to a structure. -* -* structure members are -* -* unsigned char chip_id; -* unsigned char dev_addr; -* BMG160_BRD_FUNC_PTR; -* BMG160_WR_FUNC_PTR; -* BMG160_RD_FUNC_PTR; -* void(*delay_msec)( BMG160_MDELAY_DATA_TYPE ); -* -* -* -* -* -* \return result of communication routines -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_init(struct bmg160_t *bmg160) -{ - BMG160_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r; - p_bmg160 = bmg160; - - p_bmg160->dev_addr = BMG160_I2C_ADDR; - -#if 0 - /*Read CHIP_ID */ - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_CHIP_ID_ADDR, &a_data_u8r, 1); - p_bmg160->chip_id = a_data_u8r; -#endif - - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads Rate dataX from location 02h and 03h -* registers -* -* -* -* -* \param -* BMG160_S16 *data_x : Address of data_x -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataX(BMG160_S16 *data_x) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[2]; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 2); - a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ - BMG160_RATE_X_LSB_VALUEX); - *data_x = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[1])) << \ - BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads rate dataY from location 04h and 05h -* registers -* -* -* -* -* \param -* BMG160_S16 *data_y : Address of data_y -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataY(BMG160_S16 *data_y) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[2]; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATE_Y_LSB_VALUEY__REG, a_data_u8r, 2); - a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ - BMG160_RATE_Y_LSB_VALUEY); - *data_y = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ - << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads rate dataZ from location 06h and 07h -* registers -* -* -* -* -* \param -* BMG160_S16 *data_z : Address of data_z -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataZ(BMG160_S16 *data_z) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[2]; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATE_Z_LSB_VALUEZ__REG, a_data_u8r, 2); - a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ - BMG160_RATE_Z_LSB_VALUEZ); - *data_z = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ - << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads data X,Y and Z from location 02h to 07h -* -* -* -* -* \param -* bmg160_data_t *data : Address of bmg160_data_t -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZ(struct bmg160_data_t *data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[6]; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, - BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 6); - /* Data X */ - a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], BMG160_RATE_X_LSB_VALUEX); - - data->datax = (BMG160_S16) (((BMG160_U16) a_data_u8r[1] << BMG160_RATE_X_LSB_VALUEX__LEN) | - a_data_u8r[0]); - /* Data Y */ - - a_data_u8r[2] = BMG160_GET_BITSLICE(a_data_u8r[2], BMG160_RATE_Y_LSB_VALUEY); - - data->datay = (BMG160_S16) (((BMG160_U16) a_data_u8r[3] << BMG160_RATE_Y_LSB_VALUEY__LEN) | - a_data_u8r[2]); - /* Data Z */ - a_data_u8r[4] = BMG160_GET_BITSLICE(a_data_u8r[4], BMG160_RATE_Z_LSB_VALUEZ); - data->dataz = (BMG160_S16) (((BMG160_U16) a_data_u8r[5] << BMG160_RATE_Z_LSB_VALUEZ__LEN) | - a_data_u8r[4]); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads data X,Y,Z and Interrupts -* from location 02h to 07h -* -* -* -* -* \param -* bmg160_data_t *data : Address of bmg160_data_t -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZI(struct bmg160_data_t *data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[12]; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 12); - /* Data X */ - a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ - BMG160_RATE_X_LSB_VALUEX); - data->datax = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ - << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); - /* Data Y */ - a_data_u8r[2] = BMG160_GET_BITSLICE(a_data_u8r[2], \ - BMG160_RATE_Y_LSB_VALUEY); - data->datay = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[3])) \ - << BMG160_SHIFT_8_POSITION) | (a_data_u8r[2])); - /* Data Z */ - a_data_u8r[4] = BMG160_GET_BITSLICE(a_data_u8r[4], \ - BMG160_RATE_Z_LSB_VALUEZ); - data->dataz = (BMG160_S16) \ - ((((BMG160_S16) ((signed char) a_data_u8r[5])) \ - << BMG160_SHIFT_8_POSITION) | (a_data_u8r[4])); - data->intstatus[0] = a_data_u8r[7]; - data->intstatus[1] = a_data_u8r[8]; - data->intstatus[2] = a_data_u8r[9]; - data->intstatus[3] = a_data_u8r[10]; - data->intstatus[4] = a_data_u8r[11]; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads Temperature from location 08h -* -* -* -* -* \param -* unsigned char *temp : Address of temperature -* -* -* \return -* result of communication routines -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_Temperature(unsigned char *temperature) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TEMP_ADDR, &v_data_u8r, 1); - *temperature = v_data_u8r; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the data from the given register -* -* -* -* -* \param unsigned char addr, unsigned char *data unsigned char len -* addr -> Address of the register -* data -> address of the variable, read value will be -* kept -* len -> No of byte to be read. -* \return results of bus communication function -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_read_register(unsigned char addr, \ - unsigned char *data, unsigned char len) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, addr, data, len); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the data from the given register -* -* -* -* -* \param unsigned char addr, unsigned char *data BMG160_S32 len -* addr -> Address of the register -* data -> address of the variable, read value will be -* kept -* len -> No of byte to be read. -* \return results of bus communication function -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_burst_read(unsigned char addr, \ - unsigned char *data, BMG160_S32 len) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BURST_READ_FUNC(p_bmg160->dev_addr, \ - addr, data, len); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API given data to the given register -* -* -* -* -* \param unsigned char addr, unsigned char data,unsigned char len -* addr -> Address of the register -* data -> Data to be written to the register -* len -> No of byte to be read. -* -* \return Results of bus communication function -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_write_register(unsigned char addr, \ - unsigned char *data, unsigned char len) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, addr, data, len); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt status 0 register byte from 09h -* -* -* -* -* \param -* unsigned char *status0_data : Address of status 0 register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_0( \ - unsigned char *status0_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_STATUSZERO__REG, &v_data_u8r, 1); - *status0_data = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSZERO); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt status 1 register byte from 0Ah -* -* -* -* -* \param -* unsigned char *status1_data : Address of status register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_1( \ - unsigned char *status1_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, BMG160_INT_STATUSONE__REG, \ - &v_data_u8r, 1); - *status1_data = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSONE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt status register byte from 0Bh -* -* -* -* -* \param -* unsigned char *status2_data : Address of status 2 register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_2( \ - unsigned char *status2_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_STATUSTWO__REG, &v_data_u8r, 1); - *status2_data = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSTWO); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt status 3 register byte from 0Ch -* -* -* -* -* \param -* unsigned char *status3_data : Address of status 3 register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_3( \ - unsigned char *status3_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_STATUSTHREE__REG, &v_data_u8r, 1); - *status3_data = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSTHREE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the range from register 0x0Fh of -* (0 to 2) bits -* -* -* -* -* \param unsigned char *range -* Range[0....7] -* 0 2000/s -* 1 1000/s -* 2 500/s -* 3 250/s -* 4 125/s -* -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_range_reg(unsigned char *range) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); - *range = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_RANGE_ADDR_RANGE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API sets the range register 0x0Fh -* (0 to 2 bits) -* -* -* -* -* \param unsigned char range -* -* Range[0....7] -* 0 2000/s -* 1 1000/s -* 2 500/s -* 3 250/s -* 4 125/s -* -* -* -* -* \return Communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_range_reg(unsigned char range) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (range < C_BMG160_Five_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RANGE_ADDR_RANGE, \ - range); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the high resolution bit of 0x10h -* Register 7th bit -* -* -* -* -* \param unsigned char *high_res -* Pointer to a variable passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_res(unsigned char *high_res) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BW_ADDR_HIGH_RES__REG, &v_data_u8r, 1); - *high_res = \ - BMG160_GET_BITSLICE(v_data_u8r, BMG160_BW_ADDR_HIGH_RES); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the bandwidth register of 0x10h 0 to -* 3 bits -* -* -* -* -* \param unsigned char *bandwidth -* pointer to a variable passed as a parameter -* -* 0 no filter(523 Hz) -* 1 230Hz -* 2 116Hz -* 3 47Hz -* 4 23Hz -* 5 12Hz -* 6 64Hz -* 7 32Hz -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_bw(unsigned char *bandwidth) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, BMG160_BW_ADDR__REG, &v_data_u8r, 1); - *bandwidth = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_BW_ADDR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API writes the Bandwidth register (0x10h of 0 -* to 3 bits) -* -* -* -* -* \param unsigned char bandwidth, -* The bandwidth to be set passed as a parameter -* -* 0 no filter(523 Hz) -* 1 230Hz -* 2 116Hz -* 3 47Hz -* 4 23Hz -* 5 12Hz -* 6 64Hz -* 7 32Hz -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_bw(unsigned char bandwidth) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - unsigned char v_mode_u8r; - unsigned char v_autosleepduration; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (bandwidth < C_BMG160_Eight_U8X) { - bmg160_get_mode(&v_mode_u8r); - if (v_mode_u8r == BMG160_MODE_ADVANCEDPOWERSAVING) { - bmg160_get_autosleepdur(&v_autosleepduration); - bmg160_set_autosleepdur(v_autosleepduration, \ - bandwidth); - } - dev_i2c_delay(20); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BW_ADDR__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_BW_ADDR, bandwidth); - dev_i2c_delay(20); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BW_ADDR__REG, &v_data_u8r, 1); - dev_i2c_delay(20); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the status of External Trigger -* selection bits (4 and 5) of 0x12h registers -* -* -* -* -* \param unsigned char *pwu_ext_tri_sel -* Pointer to a variable passed as a parameter -* -* -* -* \return Communication Results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_pmu_ext_tri_sel( \ - unsigned char *pwu_ext_tri_sel) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); - *pwu_ext_tri_sel = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API writes the External Trigger selection -* bits (4 and 5) of 0x12h registers -* -* -* -* -* \param unsigned char pwu_ext_tri_sel -* Value to be written passed as a parameter -* -* -* -* \return Communication Results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_pmu_ext_tri_sel( \ - unsigned char pwu_ext_tri_sel) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL, pwu_ext_tri_sel); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get data high bandwidth -* -* -* -* -* \param unsigned char *high_bw : Address of high_bw -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_bw(unsigned char *high_bw) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, &v_data_u8r, 1); - *high_bw = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_RATED_HBW_ADDR_DATA_HIGHBW); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set data high bandwidth -* -* -* -* -* \param unsigned char high_bw: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_bw(unsigned char high_bw) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (high_bw < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RATED_HBW_ADDR_DATA_HIGHBW, high_bw); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, \ - &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get shadow dis -* -* -* -* -* \param unsigned char *shadow_dis : Address of shadow_dis -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_shadow_dis(unsigned char *shadow_dis) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); - *shadow_dis = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_RATED_HBW_ADDR_SHADOW_DIS); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set shadow dis -* -* -* -* -* \param unsigned char shadow_dis -* Value to be written passed as a parameter -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_shadow_dis(unsigned char shadow_dis) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (shadow_dis < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RATED_HBW_ADDR_SHADOW_DIS, shadow_dis); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief -* This function is used for the soft reset -* The soft reset register will be written with 0xB6. -* -* -* -* \param None -* -* -* -* \return Communication results. -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_soft_reset() -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_SoftReset_u8r; - v_SoftReset_u8r = 0xB6; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_BGW_SOFTRESET_ADDR, &v_SoftReset_u8r, 1); - } - - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get data enable data -* -* -* -* -* \param unsigned char *data_en : Address of data_en -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_data_enable(unsigned char *data_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); - *data_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_DATAEN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set data enable data -* -* -* -* -* \param unsigned char data_en: -* Value to be written passed as a parameter -* 0 --> Disable -* 1 --> Enable -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_data_en(unsigned char data_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_DATAEN, data_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get fifo enable bit -* -* -* -* -* \param unsigned char *fifo_en : Address of fifo_en -* Pointer to a variable passed as a parameter - -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_enable(unsigned char *fifo_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); - *fifo_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_FIFOEN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set fifo enable bit -* -* -* -* -* \param unsigned char fifo_en: -* Value to be written passed as a parameter -* 0 --> Disable -* 1 --> Enable -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_enable(unsigned char fifo_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (fifo_en < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_FIFOEN, fifo_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API reads the status of the Auto offset -* Enable bit -* (0x15 Reg 3rd Bit) -* -* -* -* -* \param unsigned char *offset_en -* address of a variable, -* -* -* -* \return Communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_auto_offset_en( \ - unsigned char *offset_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); - *offset_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_AUTO_OFFSETEN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API sets the Auto offset enable bit -* (Reg 0x15 3rd Bit) -* -* -* -* -* \param unsigned char offset_en -* 0 --> Disable -* 1 --> Enable -* -* \return Communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_auto_offset_en(unsigned char offset_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE0_AUTO_OFFSETEN, offset_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the output type status -* -* -* -* -* \param unsigned char channel,unsigned char *int_od -* BMG160_INT1 -> 0 -* BMG160_INT2 -> 1 -* int_od : open drain -> 1 -* push pull -> 0 -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_od(unsigned char param, \ - unsigned char *int_od) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_INT1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); - *int_od = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT1_OD); - break; - - case BMG160_INT2: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); - *int_od = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT2_OD); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the output type status -* -* -* -* -* \param unsigned char channel,unsigned char *int_od -* BMG160_INT1 -> 0 -* BMG160_INT2 -> 1 -* int_od : open drain -> 1 -* push pull -> 0 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_od(unsigned char param, \ - unsigned char int_od) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_INT1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT1_OD, int_od); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); - break; - - case BMG160_INT2: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT2_OD, int_od); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Active Level status -* -* -* -* -* \param unsigned char channel,unsigned char *int_lvl -* BMG160_INT1 -> 0 -* BMG160_INT2 -> 1 -* int_lvl : Active HI -> 1 -* Active LO -> 0 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_lvl(unsigned char param, \ - unsigned char *int_lvl) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_INT1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); - *int_lvl = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT1_LVL); - break; - - case BMG160_INT2: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); - *int_lvl = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT2_LVL); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Active Level status -* -* -* -* -* \param unsigned char channel,unsigned char *int_lvl -* BMG160_INT1 -> 0 -* BMG160_INT2 -> 1 -* int_lvl : Active HI -> 1 -* Active LO -> 0 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_lvl(unsigned char param, \ - unsigned char int_lvl) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_INT1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT1_LVL, int_lvl); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); - break; - - case BMG160_INT2: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_ENABLE1_IT2_LVL, int_lvl); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get High Interrupt1 -* -* -* -* -* \param unsigned char *int1_high : Address of high_bw -* Pointer to a variable passed as a parameter - -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_high(unsigned char *int1_high) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); - *int1_high = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_0_INT1_HIGH); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set High Interrupt1 -* -* -* -* -* \param unsigned char int1_high -* 0 -> Disable -* 1 -> Enable -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_high(unsigned char int1_high) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_0_INT1_HIGH, int1_high); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Any Interrupt1 -* -* -* -* -* \param unsigned char *int1_any : Address of high_bw -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_any(unsigned char *int1_any) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); - *int1_any = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_0_INT1_ANY); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Any Interrupt1 -* -* -* -* -* \param unsigned char int1_any -* 0 -> Disable -* 1 -> Enable -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_any(unsigned char int1_any) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_0_INT1_ANY, int1_any); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get data Interrupt1 and data -* Interrupt2 -* -* -* -* -* \param unsigned char axis,unsigned char *int_data -* axis : -* BMG160_INT1_DATA -> 0 -* BMG160_INT2_DATA -> 1 -* int_data : -* Disable -> 0 -* Enable -> 1 -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_data(unsigned char axis, \ - unsigned char *int_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_INT1_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); - *int_data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_DATA); - break; - - case BMG160_INT2_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); - *int_data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_DATA); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set data Interrupt1 and data -* Interrupt2 -* -* -* -* -* \param unsigned char axis,unsigned char *int_data -* axis : -* BMG160_INT1_DATA -> 0 -* BMG160_INT2_DATA -> 1 -* int_data : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_data(unsigned char axis, \ - unsigned char int_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_INT1_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_DATA, int_data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); - break; - - case BMG160_INT2_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_DATA, int_data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get fast offset and auto -* offset Interrupt2 -* -* -* -* -* \param unsigned char axis,unsigned char *int2_offset -* axis : -* BMG160_AUTO_OFFSET -> 1 -* BMG160_FAST_OFFSET -> 2 -* int2_offset : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_offset(unsigned char axis, \ - unsigned char *int2_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); - *int2_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_FAST_OFFSET); - break; - - case BMG160_AUTO_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); - *int2_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_AUTO_OFFSET); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set fast offset and auto -* offset Interrupt2 -* -* -* -* -* \param unsigned char axis,unsigned char *int2_offset -* axis : -* BMG160_AUTO_OFFSET -> 1 -* BMG160_FAST_OFFSET -> 2 -* int2_offset : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_offset(unsigned char axis, \ - unsigned char int2_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_FAST_OFFSET, int2_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); - break; - - case BMG160_AUTO_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_AUTO_OFFSET, int2_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get fast offset and auto -* offset Interrupt1 -* -* -* -* -* \param unsigned char axis,unsigned char *int1_offset -* axis : -* BMG160_AUTO_OFFSET -> 1 -* BMG160_FAST_OFFSET -> 2 -* int2_offset : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_offset(unsigned char axis, \ - unsigned char *int1_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); - *int1_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_FAST_OFFSET); - break; - - case BMG160_AUTO_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); - *int1_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_AUTO_OFFSET); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set fast offset and auto -* offset Interrupt1 -* -* -* -* -* \param unsigned char axis,unsigned char *int1_offset -* axis : -* BMG160_AUTO_OFFSET -> 1 -* BMG160_FAST_OFFSET -> 2 -* int2_offset : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_offset(unsigned char axis, \ - unsigned char int1_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_FAST_OFFSET, int1_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); - break; - - case BMG160_AUTO_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_AUTO_OFFSET, int1_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get status of FIFO Interrupt -* -* -* -* -* \param unsigned char *int_fifo : Address of int_fifo -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_fifo(unsigned char *int_fifo) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_STATUS1_FIFO_INT__REG, &v_data_u8r, 1); - *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_STATUS1_FIFO_INT); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get FIFO Interrupt2 -* -* -* -* -* \param unsigned char *int_fifo -* int_fifo : -* Disable -> 0 -* Enable -> 1 -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_fifo(unsigned char *int_fifo) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); - *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_FIFO); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get FIFO Interrupt1 -* -* -* -* -* \param unsigned char *int_fifo -* int_fifo : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_fifo(unsigned char *int_fifo) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); - *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_FIFO); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_fifo(unsigned char axis, \ - unsigned char int_fifo) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_INT1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_FIFO, int_fifo); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); - break; - - case BMG160_INT2: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_FIFO, int_fifo); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set FIFO Interrupt1 -* -* -* -* -* \param unsigned char *fifo_int1 -* fifo_int1 : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_fifo(unsigned char fifo_int1) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (fifo_int1 < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT1_FIFO, fifo_int1); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set FIFO Interrupt2 -* -* -* -* -* \param unsigned char *fifo_int2 -* fifo_int2 : -* Disable -> 0 -* Enable -> 1 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_fifo(unsigned char fifo_int2) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (fifo_int2 < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MAP_1_INT2_FIFO, fifo_int2); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get High Interrupt2 -* -* -* -* -* \param unsigned char *int2_high : Address of int2_high -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_high(unsigned char *int2_high) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); - *int2_high = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_2_INT2_HIGH); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get High Interrupt2 -* -* -* -* -* \param unsigned char int2_high -* 0 -> Disable -* 1 -> Enable -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_high(unsigned char int2_high) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_2_INT2_HIGH, int2_high); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Any Interrupt2 -* -* -* -* -* \param unsigned char *int2_any : Address of int2_any -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_any(unsigned char *int2_any) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); - *int2_any = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_2_INT2_ANY); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Any Interrupt2 -* -* -* -* -* \param unsigned char int2_any -* 0 -> Disable -* 1 -> Enable -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_any(unsigned char int2_any) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_MAP_2_INT2_ANY, int2_any); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get slow offset and fast -* offset unfilt data -* -* -* -* \param unsigned char param,unsigned char *offset_unfilt -* param : -* BMG160_SLOW_OFFSET -> 0 -* BMG160_FAST_OFFSET -> 2 -* offset_unfilt: Enable -> 1 -* Disable -> 0 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_unfilt(unsigned char param, \ - unsigned char *offset_unfilt) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_SLOW_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - *offset_unfilt = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT); - break; - - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - *offset_unfilt = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set slow offset and fast -* offset unfilt data -* -* -* -* -* \param unsigned char param,unsigned char *offset_unfilt -* param : -* BMG160_SLOW_OFFSET -> 0 -* BMG160_FAST_OFFSET -> 2 -* offset_unfilt: Enable -> 1 -* Disable -> 0 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_unfilt(unsigned char param, \ - unsigned char offset_unfilt) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_SLOW_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT, offset_unfilt); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - break; - - case BMG160_FAST_OFFSET: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT, offset_unfilt); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ - &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Tap, High, Constant, Any, -* Shake unfilt data -* -* -* -* -* \param unsigned char param,unsigned char *unfilt_data -* param : -* -* BMG160_HIGH_UNFILT_DATA -> 1 -* BMG160_ANY_UNFILT_DATA -> 3 -* -* unfilt_data: Enable -> 1 -* Disable -> 0 -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_unfilt_data(unsigned char param, \ - unsigned char *unfilt_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_HIGH_UNFILT_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ - &v_data_u8r, 1); - *unfilt_data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_HIGH_UNFILT_DATA); - break; - - case BMG160_ANY_UNFILT_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); - *unfilt_data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_ANY_UNFILT_DATA); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Tap, High, Constant, Any, -* Shake unfilt data -* -* -* -* -* \param unsigned char param,unsigned char *unfilt_data -* param : -* -* BMG160_HIGH_UNFILT_DATA -> 1 -* BMG160_ANY_UNFILT_DATA -> 3 -* -* unfilt_data: Enable -> 1 -* Disable -> 0 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_unfilt_data(unsigned char param, \ - unsigned char unfilt_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_HIGH_UNFILT_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_HIGH_UNFILT_DATA, unfilt_data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ - &v_data_u8r, 1); - break; - - case BMG160_ANY_UNFILT_DATA: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_0_ADDR_ANY_UNFILT_DATA, unfilt_data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Any Threshold -* -* -* -* -* \param unsigned char *any_th : Address of any_th -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_th(unsigned char *any_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); - *any_th = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_1_ADDR_ANY_TH); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Any Threshold -* -* -* -* -* \param unsigned char any_th: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_th(unsigned char any_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_1_ADDR_ANY_TH, any_th); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Awake Duration -* -* -* -* -* \param unsigned char *awake_dur : Address of awake_dur -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_awake_dur(unsigned char *awake_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); - *awake_dur = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_AWAKE_DUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Awake Duration -* -* -* -* -* \param unsigned char awake_dur: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -***************************************************************************** -* Scheduling: -* -* -* -* Usage guide: -* -* -* Remarks: -* -*****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_awake_dur(unsigned char awake_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_AWAKE_DUR, awake_dur); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Any Duration Sample -* -* -* -* -* \param unsigned char *dursample : Address of dursample -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_dursample(unsigned char *dursample) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); - *dursample = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_DURSAMPLE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Any Duration Sample -* -* -* -* -* \param unsigned char dursample: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_dursample(unsigned char dursample) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_DURSAMPLE, dursample); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of Any Enable -* Channel X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *data -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* data : -* Enable -> 1 -* disable -> 0 -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_en_ch(unsigned char channel, \ - unsigned char *data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); - *data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_X); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); - *data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_Y); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); - *data = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_Z); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of Any Enable -* Channel X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *data -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* data : -* Enable -> 1 -* disable -> 0 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_en_ch(unsigned char channel, \ - unsigned char data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_X, data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_Y, data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_2_ADDR_ANY_EN_Z, data); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of FIFO WM -* Enable -* -* -* -* -* \param unsigned char *fifo_wn_en -* Enable -> 1 -* Disable -> 0 -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermark_enable( \ - unsigned char *fifo_wn_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); - *fifo_wn_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_INT_4_FIFO_WM_EN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set FIFO WM Enable -* -* -* -* -* \param unsigned char *fifo_wn_en -* Enable -> 1 -* Disable -> 0 -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermark_enable( \ - unsigned char fifo_wn_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (fifo_wn_en < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_INT_4_FIFO_WM_EN, fifo_wn_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the Interrupt Reset -* -* -* -* -* \param unsigned char reset_int -* 1 -> Reset All Interrupts -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_reset_int(unsigned char reset_int) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_RESET_INT__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_RESET_INT, reset_int); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_RESET_INT__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the Offset Reset -* -* -* -* -* \param unsigned char offset_reset -* 1 -> Resets All the Offsets -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_reset( \ - unsigned char offset_reset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_OFFSET_RESET__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_OFFSET_RESET, offset_reset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_OFFSET_RESET__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the Latch Status -* -* -* -* -* \param unsigned char *latch_status : Address of latch_status -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_status( \ - unsigned char *latch_status) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); - *latch_status = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_LATCH_STATUS); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the Latch Status -* -* -* -* -* \param unsigned char latch_status: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_status( \ - unsigned char latch_status) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_LATCH_STATUS, latch_status); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the Latch Interrupt -* -* -* -* -* \param unsigned char *latch_int : Address of latch_int -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_int(unsigned char *latch_int) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); - *latch_int = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_LATCH_INT); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the Latch Interrupt -* -* -* -* -* \param unsigned char latch_int: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_int(unsigned char latch_int) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_RST_LATCH_ADDR_LATCH_INT, latch_int); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of High -* Hysteresis X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_hy -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_hy : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_hy(unsigned char channel, \ - unsigned char *high_hy) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); - *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_X); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); - *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_Y); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); - *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_Z); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of High -* Hysteresis X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_hy -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_hy : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_hy(unsigned char channel, \ - unsigned char high_hy) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_X, high_hy); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_Y, high_hy); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_HY_Z, high_hy); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of High -* Threshold X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_th -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_th : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_th(unsigned char channel, \ - unsigned char *high_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); - *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_X); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); - *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_Y); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); - *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_Z); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of High -* Threshold X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_th -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_th : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_th(unsigned char channel, \ - unsigned char high_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_X, high_th); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_Y, high_th); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_TH_Z, high_th); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of High Enable -* Channel X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_en -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_en : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_en_ch(unsigned char channel, \ - unsigned char *high_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); - *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_X); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); - *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_Y); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); - *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_Z); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of High Enable -* Channel X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *high_en -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_en : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_en_ch(unsigned char channel, \ - unsigned char high_en) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_X, high_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_Y, high_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_HIGH_EN_Z, high_en); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get High Duration -* -* -* -* -* \param unsigned char channel,unsigned char *high_dur -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* *high_dur : Address of high_bw -* Pointer to a variable passed as a -* parameter -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_dur_ch(unsigned char channel, \ - unsigned char *high_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_X_ADDR, &v_data_u8r, 1); - *high_dur = v_data_u8r; - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_Y_ADDR, &v_data_u8r, 1); - *high_dur = v_data_u8r; - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_Z_ADDR, &v_data_u8r, 1); - *high_dur = v_data_u8r; - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set High Duration -* -* -* -* -* \param unsigned char channel,unsigned char *high_dur -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* high_dur : Value to be written passed as a parameter -* -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_dur_ch(unsigned char channel, \ - unsigned char high_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - v_data_u8r = high_dur; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_X_ADDR, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - v_data_u8r = high_dur; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_Y_ADDR, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - v_data_u8r = high_dur; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_HIGH_DUR_Z_ADDR, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Slow Offset Threshold -* -* -* -* -* \param unsigned char *offset_th : Address of offset_th -* Pointer to a variable passed as a parameter - -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_th( \ - unsigned char *offset_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); - *offset_th = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_TH); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Slow Offset Threshold -* -* -* -* -* \param unsigned char offset_th: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_th(unsigned char offset_th) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_TH, offset_th); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Slow Offset Duration -* -* -* -* -* \param unsigned char *offset_dur : Address of offset_dur -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_dur( \ - unsigned char *offset_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); - *offset_dur = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_DUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Slow Offset Duration -* -* -* -* -* \param unsigned char offset_dur: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_dur( \ - unsigned char offset_dur) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_DUR, offset_dur); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Slow Offset Enable channel -* X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *slow_offset -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* slow_offset : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_en_ch( \ - unsigned char channel, unsigned char *slow_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); - *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_X); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); - *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_Y); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); - *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_Z); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Slow Offset Enable channel -* X,Y,Z -* -* -* -* -* \param unsigned char channel,unsigned char *slow_offset -* channel : -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* slow_offset : -* Enable -> 1 -* disable -> 0 -* -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_en_ch( \ - unsigned char channel, unsigned char slow_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_X, slow_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_Y, slow_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_SLOW_OFFSET_EN_Z, \ - slow_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Fast Offset WordLength and -* Auto Offset WordLength -* -* -* -* -* \param unsigned char channel,unsigned char *offset_wl -* channel : -* BMG160_AUTO_OFFSET_WL -> 0 -* BMG160_FAST_OFFSET_WL -> 1 -* *offset_wl : Address of high_bw -* Pointer to a variable passed as a -* parameter -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_wl(unsigned char channel, \ - unsigned char *offset_wl) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_AUTO_OFFSET_WL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); - *offset_wl = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_AUTO_OFFSET_WL); - break; - - case BMG160_FAST_OFFSET_WL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); - *offset_wl = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_WL); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Fast Offset WordLength and -* Auto Offset WordLength -* -* -* -* -* \param unsigned char channel,unsigned char *offset_wl -* channel : -* BMG160_AUTO_OFFSET_WL -> 0 -* BMG160_FAST_OFFSET_WL -> 1 -* offset_wl : Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_wl( \ - unsigned char channel, unsigned char offset_wl) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_AUTO_OFFSET_WL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_AUTO_OFFSET_WL, offset_wl); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); - break; - - case BMG160_FAST_OFFSET_WL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_WL, offset_wl); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to enable fast offset -* -* -* -* -* \param bmg160_enable_fast_offset -* Enable -> 1 -* Disable -> 0 -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_enable_fast_offset() -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_EN, 1); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API read the Fast offset en status from the -* 0x32h of 0 to 2 bits. -* -* -* -* -* \param unsigned char *fast_offset -* Pointer to a variable passed as a parameter -* -* -* -* \return Communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fast_offset_en_ch( \ - unsigned char *fast_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_XYZ__REG, &v_data_u8r, 1); - *fast_offset = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_EN_XYZ); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API writes the Fast offset enable bit based -* on the Channel selection 0x32h of (0 to 2 bits) -* -* -* -* -* \param unsigned char channel,unsigned char fast_offset -* -* channel --> BMG160_X_AXIS,BMG160_Y_AXIS,BMG160_Z_AXIS -* fast_offset --> 0 - Disable -* 1 - Enable -* -* -* -* \return Communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en_ch( \ - unsigned char channel, unsigned char fast_offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (channel) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_X__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_EN_X, fast_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_X__REG, &v_data_u8r, 1); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_Y__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_EN_Y, fast_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_Y__REG, &v_data_u8r, 1); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_Z__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FAST_OFFSET_EN_Z, fast_offset); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FAST_OFFSET_EN_Z__REG, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of nvm program -* remain -* -* -* -* -* \param unsigned char *nvm_remain -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_remain(unsigned char *nvm_remain) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_REMAIN__REG, &v_data_u8r, 1); - *nvm_remain = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_REMAIN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of nvm load -* -* -* -* -* \param unsigned char nvm_load -* 1 -> load offset value from NVM -* 0 -> no action -* -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_load(unsigned char nvm_load) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD, nvm_load); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of nvmprogram -* ready -* -* -* -* -* \param unsigned char *nvm_rdy -* 1 -> program seq finished -* 0 -> program seq in progress -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_rdy(unsigned char *nvm_rdy) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_RDY__REG, &v_data_u8r, 1); - *nvm_rdy = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_RDY); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of nvm program -* trigger -* -* -* -* -* \param unsigned char trig -* 1 -> trig program seq (wo) -* 0 -> No Action -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_trig(unsigned char prog_trig) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG, prog_trig); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of nvm program -* mode -* -* -* -* -* \param unsigned char *prog_mode : Address of *prog_mode -* 1 -> Enable program mode -* 0 -> Disable program mode -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_prog_mode(unsigned char *prog_mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); - *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/****************************************************************************** - * Description: *//**\brief This API is used to set the status of nvmprogram - * mode - * - * - * - * - * \param (unsigned char prog_mode) - * 1 -> Enable program mode - * 0 -> Disable program mode - * - * - * - * - * \return communication results - * - * - *****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_mode(unsigned char prog_mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE, prog_mode); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of i2c wdt -* -* -* -* -* \param unsigned char channel,unsigned char *prog_mode -* BMG160_I2C_WDT_SEL 1 -* BMG160_I2C_WDT_EN 0 -* *prog_mode : Address of prog_mode -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_i2c_wdt(unsigned char i2c_wdt, \ - unsigned char *prog_mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (i2c_wdt) { - case BMG160_I2C_WDT_EN: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ - &v_data_u8r, 1); - *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN); - break; - - case BMG160_I2C_WDT_SEL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ - &v_data_u8r, 1); - *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of i2c wdt -* -* -* -* -* \param unsigned char channel,unsigned char prog_mode -* BMG160_I2C_WDT_SEL 1 -* BMG160_I2C_WDT_EN 0 -* prog_mode : Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_i2c_wdt(unsigned char i2c_wdt, \ - unsigned char prog_mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (i2c_wdt) { - case BMG160_I2C_WDT_EN: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN, prog_mode); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ - &v_data_u8r, 1); - break; - - case BMG160_I2C_WDT_SEL: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL, prog_mode); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ - &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of spi3 -* -* -* -* -* \param unsigned char *spi3 : Address of spi3 -* Pointer to a variable passed as a parameter -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_spi3(unsigned char *spi3) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); - *spi3 = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_SPI3); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of spi3 -* -* -* -* -* \param unsigned char spi3 -* -* -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_spi3(unsigned char spi3) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_BGW_SPI3_WDT_ADDR_SPI3, spi3); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); - } - return comres; -} - -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_tag(unsigned char *tag) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); - *tag = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF1_ADDR_TAG); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of Tag -* -* -* -* -* \param unsigned char tag -* Enable -> 1 -* Disable -> 0 -* -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_tag(unsigned char tag) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (tag < C_BMG160_Two_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF1_ADDR_TAG, tag); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get Water Mark Level -* -* -* -* -* \param unsigned char *water_mark_level : Address of water_mark_level -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermarklevel( \ - unsigned char *water_mark_level) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); - *water_mark_level = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF1_ADDR_WML); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set Water Mark Level -* -* -* -* -* \param unsigned char water_mark_level: -* Value to be written passed as a parameter - -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermarklevel( \ - unsigned char water_mark_level) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (water_mark_level < C_BMG160_OneTwentyEight_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF1_ADDR_WML, water_mark_level); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of offset -* -* -* -* -* \param unsigned char axis,unsigned char *offset -* axis -> -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* offset -> Any valid value -* -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset(unsigned char axis, \ - BMG160_S16 *offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data1_u8r, v_data2_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_X_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_X__REG, &v_data1_u8r, 1); - v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_X); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); - v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_X); - v_data2_u8r = ((v_data2_u8r << \ - BMG160_SHIFT_2_POSITION) | v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, BMG160_OFC2_ADDR, &v_data1_u8r, 1); - *offset = (BMG160_S16) ((((BMG160_S16) \ - ((signed char) v_data1_u8r)) \ - << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); - break; - - case BMG160_Y_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Y__REG, &v_data1_u8r, 1); - v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Y); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); - v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_Y); - v_data2_u8r = ((v_data2_u8r << \ - BMG160_SHIFT_1_POSITION) | v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC3_ADDR, &v_data1_u8r, 1); - *offset = (BMG160_S16) ((((BMG160_S16) \ - ((signed char) v_data1_u8r)) \ - << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); - break; - - case BMG160_Z_AXIS: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Z__REG, &v_data1_u8r, 1); - v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Z); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); - v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_Z); - v_data2_u8r = ((v_data2_u8r << BMG160_SHIFT_1_POSITION) \ - | v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC4_ADDR, &v_data1_u8r, 1); - *offset = (BMG160_S16) ((((BMG160_S16) \ - ((signed char) v_data1_u8r)) \ - << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of offset -* -* -* -* -* \param unsigned char axis,unsigned char offset -* axis -> -* BMG160_X_AXIS -> 0 -* BMG160_Y_AXIS -> 1 -* BMG160_Z_AXIS -> 2 -* offset -> Any valid value -* -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset( \ - unsigned char axis, BMG160_S16 offset) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data1_u8r, v_data2_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (axis) { - case BMG160_X_AXIS: - v_data1_u8r = ((signed char) (offset & 0x0FF0)) \ - >> BMG160_SHIFT_4_POSITION; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC2_ADDR, &v_data1_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x000C); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_X, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x0003); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_X, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); - break; - - case BMG160_Y_AXIS: - v_data1_u8r = ((signed char) (offset & 0x0FF0)) >> \ - BMG160_SHIFT_4_POSITION; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC3_ADDR, &v_data1_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x000E); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_Y, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x0001); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Y, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); - break; - - case BMG160_Z_AXIS: - v_data1_u8r = ((signed char) (offset & 0x0FF0)) >> \ - BMG160_SHIFT_4_POSITION; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC4_ADDR, &v_data1_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x000E); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_OFC1_ADDR_OFFSET_Z, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_OFC1_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); - - v_data1_u8r = (unsigned char) (offset & 0x0001); - v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Z, v_data1_u8r); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of general -* purpose register -* -* -* -* -* \param unsigned char param,unsigned char *value -* param -> -* BMG160_GP0 0 -* BMG160_GP0 1 -* *value -> Address of high_bw -* Pointer to a variable passed as a parameter -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_gp(unsigned char param, \ - unsigned char *value) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_GP0: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); - *value = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_GP0_ADDR_GP0); - break; - - case BMG160_GP1: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP1_ADDR, &v_data_u8r, 1); - *value = v_data_u8r; - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of general -* purpose register -* -* -* -* -* \param unsigned char param,unsigned char value -* param -> -* BMG160_GP0 0 -* BMG160_GP0 1 -* value -> Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_gp(unsigned char param, \ - unsigned char value) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - switch (param) { - case BMG160_GP0: - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_TRIM_GP0_ADDR_GP0, value); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); - break; - - case BMG160_GP1: - v_data_u8r = value; - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_TRIM_GP1_ADDR, &v_data_u8r, 1); - break; - - default: - comres = E_BMG160_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads FIFI data from location 3Fh -* -* -* -* -* \param -* unsigned char *FIFO_data : Address of FIFO data bits -* -* -* -* -* \return result of communication routines -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_FIFO_data_reg(unsigned char *FIFO_data) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_DATA_ADDR, &v_data_u8r, 1); - *FIFO_data = v_data_u8r; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh -* -* -* -* -* \param -* unsigned char *fifo_status : Address of Fifo status register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifostatus_reg( \ - unsigned char *fifo_status) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_STATUS_ADDR, fifo_status, 1); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh -* -* -* -* -* \param -* unsigned char *fifo_framecount: Address of FIFO status register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_framecount( \ - unsigned char *fifo_framecount) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_STATUS_FRAME_COUNTER__REG, &v_data_u8r, 1); - *fifo_framecount = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_STATUS_FRAME_COUNTER); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh -* -* -* -* -* \param -* unsigned char *fifo_overrun: Address of FIFO status register -* -* -* \return -* Result of bus communication function -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_overrun( \ - unsigned char *fifo_overrun) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_STATUS_OVERRUN__REG, &v_data_u8r, 1); - *fifo_overrun = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_STATUS_OVERRUN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of fifo mode -* -* -* -* -* \param unsigned char *mode : Address of mode -* fifo_mode 0 --> Bypass -* 1 --> FIFO -* 2 --> Stream -* 3 --> Reserved -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_mode(unsigned char *mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); - *mode = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF0_ADDR_MODE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used set to FIFO mode -* -* -* -* -* \param 0 --> BYPASS -* 1 --> FIFO -* 2 --> STREAM -* -* -* \return Communication Results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_mode(unsigned char mode) -{ - int comres = C_BMG160_Zero_U8X; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (mode < C_BMG160_Four_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF0_ADDR_MODE, mode); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the status of fifo data -* sel -* -* -* -* -* \param unsigned char *data_sel : Address of data_sel -* data_sel --> [0:3] -* 0 --> X,Y and Z (DEFAULT) -* 1 --> X only -* 2 --> Y only -* 3 --> Z only -* -* -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_data_sel(unsigned char *data_sel) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); - *data_sel = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF0_ADDR_DATA_SEL); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the status of fifo data -* sel -* -* -* -* -* \param unsigned char data_sel -* data_sel --> [0:3] -* 0 --> X,Y and Z (DEFAULT) -* 1 --> X only -* 2 --> Y only -* 3 --> Z only -* -* -* -* \return communication results -* -* -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_data_sel(unsigned char data_sel) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (data_sel < C_BMG160_Four_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_FIFO_CGF0_ADDR_DATA_SEL, data_sel); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get the operating modes of the -* sensor -* -* -* -* -* \param unsigned char * Mode : Address of Mode -* 0 -> NORMAL -* 1 -> SUSPEND -* 2 -> DEEP SUSPEND -* 3 -> FAST POWERUP -* 4 -> ADVANCED POWERSAVING -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_mode(unsigned char *Mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; - unsigned char data1 = C_BMG160_Zero_U8X; - unsigned char data2 = C_BMG160_Zero_U8X; - unsigned char data3 = C_BMG160_Zero_U8X; - if (p_bmg160 == C_BMG160_Zero_U8X) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data2, C_BMG160_One_U8X); - data1 = (data1 & 0xA0) >> 5; - data3 = (data2 & 0x40) >> 6; - data2 = (data2 & 0x80) >> 7; - if (data3 == 0x01) { - *Mode = BMG160_MODE_ADVANCEDPOWERSAVING; - } - else { - if ((data1 == 0x00) && (data2 == 0x00)) { - *Mode = BMG160_MODE_NORMAL; - } - else { - if ((data1 == 0x01) || (data1 == 0x05)) { - *Mode = BMG160_MODE_DEEPSUSPEND; - } - else { - if ((data1 == 0x04) && \ - (data2 == 0x00)) { - *Mode = BMG160_MODE_SUSPEND; - } - else { - if ((data1 == 0x04) && \ - (data2 == 0x01)) { - *Mode = \ - BMG160_MODE_FASTPOWERUP; - } - } - } - } - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set the operating Modes of the -* sensor -* -* -* -* -* \param unsigned char Mode -* 0 -> NORMAL -* 1 -> DEEPSUSPEND -* 2 -> SUSPEND -* 3 -> Fast Powerup -* 4 -> Advance Powerup -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_mode(unsigned char Mode) -{ - BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; - unsigned char data1; - unsigned char data2; - unsigned char data3; - unsigned char v_autosleepduration; - unsigned char v_bw_u8r; - if (p_bmg160 == C_BMG160_Zero_U8X) { - comres = E_BMG160_NULL_PTR; - } - else { - if (Mode < C_BMG160_Five_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data2, C_BMG160_One_U8X); - switch (Mode) { - case BMG160_MODE_NORMAL: - data1 = BMG160_SET_BITSLICE(data1, \ - BMG160_MODE_LPM1, C_BMG160_Zero_U8X); - data2 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ - C_BMG160_Zero_U8X); - data3 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ - C_BMG160_Zero_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - p_bmg160->delay_msec(1);/*A minimum delay of atleast - 450us is required for Multiple write.*/ - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); - break; - - case BMG160_MODE_DEEPSUSPEND: - data1 = BMG160_SET_BITSLICE(data1, \ - BMG160_MODE_LPM1, C_BMG160_One_U8X); - data2 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ - C_BMG160_Zero_U8X); - data3 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ - C_BMG160_Zero_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - p_bmg160->delay_msec(1);/*A minimum delay of atleast - 450us is required for Multiple write.*/ - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); - break; - - case BMG160_MODE_SUSPEND: - data1 = BMG160_SET_BITSLICE(data1, \ - BMG160_MODE_LPM1, C_BMG160_Four_U8X); - data2 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ - C_BMG160_Zero_U8X); - data3 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ - C_BMG160_Zero_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - p_bmg160->delay_msec(1);/*A minimum delay of atleast - 450us is required for Multiple write.*/ - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); - break; - - case BMG160_MODE_FASTPOWERUP: - data1 = BMG160_SET_BITSLICE(data1, \ - BMG160_MODE_LPM1, C_BMG160_Four_U8X); - data2 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ - C_BMG160_One_U8X); - data3 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ - C_BMG160_Zero_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - p_bmg160->delay_msec(1);/*A minimum delay of atleast - 450us is required for Multiple write.*/ - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); - break; - - case BMG160_MODE_ADVANCEDPOWERSAVING: - /* Configuring the proper settings for auto - sleep duration */ - bmg160_get_bw(&v_bw_u8r); - bmg160_get_autosleepdur(&v_autosleepduration); - bmg160_set_autosleepdur(v_autosleepduration, \ - v_bw_u8r); - comres += p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data2, \ - C_BMG160_One_U8X); - /* Configuring the advanced power saving mode*/ - data1 = BMG160_SET_BITSLICE(data1, \ - BMG160_MODE_LPM1, C_BMG160_Zero_U8X); - data2 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ - C_BMG160_Zero_U8X); - data3 = BMG160_SET_BITSLICE(data2, \ - BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ - C_BMG160_One_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); - p_bmg160->delay_msec(1);/*A minimum delay of atleast - 450us is required for Multiple write.*/ - comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); - break; - } - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to to do selftest to sensor -* sensor -* -* -* -* -* \param unsigned char *result -* -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_selftest(unsigned char *result) -{ - BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; - unsigned char data1 = C_BMG160_Zero_U8X; - unsigned char data2 = C_BMG160_Zero_U8X; - - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SELF_TEST_ADDR, &data1, C_BMG160_One_U8X); - data2 = BMG160_GET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_RATEOK); - data1 = BMG160_SET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_TRIGBIST, - C_BMG160_One_U8X); - comres += p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ - BMG160_SELF_TEST_ADDR_TRIGBIST__REG, &data1, C_BMG160_One_U8X); - - /* Waiting time to complete the selftest process */ - p_bmg160->delay_msec(10); - - /* Reading Selftest result bir bist_failure */ - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_SELF_TEST_ADDR_BISTFAIL__REG, &data1, C_BMG160_One_U8X); - data1 = BMG160_GET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_BISTFAIL); - if ((data1 == 0x00) && (data2 == 0x01)) { - *result = C_BMG160_SUCCESS; - } - else { - *result = C_BMG160_FAILURE; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get data auto sleep duration -* -* -* -* -* \param unsigned char *duration : Address of auto sleep duration -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_autosleepdur(unsigned char *duration) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, &v_data_u8r, 1); - *duration = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set duration -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_autosleepdur(unsigned char duration, \ - unsigned char bandwith) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - unsigned char v_autosleepduration_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, \ - &v_data_u8r, 1); - if (duration < C_BMG160_Eight_U8X) { - switch (bandwith) { - case C_BMG160_No_Filter_U8X: - if (duration > - C_BMG160_4ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_4ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_230Hz_U8X: - if (duration > - C_BMG160_4ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_4ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_116Hz_U8X: - if (duration > - C_BMG160_4ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_4ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_47Hz_U8X: - if (duration > - C_BMG160_5ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_5ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_23Hz_U8X: - if (duration > - C_BMG160_10ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_10ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_12Hz_U8X: - if (duration > - C_BMG160_20ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_20ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_64Hz_U8X: - if (duration > - C_BMG160_10ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_10ms_AutoSleepDur_U8X; - } - break; - - case C_BMG160_BW_32Hz_U8X: - if (duration > - C_BMG160_20ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_20ms_AutoSleepDur_U8X; - } - break; - - default: - if (duration > - C_BMG160_4ms_AutoSleepDur_U8X) { - v_autosleepduration_u8r = \ - duration; - } - else { - v_autosleepduration_u8r = \ - C_BMG160_4ms_AutoSleepDur_U8X; - } - break; - } - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR, \ - v_autosleepduration_u8r); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, \ - &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to get data sleep duration -* -* -* -* -* \param unsigned char *duration : Address of sleep duration -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_sleepdur(unsigned char *duration) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ - BMG160_MODELPM1_ADDR_SLEEPDUR__REG, &v_data_u8r, 1); - *duration = BMG160_GET_BITSLICE(v_data_u8r, \ - BMG160_MODELPM1_ADDR_SLEEPDUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************** -* Description: *//**\brief This API is used to set duration -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_sleepdur(unsigned char duration) -{ - BMG160_RETURN_FUNCTION_TYPE comres; - unsigned char v_data_u8r; - if (p_bmg160 == BMG160_NULL) { - comres = E_BMG160_NULL_PTR; - } - else { - if (duration < C_BMG160_Eight_U8X) { - comres = p_bmg160->BMG160_BUS_READ_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODELPM1_ADDR_SLEEPDUR__REG, \ - &v_data_u8r, 1); - v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ - BMG160_MODELPM1_ADDR_SLEEPDUR, duration); - comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ - (p_bmg160->dev_addr, \ - BMG160_MODELPM1_ADDR_SLEEPDUR__REG, \ - &v_data_u8r, 1); - } - else { - comres = E_BMG160_OUT_OF_RANGE; - } - } - return comres; -} +/* + ***************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + *****************************************************************************/ +/* Date: 2013/05/06 + * Revision: 1.4 + * + */ + +/****************************************************************************** +* Copyright (C) 2007 Bosch Sensortec GmbH +* +* API for BMG160 +* +* Usage: Driver for Gyro Sensor +* +******************************************************************************/ +/*****************************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. They + * may only be used within the parameters of the respective valid product data + * sheet. Bosch Sensortec products are provided with the express understanding + * that there is no warranty of fitness for a particular purpose.They are not + * fit for use in life-sustaining, safety or security sensitive systems or any + * system or device that may lead to bodily harm or property damage if the + * system or device malfunctions. In addition, Bosch Sensortec products are not + * fit for use in products which interact with motor vehicle systems.The resale + * and or use of products are at the purchasers own risk and his own + * responsibility. The examination of fitness for the intended use is the sole + * responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party claims, + * including any claims for incidental, or consequential damages, arising from + * any product use not covered by the parameters of the respective valid product + * data sheet or not approved by Bosch Sensortec and reimburse Bosch + * Sensortec for all costs in connection with such claims. + * + * The purchaser must monitor the market for the purchased products, + * particularly with regard to product safety and inform Bosch Sensortec without + * delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary + * from the valid technical specifications of the product series. They are + * therefore not intended or fit for resale to third parties or for use in end + * products. Their sole purpose is internal client testing. The testing of an + * engineering sample may in no way replace the testing of a product series. + * Bosch Sensortec assumes no liability for the use of engineering samples. By + * accepting the engineering samples, the Purchaser agrees to indemnify Bosch + * Sensortec from all claims arising from the use of engineering samples. + * + * Special: + * This software module (hereinafter called "Software") and any information on + * application-sheets (hereinafter called "Information") is provided free of + * charge for the sole purpose to support your application work. The Software + * and Information is subject to the following terms and conditions: + * + * The Software is specifically designed for the exclusive use for Bosch + * Sensortec products by personnel who have special experience and training. + * Do not use this Software if you do not have the proper experience or + * training. + * + * This Software package is provided `` as is `` and without any expressed or + * implied warranties, including without limitation, the implied warranties of + * merchantability and fitness for a particular purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability for + * the functional impairment of this Software in terms of fitness, performance + * and safety. Bosch Sensortec and their representatives and agents shall not be + * liable for any direct or indirect damages or injury, except as otherwise + * stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. Bosch + * Sensortec assumes no responsibility for the consequences of use of such + * Information nor for any infringement of patents or other rights of third + * parties which may result from its use. No license is granted by implication + * or otherwise under any patent or patent rights of Bosch. Specifications + * mentioned in the Information are subject to change without notice. + * + * It is not allowed to deliver the source code of the Software to any third + * party without permission of Bosch Sensortec. + */ +/*****************************************************************************/ +/*! \file BMG160.c + \brief Driver for BMG160 */ +#include "bmg160.h" +#include "sensorhub.h" +#include "common.h" +#include "gyro_common.h" +#include "osp-sensors.h" +#include "sensacq_i2c.h" +#include "gpio_api.h" +#include "gpio_irq_api.h" + +static struct bmg160_t *p_bmg160 = NULL; +static struct bmg160_t bmg160; + +static void gyro_get_chip_id(uint8_t *chipId) +{ + if ( p_bmg160 == NULL ) + return; + + /*Read CHIP_ID */ + p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_CHIP_ID_ADDR, chipId, 1); +} + +static void gyro_activate(bool enable) +{ + if (enable) { + bmg160_set_mode(BMG160_MODE_NORMAL); + bmg160_set_int_od(BMG160_INT1, 0); + bmg160_set_int_lvl(BMG160_INT1, 1); + bmg160_set_int_data(BMG160_INT1_DATA, 1); + bmg160_set_latch_int(7); + bmg160_set_data_en(1); + + /* Read to clear device */ + Gyro_ReadData(NULL); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(GYRO_PINT_IRQn); + NVIC_ClearPendingIRQ(GYRO_PINT_IRQn); + } + else { + bmg160_set_data_en(0); + NVIC_DisableIRQ(GYRO_PINT_IRQn); + bmg160_set_mode(BMG160_MODE_FASTPOWERUP); + + NVIC_DisableIRQ(GYRO_PINT_IRQn); + } + + /* ##KW## Optimized register write function? */ +} + +void Gyro_HardwareSetup(osp_bool_t enable) +{ + gpio_t hostifIrq; + NVIC_DisableIRQ(GYRO_PINT_IRQn); + NVIC_SetPriority(GYRO_PINT_IRQn, SENSOR_IRQ_PRIORITY); + //Chip_GPIO_SetPinDIRInput(LPC_GPIO, GYRO_INT_PORT, GYRO_INT_PIN); + hostifIrq.pin = ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN); + gpio_dir(&hostifIrq,PIN_INPUT); + Chip_INMUX_PinIntSel(GYRO_PINT_SEL,GYRO_INT_PORT, GYRO_INT_PIN); +// Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH); +// Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH); + { + gpio_irq_t gpioIrq; + gpioIrq.irq_index = GYRO_PINT_CH; + gpioIrq.event = IRQ_EDGE_RISE; + gpio_irq_enable(&gpioIrq); + } + Chip_SYSCON_EnableWakeup(GYRO_WAKE); +} + +void Gyro_Initialize(void) +{ + bmg160.bus_write = dev_i2c_write; + bmg160.bus_read = dev_i2c_read; + bmg160.delay_msec = dev_i2c_delay; + + bmg160_init(&bmg160); + + /* Reset all registers default setting */ + // QLY: Comment from bosch that doing a software reset cause SDA stay low forever! +// bmg160_set_soft_reset(); +// dev_i2c_delay(200); + + /* Get CHIP ID */ + gyro_get_chip_id( &bmg160.chip_id); + + D0_printf("Gyro Chip ID = 0x%x\r\n", bmg160.chip_id); + + dev_i2c_delay(10); + bmg160_set_mode(BMG160_MODE_NORMAL); + //dev_i2c_delay(10); + /* gyro_SetInterval(pSens,10); */ + bmg160_set_bw(C_BMG160_BW_32Hz_U8X); // BW = 32Hz, ODR = 100Hz + + //dev_i2c_delay(200); + bmg160_set_range_reg(C_BMG160_Zero_U8X); /* Zero = 2000 dps */ + //dev_i2c_delay(200); + + gyro_activate(true); + //dev_i2c_delay(200); + +} + +void Gyro_ConfigDataInt(osp_bool_t enable) +{ + if (enable) { + bmg160_set_mode(BMG160_MODE_NORMAL); + bmg160_set_int_od(BMG160_INT1, 0); + bmg160_set_int_lvl(BMG160_INT1, 1); + bmg160_set_int_data(BMG160_INT1_DATA, 1); + bmg160_set_latch_int(7); + bmg160_set_data_en(1); + + /* Read to clear device */ + Gyro_ClearDataInt(); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(GYRO_PINT_IRQn); + } else { + bmg160_set_data_en(0); + NVIC_DisableIRQ(GYRO_PINT_IRQn); + bmg160_set_mode(BMG160_MODE_FASTPOWERUP); + + //NVIC_DisableIRQ(GYRO_PINT_IRQn); + } + + /* ##KW## Optimized register write function? */ +} + +void Gyro_ClearDataInt(void) +{ + /* Read to clear any pending interrupt */ + Gyro_ReadData(NULL); +} + +void Gyro_ReadData(MsgGyroData *gyroData) +{ + struct bmg160_data_t data; + + /* Uses Bosch library functions for sensor data read */ + /* ##KW## Read counts or diffs? */ + bmg160_get_dataXYZ(&data); + + if (gyroData) { + gyroData->X = (int16_t) data.datax; + gyroData->Y = (int16_t) data.datay; + gyroData->Z = (int16_t) data.dataz; + } +} + +void GYRO_IRQHandler(void) +{ + gpio_irq_t gpioIrq; + uint32_t currTime = GetCurrentTime(); + gpioIrq.irq_index = GYRO_PINT_CH; +#if 0 + PhysicalSensor_t* pSens = g_phySensors[PHYS_GYRO_ID]; + uint32_t currTime = g_Timer.GetCurrent(); + pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; + pSens->ts_lastSample = currTime; + + pSens->irq_pending++; +// Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH); + gpio_irq_disable(&gpioIrq); + ResMgr_IRQDone(); +#else +// Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH); + gpio_irq_disable(&gpioIrq); + SendDataReadyIndication(GYRO_INPUT_SENSOR, currTime); +#endif +} + +/***************************************************************************** +* Description: *//**\brief API Initialization routine +* +* +* +* +* \param bmg160_t *bmg160 +* Pointer to a structure. +* +* structure members are +* +* unsigned char chip_id; +* unsigned char dev_addr; +* BMG160_BRD_FUNC_PTR; +* BMG160_WR_FUNC_PTR; +* BMG160_RD_FUNC_PTR; +* void(*delay_msec)( BMG160_MDELAY_DATA_TYPE ); +* +* +* +* +* +* \return result of communication routines +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_init(struct bmg160_t *bmg160) +{ + BMG160_RETURN_FUNCTION_TYPE comres = 0; +#if 0 + unsigned char a_data_u8r; +#endif + p_bmg160 = bmg160; + + p_bmg160->dev_addr = BMG160_I2C_ADDR; + +#if 0 + /*Read CHIP_ID */ + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_CHIP_ID_ADDR, &a_data_u8r, 1); + p_bmg160->chip_id = a_data_u8r; +#endif + + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads Rate dataX from location 02h and 03h +* registers +* +* +* +* +* \param +* BMG160_S16 *data_x : Address of data_x +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataX(BMG160_S16 *data_x) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[2]; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 2); + a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ + BMG160_RATE_X_LSB_VALUEX); + *data_x = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[1])) << \ + BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads rate dataY from location 04h and 05h +* registers +* +* +* +* +* \param +* BMG160_S16 *data_y : Address of data_y +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataY(BMG160_S16 *data_y) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[2]; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATE_Y_LSB_VALUEY__REG, a_data_u8r, 2); + a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ + BMG160_RATE_Y_LSB_VALUEY); + *data_y = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ + << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads rate dataZ from location 06h and 07h +* registers +* +* +* +* +* \param +* BMG160_S16 *data_z : Address of data_z +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataZ(BMG160_S16 *data_z) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[2]; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATE_Z_LSB_VALUEZ__REG, a_data_u8r, 2); + a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ + BMG160_RATE_Z_LSB_VALUEZ); + *data_z = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ + << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads data X,Y and Z from location 02h to 07h +* +* +* +* +* \param +* bmg160_data_t *data : Address of bmg160_data_t +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZ(struct bmg160_data_t *data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[6]; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, + BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 6); + /* Data X */ + a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], BMG160_RATE_X_LSB_VALUEX); + + data->datax = (BMG160_S16) (((BMG160_U16) a_data_u8r[1] << BMG160_RATE_X_LSB_VALUEX__LEN) | + a_data_u8r[0]); + /* Data Y */ + + a_data_u8r[2] = BMG160_GET_BITSLICE(a_data_u8r[2], BMG160_RATE_Y_LSB_VALUEY); + + data->datay = (BMG160_S16) (((BMG160_U16) a_data_u8r[3] << BMG160_RATE_Y_LSB_VALUEY__LEN) | + a_data_u8r[2]); + /* Data Z */ + a_data_u8r[4] = BMG160_GET_BITSLICE(a_data_u8r[4], BMG160_RATE_Z_LSB_VALUEZ); + data->dataz = (BMG160_S16) (((BMG160_U16) a_data_u8r[5] << BMG160_RATE_Z_LSB_VALUEZ__LEN) | + a_data_u8r[4]); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads data X,Y,Z and Interrupts +* from location 02h to 07h +* +* +* +* +* \param +* bmg160_data_t *data : Address of bmg160_data_t +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZI(struct bmg160_data_t *data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[12]; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATE_X_LSB_VALUEX__REG, a_data_u8r, 12); + /* Data X */ + a_data_u8r[0] = BMG160_GET_BITSLICE(a_data_u8r[0], \ + BMG160_RATE_X_LSB_VALUEX); + data->datax = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[1])) \ + << BMG160_SHIFT_8_POSITION) | (a_data_u8r[0])); + /* Data Y */ + a_data_u8r[2] = BMG160_GET_BITSLICE(a_data_u8r[2], \ + BMG160_RATE_Y_LSB_VALUEY); + data->datay = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[3])) \ + << BMG160_SHIFT_8_POSITION) | (a_data_u8r[2])); + /* Data Z */ + a_data_u8r[4] = BMG160_GET_BITSLICE(a_data_u8r[4], \ + BMG160_RATE_Z_LSB_VALUEZ); + data->dataz = (BMG160_S16) \ + ((((BMG160_S16) ((signed char) a_data_u8r[5])) \ + << BMG160_SHIFT_8_POSITION) | (a_data_u8r[4])); + data->intstatus[0] = a_data_u8r[7]; + data->intstatus[1] = a_data_u8r[8]; + data->intstatus[2] = a_data_u8r[9]; + data->intstatus[3] = a_data_u8r[10]; + data->intstatus[4] = a_data_u8r[11]; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads Temperature from location 08h +* +* +* +* +* \param +* unsigned char *temp : Address of temperature +* +* +* \return +* result of communication routines +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_Temperature(unsigned char *temperature) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TEMP_ADDR, &v_data_u8r, 1); + *temperature = v_data_u8r; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the data from the given register +* +* +* +* +* \param unsigned char addr, unsigned char *data unsigned char len +* addr -> Address of the register +* data -> address of the variable, read value will be +* kept +* len -> No of byte to be read. +* \return results of bus communication function +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_read_register(unsigned char addr, \ + unsigned char *data, unsigned char len) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, addr, data, len); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the data from the given register +* +* +* +* +* \param unsigned char addr, unsigned char *data BMG160_S32 len +* addr -> Address of the register +* data -> address of the variable, read value will be +* kept +* len -> No of byte to be read. +* \return results of bus communication function +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_burst_read(unsigned char addr, \ + unsigned char *data, BMG160_S32 len) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BURST_READ_FUNC(p_bmg160->dev_addr, \ + addr, data, len); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API given data to the given register +* +* +* +* +* \param unsigned char addr, unsigned char data,unsigned char len +* addr -> Address of the register +* data -> Data to be written to the register +* len -> No of byte to be read. +* +* \return Results of bus communication function +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_write_register(unsigned char addr, \ + unsigned char *data, unsigned char len) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, addr, data, len); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt status 0 register byte from 09h +* +* +* +* +* \param +* unsigned char *status0_data : Address of status 0 register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_0( \ + unsigned char *status0_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_STATUSZERO__REG, &v_data_u8r, 1); + *status0_data = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSZERO); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt status 1 register byte from 0Ah +* +* +* +* +* \param +* unsigned char *status1_data : Address of status register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_1( \ + unsigned char *status1_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, BMG160_INT_STATUSONE__REG, \ + &v_data_u8r, 1); + *status1_data = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSONE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt status register byte from 0Bh +* +* +* +* +* \param +* unsigned char *status2_data : Address of status 2 register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_2( \ + unsigned char *status2_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_STATUSTWO__REG, &v_data_u8r, 1); + *status2_data = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSTWO); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt status 3 register byte from 0Ch +* +* +* +* +* \param +* unsigned char *status3_data : Address of status 3 register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_3( \ + unsigned char *status3_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_STATUSTHREE__REG, &v_data_u8r, 1); + *status3_data = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_INT_STATUSTHREE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the range from register 0x0Fh of +* (0 to 2) bits +* +* +* +* +* \param unsigned char *range +* Range[0....7] +* 0 2000/s +* 1 1000/s +* 2 500/s +* 3 250/s +* 4 125/s +* +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_range_reg(unsigned char *range) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); + *range = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_RANGE_ADDR_RANGE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API sets the range register 0x0Fh +* (0 to 2 bits) +* +* +* +* +* \param unsigned char range +* +* Range[0....7] +* 0 2000/s +* 1 1000/s +* 2 500/s +* 3 250/s +* 4 125/s +* +* +* +* +* \return Communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_range_reg(unsigned char range) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (range < C_BMG160_Five_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RANGE_ADDR_RANGE, \ + range); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RANGE_ADDR_RANGE__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the high resolution bit of 0x10h +* Register 7th bit +* +* +* +* +* \param unsigned char *high_res +* Pointer to a variable passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_res(unsigned char *high_res) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BW_ADDR_HIGH_RES__REG, &v_data_u8r, 1); + *high_res = \ + BMG160_GET_BITSLICE(v_data_u8r, BMG160_BW_ADDR_HIGH_RES); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the bandwidth register of 0x10h 0 to +* 3 bits +* +* +* +* +* \param unsigned char *bandwidth +* pointer to a variable passed as a parameter +* +* 0 no filter(523 Hz) +* 1 230Hz +* 2 116Hz +* 3 47Hz +* 4 23Hz +* 5 12Hz +* 6 64Hz +* 7 32Hz +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_bw(unsigned char *bandwidth) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, BMG160_BW_ADDR__REG, &v_data_u8r, 1); + *bandwidth = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_BW_ADDR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API writes the Bandwidth register (0x10h of 0 +* to 3 bits) +* +* +* +* +* \param unsigned char bandwidth, +* The bandwidth to be set passed as a parameter +* +* 0 no filter(523 Hz) +* 1 230Hz +* 2 116Hz +* 3 47Hz +* 4 23Hz +* 5 12Hz +* 6 64Hz +* 7 32Hz +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_bw(unsigned char bandwidth) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + unsigned char v_mode_u8r; + unsigned char v_autosleepduration; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (bandwidth < C_BMG160_Eight_U8X) { + bmg160_get_mode(&v_mode_u8r); + if (v_mode_u8r == BMG160_MODE_ADVANCEDPOWERSAVING) { + bmg160_get_autosleepdur(&v_autosleepduration); + bmg160_set_autosleepdur(v_autosleepduration, \ + bandwidth); + } + dev_i2c_delay(20); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BW_ADDR__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_BW_ADDR, bandwidth); + dev_i2c_delay(20); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BW_ADDR__REG, &v_data_u8r, 1); + dev_i2c_delay(20); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the status of External Trigger +* selection bits (4 and 5) of 0x12h registers +* +* +* +* +* \param unsigned char *pwu_ext_tri_sel +* Pointer to a variable passed as a parameter +* +* +* +* \return Communication Results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_pmu_ext_tri_sel( \ + unsigned char *pwu_ext_tri_sel) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); + *pwu_ext_tri_sel = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API writes the External Trigger selection +* bits (4 and 5) of 0x12h registers +* +* +* +* +* \param unsigned char pwu_ext_tri_sel +* Value to be written passed as a parameter +* +* +* +* \return Communication Results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_pmu_ext_tri_sel( \ + unsigned char pwu_ext_tri_sel) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL, pwu_ext_tri_sel); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_EXT_TRI_SEL__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get data high bandwidth +* +* +* +* +* \param unsigned char *high_bw : Address of high_bw +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_bw(unsigned char *high_bw) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, &v_data_u8r, 1); + *high_bw = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_RATED_HBW_ADDR_DATA_HIGHBW); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set data high bandwidth +* +* +* +* +* \param unsigned char high_bw: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_bw(unsigned char high_bw) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (high_bw < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RATED_HBW_ADDR_DATA_HIGHBW, high_bw); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_DATA_HIGHBW__REG, \ + &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get shadow dis +* +* +* +* +* \param unsigned char *shadow_dis : Address of shadow_dis +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_shadow_dis(unsigned char *shadow_dis) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); + *shadow_dis = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_RATED_HBW_ADDR_SHADOW_DIS); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set shadow dis +* +* +* +* +* \param unsigned char shadow_dis +* Value to be written passed as a parameter +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_shadow_dis(unsigned char shadow_dis) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (shadow_dis < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RATED_HBW_ADDR_SHADOW_DIS, shadow_dis); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_RATED_HBW_ADDR_SHADOW_DIS__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief +* This function is used for the soft reset +* The soft reset register will be written with 0xB6. +* +* +* +* \param None +* +* +* +* \return Communication results. +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_soft_reset() +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_SoftReset_u8r; + v_SoftReset_u8r = 0xB6; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_BGW_SOFTRESET_ADDR, &v_SoftReset_u8r, 1); + } + + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get data enable data +* +* +* +* +* \param unsigned char *data_en : Address of data_en +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_data_enable(unsigned char *data_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); + *data_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_DATAEN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set data enable data +* +* +* +* +* \param unsigned char data_en: +* Value to be written passed as a parameter +* 0 --> Disable +* 1 --> Enable +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_data_en(unsigned char data_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_DATAEN, data_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_DATAEN__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get fifo enable bit +* +* +* +* +* \param unsigned char *fifo_en : Address of fifo_en +* Pointer to a variable passed as a parameter + +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_enable(unsigned char *fifo_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); + *fifo_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_FIFOEN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set fifo enable bit +* +* +* +* +* \param unsigned char fifo_en: +* Value to be written passed as a parameter +* 0 --> Disable +* 1 --> Enable +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_enable(unsigned char fifo_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (fifo_en < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_FIFOEN, fifo_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_FIFOEN__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API reads the status of the Auto offset +* Enable bit +* (0x15 Reg 3rd Bit) +* +* +* +* +* \param unsigned char *offset_en +* address of a variable, +* +* +* +* \return Communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_auto_offset_en( \ + unsigned char *offset_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); + *offset_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_AUTO_OFFSETEN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API sets the Auto offset enable bit +* (Reg 0x15 3rd Bit) +* +* +* +* +* \param unsigned char offset_en +* 0 --> Disable +* 1 --> Enable +* +* \return Communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_auto_offset_en(unsigned char offset_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE0_AUTO_OFFSETEN, offset_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_ENABLE0_AUTO_OFFSETEN__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the output type status +* +* +* +* +* \param unsigned char channel,unsigned char *int_od +* BMG160_INT1 -> 0 +* BMG160_INT2 -> 1 +* int_od : open drain -> 1 +* push pull -> 0 +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_od(unsigned char param, \ + unsigned char *int_od) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_INT1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); + *int_od = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT1_OD); + break; + + case BMG160_INT2: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); + *int_od = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT2_OD); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the output type status +* +* +* +* +* \param unsigned char channel,unsigned char *int_od +* BMG160_INT1 -> 0 +* BMG160_INT2 -> 1 +* int_od : open drain -> 1 +* push pull -> 0 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_od(unsigned char param, \ + unsigned char int_od) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_INT1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT1_OD, int_od); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_OD__REG, &v_data_u8r, 1); + break; + + case BMG160_INT2: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT2_OD, int_od); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_OD__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Active Level status +* +* +* +* +* \param unsigned char channel,unsigned char *int_lvl +* BMG160_INT1 -> 0 +* BMG160_INT2 -> 1 +* int_lvl : Active HI -> 1 +* Active LO -> 0 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_lvl(unsigned char param, \ + unsigned char *int_lvl) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_INT1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); + *int_lvl = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT1_LVL); + break; + + case BMG160_INT2: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); + *int_lvl = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT2_LVL); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Active Level status +* +* +* +* +* \param unsigned char channel,unsigned char *int_lvl +* BMG160_INT1 -> 0 +* BMG160_INT2 -> 1 +* int_lvl : Active HI -> 1 +* Active LO -> 0 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_lvl(unsigned char param, \ + unsigned char int_lvl) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_INT1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT1_LVL, int_lvl); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT1_LVL__REG, &v_data_u8r, 1); + break; + + case BMG160_INT2: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_ENABLE1_IT2_LVL, int_lvl); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_ENABLE1_IT2_LVL__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get High Interrupt1 +* +* +* +* +* \param unsigned char *int1_high : Address of high_bw +* Pointer to a variable passed as a parameter + +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_high(unsigned char *int1_high) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); + *int1_high = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_0_INT1_HIGH); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set High Interrupt1 +* +* +* +* +* \param unsigned char int1_high +* 0 -> Disable +* 1 -> Enable +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_high(unsigned char int1_high) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_0_INT1_HIGH, int1_high); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_HIGH__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Any Interrupt1 +* +* +* +* +* \param unsigned char *int1_any : Address of high_bw +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_any(unsigned char *int1_any) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); + *int1_any = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_0_INT1_ANY); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Any Interrupt1 +* +* +* +* +* \param unsigned char int1_any +* 0 -> Disable +* 1 -> Enable +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_any(unsigned char int1_any) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_0_INT1_ANY, int1_any); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_0_INT1_ANY__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get data Interrupt1 and data +* Interrupt2 +* +* +* +* +* \param unsigned char axis,unsigned char *int_data +* axis : +* BMG160_INT1_DATA -> 0 +* BMG160_INT2_DATA -> 1 +* int_data : +* Disable -> 0 +* Enable -> 1 +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_data(unsigned char axis, \ + unsigned char *int_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_INT1_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); + *int_data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_DATA); + break; + + case BMG160_INT2_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); + *int_data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_DATA); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set data Interrupt1 and data +* Interrupt2 +* +* +* +* +* \param unsigned char axis,unsigned char *int_data +* axis : +* BMG160_INT1_DATA -> 0 +* BMG160_INT2_DATA -> 1 +* int_data : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_data(unsigned char axis, \ + unsigned char int_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_INT1_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_DATA, int_data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_DATA__REG, &v_data_u8r, 1); + break; + + case BMG160_INT2_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_DATA, int_data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_DATA__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get fast offset and auto +* offset Interrupt2 +* +* +* +* +* \param unsigned char axis,unsigned char *int2_offset +* axis : +* BMG160_AUTO_OFFSET -> 1 +* BMG160_FAST_OFFSET -> 2 +* int2_offset : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_offset(unsigned char axis, \ + unsigned char *int2_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); + *int2_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_FAST_OFFSET); + break; + + case BMG160_AUTO_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); + *int2_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_AUTO_OFFSET); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set fast offset and auto +* offset Interrupt2 +* +* +* +* +* \param unsigned char axis,unsigned char *int2_offset +* axis : +* BMG160_AUTO_OFFSET -> 1 +* BMG160_FAST_OFFSET -> 2 +* int2_offset : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_offset(unsigned char axis, \ + unsigned char int2_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_FAST_OFFSET, int2_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FAST_OFFSET__REG, &v_data_u8r, 1); + break; + + case BMG160_AUTO_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_AUTO_OFFSET, int2_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_AUTO_OFFSET__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get fast offset and auto +* offset Interrupt1 +* +* +* +* +* \param unsigned char axis,unsigned char *int1_offset +* axis : +* BMG160_AUTO_OFFSET -> 1 +* BMG160_FAST_OFFSET -> 2 +* int2_offset : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_offset(unsigned char axis, \ + unsigned char *int1_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); + *int1_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_FAST_OFFSET); + break; + + case BMG160_AUTO_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); + *int1_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_AUTO_OFFSET); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set fast offset and auto +* offset Interrupt1 +* +* +* +* +* \param unsigned char axis,unsigned char *int1_offset +* axis : +* BMG160_AUTO_OFFSET -> 1 +* BMG160_FAST_OFFSET -> 2 +* int2_offset : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_offset(unsigned char axis, \ + unsigned char int1_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_FAST_OFFSET, int1_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FAST_OFFSET__REG, &v_data_u8r, 1); + break; + + case BMG160_AUTO_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_AUTO_OFFSET, int1_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_AUTO_OFFSET__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get status of FIFO Interrupt +* +* +* +* +* \param unsigned char *int_fifo : Address of int_fifo +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_fifo(unsigned char *int_fifo) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_STATUS1_FIFO_INT__REG, &v_data_u8r, 1); + *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_STATUS1_FIFO_INT); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get FIFO Interrupt2 +* +* +* +* +* \param unsigned char *int_fifo +* int_fifo : +* Disable -> 0 +* Enable -> 1 +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_fifo(unsigned char *int_fifo) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); + *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_FIFO); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get FIFO Interrupt1 +* +* +* +* +* \param unsigned char *int_fifo +* int_fifo : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_fifo(unsigned char *int_fifo) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); + *int_fifo = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_FIFO); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_fifo(unsigned char axis, \ + unsigned char int_fifo) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_INT1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_FIFO, int_fifo); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); + break; + + case BMG160_INT2: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_FIFO, int_fifo); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set FIFO Interrupt1 +* +* +* +* +* \param unsigned char *fifo_int1 +* fifo_int1 : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_fifo(unsigned char fifo_int1) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (fifo_int1 < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT1_FIFO, fifo_int1); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT1_FIFO__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set FIFO Interrupt2 +* +* +* +* +* \param unsigned char *fifo_int2 +* fifo_int2 : +* Disable -> 0 +* Enable -> 1 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_fifo(unsigned char fifo_int2) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (fifo_int2 < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MAP_1_INT2_FIFO, fifo_int2); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MAP_1_INT2_FIFO__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get High Interrupt2 +* +* +* +* +* \param unsigned char *int2_high : Address of int2_high +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_high(unsigned char *int2_high) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); + *int2_high = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_2_INT2_HIGH); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get High Interrupt2 +* +* +* +* +* \param unsigned char int2_high +* 0 -> Disable +* 1 -> Enable +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_high(unsigned char int2_high) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_2_INT2_HIGH, int2_high); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_HIGH__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Any Interrupt2 +* +* +* +* +* \param unsigned char *int2_any : Address of int2_any +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_any(unsigned char *int2_any) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); + *int2_any = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_2_INT2_ANY); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Any Interrupt2 +* +* +* +* +* \param unsigned char int2_any +* 0 -> Disable +* 1 -> Enable +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_any(unsigned char int2_any) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_MAP_2_INT2_ANY, int2_any); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_MAP_2_INT2_ANY__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get slow offset and fast +* offset unfilt data +* +* +* +* \param unsigned char param,unsigned char *offset_unfilt +* param : +* BMG160_SLOW_OFFSET -> 0 +* BMG160_FAST_OFFSET -> 2 +* offset_unfilt: Enable -> 1 +* Disable -> 0 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_unfilt(unsigned char param, \ + unsigned char *offset_unfilt) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_SLOW_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + *offset_unfilt = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT); + break; + + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + *offset_unfilt = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set slow offset and fast +* offset unfilt data +* +* +* +* +* \param unsigned char param,unsigned char *offset_unfilt +* param : +* BMG160_SLOW_OFFSET -> 0 +* BMG160_FAST_OFFSET -> 2 +* offset_unfilt: Enable -> 1 +* Disable -> 0 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_unfilt(unsigned char param, \ + unsigned char offset_unfilt) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_SLOW_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT, offset_unfilt); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_SLOW_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + break; + + case BMG160_FAST_OFFSET: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT, offset_unfilt); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_FAST_OFFSET_UNFILT__REG, \ + &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Tap, High, Constant, Any, +* Shake unfilt data +* +* +* +* +* \param unsigned char param,unsigned char *unfilt_data +* param : +* +* BMG160_HIGH_UNFILT_DATA -> 1 +* BMG160_ANY_UNFILT_DATA -> 3 +* +* unfilt_data: Enable -> 1 +* Disable -> 0 +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_unfilt_data(unsigned char param, \ + unsigned char *unfilt_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_HIGH_UNFILT_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ + &v_data_u8r, 1); + *unfilt_data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_HIGH_UNFILT_DATA); + break; + + case BMG160_ANY_UNFILT_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); + *unfilt_data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_ANY_UNFILT_DATA); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Tap, High, Constant, Any, +* Shake unfilt data +* +* +* +* +* \param unsigned char param,unsigned char *unfilt_data +* param : +* +* BMG160_HIGH_UNFILT_DATA -> 1 +* BMG160_ANY_UNFILT_DATA -> 3 +* +* unfilt_data: Enable -> 1 +* Disable -> 0 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_unfilt_data(unsigned char param, \ + unsigned char unfilt_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_HIGH_UNFILT_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_HIGH_UNFILT_DATA, unfilt_data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_HIGH_UNFILT_DATA__REG, \ + &v_data_u8r, 1); + break; + + case BMG160_ANY_UNFILT_DATA: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_0_ADDR_ANY_UNFILT_DATA, unfilt_data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_0_ADDR_ANY_UNFILT_DATA__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Any Threshold +* +* +* +* +* \param unsigned char *any_th : Address of any_th +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_th(unsigned char *any_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); + *any_th = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_1_ADDR_ANY_TH); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Any Threshold +* +* +* +* +* \param unsigned char any_th: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_th(unsigned char any_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_1_ADDR_ANY_TH, any_th); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_1_ADDR_ANY_TH__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Awake Duration +* +* +* +* +* \param unsigned char *awake_dur : Address of awake_dur +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_awake_dur(unsigned char *awake_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); + *awake_dur = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_AWAKE_DUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Awake Duration +* +* +* +* +* \param unsigned char awake_dur: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +***************************************************************************** +* Scheduling: +* +* +* +* Usage guide: +* +* +* Remarks: +* +*****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_awake_dur(unsigned char awake_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_AWAKE_DUR, awake_dur); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_AWAKE_DUR__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Any Duration Sample +* +* +* +* +* \param unsigned char *dursample : Address of dursample +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_dursample(unsigned char *dursample) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); + *dursample = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_DURSAMPLE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Any Duration Sample +* +* +* +* +* \param unsigned char dursample: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_dursample(unsigned char dursample) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_DURSAMPLE, dursample); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_DURSAMPLE__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of Any Enable +* Channel X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *data +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* data : +* Enable -> 1 +* disable -> 0 +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_en_ch(unsigned char channel, \ + unsigned char *data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); + *data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_X); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); + *data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_Y); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); + *data = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_Z); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of Any Enable +* Channel X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *data +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* data : +* Enable -> 1 +* disable -> 0 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_en_ch(unsigned char channel, \ + unsigned char data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_X, data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_Y, data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_2_ADDR_ANY_EN_Z, data); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_2_ADDR_ANY_EN_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of FIFO WM +* Enable +* +* +* +* +* \param unsigned char *fifo_wn_en +* Enable -> 1 +* Disable -> 0 +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermark_enable( \ + unsigned char *fifo_wn_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); + *fifo_wn_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_INT_4_FIFO_WM_EN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set FIFO WM Enable +* +* +* +* +* \param unsigned char *fifo_wn_en +* Enable -> 1 +* Disable -> 0 +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermark_enable( \ + unsigned char fifo_wn_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (fifo_wn_en < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_INT_4_FIFO_WM_EN, fifo_wn_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_INT_4_FIFO_WM_EN__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the Interrupt Reset +* +* +* +* +* \param unsigned char reset_int +* 1 -> Reset All Interrupts +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_reset_int(unsigned char reset_int) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_RESET_INT__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_RESET_INT, reset_int); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_RESET_INT__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the Offset Reset +* +* +* +* +* \param unsigned char offset_reset +* 1 -> Resets All the Offsets +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_reset( \ + unsigned char offset_reset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_OFFSET_RESET__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_OFFSET_RESET, offset_reset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_OFFSET_RESET__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the Latch Status +* +* +* +* +* \param unsigned char *latch_status : Address of latch_status +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_status( \ + unsigned char *latch_status) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); + *latch_status = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_LATCH_STATUS); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the Latch Status +* +* +* +* +* \param unsigned char latch_status: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_status( \ + unsigned char latch_status) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_LATCH_STATUS, latch_status); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_STATUS__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the Latch Interrupt +* +* +* +* +* \param unsigned char *latch_int : Address of latch_int +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_int(unsigned char *latch_int) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); + *latch_int = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_LATCH_INT); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the Latch Interrupt +* +* +* +* +* \param unsigned char latch_int: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_int(unsigned char latch_int) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_RST_LATCH_ADDR_LATCH_INT, latch_int); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_RST_LATCH_ADDR_LATCH_INT__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of High +* Hysteresis X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_hy +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_hy : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_hy(unsigned char channel, \ + unsigned char *high_hy) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); + *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_X); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); + *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_Y); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); + *high_hy = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_Z); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of High +* Hysteresis X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_hy +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_hy : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_hy(unsigned char channel, \ + unsigned char high_hy) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_X, high_hy); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_Y, high_hy); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_HY_Z, high_hy); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_HY_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of High +* Threshold X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_th +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_th : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_th(unsigned char channel, \ + unsigned char *high_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); + *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_X); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); + *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_Y); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); + *high_th = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_Z); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of High +* Threshold X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_th +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_th : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_th(unsigned char channel, \ + unsigned char high_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_X, high_th); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_Y, high_th); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_TH_Z, high_th); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_TH_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of High Enable +* Channel X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_en +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_en : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_en_ch(unsigned char channel, \ + unsigned char *high_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); + *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_X); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); + *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_Y); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); + *high_en = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_Z); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of High Enable +* Channel X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *high_en +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_en : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_en_ch(unsigned char channel, \ + unsigned char high_en) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_X, high_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_Y, high_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_HIGH_EN_Z, high_en); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_EN_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get High Duration +* +* +* +* +* \param unsigned char channel,unsigned char *high_dur +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* *high_dur : Address of high_bw +* Pointer to a variable passed as a +* parameter +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_dur_ch(unsigned char channel, \ + unsigned char *high_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_X_ADDR, &v_data_u8r, 1); + *high_dur = v_data_u8r; + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_Y_ADDR, &v_data_u8r, 1); + *high_dur = v_data_u8r; + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_Z_ADDR, &v_data_u8r, 1); + *high_dur = v_data_u8r; + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set High Duration +* +* +* +* +* \param unsigned char channel,unsigned char *high_dur +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* high_dur : Value to be written passed as a parameter +* +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_dur_ch(unsigned char channel, \ + unsigned char high_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + v_data_u8r = high_dur; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_X_ADDR, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + v_data_u8r = high_dur; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_Y_ADDR, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + v_data_u8r = high_dur; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_HIGH_DUR_Z_ADDR, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Slow Offset Threshold +* +* +* +* +* \param unsigned char *offset_th : Address of offset_th +* Pointer to a variable passed as a parameter + +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_th( \ + unsigned char *offset_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); + *offset_th = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_TH); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Slow Offset Threshold +* +* +* +* +* \param unsigned char offset_th: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_th(unsigned char offset_th) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_TH, offset_th); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_TH__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Slow Offset Duration +* +* +* +* +* \param unsigned char *offset_dur : Address of offset_dur +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_dur( \ + unsigned char *offset_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); + *offset_dur = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_DUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Slow Offset Duration +* +* +* +* +* \param unsigned char offset_dur: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_dur( \ + unsigned char offset_dur) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_DUR, offset_dur); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_DUR__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Slow Offset Enable channel +* X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *slow_offset +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* slow_offset : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_en_ch( \ + unsigned char channel, unsigned char *slow_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); + *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_X); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); + *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_Y); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); + *slow_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_Z); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Slow Offset Enable channel +* X,Y,Z +* +* +* +* +* \param unsigned char channel,unsigned char *slow_offset +* channel : +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* slow_offset : +* Enable -> 1 +* disable -> 0 +* +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_en_ch( \ + unsigned char channel, unsigned char slow_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_X, slow_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_Y, slow_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_SLOW_OFFSET_EN_Z, \ + slow_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_SLOW_OFFSET_EN_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Fast Offset WordLength and +* Auto Offset WordLength +* +* +* +* +* \param unsigned char channel,unsigned char *offset_wl +* channel : +* BMG160_AUTO_OFFSET_WL -> 0 +* BMG160_FAST_OFFSET_WL -> 1 +* *offset_wl : Address of high_bw +* Pointer to a variable passed as a +* parameter +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_wl(unsigned char channel, \ + unsigned char *offset_wl) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_AUTO_OFFSET_WL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); + *offset_wl = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_AUTO_OFFSET_WL); + break; + + case BMG160_FAST_OFFSET_WL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); + *offset_wl = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_WL); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Fast Offset WordLength and +* Auto Offset WordLength +* +* +* +* +* \param unsigned char channel,unsigned char *offset_wl +* channel : +* BMG160_AUTO_OFFSET_WL -> 0 +* BMG160_FAST_OFFSET_WL -> 1 +* offset_wl : Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_wl( \ + unsigned char channel, unsigned char offset_wl) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_AUTO_OFFSET_WL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_AUTO_OFFSET_WL, offset_wl); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_AUTO_OFFSET_WL__REG, &v_data_u8r, 1); + break; + + case BMG160_FAST_OFFSET_WL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_WL, offset_wl); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_WL__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to enable fast offset +* +* +* +* +* \param bmg160_enable_fast_offset +* Enable -> 1 +* Disable -> 0 +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_enable_fast_offset() +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_EN, 1); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API read the Fast offset en status from the +* 0x32h of 0 to 2 bits. +* +* +* +* +* \param unsigned char *fast_offset +* Pointer to a variable passed as a parameter +* +* +* +* \return Communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fast_offset_en_ch( \ + unsigned char *fast_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_XYZ__REG, &v_data_u8r, 1); + *fast_offset = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_EN_XYZ); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API writes the Fast offset enable bit based +* on the Channel selection 0x32h of (0 to 2 bits) +* +* +* +* +* \param unsigned char channel,unsigned char fast_offset +* +* channel --> BMG160_X_AXIS,BMG160_Y_AXIS,BMG160_Z_AXIS +* fast_offset --> 0 - Disable +* 1 - Enable +* +* +* +* \return Communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en_ch( \ + unsigned char channel, unsigned char fast_offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (channel) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_X__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_EN_X, fast_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_X__REG, &v_data_u8r, 1); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_Y__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_EN_Y, fast_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_Y__REG, &v_data_u8r, 1); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_Z__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FAST_OFFSET_EN_Z, fast_offset); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FAST_OFFSET_EN_Z__REG, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of nvm program +* remain +* +* +* +* +* \param unsigned char *nvm_remain +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_remain(unsigned char *nvm_remain) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_REMAIN__REG, &v_data_u8r, 1); + *nvm_remain = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_REMAIN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of nvm load +* +* +* +* +* \param unsigned char nvm_load +* 1 -> load offset value from NVM +* 0 -> no action +* +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_load(unsigned char nvm_load) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD, nvm_load); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_LOAD__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of nvmprogram +* ready +* +* +* +* +* \param unsigned char *nvm_rdy +* 1 -> program seq finished +* 0 -> program seq in progress +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_rdy(unsigned char *nvm_rdy) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_RDY__REG, &v_data_u8r, 1); + *nvm_rdy = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_RDY); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of nvm program +* trigger +* +* +* +* +* \param unsigned char trig +* 1 -> trig program seq (wo) +* 0 -> No Action +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_trig(unsigned char prog_trig) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG, prog_trig); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_TRIG__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of nvm program +* mode +* +* +* +* +* \param unsigned char *prog_mode : Address of *prog_mode +* 1 -> Enable program mode +* 0 -> Disable program mode +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_prog_mode(unsigned char *prog_mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); + *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/****************************************************************************** + * Description: *//**\brief This API is used to set the status of nvmprogram + * mode + * + * + * + * + * \param (unsigned char prog_mode) + * 1 -> Enable program mode + * 0 -> Disable program mode + * + * + * + * + * \return communication results + * + * + *****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_mode(unsigned char prog_mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE, prog_mode); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_TRIM_NVM_CTRL_ADDR_NVM_PROG_MODE__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of i2c wdt +* +* +* +* +* \param unsigned char channel,unsigned char *prog_mode +* BMG160_I2C_WDT_SEL 1 +* BMG160_I2C_WDT_EN 0 +* *prog_mode : Address of prog_mode +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_i2c_wdt(unsigned char i2c_wdt, \ + unsigned char *prog_mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (i2c_wdt) { + case BMG160_I2C_WDT_EN: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ + &v_data_u8r, 1); + *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN); + break; + + case BMG160_I2C_WDT_SEL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ + &v_data_u8r, 1); + *prog_mode = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of i2c wdt +* +* +* +* +* \param unsigned char channel,unsigned char prog_mode +* BMG160_I2C_WDT_SEL 1 +* BMG160_I2C_WDT_EN 0 +* prog_mode : Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_i2c_wdt(unsigned char i2c_wdt, \ + unsigned char prog_mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (i2c_wdt) { + case BMG160_I2C_WDT_EN: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN, prog_mode); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_EN__REG, \ + &v_data_u8r, 1); + break; + + case BMG160_I2C_WDT_SEL: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL, prog_mode); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_I2C_WDT_SEL__REG, \ + &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of spi3 +* +* +* +* +* \param unsigned char *spi3 : Address of spi3 +* Pointer to a variable passed as a parameter +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_spi3(unsigned char *spi3) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); + *spi3 = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_SPI3); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of spi3 +* +* +* +* +* \param unsigned char spi3 +* +* +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_spi3(unsigned char spi3) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_BGW_SPI3_WDT_ADDR_SPI3, spi3); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_BGW_SPI3_WDT_ADDR_SPI3__REG, &v_data_u8r, 1); + } + return comres; +} + +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_tag(unsigned char *tag) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); + *tag = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF1_ADDR_TAG); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of Tag +* +* +* +* +* \param unsigned char tag +* Enable -> 1 +* Disable -> 0 +* +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_tag(unsigned char tag) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (tag < C_BMG160_Two_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF1_ADDR_TAG, tag); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_TAG__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get Water Mark Level +* +* +* +* +* \param unsigned char *water_mark_level : Address of water_mark_level +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermarklevel( \ + unsigned char *water_mark_level) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); + *water_mark_level = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF1_ADDR_WML); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set Water Mark Level +* +* +* +* +* \param unsigned char water_mark_level: +* Value to be written passed as a parameter + +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermarklevel( \ + unsigned char water_mark_level) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (water_mark_level < C_BMG160_OneTwentyEight_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF1_ADDR_WML, water_mark_level); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF1_ADDR_WML__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of offset +* +* +* +* +* \param unsigned char axis,unsigned char *offset +* axis -> +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* offset -> Any valid value +* +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset(unsigned char axis, \ + BMG160_S16 *offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data1_u8r, v_data2_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_X_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_X__REG, &v_data1_u8r, 1); + v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_X); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); + v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_X); + v_data2_u8r = ((v_data2_u8r << \ + BMG160_SHIFT_2_POSITION) | v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, BMG160_OFC2_ADDR, &v_data1_u8r, 1); + *offset = (BMG160_S16) ((((BMG160_S16) \ + ((signed char) v_data1_u8r)) \ + << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); + break; + + case BMG160_Y_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Y__REG, &v_data1_u8r, 1); + v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Y); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); + v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_Y); + v_data2_u8r = ((v_data2_u8r << \ + BMG160_SHIFT_1_POSITION) | v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC3_ADDR, &v_data1_u8r, 1); + *offset = (BMG160_S16) ((((BMG160_S16) \ + ((signed char) v_data1_u8r)) \ + << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); + break; + + case BMG160_Z_AXIS: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Z__REG, &v_data1_u8r, 1); + v_data1_u8r = BMG160_GET_BITSLICE(v_data1_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Z); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); + v_data2_u8r = BMG160_GET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_Z); + v_data2_u8r = ((v_data2_u8r << BMG160_SHIFT_1_POSITION) \ + | v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC4_ADDR, &v_data1_u8r, 1); + *offset = (BMG160_S16) ((((BMG160_S16) \ + ((signed char) v_data1_u8r)) \ + << BMG160_SHIFT_4_POSITION) | (v_data2_u8r)); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of offset +* +* +* +* +* \param unsigned char axis,unsigned char offset +* axis -> +* BMG160_X_AXIS -> 0 +* BMG160_Y_AXIS -> 1 +* BMG160_Z_AXIS -> 2 +* offset -> Any valid value +* +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset( \ + unsigned char axis, BMG160_S16 offset) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data1_u8r, v_data2_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (axis) { + case BMG160_X_AXIS: + v_data1_u8r = ((signed char) (offset & 0x0FF0)) \ + >> BMG160_SHIFT_4_POSITION; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC2_ADDR, &v_data1_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x000C); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_X, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x0003); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_X, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_X__REG, &v_data2_u8r, 1); + break; + + case BMG160_Y_AXIS: + v_data1_u8r = ((signed char) (offset & 0x0FF0)) >> \ + BMG160_SHIFT_4_POSITION; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC3_ADDR, &v_data1_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x000E); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_Y, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x0001); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Y, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Y__REG, &v_data2_u8r, 1); + break; + + case BMG160_Z_AXIS: + v_data1_u8r = ((signed char) (offset & 0x0FF0)) >> \ + BMG160_SHIFT_4_POSITION; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC4_ADDR, &v_data1_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x000E); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_OFC1_ADDR_OFFSET_Z, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_OFC1_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); + + v_data1_u8r = (unsigned char) (offset & 0x0001); + v_data2_u8r = BMG160_SET_BITSLICE(v_data2_u8r, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Z, v_data1_u8r); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_OFFSET_Z__REG, &v_data2_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of general +* purpose register +* +* +* +* +* \param unsigned char param,unsigned char *value +* param -> +* BMG160_GP0 0 +* BMG160_GP0 1 +* *value -> Address of high_bw +* Pointer to a variable passed as a parameter +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_gp(unsigned char param, \ + unsigned char *value) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_GP0: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); + *value = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_GP0_ADDR_GP0); + break; + + case BMG160_GP1: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP1_ADDR, &v_data_u8r, 1); + *value = v_data_u8r; + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of general +* purpose register +* +* +* +* +* \param unsigned char param,unsigned char value +* param -> +* BMG160_GP0 0 +* BMG160_GP0 1 +* value -> Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_gp(unsigned char param, \ + unsigned char value) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + switch (param) { + case BMG160_GP0: + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_TRIM_GP0_ADDR_GP0, value); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP0_ADDR_GP0__REG, &v_data_u8r, 1); + break; + + case BMG160_GP1: + v_data_u8r = value; + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_TRIM_GP1_ADDR, &v_data_u8r, 1); + break; + + default: + comres = E_BMG160_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads FIFI data from location 3Fh +* +* +* +* +* \param +* unsigned char *FIFO_data : Address of FIFO data bits +* +* +* +* +* \return result of communication routines +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_FIFO_data_reg(unsigned char *FIFO_data) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_DATA_ADDR, &v_data_u8r, 1); + *FIFO_data = v_data_u8r; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh +* +* +* +* +* \param +* unsigned char *fifo_status : Address of Fifo status register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifostatus_reg( \ + unsigned char *fifo_status) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_STATUS_ADDR, fifo_status, 1); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh +* +* +* +* +* \param +* unsigned char *fifo_framecount: Address of FIFO status register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_framecount( \ + unsigned char *fifo_framecount) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_STATUS_FRAME_COUNTER__REG, &v_data_u8r, 1); + *fifo_framecount = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_STATUS_FRAME_COUNTER); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief Reads interrupt fifo status register byte from 0Eh +* +* +* +* +* \param +* unsigned char *fifo_overrun: Address of FIFO status register +* +* +* \return +* Result of bus communication function +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_overrun( \ + unsigned char *fifo_overrun) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_STATUS_OVERRUN__REG, &v_data_u8r, 1); + *fifo_overrun = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_STATUS_OVERRUN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of fifo mode +* +* +* +* +* \param unsigned char *mode : Address of mode +* fifo_mode 0 --> Bypass +* 1 --> FIFO +* 2 --> Stream +* 3 --> Reserved +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_mode(unsigned char *mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); + *mode = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF0_ADDR_MODE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used set to FIFO mode +* +* +* +* +* \param 0 --> BYPASS +* 1 --> FIFO +* 2 --> STREAM +* +* +* \return Communication Results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_mode(unsigned char mode) +{ + int comres = C_BMG160_Zero_U8X; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (mode < C_BMG160_Four_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF0_ADDR_MODE, mode); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_MODE__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the status of fifo data +* sel +* +* +* +* +* \param unsigned char *data_sel : Address of data_sel +* data_sel --> [0:3] +* 0 --> X,Y and Z (DEFAULT) +* 1 --> X only +* 2 --> Y only +* 3 --> Z only +* +* +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_data_sel(unsigned char *data_sel) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); + *data_sel = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF0_ADDR_DATA_SEL); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the status of fifo data +* sel +* +* +* +* +* \param unsigned char data_sel +* data_sel --> [0:3] +* 0 --> X,Y and Z (DEFAULT) +* 1 --> X only +* 2 --> Y only +* 3 --> Z only +* +* +* +* \return communication results +* +* +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_data_sel(unsigned char data_sel) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (data_sel < C_BMG160_Four_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_FIFO_CGF0_ADDR_DATA_SEL, data_sel); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_FIFO_CGF0_ADDR_DATA_SEL__REG, &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get the operating modes of the +* sensor +* +* +* +* +* \param unsigned char * Mode : Address of Mode +* 0 -> NORMAL +* 1 -> SUSPEND +* 2 -> DEEP SUSPEND +* 3 -> FAST POWERUP +* 4 -> ADVANCED POWERSAVING +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_mode(unsigned char *Mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; + unsigned char data1 = C_BMG160_Zero_U8X; + unsigned char data2 = C_BMG160_Zero_U8X; + unsigned char data3 = C_BMG160_Zero_U8X; + if (p_bmg160 == C_BMG160_Zero_U8X) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data2, C_BMG160_One_U8X); + data1 = (data1 & 0xA0) >> 5; + data3 = (data2 & 0x40) >> 6; + data2 = (data2 & 0x80) >> 7; + if (data3 == 0x01) { + *Mode = BMG160_MODE_ADVANCEDPOWERSAVING; + } + else { + if ((data1 == 0x00) && (data2 == 0x00)) { + *Mode = BMG160_MODE_NORMAL; + } + else { + if ((data1 == 0x01) || (data1 == 0x05)) { + *Mode = BMG160_MODE_DEEPSUSPEND; + } + else { + if ((data1 == 0x04) && \ + (data2 == 0x00)) { + *Mode = BMG160_MODE_SUSPEND; + } + else { + if ((data1 == 0x04) && \ + (data2 == 0x01)) { + *Mode = \ + BMG160_MODE_FASTPOWERUP; + } + } + } + } + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set the operating Modes of the +* sensor +* +* +* +* +* \param unsigned char Mode +* 0 -> NORMAL +* 1 -> DEEPSUSPEND +* 2 -> SUSPEND +* 3 -> Fast Powerup +* 4 -> Advance Powerup +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_mode(unsigned char Mode) +{ + BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; + unsigned char data1; + unsigned char data2; + unsigned char data3; + unsigned char v_autosleepduration; + unsigned char v_bw_u8r; + if (p_bmg160 == C_BMG160_Zero_U8X) { + comres = E_BMG160_NULL_PTR; + } + else { + if (Mode < C_BMG160_Five_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data2, C_BMG160_One_U8X); + switch (Mode) { + case BMG160_MODE_NORMAL: + data1 = BMG160_SET_BITSLICE(data1, \ + BMG160_MODE_LPM1, C_BMG160_Zero_U8X); + data2 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ + C_BMG160_Zero_U8X); + data3 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ + C_BMG160_Zero_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + p_bmg160->delay_msec(1);/*A minimum delay of atleast + 450us is required for Multiple write.*/ + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); + break; + + case BMG160_MODE_DEEPSUSPEND: + data1 = BMG160_SET_BITSLICE(data1, \ + BMG160_MODE_LPM1, C_BMG160_One_U8X); + data2 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ + C_BMG160_Zero_U8X); + data3 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ + C_BMG160_Zero_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + p_bmg160->delay_msec(1);/*A minimum delay of atleast + 450us is required for Multiple write.*/ + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); + break; + + case BMG160_MODE_SUSPEND: + data1 = BMG160_SET_BITSLICE(data1, \ + BMG160_MODE_LPM1, C_BMG160_Four_U8X); + data2 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ + C_BMG160_Zero_U8X); + data3 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ + C_BMG160_Zero_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + p_bmg160->delay_msec(1);/*A minimum delay of atleast + 450us is required for Multiple write.*/ + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); + break; + + case BMG160_MODE_FASTPOWERUP: + data1 = BMG160_SET_BITSLICE(data1, \ + BMG160_MODE_LPM1, C_BMG160_Four_U8X); + data2 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ + C_BMG160_One_U8X); + data3 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ + C_BMG160_Zero_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + p_bmg160->delay_msec(1);/*A minimum delay of atleast + 450us is required for Multiple write.*/ + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); + break; + + case BMG160_MODE_ADVANCEDPOWERSAVING: + /* Configuring the proper settings for auto + sleep duration */ + bmg160_get_bw(&v_bw_u8r); + bmg160_get_autosleepdur(&v_autosleepduration); + bmg160_set_autosleepdur(v_autosleepduration, \ + v_bw_u8r); + comres += p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data2, \ + C_BMG160_One_U8X); + /* Configuring the advanced power saving mode*/ + data1 = BMG160_SET_BITSLICE(data1, \ + BMG160_MODE_LPM1, C_BMG160_Zero_U8X); + data2 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_FAST_POWERUP, \ + C_BMG160_Zero_U8X); + data3 = BMG160_SET_BITSLICE(data2, \ + BMG160_MODE_LPM2_ADDR_ADV_POWERSAVING, \ + C_BMG160_One_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM1_ADDR, &data1, C_BMG160_One_U8X); + p_bmg160->delay_msec(1);/*A minimum delay of atleast + 450us is required for Multiple write.*/ + comres += p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR, &data3, C_BMG160_One_U8X); + break; + } + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to to do selftest to sensor +* sensor +* +* +* +* +* \param unsigned char *result +* +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_selftest(unsigned char *result) +{ + BMG160_RETURN_FUNCTION_TYPE comres = C_BMG160_Zero_U8X; + unsigned char data1 = C_BMG160_Zero_U8X; + unsigned char data2 = C_BMG160_Zero_U8X; + + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SELF_TEST_ADDR, &data1, C_BMG160_One_U8X); + data2 = BMG160_GET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_RATEOK); + data1 = BMG160_SET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_TRIGBIST, + C_BMG160_One_U8X); + comres += p_bmg160->BMG160_BUS_WRITE_FUNC(p_bmg160->dev_addr, \ + BMG160_SELF_TEST_ADDR_TRIGBIST__REG, &data1, C_BMG160_One_U8X); + + /* Waiting time to complete the selftest process */ + p_bmg160->delay_msec(10); + + /* Reading Selftest result bir bist_failure */ + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_SELF_TEST_ADDR_BISTFAIL__REG, &data1, C_BMG160_One_U8X); + data1 = BMG160_GET_BITSLICE(data1, BMG160_SELF_TEST_ADDR_BISTFAIL); + if ((data1 == 0x00) && (data2 == 0x01)) { + *result = C_BMG160_SUCCESS; + } + else { + *result = C_BMG160_FAILURE; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get data auto sleep duration +* +* +* +* +* \param unsigned char *duration : Address of auto sleep duration +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_autosleepdur(unsigned char *duration) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, &v_data_u8r, 1); + *duration = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set duration +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_autosleepdur(unsigned char duration, \ + unsigned char bandwith) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + unsigned char v_autosleepduration_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, \ + &v_data_u8r, 1); + if (duration < C_BMG160_Eight_U8X) { + switch (bandwith) { + case C_BMG160_No_Filter_U8X: + if (duration > + C_BMG160_4ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_4ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_230Hz_U8X: + if (duration > + C_BMG160_4ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_4ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_116Hz_U8X: + if (duration > + C_BMG160_4ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_4ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_47Hz_U8X: + if (duration > + C_BMG160_5ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_5ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_23Hz_U8X: + if (duration > + C_BMG160_10ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_10ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_12Hz_U8X: + if (duration > + C_BMG160_20ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_20ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_64Hz_U8X: + if (duration > + C_BMG160_10ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_10ms_AutoSleepDur_U8X; + } + break; + + case C_BMG160_BW_32Hz_U8X: + if (duration > + C_BMG160_20ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_20ms_AutoSleepDur_U8X; + } + break; + + default: + if (duration > + C_BMG160_4ms_AutoSleepDur_U8X) { + v_autosleepduration_u8r = \ + duration; + } + else { + v_autosleepduration_u8r = \ + C_BMG160_4ms_AutoSleepDur_U8X; + } + break; + } + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR, \ + v_autosleepduration_u8r); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODE_LPM2_ADDR_AUTOSLEEPDUR__REG, \ + &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to get data sleep duration +* +* +* +* +* \param unsigned char *duration : Address of sleep duration +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_sleepdur(unsigned char *duration) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr, \ + BMG160_MODELPM1_ADDR_SLEEPDUR__REG, &v_data_u8r, 1); + *duration = BMG160_GET_BITSLICE(v_data_u8r, \ + BMG160_MODELPM1_ADDR_SLEEPDUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************** +* Description: *//**\brief This API is used to set duration +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_sleepdur(unsigned char duration) +{ + BMG160_RETURN_FUNCTION_TYPE comres; + unsigned char v_data_u8r; + if (p_bmg160 == BMG160_NULL) { + comres = E_BMG160_NULL_PTR; + } + else { + if (duration < C_BMG160_Eight_U8X) { + comres = p_bmg160->BMG160_BUS_READ_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODELPM1_ADDR_SLEEPDUR__REG, \ + &v_data_u8r, 1); + v_data_u8r = BMG160_SET_BITSLICE(v_data_u8r, \ + BMG160_MODELPM1_ADDR_SLEEPDUR, duration); + comres = p_bmg160->BMG160_BUS_WRITE_FUNC \ + (p_bmg160->dev_addr, \ + BMG160_MODELPM1_ADDR_SLEEPDUR__REG, \ + &v_data_u8r, 1); + } + else { + comres = E_BMG160_OUT_OF_RANGE; + } + } + return comres; +} diff --git a/embedded/common/modules/sensor-drivers/acc_bmc150_i2c.c b/embedded/common/modules/sensor-drivers/acc_bmc150_i2c.c index aa674c6..a79ff64 100644 --- a/embedded/common/modules/sensor-drivers/acc_bmc150_i2c.c +++ b/embedded/common/modules/sensor-drivers/acc_bmc150_i2c.c @@ -43,7 +43,7 @@ extern uint32_t AccelTimeExtend; /*-------------------------------------------------------------------------------------------------*\ | P R I V A T E C O N S T A N T S & M A C R O S \*-------------------------------------------------------------------------------------------------*/ -#define delay_ms(msec) os_dly_wait(MSEC_TO_TICS(msec)) +#define delay_ms(msec) osDelay(msec)) #define PORT_ACCIRQREQ 4 #define PIN_ACCIRQREQ 11 #define ACCEL_INT_IRQCh PIN_INT0_IRQn diff --git a/embedded/common/modules/sensor-drivers/acc_lsm303dlhc_i2c.c b/embedded/common/modules/sensor-drivers/acc_lsm303dlhc_i2c.c index 4f5ce9e..fb767e6 100644 --- a/embedded/common/modules/sensor-drivers/acc_lsm303dlhc_i2c.c +++ b/embedded/common/modules/sensor-drivers/acc_lsm303dlhc_i2c.c @@ -40,7 +40,7 @@ /*-------------------------------------------------------------------------------------------------*\ | P R I V A T E C O N S T A N T S & M A C R O S \*-------------------------------------------------------------------------------------------------*/ -#define delay_ms(msec) os_dly_wait(MSEC_TO_TICS(msec)) +#define delay_ms(msec) osDelay(msec) /*-------------------------------------------------------------------------------------------------*\ | P R I V A T E T Y P E D E F I N I T I O N S diff --git a/embedded/common/modules/sensor-drivers/bma2x2.c b/embedded/common/modules/sensor-drivers/bma2x2.c index 8a22084..583ec9c 100644 --- a/embedded/common/modules/sensor-drivers/bma2x2.c +++ b/embedded/common/modules/sensor-drivers/bma2x2.c @@ -1,9126 +1,9140 @@ -/* - *************************************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - **************************************************************************************************/ -/* $Date: 2012/11/06 - * $Revision: 1.3 $ - * - */ - -/************************************************************************************************** -* Copyright (C) 2007 Bosch Sensortec GmbH -* -* bma2x2.c -* -* Usage: Sensor Driver for BMA2x2 Triaxial acceleration sensor -* -**************************************************************************************************/ -/*************************************************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. They may only be used - * within the parameters of the respective valid product data sheet. Bosch Sensortec products are - * provided with the express understanding that there is no warranty of fitness for a particular purpose. - * They are not fit for use in life-sustaining, safety or security sensitive systems or any system or device - * that may lead to bodily harm or property damage if the system or device malfunctions. In addition, - * Bosch Sensortec products are not fit for use in products which interact with motor vehicle systems. - * The resale and/or use of products are at the purchaser’s own risk and his own responsibility. The - * examination of fitness for the intended use is the sole responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party claims, including any claims for - * incidental, or consequential damages, arising from any product use not covered by the parameters of - * the respective valid product data sheet or not approved by Bosch Sensortec and reimburse Bosch - * Sensortec for all costs in connection with such claims. - * - * The purchaser must monitor the market for the purchased products, particularly with regard to - * product safety and inform Bosch Sensortec without delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary from the valid - * technical specifications of the product series. They are therefore not intended or fit for resale to third - * parties or for use in end products. Their sole purpose is internal client testing. The testing of an - * engineering sample may in no way replace the testing of a product series. Bosch Sensortec - * assumes no liability for the use of engineering samples. By accepting the engineering samples, the - * Purchaser agrees to indemnify Bosch Sensortec from all claims arising from the use of engineering - * samples. - * - * Special: - * This software module (hereinafter called "Software") and any information on application-sheets - * (hereinafter called "Information") is provided free of charge for the sole purpose to support your - * application work. The Software and Information is subject to the following terms and conditions: - * - * The Software is specifically designed for the exclusive use for Bosch Sensortec products by - * personnel who have special experience and training. Do not use this Software if you do not have the - * proper experience or training. - * - * This Software package is provided `` as is `` and without any expressed or implied warranties, - * including without limitation, the implied warranties of merchantability and fitness for a particular - * purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability for the functional impairment - * of this Software in terms of fitness, performance and safety. Bosch Sensortec and their - * representatives and agents shall not be liable for any direct or indirect damages or injury, except as - * otherwise stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. Bosch Sensortec assumes no - * responsibility for the consequences of use of such Information nor for any infringement of patents or - * other rights of third parties which may result from its use. No license is granted by implication or - * otherwise under any patent or patent rights of Bosch. Specifications mentioned in the Information are - * subject to change without notice. - * - * It is not allowed to deliver the source code of the Software to any third party without permission of - * Bosch Sensortec. - */ -/*************************************************************************************************/ -/*! \file - \brief */ -#include "bma2x2.h" -#include "sensorhub.h" -#include "common.h" -#include "acc_common.h" -#include "board.h" -#include "osp-sensors.h" -#include "sensacq_i2c.h" - -/* user defined code to be added here ... */ -static bma2x2_t *p_bma2x2; -const unsigned char V_BMA2x2RESOLUTION_U8R = BMA2x2_12_RESOLUTION; /* Based on Bit resolution value should be modified */ -/* Compiler Switch if applicable - #ifdef - - #endif - */ -static bma2x2_t bma2x2; - -static void accel_activate(bool enable) -{ - if (enable) { - bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power - bma2x2_set_range(BMA2x2_RANGE_4G); /* set range 4g for grange */ - bma2x2_set_bandwidth(BMA2x2_BW_31_25HZ); - - /* configure interrupt pin INT1 as data interrupt */ - bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); - bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); - bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); - /* enable data interrupt */ - bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); - /* configure INT2 pin */ - bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(ACCEL_PINT_IRQn); - NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); - } - else { - NVIC_DisableIRQ(ACCEL_PINT_IRQn); - bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); // Low power - } -} -void Accel_HardwareSetup(osp_bool_t enable) -{ - /* ACCEL INT1 irq setup */ - NVIC_DisableIRQ(ACCEL_PINT_IRQn); - NVIC_SetPriority(ACCEL_PINT_IRQn, SENSOR_IRQ_PRIORITY); - Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT_PORT, ACCEL_INT_PIN); - - Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN); - - - Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive and rising edge interrupt */ - Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH); - - //Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT2_PORT, ACCEL_INT2_PIN); - - Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */ - - //Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); - - -} -void Accel_Initialize(AccelInitOption option) -{ - bma2x2.bus_write = dev_i2c_write; - bma2x2.bus_read = dev_i2c_read; - bma2x2.delay_msec = dev_i2c_delay; - - bma2x2_init(&bma2x2); - bma2x2_soft_reset(); - dev_i2c_delay(1); - bma2x2_set_mode(BMA2x2_MODE_NORMAL); - bma2x2_set_range(BMA2x2_RANGE_4G); - /* accel_setDelay(pSens, 16); */ - bma2x2_set_bandwidth(BMA2x2_BW_62_50HZ); - - /* configure interrupt pin INT1 as data interrupt */ - bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); - bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); - bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); - /* enable data interrupt */ - bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); - /* configure INT2 pin */ - bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); - - bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); - - // QLY: Somehow on the LPC54102 platform, no accel interrupt if the following API is not call with argument 'true' - accel_activate(true); -} - -void Accel_ConfigDataInt(osp_bool_t enable) -{ - if (enable) { - bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power - bma2x2_set_range(BMA2x2_RANGE_4G); /* set range 4g for grange */ - /* Baccel_setDelay(pSens, 16); */ - - /* configure interrupt pin INT1 as data interrupt */ - bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); - bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); - bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); - /* enable data interrupt */ - bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); - /* configure INT2 pin */ - bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); - bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); - - NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(ACCEL_PINT_IRQn); - - } - else { - NVIC_DisableIRQ(ACCEL_PINT_IRQn); - bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); // Low power - } -} - -void Accel_ClearDataInt(void) -{ - /* Read to clear any pending interrupt */ - Accel_ReadData(NULL); -} - -void Accel_ReadData(MsgAccelData *accelData ) -{ - bma2x2acc_t bma; - bma2x2_read_accel_xyz(&bma); // get acceleration data from sensor - if (accelData) { - accelData->X = bma.x; - accelData->Y = bma.y; - accelData->Z = bma.z; - } - -} - -void ACCEL_IRQHandler(void) -{ - uint32_t currTime = GetCurrentTime(); -#if 0 - uint32_t currTime = g_Timer.GetCurrent(); - PhysicalSensor_t* pSens = g_phySensors[PHYS_ACCEL_ID]; - pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; - pSens->ts_lastSample = currTime; - - pSens->irq_pending++; - - Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); - ResMgr_IRQDone(); -#else - Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); - SendDataReadyIndication(ACCEL_INPUT_SENSOR, currTime); -#endif -} - -/******************************************************************************* - * Description: *//**\brief This API reads the data from the given register continously - * - * - * - * - * \param unsigned char addr, unsigned char *data - * addr -> Address of the register - * data -> address of the variable, read value will be kept - * \return results of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_burst_read(unsigned char addr, unsigned char *data, unsigned int len) -{ - BMA2x2_RETURN_FUNCTION_TYPE comres; - if (p_bma2x2 == BMA2x2_NULL) { - comres = E_BMA2x2_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BURST_READ_FUNC(p_bma2x2->dev_addr, addr, data, len); - } - return comres; -} - -/******************************************************************************* - * Description: *//**\brief - * This function initialises the structure pointer and assigns the I2C address. - * - * - * - * - * - * \param bma2x2_t *bma2x2 structure pointer. - * - * - * - * \return communication results. - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_init(bma2x2_t *bma2x2) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - - p_bma2x2 = bma2x2; /* assign bma2x2 ptr */ - p_bma2x2->dev_addr = BMA2x2_I2C_ADDR; /* preset bma2x2 I2C_addr */ - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CHIP_ID__REG, &data, 1); /* read Chip Id */ - p_bma2x2->chip_id = data; /* get bitslice */ - return comres; -} - -/******************************************************************************* - * Description: *//**\brief This API gives data to the given register and - * the data is written in the corresponding register address - * - * - * - * - * \param unsigned char addr, unsigned char data, unsigned char len - * addr -> Address of the register - * data -> Data to be written to the register - * len -> Length of the Data - * - * - * - * \return communication results. - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_write_reg(unsigned char addr, unsigned char *data, unsigned char len) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, addr, data, len); - } - return comres; -} - -/******************************************************************************* - * Description: *//**\brief This API reads the data from the given register address - * - * - * - * - * \param unsigned char addr, unsigned char *data, unsigned char len - * addr -> Address of the register - * data -> address of the variable, read value will be kept - * len -> Length of the data - * - * - * - * - * \return results of communication routine - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_read_reg(unsigned char addr, unsigned char *data, unsigned char len) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, addr, data, len); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API reads acceleration data X values - * from location 02h and 03h - * - * - * - * - * \param short *a_x : Address of a_x - * - * - * - * \return result of communication routines - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_read_accel_x(short *a_x) -{ - int comres = 0; - unsigned char data[2]; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (V_BMA2x2RESOLUTION_U8R) { - case BMA2x2_12_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 2); - *a_x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X12_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); - *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - break; - - case BMA2x2_10_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 2); - *a_x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X10_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); - *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - break; - - case BMA2x2_8_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 2); - *a_x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X8_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); - *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - break; - - case BMA2x2_14_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 2); - *a_x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X14_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); - *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - break; - - default: - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API reads acceleration data Y values - * from location 04h and 05h - * - * - * - * - * \param short *a_y : Address of a_y - * - * - * - * \return result of communication routines - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_read_accel_y(short *a_y) -{ - int comres = 0; - unsigned char data[2]; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (V_BMA2x2RESOLUTION_U8R) { - case BMA2x2_12_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y12_LSB__REG, data, 2); - *a_y = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Y12_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); - *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - break; - - case BMA2x2_10_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y10_LSB__REG, data, 2); - *a_y = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Y10_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); - *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - break; - - case BMA2x2_8_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y8_LSB__REG, data, 2); - *a_y = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Y8_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); - *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - break; - - case BMA2x2_14_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y14_LSB__REG, data, 2); - *a_y = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Y14_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); - *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - break; - - default: - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API reads acceleration data Z values - * from location 06h and 07h - * - * - * - * - * \param short *a_z : Address of a_z - * - * - * - * \return result of communication routines - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_read_accel_z(short *a_z) -{ - int comres = 0; - unsigned char data[2]; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (V_BMA2x2RESOLUTION_U8R) { - case BMA2x2_12_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z12_LSB__REG, data, 2); - *a_z = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Z12_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); - *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - case BMA2x2_10_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z10_LSB__REG, data, 2); - *a_z = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Z10_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); - *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - case BMA2x2_8_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z8_LSB__REG, data, 2); - *a_z = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Z8_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); - *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - case BMA2x2_14_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z14_LSB__REG, data, 2); - *a_z = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_Z14_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); - *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - default: - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API reads acceleration data X,Y,Z values - * from location 02h to 07h - * - * - * - * - * \param bma2x2acc_t * acc : Address of bma2x2acc_t - * - * - * - * \return result of communication routines - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_read_accel_xyz(bma2x2acc_t *acc) -{ - int comres = 0; - unsigned char data[6]; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (V_BMA2x2RESOLUTION_U8R) { - case BMA2x2_12_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 6); - - data[0] = BMA2x2_GET_BITSLICE(data[0], BMA2x2_ACC_X12_LSB); - acc->x = (short) (((unsigned short) data[1] << BMA2x2_ACC_X12_LSB__POS) | data[0]); - if (data[1] & 0x80) { - acc->x |= 0xf000; - } - - data[2] = BMA2x2_GET_BITSLICE(data[2], BMA2x2_ACC_Y12_LSB); - acc->y = (short) (((unsigned short) data[3] << BMA2x2_ACC_Y12_LSB__POS) | data[2]); - if (data[3] & 0x80) { - acc->y |= 0xf000; - } - - data[4] = BMA2x2_GET_BITSLICE(data[4], BMA2x2_ACC_Z12_LSB); - acc->z = (short) (((unsigned short) data[5] << BMA2x2_ACC_Z12_LSB__POS) | data[4]); - if (data[5] & 0x80) { - acc->z |= 0xf000; - } -#if 0 - - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X12_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y12_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z12_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); -#endif - - break; - - case BMA2x2_10_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 6); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X10_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y10_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z10_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - case BMA2x2_8_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 6); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X8_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y8_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z8_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - case BMA2x2_14_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 6); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X14_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y14_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z14_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - break; - - default: - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads tap slope status register byte - * from location 0Bh - * - * - * - * - * \param unsigned char * status_tap : Address of status_tap register - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_int_tap_status(unsigned char *status_tap) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_STATUS_TAP_SLOPE_REG, - status_tap, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads orient status register byte - * from location 0Ch - * - * - * - * - * \param unsigned char *status_orient : Address of status_orient register - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_int_orient_status(unsigned char *status_orient) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_STATUS_ORIENT_HIGH_REG, - status_orient, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads fifo status register byte - * from location 0Eh - * - * - * - * - * \param unsigned char *status_fifo : Address of status_fifo register - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_fifo_status(unsigned char *status_fifo) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_STATUS_FIFO_REG, - status_fifo, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads fifo framecount bits from location 0Eh - * - * - * - * - * \param unsigned char *framecount : Address of framecount - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_fifo_framecount(unsigned char *framecount) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_FRAME_COUNTER_S__REG, - &data, - C_BMA2x2_One_U8X); - *framecount = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_FRAME_COUNTER_S); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads fifo overrun bits from location 0Eh - * - * - * - * - * \param unsigned char *overrun : Address of overrun - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_fifo_overrun(unsigned char *overrun) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_OVERRUN_S__REG, &data, C_BMA2x2_One_U8X); - *overrun = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_OVERRUN_S); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API Reads interrupt status register byte - * from location 09h - * - * - * - * - * \param unsigned char * status : Address of status register - * - * - * - * \return Result of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_interrupt_status(unsigned char *status) -{ - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_STATUS1_REG, status, C_BMA2x2_Four_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************** - * Description: *//**\brief This API is used to get the Ranges(g values) of the sensor - * - * - * - * - * \param unsigned char * Range : Address of Range - * 3 -> 2G - * 5 -> 4G - * 8 -> 8G - * 12 -> 16G - * - * - * - * \return - * - * - ***************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_range(unsigned char *Range) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RANGE_SEL__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_GET_BITSLICE(data, BMA2x2_RANGE_SEL); - *Range = data; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*********************************************************************************** - * Description: *//**\brief This API is used to set Ranges(g value) of the sensor - * - * - * - * - * \param unsigned char Range - * 3 -> 2G - * 5 -> 4G - * 8 -> 8G - * 12 -> 16G - * - * \return communication results - * - * - ************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_set_range(unsigned char Range) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data1; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if ((Range == C_BMA2x2_Three_U8X) || (Range == C_BMA2x2_Five_U8X) || (Range == C_BMA2x2_Eight_U8X) || - (Range == C_BMA2x2_Twelve_U8X)) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RANGE_SEL_REG, &data1, C_BMA2x2_One_U8X); - switch (Range) { - case BMA2x2_RANGE_2G: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Three_U8X); - break; - - case BMA2x2_RANGE_4G: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Five_U8X); - break; - - case BMA2x2_RANGE_8G: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Eight_U8X); - break; - - case BMA2x2_RANGE_16G: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Twelve_U8X); - break; - - default: - break; - } - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_RANGE_SEL_REG, - &data1, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*********************************************************************************** - * Description: *//**\brief This API is used to get the bandwidth of the sensor - * - * - * - * - * \param unsigned char * BW : Address of * BW - * 8 -> 7.81HZ - * 9 -> 15.63HZ - * 10 -> 31.25HZ - * 11 -> 62.50HZ - * 12 -> 125HZ - * 13 -> 250HZ - * 14 -> 500HZ - * 15 -> 1000HZ - * - * - * - * \return - * - * - ************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_bandwidth(unsigned char *BW) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_BANDWIDTH__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_GET_BITSLICE(data, BMA2x2_BANDWIDTH); - *BW = data; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set Bandwidth of the sensor - * - * - * - * - * \param unsigned char BW - * 8 -> 7.81HZ - * 9 -> 15.63HZ - * 10 -> 31.25HZ - * 11 -> 62.50HZ - * 12 -> 125HZ - * 13 -> 250HZ - * 14 -> 500HZ - * 15 -> 1000HZ - * - * - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_set_bandwidth(unsigned char BW) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - int Bandwidth; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (p_bma2x2->chip_id == 0xFB) { - if (( BW > C_BMA2x2_Seven_U8X) && ( BW < C_BMA2x2_Fifteen_U8X) ) { - switch (BW) { - case BMA2x2_BW_7_81HZ: - Bandwidth = BMA2x2_BW_7_81HZ; - - /* 7.81 Hz 64000 uS */ - break; - - case BMA2x2_BW_15_63HZ: - Bandwidth = BMA2x2_BW_15_63HZ; - - /* 15.63 Hz 32000 uS */ - break; - - case BMA2x2_BW_31_25HZ: - Bandwidth = BMA2x2_BW_31_25HZ; - - /* 31.25 Hz 16000 uS */ - break; - - case BMA2x2_BW_62_50HZ: - Bandwidth = BMA2x2_BW_62_50HZ; - - /* 62.50 Hz 8000 uS */ - break; - - case BMA2x2_BW_125HZ: - Bandwidth = BMA2x2_BW_125HZ; - - /* 125 Hz 4000 uS */ - break; - - case BMA2x2_BW_250HZ: - Bandwidth = BMA2x2_BW_250HZ; - - /* 250 Hz 2000 uS */ - break; - - case BMA2x2_BW_500HZ: - Bandwidth = BMA2x2_BW_500HZ; - - /* 500 Hz 1000 uS */ - break; - - default: - break; - } - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_BANDWIDTH__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_BANDWIDTH, Bandwidth); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_BANDWIDTH__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - else { - if (( BW > C_BMA2x2_Seven_U8X) && ( BW < C_BMA2x2_Sixteen_U8X) ) { - switch (BW) { - case BMA2x2_BW_7_81HZ: - Bandwidth = BMA2x2_BW_7_81HZ; - - /* 7.81 Hz 64000 uS */ - break; - - case BMA2x2_BW_15_63HZ: - Bandwidth = BMA2x2_BW_15_63HZ; - - /* 15.63 Hz 32000 uS */ - break; - - case BMA2x2_BW_31_25HZ: - Bandwidth = BMA2x2_BW_31_25HZ; - - /* 31.25 Hz 16000 uS */ - break; - - case BMA2x2_BW_62_50HZ: - Bandwidth = BMA2x2_BW_62_50HZ; - - /* 62.50 Hz 8000 uS */ - break; - - case BMA2x2_BW_125HZ: - Bandwidth = BMA2x2_BW_125HZ; - - /* 125 Hz 4000 uS */ - break; - - case BMA2x2_BW_250HZ: - Bandwidth = BMA2x2_BW_250HZ; - - /* 250 Hz 2000 uS */ - break; - - case BMA2x2_BW_500HZ: - Bandwidth = BMA2x2_BW_500HZ; - - /* 500 Hz 1000 uS */ - break; - - case BMA2x2_BW_1000HZ: - Bandwidth = BMA2x2_BW_1000HZ; - - /* 1000 Hz 500 uS */ - break; - - default: - break; - } - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_BANDWIDTH__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_BANDWIDTH, Bandwidth); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_BANDWIDTH__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*************************************************************************************** - * Description: *//**\brief This API is used to get the operating modes of the sensor - * - * - * - * - * \param unsigned char * Mode : Address of Mode - * 0 -> NORMAL - * 1 -> LOWPOWER1 - * 2 -> SUSPEND - * 3 -> DEEP_SUSPEND - * 4 -> LOWPOWER2 - * 5 -> STANDBY - * - * - * - * \return - * - * - **************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_mode(unsigned char *Mode) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data1, data2; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_MODE_CTRL_REG, &data1, C_BMA2x2_One_U8X); - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_NOISE_CTRL_REG, &data2, C_BMA2x2_One_U8X); - - data1 = (data1 & 0xE0) >> 5; - data2 = (data2 & 0x40) >> 6; - - // *Mode = (*Mode) >> C_Six_U8X; - if ((data1 == 0x00) && (data2 == 0x00)) { - *Mode = BMA2x2_MODE_NORMAL; - } - else { - if ((data1 == 0x02) && (data2 == 0x00)) { - *Mode = BMA2x2_MODE_LOWPOWER1; - } - else { - if ((( data1 == 0x04) || ( data1 == 0x06) ) && (data2 == 0x00)) { - *Mode = BMA2x2_MODE_SUSPEND; - } - else { - if (((data1 & 0x01) == 0x01)) { - *Mode = BMA2x2_MODE_DEEP_SUSPEND; - } - else { - if ((data1 == 0x02) && (data2 == 0x01)) { - *Mode = BMA2x2_MODE_LOWPOWER2; - } - else { - if ((data1 == 0x04) && (data2 == 0x01)) { - *Mode = BMA2x2_MODE_STANDBY; - } - else { - *Mode = BMA2x2_MODE_DEEP_SUSPEND; - } - } - } - } - } - } - } - p_bma2x2->mode = *Mode; - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*************************************************************************************** -* Description: *//**\brief This API is used to set the operating Modes of the sensor -* -* -* -* -* \param unsigned char Mode -* 0 -> NORMAL -* 1 -> LOWPOWER1 -* 2 -> SUSPEND -* 3 -> DEEP_SUSPEND -* 4 -> LOWPOWER2 -* 5 -> STANDBY -* -* \return communication results -* -* -***************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -unsigned char bma2x2_set_mode(unsigned char Mode) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data1, data2; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (Mode < C_BMA2x2_Six_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_MODE_CTRL_REG, &data1, C_BMA2x2_One_U8X); - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - switch (Mode) { - case BMA2x2_MODE_NORMAL: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Zero_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_MODE_LOWPOWER1: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Two_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_MODE_SUSPEND: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Four_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_MODE_DEEP_SUSPEND: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_One_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_MODE_LOWPOWER2: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Two_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_MODE_STANDBY: - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Four_U8X); - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_LOW_NOISE_CTRL_REG, - &data2, - C_BMA2x2_One_U8X); - p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ - comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_MODE_CTRL_REG, - &data1, - C_BMA2x2_One_U8X); - break; - } - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************************** - * Description: *//**\brief This API is used to get the sleep duration status of the sensor - * - * - * - * - * \param unsigned char *sleep_dur : Address of sleep_dur - * 5 -> 0.5MS - * 6 -> 1MS - * 7 -> 2MS - * 8 -> 4MS - * 9 -> 6MS - * 10 -> 10MS - * 11 -> 25MS - * 12 -> 50MS - * 13 -> 100MS - * 14 -> 500MS - * 15 -> 1S - * - * - * - * \return - * - * - *********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleep_dur(unsigned char *sleep_dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - // SLEEP DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); - *sleep_dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLEEP_DUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************ - * Description: *//**\brief This API is used to set Sleep Duration of the sensor - * - * - * - * - * \param unsigned char sleep_dur - * 5 -> 0.5MS - * 6 -> 1MS - * 7 -> 2MS - * 8 -> 4MS - * 9 -> 6MS - * 10 -> 10MS - * 11 -> 25MS - * 12 -> 50MS - * 13 -> 100MS - * 14 -> 500MS - * 15 -> 1S - * - * - * \return communication results - * - * - **************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleep_dur(unsigned char sleep_dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - int sleep_duration = 0; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (( sleep_dur > C_BMA2x2_Four_U8X) && ( sleep_dur < C_BMA2x2_Sixteen_U8X) ) { - switch (sleep_dur) { - case BMA2x2_SLEEP_DUR_0_5MS: - sleep_duration = BMA2x2_SLEEP_DUR_0_5MS; - - /* 0.5 MS */ - break; - - case BMA2x2_SLEEP_DUR_1MS: - sleep_duration = BMA2x2_SLEEP_DUR_1MS; - - /* 1 MS */ - break; - - case BMA2x2_SLEEP_DUR_2MS: - sleep_duration = BMA2x2_SLEEP_DUR_2MS; - - /* 2 MS */ - break; - - case BMA2x2_SLEEP_DUR_4MS: - sleep_duration = BMA2x2_SLEEP_DUR_4MS; - - /* 4 MS */ - break; - - case BMA2x2_SLEEP_DUR_6MS: - sleep_duration = BMA2x2_SLEEP_DUR_6MS; - - /* 6 MS */ - break; - - case BMA2x2_SLEEP_DUR_10MS: - sleep_duration = BMA2x2_SLEEP_DUR_10MS; - - /* 10 MS */ - break; - - case BMA2x2_SLEEP_DUR_25MS: - sleep_duration = BMA2x2_SLEEP_DUR_25MS; - - /* 25 MS */ - break; - - case BMA2x2_SLEEP_DUR_50MS: - sleep_duration = BMA2x2_SLEEP_DUR_50MS; - - /* 50 MS */ - break; - - case BMA2x2_SLEEP_DUR_100MS: - sleep_duration = BMA2x2_SLEEP_DUR_100MS; - - /* 100 MS */ - break; - - case BMA2x2_SLEEP_DUR_500MS: - sleep_duration = BMA2x2_SLEEP_DUR_500MS; - - /* 500 MS */ - break; - - case BMA2x2_SLEEP_DUR_1S: - sleep_duration = BMA2x2_SLEEP_DUR_1S; - - /* 1 SECS */ - break; - - default: - break; - } - // SLEEP DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLEEP_DUR, sleep_duration); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the sleep timer mode status - * - * - * - * - * \param unsigned char *sleep_tmr : Address of sleep_tmr - * sleep_tmr -> [0:1] - * 0 => enable EventDrivenSampling(EDT) - * 1 => enable Eqidistant sampling mode(EST) - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleeptmr_mode(unsigned char *sleep_tmr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - // SLEEP TIMER MODE - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_TIMER__REG, &data, C_BMA2x2_One_U8X); - *sleep_tmr = BMA2x2_GET_BITSLICE(data, BMA2x2_SLEEP_TIMER); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the sleep timer mode status - * - * - * - * - * \param unsigned char sleep_tmr - * sleep_tmr -> [0:1] - * 0 => enable EventDrivenSampling(EDT) - * 1 => enable Eqidistant sampling mode(EST) - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleeptmr_mode(unsigned char sleep_tmr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (sleep_tmr < C_BMA2x2_Two_U8X) { - // SLEEP TIMER MODE - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLEEP_TIMER__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLEEP_TIMER, sleep_tmr); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLEEP_TIMER__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get high bandwidth - * - * - * - * - * \param unsigned char *high_bw : Address of high_bw - * 1 -> Unfiltered High Bandwidth - * 0 -> Filtered Low Bandwidth - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_high_bw(unsigned char *high_bw) -{ - { - char comres; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_DATA_HIGH_BW__REG, - &data, - C_BMA2x2_One_U8X); - *high_bw = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_DATA_HIGH_BW); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set high bandwidth - * - * - * - * - * \param unsigned char high_bw - * 1 -> Unfiltered High Bandwidth - * 0 -> Filtered Low Bandwidth - * - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_high_bw(unsigned char high_bw) -{ - { - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_DATA_HIGH_BW__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_DATA_HIGH_BW, high_bw); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_DATA_HIGH_BW__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get shadow dis - * - * - * - * - * \param unsigned char *shadow_dis : Address of shadow_dis - * 1 -> No MSB Locking - * 0 -> MSB is Locked - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_shadow_dis(unsigned char *shadow_dis) -{ - { - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_DIS_SHADOW_PROC__REG, - &data, - C_BMA2x2_One_U8X); - *shadow_dis = BMA2x2_GET_BITSLICE(data, BMA2x2_DIS_SHADOW_PROC); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set shadow dis - * - * - * - * - * \param unsigned char shadow_dis - * 1 -> No MSB Locking - * 0 -> MSB is Locked - * - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_shadow_dis(unsigned char shadow_dis) -{ - { - int comres = C_BMA2x2_Zero_U8X; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_DIS_SHADOW_PROC__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_DIS_SHADOW_PROC, shadow_dis); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_DIS_SHADOW_PROC__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief - * This function is used for the soft reset - * The soft reset register will be written with 0xB6. - * - * - * - * \param None - * - * - * - * \return Communication results. - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_soft_reset(void) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data = BMA2x2_EN_SOFT_RESET_VALUE; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_REG, &data, C_BMA2x2_One_U8X);/* To reset the sensor 0xB6 value will be written */ - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to update the register values - * - * - * - * - * \param - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_update_image(void) -{ - int comres; - unsigned char data = 0; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_UPDATE_IMAGE__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UPDATE_IMAGE, C_BMA2x2_One_U8X); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_UPDATE_IMAGE__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/**************************************************************************************** -* Description: *//**\brief This API is used to set interrupt enable bits of the sensor -* -* -* -* -* \param unsigned char InterruptType , unsigned char value -* 0 -> Low_G_Interrupt -* 1 -> High_G_X_Interrupt -* 2 -> High_G_Y_Interrupt -* 3 -> High_G_Z_Interrupt -* 4 -> DATA_EN -* 5 -> Slope_X_Interrupt -* 6 -> Slope_Y_Interrupt -* 7 -> Slope_Z_Interrupt -* 8 -> Single_Tap_Interrupt -* 9 -> Double_Tap_Interrupt -* 10 -> Orient_Interrupt -* 11 -> Flat_Interrupt -* -* -* -* -* \return communication results -* -* -****************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_set_Int_Enable(unsigned char InterruptType, unsigned char value) -{ - int comres = C_BMA2x2_Zero_U8X; - unsigned char data1, data2; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE1_REG, &data1, C_BMA2x2_One_U8X); - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE2_REG, &data2, C_BMA2x2_One_U8X); - - value = value & C_BMA2x2_One_U8X; - switch (InterruptType) { - case BMA2x2_Low_G_Interrupt: - /* Low G Interrupt */ - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_LOWG_INT, value); - break; - - case BMA2x2_High_G_X_Interrupt: - /* High G X Interrupt */ - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_X_INT, value); - break; - - case BMA2x2_High_G_Y_Interrupt: - /* High G Y Interrupt */ - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_Y_INT, value); - break; - - case BMA2x2_High_G_Z_Interrupt: - /* High G Z Interrupt */ - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_Z_INT, value); - break; - - case BMA2x2_DATA_EN: - /*Data En Interrupt */ - data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_NEW_DATA_INT, value); - break; - - case BMA2x2_Slope_X_Interrupt: - /* Slope X Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_X_INT, value); - break; - - case BMA2x2_Slope_Y_Interrupt: - /* Slope Y Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_Y_INT, value); - break; - - case BMA2x2_Slope_Z_Interrupt: - /* Slope Z Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_Z_INT, value); - break; - - case BMA2x2_Single_Tap_Interrupt: - /* Single Tap Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SINGLE_TAP_INT, value); - break; - - case BMA2x2_Double_Tap_Interrupt: - /* Double Tap Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_DOUBLE_TAP_INT, value); - break; - - case BMA2x2_Orient_Interrupt: - /* Orient Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_ORIENT_INT, value); - break; - - case BMA2x2_Flat_Interrupt: - /* Flat Interrupt */ - data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_FLAT_INT, value); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE1_REG, &data1, C_BMA2x2_One_U8X); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE2_REG, &data2, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the interrupt ffull enable status - * - * - * - * - * \param unsigned char *ffull : Address of ffull - * ffull -> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_ffull(unsigned char *ffull) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_FFULL_EN_INT__REG, - &data, - C_BMA2x2_One_U8X); - *ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_FFULL_EN_INT); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the interrupt ffull enable status - * - * - * - * - * \param unsigned char ffull - * ffull -> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_ffull(unsigned char ffull) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (ffull < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_FFULL_EN_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_FFULL_EN_INT, ffull); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_FFULL_EN_INT__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************** - * Description: *//**\brief This API is used to get the interrupt fwm enable status - * - * - * - * - * \param unsigned char *fwm : Address of fwm - * fwm -> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - *************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_fwm(unsigned char *fwm) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_FWM_EN_INT__REG, &data, C_BMA2x2_One_U8X); - *fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_FWM_EN_INT); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************* -* Description: *//**\brief This API is used to set the interrupt fwm enable status -* -* -* -* -* \param unsigned char fwm -* fwm -> [0:1] -* 0 --> Clear -* 1 --> Set -* -* -* -* \return communication results -* -* -*************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_fwm(unsigned char fwm) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (fwm < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_FWM_EN_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_FWM_EN_INT, fwm); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_FWM_EN_INT__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************************* - * Description: *//**\brief This API is used to get the status of slow/no motion interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *slo_data - * channel --> - * BMA2x2_SLO_NO_MOT_EN_X -> 0 - * BMA2x2_SLO_NO_MOT_EN_Y -> 1 - * BMA2x2_SLO_NO_MOT_EN_Z -> 2 - * BMA2x2_SLO_NO_MOT_EN_SEL -> 3 - * slo_data --> 1 - * - * - * - * \return - * - * - **********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slo_no_mot(unsigned char channel, unsigned char *slo_data) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SLO_NO_MOT_EN_X: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, - &data, - C_BMA2x2_One_U8X); - *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_X_INT); - break; - - case BMA2x2_SLO_NO_MOT_EN_Y: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, - &data, - C_BMA2x2_One_U8X); - *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Y_INT); - break; - - case BMA2x2_SLO_NO_MOT_EN_Z: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, - &data, - C_BMA2x2_One_U8X); - *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Z_INT); - break; - - case BMA2x2_SLO_NO_MOT_EN_SEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, - &data, - C_BMA2x2_One_U8X); - *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************************** - * Description: *//**\brief This API is used to set the status of slow/no motion interrupt - * - * - * - * - * \param unsigned char channel,unsigned char slo_data - * channel --> - * BMA2x2_SLO_NO_MOT_EN_X -> 0 - * BMA2x2_SLO_NO_MOT_EN_Y -> 1 - * BMA2x2_SLO_NO_MOT_EN_Z -> 2 - * BMA2x2_SLO_NO_MOT_EN_SEL -> 3 - * slo_data --> 1 - * - * - * - * \return communication results - * - * - *******************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slo_no_mot(unsigned char channel, unsigned char slo_data) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SLO_NO_MOT_EN_X: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_X_INT, slo_data); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLO_NO_MOT_EN_Y: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Y_INT, slo_data); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLO_NO_MOT_EN_Z: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Z_INT, slo_data); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLO_NO_MOT_EN_SEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT, slo_data); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************* - * Description: *//**\brief This API is used to get the status of low interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *int_low - * channel --> - * BMA2x2_INT1_LOWG -> 0 - * BMA2x2_INT2_LOWG -> 1 - * int_low --> 1 - * - * - * - * \return - * - * - ********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_low(unsigned char channel, unsigned char *int_low) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - *int_low = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_LOWG); - break; - - case BMA2x2_INT2_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - *int_low = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_LOWG); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************* - * Description: *//**\brief This API is used to set the status of low interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_low - * channel --> - * BMA2x2_INT1_LOWG -> 0 - * BMA2x2_INT2_LOWG -> 1 - * int_low --> 1 - * - * - * - * \return communication results - * - * - ********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_low(unsigned char channel, unsigned char int_low) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_LOWG, int_low); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_LOWG, int_low); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************* - * Description: *//**\brief This API is used to get the status of high interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *int_high - * channel --> - * BMA2x2_INT1_HIGHG -> 0 - * BMA2x2_INT2_HIGHG -> 1 - * int_high --> 1 - * - * - * - * \return - * - * - ********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_high(unsigned char channel, unsigned char *int_high) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - *int_high = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_HIGHG); - break; - - case BMA2x2_INT2_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - *int_high = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_HIGHG); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************* - * Description: *//**\brief This API is used to set the status of high interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_high - * channel --> - * BMA2x2_INT1_HIGHG -> 0 - * BMA2x2_INT2_HIGHG -> 1 - * int_high --> 1 - * - * - * - * \return communication results - * - * - ********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_high(unsigned char channel, unsigned char int_high) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_HIGHG, int_high); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_HIGHG, int_high); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************** - * Description: *//**\brief This API is used to get the status of slope interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *int_slope - * channel --> - * BMA2x2_INT1_SLOPE -> 0 - * BMA2x2_INT2_SLOPE -> 1 - * int_slope --> 1 - * - * - * - * \return - * - * - *********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slope(unsigned char channel, unsigned char *int_slope) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - *int_slope = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLOPE); - break; - - case BMA2x2_INT2_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - *int_slope = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLOPE); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************** - * Description: *//**\brief This API is used to set the status of slope interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_slope - * channel --> - * BMA2x2_INT1_SLOPE -> 0 - * BMA2x2_INT2_SLOPE -> 1 - * int_slope --> 1 - * - * - * \return communication results - * - * - *********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slope(unsigned char channel, unsigned char int_slope) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLOPE, int_slope); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLOPE, int_slope); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************************* -* Description: *//**\brief This API is used to get the status of slow/no motion interrupt -* -* -* -* -* \param unsigned char channel,unsigned char *int_slo_no_mot -* channel --> -* BMA2x2_INT1_SLO_NO_MOT -> 0 -* BMA2x2_INT2_SLO_NO_MOT -> 1 -* int_slo_no_mot --> 1 -* -* -* -* \return -* -* -*********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slo_no_mot(unsigned char channel, unsigned char *int_slo_no_mot) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - *int_slo_no_mot = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLO_NO_MOT); - break; - - case BMA2x2_INT2_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - *int_slo_no_mot = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLO_NO_MOT); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************************* - * Description: *//**\brief This API is used to set the status of slow/no motion interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_slo_no_mot - * channel --> - * BMA2x2_INT1_SLO_NO_MOT -> 0 - * BMA2x2_INT2_SLO_NO_MOT -> 1 - * int_slo_no_mot --> 1 - * - * - * - * \return communication results - * - * - **********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slo_no_mot(unsigned char channel, unsigned char int_slo_no_mot) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLO_NO_MOT, int_slo_no_mot); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLO_NO_MOT, int_slo_no_mot); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************************** - * Description: *//**\brief This API is used to get the status of double tap interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *int_d_tap - * channel --> - * BMA2x2_INT1_DTAP -> 0 - * BMA2x2_INT2_DTAP -> 1 - * int_d_tap --> 1 - * - * - * - * \return - * - * - ****************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_d_tap(unsigned char channel, unsigned char *int_d_tap) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_DTAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - *int_d_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_DB_TAP); - break; - - case BMA2x2_INT2_DTAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - *int_d_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_DB_TAP); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/**************************************************************************************** - * Description: *//**\brief This API is used to set the status of double tap interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_d_tap - * channel --> - * BMA2x2_INT1_DTAP -> 0 - * BMA2x2_INT2_DTAP -> 1 - * int_d_tap --> 1 - * - * - * - * \return communication results - * - * - *****************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_d_tap(unsigned char channel, unsigned char int_d_tap) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_DTAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_DB_TAP, int_d_tap); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_DTAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_DB_TAP, int_d_tap); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_DB_TAP__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*************************************************************************************** -* Description: *//**\brief This API is used to get the status of single tap interrupt -* -* -* -* -* \param unsigned char channel,unsigned char *int_s_tap -* channel --> -* BMA2x2_INT1_STAP -> 0 -* BMA2x2_INT2_STAP -> 1 -* int_s_tap --> 1 -* -* -* -* \return -* -* -***************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_s_tap(unsigned char channel, unsigned char *int_s_tap) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_STAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - *int_s_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SNG_TAP); - break; - - case BMA2x2_INT2_STAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - *int_s_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SNG_TAP); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/**************************************************************************************** -* Description: *//**\brief This API is used to set the status of single tap interrupt -* -* -* -* -* \param unsigned char channel,unsigned char int_s_tap -* channel --> -* BMA2x2_INT1_STAP -> 0 -* BMA2x2_INT2_STAP -> 1 -* int_s_tap --> 1 -* -* -* -* \return communication results -* -* -****************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_s_tap(unsigned char channel, unsigned char int_s_tap) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_STAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SNG_TAP, int_s_tap); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_STAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SNG_TAP, int_s_tap); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_SNG_TAP__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************** -* Description: *//**\brief This API is used to get the status of orient interrupt -* -* -* -* -* \param unsigned char channel,unsigned char *int_orient -* channel --> -* BMA2x2_INT1_ORIENT -> 0 -* BMA2x2_INT2_ORIENT -> 1 -* int_orient --> 1 -* -* -* -* \return -* -* -**************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_orient(unsigned char channel, unsigned char *int_orient) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_ORIENT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - *int_orient = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_ORIENT); - break; - - case BMA2x2_INT2_ORIENT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - *int_orient = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_ORIENT); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/************************************************************************************* - * Description: *//**\brief This API is used to set the status of orient interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_orient - * channel --> - * BMA2x2_INT1_ORIENT -> 0 - * BMA2x2_INT2_ORIENT -> 1 - * int_orient --> 1 - * - * - * - * \return communication results - * - * - ************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_orient(unsigned char channel, unsigned char int_orient) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_ORIENT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_ORIENT, int_orient); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_ORIENT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_ORIENT, int_orient); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_ORIENT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************** - * Description: *//**\brief This API is used to get the status of flat interrupt - * - * - * - * - * \param unsigned char channel,unsigned char *int_flat - * channel --> - * BMA2x2_INT1_FLAT -> 0 - * BMA2x2_INT2_FLAT -> 1 - * int_flat --> 1 - * - * - * - * \return - * - * - *********************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_flat(unsigned char channel, unsigned char *int_flat) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_FLAT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - *int_flat = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FLAT); - break; - - case BMA2x2_INT2_FLAT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - *int_flat = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FLAT); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of flat interrupt - * - * - * - * - * \param unsigned char channel,unsigned char int_flat - * channel --> - * BMA2x2_INT1_FLAT -> 0 - * BMA2x2_INT2_FLAT -> 1 - * int_flat --> 1 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_flat(unsigned char channel, unsigned char int_flat) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_FLAT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FLAT, int_flat); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_FLAT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FLAT, int_flat); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of new data - * - * - * - * - * \param unsigned char channel,unsigned char *int_newdata - * channel --> - * BMA2x2_INT1_NDATA -> 0 - * BMA2x2_INT2_NDATA -> 1 - * int_newdata --> 1 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_newdata(unsigned char channel, unsigned char *int_newdata) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_NDATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - *int_newdata = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_NEWDATA); - break; - - case BMA2x2_INT2_NDATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - *int_newdata = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_NEWDATA); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of new data - * - * - * - * - * \param unsigned char channel,unsigned char int_newdata - * channel --> - * BMA2x2_INT1_NDATA -> 0 - * BMA2x2_INT2_NDATA -> 1 - * int_newdata --> 1 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_newdata(unsigned char channel, unsigned char int_newdata) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_NDATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_NEWDATA, int_newdata); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_NDATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_NEWDATA, int_newdata); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_NEWDATA__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the fwm interrupt1 data - * - * - * - * - * \param unsigned char *int1_fwm : Address of int1_fwm - * int1_fwm --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_fwm(unsigned char *int1_fwm) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - *int1_fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FWM); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the fwm interrupt1 data - * - * - * - * - * \param unsigned char int1_fwm - * int1_fwm --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_fwm(unsigned char int1_fwm) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (int1_fwm < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FWM, int1_fwm); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the fwm interrupt2 data - * - * - * - * - * \param unsigned char*int2_fwm : Address of int2_fwm - * int2_fwm[0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_fwm(unsigned char *int2_fwm) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - *int2_fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FWM); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the fwm interrupt2 data - * - * - * - * - * \param unsigned char int2_fwm - * int2_fwm --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_fwm(unsigned char int2_fwm) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (int2_fwm < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FWM, int2_fwm); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FWM__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the ffull interrupt1 data - * - * - * - * - * \param unsigned char *int1_ffull : Address of int1_ffull - * int1_ffull --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_ffull(unsigned char *int1_ffull) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - *int1_ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FFULL); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the ffull interrupt1 data - * - * - * - * - * \param unsigned char int1_ffull - * int1_ffull --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_ffull(unsigned char int1_ffull) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (int1_ffull < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FFULL, int1_ffull); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT1_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the ffull interrupt2 data - * - * - * - * - * \param unsigned char *int2_ffull : Address of int2_ffull - * int2_ffull --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_ffull(unsigned char *int2_ffull) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - *int2_ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FFULL); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the ffull interrupt2 data - * - * - * - * - * \param unsigned char int2_ffull - * int2_ffull --> [0:1] - * 0 --> Clear - * 1 --> Set - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_ffull(unsigned char int2_ffull) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (int2_ffull < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FFULL, int2_ffull); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_INT2_PAD_FFULL__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the source status data - * - * - * - * - * \param unsigned char channel,unsigned char *int_source - * Channel -> - * BMA2x2_SRC_LOWG 0 - * BMA2x2_SRC_HIGHG 1 - * BMA2x2_SRC_SLOPE 2 - * BMA2x2_SRC_SLO_NO_MOT 3 - * BMA2x2_SRC_TAP 4 - * BMA2x2_SRC_DATA 5 - * int_source -> 1 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_source(unsigned char channel, unsigned char *int_source) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SRC_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_LOWG); - break; - - case BMA2x2_SRC_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_HIGHG); - break; - - case BMA2x2_SRC_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLOPE); - break; - - case BMA2x2_SRC_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT); - break; - - case BMA2x2_SRC_TAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_TAP__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_TAP); - break; - - case BMA2x2_SRC_DATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_DATA__REG, - &data, - C_BMA2x2_One_U8X); - *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_DATA); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set source status data - * - * - * - * - * \param unsigned char channel,unsigned char int_source - * Channel -> - * BMA2x2_SRC_LOWG 0 - * BMA2x2_SRC_HIGHG 1 - * BMA2x2_SRC_SLOPE 2 - * BMA2x2_SRC_SLO_NO_MOT 3 - * BMA2x2_SRC_TAP 4 - * BMA2x2_SRC_DATA 5 - * int_source -> 1 - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_source(unsigned char channel, unsigned char int_source) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SRC_LOWG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_LOWG, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_LOWG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SRC_HIGHG: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_HIGHG, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_HIGHG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SRC_SLOPE: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLOPE, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLOPE__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SRC_SLO_NO_MOT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SRC_TAP: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_TAP__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_TAP, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_TAP__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SRC_DATA: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_DATA__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_DATA, int_source); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNFILT_INT_SRC_DATA__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the output type status - * - * - * - * - * \param unsigned char channel,unsigned char *int_od - * BMA2x2_INT1_OUTPUT -> 0 - * BMA2x2_INT2_OUTPUT -> 1 - * int_od : open drain -> 1 - * push pull -> 0 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_od(unsigned char channel, unsigned char *int_od) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_OUTPUT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - *int_od = BMA2x2_GET_BITSLICE(data, BMA2x2_INT1_PAD_OUTPUT_TYPE); - break; - - case BMA2x2_INT2_OUTPUT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - *int_od = BMA2x2_GET_BITSLICE(data, BMA2x2_INT2_PAD_OUTPUT_TYPE); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the output type status - * - * - * - * - * \param unsigned char channel,unsigned char int_od - * BMA2x2_INT1_OUTPUT -> 0 - * BMA2x2_INT2_OUTPUT -> 1 - * int_od : open drain -> 1 - * push pull -> 0 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_od(unsigned char channel, unsigned char int_od) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_OUTPUT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT1_PAD_OUTPUT_TYPE, int_od); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_OUTPUT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT2_PAD_OUTPUT_TYPE, int_od); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get Active Level status - * - * - * - * - * \param unsigned char channel,unsigned char *int_lvl - * BMA2x2_INT1_LEVEL -> 0 - * BMA2x2_INT2_LEVEL -> 1 - * int_lvl : Active HI -> 1 - * Active LO -> 0 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_lvl(unsigned char channel, unsigned char *int_lvl) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_LEVEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - *int_lvl = BMA2x2_GET_BITSLICE(data, BMA2x2_INT1_PAD_ACTIVE_LEVEL); - break; - - case BMA2x2_INT2_LEVEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - *int_lvl = BMA2x2_GET_BITSLICE(data, BMA2x2_INT2_PAD_ACTIVE_LEVEL); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set Active Level status - * - * - * - * - * \param (unsigned char channel,unsigned char int_lvl) - * BMA2x2_INT1_LEVEL -> 0 - * BMA2x2_INT2_LEVEL -> 1 - * int_lvl : Active HI -> 1 - * Active LO -> 0 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_lvl(unsigned char channel, unsigned char int_lvl) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_INT1_LEVEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT1_PAD_ACTIVE_LEVEL, int_lvl); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_INT2_LEVEL: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT2_PAD_ACTIVE_LEVEL, int_lvl); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the reset interrupt - * - * - * - * - * \param unsigned char reset_int - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_reset_interrupt(unsigned char reset_int) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_INT__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_RESET_INT, reset_int); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_INT__REG, &data, C_BMA2x2_One_U8X); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the latch duration - * - * - * - * - * \param unsigned char *latch_int : Address of latch_int - * 0 -> NON_LATCH - * 1 -> 250MS - * 2 -> 500MS - * 3 -> 1S - * 4 -> 2S - * 5 -> 4S - * 6 -> 8S - * 7 -> LATCH - * 8 -> NON_LATCH1 - * 9 -> 250US - * 10 -> 500US - * 11 -> 1MS - * 12 -> 12.5MS - * 13 -> 25MS - * 14 -> 50MS - * 15 -> LATCH1 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_latch_int(unsigned char *latch_int) -{ - { - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); - *latch_int = BMA2x2_GET_BITSLICE(data, BMA2x2_LATCH_INT); - } - return comres; - } -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the latch duration - * - * - * - * - * \param unsigned char latch_int - * 0 -> NON_LATCH - * 1 -> 250MS - * 2 -> 500MS - * 3 -> 1S - * 4 -> 2S - * 5 -> 4S - * 6 -> 8S - * 7 -> LATCH - * 8 -> NON_LATCH1 - * 9 -> 250US - * 10 -> 500US - * 11 -> 1MS - * 12 -> 12.5MS - * 13 -> 25MS - * 14 -> 50MS - * 15 -> LATCH1 - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_latch_int(unsigned char latch_int) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - int latch_duration = 0; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (latch_int < C_BMA2x2_Sixteen_U8X) { - switch (latch_int) { - case BMA2x2_LATCH_DUR_NON_LATCH: - latch_duration = BMA2x2_LATCH_DUR_NON_LATCH; - - /* NON LATCH */ - break; - - case BMA2x2_LATCH_DUR_250MS: - latch_duration = BMA2x2_LATCH_DUR_250MS; - - /* 250 MS */ - break; - - case BMA2x2_LATCH_DUR_500MS: - latch_duration = BMA2x2_LATCH_DUR_500MS; - - /* 500 MS */ - break; - - case BMA2x2_LATCH_DUR_1S: - latch_duration = BMA2x2_LATCH_DUR_1S; - - /* 1 S */ - break; - - case BMA2x2_LATCH_DUR_2S: - latch_duration = BMA2x2_LATCH_DUR_2S; - - /* 2 S */ - break; - - case BMA2x2_LATCH_DUR_4S: - latch_duration = BMA2x2_LATCH_DUR_4S; - - /* 4 S */ - break; - - case BMA2x2_LATCH_DUR_8S: - latch_duration = BMA2x2_LATCH_DUR_8S; - - /* 8 S */ - break; - - case BMA2x2_LATCH_DUR_LATCH: - latch_duration = BMA2x2_LATCH_DUR_LATCH; - - /* LATCH */ - break; - - case BMA2x2_LATCH_DUR_NON_LATCH1: - latch_duration = BMA2x2_LATCH_DUR_NON_LATCH1; - - /* NON LATCH1 */ - break; - - case BMA2x2_LATCH_DUR_250US: - latch_duration = BMA2x2_LATCH_DUR_250US; - - /* 250 US */ - break; - - case BMA2x2_LATCH_DUR_500US: - latch_duration = BMA2x2_LATCH_DUR_500US; - - /* 500 US */ - break; - - case BMA2x2_LATCH_DUR_1MS: - latch_duration = BMA2x2_LATCH_DUR_1MS; - - /* 1 MS */ - break; - - case BMA2x2_LATCH_DUR_12_5MS: - latch_duration = BMA2x2_LATCH_DUR_12_5MS; - - /* 12.5 MS */ - break; - - case BMA2x2_LATCH_DUR_25MS: - latch_duration = BMA2x2_LATCH_DUR_25MS; - - /* 25 MS */ - break; - - case BMA2x2_LATCH_DUR_50MS: - latch_duration = BMA2x2_LATCH_DUR_50MS; - - /* 50 MS */ - break; - - case BMA2x2_LATCH_DUR_LATCH1: - latch_duration = BMA2x2_LATCH_DUR_LATCH1; - - /* LATCH1 */ - break; - - default: - break; - } - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_LATCH_INT, latch_duration); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get duration - * - * - * - * - * \param unsigned char channel,unsigned char *dur - * BMA2x2_LOW_DURATION 0,1 - * BMA2x2_HIGH_DURATION 1,2 - * BMA2x2_SLOPE_DURATION 2,3 - * BMA2x2_SLO_NO_MOT_DURATION 3,4 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_dur(unsigned char channel, unsigned char *dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOW_DURATION: - // LOW DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_DURN_REG, &data, C_BMA2x2_One_U8X); - *dur = data; - break; - - case BMA2x2_HIGH_DURATION: - // HIGH DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_DURN_REG, &data, C_BMA2x2_One_U8X); - *dur = data; - break; - - case BMA2x2_SLOPE_DURATION: - // SLOPE DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); - *dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLOPE_DUR); - break; - - case BMA2x2_SLO_NO_MOT_DURATION: - // SLO NO MOT DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLO_NO_MOT_DUR__REG, - &data, - C_BMA2x2_One_U8X); - *dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set duration - * - * - * - * - * \param unsigned char channel,unsigned char dur - * BMA2x2_LOW_DURATION 0,1 - * BMA2x2_HIGH_DURATION 1,2 - * BMA2x2_SLOPE_DURATION 2,3 - * BMA2x2_SLO_NO_MOT_DURATION 3,4 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_dur(unsigned char channel, unsigned char dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOW_DURATION: - // LOW DURATION - data = dur; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_DURN_REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_HIGH_DURATION: - // HIGH DURATION - data = dur; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_DURN_REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLOPE_DURATION: - // SLOPE DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLOPE_DUR, dur); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLO_NO_MOT_DURATION: - // SLO NO MOT DURATION - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLO_NO_MOT_DUR__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR, dur); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLO_NO_MOT_DUR__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get threshold - * - * - * - * - * \param unsigned char channel,unsigned char *thr - * BMA2x2_LOW_THRESHOLD 0,FE - * BMA2x2_HIGH_THRESHOLD 1,01 - * BMA2x2_SLOPE_THRESHOLD 2,01 - * BMA2x2_SLO_NO_MOT_THRESHOLD 3,00 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_thr(unsigned char channel, unsigned char *thr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOW_THRESHOLD: - // LOW THRESHOLD - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_THRES_REG, &data, C_BMA2x2_One_U8X); - *thr = data; - break; - - case BMA2x2_HIGH_THRESHOLD: - // HIGH THRESHOLD - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_THRES_REG, &data, C_BMA2x2_One_U8X); - *thr = data; - break; - - case BMA2x2_SLOPE_THRESHOLD: - // SLOPE THRESHOLD - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_THRES_REG, &data, C_BMA2x2_One_U8X); - *thr = data; - break; - - case BMA2x2_SLO_NO_MOT_THRESHOLD: - // SLO NO MOT THRESHOLD - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLO_NO_MOT_THRES_REG, - &data, - C_BMA2x2_One_U8X); - *thr = data; - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set threshold - * - * - * - * - * \param unsigned char channel,unsigned char thr - * BMA2x2_LOW_THRESHOLD 0,FE - * BMA2x2_HIGH_THRESHOLD 1,01 - * BMA2x2_SLOPE_THRESHOLD 2,01 - * BMA2x2_SLO_NO_MOT_THRESHOLD 3,00 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_thr(unsigned char channel, unsigned char thr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOW_THRESHOLD: - // LOW THRESHOLD - data = thr; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_THRES_REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_HIGH_THRESHOLD: - // HIGH THRESHOLD - data = thr; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_THRES_REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLOPE_THRESHOLD: - // SLOPE THRESHOLD - data = thr; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLOPE_THRES_REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLO_NO_MOT_THRESHOLD: - // SLO NO MOT THRESHOLD - data = thr; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_SLO_NO_MOT_THRES_REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get low high hysteresis - * - * - * - * - * \param unsigned char channel,unsigned char *hyst - * channel --> - * BMA2x2_LOWG_HYST 0 - * BMA2x2_HIGHG_HYST 1 - * hyst --> 1 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst(unsigned char channel, unsigned char *hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOWG_HYST: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); - *hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_LOWG_HYST); - break; - - case BMA2x2_HIGHG_HYST: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGHG_HYST__REG, &data, C_BMA2x2_One_U8X); - *hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_HIGHG_HYST); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set low high hysteresis - * - * - * - * - * \param (unsigned char channel,unsigned char hyst) - * channel --> - * BMA2x2_LOWG_HYST 0 - * BMA2x2_HIGHG_HYST 1 - * hyst --> 1 - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst(unsigned char channel, unsigned char hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_LOWG_HYST: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_LOWG_HYST, hyst); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_HIGHG_HYST: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_HIGHG_HYST__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_HIGHG_HYST, hyst); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_HIGHG_HYST__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get low high hysteresis mode - * - * - * - * - * \param unsigned char *mode - * 0 -> single mode - * 1 -> sum mode - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst_mode(unsigned char *mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); - *mode = BMA2x2_GET_BITSLICE(data, BMA2x2_LOWG_INT_MODE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set low high hysteresis mode - * - * - * - * - * \param (unsigned char mode) - * 0 -> single mode - * 1 -> sum mode - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst_mode(unsigned char mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_LOWG_INT_MODE, mode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get tap duration - * - * - * - * - * \param unsigned char *tap_dur : Address of tap_dur - * 0 -> 50ms - * 1 -> 100ms - * 2 -> 150ms - * 3 -> 200ms - * 4 -> 250ms - * 5 -> 375ms - * 6 -> 500ms - * 7 -> 700ms - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_dur(unsigned char *tap_dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); - *tap_dur = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_DUR); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set tap duration - * - * - * - * - * \param unsigned char tap_dur - * 0 -> 50ms - * 1 -> 100ms - * 2 -> 150ms - * 3 -> 200ms - * 4 -> 250ms - * 5 -> 375ms - * 6 -> 500ms - * 7 -> 700ms - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_dur(unsigned char tap_dur) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_DUR, tap_dur); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get tap shock - * - * - * - * - * \param unsigned char *tap_shock : Address of tap_shock - * 0 -> 50ms - * 1 -> 75ms - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_shock(unsigned char *tap_shock) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SHOCK_DURN__REG, &data, C_BMA2x2_One_U8X); - *tap_shock = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_SHOCK_DURN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set tap shock - * - * - * - * - * \param unsigned char tap_shock - * 0 -> 50ms - * 1 -> 75ms - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_shock(unsigned char tap_shock) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SHOCK_DURN__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_SHOCK_DURN, tap_shock); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_TAP_SHOCK_DURN__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get tap quiet - * - * - * - * - * \param unsigned char *tap_quiet : Address of tap_quiet - * 0 -> 30ms - * 1 -> 20ms - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_quiet(unsigned char *tap_quiet) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_QUIET_DURN__REG, &data, C_BMA2x2_One_U8X); - *tap_quiet = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_QUIET_DURN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set tap quiet - * - * - * - * - * \param unsigned char tap_quiet - * 0 -> 30ms - * 1 -> 20ms - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_quiet(unsigned char tap_quiet) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_QUIET_DURN__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_QUIET_DURN, tap_quiet); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_TAP_QUIET_DURN__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get tap threshold - * - * - * - * - * \param unsigned char *tap_thr : Address of tap_thr - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_thr(unsigned char *tap_thr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); - *tap_thr = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_THRES); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set tap threshold - * - * - * - * - * \param unsigned char tap_thr - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_thr(unsigned char tap_thr) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_THRES, tap_thr); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get tap sample - * - * - * - * - * \param unsigned char *tap_sample : Address of tap_sample - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_sample(unsigned char *tap_sample) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); - *tap_sample = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_SAMPLES); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set tap sample - * - * - * - * - * \param unsigned char tap_sample - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_sample(unsigned char tap_sample) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_SAMPLES, tap_sample); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get orient mode - * - * - * - * - * \param unsigned char *orient_mode : Address of orient_mode - * 00 -> 45' symmetrical - * 01 -> 63' high asymmetrical - * 10 -> 27' low asymmetrical - * 11 -> reserved - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_mode(unsigned char *orient_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); - *orient_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_MODE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set orient mode - * - * - * - * - * \param unsigned char orient_mode - * 00 -> 45' symmetrical - * 01 -> 63' high asymmetrical - * 10 -> 27' low asymmetrical - * 11 -> reserved - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_mode(unsigned char orient_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_MODE, orient_mode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get orient block - * - * - * - * - * \param unsigned char *orient_block : Address of orient_block - * 00 -> disabled - * 01 -> horizontal position or acc >1.75g - * 10 -> horizontal position or acc >1.75g or slope > 0.2g - * 11 -> horizontal position or acc >1.75g or slope > 0.4g or wait 100ms - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_block(unsigned char *orient_block) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); - *orient_block = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_BLOCK); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set orient block - * - * - * - * - * \param unsigned char orient_block - * 00 -> disabled - * 01 -> horizontal position or acc >1.75g - * 10 -> horizontal position or acc >1.75g or slope > 0.2g - * 11 -> horizontal position or acc >1.75g or slope > 0.4g or wait 100ms - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_block(unsigned char orient_block) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_BLOCK, orient_block); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get orient hysteresis - * - * - * - * - * \param unsigned char *orient_hyst : Address of orient_hyst - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_hyst(unsigned char *orient_hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); - *orient_hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_HYST); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set orient hysteresis - * - * - * - * - * \param unsigned char orient_hyst - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_hyst(unsigned char orient_hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_HYST, orient_hyst); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get theta - * - * - * - * - * \param unsigned char channel,unsigned char *theta - * channel --> - * BMA2x2_ORIENT_THETA 0 - * BMA2x2_FLAT_THETA 1 - * theta --> Any valid value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_theta(unsigned char channel, unsigned char *theta) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_ORIENT_THETA: - // ORIENT THETA - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_THETA_BLOCK__REG, - &data, - C_BMA2x2_One_U8X); - *theta = BMA2x2_GET_BITSLICE(data, BMA2x2_THETA_BLOCK); - break; - - case BMA2x2_FLAT_THETA: - // FLAT THETA - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_THETA_FLAT__REG, &data, C_BMA2x2_One_U8X); - *theta = data; - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set theta - * - * - * - * - * \param unsigned char channel,unsigned char theta - * channel --> - * BMA2x2_ORIENT_THETA 0 - * BMA2x2_FLAT_THETA 1 - * theta --> Any valid value - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_theta(unsigned char channel, unsigned char theta) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_ORIENT_THETA: - // ORIENT THETA - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_THETA_BLOCK__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_THETA_BLOCK, theta); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_THETA_BLOCK__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_FLAT_THETA: - // FLAT THETA - data = theta; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_THETA_FLAT__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of orient enable - * - * - * - * - * \param unsigned char *orient_en : Address of orient_en - * 1 -> Generates Interrupt - * 0 -> Do not generate interrupt - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_en(unsigned char *orient_en) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); - *orient_en = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_UD_EN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of orient enable - * - * - * - * - * \param unsigned char orient_en - * 1 -> Generates Interrupt - * 0 -> Do not generate interrupt - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_en(unsigned char orient_en) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_UD_EN, orient_en); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of flat hyst - * - * - * - * - * \param unsigned char *flat_hyst : Address of flat_hyst - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hyst(unsigned char *flat_hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); - *flat_hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_FLAT_HYS); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of flat hyst - * - * - * - * - * \param unsigned char flat_hyst - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hyst(unsigned char flat_hyst) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FLAT_HYS, flat_hyst); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of flat hold time - * - * - * - * - * \param unsigned char *flat_hold_time : Address of flat_hold_time - * 00 -> disabled - * 01 -> 512ms - * 10 -> 1024ms - * 11 -> 2048ms - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hold_time(unsigned char *flat_hold_time) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HOLD_TIME__REG, &data, C_BMA2x2_One_U8X); - *flat_hold_time = BMA2x2_GET_BITSLICE(data, BMA2x2_FLAT_HOLD_TIME); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of flat hold time - * - * - * - * - * \param unsigned char flat_hold_time - * 00 -> disabled - * 01 -> 512ms - * 10 -> 1024ms - * 11 -> 2048ms - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hold_time(unsigned char flat_hold_time) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HOLD_TIME__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FLAT_HOLD_TIME, flat_hold_time); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_FLAT_HOLD_TIME__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*********************************************************************************************** -* Description: *//**\brief This API is used to get the fifo water mark level trigger status -* -* -* -* -* \param fifo_wml_trig -* -* -* -* \return -* -* -***********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_wml_trig(unsigned char *fifo_wml_trig) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_WML_TRIG_RETAIN__REG, - &data, - C_BMA2x2_One_U8X); - *fifo_wml_trig = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_WML_TRIG_RETAIN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************************** -* Description: *//**\brief This API is used to set the fifo water mark level trigger status -* -* -* -* -* \param unsigned char fifo_wml_trig -* 0-31 -* -* -* -* \return -* -* -**********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_wml_trig(unsigned char fifo_wml_trig) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (fifo_wml_trig < C_BMA2x2_ThirtyTwo_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_WML_TRIG_RETAIN__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_WML_TRIG_RETAIN, fifo_wml_trig); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_WML_TRIG_RETAIN__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is for to get Self Test Axis - * - * - * - * - * \param unsigned char *self_test_axis : Address of self_test_axis - * Possible values [1:0] are 0 to 3. - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_axis(unsigned char *self_test_axis) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SELF_TEST__REG, &data, C_BMA2x2_One_U8X); - *self_test_axis = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SELF_TEST); - } - return comres; -} - -/******************************************************************************* - * Description: *//**\brief This API is for to Set Self Test Axis - * - * - * - * - * \param unsigned char self_test_axis - * - * Possible values [1:0] are 0 to 3. - * - * - * - * - * - * - * - * \return Communication Results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_axis(unsigned char self_test_axis) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (self_test_axis < C_BMA2x2_Four_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SELF_TEST__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SELF_TEST, self_test_axis); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SELF_TEST__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is for to get Self Test sign - * - * - * - * - * \param unsigned char *self_test_sign : Address of self_test_sign - * 0 => '+'ve sign - * 1 => '-'ve sign - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_sign(unsigned char *self_test_sign) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_NEG_SELF_TEST__REG, &data, C_BMA2x2_One_U8X); - *self_test_sign = BMA2x2_GET_BITSLICE(data, BMA2x2_NEG_SELF_TEST); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is for to set Self Test sign - * - * - * - * - * \param unsigned char self_test_sign - * 0 => '+'ve sign - * 1 => '-'ve sign - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_sign(unsigned char self_test_sign) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (self_test_sign < C_BMA2x2_Two_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_NEG_SELF_TEST__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_NEG_SELF_TEST, self_test_sign); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_NEG_SELF_TEST__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of nvm program mode - * - * - * - * - * \param unsigned char *nvmprog_mode : Address of *nvmprog_mode - * 1 -> Enable program mode - * 0 -> Disable program mode - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_nvmprog_mode(unsigned char *nvmprog_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNLOCK_EE_PROG_MODE__REG, - &data, - C_BMA2x2_One_U8X); - *nvmprog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_UNLOCK_EE_PROG_MODE); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of nvmprogram mode - * - * - * - * - * \param (unsigned char prgmode) - * 1 -> Enable program mode - * 0 -> Disable program mode - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_set_nvmprog_mode(unsigned char prgmode) -{ - unsigned char data; - int comres; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNLOCK_EE_PROG_MODE__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNLOCK_EE_PROG_MODE, prgmode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_UNLOCK_EE_PROG_MODE__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of nvm program trig - * - * - * - * - * \param unsigned char trig - * 1 -> trig program seq (wo) - * 0 -> No Action - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_set_nvprog_trig(unsigned char trig) -{ - unsigned char data; - int comres; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_START_EE_PROG_TRIG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_START_EE_PROG_TRIG, trig); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_START_EE_PROG_TRIG__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of nvmprogram ready - * - * - * - * - * \param unsigned char *ready - * 1 -> program seq finished - * 0 -> program seq in progress - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_nvmprog_ready(unsigned char *ready) -{ - int comres; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EE_PROG_READY__REG, &data, C_BMA2x2_One_U8X); - *ready = BMA2x2_GET_BITSLICE(data, BMA2x2_EE_PROG_READY); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of nvm program remain - * - * - * - * - * \param unsigned char *remain - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -int bma2x2_get_nvmprog_remain(unsigned char *remain) -{ - int comres; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EE_REMAIN__REG, &data, C_BMA2x2_One_U8X); - *remain = BMA2x2_GET_BITSLICE(data, BMA2x2_EE_REMAIN); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of spi3 - * - * - * - * - * \param unsigned char *spi3 : Address of spi3 - * 0 -> spi3 - * 1 -> spi4(default) - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_spi3(unsigned char *spi3) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); - *spi3 = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SPI_MODE_3); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of spi3 - * - * - * - * - * \param unsigned char spi3 - * 0 -> spi3 - * 1 -> spi4(default) - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_spi3(unsigned char spi3) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SPI_MODE_3, spi3); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of i2c wdt - * - * - * - * - * \param unsigned char channel,unsigned char *prog_mode - * BMA2x2_I2C_SELECT 0 - * BMA2x2_I2C_EN 1 - * - * sel,en - x,0 ->OFF - * 0,1 ->1 ms - * 1,1 ->50ms - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_i2c_wdt(unsigned char channel, unsigned char *prog_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_I2C_SELECT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_I2C_WATCHDOG_PERIOD__REG, - &data, - C_BMA2x2_One_U8X); - *prog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_I2C_WATCHDOG_PERIOD); - break; - - case BMA2x2_I2C_EN: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_I2C_WATCHDOG__REG, - &data, - C_BMA2x2_One_U8X); - *prog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_I2C_WATCHDOG); - break; - - default: - comres = E_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of i2c wdt - * - * - * - * - * \param unsigned char channel,unsigned char prog_mode - * BMA2x2_I2C_SELECT 0 - * BMA2x2_I2C_EN 1 - * - * sel,en - x,0 ->OFF - * 0,1 ->1 ms - * 1,1 ->50ms - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_i2c_wdt(unsigned char channel, unsigned char prog_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_I2C_SELECT: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_I2C_WATCHDOG_PERIOD__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_I2C_WATCHDOG_PERIOD, prog_mode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_I2C_WATCHDOG_PERIOD__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_I2C_EN: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_I2C_WATCHDOG__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_I2C_WATCHDOG, prog_mode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_I2C_WATCHDOG__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status slow compensation - * - * - * - * - * \param unsigned char channel,unsigned char *slow_comp - * BMA2x2_SLOW_COMP_X 0 - * BMA2x2_SLOW_COMP_Y 1 - * BMA2x2_SLOW_COMP_Z 2 - * - * - * slow_comp : 1 -> enable - * 0 -> disable slow offset - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slow_comp(unsigned char channel, unsigned char *slow_comp) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SLOW_COMP_X: - // SLOW COMP X - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_X__REG, - &data, - C_BMA2x2_One_U8X); - *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_X); - break; - - case BMA2x2_SLOW_COMP_Y: - // SLOW COMP Y - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Y__REG, - &data, - C_BMA2x2_One_U8X); - *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Y); - break; - - case BMA2x2_SLOW_COMP_Z: - // SLOW COMP Z - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Z__REG, - &data, - C_BMA2x2_One_U8X); - *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Z); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status slow compensation - * - * - * - * - * \param unsigned char channel,unsigned char slow_comp - * BMA2x2_SLOW_COMP_X 0 - * BMA2x2_SLOW_COMP_Y 1 - * BMA2x2_SLOW_COMP_Z 2 - * - * - * slow_comp : 1 -> enable - * 0 -> disable slow offset - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slow_comp(unsigned char channel, unsigned char slow_comp) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_SLOW_COMP_X: - // SLOW COMP X - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_X__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_X, slow_comp); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_X__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLOW_COMP_Y: - // SLOW COMP Y - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Y__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Y, slow_comp); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Y__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_SLOW_COMP_Z: - // SLOW COMP Z - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Z__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Z, slow_comp); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_EN_SLOW_COMP_Z__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/*************************************************************************************************** - * Description: *//**\brief This API is used to get the status of fast offset compensation(cal rdy) - * - * - * - * - * \param unsigned char *rdy - * Read Only Possible - * - * - * - * \return - * - * - ****************************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_rdy(unsigned char *rdy) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FAST_CAL_RDY_S__REG, &data, C_BMA2x2_One_U8X); - *rdy = BMA2x2_GET_BITSLICE(data, BMA2x2_FAST_CAL_RDY_S); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of cal rdy - * - * - * - * - * \param unsigned char rdy - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_rdy(unsigned char rdy) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FAST_CAL_RDY_S__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FAST_CAL_RDY_S, rdy); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_FAST_CAL_RDY_S__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of cal trig - * - * - * - * - * \param unsigned char *cal_trig - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_trig(unsigned char *cal_trig) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); - *cal_trig = BMA2x2_GET_BITSLICE(data, BMA2x2_CAL_TRIGGER); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/***************************************************************************************************** -* Description: *//**\brief This API is used to set the status of fast offset calculation(cal trig) -* -* -* -* -* \param unsigned char cal_trig -* Write only possible -* -* -* -* \return communication results -* -* -*****************************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_trig(unsigned char cal_trig) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_CAL_TRIGGER, cal_trig); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of offset reset - * - * - * - * - * \param unsigned char offset_reset - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_reset(unsigned char offset_reset) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_RESET_OFFSET_REGS__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_RESET_OFFSET_REGS, offset_reset); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_RESET_OFFSET_REGS__REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of offset reset - * - * - * - * - * \param unsigned char channel,unsigned char *offset - * Channel -> - * BMA2x2_CUT_OFF -> 0 - * BMA2x2_OFFSET_TRIGGER_X -> 1 - * BMA2x2_OFFSET_TRIGGER_Y -> 2 - * BMA2x2_OFFSET_TRIGGER_Z -> 3 - * offset -> - * CUT_OFF -> 0 or 1 - * BMA2x2_OFFSET_TRIGGER_X -> 0,1,2,3 - * BMA2x2_OFFSET_TRIGGER_Y -> 0,1,2,3 - * BMA2x2_OFFSET_TRIGGER_Z -> 0,1,2,3 - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset_target(unsigned char channel, unsigned char *offset) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_CUT_OFF: - // CUT-OFF - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_CUTOFF__REG, - &data, - C_BMA2x2_One_U8X); - *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_CUTOFF); - break; - - case BMA2x2_OFFSET_TRIGGER_X: - // OFFSET TRIGGER X - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_X__REG, - &data, - C_BMA2x2_One_U8X); - *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_X); - break; - - case BMA2x2_OFFSET_TRIGGER_Y: - // OFFSET TRIGGER Y - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Y__REG, - &data, - C_BMA2x2_One_U8X); - *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Y); - break; - - case BMA2x2_OFFSET_TRIGGER_Z: - // OFFSET TRIGGER Z - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Z__REG, - &data, - C_BMA2x2_One_U8X); - *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Z); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of offset reset - * - * - * - * - * \param unsigned char channel,unsigned char offset - * Channel -> - * BMA2x2_CUT_OFF -> 0 - * BMA2x2_OFFSET_TRIGGER_X -> 1 - * BMA2x2_OFFSET_TRIGGER_Y -> 2 - * BMA2x2_OFFSET_TRIGGER_Z -> 3 - * offset -> - * CUT_OFF -> 0 or 1 - * BMA2x2_OFFSET_TRIGGER_X -> 0,1,2,3 - * BMA2x2_OFFSET_TRIGGER_Y -> 0,1,2,3 - * BMA2x2_OFFSET_TRIGGER_Z -> 0,1,2,3 - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_target(unsigned char channel, unsigned char offset) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_CUT_OFF: - // CUT-OFF - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_CUTOFF__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_CUTOFF, offset); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_CUTOFF__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_OFFSET_TRIGGER_X: - // OFFSET TARGET X - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_X__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_X, offset); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_X__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_OFFSET_TRIGGER_Y: - // OFFSET TARGET Y - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Y__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Y, offset); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Y__REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_OFFSET_TRIGGER_Z: - // OFFSET TARGET Z - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Z__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Z, offset); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_COMP_TARGET_OFFSET_Z__REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of offset - * - * - * - * - * \param unsigned char channel,unsigned char *offset - * Channel -> - * BMA2x2_X_AXIS -> 0 - * BMA2x2_Y_AXIS -> 1 - * BMA2x2_Z_AXIS -> 2 - * offset -> Any valid value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset(unsigned char channel, unsigned char *offset) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_X_AXIS: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_X_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - *offset = data; - break; - - case BMA2x2_Y_AXIS: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_Y_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - *offset = data; - break; - - case BMA2x2_Z_AXIS: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_Z_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - *offset = data; - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of offset - * - * - * - * - * \param unsigned char channel,unsigned char offset - * Channel -> - * BMA2x2_X_AXIS -> 0 - * BMA2x2_Y_AXIS -> 1 - * BMA2x2_Z_AXIS -> 2 - * offset -> Any valid value - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset(unsigned char channel, unsigned char offset) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_X_AXIS: - data = offset; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_X_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_Y_AXIS: - data = offset; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_Y_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - break; - - case BMA2x2_Z_AXIS: - data = offset; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_OFFSET_Z_AXIS_REG, - &data, - C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************************** - * Description: *//**\brief This API is used to get the status of general purpose register - * - * - * - * - * \param unsigned char channel,unsigned char *gp - * channel -> - * BMA2x2_GP0 0 - * BMA2x2_GP1 1 - * gp -> Any valid value - * - * - * - * \return - * - * - *******************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_gp(unsigned char channel, unsigned char *gp) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_GP0: - // GP0 - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_GP0_REG, &data, C_BMA2x2_One_U8X); - *gp = data; - break; - - case BMA2x2_GP1: - // GP1 - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_GP1_REG, &data, C_BMA2x2_One_U8X); - *gp = data; - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/********************************************************************************************* -* Description: *//**\brief This API is used to set the status of general purpose register -* -* -* -* -* \param unsigned char channel,unsigned char gp -* channel -> -* BMA2x2_GP0 0 -* BMA2x2_GP1 1 -* gp -> Any valid value -* -* -* -* \return communication results -* -* -*********************************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_gp(unsigned char channel, unsigned char gp) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (channel) { - case BMA2x2_GP0: - // GP0 - data = gp; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_GP0_REG, &data, C_BMA2x2_One_U8X); - break; - - case BMA2x2_GP1: - // GP1 - data = gp; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_GP1_REG, &data, C_BMA2x2_One_U8X); - break; - - default: - comres = E_BMA2x2_OUT_OF_RANGE; - break; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of fifo mode - * - * - * - * - * \param unsigned char *fifo_mode : Address of fifo_mode - * fifo_mode 0 --> Bypass - * 1 --> FIFO - * 2 --> Stream - * 3 --> Reserved - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_mode(unsigned char *fifo_mode) -{ - int comres; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); - *fifo_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_MODE); - } - return comres; -} - -/******************************************************************************* - * Description: *//**\brief This API is used set to FIFO mode - * - * - * - * - * \param unsigned char fifo_mode - * - * - * fifo_mode 0 --> Bypass - * 1 --> FIFO - * 2 --> Stream - * 3 --> Reserved - * - * - * - * - * \return Communication Results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_mode(unsigned char fifo_mode) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (fifo_mode < C_BMA2x2_Four_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_MODE, fifo_mode); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of fifo data sel - * - * - * - * - * \param unsigned char *data_sel : Address of data_sel - * data_sel --> [0:3] - * 0 --> X,Y and Z (DEFAULT) - * 1 --> X only - * 2 --> Y only - * 3 --> Z only - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_sel(unsigned char *data_sel) -{ - int comres; - unsigned char data; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_DATA_SELECT__REG, - &data, - C_BMA2x2_One_U8X); - *data_sel = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_DATA_SELECT); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of fifo data sel - * - * - * - * - * \param unsigned char data_sel - * data_sel --> [0:3] - * 0 --> X,Y and Z (DEFAULT) - * 1 --> X only - * 2 --> Y only - * 3 --> Z only - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_sel(unsigned char data_sel) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - if (data_sel < C_BMA2x2_Four_U8X) { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_DATA_SELECT__REG, - &data, - C_BMA2x2_One_U8X); - data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_DATA_SELECT, data_sel); - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_DATA_SELECT__REG, - &data, - C_BMA2x2_One_U8X); - } - else { - comres = E_OUT_OF_RANGE; - } - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to get the status of fifo data out reg - * - * - * - * - * \param unsigned char *out_reg : Address of out_reg - * Any Valid Value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_out_reg(unsigned char *out_reg) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - // GET FIFO DATA OUTPUT REGISTER - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_DATA_OUTPUT_REG, - &data, - C_BMA2x2_One_U8X); - *out_reg = data; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to set the status of fifo data out reg - * - * - * - * - * \param unsigned char out_reg - * Any Valid Value - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_out_reg(unsigned char out_reg) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - // SET FIFO DATA REGISTER - data = out_reg; - comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, - BMA2x2_FIFO_DATA_OUTPUT_REG, - &data, - C_BMA2x2_One_U8X); - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API is used to read the temperature - * - * - * - * - * \param signed char temperature - * Pointer to temperature - * - * - * - * \return communication results - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_temperature(signed char *temperature) -{ - unsigned char data; - int comres = C_BMA2x2_Zero_U8X; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TEMPERATURE_REG, &data, C_BMA2x2_One_U8X); - *temperature = (signed char) data; - } - return comres; -} - -/* Compiler Switch if applicable - #ifdef - - #endif - */ -/******************************************************************************* - * Description: *//**\brief This API reads acceleration data X,Y,Z values and - * Temperature data from location 02h to 08h - * - * - * - * - * \param bma2x2acc_data * acc : Address of bma2x2acc_data - * - * - * - * \return result of communication routines - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_accel_xyzt(bma2x2acc_data *acc) -{ - BMA2x2_RETURN_FUNCTION_TYPE comres = 0; - unsigned char data[7]; - if (p_bma2x2 == C_BMA2x2_Zero_U8X) { - comres = E_SMB_NULL_PTR; - } - else { - switch (V_BMA2x2RESOLUTION_U8R) { - case BMA2x2_12_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 7); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X12_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y12_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z12_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->temperature = (signed char) data[6]; - break; - - case BMA2x2_10_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 7); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X10_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y10_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z10_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->temperature = (signed char) data[6]; - break; - - case BMA2x2_8_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 7); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X8_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y8_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z8_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->temperature = (signed char) data[6]; - break; - - case BMA2x2_14_RESOLUTION: - comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 7); - acc->x = - BMA2x2_GET_BITSLICE(data[0], - BMA2x2_ACC_X14_LSB) | - (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); - acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); - - acc->y = - BMA2x2_GET_BITSLICE(data[2], - BMA2x2_ACC_Y14_LSB) | - (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); - acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); - - acc->z = - BMA2x2_GET_BITSLICE(data[4], - BMA2x2_ACC_Z14_LSB) | - (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); - acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); - acc->temperature = (signed char) data[6]; - break; - - default: - break; - } - } - return comres; -} - - - +/* + *************************************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + **************************************************************************************************/ +/* $Date: 2012/11/06 + * $Revision: 1.3 $ + * + */ + +/************************************************************************************************** +* Copyright (C) 2007 Bosch Sensortec GmbH +* +* bma2x2.c +* +* Usage: Sensor Driver for BMA2x2 Triaxial acceleration sensor +* +**************************************************************************************************/ +/*************************************************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. They may only be used + * within the parameters of the respective valid product data sheet. Bosch Sensortec products are + * provided with the express understanding that there is no warranty of fitness for a particular purpose. + * They are not fit for use in life-sustaining, safety or security sensitive systems or any system or device + * that may lead to bodily harm or property damage if the system or device malfunctions. In addition, + * Bosch Sensortec products are not fit for use in products which interact with motor vehicle systems. + * The resale and/or use of products are at the purchaser’s own risk and his own responsibility. The + * examination of fitness for the intended use is the sole responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party claims, including any claims for + * incidental, or consequential damages, arising from any product use not covered by the parameters of + * the respective valid product data sheet or not approved by Bosch Sensortec and reimburse Bosch + * Sensortec for all costs in connection with such claims. + * + * The purchaser must monitor the market for the purchased products, particularly with regard to + * product safety and inform Bosch Sensortec without delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary from the valid + * technical specifications of the product series. They are therefore not intended or fit for resale to third + * parties or for use in end products. Their sole purpose is internal client testing. The testing of an + * engineering sample may in no way replace the testing of a product series. Bosch Sensortec + * assumes no liability for the use of engineering samples. By accepting the engineering samples, the + * Purchaser agrees to indemnify Bosch Sensortec from all claims arising from the use of engineering + * samples. + * + * Special: + * This software module (hereinafter called "Software") and any information on application-sheets + * (hereinafter called "Information") is provided free of charge for the sole purpose to support your + * application work. The Software and Information is subject to the following terms and conditions: + * + * The Software is specifically designed for the exclusive use for Bosch Sensortec products by + * personnel who have special experience and training. Do not use this Software if you do not have the + * proper experience or training. + * + * This Software package is provided `` as is `` and without any expressed or implied warranties, + * including without limitation, the implied warranties of merchantability and fitness for a particular + * purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability for the functional impairment + * of this Software in terms of fitness, performance and safety. Bosch Sensortec and their + * representatives and agents shall not be liable for any direct or indirect damages or injury, except as + * otherwise stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. Bosch Sensortec assumes no + * responsibility for the consequences of use of such Information nor for any infringement of patents or + * other rights of third parties which may result from its use. No license is granted by implication or + * otherwise under any patent or patent rights of Bosch. Specifications mentioned in the Information are + * subject to change without notice. + * + * It is not allowed to deliver the source code of the Software to any third party without permission of + * Bosch Sensortec. + */ +/*************************************************************************************************/ +/*! \file + \brief */ +#include "bma2x2.h" +#include "sensorhub.h" +#include "common.h" +#include "acc_common.h" +#include "osp-sensors.h" +#include "sensacq_i2c.h" +#include "gpio_api.h" +#include "gpio_irq_api.h" + +/* user defined code to be added here ... */ +static bma2x2_t *p_bma2x2; +const unsigned char V_BMA2x2RESOLUTION_U8R = BMA2x2_12_RESOLUTION; /* Based on Bit resolution value should be modified */ +/* Compiler Switch if applicable + #ifdef + + #endif + */ +static bma2x2_t bma2x2; + +static void accel_activate(bool enable) +{ + if (enable) { + bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power + bma2x2_set_range(BMA2x2_RANGE_4G); /* set range 4g for grange */ + bma2x2_set_bandwidth(BMA2x2_BW_31_25HZ); + + /* configure interrupt pin INT1 as data interrupt */ + bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); + bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); + bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); + /* enable data interrupt */ + bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); + /* configure INT2 pin */ + bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(ACCEL_PINT_IRQn); + NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); + } + else { + NVIC_DisableIRQ(ACCEL_PINT_IRQn); + bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); // Low power + } +} +void Accel_HardwareSetup(osp_bool_t enable) +{ + gpio_t hostifIrq; + gpio_irq_t gpioIrq; + /* ACCEL INT1 irq setup */ + NVIC_DisableIRQ(ACCEL_PINT_IRQn); + NVIC_SetPriority(ACCEL_PINT_IRQn, SENSOR_IRQ_PRIORITY); + //Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT_PORT, ACCEL_INT_PIN); + hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN); + gpio_dir(&hostifIrq,PIN_INPUT); + + Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN); + + +// Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive and rising edge interrupt */ +// Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH); + gpioIrq.irq_index = ACCEL_PINT_CH; + gpioIrq.event = IRQ_EDGE_RISE; + gpio_irq_enable(&gpioIrq); + + //Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT2_PORT, ACCEL_INT2_PIN); + hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT2_PORT, ACCEL_INT2_PIN); + gpio_dir(&hostifIrq,PIN_INPUT); + + Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */ + + //Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); + //gpio_irq_disable(&gpioIrq); + +} +void Accel_Initialize(AccelInitOption option) +{ + bma2x2.bus_write = dev_i2c_write; + bma2x2.bus_read = dev_i2c_read; + bma2x2.delay_msec = dev_i2c_delay; + + bma2x2_init(&bma2x2); + bma2x2_soft_reset(); + dev_i2c_delay(1); + bma2x2_set_mode(BMA2x2_MODE_NORMAL); + bma2x2_set_range(BMA2x2_RANGE_4G); + /* accel_setDelay(pSens, 16); */ + bma2x2_set_bandwidth(BMA2x2_BW_62_50HZ); + + /* configure interrupt pin INT1 as data interrupt */ + bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); + bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); + bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); + /* enable data interrupt */ + bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); + /* configure INT2 pin */ + bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); + + bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); + + // QLY: Somehow on the LPC54102 platform, no accel interrupt if the following API is not call with argument 'true' + accel_activate(true); +} + +void Accel_ConfigDataInt(osp_bool_t enable) +{ + if (enable) { + bma2x2_set_mode(BMA2x2_MODE_NORMAL); // Normal power + bma2x2_set_range(BMA2x2_RANGE_4G); /* set range 4g for grange */ + /* Baccel_setDelay(pSens, 16); */ + + /* configure interrupt pin INT1 as data interrupt */ + bma2x2_set_newdata(BMA2x2_INT1_NDATA, 1); + bma2x2_set_int_lvl(BMA2x2_INT1_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT1_OUTPUT, 0); + bma2x2_set_latch_int(BMA2x2_LATCH_DUR_LATCH); + /* enable data interrupt */ + bma2x2_set_Int_Enable(BMA2x2_DATA_EN, 1); + /* configure INT2 pin */ + bma2x2_set_int_lvl(BMA2x2_INT2_LEVEL, 1); + bma2x2_set_int_od(BMA2x2_INT2_OUTPUT, 0); + + NVIC_ClearPendingIRQ(ACCEL_PINT_IRQn); + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(ACCEL_PINT_IRQn); + + } + else { + NVIC_DisableIRQ(ACCEL_PINT_IRQn); + bma2x2_set_mode(BMA2x2_MODE_DEEP_SUSPEND); // Low power + } +} + +void Accel_ClearDataInt(void) +{ + /* Read to clear any pending interrupt */ + Accel_ReadData(NULL); +} + +void Accel_ReadData(MsgAccelData *accelData ) +{ + bma2x2acc_t bma; + bma2x2_read_accel_xyz(&bma); // get acceleration data from sensor + if (accelData) { + accelData->X = bma.x; + accelData->Y = bma.y; + accelData->Z = bma.z; + } + +} + +void ACCEL_IRQHandler(void) +{ + gpio_irq_t gpioIrq; + uint32_t currTime = GetCurrentTime(); + gpioIrq.irq_index = ACCEL_PINT_CH; +#if 0 + uint32_t currTime = g_Timer.GetCurrent(); + PhysicalSensor_t* pSens = g_phySensors[PHYS_ACCEL_ID]; + pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; + pSens->ts_lastSample = currTime; + + pSens->irq_pending++; + +// Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); + gpio_irq_disable(&gpioIrq); + ResMgr_IRQDone(); +#else +// Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH); + gpio_irq_disable(&gpioIrq); + SendDataReadyIndication(ACCEL_INPUT_SENSOR, currTime); +#endif +} + +/******************************************************************************* + * Description: *//**\brief This API reads the data from the given register continously + * + * + * + * + * \param unsigned char addr, unsigned char *data + * addr -> Address of the register + * data -> address of the variable, read value will be kept + * \return results of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_burst_read(unsigned char addr, unsigned char *data, unsigned int len) +{ + BMA2x2_RETURN_FUNCTION_TYPE comres; + if (p_bma2x2 == BMA2x2_NULL) { + comres = E_BMA2x2_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BURST_READ_FUNC(p_bma2x2->dev_addr, addr, data, len); + } + return comres; +} + +/******************************************************************************* + * Description: *//**\brief + * This function initialises the structure pointer and assigns the I2C address. + * + * + * + * + * + * \param bma2x2_t *bma2x2 structure pointer. + * + * + * + * \return communication results. + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_init(bma2x2_t *bma2x2) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + + p_bma2x2 = bma2x2; /* assign bma2x2 ptr */ + p_bma2x2->dev_addr = BMA2x2_I2C_ADDR; /* preset bma2x2 I2C_addr */ + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CHIP_ID__REG, &data, 1); /* read Chip Id */ + p_bma2x2->chip_id = data; /* get bitslice */ + return comres; +} + +/******************************************************************************* + * Description: *//**\brief This API gives data to the given register and + * the data is written in the corresponding register address + * + * + * + * + * \param unsigned char addr, unsigned char data, unsigned char len + * addr -> Address of the register + * data -> Data to be written to the register + * len -> Length of the Data + * + * + * + * \return communication results. + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_write_reg(unsigned char addr, unsigned char *data, unsigned char len) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, addr, data, len); + } + return comres; +} + +/******************************************************************************* + * Description: *//**\brief This API reads the data from the given register address + * + * + * + * + * \param unsigned char addr, unsigned char *data, unsigned char len + * addr -> Address of the register + * data -> address of the variable, read value will be kept + * len -> Length of the data + * + * + * + * + * \return results of communication routine + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_read_reg(unsigned char addr, unsigned char *data, unsigned char len) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, addr, data, len); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API reads acceleration data X values + * from location 02h and 03h + * + * + * + * + * \param short *a_x : Address of a_x + * + * + * + * \return result of communication routines + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_read_accel_x(short *a_x) +{ + int comres = 0; + unsigned char data[2]; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (V_BMA2x2RESOLUTION_U8R) { + case BMA2x2_12_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 2); + *a_x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X12_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); + *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + break; + + case BMA2x2_10_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 2); + *a_x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X10_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); + *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + break; + + case BMA2x2_8_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 2); + *a_x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X8_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); + *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + break; + + case BMA2x2_14_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 2); + *a_x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X14_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); + *a_x = *a_x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + *a_x = *a_x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + break; + + default: + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API reads acceleration data Y values + * from location 04h and 05h + * + * + * + * + * \param short *a_y : Address of a_y + * + * + * + * \return result of communication routines + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_read_accel_y(short *a_y) +{ + int comres = 0; + unsigned char data[2]; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (V_BMA2x2RESOLUTION_U8R) { + case BMA2x2_12_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y12_LSB__REG, data, 2); + *a_y = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Y12_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); + *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + break; + + case BMA2x2_10_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y10_LSB__REG, data, 2); + *a_y = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Y10_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); + *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + break; + + case BMA2x2_8_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y8_LSB__REG, data, 2); + *a_y = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Y8_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); + *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + break; + + case BMA2x2_14_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Y14_LSB__REG, data, 2); + *a_y = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Y14_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); + *a_y = *a_y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + *a_y = *a_y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + break; + + default: + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API reads acceleration data Z values + * from location 06h and 07h + * + * + * + * + * \param short *a_z : Address of a_z + * + * + * + * \return result of communication routines + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_read_accel_z(short *a_z) +{ + int comres = 0; + unsigned char data[2]; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (V_BMA2x2RESOLUTION_U8R) { + case BMA2x2_12_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z12_LSB__REG, data, 2); + *a_z = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Z12_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); + *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + case BMA2x2_10_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z10_LSB__REG, data, 2); + *a_z = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Z10_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); + *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + case BMA2x2_8_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z8_LSB__REG, data, 2); + *a_z = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Z8_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); + *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + case BMA2x2_14_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_Z14_LSB__REG, data, 2); + *a_z = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_Z14_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); + *a_z = *a_z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + *a_z = *a_z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + default: + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API reads acceleration data X,Y,Z values + * from location 02h to 07h + * + * + * + * + * \param bma2x2acc_t * acc : Address of bma2x2acc_t + * + * + * + * \return result of communication routines + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_read_accel_xyz(bma2x2acc_t *acc) +{ + int comres = 0; + unsigned char data[6]; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (V_BMA2x2RESOLUTION_U8R) { + case BMA2x2_12_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 6); + + data[0] = BMA2x2_GET_BITSLICE(data[0], BMA2x2_ACC_X12_LSB); + acc->x = (short) (((unsigned short) data[1] << BMA2x2_ACC_X12_LSB__POS) | data[0]); + if (data[1] & 0x80) { + acc->x |= 0xf000; + } + + data[2] = BMA2x2_GET_BITSLICE(data[2], BMA2x2_ACC_Y12_LSB); + acc->y = (short) (((unsigned short) data[3] << BMA2x2_ACC_Y12_LSB__POS) | data[2]); + if (data[3] & 0x80) { + acc->y |= 0xf000; + } + + data[4] = BMA2x2_GET_BITSLICE(data[4], BMA2x2_ACC_Z12_LSB); + acc->z = (short) (((unsigned short) data[5] << BMA2x2_ACC_Z12_LSB__POS) | data[4]); + if (data[5] & 0x80) { + acc->z |= 0xf000; + } +#if 0 + + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X12_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y12_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z12_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); +#endif + + break; + + case BMA2x2_10_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 6); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X10_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y10_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z10_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + case BMA2x2_8_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 6); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X8_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y8_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z8_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + case BMA2x2_14_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 6); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X14_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y14_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z14_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + break; + + default: + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads tap slope status register byte + * from location 0Bh + * + * + * + * + * \param unsigned char * status_tap : Address of status_tap register + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_int_tap_status(unsigned char *status_tap) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_STATUS_TAP_SLOPE_REG, + status_tap, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads orient status register byte + * from location 0Ch + * + * + * + * + * \param unsigned char *status_orient : Address of status_orient register + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_int_orient_status(unsigned char *status_orient) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_STATUS_ORIENT_HIGH_REG, + status_orient, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads fifo status register byte + * from location 0Eh + * + * + * + * + * \param unsigned char *status_fifo : Address of status_fifo register + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_fifo_status(unsigned char *status_fifo) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_STATUS_FIFO_REG, + status_fifo, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads fifo framecount bits from location 0Eh + * + * + * + * + * \param unsigned char *framecount : Address of framecount + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_fifo_framecount(unsigned char *framecount) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_FRAME_COUNTER_S__REG, + &data, + C_BMA2x2_One_U8X); + *framecount = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_FRAME_COUNTER_S); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads fifo overrun bits from location 0Eh + * + * + * + * + * \param unsigned char *overrun : Address of overrun + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_fifo_overrun(unsigned char *overrun) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_OVERRUN_S__REG, &data, C_BMA2x2_One_U8X); + *overrun = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_OVERRUN_S); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API Reads interrupt status register byte + * from location 09h + * + * + * + * + * \param unsigned char * status : Address of status register + * + * + * + * \return Result of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_interrupt_status(unsigned char *status) +{ + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_STATUS1_REG, status, C_BMA2x2_Four_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************** + * Description: *//**\brief This API is used to get the Ranges(g values) of the sensor + * + * + * + * + * \param unsigned char * Range : Address of Range + * 3 -> 2G + * 5 -> 4G + * 8 -> 8G + * 12 -> 16G + * + * + * + * \return + * + * + ***************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_range(unsigned char *Range) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RANGE_SEL__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_GET_BITSLICE(data, BMA2x2_RANGE_SEL); + *Range = data; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*********************************************************************************** + * Description: *//**\brief This API is used to set Ranges(g value) of the sensor + * + * + * + * + * \param unsigned char Range + * 3 -> 2G + * 5 -> 4G + * 8 -> 8G + * 12 -> 16G + * + * \return communication results + * + * + ************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_set_range(unsigned char Range) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data1; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if ((Range == C_BMA2x2_Three_U8X) || (Range == C_BMA2x2_Five_U8X) || (Range == C_BMA2x2_Eight_U8X) || + (Range == C_BMA2x2_Twelve_U8X)) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RANGE_SEL_REG, &data1, C_BMA2x2_One_U8X); + switch (Range) { + case BMA2x2_RANGE_2G: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Three_U8X); + break; + + case BMA2x2_RANGE_4G: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Five_U8X); + break; + + case BMA2x2_RANGE_8G: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Eight_U8X); + break; + + case BMA2x2_RANGE_16G: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_RANGE_SEL, C_BMA2x2_Twelve_U8X); + break; + + default: + break; + } + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_RANGE_SEL_REG, + &data1, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*********************************************************************************** + * Description: *//**\brief This API is used to get the bandwidth of the sensor + * + * + * + * + * \param unsigned char * BW : Address of * BW + * 8 -> 7.81HZ + * 9 -> 15.63HZ + * 10 -> 31.25HZ + * 11 -> 62.50HZ + * 12 -> 125HZ + * 13 -> 250HZ + * 14 -> 500HZ + * 15 -> 1000HZ + * + * + * + * \return + * + * + ************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_bandwidth(unsigned char *BW) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_BANDWIDTH__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_GET_BITSLICE(data, BMA2x2_BANDWIDTH); + *BW = data; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set Bandwidth of the sensor + * + * + * + * + * \param unsigned char BW + * 8 -> 7.81HZ + * 9 -> 15.63HZ + * 10 -> 31.25HZ + * 11 -> 62.50HZ + * 12 -> 125HZ + * 13 -> 250HZ + * 14 -> 500HZ + * 15 -> 1000HZ + * + * + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_set_bandwidth(unsigned char BW) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + int Bandwidth; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (p_bma2x2->chip_id == 0xFB) { + if (( BW > C_BMA2x2_Seven_U8X) && ( BW < C_BMA2x2_Fifteen_U8X) ) { + switch (BW) { + case BMA2x2_BW_7_81HZ: + Bandwidth = BMA2x2_BW_7_81HZ; + + /* 7.81 Hz 64000 uS */ + break; + + case BMA2x2_BW_15_63HZ: + Bandwidth = BMA2x2_BW_15_63HZ; + + /* 15.63 Hz 32000 uS */ + break; + + case BMA2x2_BW_31_25HZ: + Bandwidth = BMA2x2_BW_31_25HZ; + + /* 31.25 Hz 16000 uS */ + break; + + case BMA2x2_BW_62_50HZ: + Bandwidth = BMA2x2_BW_62_50HZ; + + /* 62.50 Hz 8000 uS */ + break; + + case BMA2x2_BW_125HZ: + Bandwidth = BMA2x2_BW_125HZ; + + /* 125 Hz 4000 uS */ + break; + + case BMA2x2_BW_250HZ: + Bandwidth = BMA2x2_BW_250HZ; + + /* 250 Hz 2000 uS */ + break; + + case BMA2x2_BW_500HZ: + Bandwidth = BMA2x2_BW_500HZ; + + /* 500 Hz 1000 uS */ + break; + + default: + break; + } + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_BANDWIDTH__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_BANDWIDTH, Bandwidth); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_BANDWIDTH__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + else { + if (( BW > C_BMA2x2_Seven_U8X) && ( BW < C_BMA2x2_Sixteen_U8X) ) { + switch (BW) { + case BMA2x2_BW_7_81HZ: + Bandwidth = BMA2x2_BW_7_81HZ; + + /* 7.81 Hz 64000 uS */ + break; + + case BMA2x2_BW_15_63HZ: + Bandwidth = BMA2x2_BW_15_63HZ; + + /* 15.63 Hz 32000 uS */ + break; + + case BMA2x2_BW_31_25HZ: + Bandwidth = BMA2x2_BW_31_25HZ; + + /* 31.25 Hz 16000 uS */ + break; + + case BMA2x2_BW_62_50HZ: + Bandwidth = BMA2x2_BW_62_50HZ; + + /* 62.50 Hz 8000 uS */ + break; + + case BMA2x2_BW_125HZ: + Bandwidth = BMA2x2_BW_125HZ; + + /* 125 Hz 4000 uS */ + break; + + case BMA2x2_BW_250HZ: + Bandwidth = BMA2x2_BW_250HZ; + + /* 250 Hz 2000 uS */ + break; + + case BMA2x2_BW_500HZ: + Bandwidth = BMA2x2_BW_500HZ; + + /* 500 Hz 1000 uS */ + break; + + case BMA2x2_BW_1000HZ: + Bandwidth = BMA2x2_BW_1000HZ; + + /* 1000 Hz 500 uS */ + break; + + default: + break; + } + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_BANDWIDTH__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_BANDWIDTH, Bandwidth); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_BANDWIDTH__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*************************************************************************************** + * Description: *//**\brief This API is used to get the operating modes of the sensor + * + * + * + * + * \param unsigned char * Mode : Address of Mode + * 0 -> NORMAL + * 1 -> LOWPOWER1 + * 2 -> SUSPEND + * 3 -> DEEP_SUSPEND + * 4 -> LOWPOWER2 + * 5 -> STANDBY + * + * + * + * \return + * + * + **************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_mode(unsigned char *Mode) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data1, data2; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_MODE_CTRL_REG, &data1, C_BMA2x2_One_U8X); + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_NOISE_CTRL_REG, &data2, C_BMA2x2_One_U8X); + + data1 = (data1 & 0xE0) >> 5; + data2 = (data2 & 0x40) >> 6; + + // *Mode = (*Mode) >> C_Six_U8X; + if ((data1 == 0x00) && (data2 == 0x00)) { + *Mode = BMA2x2_MODE_NORMAL; + } + else { + if ((data1 == 0x02) && (data2 == 0x00)) { + *Mode = BMA2x2_MODE_LOWPOWER1; + } + else { + if ((( data1 == 0x04) || ( data1 == 0x06) ) && (data2 == 0x00)) { + *Mode = BMA2x2_MODE_SUSPEND; + } + else { + if (((data1 & 0x01) == 0x01)) { + *Mode = BMA2x2_MODE_DEEP_SUSPEND; + } + else { + if ((data1 == 0x02) && (data2 == 0x01)) { + *Mode = BMA2x2_MODE_LOWPOWER2; + } + else { + if ((data1 == 0x04) && (data2 == 0x01)) { + *Mode = BMA2x2_MODE_STANDBY; + } + else { + *Mode = BMA2x2_MODE_DEEP_SUSPEND; + } + } + } + } + } + } + } + p_bma2x2->mode = *Mode; + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*************************************************************************************** +* Description: *//**\brief This API is used to set the operating Modes of the sensor +* +* +* +* +* \param unsigned char Mode +* 0 -> NORMAL +* 1 -> LOWPOWER1 +* 2 -> SUSPEND +* 3 -> DEEP_SUSPEND +* 4 -> LOWPOWER2 +* 5 -> STANDBY +* +* \return communication results +* +* +***************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +unsigned char bma2x2_set_mode(unsigned char Mode) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data1, data2; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (Mode < C_BMA2x2_Six_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_MODE_CTRL_REG, &data1, C_BMA2x2_One_U8X); + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + switch (Mode) { + case BMA2x2_MODE_NORMAL: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Zero_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_MODE_LOWPOWER1: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Two_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_MODE_SUSPEND: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Four_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_Zero_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_MODE_DEEP_SUSPEND: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_One_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_MODE_LOWPOWER2: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Two_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_MODE_STANDBY: + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_MODE_CTRL, C_BMA2x2_Four_U8X); + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_LOW_POWER_MODE, C_BMA2x2_One_U8X); + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_LOW_NOISE_CTRL_REG, + &data2, + C_BMA2x2_One_U8X); + p_bma2x2->delay_msec(1);/*A minimum delay of atleast 450us is required for the low power modes, as per the data sheet.*/ + comres += p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_MODE_CTRL_REG, + &data1, + C_BMA2x2_One_U8X); + break; + } + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************************** + * Description: *//**\brief This API is used to get the sleep duration status of the sensor + * + * + * + * + * \param unsigned char *sleep_dur : Address of sleep_dur + * 5 -> 0.5MS + * 6 -> 1MS + * 7 -> 2MS + * 8 -> 4MS + * 9 -> 6MS + * 10 -> 10MS + * 11 -> 25MS + * 12 -> 50MS + * 13 -> 100MS + * 14 -> 500MS + * 15 -> 1S + * + * + * + * \return + * + * + *********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleep_dur(unsigned char *sleep_dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + // SLEEP DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); + *sleep_dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLEEP_DUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************ + * Description: *//**\brief This API is used to set Sleep Duration of the sensor + * + * + * + * + * \param unsigned char sleep_dur + * 5 -> 0.5MS + * 6 -> 1MS + * 7 -> 2MS + * 8 -> 4MS + * 9 -> 6MS + * 10 -> 10MS + * 11 -> 25MS + * 12 -> 50MS + * 13 -> 100MS + * 14 -> 500MS + * 15 -> 1S + * + * + * \return communication results + * + * + **************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleep_dur(unsigned char sleep_dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + int sleep_duration = 0; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (( sleep_dur > C_BMA2x2_Four_U8X) && ( sleep_dur < C_BMA2x2_Sixteen_U8X) ) { + switch (sleep_dur) { + case BMA2x2_SLEEP_DUR_0_5MS: + sleep_duration = BMA2x2_SLEEP_DUR_0_5MS; + + /* 0.5 MS */ + break; + + case BMA2x2_SLEEP_DUR_1MS: + sleep_duration = BMA2x2_SLEEP_DUR_1MS; + + /* 1 MS */ + break; + + case BMA2x2_SLEEP_DUR_2MS: + sleep_duration = BMA2x2_SLEEP_DUR_2MS; + + /* 2 MS */ + break; + + case BMA2x2_SLEEP_DUR_4MS: + sleep_duration = BMA2x2_SLEEP_DUR_4MS; + + /* 4 MS */ + break; + + case BMA2x2_SLEEP_DUR_6MS: + sleep_duration = BMA2x2_SLEEP_DUR_6MS; + + /* 6 MS */ + break; + + case BMA2x2_SLEEP_DUR_10MS: + sleep_duration = BMA2x2_SLEEP_DUR_10MS; + + /* 10 MS */ + break; + + case BMA2x2_SLEEP_DUR_25MS: + sleep_duration = BMA2x2_SLEEP_DUR_25MS; + + /* 25 MS */ + break; + + case BMA2x2_SLEEP_DUR_50MS: + sleep_duration = BMA2x2_SLEEP_DUR_50MS; + + /* 50 MS */ + break; + + case BMA2x2_SLEEP_DUR_100MS: + sleep_duration = BMA2x2_SLEEP_DUR_100MS; + + /* 100 MS */ + break; + + case BMA2x2_SLEEP_DUR_500MS: + sleep_duration = BMA2x2_SLEEP_DUR_500MS; + + /* 500 MS */ + break; + + case BMA2x2_SLEEP_DUR_1S: + sleep_duration = BMA2x2_SLEEP_DUR_1S; + + /* 1 SECS */ + break; + + default: + break; + } + // SLEEP DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLEEP_DUR, sleep_duration); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_DUR__REG, &data, C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the sleep timer mode status + * + * + * + * + * \param unsigned char *sleep_tmr : Address of sleep_tmr + * sleep_tmr -> [0:1] + * 0 => enable EventDrivenSampling(EDT) + * 1 => enable Eqidistant sampling mode(EST) + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleeptmr_mode(unsigned char *sleep_tmr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + // SLEEP TIMER MODE + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLEEP_TIMER__REG, &data, C_BMA2x2_One_U8X); + *sleep_tmr = BMA2x2_GET_BITSLICE(data, BMA2x2_SLEEP_TIMER); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the sleep timer mode status + * + * + * + * + * \param unsigned char sleep_tmr + * sleep_tmr -> [0:1] + * 0 => enable EventDrivenSampling(EDT) + * 1 => enable Eqidistant sampling mode(EST) + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleeptmr_mode(unsigned char sleep_tmr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (sleep_tmr < C_BMA2x2_Two_U8X) { + // SLEEP TIMER MODE + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLEEP_TIMER__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLEEP_TIMER, sleep_tmr); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLEEP_TIMER__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get high bandwidth + * + * + * + * + * \param unsigned char *high_bw : Address of high_bw + * 1 -> Unfiltered High Bandwidth + * 0 -> Filtered Low Bandwidth + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_high_bw(unsigned char *high_bw) +{ + { + char comres; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_DATA_HIGH_BW__REG, + &data, + C_BMA2x2_One_U8X); + *high_bw = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_DATA_HIGH_BW); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set high bandwidth + * + * + * + * + * \param unsigned char high_bw + * 1 -> Unfiltered High Bandwidth + * 0 -> Filtered Low Bandwidth + * + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_high_bw(unsigned char high_bw) +{ + { + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_DATA_HIGH_BW__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_DATA_HIGH_BW, high_bw); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_DATA_HIGH_BW__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get shadow dis + * + * + * + * + * \param unsigned char *shadow_dis : Address of shadow_dis + * 1 -> No MSB Locking + * 0 -> MSB is Locked + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_shadow_dis(unsigned char *shadow_dis) +{ + { + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_DIS_SHADOW_PROC__REG, + &data, + C_BMA2x2_One_U8X); + *shadow_dis = BMA2x2_GET_BITSLICE(data, BMA2x2_DIS_SHADOW_PROC); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set shadow dis + * + * + * + * + * \param unsigned char shadow_dis + * 1 -> No MSB Locking + * 0 -> MSB is Locked + * + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_shadow_dis(unsigned char shadow_dis) +{ + { + int comres = C_BMA2x2_Zero_U8X; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_DIS_SHADOW_PROC__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_DIS_SHADOW_PROC, shadow_dis); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_DIS_SHADOW_PROC__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief + * This function is used for the soft reset + * The soft reset register will be written with 0xB6. + * + * + * + * \param None + * + * + * + * \return Communication results. + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_soft_reset(void) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data = BMA2x2_EN_SOFT_RESET_VALUE; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_REG, &data, C_BMA2x2_One_U8X);/* To reset the sensor 0xB6 value will be written */ + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to update the register values + * + * + * + * + * \param + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_update_image(void) +{ + int comres; + unsigned char data = 0; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_UPDATE_IMAGE__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UPDATE_IMAGE, C_BMA2x2_One_U8X); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_UPDATE_IMAGE__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/**************************************************************************************** +* Description: *//**\brief This API is used to set interrupt enable bits of the sensor +* +* +* +* +* \param unsigned char InterruptType , unsigned char value +* 0 -> Low_G_Interrupt +* 1 -> High_G_X_Interrupt +* 2 -> High_G_Y_Interrupt +* 3 -> High_G_Z_Interrupt +* 4 -> DATA_EN +* 5 -> Slope_X_Interrupt +* 6 -> Slope_Y_Interrupt +* 7 -> Slope_Z_Interrupt +* 8 -> Single_Tap_Interrupt +* 9 -> Double_Tap_Interrupt +* 10 -> Orient_Interrupt +* 11 -> Flat_Interrupt +* +* +* +* +* \return communication results +* +* +****************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_set_Int_Enable(unsigned char InterruptType, unsigned char value) +{ + int comres = C_BMA2x2_Zero_U8X; + unsigned char data1, data2; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE1_REG, &data1, C_BMA2x2_One_U8X); + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE2_REG, &data2, C_BMA2x2_One_U8X); + + value = value & C_BMA2x2_One_U8X; + switch (InterruptType) { + case BMA2x2_Low_G_Interrupt: + /* Low G Interrupt */ + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_LOWG_INT, value); + break; + + case BMA2x2_High_G_X_Interrupt: + /* High G X Interrupt */ + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_X_INT, value); + break; + + case BMA2x2_High_G_Y_Interrupt: + /* High G Y Interrupt */ + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_Y_INT, value); + break; + + case BMA2x2_High_G_Z_Interrupt: + /* High G Z Interrupt */ + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_HIGHG_Z_INT, value); + break; + + case BMA2x2_DATA_EN: + /*Data En Interrupt */ + data2 = BMA2x2_SET_BITSLICE(data2, BMA2x2_EN_NEW_DATA_INT, value); + break; + + case BMA2x2_Slope_X_Interrupt: + /* Slope X Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_X_INT, value); + break; + + case BMA2x2_Slope_Y_Interrupt: + /* Slope Y Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_Y_INT, value); + break; + + case BMA2x2_Slope_Z_Interrupt: + /* Slope Z Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SLOPE_Z_INT, value); + break; + + case BMA2x2_Single_Tap_Interrupt: + /* Single Tap Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_SINGLE_TAP_INT, value); + break; + + case BMA2x2_Double_Tap_Interrupt: + /* Double Tap Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_DOUBLE_TAP_INT, value); + break; + + case BMA2x2_Orient_Interrupt: + /* Orient Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_ORIENT_INT, value); + break; + + case BMA2x2_Flat_Interrupt: + /* Flat Interrupt */ + data1 = BMA2x2_SET_BITSLICE(data1, BMA2x2_EN_FLAT_INT, value); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE1_REG, &data1, C_BMA2x2_One_U8X); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_ENABLE2_REG, &data2, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the interrupt ffull enable status + * + * + * + * + * \param unsigned char *ffull : Address of ffull + * ffull -> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_ffull(unsigned char *ffull) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_FFULL_EN_INT__REG, + &data, + C_BMA2x2_One_U8X); + *ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_FFULL_EN_INT); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the interrupt ffull enable status + * + * + * + * + * \param unsigned char ffull + * ffull -> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_ffull(unsigned char ffull) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (ffull < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_FFULL_EN_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_FFULL_EN_INT, ffull); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_FFULL_EN_INT__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************** + * Description: *//**\brief This API is used to get the interrupt fwm enable status + * + * + * + * + * \param unsigned char *fwm : Address of fwm + * fwm -> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + *************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_fwm(unsigned char *fwm) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_INT_FWM_EN_INT__REG, &data, C_BMA2x2_One_U8X); + *fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_FWM_EN_INT); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************* +* Description: *//**\brief This API is used to set the interrupt fwm enable status +* +* +* +* +* \param unsigned char fwm +* fwm -> [0:1] +* 0 --> Clear +* 1 --> Set +* +* +* +* \return communication results +* +* +*************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_fwm(unsigned char fwm) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (fwm < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_FWM_EN_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_FWM_EN_INT, fwm); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_FWM_EN_INT__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************************* + * Description: *//**\brief This API is used to get the status of slow/no motion interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *slo_data + * channel --> + * BMA2x2_SLO_NO_MOT_EN_X -> 0 + * BMA2x2_SLO_NO_MOT_EN_Y -> 1 + * BMA2x2_SLO_NO_MOT_EN_Z -> 2 + * BMA2x2_SLO_NO_MOT_EN_SEL -> 3 + * slo_data --> 1 + * + * + * + * \return + * + * + **********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slo_no_mot(unsigned char channel, unsigned char *slo_data) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SLO_NO_MOT_EN_X: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, + &data, + C_BMA2x2_One_U8X); + *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_X_INT); + break; + + case BMA2x2_SLO_NO_MOT_EN_Y: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, + &data, + C_BMA2x2_One_U8X); + *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Y_INT); + break; + + case BMA2x2_SLO_NO_MOT_EN_Z: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, + &data, + C_BMA2x2_One_U8X); + *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Z_INT); + break; + + case BMA2x2_SLO_NO_MOT_EN_SEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, + &data, + C_BMA2x2_One_U8X); + *slo_data = BMA2x2_GET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************************** + * Description: *//**\brief This API is used to set the status of slow/no motion interrupt + * + * + * + * + * \param unsigned char channel,unsigned char slo_data + * channel --> + * BMA2x2_SLO_NO_MOT_EN_X -> 0 + * BMA2x2_SLO_NO_MOT_EN_Y -> 1 + * BMA2x2_SLO_NO_MOT_EN_Z -> 2 + * BMA2x2_SLO_NO_MOT_EN_SEL -> 3 + * slo_data --> 1 + * + * + * + * \return communication results + * + * + *******************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slo_no_mot(unsigned char channel, unsigned char slo_data) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SLO_NO_MOT_EN_X: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_X_INT, slo_data); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLO_NO_MOT_EN_Y: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Y_INT, slo_data); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLO_NO_MOT_EN_Z: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_Z_INT, slo_data); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLO_NO_MOT_EN_SEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT, slo_data); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************* + * Description: *//**\brief This API is used to get the status of low interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *int_low + * channel --> + * BMA2x2_INT1_LOWG -> 0 + * BMA2x2_INT2_LOWG -> 1 + * int_low --> 1 + * + * + * + * \return + * + * + ********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_low(unsigned char channel, unsigned char *int_low) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + *int_low = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_LOWG); + break; + + case BMA2x2_INT2_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + *int_low = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_LOWG); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************* + * Description: *//**\brief This API is used to set the status of low interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_low + * channel --> + * BMA2x2_INT1_LOWG -> 0 + * BMA2x2_INT2_LOWG -> 1 + * int_low --> 1 + * + * + * + * \return communication results + * + * + ********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_low(unsigned char channel, unsigned char int_low) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_LOWG, int_low); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_LOWG, int_low); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************* + * Description: *//**\brief This API is used to get the status of high interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *int_high + * channel --> + * BMA2x2_INT1_HIGHG -> 0 + * BMA2x2_INT2_HIGHG -> 1 + * int_high --> 1 + * + * + * + * \return + * + * + ********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_high(unsigned char channel, unsigned char *int_high) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + *int_high = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_HIGHG); + break; + + case BMA2x2_INT2_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + *int_high = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_HIGHG); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************* + * Description: *//**\brief This API is used to set the status of high interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_high + * channel --> + * BMA2x2_INT1_HIGHG -> 0 + * BMA2x2_INT2_HIGHG -> 1 + * int_high --> 1 + * + * + * + * \return communication results + * + * + ********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_high(unsigned char channel, unsigned char int_high) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_HIGHG, int_high); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_HIGHG, int_high); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************** + * Description: *//**\brief This API is used to get the status of slope interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *int_slope + * channel --> + * BMA2x2_INT1_SLOPE -> 0 + * BMA2x2_INT2_SLOPE -> 1 + * int_slope --> 1 + * + * + * + * \return + * + * + *********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slope(unsigned char channel, unsigned char *int_slope) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + *int_slope = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLOPE); + break; + + case BMA2x2_INT2_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + *int_slope = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLOPE); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************** + * Description: *//**\brief This API is used to set the status of slope interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_slope + * channel --> + * BMA2x2_INT1_SLOPE -> 0 + * BMA2x2_INT2_SLOPE -> 1 + * int_slope --> 1 + * + * + * \return communication results + * + * + *********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slope(unsigned char channel, unsigned char int_slope) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLOPE, int_slope); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLOPE, int_slope); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************************* +* Description: *//**\brief This API is used to get the status of slow/no motion interrupt +* +* +* +* +* \param unsigned char channel,unsigned char *int_slo_no_mot +* channel --> +* BMA2x2_INT1_SLO_NO_MOT -> 0 +* BMA2x2_INT2_SLO_NO_MOT -> 1 +* int_slo_no_mot --> 1 +* +* +* +* \return +* +* +*********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slo_no_mot(unsigned char channel, unsigned char *int_slo_no_mot) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + *int_slo_no_mot = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLO_NO_MOT); + break; + + case BMA2x2_INT2_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + *int_slo_no_mot = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLO_NO_MOT); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************************* + * Description: *//**\brief This API is used to set the status of slow/no motion interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_slo_no_mot + * channel --> + * BMA2x2_INT1_SLO_NO_MOT -> 0 + * BMA2x2_INT2_SLO_NO_MOT -> 1 + * int_slo_no_mot --> 1 + * + * + * + * \return communication results + * + * + **********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slo_no_mot(unsigned char channel, unsigned char int_slo_no_mot) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SLO_NO_MOT, int_slo_no_mot); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SLO_NO_MOT, int_slo_no_mot); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************************** + * Description: *//**\brief This API is used to get the status of double tap interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *int_d_tap + * channel --> + * BMA2x2_INT1_DTAP -> 0 + * BMA2x2_INT2_DTAP -> 1 + * int_d_tap --> 1 + * + * + * + * \return + * + * + ****************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_d_tap(unsigned char channel, unsigned char *int_d_tap) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_DTAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + *int_d_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_DB_TAP); + break; + + case BMA2x2_INT2_DTAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + *int_d_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_DB_TAP); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/**************************************************************************************** + * Description: *//**\brief This API is used to set the status of double tap interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_d_tap + * channel --> + * BMA2x2_INT1_DTAP -> 0 + * BMA2x2_INT2_DTAP -> 1 + * int_d_tap --> 1 + * + * + * + * \return communication results + * + * + *****************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_d_tap(unsigned char channel, unsigned char int_d_tap) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_DTAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_DB_TAP, int_d_tap); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_DTAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_DB_TAP, int_d_tap); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_DB_TAP__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*************************************************************************************** +* Description: *//**\brief This API is used to get the status of single tap interrupt +* +* +* +* +* \param unsigned char channel,unsigned char *int_s_tap +* channel --> +* BMA2x2_INT1_STAP -> 0 +* BMA2x2_INT2_STAP -> 1 +* int_s_tap --> 1 +* +* +* +* \return +* +* +***************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_s_tap(unsigned char channel, unsigned char *int_s_tap) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_STAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + *int_s_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SNG_TAP); + break; + + case BMA2x2_INT2_STAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + *int_s_tap = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SNG_TAP); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/**************************************************************************************** +* Description: *//**\brief This API is used to set the status of single tap interrupt +* +* +* +* +* \param unsigned char channel,unsigned char int_s_tap +* channel --> +* BMA2x2_INT1_STAP -> 0 +* BMA2x2_INT2_STAP -> 1 +* int_s_tap --> 1 +* +* +* +* \return communication results +* +* +****************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_s_tap(unsigned char channel, unsigned char int_s_tap) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_STAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_SNG_TAP, int_s_tap); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_STAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_SNG_TAP, int_s_tap); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_SNG_TAP__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************** +* Description: *//**\brief This API is used to get the status of orient interrupt +* +* +* +* +* \param unsigned char channel,unsigned char *int_orient +* channel --> +* BMA2x2_INT1_ORIENT -> 0 +* BMA2x2_INT2_ORIENT -> 1 +* int_orient --> 1 +* +* +* +* \return +* +* +**************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_orient(unsigned char channel, unsigned char *int_orient) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_ORIENT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + *int_orient = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_ORIENT); + break; + + case BMA2x2_INT2_ORIENT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + *int_orient = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_ORIENT); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/************************************************************************************* + * Description: *//**\brief This API is used to set the status of orient interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_orient + * channel --> + * BMA2x2_INT1_ORIENT -> 0 + * BMA2x2_INT2_ORIENT -> 1 + * int_orient --> 1 + * + * + * + * \return communication results + * + * + ************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_orient(unsigned char channel, unsigned char int_orient) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_ORIENT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_ORIENT, int_orient); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_ORIENT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_ORIENT, int_orient); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_ORIENT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************** + * Description: *//**\brief This API is used to get the status of flat interrupt + * + * + * + * + * \param unsigned char channel,unsigned char *int_flat + * channel --> + * BMA2x2_INT1_FLAT -> 0 + * BMA2x2_INT2_FLAT -> 1 + * int_flat --> 1 + * + * + * + * \return + * + * + *********************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_flat(unsigned char channel, unsigned char *int_flat) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_FLAT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + *int_flat = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FLAT); + break; + + case BMA2x2_INT2_FLAT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + *int_flat = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FLAT); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of flat interrupt + * + * + * + * + * \param unsigned char channel,unsigned char int_flat + * channel --> + * BMA2x2_INT1_FLAT -> 0 + * BMA2x2_INT2_FLAT -> 1 + * int_flat --> 1 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_flat(unsigned char channel, unsigned char int_flat) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_FLAT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FLAT, int_flat); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_FLAT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FLAT, int_flat); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of new data + * + * + * + * + * \param unsigned char channel,unsigned char *int_newdata + * channel --> + * BMA2x2_INT1_NDATA -> 0 + * BMA2x2_INT2_NDATA -> 1 + * int_newdata --> 1 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_newdata(unsigned char channel, unsigned char *int_newdata) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_NDATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + *int_newdata = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_NEWDATA); + break; + + case BMA2x2_INT2_NDATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + *int_newdata = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_NEWDATA); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of new data + * + * + * + * + * \param unsigned char channel,unsigned char int_newdata + * channel --> + * BMA2x2_INT1_NDATA -> 0 + * BMA2x2_INT2_NDATA -> 1 + * int_newdata --> 1 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_newdata(unsigned char channel, unsigned char int_newdata) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_NDATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_NEWDATA, int_newdata); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_NDATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_NEWDATA, int_newdata); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_NEWDATA__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the fwm interrupt1 data + * + * + * + * + * \param unsigned char *int1_fwm : Address of int1_fwm + * int1_fwm --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_fwm(unsigned char *int1_fwm) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + *int1_fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FWM); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the fwm interrupt1 data + * + * + * + * + * \param unsigned char int1_fwm + * int1_fwm --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_fwm(unsigned char int1_fwm) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (int1_fwm < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FWM, int1_fwm); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the fwm interrupt2 data + * + * + * + * + * \param unsigned char*int2_fwm : Address of int2_fwm + * int2_fwm[0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_fwm(unsigned char *int2_fwm) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + *int2_fwm = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FWM); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the fwm interrupt2 data + * + * + * + * + * \param unsigned char int2_fwm + * int2_fwm --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_fwm(unsigned char int2_fwm) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (int2_fwm < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FWM, int2_fwm); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FWM__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the ffull interrupt1 data + * + * + * + * + * \param unsigned char *int1_ffull : Address of int1_ffull + * int1_ffull --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_ffull(unsigned char *int1_ffull) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + *int1_ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FFULL); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the ffull interrupt1 data + * + * + * + * + * \param unsigned char int1_ffull + * int1_ffull --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_ffull(unsigned char int1_ffull) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (int1_ffull < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT1_PAD_FFULL, int1_ffull); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT1_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the ffull interrupt2 data + * + * + * + * + * \param unsigned char *int2_ffull : Address of int2_ffull + * int2_ffull --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_ffull(unsigned char *int2_ffull) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + *int2_ffull = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FFULL); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the ffull interrupt2 data + * + * + * + * + * \param unsigned char int2_ffull + * int2_ffull --> [0:1] + * 0 --> Clear + * 1 --> Set + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_ffull(unsigned char int2_ffull) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (int2_ffull < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_INT2_PAD_FFULL, int2_ffull); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_INT2_PAD_FFULL__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the source status data + * + * + * + * + * \param unsigned char channel,unsigned char *int_source + * Channel -> + * BMA2x2_SRC_LOWG 0 + * BMA2x2_SRC_HIGHG 1 + * BMA2x2_SRC_SLOPE 2 + * BMA2x2_SRC_SLO_NO_MOT 3 + * BMA2x2_SRC_TAP 4 + * BMA2x2_SRC_DATA 5 + * int_source -> 1 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_source(unsigned char channel, unsigned char *int_source) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SRC_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_LOWG); + break; + + case BMA2x2_SRC_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_HIGHG); + break; + + case BMA2x2_SRC_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLOPE); + break; + + case BMA2x2_SRC_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT); + break; + + case BMA2x2_SRC_TAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_TAP__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_TAP); + break; + + case BMA2x2_SRC_DATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_DATA__REG, + &data, + C_BMA2x2_One_U8X); + *int_source = BMA2x2_GET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_DATA); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set source status data + * + * + * + * + * \param unsigned char channel,unsigned char int_source + * Channel -> + * BMA2x2_SRC_LOWG 0 + * BMA2x2_SRC_HIGHG 1 + * BMA2x2_SRC_SLOPE 2 + * BMA2x2_SRC_SLO_NO_MOT 3 + * BMA2x2_SRC_TAP 4 + * BMA2x2_SRC_DATA 5 + * int_source -> 1 + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_source(unsigned char channel, unsigned char int_source) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SRC_LOWG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_LOWG, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_LOWG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SRC_HIGHG: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_HIGHG, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_HIGHG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SRC_SLOPE: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLOPE, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLOPE__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SRC_SLO_NO_MOT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SRC_TAP: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_TAP__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_TAP, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_TAP__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SRC_DATA: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_DATA__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNFILT_INT_SRC_DATA, int_source); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNFILT_INT_SRC_DATA__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the output type status + * + * + * + * + * \param unsigned char channel,unsigned char *int_od + * BMA2x2_INT1_OUTPUT -> 0 + * BMA2x2_INT2_OUTPUT -> 1 + * int_od : open drain -> 1 + * push pull -> 0 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_od(unsigned char channel, unsigned char *int_od) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_OUTPUT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + *int_od = BMA2x2_GET_BITSLICE(data, BMA2x2_INT1_PAD_OUTPUT_TYPE); + break; + + case BMA2x2_INT2_OUTPUT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + *int_od = BMA2x2_GET_BITSLICE(data, BMA2x2_INT2_PAD_OUTPUT_TYPE); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the output type status + * + * + * + * + * \param unsigned char channel,unsigned char int_od + * BMA2x2_INT1_OUTPUT -> 0 + * BMA2x2_INT2_OUTPUT -> 1 + * int_od : open drain -> 1 + * push pull -> 0 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_od(unsigned char channel, unsigned char int_od) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_OUTPUT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT1_PAD_OUTPUT_TYPE, int_od); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_OUTPUT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT2_PAD_OUTPUT_TYPE, int_od); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_OUTPUT_TYPE__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get Active Level status + * + * + * + * + * \param unsigned char channel,unsigned char *int_lvl + * BMA2x2_INT1_LEVEL -> 0 + * BMA2x2_INT2_LEVEL -> 1 + * int_lvl : Active HI -> 1 + * Active LO -> 0 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_lvl(unsigned char channel, unsigned char *int_lvl) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_LEVEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + *int_lvl = BMA2x2_GET_BITSLICE(data, BMA2x2_INT1_PAD_ACTIVE_LEVEL); + break; + + case BMA2x2_INT2_LEVEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + *int_lvl = BMA2x2_GET_BITSLICE(data, BMA2x2_INT2_PAD_ACTIVE_LEVEL); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set Active Level status + * + * + * + * + * \param (unsigned char channel,unsigned char int_lvl) + * BMA2x2_INT1_LEVEL -> 0 + * BMA2x2_INT2_LEVEL -> 1 + * int_lvl : Active HI -> 1 + * Active LO -> 0 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_lvl(unsigned char channel, unsigned char int_lvl) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_INT1_LEVEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT1_PAD_ACTIVE_LEVEL, int_lvl); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_INT2_LEVEL: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_INT2_PAD_ACTIVE_LEVEL, int_lvl); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the reset interrupt + * + * + * + * + * \param unsigned char reset_int + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_reset_interrupt(unsigned char reset_int) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_INT__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_RESET_INT, reset_int); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_RESET_INT__REG, &data, C_BMA2x2_One_U8X); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the latch duration + * + * + * + * + * \param unsigned char *latch_int : Address of latch_int + * 0 -> NON_LATCH + * 1 -> 250MS + * 2 -> 500MS + * 3 -> 1S + * 4 -> 2S + * 5 -> 4S + * 6 -> 8S + * 7 -> LATCH + * 8 -> NON_LATCH1 + * 9 -> 250US + * 10 -> 500US + * 11 -> 1MS + * 12 -> 12.5MS + * 13 -> 25MS + * 14 -> 50MS + * 15 -> LATCH1 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_latch_int(unsigned char *latch_int) +{ + { + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); + *latch_int = BMA2x2_GET_BITSLICE(data, BMA2x2_LATCH_INT); + } + return comres; + } +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the latch duration + * + * + * + * + * \param unsigned char latch_int + * 0 -> NON_LATCH + * 1 -> 250MS + * 2 -> 500MS + * 3 -> 1S + * 4 -> 2S + * 5 -> 4S + * 6 -> 8S + * 7 -> LATCH + * 8 -> NON_LATCH1 + * 9 -> 250US + * 10 -> 500US + * 11 -> 1MS + * 12 -> 12.5MS + * 13 -> 25MS + * 14 -> 50MS + * 15 -> LATCH1 + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_latch_int(unsigned char latch_int) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + int latch_duration = 0; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (latch_int < C_BMA2x2_Sixteen_U8X) { + switch (latch_int) { + case BMA2x2_LATCH_DUR_NON_LATCH: + latch_duration = BMA2x2_LATCH_DUR_NON_LATCH; + + /* NON LATCH */ + break; + + case BMA2x2_LATCH_DUR_250MS: + latch_duration = BMA2x2_LATCH_DUR_250MS; + + /* 250 MS */ + break; + + case BMA2x2_LATCH_DUR_500MS: + latch_duration = BMA2x2_LATCH_DUR_500MS; + + /* 500 MS */ + break; + + case BMA2x2_LATCH_DUR_1S: + latch_duration = BMA2x2_LATCH_DUR_1S; + + /* 1 S */ + break; + + case BMA2x2_LATCH_DUR_2S: + latch_duration = BMA2x2_LATCH_DUR_2S; + + /* 2 S */ + break; + + case BMA2x2_LATCH_DUR_4S: + latch_duration = BMA2x2_LATCH_DUR_4S; + + /* 4 S */ + break; + + case BMA2x2_LATCH_DUR_8S: + latch_duration = BMA2x2_LATCH_DUR_8S; + + /* 8 S */ + break; + + case BMA2x2_LATCH_DUR_LATCH: + latch_duration = BMA2x2_LATCH_DUR_LATCH; + + /* LATCH */ + break; + + case BMA2x2_LATCH_DUR_NON_LATCH1: + latch_duration = BMA2x2_LATCH_DUR_NON_LATCH1; + + /* NON LATCH1 */ + break; + + case BMA2x2_LATCH_DUR_250US: + latch_duration = BMA2x2_LATCH_DUR_250US; + + /* 250 US */ + break; + + case BMA2x2_LATCH_DUR_500US: + latch_duration = BMA2x2_LATCH_DUR_500US; + + /* 500 US */ + break; + + case BMA2x2_LATCH_DUR_1MS: + latch_duration = BMA2x2_LATCH_DUR_1MS; + + /* 1 MS */ + break; + + case BMA2x2_LATCH_DUR_12_5MS: + latch_duration = BMA2x2_LATCH_DUR_12_5MS; + + /* 12.5 MS */ + break; + + case BMA2x2_LATCH_DUR_25MS: + latch_duration = BMA2x2_LATCH_DUR_25MS; + + /* 25 MS */ + break; + + case BMA2x2_LATCH_DUR_50MS: + latch_duration = BMA2x2_LATCH_DUR_50MS; + + /* 50 MS */ + break; + + case BMA2x2_LATCH_DUR_LATCH1: + latch_duration = BMA2x2_LATCH_DUR_LATCH1; + + /* LATCH1 */ + break; + + default: + break; + } + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_LATCH_INT, latch_duration); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LATCH_INT__REG, &data, C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get duration + * + * + * + * + * \param unsigned char channel,unsigned char *dur + * BMA2x2_LOW_DURATION 0,1 + * BMA2x2_HIGH_DURATION 1,2 + * BMA2x2_SLOPE_DURATION 2,3 + * BMA2x2_SLO_NO_MOT_DURATION 3,4 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_dur(unsigned char channel, unsigned char *dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOW_DURATION: + // LOW DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_DURN_REG, &data, C_BMA2x2_One_U8X); + *dur = data; + break; + + case BMA2x2_HIGH_DURATION: + // HIGH DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_DURN_REG, &data, C_BMA2x2_One_U8X); + *dur = data; + break; + + case BMA2x2_SLOPE_DURATION: + // SLOPE DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); + *dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLOPE_DUR); + break; + + case BMA2x2_SLO_NO_MOT_DURATION: + // SLO NO MOT DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLO_NO_MOT_DUR__REG, + &data, + C_BMA2x2_One_U8X); + *dur = BMA2x2_GET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set duration + * + * + * + * + * \param unsigned char channel,unsigned char dur + * BMA2x2_LOW_DURATION 0,1 + * BMA2x2_HIGH_DURATION 1,2 + * BMA2x2_SLOPE_DURATION 2,3 + * BMA2x2_SLO_NO_MOT_DURATION 3,4 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_dur(unsigned char channel, unsigned char dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOW_DURATION: + // LOW DURATION + data = dur; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_DURN_REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_HIGH_DURATION: + // HIGH DURATION + data = dur; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_DURN_REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLOPE_DURATION: + // SLOPE DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLOPE_DUR, dur); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_DUR__REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLO_NO_MOT_DURATION: + // SLO NO MOT DURATION + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLO_NO_MOT_DUR__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR, dur); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLO_NO_MOT_DUR__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get threshold + * + * + * + * + * \param unsigned char channel,unsigned char *thr + * BMA2x2_LOW_THRESHOLD 0,FE + * BMA2x2_HIGH_THRESHOLD 1,01 + * BMA2x2_SLOPE_THRESHOLD 2,01 + * BMA2x2_SLO_NO_MOT_THRESHOLD 3,00 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_thr(unsigned char channel, unsigned char *thr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOW_THRESHOLD: + // LOW THRESHOLD + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_THRES_REG, &data, C_BMA2x2_One_U8X); + *thr = data; + break; + + case BMA2x2_HIGH_THRESHOLD: + // HIGH THRESHOLD + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_THRES_REG, &data, C_BMA2x2_One_U8X); + *thr = data; + break; + + case BMA2x2_SLOPE_THRESHOLD: + // SLOPE THRESHOLD + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_SLOPE_THRES_REG, &data, C_BMA2x2_One_U8X); + *thr = data; + break; + + case BMA2x2_SLO_NO_MOT_THRESHOLD: + // SLO NO MOT THRESHOLD + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLO_NO_MOT_THRES_REG, + &data, + C_BMA2x2_One_U8X); + *thr = data; + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set threshold + * + * + * + * + * \param unsigned char channel,unsigned char thr + * BMA2x2_LOW_THRESHOLD 0,FE + * BMA2x2_HIGH_THRESHOLD 1,01 + * BMA2x2_SLOPE_THRESHOLD 2,01 + * BMA2x2_SLO_NO_MOT_THRESHOLD 3,00 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_thr(unsigned char channel, unsigned char thr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOW_THRESHOLD: + // LOW THRESHOLD + data = thr; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOW_THRES_REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_HIGH_THRESHOLD: + // HIGH THRESHOLD + data = thr; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGH_THRES_REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLOPE_THRESHOLD: + // SLOPE THRESHOLD + data = thr; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLOPE_THRES_REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLO_NO_MOT_THRESHOLD: + // SLO NO MOT THRESHOLD + data = thr; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_SLO_NO_MOT_THRES_REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get low high hysteresis + * + * + * + * + * \param unsigned char channel,unsigned char *hyst + * channel --> + * BMA2x2_LOWG_HYST 0 + * BMA2x2_HIGHG_HYST 1 + * hyst --> 1 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst(unsigned char channel, unsigned char *hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOWG_HYST: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); + *hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_LOWG_HYST); + break; + + case BMA2x2_HIGHG_HYST: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_HIGHG_HYST__REG, &data, C_BMA2x2_One_U8X); + *hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_HIGHG_HYST); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set low high hysteresis + * + * + * + * + * \param (unsigned char channel,unsigned char hyst) + * channel --> + * BMA2x2_LOWG_HYST 0 + * BMA2x2_HIGHG_HYST 1 + * hyst --> 1 + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst(unsigned char channel, unsigned char hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_LOWG_HYST: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_LOWG_HYST, hyst); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_HYST__REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_HIGHG_HYST: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_HIGHG_HYST__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_HIGHG_HYST, hyst); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_HIGHG_HYST__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get low high hysteresis mode + * + * + * + * + * \param unsigned char *mode + * 0 -> single mode + * 1 -> sum mode + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst_mode(unsigned char *mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); + *mode = BMA2x2_GET_BITSLICE(data, BMA2x2_LOWG_INT_MODE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set low high hysteresis mode + * + * + * + * + * \param (unsigned char mode) + * 0 -> single mode + * 1 -> sum mode + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst_mode(unsigned char mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_LOWG_INT_MODE, mode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_LOWG_INT_MODE__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get tap duration + * + * + * + * + * \param unsigned char *tap_dur : Address of tap_dur + * 0 -> 50ms + * 1 -> 100ms + * 2 -> 150ms + * 3 -> 200ms + * 4 -> 250ms + * 5 -> 375ms + * 6 -> 500ms + * 7 -> 700ms + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_dur(unsigned char *tap_dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); + *tap_dur = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_DUR); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set tap duration + * + * + * + * + * \param unsigned char tap_dur + * 0 -> 50ms + * 1 -> 100ms + * 2 -> 150ms + * 3 -> 200ms + * 4 -> 250ms + * 5 -> 375ms + * 6 -> 500ms + * 7 -> 700ms + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_dur(unsigned char tap_dur) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_DUR, tap_dur); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_DUR__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get tap shock + * + * + * + * + * \param unsigned char *tap_shock : Address of tap_shock + * 0 -> 50ms + * 1 -> 75ms + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_shock(unsigned char *tap_shock) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SHOCK_DURN__REG, &data, C_BMA2x2_One_U8X); + *tap_shock = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_SHOCK_DURN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set tap shock + * + * + * + * + * \param unsigned char tap_shock + * 0 -> 50ms + * 1 -> 75ms + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_shock(unsigned char tap_shock) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SHOCK_DURN__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_SHOCK_DURN, tap_shock); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_TAP_SHOCK_DURN__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get tap quiet + * + * + * + * + * \param unsigned char *tap_quiet : Address of tap_quiet + * 0 -> 30ms + * 1 -> 20ms + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_quiet(unsigned char *tap_quiet) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_QUIET_DURN__REG, &data, C_BMA2x2_One_U8X); + *tap_quiet = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_QUIET_DURN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set tap quiet + * + * + * + * + * \param unsigned char tap_quiet + * 0 -> 30ms + * 1 -> 20ms + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_quiet(unsigned char tap_quiet) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_QUIET_DURN__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_QUIET_DURN, tap_quiet); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_TAP_QUIET_DURN__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get tap threshold + * + * + * + * + * \param unsigned char *tap_thr : Address of tap_thr + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_thr(unsigned char *tap_thr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); + *tap_thr = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_THRES); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set tap threshold + * + * + * + * + * \param unsigned char tap_thr + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_thr(unsigned char tap_thr) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_THRES, tap_thr); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_THRES__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get tap sample + * + * + * + * + * \param unsigned char *tap_sample : Address of tap_sample + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_sample(unsigned char *tap_sample) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); + *tap_sample = BMA2x2_GET_BITSLICE(data, BMA2x2_TAP_SAMPLES); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set tap sample + * + * + * + * + * \param unsigned char tap_sample + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_sample(unsigned char tap_sample) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_TAP_SAMPLES, tap_sample); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_TAP_SAMPLES__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get orient mode + * + * + * + * + * \param unsigned char *orient_mode : Address of orient_mode + * 00 -> 45' symmetrical + * 01 -> 63' high asymmetrical + * 10 -> 27' low asymmetrical + * 11 -> reserved + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_mode(unsigned char *orient_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); + *orient_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_MODE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set orient mode + * + * + * + * + * \param unsigned char orient_mode + * 00 -> 45' symmetrical + * 01 -> 63' high asymmetrical + * 10 -> 27' low asymmetrical + * 11 -> reserved + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_mode(unsigned char orient_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_MODE, orient_mode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_MODE__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get orient block + * + * + * + * + * \param unsigned char *orient_block : Address of orient_block + * 00 -> disabled + * 01 -> horizontal position or acc >1.75g + * 10 -> horizontal position or acc >1.75g or slope > 0.2g + * 11 -> horizontal position or acc >1.75g or slope > 0.4g or wait 100ms + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_block(unsigned char *orient_block) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); + *orient_block = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_BLOCK); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set orient block + * + * + * + * + * \param unsigned char orient_block + * 00 -> disabled + * 01 -> horizontal position or acc >1.75g + * 10 -> horizontal position or acc >1.75g or slope > 0.2g + * 11 -> horizontal position or acc >1.75g or slope > 0.4g or wait 100ms + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_block(unsigned char orient_block) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_BLOCK, orient_block); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_BLOCK__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get orient hysteresis + * + * + * + * + * \param unsigned char *orient_hyst : Address of orient_hyst + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_hyst(unsigned char *orient_hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); + *orient_hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_HYST); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set orient hysteresis + * + * + * + * + * \param unsigned char orient_hyst + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_hyst(unsigned char orient_hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_HYST, orient_hyst); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_HYST__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get theta + * + * + * + * + * \param unsigned char channel,unsigned char *theta + * channel --> + * BMA2x2_ORIENT_THETA 0 + * BMA2x2_FLAT_THETA 1 + * theta --> Any valid value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_theta(unsigned char channel, unsigned char *theta) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_ORIENT_THETA: + // ORIENT THETA + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_THETA_BLOCK__REG, + &data, + C_BMA2x2_One_U8X); + *theta = BMA2x2_GET_BITSLICE(data, BMA2x2_THETA_BLOCK); + break; + + case BMA2x2_FLAT_THETA: + // FLAT THETA + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_THETA_FLAT__REG, &data, C_BMA2x2_One_U8X); + *theta = data; + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set theta + * + * + * + * + * \param unsigned char channel,unsigned char theta + * channel --> + * BMA2x2_ORIENT_THETA 0 + * BMA2x2_FLAT_THETA 1 + * theta --> Any valid value + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_theta(unsigned char channel, unsigned char theta) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_ORIENT_THETA: + // ORIENT THETA + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_THETA_BLOCK__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_THETA_BLOCK, theta); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_THETA_BLOCK__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_FLAT_THETA: + // FLAT THETA + data = theta; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_THETA_FLAT__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of orient enable + * + * + * + * + * \param unsigned char *orient_en : Address of orient_en + * 1 -> Generates Interrupt + * 0 -> Do not generate interrupt + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_en(unsigned char *orient_en) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); + *orient_en = BMA2x2_GET_BITSLICE(data, BMA2x2_ORIENT_UD_EN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of orient enable + * + * + * + * + * \param unsigned char orient_en + * 1 -> Generates Interrupt + * 0 -> Do not generate interrupt + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_en(unsigned char orient_en) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_ORIENT_UD_EN, orient_en); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_ORIENT_UD_EN__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of flat hyst + * + * + * + * + * \param unsigned char *flat_hyst : Address of flat_hyst + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hyst(unsigned char *flat_hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); + *flat_hyst = BMA2x2_GET_BITSLICE(data, BMA2x2_FLAT_HYS); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of flat hyst + * + * + * + * + * \param unsigned char flat_hyst + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hyst(unsigned char flat_hyst) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FLAT_HYS, flat_hyst); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HYS__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of flat hold time + * + * + * + * + * \param unsigned char *flat_hold_time : Address of flat_hold_time + * 00 -> disabled + * 01 -> 512ms + * 10 -> 1024ms + * 11 -> 2048ms + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hold_time(unsigned char *flat_hold_time) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HOLD_TIME__REG, &data, C_BMA2x2_One_U8X); + *flat_hold_time = BMA2x2_GET_BITSLICE(data, BMA2x2_FLAT_HOLD_TIME); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of flat hold time + * + * + * + * + * \param unsigned char flat_hold_time + * 00 -> disabled + * 01 -> 512ms + * 10 -> 1024ms + * 11 -> 2048ms + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hold_time(unsigned char flat_hold_time) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FLAT_HOLD_TIME__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FLAT_HOLD_TIME, flat_hold_time); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_FLAT_HOLD_TIME__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*********************************************************************************************** +* Description: *//**\brief This API is used to get the fifo water mark level trigger status +* +* +* +* +* \param fifo_wml_trig +* +* +* +* \return +* +* +***********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_wml_trig(unsigned char *fifo_wml_trig) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_WML_TRIG_RETAIN__REG, + &data, + C_BMA2x2_One_U8X); + *fifo_wml_trig = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_WML_TRIG_RETAIN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************************** +* Description: *//**\brief This API is used to set the fifo water mark level trigger status +* +* +* +* +* \param unsigned char fifo_wml_trig +* 0-31 +* +* +* +* \return +* +* +**********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_wml_trig(unsigned char fifo_wml_trig) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (fifo_wml_trig < C_BMA2x2_ThirtyTwo_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_WML_TRIG_RETAIN__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_WML_TRIG_RETAIN, fifo_wml_trig); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_WML_TRIG_RETAIN__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is for to get Self Test Axis + * + * + * + * + * \param unsigned char *self_test_axis : Address of self_test_axis + * Possible values [1:0] are 0 to 3. + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_axis(unsigned char *self_test_axis) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SELF_TEST__REG, &data, C_BMA2x2_One_U8X); + *self_test_axis = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SELF_TEST); + } + return comres; +} + +/******************************************************************************* + * Description: *//**\brief This API is for to Set Self Test Axis + * + * + * + * + * \param unsigned char self_test_axis + * + * Possible values [1:0] are 0 to 3. + * + * + * + * + * + * + * + * \return Communication Results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_axis(unsigned char self_test_axis) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (self_test_axis < C_BMA2x2_Four_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SELF_TEST__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SELF_TEST, self_test_axis); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SELF_TEST__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is for to get Self Test sign + * + * + * + * + * \param unsigned char *self_test_sign : Address of self_test_sign + * 0 => '+'ve sign + * 1 => '-'ve sign + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_sign(unsigned char *self_test_sign) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_NEG_SELF_TEST__REG, &data, C_BMA2x2_One_U8X); + *self_test_sign = BMA2x2_GET_BITSLICE(data, BMA2x2_NEG_SELF_TEST); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is for to set Self Test sign + * + * + * + * + * \param unsigned char self_test_sign + * 0 => '+'ve sign + * 1 => '-'ve sign + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_sign(unsigned char self_test_sign) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (self_test_sign < C_BMA2x2_Two_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_NEG_SELF_TEST__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_NEG_SELF_TEST, self_test_sign); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_NEG_SELF_TEST__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of nvm program mode + * + * + * + * + * \param unsigned char *nvmprog_mode : Address of *nvmprog_mode + * 1 -> Enable program mode + * 0 -> Disable program mode + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_nvmprog_mode(unsigned char *nvmprog_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNLOCK_EE_PROG_MODE__REG, + &data, + C_BMA2x2_One_U8X); + *nvmprog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_UNLOCK_EE_PROG_MODE); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of nvmprogram mode + * + * + * + * + * \param (unsigned char prgmode) + * 1 -> Enable program mode + * 0 -> Disable program mode + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_set_nvmprog_mode(unsigned char prgmode) +{ + unsigned char data; + int comres; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNLOCK_EE_PROG_MODE__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_UNLOCK_EE_PROG_MODE, prgmode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_UNLOCK_EE_PROG_MODE__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of nvm program trig + * + * + * + * + * \param unsigned char trig + * 1 -> trig program seq (wo) + * 0 -> No Action + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_set_nvprog_trig(unsigned char trig) +{ + unsigned char data; + int comres; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_START_EE_PROG_TRIG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_START_EE_PROG_TRIG, trig); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_START_EE_PROG_TRIG__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of nvmprogram ready + * + * + * + * + * \param unsigned char *ready + * 1 -> program seq finished + * 0 -> program seq in progress + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_nvmprog_ready(unsigned char *ready) +{ + int comres; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EE_PROG_READY__REG, &data, C_BMA2x2_One_U8X); + *ready = BMA2x2_GET_BITSLICE(data, BMA2x2_EE_PROG_READY); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of nvm program remain + * + * + * + * + * \param unsigned char *remain + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +int bma2x2_get_nvmprog_remain(unsigned char *remain) +{ + int comres; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EE_REMAIN__REG, &data, C_BMA2x2_One_U8X); + *remain = BMA2x2_GET_BITSLICE(data, BMA2x2_EE_REMAIN); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of spi3 + * + * + * + * + * \param unsigned char *spi3 : Address of spi3 + * 0 -> spi3 + * 1 -> spi4(default) + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_spi3(unsigned char *spi3) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); + *spi3 = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SPI_MODE_3); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of spi3 + * + * + * + * + * \param unsigned char spi3 + * 0 -> spi3 + * 1 -> spi4(default) + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_spi3(unsigned char spi3) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SPI_MODE_3, spi3); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_EN_SPI_MODE_3__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of i2c wdt + * + * + * + * + * \param unsigned char channel,unsigned char *prog_mode + * BMA2x2_I2C_SELECT 0 + * BMA2x2_I2C_EN 1 + * + * sel,en - x,0 ->OFF + * 0,1 ->1 ms + * 1,1 ->50ms + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_i2c_wdt(unsigned char channel, unsigned char *prog_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_I2C_SELECT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_I2C_WATCHDOG_PERIOD__REG, + &data, + C_BMA2x2_One_U8X); + *prog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_I2C_WATCHDOG_PERIOD); + break; + + case BMA2x2_I2C_EN: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_I2C_WATCHDOG__REG, + &data, + C_BMA2x2_One_U8X); + *prog_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_I2C_WATCHDOG); + break; + + default: + comres = E_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of i2c wdt + * + * + * + * + * \param unsigned char channel,unsigned char prog_mode + * BMA2x2_I2C_SELECT 0 + * BMA2x2_I2C_EN 1 + * + * sel,en - x,0 ->OFF + * 0,1 ->1 ms + * 1,1 ->50ms + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_i2c_wdt(unsigned char channel, unsigned char prog_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_I2C_SELECT: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_I2C_WATCHDOG_PERIOD__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_I2C_WATCHDOG_PERIOD, prog_mode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_I2C_WATCHDOG_PERIOD__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_I2C_EN: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_I2C_WATCHDOG__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_I2C_WATCHDOG, prog_mode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_I2C_WATCHDOG__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status slow compensation + * + * + * + * + * \param unsigned char channel,unsigned char *slow_comp + * BMA2x2_SLOW_COMP_X 0 + * BMA2x2_SLOW_COMP_Y 1 + * BMA2x2_SLOW_COMP_Z 2 + * + * + * slow_comp : 1 -> enable + * 0 -> disable slow offset + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slow_comp(unsigned char channel, unsigned char *slow_comp) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SLOW_COMP_X: + // SLOW COMP X + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_X__REG, + &data, + C_BMA2x2_One_U8X); + *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_X); + break; + + case BMA2x2_SLOW_COMP_Y: + // SLOW COMP Y + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Y__REG, + &data, + C_BMA2x2_One_U8X); + *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Y); + break; + + case BMA2x2_SLOW_COMP_Z: + // SLOW COMP Z + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Z__REG, + &data, + C_BMA2x2_One_U8X); + *slow_comp = BMA2x2_GET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Z); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status slow compensation + * + * + * + * + * \param unsigned char channel,unsigned char slow_comp + * BMA2x2_SLOW_COMP_X 0 + * BMA2x2_SLOW_COMP_Y 1 + * BMA2x2_SLOW_COMP_Z 2 + * + * + * slow_comp : 1 -> enable + * 0 -> disable slow offset + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slow_comp(unsigned char channel, unsigned char slow_comp) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_SLOW_COMP_X: + // SLOW COMP X + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_X__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_X, slow_comp); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_X__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLOW_COMP_Y: + // SLOW COMP Y + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Y__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Y, slow_comp); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Y__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_SLOW_COMP_Z: + // SLOW COMP Z + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Z__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_EN_SLOW_COMP_Z, slow_comp); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_EN_SLOW_COMP_Z__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/*************************************************************************************************** + * Description: *//**\brief This API is used to get the status of fast offset compensation(cal rdy) + * + * + * + * + * \param unsigned char *rdy + * Read Only Possible + * + * + * + * \return + * + * + ****************************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_rdy(unsigned char *rdy) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FAST_CAL_RDY_S__REG, &data, C_BMA2x2_One_U8X); + *rdy = BMA2x2_GET_BITSLICE(data, BMA2x2_FAST_CAL_RDY_S); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of cal rdy + * + * + * + * + * \param unsigned char rdy + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_rdy(unsigned char rdy) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FAST_CAL_RDY_S__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FAST_CAL_RDY_S, rdy); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_FAST_CAL_RDY_S__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of cal trig + * + * + * + * + * \param unsigned char *cal_trig + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_trig(unsigned char *cal_trig) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); + *cal_trig = BMA2x2_GET_BITSLICE(data, BMA2x2_CAL_TRIGGER); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/***************************************************************************************************** +* Description: *//**\brief This API is used to set the status of fast offset calculation(cal trig) +* +* +* +* +* \param unsigned char cal_trig +* Write only possible +* +* +* +* \return communication results +* +* +*****************************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_trig(unsigned char cal_trig) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_CAL_TRIGGER, cal_trig); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_CAL_TRIGGER__REG, &data, C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of offset reset + * + * + * + * + * \param unsigned char offset_reset + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_reset(unsigned char offset_reset) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_RESET_OFFSET_REGS__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_RESET_OFFSET_REGS, offset_reset); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_RESET_OFFSET_REGS__REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of offset reset + * + * + * + * + * \param unsigned char channel,unsigned char *offset + * Channel -> + * BMA2x2_CUT_OFF -> 0 + * BMA2x2_OFFSET_TRIGGER_X -> 1 + * BMA2x2_OFFSET_TRIGGER_Y -> 2 + * BMA2x2_OFFSET_TRIGGER_Z -> 3 + * offset -> + * CUT_OFF -> 0 or 1 + * BMA2x2_OFFSET_TRIGGER_X -> 0,1,2,3 + * BMA2x2_OFFSET_TRIGGER_Y -> 0,1,2,3 + * BMA2x2_OFFSET_TRIGGER_Z -> 0,1,2,3 + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset_target(unsigned char channel, unsigned char *offset) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_CUT_OFF: + // CUT-OFF + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_CUTOFF__REG, + &data, + C_BMA2x2_One_U8X); + *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_CUTOFF); + break; + + case BMA2x2_OFFSET_TRIGGER_X: + // OFFSET TRIGGER X + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_X__REG, + &data, + C_BMA2x2_One_U8X); + *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_X); + break; + + case BMA2x2_OFFSET_TRIGGER_Y: + // OFFSET TRIGGER Y + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Y__REG, + &data, + C_BMA2x2_One_U8X); + *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Y); + break; + + case BMA2x2_OFFSET_TRIGGER_Z: + // OFFSET TRIGGER Z + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Z__REG, + &data, + C_BMA2x2_One_U8X); + *offset = BMA2x2_GET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Z); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of offset reset + * + * + * + * + * \param unsigned char channel,unsigned char offset + * Channel -> + * BMA2x2_CUT_OFF -> 0 + * BMA2x2_OFFSET_TRIGGER_X -> 1 + * BMA2x2_OFFSET_TRIGGER_Y -> 2 + * BMA2x2_OFFSET_TRIGGER_Z -> 3 + * offset -> + * CUT_OFF -> 0 or 1 + * BMA2x2_OFFSET_TRIGGER_X -> 0,1,2,3 + * BMA2x2_OFFSET_TRIGGER_Y -> 0,1,2,3 + * BMA2x2_OFFSET_TRIGGER_Z -> 0,1,2,3 + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_target(unsigned char channel, unsigned char offset) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_CUT_OFF: + // CUT-OFF + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_CUTOFF__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_CUTOFF, offset); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_CUTOFF__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_OFFSET_TRIGGER_X: + // OFFSET TARGET X + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_X__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_X, offset); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_X__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_OFFSET_TRIGGER_Y: + // OFFSET TARGET Y + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Y__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Y, offset); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Y__REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_OFFSET_TRIGGER_Z: + // OFFSET TARGET Z + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Z__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_COMP_TARGET_OFFSET_Z, offset); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_COMP_TARGET_OFFSET_Z__REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of offset + * + * + * + * + * \param unsigned char channel,unsigned char *offset + * Channel -> + * BMA2x2_X_AXIS -> 0 + * BMA2x2_Y_AXIS -> 1 + * BMA2x2_Z_AXIS -> 2 + * offset -> Any valid value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset(unsigned char channel, unsigned char *offset) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_X_AXIS: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_X_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + *offset = data; + break; + + case BMA2x2_Y_AXIS: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_Y_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + *offset = data; + break; + + case BMA2x2_Z_AXIS: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_Z_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + *offset = data; + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of offset + * + * + * + * + * \param unsigned char channel,unsigned char offset + * Channel -> + * BMA2x2_X_AXIS -> 0 + * BMA2x2_Y_AXIS -> 1 + * BMA2x2_Z_AXIS -> 2 + * offset -> Any valid value + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset(unsigned char channel, unsigned char offset) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_X_AXIS: + data = offset; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_X_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_Y_AXIS: + data = offset; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_Y_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + break; + + case BMA2x2_Z_AXIS: + data = offset; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_OFFSET_Z_AXIS_REG, + &data, + C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************************** + * Description: *//**\brief This API is used to get the status of general purpose register + * + * + * + * + * \param unsigned char channel,unsigned char *gp + * channel -> + * BMA2x2_GP0 0 + * BMA2x2_GP1 1 + * gp -> Any valid value + * + * + * + * \return + * + * + *******************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_gp(unsigned char channel, unsigned char *gp) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_GP0: + // GP0 + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_GP0_REG, &data, C_BMA2x2_One_U8X); + *gp = data; + break; + + case BMA2x2_GP1: + // GP1 + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_GP1_REG, &data, C_BMA2x2_One_U8X); + *gp = data; + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/********************************************************************************************* +* Description: *//**\brief This API is used to set the status of general purpose register +* +* +* +* +* \param unsigned char channel,unsigned char gp +* channel -> +* BMA2x2_GP0 0 +* BMA2x2_GP1 1 +* gp -> Any valid value +* +* +* +* \return communication results +* +* +*********************************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_gp(unsigned char channel, unsigned char gp) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (channel) { + case BMA2x2_GP0: + // GP0 + data = gp; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_GP0_REG, &data, C_BMA2x2_One_U8X); + break; + + case BMA2x2_GP1: + // GP1 + data = gp; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_GP1_REG, &data, C_BMA2x2_One_U8X); + break; + + default: + comres = E_BMA2x2_OUT_OF_RANGE; + break; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of fifo mode + * + * + * + * + * \param unsigned char *fifo_mode : Address of fifo_mode + * fifo_mode 0 --> Bypass + * 1 --> FIFO + * 2 --> Stream + * 3 --> Reserved + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_mode(unsigned char *fifo_mode) +{ + int comres; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); + *fifo_mode = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_MODE); + } + return comres; +} + +/******************************************************************************* + * Description: *//**\brief This API is used set to FIFO mode + * + * + * + * + * \param unsigned char fifo_mode + * + * + * fifo_mode 0 --> Bypass + * 1 --> FIFO + * 2 --> Stream + * 3 --> Reserved + * + * + * + * + * \return Communication Results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_mode(unsigned char fifo_mode) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (fifo_mode < C_BMA2x2_Four_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_MODE, fifo_mode); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, BMA2x2_FIFO_MODE__REG, &data, C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of fifo data sel + * + * + * + * + * \param unsigned char *data_sel : Address of data_sel + * data_sel --> [0:3] + * 0 --> X,Y and Z (DEFAULT) + * 1 --> X only + * 2 --> Y only + * 3 --> Z only + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_sel(unsigned char *data_sel) +{ + int comres; + unsigned char data; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_DATA_SELECT__REG, + &data, + C_BMA2x2_One_U8X); + *data_sel = BMA2x2_GET_BITSLICE(data, BMA2x2_FIFO_DATA_SELECT); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of fifo data sel + * + * + * + * + * \param unsigned char data_sel + * data_sel --> [0:3] + * 0 --> X,Y and Z (DEFAULT) + * 1 --> X only + * 2 --> Y only + * 3 --> Z only + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_sel(unsigned char data_sel) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + if (data_sel < C_BMA2x2_Four_U8X) { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_DATA_SELECT__REG, + &data, + C_BMA2x2_One_U8X); + data = BMA2x2_SET_BITSLICE(data, BMA2x2_FIFO_DATA_SELECT, data_sel); + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_DATA_SELECT__REG, + &data, + C_BMA2x2_One_U8X); + } + else { + comres = E_OUT_OF_RANGE; + } + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to get the status of fifo data out reg + * + * + * + * + * \param unsigned char *out_reg : Address of out_reg + * Any Valid Value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_out_reg(unsigned char *out_reg) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + // GET FIFO DATA OUTPUT REGISTER + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_DATA_OUTPUT_REG, + &data, + C_BMA2x2_One_U8X); + *out_reg = data; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to set the status of fifo data out reg + * + * + * + * + * \param unsigned char out_reg + * Any Valid Value + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_out_reg(unsigned char out_reg) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + // SET FIFO DATA REGISTER + data = out_reg; + comres = p_bma2x2->BMA2x2_BUS_WRITE_FUNC(p_bma2x2->dev_addr, + BMA2x2_FIFO_DATA_OUTPUT_REG, + &data, + C_BMA2x2_One_U8X); + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API is used to read the temperature + * + * + * + * + * \param signed char temperature + * Pointer to temperature + * + * + * + * \return communication results + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_temperature(signed char *temperature) +{ + unsigned char data; + int comres = C_BMA2x2_Zero_U8X; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_TEMPERATURE_REG, &data, C_BMA2x2_One_U8X); + *temperature = (signed char) data; + } + return comres; +} + +/* Compiler Switch if applicable + #ifdef + + #endif + */ +/******************************************************************************* + * Description: *//**\brief This API reads acceleration data X,Y,Z values and + * Temperature data from location 02h to 08h + * + * + * + * + * \param bma2x2acc_data * acc : Address of bma2x2acc_data + * + * + * + * \return result of communication routines + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_accel_xyzt(bma2x2acc_data *acc) +{ + BMA2x2_RETURN_FUNCTION_TYPE comres = 0; + unsigned char data[7]; + if (p_bma2x2 == C_BMA2x2_Zero_U8X) { + comres = E_SMB_NULL_PTR; + } + else { + switch (V_BMA2x2RESOLUTION_U8R) { + case BMA2x2_12_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X12_LSB__REG, data, 7); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X12_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X12_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X12_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y12_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y12_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y12_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z12_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z12_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z12_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->temperature = (signed char) data[6]; + break; + + case BMA2x2_10_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X10_LSB__REG, data, 7); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X10_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X10_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X10_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y10_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y10_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y10_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z10_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z10_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z10_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->temperature = (signed char) data[6]; + break; + + case BMA2x2_8_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X8_LSB__REG, data, 7); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X8_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X8_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X8_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y8_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y8_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y8_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z8_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z8_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z8_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->temperature = (signed char) data[6]; + break; + + case BMA2x2_14_RESOLUTION: + comres = p_bma2x2->BMA2x2_BUS_READ_FUNC(p_bma2x2->dev_addr, BMA2x2_ACC_X14_LSB__REG, data, 7); + acc->x = + BMA2x2_GET_BITSLICE(data[0], + BMA2x2_ACC_X14_LSB) | + (BMA2x2_GET_BITSLICE(data[1], BMA2x2_ACC_X_MSB) << (BMA2x2_ACC_X14_LSB__LEN)); + acc->x = acc->x << (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + acc->x = acc->x >> (sizeof(short) * 8 - (BMA2x2_ACC_X14_LSB__LEN + BMA2x2_ACC_X_MSB__LEN)); + + acc->y = + BMA2x2_GET_BITSLICE(data[2], + BMA2x2_ACC_Y14_LSB) | + (BMA2x2_GET_BITSLICE(data[3], BMA2x2_ACC_Y_MSB) << (BMA2x2_ACC_Y14_LSB__LEN )); + acc->y = acc->y << (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + acc->y = acc->y >> (sizeof(short) * 8 - (BMA2x2_ACC_Y14_LSB__LEN + BMA2x2_ACC_Y_MSB__LEN)); + + acc->z = + BMA2x2_GET_BITSLICE(data[4], + BMA2x2_ACC_Z14_LSB) | + (BMA2x2_GET_BITSLICE(data[5], BMA2x2_ACC_Z_MSB) << (BMA2x2_ACC_Z14_LSB__LEN)); + acc->z = acc->z << (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->z = acc->z >> (sizeof(short) * 8 - (BMA2x2_ACC_Z14_LSB__LEN + BMA2x2_ACC_Z_MSB__LEN)); + acc->temperature = (signed char) data[6]; + break; + + default: + break; + } + } + return comres; +} + + + diff --git a/embedded/common/modules/sensor-drivers/bma2x2.h b/embedded/common/modules/sensor-drivers/bma2x2.h index 9abe7d2..17635bb 100644 --- a/embedded/common/modules/sensor-drivers/bma2x2.h +++ b/embedded/common/modules/sensor-drivers/bma2x2.h @@ -1,1747 +1,1747 @@ -/* - *************************************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - **************************************************************************************************/ -/* $Date: 2012/11/06 - * $Revision: 1.3 $ - * - */ - -/************************************************************************************************** -* Copyright (C) 2007 Bosch Sensortec GmbH -* -* bma2x2.h -* -* Usage: BMA2x2 Sensor Driver Support Header File -* -**************************************************************************************************/ -/*************************************************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. They may only be used - * within the parameters of the respective valid product data sheet. Bosch Sensortec products are - * provided with the express understanding that there is no warranty of fitness for a particular purpose. - * They are not fit for use in life-sustaining, safety or security sensitive systems or any system or device - * that may lead to bodily harm or property damage if the system or device malfunctions. In addition, - * Bosch Sensortec products are not fit for use in products which interact with motor vehicle systems. - * The resale and/or use of products are at the purchaser’s own risk and his own responsibility. The - * examination of fitness for the intended use is the sole responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party claims, including any claims for - * incidental, or consequential damages, arising from any product use not covered by the parameters of - * the respective valid product data sheet or not approved by Bosch Sensortec and reimburse Bosch - * Sensortec for all costs in connection with such claims. - * - * The purchaser must monitor the market for the purchased products, particularly with regard to - * product safety and inform Bosch Sensortec without delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary from the valid - * technical specifications of the product series. They are therefore not intended or fit for resale to third - * parties or for use in end products. Their sole purpose is internal client testing. The testing of an - * engineering sample may in no way replace the testing of a product series. Bosch Sensortec - * assumes no liability for the use of engineering samples. By accepting the engineering samples, the - * Purchaser agrees to indemnify Bosch Sensortec from all claims arising from the use of engineering - * samples. - * - * Special: - * This software module (hereinafter called "Software") and any information on application-sheets - * (hereinafter called "Information") is provided free of charge for the sole purpose to support your - * application work. The Software and Information is subject to the following terms and conditions: - * - * The Software is specifically designed for the exclusive use for Bosch Sensortec products by - * personnel who have special experience and training. Do not use this Software if you do not have the - * proper experience or training. - * - * This Software package is provided `` as is `` and without any expressed or implied warranties, - * including without limitation, the implied warranties of merchantability and fitness for a particular - * purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability for the functional impairment - * of this Software in terms of fitness, performance and safety. Bosch Sensortec and their - * representatives and agents shall not be liable for any direct or indirect damages or injury, except as - * otherwise stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. Bosch Sensortec assumes no - * responsibility for the consequences of use of such Information nor for any infringement of patents or - * other rights of third parties which may result from its use. No license is granted by implication or - * otherwise under any patent or patent rights of Bosch. Specifications mentioned in the Information are - * subject to change without notice. - * - * It is not allowed to deliver the source code of the Software to any third party without permission of - * Bosch Sensortec. - */ -/*************************************************************************************************/ -/*! \file bma2x2.h - \brief BMA2x2 Sensor Driver Support Header File */ -/* user defined code to be added here ... */ -#ifndef __BMA2x2_H__ -#define __BMA2x2_H__ - -// Example.... -// #define YOUR_H_DEFINE /**< */ -/** Define the calling convention of YOUR bus communication routine. - \note This includes types of parameters. This example shows the configuration for an SPI bus link. - - If your communication function looks like this: - - write_my_bus_xy(unsigned char device_addr, unsigned char register_addr, unsigned char * data, unsigned char length); - - The BMA2x2_WR_FUNC_PTR would equal: - - #define BMA2x2_WR_FUNC_PTR char (* bus_write)(unsigned char, unsigned char, unsigned char *, unsigned char) - - Parameters can be mixed as needed refer to the \ref BMA2x2_BUS_WRITE_FUNC macro. - - - */ -#define BMA2x2_WR_FUNC_PTR char (*bus_write)(unsigned char, unsigned char, unsigned char *, unsigned char) - -/** link makro between API function calls and bus write function - \note The bus write function can change since this is a system dependant issue. - - If the bus_write parameter calling order is like: reg_addr, reg_data, wr_len it would be as it is here. - - If the parameters are differently ordered or your communication function like I2C need to know the device address, - you can change this macro accordingly. - - - define BMA2x2_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ - bus_write(dev_addr, reg_addr, reg_data, wr_len) - - This macro lets all API functions call YOUR communication routine in a way that equals your definition in the - \ref BMA2x2_WR_FUNC_PTR definition. - - - - */ -#define BMA2x2_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len) \ - bus_write(dev_addr, reg_addr, reg_data, wr_len) - -/** Define the calling convention of YOUR bus communication routine. - \note This includes types of parameters. This example shows the configuration for an SPI bus link. - - If your communication function looks like this: - - read_my_bus_xy(unsigned char device_addr, unsigned char register_addr, unsigned char * data, unsigned char length); - - The BMA2x2_RD_FUNC_PTR would equal: - - #define BMA2x2_RD_FUNC_PTR char (* bus_read)(unsigned char, unsigned char, unsigned char *, unsigned char) - - Parameters can be mixed as needed refer to the \ref BMA2x2_BUS_READ_FUNC macro. - - - */ - -#define BMA2x2_SPI_RD_MASK 0x80 /* for spi read transactions on SPI the MSB has to be set */ -#define BMA2x2_RD_FUNC_PTR char (*bus_read)(unsigned char, unsigned char, unsigned char *, unsigned char) -#define BMA2x2_BRD_FUNC_PTR char (*burst_read)(unsigned char, unsigned char, unsigned char *, unsigned int) - -/** link makro between API function calls and bus read function - \note The bus write function can change since this is a system dependant issue. - - If the bus_read parameter calling order is like: reg_addr, reg_data, wr_len it would be as it is here. - - If the parameters are differently ordered or your communication function like I2C need to know the device address, - you can change this macro accordingly. - - - define BMA2x2_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ - bus_read(dev_addr, reg_addr, reg_data, wr_len) - - This macro lets all API functions call YOUR communication routine in a way that equals your definition in the - \ref BMA2x2_WR_FUNC_PTR definition. - - \note: this macro also includes the "MSB='1'" for reading BMA2x2 addresses. - - */ -#define BMA2x2_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, r_len) \ - bus_read(dev_addr, reg_addr, reg_data, r_len) -#define BMA2x2_BURST_READ_FUNC(device_addr, register_addr, register_data, rd_len) \ - burst_read(device_addr, register_addr, register_data, rd_len) -/** bma2x2 I2C Address - */ - -/* The LPC5102 sensor board has BMC150 and BMI055. - * BMC150 is an Accel/Mag combo chip. Accel I2C address is 0x10. Mag I2C address is 0x12 - * BMI055 is an Accel/Gyro combo chip. Accel I2C address is 0x19. Gyro I2C address is 0x69 - */ -#define BMA2x2_I2C_ADDR1 0x18 -#define BMA2x2_I2C_ADDR2 0x19 - -#define BMA2x2_I2C_ADDR (0x19) - - - -#define C_BMA2x2_Zero_U8X (unsigned char) 0 -#define C_BMA2x2_One_U8X (unsigned char) 1 -#define C_BMA2x2_Two_U8X (unsigned char) 2 -#define C_BMA2x2_Three_U8X (unsigned char) 3 -#define C_BMA2x2_Four_U8X (unsigned char) 4 -#define C_BMA2x2_Five_U8X (unsigned char) 5 -#define C_BMA2x2_Six_U8X (unsigned char) 6 -#define C_BMA2x2_Seven_U8X (unsigned char) 7 -#define C_BMA2x2_Eight_U8X (unsigned char) 8 -#define C_BMA2x2_Nine_U8X (unsigned char) 9 -#define C_BMA2x2_Twelve_U8X (unsigned char) 12 -#define C_BMA2x2_Fifteen_U8X (unsigned char) 15 -#define C_BMA2x2_Sixteen_U8X (unsigned char) 16 -#define C_BMA2x2_ThirtyTwo_U8X (unsigned char) 32 - -/* - SMB380 API error codes - */ - -#define E_SMB_NULL_PTR (char) -127 -#define E_COMM_RES (char) -1 -#define E_OUT_OF_RANGE (char) -2 -#define E_EEPROM_BUSY (char) -3 - -#define BMA2x2_RETURN_FUNCTION_TYPE int /**< This refers BMA2x2 return type as char */ - -/* - * - * register definitions - * - */ - -#define BMA2x2_EEP_OFFSET 0x16 -#define BMA2x2_IMAGE_BASE 0x38 -#define BMA2x2_IMAGE_LEN 22 - -#define BMA2x2_CHIP_ID_REG 0x00 -#define BMA2x2_X_AXIS_LSB_REG 0x02 -#define BMA2x2_X_AXIS_MSB_REG 0x03 -#define BMA2x2_Y_AXIS_LSB_REG 0x04 -#define BMA2x2_Y_AXIS_MSB_REG 0x05 -#define BMA2x2_Z_AXIS_LSB_REG 0x06 -#define BMA2x2_Z_AXIS_MSB_REG 0x07 -#define BMA2x2_TEMPERATURE_REG 0x08 -#define BMA2x2_STATUS1_REG 0x09 -#define BMA2x2_STATUS2_REG 0x0A -#define BMA2x2_STATUS_TAP_SLOPE_REG 0x0B -#define BMA2x2_STATUS_ORIENT_HIGH_REG 0x0C -#define BMA2x2_STATUS_FIFO_REG 0x0E // ADDED -#define BMA2x2_RANGE_SEL_REG 0x0F -#define BMA2x2_BW_SEL_REG 0x10 -#define BMA2x2_MODE_CTRL_REG 0x11 -#define BMA2x2_LOW_NOISE_CTRL_REG 0x12 -#define BMA2x2_DATA_CTRL_REG 0x13 -#define BMA2x2_RESET_REG 0x14 -#define BMA2x2_INT_ENABLE1_REG 0x16 -#define BMA2x2_INT_ENABLE2_REG 0x17 -#define BMA2x2_INT_SLO_NO_MOT_REG 0x18 // ADDED -#define BMA2x2_INT1_PAD_SEL_REG 0x19 -#define BMA2x2_INT_DATA_SEL_REG 0x1A -#define BMA2x2_INT2_PAD_SEL_REG 0x1B -#define BMA2x2_INT_SRC_REG 0x1E -#define BMA2x2_INT_SET_REG 0x20 -#define BMA2x2_INT_CTRL_REG 0x21 -#define BMA2x2_LOW_DURN_REG 0x22 -#define BMA2x2_LOW_THRES_REG 0x23 -#define BMA2x2_LOW_HIGH_HYST_REG 0x24 -#define BMA2x2_HIGH_DURN_REG 0x25 -#define BMA2x2_HIGH_THRES_REG 0x26 -#define BMA2x2_SLOPE_DURN_REG 0x27 -#define BMA2x2_SLOPE_THRES_REG 0x28 -#define BMA2x2_SLO_NO_MOT_THRES_REG 0x29 // ADDED -#define BMA2x2_TAP_PARAM_REG 0x2A -#define BMA2x2_TAP_THRES_REG 0x2B -#define BMA2x2_ORIENT_PARAM_REG 0x2C -#define BMA2x2_THETA_BLOCK_REG 0x2D -#define BMA2x2_THETA_FLAT_REG 0x2E -#define BMA2x2_FLAT_HOLD_TIME_REG 0x2F -#define BMA2x2_FIFO_WML_TRIG 0x30 // ADDED -#define BMA2x2_SELF_TEST_REG 0x32 -#define BMA2x2_EEPROM_CTRL_REG 0x33 -#define BMA2x2_SERIAL_CTRL_REG 0x34 -#define BMA2x2_OFFSET_CTRL_REG 0x36 -#define BMA2x2_OFFSET_PARAMS_REG 0x37 -#define BMA2x2_OFFSET_X_AXIS_REG 0x38 -#define BMA2x2_OFFSET_Y_AXIS_REG 0x39 -#define BMA2x2_OFFSET_Z_AXIS_REG 0x3A -#define BMA2x2_GP0_REG 0x3B // ADDED -#define BMA2x2_GP1_REG 0x3C // ADDED -#define BMA2x2_FIFO_MODE_REG 0x3E // ADDED -#define BMA2x2_FIFO_DATA_OUTPUT_REG 0x3F // ADDED - -#define E_BMA2x2_NULL_PTR (char) -127 -#define BMA2x2_NULL 0 - -#define BMA2x2_12_RESOLUTION 0 -#define BMA2x2_10_RESOLUTION 1 -#define BMA2x2_8_RESOLUTION 2 -#define BMA2x2_14_RESOLUTION 3 - -/* register write and read delays */ - -#define BMA2x2_MDELAY_DATA_TYPE unsigned int -#define BMA2x2_EE_W_DELAY 28 /* delay after EEP write is 28 msec */ -/** bma2x2 acceleration data - \brief Structure containing acceleration values for x,y and z-axis in signed short - - */ - -typedef struct { - short x,/**< holds x-axis acceleration data sign extended. Range -512 to 511. */ - y,/**< holds y-axis acceleration data sign extended. Range -512 to 511. */ - z;/**< holds z-axis acceleration data sign extended. Range -512 to 511. */ -} bma2x2acc_t; -typedef struct { - short x,/**< holds x-axis acceleration data sign extended. Range -512 to 511. */ - y,/**< holds y-axis acceleration data sign extended. Range -512 to 511. */ - z;/**< holds z-axis acceleration data sign extended. Range -512 to 511. */ - signed char temperature; /**< holds Temperature data sign extended. Range -128 to 127. */ -} bma2x2acc_data; -/** bma2x2 image registers data structure - \brief Register type that contains all bma2x2 image registers from address 0x38 to 0x4D - This structure can hold the complete image data of bma2x2 - - */ -typedef struct { - unsigned char - offset_filt_x, /**< image address 0x38: */ - offset_filt_y, /**< image address 0x39: */ - offset_filt_z, /**< image address 0x3A: */ - offset_unfilt_x, /**< image address 0x3B: */ - offset_unfilt_y, /**< image address 0x3C: */ - offset_unfilt_z, /**< image address 0x3D: */ - spare_0, /**< image address 0x3E: */ - spare_1, /**< image address 0x3F: */ - crc, /**< image address 0x40: */ - i2c_addr, /**< image address 0x41: */ - dev_config, /**< image address 0x42: */ - trim_offset_t, /**< image address 0x43: */ - gain_x, /**< image address 0x44: */ - offset_x, /**< image address 0x45: */ - gain_y, /**< image address 0x46: */ - offset_y, /**< image address 0x47: */ - gain_z, /**< image address 0x48: */ - offset_z, /**< image address 0x49: */ - trim1, /**< image address 0x4A: */ - trim2, /**< image address 0x4B: */ - trim3, /**< image address 0x4C: */ - trim4; /**< image address 0x4D: */ -} bma2x2regs_t; -/** bma2x2 typedef structure - \brief This structure holds all relevant information about bma2x2 and links communication to the - */ -typedef struct { - bma2x2regs_t *image; /**< pointer to bma2x2regs_t structure not mandatory */ - unsigned char mode; /**< save current bma2x2 operation mode */ - unsigned char chip_id, /**< save bma2x2's chip id which has to be 0x02 after calling bma2x2_init() */ - version; /**< holds the bma2x2 version number */ - unsigned char dev_addr; /**< initializes bma2x2's I2C device address 0x38 */ - unsigned char int_mask; /**< stores the current bma2x2 API generated interrupt mask */ - BMA2x2_WR_FUNC_PTR; /**< function pointer to the SPI/I2C write function */ - BMA2x2_RD_FUNC_PTR; /**< function pointer to the SPI/I2C read function */ - BMA2x2_BRD_FUNC_PTR; - void (*delay_msec)(BMA2x2_MDELAY_DATA_TYPE); /**< function pointer to a pause in mili seconds function */ -} bma2x2_t; -#define BMA2x2_CHIP_ID__POS 0 -#define BMA2x2_CHIP_ID__MSK 0xFF -#define BMA2x2_CHIP_ID__LEN 8 -#define BMA2x2_CHIP_ID__REG BMA2x2_CHIP_ID_REG - -/* DATA REGISTERS */ - -#define BMA2x2_NEW_DATA_X__POS 0 -#define BMA2x2_NEW_DATA_X__LEN 1 -#define BMA2x2_NEW_DATA_X__MSK 0x01 -#define BMA2x2_NEW_DATA_X__REG BMA2x2_X_AXIS_LSB_REG - -#define BMA2x2_ACC_X14_LSB__POS 2 -#define BMA2x2_ACC_X14_LSB__LEN 6 -#define BMA2x2_ACC_X14_LSB__MSK 0xFC -#define BMA2x2_ACC_X14_LSB__REG BMA2x2_X_AXIS_LSB_REG - -#define BMA2x2_ACC_X12_LSB__POS 4 -#define BMA2x2_ACC_X12_LSB__LEN 4 -#define BMA2x2_ACC_X12_LSB__MSK 0xF0 -#define BMA2x2_ACC_X12_LSB__REG BMA2x2_X_AXIS_LSB_REG - -#define BMA2x2_ACC_X10_LSB__POS 6 -#define BMA2x2_ACC_X10_LSB__LEN 2 -#define BMA2x2_ACC_X10_LSB__MSK 0xC0 -#define BMA2x2_ACC_X10_LSB__REG BMA2x2_X_AXIS_LSB_REG - -#define BMA2x2_ACC_X8_LSB__POS 0 -#define BMA2x2_ACC_X8_LSB__LEN 0 -#define BMA2x2_ACC_X8_LSB__MSK 0x00 -#define BMA2x2_ACC_X8_LSB__REG BMA2x2_X_AXIS_LSB_REG - -#define BMA2x2_ACC_X_MSB__POS 0 -#define BMA2x2_ACC_X_MSB__LEN 8 -#define BMA2x2_ACC_X_MSB__MSK 0xFF -#define BMA2x2_ACC_X_MSB__REG BMA2x2_X_AXIS_MSB_REG - -#define BMA2x2_NEW_DATA_Y__POS 0 -#define BMA2x2_NEW_DATA_Y__LEN 1 -#define BMA2x2_NEW_DATA_Y__MSK 0x01 -#define BMA2x2_NEW_DATA_Y__REG BMA2x2_Y_AXIS_LSB_REG - -#define BMA2x2_ACC_Y14_LSB__POS 2 -#define BMA2x2_ACC_Y14_LSB__LEN 6 -#define BMA2x2_ACC_Y14_LSB__MSK 0xFC -#define BMA2x2_ACC_Y14_LSB__REG BMA2x2_Y_AXIS_LSB_REG - -#define BMA2x2_ACC_Y12_LSB__POS 4 -#define BMA2x2_ACC_Y12_LSB__LEN 4 -#define BMA2x2_ACC_Y12_LSB__MSK 0xF0 -#define BMA2x2_ACC_Y12_LSB__REG BMA2x2_Y_AXIS_LSB_REG - -#define BMA2x2_ACC_Y10_LSB__POS 6 -#define BMA2x2_ACC_Y10_LSB__LEN 2 -#define BMA2x2_ACC_Y10_LSB__MSK 0xC0 -#define BMA2x2_ACC_Y10_LSB__REG BMA2x2_Y_AXIS_LSB_REG - -#define BMA2x2_ACC_Y8_LSB__POS 0 -#define BMA2x2_ACC_Y8_LSB__LEN 0 -#define BMA2x2_ACC_Y8_LSB__MSK 0x00 -#define BMA2x2_ACC_Y8_LSB__REG BMA2x2_Y_AXIS_LSB_REG - -#define BMA2x2_ACC_Y_MSB__POS 0 -#define BMA2x2_ACC_Y_MSB__LEN 8 -#define BMA2x2_ACC_Y_MSB__MSK 0xFF -#define BMA2x2_ACC_Y_MSB__REG BMA2x2_Y_AXIS_MSB_REG - -#define BMA2x2_NEW_DATA_Z__POS 0 -#define BMA2x2_NEW_DATA_Z__LEN 1 -#define BMA2x2_NEW_DATA_Z__MSK 0x01 -#define BMA2x2_NEW_DATA_Z__REG BMA2x2_Z_AXIS_LSB_REG - -#define BMA2x2_ACC_Z14_LSB__POS 2 -#define BMA2x2_ACC_Z14_LSB__LEN 6 -#define BMA2x2_ACC_Z14_LSB__MSK 0xFC -#define BMA2x2_ACC_Z14_LSB__REG BMA2x2_Z_AXIS_LSB_REG - -#define BMA2x2_ACC_Z12_LSB__POS 4 -#define BMA2x2_ACC_Z12_LSB__LEN 4 -#define BMA2x2_ACC_Z12_LSB__MSK 0xF0 -#define BMA2x2_ACC_Z12_LSB__REG BMA2x2_Z_AXIS_LSB_REG - -#define BMA2x2_ACC_Z10_LSB__POS 6 -#define BMA2x2_ACC_Z10_LSB__LEN 2 -#define BMA2x2_ACC_Z10_LSB__MSK 0xC0 -#define BMA2x2_ACC_Z10_LSB__REG BMA2x2_Z_AXIS_LSB_REG - -#define BMA2x2_ACC_Z8_LSB__POS 0 -#define BMA2x2_ACC_Z8_LSB__LEN 0 -#define BMA2x2_ACC_Z8_LSB__MSK 0x00 -#define BMA2x2_ACC_Z8_LSB__REG BMA2x2_Z_AXIS_LSB_REG - -#define BMA2x2_ACC_Z_MSB__POS 0 -#define BMA2x2_ACC_Z_MSB__LEN 8 -#define BMA2x2_ACC_Z_MSB__MSK 0xFF -#define BMA2x2_ACC_Z_MSB__REG BMA2x2_Z_AXIS_MSB_REG - -/* INTERRUPT STATUS BITS */ - -#define BMA2x2_LOWG_INT_S__POS 0 -#define BMA2x2_LOWG_INT_S__LEN 1 -#define BMA2x2_LOWG_INT_S__MSK 0x01 -#define BMA2x2_LOWG_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_HIGHG_INT_S__POS 1 -#define BMA2x2_HIGHG_INT_S__LEN 1 -#define BMA2x2_HIGHG_INT_S__MSK 0x02 -#define BMA2x2_HIGHG_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_SLOPE_INT_S__POS 2 -#define BMA2x2_SLOPE_INT_S__LEN 1 -#define BMA2x2_SLOPE_INT_S__MSK 0x04 -#define BMA2x2_SLOPE_INT_S__REG BMA2x2_STATUS1_REG - -// ADDED -#define BMA2x2_SLO_NO_MOT_INT_S__POS 3 -#define BMA2x2_SLO_NO_MOT_INT_S__LEN 1 -#define BMA2x2_SLO_NO_MOT_INT_S__MSK 0x08 -#define BMA2x2_SLO_NO_MOT_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_DOUBLE_TAP_INT_S__POS 4 -#define BMA2x2_DOUBLE_TAP_INT_S__LEN 1 -#define BMA2x2_DOUBLE_TAP_INT_S__MSK 0x10 -#define BMA2x2_DOUBLE_TAP_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_SINGLE_TAP_INT_S__POS 5 -#define BMA2x2_SINGLE_TAP_INT_S__LEN 1 -#define BMA2x2_SINGLE_TAP_INT_S__MSK 0x20 -#define BMA2x2_SINGLE_TAP_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_ORIENT_INT_S__POS 6 -#define BMA2x2_ORIENT_INT_S__LEN 1 -#define BMA2x2_ORIENT_INT_S__MSK 0x40 -#define BMA2x2_ORIENT_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_FLAT_INT_S__POS 7 -#define BMA2x2_FLAT_INT_S__LEN 1 -#define BMA2x2_FLAT_INT_S__MSK 0x80 -#define BMA2x2_FLAT_INT_S__REG BMA2x2_STATUS1_REG - -#define BMA2x2_FIFO_FULL_INT_S__POS 5 -#define BMA2x2_FIFO_FULL_INT_S__LEN 1 -#define BMA2x2_FIFO_FULL_INT_S__MSK 0x20 -#define BMA2x2_FIFO_FULL_INT_S__REG BMA2x2_STATUS2_REG - -#define BMA2x2_FIFO_WM_INT_S__POS 6 -#define BMA2x2_FIFO_WM_INT_S__LEN 1 -#define BMA2x2_FIFO_WM_INT_S__MSK 0x40 -#define BMA2x2_FIFO_WM_INT_S__REG BMA2x2_STATUS2_REG - -#define BMA2x2_DATA_INT_S__POS 7 -#define BMA2x2_DATA_INT_S__LEN 1 -#define BMA2x2_DATA_INT_S__MSK 0x80 -#define BMA2x2_DATA_INT_S__REG BMA2x2_STATUS2_REG -#define BMA2x2_SLOPE_FIRST_X__POS 0 -#define BMA2x2_SLOPE_FIRST_X__LEN 1 -#define BMA2x2_SLOPE_FIRST_X__MSK 0x01 -#define BMA2x2_SLOPE_FIRST_X__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_SLOPE_FIRST_Y__POS 1 -#define BMA2x2_SLOPE_FIRST_Y__LEN 1 -#define BMA2x2_SLOPE_FIRST_Y__MSK 0x02 -#define BMA2x2_SLOPE_FIRST_Y__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_SLOPE_FIRST_Z__POS 2 -#define BMA2x2_SLOPE_FIRST_Z__LEN 1 -#define BMA2x2_SLOPE_FIRST_Z__MSK 0x04 -#define BMA2x2_SLOPE_FIRST_Z__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_SLOPE_SIGN_S__POS 3 -#define BMA2x2_SLOPE_SIGN_S__LEN 1 -#define BMA2x2_SLOPE_SIGN_S__MSK 0x08 -#define BMA2x2_SLOPE_SIGN_S__REG BMA2x2_STATUS_TAP_SLOPE_REG -#define BMA2x2_TAP_FIRST_X__POS 4 -#define BMA2x2_TAP_FIRST_X__LEN 1 -#define BMA2x2_TAP_FIRST_X__MSK 0x10 -#define BMA2x2_TAP_FIRST_X__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_TAP_FIRST_Y__POS 5 -#define BMA2x2_TAP_FIRST_Y__LEN 1 -#define BMA2x2_TAP_FIRST_Y__MSK 0x20 -#define BMA2x2_TAP_FIRST_Y__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_TAP_FIRST_Z__POS 6 -#define BMA2x2_TAP_FIRST_Z__LEN 1 -#define BMA2x2_TAP_FIRST_Z__MSK 0x40 -#define BMA2x2_TAP_FIRST_Z__REG BMA2x2_STATUS_TAP_SLOPE_REG - -#define BMA2x2_TAP_SIGN_S__POS 7 -#define BMA2x2_TAP_SIGN_S__LEN 1 -#define BMA2x2_TAP_SIGN_S__MSK 0x80 -#define BMA2x2_TAP_SIGN_S__REG BMA2x2_STATUS_TAP_SLOPE_REG -#define BMA2x2_HIGHG_FIRST_X__POS 0 -#define BMA2x2_HIGHG_FIRST_X__LEN 1 -#define BMA2x2_HIGHG_FIRST_X__MSK 0x01 -#define BMA2x2_HIGHG_FIRST_X__REG BMA2x2_STATUS_ORIENT_HIGH_REG - -#define BMA2x2_HIGHG_FIRST_Y__POS 1 -#define BMA2x2_HIGHG_FIRST_Y__LEN 1 -#define BMA2x2_HIGHG_FIRST_Y__MSK 0x02 -#define BMA2x2_HIGHG_FIRST_Y__REG BMA2x2_STATUS_ORIENT_HIGH_REG - -#define BMA2x2_HIGHG_FIRST_Z__POS 2 -#define BMA2x2_HIGHG_FIRST_Z__LEN 1 -#define BMA2x2_HIGHG_FIRST_Z__MSK 0x04 -#define BMA2x2_HIGHG_FIRST_Z__REG BMA2x2_STATUS_ORIENT_HIGH_REG - -#define BMA2x2_HIGHG_SIGN_S__POS 3 -#define BMA2x2_HIGHG_SIGN_S__LEN 1 -#define BMA2x2_HIGHG_SIGN_S__MSK 0x08 -#define BMA2x2_HIGHG_SIGN_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG -#define BMA2x2_ORIENT_S__POS 4 -#define BMA2x2_ORIENT_S__LEN 3 -#define BMA2x2_ORIENT_S__MSK 0x70 -#define BMA2x2_ORIENT_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG - -#define BMA2x2_FLAT_S__POS 7 -#define BMA2x2_FLAT_S__LEN 1 -#define BMA2x2_FLAT_S__MSK 0x80 -#define BMA2x2_FLAT_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG -// FIFO_STATUS - -#define BMA2x2_FIFO_FRAME_COUNTER_S__POS 0 -#define BMA2x2_FIFO_FRAME_COUNTER_S__LEN 7 -#define BMA2x2_FIFO_FRAME_COUNTER_S__MSK 0x7F -#define BMA2x2_FIFO_FRAME_COUNTER_S__REG BMA2x2_STATUS_FIFO_REG - -#define BMA2x2_FIFO_OVERRUN_S__POS 7 -#define BMA2x2_FIFO_OVERRUN_S__LEN 1 -#define BMA2x2_FIFO_OVERRUN_S__MSK 0x80 -#define BMA2x2_FIFO_OVERRUN_S__REG BMA2x2_STATUS_FIFO_REG -#define BMA2x2_RANGE_SEL__POS 0 -#define BMA2x2_RANGE_SEL__LEN 4 -#define BMA2x2_RANGE_SEL__MSK 0x0F -#define BMA2x2_RANGE_SEL__REG BMA2x2_RANGE_SEL_REG -#define BMA2x2_BANDWIDTH__POS 0 -#define BMA2x2_BANDWIDTH__LEN 5 -#define BMA2x2_BANDWIDTH__MSK 0x1F -#define BMA2x2_BANDWIDTH__REG BMA2x2_BW_SEL_REG -#define BMA2x2_SLEEP_DUR__POS 1 -#define BMA2x2_SLEEP_DUR__LEN 4 -#define BMA2x2_SLEEP_DUR__MSK 0x1E -#define BMA2x2_SLEEP_DUR__REG BMA2x2_MODE_CTRL_REG - -#define BMA2x2_MODE_CTRL__POS 5 -#define BMA2x2_MODE_CTRL__LEN 3 -#define BMA2x2_MODE_CTRL__MSK 0xE0 -#define BMA2x2_MODE_CTRL__REG BMA2x2_MODE_CTRL_REG -// ADDED - -#define BMA2x2_EN_LOW_POWER__POS 6 -#define BMA2x2_EN_LOW_POWER__LEN 1 -#define BMA2x2_EN_LOW_POWER__MSK 0x40 -#define BMA2x2_EN_LOW_POWER__REG BMA2x2_MODE_CTRL_REG - -// ADDED - -#define BMA2x2_SLEEP_TIMER__POS 5 -#define BMA2x2_SLEEP_TIMER__LEN 1 -#define BMA2x2_SLEEP_TIMER__MSK 0x20 -#define BMA2x2_SLEEP_TIMER__REG BMA2x2_LOW_NOISE_CTRL_REG - -// ADDED -#define BMA2x2_LOW_POWER_MODE__POS 6 -#define BMA2x2_LOW_POWER_MODE__LEN 1 -#define BMA2x2_LOW_POWER_MODE__MSK 0x40 -#define BMA2x2_LOW_POWER_MODE__REG BMA2x2_LOW_NOISE_CTRL_REG - -/** DISABLE MSB SHADOWING PROCEDURE **/ - -#define BMA2x2_DIS_SHADOW_PROC__POS 6 -#define BMA2x2_DIS_SHADOW_PROC__LEN 1 -#define BMA2x2_DIS_SHADOW_PROC__MSK 0x40 -#define BMA2x2_DIS_SHADOW_PROC__REG BMA2x2_DATA_CTRL_REG - -/** FILTERED OR UNFILTERED ACCELERATION DATA **/ - -#define BMA2x2_EN_DATA_HIGH_BW__POS 7 -#define BMA2x2_EN_DATA_HIGH_BW__LEN 1 -#define BMA2x2_EN_DATA_HIGH_BW__MSK 0x80 -#define BMA2x2_EN_DATA_HIGH_BW__REG BMA2x2_DATA_CTRL_REG - -#define BMA2x2_EN_SOFT_RESET_VALUE 0xB6 -/** INTERRUPT ENABLE REGISTER **/ - -#define BMA2x2_EN_SLOPE_X_INT__POS 0 -#define BMA2x2_EN_SLOPE_X_INT__LEN 1 -#define BMA2x2_EN_SLOPE_X_INT__MSK 0x01 -#define BMA2x2_EN_SLOPE_X_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_SLOPE_Y_INT__POS 1 -#define BMA2x2_EN_SLOPE_Y_INT__LEN 1 -#define BMA2x2_EN_SLOPE_Y_INT__MSK 0x02 -#define BMA2x2_EN_SLOPE_Y_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_SLOPE_Z_INT__POS 2 -#define BMA2x2_EN_SLOPE_Z_INT__LEN 1 -#define BMA2x2_EN_SLOPE_Z_INT__MSK 0x04 -#define BMA2x2_EN_SLOPE_Z_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_DOUBLE_TAP_INT__POS 4 -#define BMA2x2_EN_DOUBLE_TAP_INT__LEN 1 -#define BMA2x2_EN_DOUBLE_TAP_INT__MSK 0x10 -#define BMA2x2_EN_DOUBLE_TAP_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_SINGLE_TAP_INT__POS 5 -#define BMA2x2_EN_SINGLE_TAP_INT__LEN 1 -#define BMA2x2_EN_SINGLE_TAP_INT__MSK 0x20 -#define BMA2x2_EN_SINGLE_TAP_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_ORIENT_INT__POS 6 -#define BMA2x2_EN_ORIENT_INT__LEN 1 -#define BMA2x2_EN_ORIENT_INT__MSK 0x40 -#define BMA2x2_EN_ORIENT_INT__REG BMA2x2_INT_ENABLE1_REG - -#define BMA2x2_EN_FLAT_INT__POS 7 -#define BMA2x2_EN_FLAT_INT__LEN 1 -#define BMA2x2_EN_FLAT_INT__MSK 0x80 -#define BMA2x2_EN_FLAT_INT__REG BMA2x2_INT_ENABLE1_REG -/** INTERRUPT ENABLE REGISTER **/ - -#define BMA2x2_EN_HIGHG_X_INT__POS 0 -#define BMA2x2_EN_HIGHG_X_INT__LEN 1 -#define BMA2x2_EN_HIGHG_X_INT__MSK 0x01 -#define BMA2x2_EN_HIGHG_X_INT__REG BMA2x2_INT_ENABLE2_REG - -#define BMA2x2_EN_HIGHG_Y_INT__POS 1 -#define BMA2x2_EN_HIGHG_Y_INT__LEN 1 -#define BMA2x2_EN_HIGHG_Y_INT__MSK 0x02 -#define BMA2x2_EN_HIGHG_Y_INT__REG BMA2x2_INT_ENABLE2_REG - -#define BMA2x2_EN_HIGHG_Z_INT__POS 2 -#define BMA2x2_EN_HIGHG_Z_INT__LEN 1 -#define BMA2x2_EN_HIGHG_Z_INT__MSK 0x04 -#define BMA2x2_EN_HIGHG_Z_INT__REG BMA2x2_INT_ENABLE2_REG - -#define BMA2x2_EN_LOWG_INT__POS 3 -#define BMA2x2_EN_LOWG_INT__LEN 1 -#define BMA2x2_EN_LOWG_INT__MSK 0x08 -#define BMA2x2_EN_LOWG_INT__REG BMA2x2_INT_ENABLE2_REG - -#define BMA2x2_EN_NEW_DATA_INT__POS 4 -#define BMA2x2_EN_NEW_DATA_INT__LEN 1 -#define BMA2x2_EN_NEW_DATA_INT__MSK 0x10 -#define BMA2x2_EN_NEW_DATA_INT__REG BMA2x2_INT_ENABLE2_REG - -// ADDED -#define BMA2x2_INT_FFULL_EN_INT__POS 5 -#define BMA2x2_INT_FFULL_EN_INT__LEN 1 -#define BMA2x2_INT_FFULL_EN_INT__MSK 0x20 -#define BMA2x2_INT_FFULL_EN_INT__REG BMA2x2_INT_ENABLE2_REG - -#define BMA2x2_INT_FWM_EN_INT__POS 6 -#define BMA2x2_INT_FWM_EN_INT__LEN 1 -#define BMA2x2_INT_FWM_EN_INT__MSK 0x40 -#define BMA2x2_INT_FWM_EN_INT__REG BMA2x2_INT_ENABLE2_REG -// INT SLO NO MOT - -#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__POS 0 -#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__LEN 1 -#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__MSK 0x01 -#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG BMA2x2_INT_SLO_NO_MOT_REG - -#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__POS 1 -#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__LEN 1 -#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__MSK 0x02 -#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG BMA2x2_INT_SLO_NO_MOT_REG - -#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__POS 2 -#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__LEN 1 -#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__MSK 0x04 -#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG BMA2x2_INT_SLO_NO_MOT_REG - -#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__POS 3 -#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__LEN 1 -#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__MSK 0x08 -#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG BMA2x2_INT_SLO_NO_MOT_REG -#define BMA2x2_EN_INT1_PAD_LOWG__POS 0 -#define BMA2x2_EN_INT1_PAD_LOWG__LEN 1 -#define BMA2x2_EN_INT1_PAD_LOWG__MSK 0x01 -#define BMA2x2_EN_INT1_PAD_LOWG__REG BMA2x2_INT1_PAD_SEL_REG -#define BMA2x2_EN_INT1_PAD_HIGHG__POS 1 -#define BMA2x2_EN_INT1_PAD_HIGHG__LEN 1 -#define BMA2x2_EN_INT1_PAD_HIGHG__MSK 0x02 -#define BMA2x2_EN_INT1_PAD_HIGHG__REG BMA2x2_INT1_PAD_SEL_REG - -#define BMA2x2_EN_INT1_PAD_SLOPE__POS 2 -#define BMA2x2_EN_INT1_PAD_SLOPE__LEN 1 -#define BMA2x2_EN_INT1_PAD_SLOPE__MSK 0x04 -#define BMA2x2_EN_INT1_PAD_SLOPE__REG BMA2x2_INT1_PAD_SEL_REG - -// ADDED -#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__POS 3 -#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__LEN 1 -#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__MSK 0x08 -#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG BMA2x2_INT1_PAD_SEL_REG - -#define BMA2x2_EN_INT1_PAD_DB_TAP__POS 4 -#define BMA2x2_EN_INT1_PAD_DB_TAP__LEN 1 -#define BMA2x2_EN_INT1_PAD_DB_TAP__MSK 0x10 -#define BMA2x2_EN_INT1_PAD_DB_TAP__REG BMA2x2_INT1_PAD_SEL_REG - -#define BMA2x2_EN_INT1_PAD_SNG_TAP__POS 5 -#define BMA2x2_EN_INT1_PAD_SNG_TAP__LEN 1 -#define BMA2x2_EN_INT1_PAD_SNG_TAP__MSK 0x20 -#define BMA2x2_EN_INT1_PAD_SNG_TAP__REG BMA2x2_INT1_PAD_SEL_REG - -#define BMA2x2_EN_INT1_PAD_ORIENT__POS 6 -#define BMA2x2_EN_INT1_PAD_ORIENT__LEN 1 -#define BMA2x2_EN_INT1_PAD_ORIENT__MSK 0x40 -#define BMA2x2_EN_INT1_PAD_ORIENT__REG BMA2x2_INT1_PAD_SEL_REG - -#define BMA2x2_EN_INT1_PAD_FLAT__POS 7 -#define BMA2x2_EN_INT1_PAD_FLAT__LEN 1 -#define BMA2x2_EN_INT1_PAD_FLAT__MSK 0x80 -#define BMA2x2_EN_INT1_PAD_FLAT__REG BMA2x2_INT1_PAD_SEL_REG -#define BMA2x2_EN_INT2_PAD_LOWG__POS 0 -#define BMA2x2_EN_INT2_PAD_LOWG__LEN 1 -#define BMA2x2_EN_INT2_PAD_LOWG__MSK 0x01 -#define BMA2x2_EN_INT2_PAD_LOWG__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_HIGHG__POS 1 -#define BMA2x2_EN_INT2_PAD_HIGHG__LEN 1 -#define BMA2x2_EN_INT2_PAD_HIGHG__MSK 0x02 -#define BMA2x2_EN_INT2_PAD_HIGHG__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_SLOPE__POS 2 -#define BMA2x2_EN_INT2_PAD_SLOPE__LEN 1 -#define BMA2x2_EN_INT2_PAD_SLOPE__MSK 0x04 -#define BMA2x2_EN_INT2_PAD_SLOPE__REG BMA2x2_INT2_PAD_SEL_REG - -// ADDED - -#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__POS 3 -#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__LEN 1 -#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__MSK 0x08 -#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_DB_TAP__POS 4 -#define BMA2x2_EN_INT2_PAD_DB_TAP__LEN 1 -#define BMA2x2_EN_INT2_PAD_DB_TAP__MSK 0x10 -#define BMA2x2_EN_INT2_PAD_DB_TAP__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_SNG_TAP__POS 5 -#define BMA2x2_EN_INT2_PAD_SNG_TAP__LEN 1 -#define BMA2x2_EN_INT2_PAD_SNG_TAP__MSK 0x20 -#define BMA2x2_EN_INT2_PAD_SNG_TAP__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_ORIENT__POS 6 -#define BMA2x2_EN_INT2_PAD_ORIENT__LEN 1 -#define BMA2x2_EN_INT2_PAD_ORIENT__MSK 0x40 -#define BMA2x2_EN_INT2_PAD_ORIENT__REG BMA2x2_INT2_PAD_SEL_REG - -#define BMA2x2_EN_INT2_PAD_FLAT__POS 7 -#define BMA2x2_EN_INT2_PAD_FLAT__LEN 1 -#define BMA2x2_EN_INT2_PAD_FLAT__MSK 0x80 -#define BMA2x2_EN_INT2_PAD_FLAT__REG BMA2x2_INT2_PAD_SEL_REG -#define BMA2x2_EN_INT1_PAD_NEWDATA__POS 0 -#define BMA2x2_EN_INT1_PAD_NEWDATA__LEN 1 -#define BMA2x2_EN_INT1_PAD_NEWDATA__MSK 0x01 -#define BMA2x2_EN_INT1_PAD_NEWDATA__REG BMA2x2_INT_DATA_SEL_REG - -// ADDED -#define BMA2x2_EN_INT1_PAD_FWM__POS 1 -#define BMA2x2_EN_INT1_PAD_FWM__LEN 1 -#define BMA2x2_EN_INT1_PAD_FWM__MSK 0x02 -#define BMA2x2_EN_INT1_PAD_FWM__REG BMA2x2_INT_DATA_SEL_REG - -#define BMA2x2_EN_INT1_PAD_FFULL__POS 2 -#define BMA2x2_EN_INT1_PAD_FFULL__LEN 1 -#define BMA2x2_EN_INT1_PAD_FFULL__MSK 0x04 -#define BMA2x2_EN_INT1_PAD_FFULL__REG BMA2x2_INT_DATA_SEL_REG - -#define BMA2x2_EN_INT2_PAD_FFULL__POS 5 -#define BMA2x2_EN_INT2_PAD_FFULL__LEN 1 -#define BMA2x2_EN_INT2_PAD_FFULL__MSK 0x20 -#define BMA2x2_EN_INT2_PAD_FFULL__REG BMA2x2_INT_DATA_SEL_REG - -#define BMA2x2_EN_INT2_PAD_FWM__POS 6 -#define BMA2x2_EN_INT2_PAD_FWM__LEN 1 -#define BMA2x2_EN_INT2_PAD_FWM__MSK 0x40 -#define BMA2x2_EN_INT2_PAD_FWM__REG BMA2x2_INT_DATA_SEL_REG - -#define BMA2x2_EN_INT2_PAD_NEWDATA__POS 7 -#define BMA2x2_EN_INT2_PAD_NEWDATA__LEN 1 -#define BMA2x2_EN_INT2_PAD_NEWDATA__MSK 0x80 -#define BMA2x2_EN_INT2_PAD_NEWDATA__REG BMA2x2_INT_DATA_SEL_REG -/***** INTERRUPT SOURCE SELECTION *****/ - -#define BMA2x2_UNFILT_INT_SRC_LOWG__POS 0 -#define BMA2x2_UNFILT_INT_SRC_LOWG__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_LOWG__MSK 0x01 -#define BMA2x2_UNFILT_INT_SRC_LOWG__REG BMA2x2_INT_SRC_REG - -#define BMA2x2_UNFILT_INT_SRC_HIGHG__POS 1 -#define BMA2x2_UNFILT_INT_SRC_HIGHG__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_HIGHG__MSK 0x02 -#define BMA2x2_UNFILT_INT_SRC_HIGHG__REG BMA2x2_INT_SRC_REG - -#define BMA2x2_UNFILT_INT_SRC_SLOPE__POS 2 -#define BMA2x2_UNFILT_INT_SRC_SLOPE__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_SLOPE__MSK 0x04 -#define BMA2x2_UNFILT_INT_SRC_SLOPE__REG BMA2x2_INT_SRC_REG - -// ADDED -#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__POS 3 -#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__MSK 0x08 -#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG BMA2x2_INT_SRC_REG - -#define BMA2x2_UNFILT_INT_SRC_TAP__POS 4 -#define BMA2x2_UNFILT_INT_SRC_TAP__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_TAP__MSK 0x10 -#define BMA2x2_UNFILT_INT_SRC_TAP__REG BMA2x2_INT_SRC_REG - -#define BMA2x2_UNFILT_INT_SRC_DATA__POS 5 -#define BMA2x2_UNFILT_INT_SRC_DATA__LEN 1 -#define BMA2x2_UNFILT_INT_SRC_DATA__MSK 0x20 -#define BMA2x2_UNFILT_INT_SRC_DATA__REG BMA2x2_INT_SRC_REG -/***** INTERRUPT PAD ACTIVE LEVEL AND OUTPUT TYPE *****/ - -#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__POS 0 -#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__LEN 1 -#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__MSK 0x01 -#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG BMA2x2_INT_SET_REG - -#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__POS 2 -#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__LEN 1 -#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__MSK 0x04 -#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG BMA2x2_INT_SET_REG - -/***** OUTPUT TYPE IF SET TO 1 IS : OPEN DRIVE , IF NOT SET - IT IS PUSH-PULL *****/ - -#define BMA2x2_INT1_PAD_OUTPUT_TYPE__POS 1 -#define BMA2x2_INT1_PAD_OUTPUT_TYPE__LEN 1 -#define BMA2x2_INT1_PAD_OUTPUT_TYPE__MSK 0x02 -#define BMA2x2_INT1_PAD_OUTPUT_TYPE__REG BMA2x2_INT_SET_REG - -#define BMA2x2_INT2_PAD_OUTPUT_TYPE__POS 3 -#define BMA2x2_INT2_PAD_OUTPUT_TYPE__LEN 1 -#define BMA2x2_INT2_PAD_OUTPUT_TYPE__MSK 0x08 -#define BMA2x2_INT2_PAD_OUTPUT_TYPE__REG BMA2x2_INT_SET_REG -/***** INTERRUPT MODE SELECTION ******/ - -#define BMA2x2_LATCH_INT__POS 0 -#define BMA2x2_LATCH_INT__LEN 4 -#define BMA2x2_LATCH_INT__MSK 0x0F -#define BMA2x2_LATCH_INT__REG BMA2x2_INT_CTRL_REG - -/***** LATCHED INTERRUPT RESET ******/ - -#define BMA2x2_RESET_INT__POS 7 -#define BMA2x2_RESET_INT__LEN 1 -#define BMA2x2_RESET_INT__MSK 0x80 -#define BMA2x2_RESET_INT__REG BMA2x2_INT_CTRL_REG - -/***** LOW-G HYSTERESIS ******/ - -#define BMA2x2_LOWG_HYST__POS 0 -#define BMA2x2_LOWG_HYST__LEN 2 -#define BMA2x2_LOWG_HYST__MSK 0x03 -#define BMA2x2_LOWG_HYST__REG BMA2x2_LOW_HIGH_HYST_REG - -/***** LOW-G INTERRUPT MODE ******/ -/***** IF 1 -- SUM MODE , 0 -- SINGLE MODE ******/ -#define BMA2x2_LOWG_INT_MODE__POS 2 -#define BMA2x2_LOWG_INT_MODE__LEN 1 -#define BMA2x2_LOWG_INT_MODE__MSK 0x04 -#define BMA2x2_LOWG_INT_MODE__REG BMA2x2_LOW_HIGH_HYST_REG - -/***** HIGH-G HYSTERESIS ******/ - -#define BMA2x2_HIGHG_HYST__POS 6 -#define BMA2x2_HIGHG_HYST__LEN 2 -#define BMA2x2_HIGHG_HYST__MSK 0xC0 -#define BMA2x2_HIGHG_HYST__REG BMA2x2_LOW_HIGH_HYST_REG -/***** SLOPE DURATION ******/ - -#define BMA2x2_SLOPE_DUR__POS 0 -#define BMA2x2_SLOPE_DUR__LEN 2 -#define BMA2x2_SLOPE_DUR__MSK 0x03 -#define BMA2x2_SLOPE_DUR__REG BMA2x2_SLOPE_DURN_REG - -// SLO_NO_MOT_DUR ADDED -#define BMA2x2_SLO_NO_MOT_DUR__POS 2 -#define BMA2x2_SLO_NO_MOT_DUR__LEN 6 -#define BMA2x2_SLO_NO_MOT_DUR__MSK 0xFC -#define BMA2x2_SLO_NO_MOT_DUR__REG BMA2x2_SLOPE_DURN_REG - -/***** TAP DURATION ******/ - -#define BMA2x2_TAP_DUR__POS 0 -#define BMA2x2_TAP_DUR__LEN 3 -#define BMA2x2_TAP_DUR__MSK 0x07 -#define BMA2x2_TAP_DUR__REG BMA2x2_TAP_PARAM_REG - -/***** TAP SHOCK DURATION ******/ - -#define BMA2x2_TAP_SHOCK_DURN__POS 6 -#define BMA2x2_TAP_SHOCK_DURN__LEN 1 -#define BMA2x2_TAP_SHOCK_DURN__MSK 0x40 -#define BMA2x2_TAP_SHOCK_DURN__REG BMA2x2_TAP_PARAM_REG - -/***** ADV TAP INT ******/ - -#define BMA2x2_ADV_TAP_INT__POS 5 -#define BMA2x2_ADV_TAP_INT__LEN 1 -#define BMA2x2_ADV_TAP_INT__MSK 0x20 -#define BMA2x2_ADV_TAP_INT__REG BMA2x2_TAP_PARAM_REG - -/***** TAP QUIET DURATION ******/ - -#define BMA2x2_TAP_QUIET_DURN__POS 7 -#define BMA2x2_TAP_QUIET_DURN__LEN 1 -#define BMA2x2_TAP_QUIET_DURN__MSK 0x80 -#define BMA2x2_TAP_QUIET_DURN__REG BMA2x2_TAP_PARAM_REG -/***** TAP THRESHOLD ******/ - -#define BMA2x2_TAP_THRES__POS 0 -#define BMA2x2_TAP_THRES__LEN 5 -#define BMA2x2_TAP_THRES__MSK 0x1F -#define BMA2x2_TAP_THRES__REG BMA2x2_TAP_THRES_REG - -/***** TAP SAMPLES ******/ - -#define BMA2x2_TAP_SAMPLES__POS 6 -#define BMA2x2_TAP_SAMPLES__LEN 2 -#define BMA2x2_TAP_SAMPLES__MSK 0xC0 -#define BMA2x2_TAP_SAMPLES__REG BMA2x2_TAP_THRES_REG -/***** ORIENTATION MODE ******/ - -#define BMA2x2_ORIENT_MODE__POS 0 -#define BMA2x2_ORIENT_MODE__LEN 2 -#define BMA2x2_ORIENT_MODE__MSK 0x03 -#define BMA2x2_ORIENT_MODE__REG BMA2x2_ORIENT_PARAM_REG - -/***** ORIENTATION BLOCKING ******/ - -#define BMA2x2_ORIENT_BLOCK__POS 2 -#define BMA2x2_ORIENT_BLOCK__LEN 2 -#define BMA2x2_ORIENT_BLOCK__MSK 0x0C -#define BMA2x2_ORIENT_BLOCK__REG BMA2x2_ORIENT_PARAM_REG - -/***** ORIENTATION HYSTERESIS ******/ - -#define BMA2x2_ORIENT_HYST__POS 4 -#define BMA2x2_ORIENT_HYST__LEN 3 -#define BMA2x2_ORIENT_HYST__MSK 0x70 -#define BMA2x2_ORIENT_HYST__REG BMA2x2_ORIENT_PARAM_REG -/***** ORIENTATION AXIS SELECTION ******/ -/***** IF SET TO 1 -- X AND Z ARE SWAPPED , Y IS INVERTED */ - -// ADDED -#define BMA2x2_ORIENT_UD_EN__POS 6 -#define BMA2x2_ORIENT_UD_EN__LEN 1 -#define BMA2x2_ORIENT_UD_EN__MSK 0x40 -#define BMA2x2_ORIENT_UD_EN__REG BMA2x2_THETA_BLOCK_REG - -/***** THETA BLOCKING ******/ - -#define BMA2x2_THETA_BLOCK__POS 0 -#define BMA2x2_THETA_BLOCK__LEN 6 -#define BMA2x2_THETA_BLOCK__MSK 0x3F -#define BMA2x2_THETA_BLOCK__REG BMA2x2_THETA_BLOCK_REG -/***** THETA FLAT ******/ - -#define BMA2x2_THETA_FLAT__POS 0 -#define BMA2x2_THETA_FLAT__LEN 6 -#define BMA2x2_THETA_FLAT__MSK 0x3F -#define BMA2x2_THETA_FLAT__REG BMA2x2_THETA_FLAT_REG -/***** FLAT HOLD TIME ******/ - -#define BMA2x2_FLAT_HOLD_TIME__POS 4 -#define BMA2x2_FLAT_HOLD_TIME__LEN 2 -#define BMA2x2_FLAT_HOLD_TIME__MSK 0x30 -#define BMA2x2_FLAT_HOLD_TIME__REG BMA2x2_FLAT_HOLD_TIME_REG -/***** FLAT HYS ******/ - -#define BMA2x2_FLAT_HYS__POS 0 -#define BMA2x2_FLAT_HYS__LEN 3 -#define BMA2x2_FLAT_HYS__MSK 0x07 -#define BMA2x2_FLAT_HYS__REG BMA2x2_FLAT_HOLD_TIME_REG -/***** FIFO WATER MARK LEVEL TRIGGER RETAIN ******/ -// ADDED -#define BMA2x2_FIFO_WML_TRIG_RETAIN__POS 0 -#define BMA2x2_FIFO_WML_TRIG_RETAIN__LEN 6 -#define BMA2x2_FIFO_WML_TRIG_RETAIN__MSK 0x3F -#define BMA2x2_FIFO_WML_TRIG_RETAIN__REG BMA2x2_FIFO_WML_TRIG -/***** ACTIVATE SELF TEST ******/ - -#define BMA2x2_EN_SELF_TEST__POS 0 -#define BMA2x2_EN_SELF_TEST__LEN 2 -#define BMA2x2_EN_SELF_TEST__MSK 0x03 -#define BMA2x2_EN_SELF_TEST__REG BMA2x2_SELF_TEST_REG - -/***** SELF TEST -- NEGATIVE ******/ - -#define BMA2x2_NEG_SELF_TEST__POS 2 -#define BMA2x2_NEG_SELF_TEST__LEN 1 -#define BMA2x2_NEG_SELF_TEST__MSK 0x04 -#define BMA2x2_NEG_SELF_TEST__REG BMA2x2_SELF_TEST_REG - -/***** EEPROM CONTROL ******/ - -/* SETTING THIS BIT UNLOCK'S WRITING SETTING REGISTERS TO EEPROM */ - -#define BMA2x2_UNLOCK_EE_PROG_MODE__POS 0 -#define BMA2x2_UNLOCK_EE_PROG_MODE__LEN 1 -#define BMA2x2_UNLOCK_EE_PROG_MODE__MSK 0x01 -#define BMA2x2_UNLOCK_EE_PROG_MODE__REG BMA2x2_EEPROM_CTRL_REG - -/* SETTING THIS BIT STARTS WRITING SETTING REGISTERS TO EEPROM */ - -#define BMA2x2_START_EE_PROG_TRIG__POS 1 -#define BMA2x2_START_EE_PROG_TRIG__LEN 1 -#define BMA2x2_START_EE_PROG_TRIG__MSK 0x02 -#define BMA2x2_START_EE_PROG_TRIG__REG BMA2x2_EEPROM_CTRL_REG - -/* STATUS OF WRITING TO EEPROM */ - -#define BMA2x2_EE_PROG_READY__POS 2 -#define BMA2x2_EE_PROG_READY__LEN 1 -#define BMA2x2_EE_PROG_READY__MSK 0x04 -#define BMA2x2_EE_PROG_READY__REG BMA2x2_EEPROM_CTRL_REG - -/* UPDATE IMAGE REGISTERS WRITING TO EEPROM */ - -#define BMA2x2_UPDATE_IMAGE__POS 3 -#define BMA2x2_UPDATE_IMAGE__LEN 1 -#define BMA2x2_UPDATE_IMAGE__MSK 0x08 -#define BMA2x2_UPDATE_IMAGE__REG BMA2x2_EEPROM_CTRL_REG - -/* ADDED */ -#define BMA2x2_EE_REMAIN__POS 4 -#define BMA2x2_EE_REMAIN__LEN 4 -#define BMA2x2_EE_REMAIN__MSK 0xF0 -#define BMA2x2_EE_REMAIN__REG BMA2x2_EEPROM_CTRL_REG -/* SPI INTERFACE MODE SELECTION */ - -#define BMA2x2_EN_SPI_MODE_3__POS 0 -#define BMA2x2_EN_SPI_MODE_3__LEN 1 -#define BMA2x2_EN_SPI_MODE_3__MSK 0x01 -#define BMA2x2_EN_SPI_MODE_3__REG BMA2x2_SERIAL_CTRL_REG - -/* I2C WATCHDOG PERIOD SELECTION */ - -#define BMA2x2_I2C_WATCHDOG_PERIOD__POS 1 -#define BMA2x2_I2C_WATCHDOG_PERIOD__LEN 1 -#define BMA2x2_I2C_WATCHDOG_PERIOD__MSK 0x02 -#define BMA2x2_I2C_WATCHDOG_PERIOD__REG BMA2x2_SERIAL_CTRL_REG - -/* I2C WATCHDOG ENABLE */ - -#define BMA2x2_EN_I2C_WATCHDOG__POS 2 -#define BMA2x2_EN_I2C_WATCHDOG__LEN 1 -#define BMA2x2_EN_I2C_WATCHDOG__MSK 0x04 -#define BMA2x2_EN_I2C_WATCHDOG__REG BMA2x2_SERIAL_CTRL_REG -/* SPI INTERFACE MODE SELECTION */ -// ADDED - -/* SETTING THIS BIT UNLOCK'S WRITING TRIMMING REGISTERS TO EEPROM */ - -#define BMA2x2_UNLOCK_EE_WRITE_TRIM__POS 4 -#define BMA2x2_UNLOCK_EE_WRITE_TRIM__LEN 4 -#define BMA2x2_UNLOCK_EE_WRITE_TRIM__MSK 0xF0 -#define BMA2x2_UNLOCK_EE_WRITE_TRIM__REG BMA2x2_CTRL_UNLOCK_REG -/** OFFSET COMPENSATION **/ - -/** SLOW COMPENSATION FOR X,Y,Z AXIS **/ - -#define BMA2x2_EN_SLOW_COMP_X__POS 0 -#define BMA2x2_EN_SLOW_COMP_X__LEN 1 -#define BMA2x2_EN_SLOW_COMP_X__MSK 0x01 -#define BMA2x2_EN_SLOW_COMP_X__REG BMA2x2_OFFSET_CTRL_REG - -#define BMA2x2_EN_SLOW_COMP_Y__POS 1 -#define BMA2x2_EN_SLOW_COMP_Y__LEN 1 -#define BMA2x2_EN_SLOW_COMP_Y__MSK 0x02 -#define BMA2x2_EN_SLOW_COMP_Y__REG BMA2x2_OFFSET_CTRL_REG - -#define BMA2x2_EN_SLOW_COMP_Z__POS 2 -#define BMA2x2_EN_SLOW_COMP_Z__LEN 1 -#define BMA2x2_EN_SLOW_COMP_Z__MSK 0x04 -#define BMA2x2_EN_SLOW_COMP_Z__REG BMA2x2_OFFSET_CTRL_REG - -/** FAST COMPENSATION READY FLAG **/ -// ADDED -#define BMA2x2_FAST_CAL_RDY_S__POS 4 -#define BMA2x2_FAST_CAL_RDY_S__LEN 1 -#define BMA2x2_FAST_CAL_RDY_S__MSK 0x10 -#define BMA2x2_FAST_CAL_RDY_S__REG BMA2x2_OFFSET_CTRL_REG - -/** FAST COMPENSATION FOR X,Y,Z AXIS **/ - -#define BMA2x2_CAL_TRIGGER__POS 5 -#define BMA2x2_CAL_TRIGGER__LEN 2 -#define BMA2x2_CAL_TRIGGER__MSK 0x60 -#define BMA2x2_CAL_TRIGGER__REG BMA2x2_OFFSET_CTRL_REG - -/** RESET OFFSET REGISTERS **/ - -#define BMA2x2_RESET_OFFSET_REGS__POS 7 -#define BMA2x2_RESET_OFFSET_REGS__LEN 1 -#define BMA2x2_RESET_OFFSET_REGS__MSK 0x80 -#define BMA2x2_RESET_OFFSET_REGS__REG BMA2x2_OFFSET_CTRL_REG -/** SLOW COMPENSATION CUTOFF **/ - -#define BMA2x2_COMP_CUTOFF__POS 0 -#define BMA2x2_COMP_CUTOFF__LEN 1 -#define BMA2x2_COMP_CUTOFF__MSK 0x01 -#define BMA2x2_COMP_CUTOFF__REG BMA2x2_OFFSET_PARAMS_REG - -/** COMPENSATION TARGET **/ - -#define BMA2x2_COMP_TARGET_OFFSET_X__POS 1 -#define BMA2x2_COMP_TARGET_OFFSET_X__LEN 2 -#define BMA2x2_COMP_TARGET_OFFSET_X__MSK 0x06 -#define BMA2x2_COMP_TARGET_OFFSET_X__REG BMA2x2_OFFSET_PARAMS_REG - -#define BMA2x2_COMP_TARGET_OFFSET_Y__POS 3 -#define BMA2x2_COMP_TARGET_OFFSET_Y__LEN 2 -#define BMA2x2_COMP_TARGET_OFFSET_Y__MSK 0x18 -#define BMA2x2_COMP_TARGET_OFFSET_Y__REG BMA2x2_OFFSET_PARAMS_REG - -#define BMA2x2_COMP_TARGET_OFFSET_Z__POS 5 -#define BMA2x2_COMP_TARGET_OFFSET_Z__LEN 2 -#define BMA2x2_COMP_TARGET_OFFSET_Z__MSK 0x60 -#define BMA2x2_COMP_TARGET_OFFSET_Z__REG BMA2x2_OFFSET_PARAMS_REG -/** FIFO DATA SELECT **/ -// ADDED - -#define BMA2x2_FIFO_DATA_SELECT__POS 0 -#define BMA2x2_FIFO_DATA_SELECT__LEN 2 -#define BMA2x2_FIFO_DATA_SELECT__MSK 0x03 -#define BMA2x2_FIFO_DATA_SELECT__REG BMA2x2_FIFO_MODE_REG - -// FIFO MODE - -#define BMA2x2_FIFO_MODE__POS 6 -#define BMA2x2_FIFO_MODE__LEN 2 -#define BMA2x2_FIFO_MODE__MSK 0xC0 -#define BMA2x2_FIFO_MODE__REG BMA2x2_FIFO_MODE_REG -#define BMA2x2_GET_BITSLICE(regvar, bitname) \ - (regvar & bitname ## __MSK) >> bitname ## __POS - -#define BMA2x2_SET_BITSLICE(regvar, bitname, val) \ - (regvar & ~bitname ## __MSK) | ((val << bitname ## __POS) & bitname ## __MSK) - -/** \endcond */ - -/* CONSTANTS */ - -#define BMA2x2_STATUS1 0 /**< It refers BMA2x2 STATUS_INT1 */ -#define BMA2x2_STATUS2 1 /**< It refers BMA2x2 STATUS_INT2 */ -#define BMA2x2_STATUS3 2 /**< It refers BMA2x2 STATUS_INT_TAP */ -#define BMA2x2_STATUS4 3 /**< It refers BMA2x2 STATUS_INT_ORIENT */ -#define BMA2x2_STATUS5 4 /**< It refers BMA2x2 STATUS_INT_FIFO */ - -#define E_BMA2x2_OUT_OF_RANGE (char) -2 - -/* range and bandwidth */ - -#define BMA2x2_RANGE_2G 3 /**< sets range to +/- 2G mode \see BMA2x2_set_range() */ -#define BMA2x2_RANGE_4G 5 /**< sets range to +/- 4G mode \see BMA2x2_set_range() */ -#define BMA2x2_RANGE_8G 8 /**< sets range to +/- 8G mode \see BMA2x2_set_range() */ -#define BMA2x2_RANGE_16G 12 /**< sets range to +/- 16G mode \see BMA2x2_set_range() */ - -#define BMA2x2_BW_7_81HZ 0x08 /**< sets bandwidth to LowPass 7.81 HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_15_63HZ 0x09 /**< sets bandwidth to LowPass 15.63 HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_31_25HZ 0x0A /**< sets bandwidth to LowPass 31.25 HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_62_50HZ 0x0B /**< sets bandwidth to LowPass 62.50 HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_125HZ 0x0C /**< sets bandwidth to LowPass 125HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_250HZ 0x0D /**< sets bandwidth to LowPass 250HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_500HZ 0x0E /**< sets bandwidth to LowPass 500HZ \see BMA2x2_set_bandwidth() */ -#define BMA2x2_BW_1000HZ 0x0F /**< sets bandwidth to LowPass 1000HZ \see BMA2x2_set_bandwidth() */ - -/* SLEEP DURATION */ - -#define BMA2x2_SLEEP_DUR_0_5MS 0x05 /* sets sleep duration to 0.5 ms */ -#define BMA2x2_SLEEP_DUR_1MS 0x06 /* sets sleep duration to 1 ms */ -#define BMA2x2_SLEEP_DUR_2MS 0x07 /* sets sleep duration to 2 ms */ -#define BMA2x2_SLEEP_DUR_4MS 0x08 /* sets sleep duration to 4 ms */ -#define BMA2x2_SLEEP_DUR_6MS 0x09 /* sets sleep duration to 6 ms*/ -#define BMA2x2_SLEEP_DUR_10MS 0x0A /* sets sleep duration to 10 ms */ -#define BMA2x2_SLEEP_DUR_25MS 0x0B /* sets sleep duration to 25 ms */ -#define BMA2x2_SLEEP_DUR_50MS 0x0C /* sets sleep duration to 50 ms */ -#define BMA2x2_SLEEP_DUR_100MS 0x0D /* sets sleep duration to 100 ms */ -#define BMA2x2_SLEEP_DUR_500MS 0x0E /* sets sleep duration to 500 ms */ -#define BMA2x2_SLEEP_DUR_1S 0x0F /* sets sleep duration to 1 s */ - -/* LATCH DURATION */ - -#define BMA2x2_LATCH_DUR_NON_LATCH 0x00 /* sets LATCH duration to NON LATCH */ -#define BMA2x2_LATCH_DUR_250MS 0x01 /* sets LATCH duration to 250 ms */ -#define BMA2x2_LATCH_DUR_500MS 0x02 /* sets LATCH duration to 500 ms */ -#define BMA2x2_LATCH_DUR_1S 0x03 /* sets LATCH duration to 1 s */ -#define BMA2x2_LATCH_DUR_2S 0x04 /* sets LATCH duration to 2 s*/ -#define BMA2x2_LATCH_DUR_4S 0x05 /* sets LATCH duration to 4 s */ -#define BMA2x2_LATCH_DUR_8S 0x06 /* sets LATCH duration to 8 s */ -#define BMA2x2_LATCH_DUR_LATCH 0x07 /* sets LATCH duration to LATCH */ -#define BMA2x2_LATCH_DUR_NON_LATCH1 0x08 /* sets LATCH duration to NON LATCH1 */ -#define BMA2x2_LATCH_DUR_250US 0x09 /* sets LATCH duration to 250 Us */ -#define BMA2x2_LATCH_DUR_500US 0x0A /* sets LATCH duration to 500 Us */ -#define BMA2x2_LATCH_DUR_1MS 0x0B /* sets LATCH duration to 1 Ms */ -#define BMA2x2_LATCH_DUR_12_5MS 0x0C /* sets LATCH duration to 12.5 Ms */ -#define BMA2x2_LATCH_DUR_25MS 0x0D /* sets LATCH duration to 25 Ms */ -#define BMA2x2_LATCH_DUR_50MS 0x0E /* sets LATCH duration to 50 Ms */ -#define BMA2x2_LATCH_DUR_LATCH1 0x0F /* sets LATCH duration to LATCH*/ - -/* mode settings */ - -#define BMA2x2_MODE_NORMAL 0 -#define BMA2x2_MODE_LOWPOWER1 1 -#define BMA2x2_MODE_SUSPEND 2 -#define BMA2x2_MODE_DEEP_SUSPEND 3 -#define BMA2x2_MODE_LOWPOWER2 4 -#define BMA2x2_MODE_STANDBY 5 - -/* BMA2x2 AXIS */ - -#define BMA2x2_X_AXIS 0 /**< It refers BMA2x2 X-axis */ -#define BMA2x2_Y_AXIS 1 /**< It refers BMA2x2 Y-axis */ -#define BMA2x2_Z_AXIS 2 /**< It refers BMA2x2 Z-axis */ - -/* INTERRUPT TYPES */ - -#define BMA2x2_Low_G_Interrupt 0 -#define BMA2x2_High_G_X_Interrupt 1 -#define BMA2x2_High_G_Y_Interrupt 2 -#define BMA2x2_High_G_Z_Interrupt 3 -#define BMA2x2_DATA_EN 4 -#define BMA2x2_Slope_X_Interrupt 5 -#define BMA2x2_Slope_Y_Interrupt 6 -#define BMA2x2_Slope_Z_Interrupt 7 -#define BMA2x2_Single_Tap_Interrupt 8 -#define BMA2x2_Double_Tap_Interrupt 9 -#define BMA2x2_Orient_Interrupt 10 -#define BMA2x2_Flat_Interrupt 11 -#define BMA2x2_FFULL_INTERRUPT 12 -#define BMA2x2_FWM_INTERRUPT 13 - -/* INTERRUPTS PADS */ - -#define BMA2x2_INT1_LOWG 0 -#define BMA2x2_INT2_LOWG 1 -#define BMA2x2_INT1_HIGHG 0 -#define BMA2x2_INT2_HIGHG 1 -#define BMA2x2_INT1_SLOPE 0 -#define BMA2x2_INT2_SLOPE 1 -#define BMA2x2_INT1_SLO_NO_MOT 0 -#define BMA2x2_INT2_SLO_NO_MOT 1 -#define BMA2x2_INT1_DTAP 0 -#define BMA2x2_INT2_DTAP 1 -#define BMA2x2_INT1_STAP 0 -#define BMA2x2_INT2_STAP 1 -#define BMA2x2_INT1_ORIENT 0 -#define BMA2x2_INT2_ORIENT 1 -#define BMA2x2_INT1_FLAT 0 -#define BMA2x2_INT2_FLAT 1 -#define BMA2x2_INT1_NDATA 0 -#define BMA2x2_INT2_NDATA 1 -#define BMA2x2_INT1_FWM 0 -#define BMA2x2_INT2_FWM 1 -#define BMA2x2_INT1_FFULL 0 -#define BMA2x2_INT2_FFULL 1 - -/* SOURCE REGISTER */ - -#define BMA2x2_SRC_LOWG 0 -#define BMA2x2_SRC_HIGHG 1 -#define BMA2x2_SRC_SLOPE 2 -#define BMA2x2_SRC_SLO_NO_MOT 3 -#define BMA2x2_SRC_TAP 4 -#define BMA2x2_SRC_DATA 5 - -#define BMA2x2_INT1_OUTPUT 0 -#define BMA2x2_INT2_OUTPUT 1 -#define BMA2x2_INT1_LEVEL 0 -#define BMA2x2_INT2_LEVEL 1 - -/* DURATION */ - -#define BMA2x2_LOW_DURATION 0 -#define BMA2x2_HIGH_DURATION 1 -#define BMA2x2_SLOPE_DURATION 2 -#define BMA2x2_SLO_NO_MOT_DURATION 3 - -/* THRESHOLD */ - -#define BMA2x2_LOW_THRESHOLD 0 -#define BMA2x2_HIGH_THRESHOLD 1 -#define BMA2x2_SLOPE_THRESHOLD 2 -#define BMA2x2_SLO_NO_MOT_THRESHOLD 3 - -#define BMA2x2_LOWG_HYST 0 -#define BMA2x2_HIGHG_HYST 1 - -#define BMA2x2_ORIENT_THETA 0 -#define BMA2x2_FLAT_THETA 1 - -#define BMA2x2_I2C_SELECT 0 -#define BMA2x2_I2C_EN 1 - -/* COMPENSATION */ - -#define BMA2x2_SLOW_COMP_X 0 -#define BMA2x2_SLOW_COMP_Y 1 -#define BMA2x2_SLOW_COMP_Z 2 - -/* OFFSET TRIGGER */ - -#define BMA2x2_CUT_OFF 0 -#define BMA2x2_OFFSET_TRIGGER_X 1 -#define BMA2x2_OFFSET_TRIGGER_Y 2 -#define BMA2x2_OFFSET_TRIGGER_Z 3 - -/* GP REGISTERS */ - -#define BMA2x2_GP0 0 -#define BMA2x2_GP1 1 - -/* SLO NO MOT REGISTER */ - -#define BMA2x2_SLO_NO_MOT_EN_X 0 -#define BMA2x2_SLO_NO_MOT_EN_Y 1 -#define BMA2x2_SLO_NO_MOT_EN_Z 2 -#define BMA2x2_SLO_NO_MOT_EN_SEL 3 - -/* wake up */ - -#define BMA2x2_WAKE_UP_DUR_20MS 0 -#define BMA2x2_WAKE_UP_DUR_80MS 1 -#define BMA2x2_WAKE_UP_DUR_320MS 2 -#define BMA2x2_WAKE_UP_DUR_2560MS 3 - -/* LG/HG thresholds are in LSB and depend on RANGE setting */ -/* no range check on threshold calculation */ - -#define BMA2x2_SELF_TEST0_ON 1 -#define BMA2x2_SELF_TEST1_ON 2 - -#define BMA2x2_EE_W_OFF 0 -#define BMA2x2_EE_W_ON 1 - -/* Resolution Settings */ -#define BMA2x2_RESOLUTION_12_BIT 0 -#define BMA2x2_RESOLUTION_10_BIT 1 -#define BMA2x2_RESOLUTION_8_BIT 2 -#define BMA2x2_RESOLUTION_14_BIT 3 - -#define BMA2x2 0x16 -#define BMA280 0x17 -#define BMA222E 0x18 -#define BMA250E 0x19 -/** Macro to convert floating point low-g-thresholds in G to 8-bit register values.
- * Example: BMA2x2_LOW_TH_IN_G( 0.3, 2.0) generates the register value for 0.3G threshold in 2G mode. - * \brief convert g-values to 8-bit value - */ -#define BMA2x2_LOW_TH_IN_G(gthres, range) ((256 * gthres ) / range) - -/** Macro to convert floating point high-g-thresholds in G to 8-bit register values.
- * Example: BMA2x2_HIGH_TH_IN_G( 1.4, 2.0) generates the register value for 1.4G threshold in 2G mode. - * \brief convert g-values to 8-bit value - */ -#define BMA2x2_HIGH_TH_IN_G(gthres, range) ((256 * gthres ) / range) - -/** Macro to convert floating point low-g-hysteresis in G to 8-bit register values.
- * Example: BMA2x2_LOW_HY_IN_G( 0.2, 2.0) generates the register value for 0.2G threshold in 2G mode. - * \brief convert g-values to 8-bit value - */ -#define BMA2x2_LOW_HY_IN_G(ghyst, range) ((32 * ghyst) / range) - -/** Macro to convert floating point high-g-hysteresis in G to 8-bit register values.
- * Example: BMA2x2_HIGH_HY_IN_G( 0.2, 2.0) generates the register value for 0.2G threshold in 2G mode. - * \brief convert g-values to 8-bit value - */ -#define BMA2x2_HIGH_HY_IN_G(ghyst, range) ((32 * ghyst) / range) - -/** Macro to convert floating point G-thresholds to 8-bit register values
- * Example: BMA2x2_SLOPE_TH_IN_G( 1.2, 2.0) generates the register value for 1.2G threshold in 2G mode. - * \brief convert g-values to 8-bit value - */ - -#define BMA2x2_SLOPE_TH_IN_G(gthres, range) ((128 * gthres ) / range) -/*user defined Enums*/ -// Example.. -// enum { -// E_YOURDATA1, /**< */ -// E_YOURDATA2 /**< */ -// }; -// Example... -// struct DUMMY_STRUCT { -// data1, /**< */ -// data2 /**< */ -// }; -/******************************************************************************* - * Description: *//**\brief This API reads the data from the given register - * - * - * - * - * \param unsigned char addr, unsigned char *data - * addr -> Address of the register - * data -> address of the variable, read value will be kept - * \return results of bus communication function - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_burst_read(unsigned char addr, unsigned char *data, unsigned int len); - -int bma2x2_init(bma2x2_t *bma2x2); - -int bma2x2_write_reg(unsigned char addr, unsigned char *data, unsigned char len); - -int bma2x2_read_reg(unsigned char addr, unsigned char *data, unsigned char len); - -int bma2x2_read_accel_x(short *a_x); - -int bma2x2_read_accel_y(short *a_y); - -int bma2x2_read_accel_z(short *a_z); - -int bma2x2_read_accel_xyz(bma2x2acc_t *acc); - -int bma2x2_get_int_tap_status(unsigned char *status_tap); - -int bma2x2_get_int_orient_status(unsigned char *status_orient); - -int bma2x2_get_fifo_status(unsigned char *status_fifo); - -int bma2x2_get_fifo_framecount(unsigned char *framecount); - -int bma2x2_get_fifo_overrun(unsigned char *overrun); - -int bma2x2_get_interrupt_status(unsigned char *status); - -int bma2x2_get_range(unsigned char *Range); - -int bma2x2_set_range(unsigned char Range); - -int bma2x2_get_bandwidth(unsigned char *bw); - -int bma2x2_set_bandwidth(unsigned char bw); - -int bma2x2_get_mode(unsigned char *Mode); - -unsigned char bma2x2_set_mode(unsigned char Mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleep_dur(unsigned char *sleep_dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleep_dur (unsigned char sleep_dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleeptmr_mode(unsigned char *sleep_tmr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleeptmr_mode (unsigned char sleep_tmr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_high_bw (unsigned char *high_bw); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_high_bw (unsigned char high_bw); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_shadow_dis (unsigned char *shadow_dis); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_shadow_dis (unsigned char shadow_dis); - -int bma2x2_soft_reset(void); - -int bma2x2_update_image(void); - -int bma2x2_set_Int_Enable(unsigned char InterruptType, unsigned char value); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_ffull (unsigned char *ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_ffull (unsigned char ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_fwm (unsigned char *fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_fwm (unsigned char fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slo_no_mot (unsigned char channel, unsigned char *slo_data); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slo_no_mot (unsigned char channel, unsigned char slo_data); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_low (unsigned char channel, unsigned char *int_low); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_low (unsigned char channel, unsigned char int_low); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_high(unsigned char channel, unsigned char *int_high); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_high(unsigned char channel, unsigned char int_high); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slope(unsigned char channel, unsigned char *int_slope); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slope(unsigned char channel, unsigned char int_slope); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slo_no_mot (unsigned char channel, unsigned char *int_slo_no_mot); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slo_no_mot (unsigned char channel, unsigned char int_slo_no_mot); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_d_tap (unsigned char channel, unsigned char *int_d_tap); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_d_tap (unsigned char channel, unsigned char int_d_tap); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_s_tap (unsigned char channel, unsigned char *int_s_tap); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_s_tap (unsigned char channel, unsigned char int_s_tap); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_orient (unsigned char channel, unsigned char *int_orient); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_orient (unsigned char channel, unsigned char int_orient); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_flat (unsigned char channel, unsigned char *int_flat); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_flat (unsigned char channel, unsigned char int_flat); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_newdata (unsigned char channel, unsigned char *int_newdata); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_newdata (unsigned char channel, unsigned char int_newdata); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_fwm (unsigned char *int1_fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_fwm (unsigned char int1_fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_fwm (unsigned char *int2_fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_fwm (unsigned char int2_fwm); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_ffull (unsigned char *int1_ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_ffull (unsigned char int1_ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_ffull (unsigned char *int2_ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_ffull (unsigned char int2_ffull); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_source (unsigned char channel, unsigned char *int_source); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_source (unsigned char channel, unsigned char int_source); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_od (unsigned char channel, unsigned char *int_od); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_od (unsigned char channel, unsigned char int_od); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_lvl (unsigned char channel, unsigned char *int_lvl); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_lvl (unsigned char channel, unsigned char int_lvl); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_reset_interrupt (unsigned char reset_int); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_latch_int (unsigned char *latch_int); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_latch_int (unsigned char latch_int); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_dur(unsigned char channel, unsigned char *dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_dur (unsigned char channel, unsigned char dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_thr(unsigned char channel, unsigned char *thr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_thr (unsigned char channel, unsigned char thr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst(unsigned char channel, unsigned char *hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst (unsigned char channel, unsigned char hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst_mode(unsigned char *mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst_mode (unsigned char mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_dur (unsigned char *tap_dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_dur (unsigned char tap_dur); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_shock (unsigned char *tap_shock); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_shock (unsigned char tap_shock); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_quiet (unsigned char *tap_quiet); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_quiet (unsigned char tap_quiet); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_thr (unsigned char *tap_thr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_thr (unsigned char tap_thr); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_sample (unsigned char *tap_sample); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_sample (unsigned char tap_sample); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_mode (unsigned char *orient_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_mode (unsigned char orient_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_block (unsigned char *orient_block); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_block (unsigned char orient_block); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_hyst (unsigned char *orient_hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_hyst (unsigned char orient_hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_theta(unsigned char channel, unsigned char *theta); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_theta (unsigned char channel, unsigned char theta); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_en (unsigned char *orient_en); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_en (unsigned char orient_en); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hyst (unsigned char *flat_hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hyst (unsigned char flat_hyst); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hold_time (unsigned char *flat_hold_time); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hold_time (unsigned char flat_hold_time); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_wml_trig (unsigned char *fifo_wml_trig); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_wml_trig (unsigned char fifo_wml_trig); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_axis (unsigned char *self_test_axis); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_axis (unsigned char self_test_axis); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_sign (unsigned char *self_test_sign); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_sign (unsigned char self_test_sign); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_nvmprog_mode (unsigned char *nvmprog_mode); - -int bma2x2_set_nvmprog_mode(unsigned char prgmode); - -int bma2x2_set_nvprog_trig(unsigned char trig); - -int bma2x2_get_nvmprog_ready(unsigned char *ready); - -int bma2x2_get_nvmprog_remain(unsigned char *remain); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_spi3 (unsigned char *spi3); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_spi3 (unsigned char spi3); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_i2c_wdt (unsigned char channel, unsigned char *prog_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_i2c_wdt (unsigned char channel, unsigned char prog_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slow_comp(unsigned char channel, unsigned char *slow_comp); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slow_comp (unsigned char channel, unsigned char slow_comp); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_rdy (unsigned char *rdy); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_rdy (unsigned char rdy); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_trig (unsigned char *cal_trig); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_trig (unsigned char cal_trig); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_reset (unsigned char offset_reset); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset_target(unsigned char channel, unsigned char *offset); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_target (unsigned char channel, unsigned char offset); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset(unsigned char channel, unsigned char *offset); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset (unsigned char channel, unsigned char offset); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_gp(unsigned char channel, unsigned char *gp); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_gp (unsigned char channel, unsigned char gp); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_mode (unsigned char *fifo_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_mode (unsigned char fifo_mode); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_sel (unsigned char *data_sel); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_sel (unsigned char data_sel); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_out_reg(unsigned char *out_reg); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_out_reg (unsigned char out_reg); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_temperature (signed char *temperature); - -BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_accel_xyzt(bma2x2acc_data *acc); - -BMA2x2_RETURN_FUNCTION_TYPE bmm050_set_accel_int1_drdy_interrupt \ - (unsigned char enable_disable, - unsigned char active_low0_high1); - -#endif +/* + *************************************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + **************************************************************************************************/ +/* $Date: 2012/11/06 + * $Revision: 1.3 $ + * + */ + +/************************************************************************************************** +* Copyright (C) 2007 Bosch Sensortec GmbH +* +* bma2x2.h +* +* Usage: BMA2x2 Sensor Driver Support Header File +* +**************************************************************************************************/ +/*************************************************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. They may only be used + * within the parameters of the respective valid product data sheet. Bosch Sensortec products are + * provided with the express understanding that there is no warranty of fitness for a particular purpose. + * They are not fit for use in life-sustaining, safety or security sensitive systems or any system or device + * that may lead to bodily harm or property damage if the system or device malfunctions. In addition, + * Bosch Sensortec products are not fit for use in products which interact with motor vehicle systems. + * The resale and/or use of products are at the purchaser’s own risk and his own responsibility. The + * examination of fitness for the intended use is the sole responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party claims, including any claims for + * incidental, or consequential damages, arising from any product use not covered by the parameters of + * the respective valid product data sheet or not approved by Bosch Sensortec and reimburse Bosch + * Sensortec for all costs in connection with such claims. + * + * The purchaser must monitor the market for the purchased products, particularly with regard to + * product safety and inform Bosch Sensortec without delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary from the valid + * technical specifications of the product series. They are therefore not intended or fit for resale to third + * parties or for use in end products. Their sole purpose is internal client testing. The testing of an + * engineering sample may in no way replace the testing of a product series. Bosch Sensortec + * assumes no liability for the use of engineering samples. By accepting the engineering samples, the + * Purchaser agrees to indemnify Bosch Sensortec from all claims arising from the use of engineering + * samples. + * + * Special: + * This software module (hereinafter called "Software") and any information on application-sheets + * (hereinafter called "Information") is provided free of charge for the sole purpose to support your + * application work. The Software and Information is subject to the following terms and conditions: + * + * The Software is specifically designed for the exclusive use for Bosch Sensortec products by + * personnel who have special experience and training. Do not use this Software if you do not have the + * proper experience or training. + * + * This Software package is provided `` as is `` and without any expressed or implied warranties, + * including without limitation, the implied warranties of merchantability and fitness for a particular + * purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability for the functional impairment + * of this Software in terms of fitness, performance and safety. Bosch Sensortec and their + * representatives and agents shall not be liable for any direct or indirect damages or injury, except as + * otherwise stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. Bosch Sensortec assumes no + * responsibility for the consequences of use of such Information nor for any infringement of patents or + * other rights of third parties which may result from its use. No license is granted by implication or + * otherwise under any patent or patent rights of Bosch. Specifications mentioned in the Information are + * subject to change without notice. + * + * It is not allowed to deliver the source code of the Software to any third party without permission of + * Bosch Sensortec. + */ +/*************************************************************************************************/ +/*! \file bma2x2.h + \brief BMA2x2 Sensor Driver Support Header File */ +/* user defined code to be added here ... */ +#ifndef __BMA2x2_H__ +#define __BMA2x2_H__ + +// Example.... +// #define YOUR_H_DEFINE /**< */ +/** Define the calling convention of YOUR bus communication routine. + \note This includes types of parameters. This example shows the configuration for an SPI bus link. + + If your communication function looks like this: + + write_my_bus_xy(unsigned char device_addr, unsigned char register_addr, unsigned char * data, unsigned char length); + + The BMA2x2_WR_FUNC_PTR would equal: + + #define BMA2x2_WR_FUNC_PTR char (* bus_write)(unsigned char, unsigned char, unsigned char *, unsigned char) + + Parameters can be mixed as needed refer to the \ref BMA2x2_BUS_WRITE_FUNC macro. + + + */ +#define BMA2x2_WR_FUNC_PTR char (*bus_write)(unsigned char, unsigned char, unsigned char *, unsigned char) + +/** link makro between API function calls and bus write function + \note The bus write function can change since this is a system dependant issue. + + If the bus_write parameter calling order is like: reg_addr, reg_data, wr_len it would be as it is here. + + If the parameters are differently ordered or your communication function like I2C need to know the device address, + you can change this macro accordingly. + + + define BMA2x2_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_write(dev_addr, reg_addr, reg_data, wr_len) + + This macro lets all API functions call YOUR communication routine in a way that equals your definition in the + \ref BMA2x2_WR_FUNC_PTR definition. + + + + */ +#define BMA2x2_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len) \ + bus_write(dev_addr, reg_addr, reg_data, wr_len) + +/** Define the calling convention of YOUR bus communication routine. + \note This includes types of parameters. This example shows the configuration for an SPI bus link. + + If your communication function looks like this: + + read_my_bus_xy(unsigned char device_addr, unsigned char register_addr, unsigned char * data, unsigned char length); + + The BMA2x2_RD_FUNC_PTR would equal: + + #define BMA2x2_RD_FUNC_PTR char (* bus_read)(unsigned char, unsigned char, unsigned char *, unsigned char) + + Parameters can be mixed as needed refer to the \ref BMA2x2_BUS_READ_FUNC macro. + + + */ + +#define BMA2x2_SPI_RD_MASK 0x80 /* for spi read transactions on SPI the MSB has to be set */ +#define BMA2x2_RD_FUNC_PTR char (*bus_read)(unsigned char, unsigned char, unsigned char *, unsigned char) +#define BMA2x2_BRD_FUNC_PTR char (*burst_read)(unsigned char, unsigned char, unsigned char *, unsigned int) + +/** link makro between API function calls and bus read function + \note The bus write function can change since this is a system dependant issue. + + If the bus_read parameter calling order is like: reg_addr, reg_data, wr_len it would be as it is here. + + If the parameters are differently ordered or your communication function like I2C need to know the device address, + you can change this macro accordingly. + + + define BMA2x2_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_read(dev_addr, reg_addr, reg_data, wr_len) + + This macro lets all API functions call YOUR communication routine in a way that equals your definition in the + \ref BMA2x2_WR_FUNC_PTR definition. + + \note: this macro also includes the "MSB='1'" for reading BMA2x2 addresses. + + */ +#define BMA2x2_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, r_len) \ + bus_read(dev_addr, reg_addr, reg_data, r_len) +#define BMA2x2_BURST_READ_FUNC(device_addr, register_addr, register_data, rd_len) \ + burst_read(device_addr, register_addr, register_data, rd_len) +/** bma2x2 I2C Address + */ + +/* The LPC5102 sensor board has BMC150 and BMI055. + * BMC150 is an Accel/Mag combo chip. Accel I2C address is 0x10. Mag I2C address is 0x12 + * BMI055 is an Accel/Gyro combo chip. Accel I2C address is 0x19. Gyro I2C address is 0x69 + */ +#define BMA2x2_I2C_ADDR1 0x18 +#define BMA2x2_I2C_ADDR2 0x19 + +#define BMA2x2_I2C_ADDR (0x19) + + + +#define C_BMA2x2_Zero_U8X (unsigned char) 0 +#define C_BMA2x2_One_U8X (unsigned char) 1 +#define C_BMA2x2_Two_U8X (unsigned char) 2 +#define C_BMA2x2_Three_U8X (unsigned char) 3 +#define C_BMA2x2_Four_U8X (unsigned char) 4 +#define C_BMA2x2_Five_U8X (unsigned char) 5 +#define C_BMA2x2_Six_U8X (unsigned char) 6 +#define C_BMA2x2_Seven_U8X (unsigned char) 7 +#define C_BMA2x2_Eight_U8X (unsigned char) 8 +#define C_BMA2x2_Nine_U8X (unsigned char) 9 +#define C_BMA2x2_Twelve_U8X (unsigned char) 12 +#define C_BMA2x2_Fifteen_U8X (unsigned char) 15 +#define C_BMA2x2_Sixteen_U8X (unsigned char) 16 +#define C_BMA2x2_ThirtyTwo_U8X (unsigned char) 32 + +/* + SMB380 API error codes + */ + +#define E_SMB_NULL_PTR (char) -127 +#define E_COMM_RES (char) -1 +#define E_OUT_OF_RANGE (char) -2 +#define E_EEPROM_BUSY (char) -3 + +#define BMA2x2_RETURN_FUNCTION_TYPE int /**< This refers BMA2x2 return type as char */ + +/* + * + * register definitions + * + */ + +#define BMA2x2_EEP_OFFSET 0x16 +#define BMA2x2_IMAGE_BASE 0x38 +#define BMA2x2_IMAGE_LEN 22 + +#define BMA2x2_CHIP_ID_REG 0x00 +#define BMA2x2_X_AXIS_LSB_REG 0x02 +#define BMA2x2_X_AXIS_MSB_REG 0x03 +#define BMA2x2_Y_AXIS_LSB_REG 0x04 +#define BMA2x2_Y_AXIS_MSB_REG 0x05 +#define BMA2x2_Z_AXIS_LSB_REG 0x06 +#define BMA2x2_Z_AXIS_MSB_REG 0x07 +#define BMA2x2_TEMPERATURE_REG 0x08 +#define BMA2x2_STATUS1_REG 0x09 +#define BMA2x2_STATUS2_REG 0x0A +#define BMA2x2_STATUS_TAP_SLOPE_REG 0x0B +#define BMA2x2_STATUS_ORIENT_HIGH_REG 0x0C +#define BMA2x2_STATUS_FIFO_REG 0x0E // ADDED +#define BMA2x2_RANGE_SEL_REG 0x0F +#define BMA2x2_BW_SEL_REG 0x10 +#define BMA2x2_MODE_CTRL_REG 0x11 +#define BMA2x2_LOW_NOISE_CTRL_REG 0x12 +#define BMA2x2_DATA_CTRL_REG 0x13 +#define BMA2x2_RESET_REG 0x14 +#define BMA2x2_INT_ENABLE1_REG 0x16 +#define BMA2x2_INT_ENABLE2_REG 0x17 +#define BMA2x2_INT_SLO_NO_MOT_REG 0x18 // ADDED +#define BMA2x2_INT1_PAD_SEL_REG 0x19 +#define BMA2x2_INT_DATA_SEL_REG 0x1A +#define BMA2x2_INT2_PAD_SEL_REG 0x1B +#define BMA2x2_INT_SRC_REG 0x1E +#define BMA2x2_INT_SET_REG 0x20 +#define BMA2x2_INT_CTRL_REG 0x21 +#define BMA2x2_LOW_DURN_REG 0x22 +#define BMA2x2_LOW_THRES_REG 0x23 +#define BMA2x2_LOW_HIGH_HYST_REG 0x24 +#define BMA2x2_HIGH_DURN_REG 0x25 +#define BMA2x2_HIGH_THRES_REG 0x26 +#define BMA2x2_SLOPE_DURN_REG 0x27 +#define BMA2x2_SLOPE_THRES_REG 0x28 +#define BMA2x2_SLO_NO_MOT_THRES_REG 0x29 // ADDED +#define BMA2x2_TAP_PARAM_REG 0x2A +#define BMA2x2_TAP_THRES_REG 0x2B +#define BMA2x2_ORIENT_PARAM_REG 0x2C +#define BMA2x2_THETA_BLOCK_REG 0x2D +#define BMA2x2_THETA_FLAT_REG 0x2E +#define BMA2x2_FLAT_HOLD_TIME_REG 0x2F +#define BMA2x2_FIFO_WML_TRIG 0x30 // ADDED +#define BMA2x2_SELF_TEST_REG 0x32 +#define BMA2x2_EEPROM_CTRL_REG 0x33 +#define BMA2x2_SERIAL_CTRL_REG 0x34 +#define BMA2x2_OFFSET_CTRL_REG 0x36 +#define BMA2x2_OFFSET_PARAMS_REG 0x37 +#define BMA2x2_OFFSET_X_AXIS_REG 0x38 +#define BMA2x2_OFFSET_Y_AXIS_REG 0x39 +#define BMA2x2_OFFSET_Z_AXIS_REG 0x3A +#define BMA2x2_GP0_REG 0x3B // ADDED +#define BMA2x2_GP1_REG 0x3C // ADDED +#define BMA2x2_FIFO_MODE_REG 0x3E // ADDED +#define BMA2x2_FIFO_DATA_OUTPUT_REG 0x3F // ADDED + +#define E_BMA2x2_NULL_PTR (char) -127 +#define BMA2x2_NULL 0 + +#define BMA2x2_12_RESOLUTION 0 +#define BMA2x2_10_RESOLUTION 1 +#define BMA2x2_8_RESOLUTION 2 +#define BMA2x2_14_RESOLUTION 3 + +/* register write and read delays */ + +#define BMA2x2_MDELAY_DATA_TYPE unsigned int +#define BMA2x2_EE_W_DELAY 28 /* delay after EEP write is 28 msec */ +/** bma2x2 acceleration data + \brief Structure containing acceleration values for x,y and z-axis in signed short + + */ + +typedef struct { + short x,/**< holds x-axis acceleration data sign extended. Range -512 to 511. */ + y,/**< holds y-axis acceleration data sign extended. Range -512 to 511. */ + z;/**< holds z-axis acceleration data sign extended. Range -512 to 511. */ +} bma2x2acc_t; +typedef struct { + short x,/**< holds x-axis acceleration data sign extended. Range -512 to 511. */ + y,/**< holds y-axis acceleration data sign extended. Range -512 to 511. */ + z;/**< holds z-axis acceleration data sign extended. Range -512 to 511. */ + signed char temperature; /**< holds Temperature data sign extended. Range -128 to 127. */ +} bma2x2acc_data; +/** bma2x2 image registers data structure + \brief Register type that contains all bma2x2 image registers from address 0x38 to 0x4D + This structure can hold the complete image data of bma2x2 + + */ +typedef struct { + unsigned char + offset_filt_x, /**< image address 0x38: */ + offset_filt_y, /**< image address 0x39: */ + offset_filt_z, /**< image address 0x3A: */ + offset_unfilt_x, /**< image address 0x3B: */ + offset_unfilt_y, /**< image address 0x3C: */ + offset_unfilt_z, /**< image address 0x3D: */ + spare_0, /**< image address 0x3E: */ + spare_1, /**< image address 0x3F: */ + crc, /**< image address 0x40: */ + i2c_addr, /**< image address 0x41: */ + dev_config, /**< image address 0x42: */ + trim_offset_t, /**< image address 0x43: */ + gain_x, /**< image address 0x44: */ + offset_x, /**< image address 0x45: */ + gain_y, /**< image address 0x46: */ + offset_y, /**< image address 0x47: */ + gain_z, /**< image address 0x48: */ + offset_z, /**< image address 0x49: */ + trim1, /**< image address 0x4A: */ + trim2, /**< image address 0x4B: */ + trim3, /**< image address 0x4C: */ + trim4; /**< image address 0x4D: */ +} bma2x2regs_t; +/** bma2x2 typedef structure + \brief This structure holds all relevant information about bma2x2 and links communication to the + */ +typedef struct { + bma2x2regs_t *image; /**< pointer to bma2x2regs_t structure not mandatory */ + unsigned char mode; /**< save current bma2x2 operation mode */ + unsigned char chip_id, /**< save bma2x2's chip id which has to be 0x02 after calling bma2x2_init() */ + version; /**< holds the bma2x2 version number */ + unsigned char dev_addr; /**< initializes bma2x2's I2C device address 0x38 */ + unsigned char int_mask; /**< stores the current bma2x2 API generated interrupt mask */ + BMA2x2_WR_FUNC_PTR; /**< function pointer to the SPI/I2C write function */ + BMA2x2_RD_FUNC_PTR; /**< function pointer to the SPI/I2C read function */ + BMA2x2_BRD_FUNC_PTR; + void (*delay_msec)(BMA2x2_MDELAY_DATA_TYPE); /**< function pointer to a pause in mili seconds function */ +} bma2x2_t; +#define BMA2x2_CHIP_ID__POS 0 +#define BMA2x2_CHIP_ID__MSK 0xFF +#define BMA2x2_CHIP_ID__LEN 8 +#define BMA2x2_CHIP_ID__REG BMA2x2_CHIP_ID_REG + +/* DATA REGISTERS */ + +#define BMA2x2_NEW_DATA_X__POS 0 +#define BMA2x2_NEW_DATA_X__LEN 1 +#define BMA2x2_NEW_DATA_X__MSK 0x01 +#define BMA2x2_NEW_DATA_X__REG BMA2x2_X_AXIS_LSB_REG + +#define BMA2x2_ACC_X14_LSB__POS 2 +#define BMA2x2_ACC_X14_LSB__LEN 6 +#define BMA2x2_ACC_X14_LSB__MSK 0xFC +#define BMA2x2_ACC_X14_LSB__REG BMA2x2_X_AXIS_LSB_REG + +#define BMA2x2_ACC_X12_LSB__POS 4 +#define BMA2x2_ACC_X12_LSB__LEN 4 +#define BMA2x2_ACC_X12_LSB__MSK 0xF0 +#define BMA2x2_ACC_X12_LSB__REG BMA2x2_X_AXIS_LSB_REG + +#define BMA2x2_ACC_X10_LSB__POS 6 +#define BMA2x2_ACC_X10_LSB__LEN 2 +#define BMA2x2_ACC_X10_LSB__MSK 0xC0 +#define BMA2x2_ACC_X10_LSB__REG BMA2x2_X_AXIS_LSB_REG + +#define BMA2x2_ACC_X8_LSB__POS 0 +#define BMA2x2_ACC_X8_LSB__LEN 0 +#define BMA2x2_ACC_X8_LSB__MSK 0x00 +#define BMA2x2_ACC_X8_LSB__REG BMA2x2_X_AXIS_LSB_REG + +#define BMA2x2_ACC_X_MSB__POS 0 +#define BMA2x2_ACC_X_MSB__LEN 8 +#define BMA2x2_ACC_X_MSB__MSK 0xFF +#define BMA2x2_ACC_X_MSB__REG BMA2x2_X_AXIS_MSB_REG + +#define BMA2x2_NEW_DATA_Y__POS 0 +#define BMA2x2_NEW_DATA_Y__LEN 1 +#define BMA2x2_NEW_DATA_Y__MSK 0x01 +#define BMA2x2_NEW_DATA_Y__REG BMA2x2_Y_AXIS_LSB_REG + +#define BMA2x2_ACC_Y14_LSB__POS 2 +#define BMA2x2_ACC_Y14_LSB__LEN 6 +#define BMA2x2_ACC_Y14_LSB__MSK 0xFC +#define BMA2x2_ACC_Y14_LSB__REG BMA2x2_Y_AXIS_LSB_REG + +#define BMA2x2_ACC_Y12_LSB__POS 4 +#define BMA2x2_ACC_Y12_LSB__LEN 4 +#define BMA2x2_ACC_Y12_LSB__MSK 0xF0 +#define BMA2x2_ACC_Y12_LSB__REG BMA2x2_Y_AXIS_LSB_REG + +#define BMA2x2_ACC_Y10_LSB__POS 6 +#define BMA2x2_ACC_Y10_LSB__LEN 2 +#define BMA2x2_ACC_Y10_LSB__MSK 0xC0 +#define BMA2x2_ACC_Y10_LSB__REG BMA2x2_Y_AXIS_LSB_REG + +#define BMA2x2_ACC_Y8_LSB__POS 0 +#define BMA2x2_ACC_Y8_LSB__LEN 0 +#define BMA2x2_ACC_Y8_LSB__MSK 0x00 +#define BMA2x2_ACC_Y8_LSB__REG BMA2x2_Y_AXIS_LSB_REG + +#define BMA2x2_ACC_Y_MSB__POS 0 +#define BMA2x2_ACC_Y_MSB__LEN 8 +#define BMA2x2_ACC_Y_MSB__MSK 0xFF +#define BMA2x2_ACC_Y_MSB__REG BMA2x2_Y_AXIS_MSB_REG + +#define BMA2x2_NEW_DATA_Z__POS 0 +#define BMA2x2_NEW_DATA_Z__LEN 1 +#define BMA2x2_NEW_DATA_Z__MSK 0x01 +#define BMA2x2_NEW_DATA_Z__REG BMA2x2_Z_AXIS_LSB_REG + +#define BMA2x2_ACC_Z14_LSB__POS 2 +#define BMA2x2_ACC_Z14_LSB__LEN 6 +#define BMA2x2_ACC_Z14_LSB__MSK 0xFC +#define BMA2x2_ACC_Z14_LSB__REG BMA2x2_Z_AXIS_LSB_REG + +#define BMA2x2_ACC_Z12_LSB__POS 4 +#define BMA2x2_ACC_Z12_LSB__LEN 4 +#define BMA2x2_ACC_Z12_LSB__MSK 0xF0 +#define BMA2x2_ACC_Z12_LSB__REG BMA2x2_Z_AXIS_LSB_REG + +#define BMA2x2_ACC_Z10_LSB__POS 6 +#define BMA2x2_ACC_Z10_LSB__LEN 2 +#define BMA2x2_ACC_Z10_LSB__MSK 0xC0 +#define BMA2x2_ACC_Z10_LSB__REG BMA2x2_Z_AXIS_LSB_REG + +#define BMA2x2_ACC_Z8_LSB__POS 0 +#define BMA2x2_ACC_Z8_LSB__LEN 0 +#define BMA2x2_ACC_Z8_LSB__MSK 0x00 +#define BMA2x2_ACC_Z8_LSB__REG BMA2x2_Z_AXIS_LSB_REG + +#define BMA2x2_ACC_Z_MSB__POS 0 +#define BMA2x2_ACC_Z_MSB__LEN 8 +#define BMA2x2_ACC_Z_MSB__MSK 0xFF +#define BMA2x2_ACC_Z_MSB__REG BMA2x2_Z_AXIS_MSB_REG + +/* INTERRUPT STATUS BITS */ + +#define BMA2x2_LOWG_INT_S__POS 0 +#define BMA2x2_LOWG_INT_S__LEN 1 +#define BMA2x2_LOWG_INT_S__MSK 0x01 +#define BMA2x2_LOWG_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_HIGHG_INT_S__POS 1 +#define BMA2x2_HIGHG_INT_S__LEN 1 +#define BMA2x2_HIGHG_INT_S__MSK 0x02 +#define BMA2x2_HIGHG_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_SLOPE_INT_S__POS 2 +#define BMA2x2_SLOPE_INT_S__LEN 1 +#define BMA2x2_SLOPE_INT_S__MSK 0x04 +#define BMA2x2_SLOPE_INT_S__REG BMA2x2_STATUS1_REG + +// ADDED +#define BMA2x2_SLO_NO_MOT_INT_S__POS 3 +#define BMA2x2_SLO_NO_MOT_INT_S__LEN 1 +#define BMA2x2_SLO_NO_MOT_INT_S__MSK 0x08 +#define BMA2x2_SLO_NO_MOT_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_DOUBLE_TAP_INT_S__POS 4 +#define BMA2x2_DOUBLE_TAP_INT_S__LEN 1 +#define BMA2x2_DOUBLE_TAP_INT_S__MSK 0x10 +#define BMA2x2_DOUBLE_TAP_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_SINGLE_TAP_INT_S__POS 5 +#define BMA2x2_SINGLE_TAP_INT_S__LEN 1 +#define BMA2x2_SINGLE_TAP_INT_S__MSK 0x20 +#define BMA2x2_SINGLE_TAP_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_ORIENT_INT_S__POS 6 +#define BMA2x2_ORIENT_INT_S__LEN 1 +#define BMA2x2_ORIENT_INT_S__MSK 0x40 +#define BMA2x2_ORIENT_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_FLAT_INT_S__POS 7 +#define BMA2x2_FLAT_INT_S__LEN 1 +#define BMA2x2_FLAT_INT_S__MSK 0x80 +#define BMA2x2_FLAT_INT_S__REG BMA2x2_STATUS1_REG + +#define BMA2x2_FIFO_FULL_INT_S__POS 5 +#define BMA2x2_FIFO_FULL_INT_S__LEN 1 +#define BMA2x2_FIFO_FULL_INT_S__MSK 0x20 +#define BMA2x2_FIFO_FULL_INT_S__REG BMA2x2_STATUS2_REG + +#define BMA2x2_FIFO_WM_INT_S__POS 6 +#define BMA2x2_FIFO_WM_INT_S__LEN 1 +#define BMA2x2_FIFO_WM_INT_S__MSK 0x40 +#define BMA2x2_FIFO_WM_INT_S__REG BMA2x2_STATUS2_REG + +#define BMA2x2_DATA_INT_S__POS 7 +#define BMA2x2_DATA_INT_S__LEN 1 +#define BMA2x2_DATA_INT_S__MSK 0x80 +#define BMA2x2_DATA_INT_S__REG BMA2x2_STATUS2_REG +#define BMA2x2_SLOPE_FIRST_X__POS 0 +#define BMA2x2_SLOPE_FIRST_X__LEN 1 +#define BMA2x2_SLOPE_FIRST_X__MSK 0x01 +#define BMA2x2_SLOPE_FIRST_X__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_SLOPE_FIRST_Y__POS 1 +#define BMA2x2_SLOPE_FIRST_Y__LEN 1 +#define BMA2x2_SLOPE_FIRST_Y__MSK 0x02 +#define BMA2x2_SLOPE_FIRST_Y__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_SLOPE_FIRST_Z__POS 2 +#define BMA2x2_SLOPE_FIRST_Z__LEN 1 +#define BMA2x2_SLOPE_FIRST_Z__MSK 0x04 +#define BMA2x2_SLOPE_FIRST_Z__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_SLOPE_SIGN_S__POS 3 +#define BMA2x2_SLOPE_SIGN_S__LEN 1 +#define BMA2x2_SLOPE_SIGN_S__MSK 0x08 +#define BMA2x2_SLOPE_SIGN_S__REG BMA2x2_STATUS_TAP_SLOPE_REG +#define BMA2x2_TAP_FIRST_X__POS 4 +#define BMA2x2_TAP_FIRST_X__LEN 1 +#define BMA2x2_TAP_FIRST_X__MSK 0x10 +#define BMA2x2_TAP_FIRST_X__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_TAP_FIRST_Y__POS 5 +#define BMA2x2_TAP_FIRST_Y__LEN 1 +#define BMA2x2_TAP_FIRST_Y__MSK 0x20 +#define BMA2x2_TAP_FIRST_Y__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_TAP_FIRST_Z__POS 6 +#define BMA2x2_TAP_FIRST_Z__LEN 1 +#define BMA2x2_TAP_FIRST_Z__MSK 0x40 +#define BMA2x2_TAP_FIRST_Z__REG BMA2x2_STATUS_TAP_SLOPE_REG + +#define BMA2x2_TAP_SIGN_S__POS 7 +#define BMA2x2_TAP_SIGN_S__LEN 1 +#define BMA2x2_TAP_SIGN_S__MSK 0x80 +#define BMA2x2_TAP_SIGN_S__REG BMA2x2_STATUS_TAP_SLOPE_REG +#define BMA2x2_HIGHG_FIRST_X__POS 0 +#define BMA2x2_HIGHG_FIRST_X__LEN 1 +#define BMA2x2_HIGHG_FIRST_X__MSK 0x01 +#define BMA2x2_HIGHG_FIRST_X__REG BMA2x2_STATUS_ORIENT_HIGH_REG + +#define BMA2x2_HIGHG_FIRST_Y__POS 1 +#define BMA2x2_HIGHG_FIRST_Y__LEN 1 +#define BMA2x2_HIGHG_FIRST_Y__MSK 0x02 +#define BMA2x2_HIGHG_FIRST_Y__REG BMA2x2_STATUS_ORIENT_HIGH_REG + +#define BMA2x2_HIGHG_FIRST_Z__POS 2 +#define BMA2x2_HIGHG_FIRST_Z__LEN 1 +#define BMA2x2_HIGHG_FIRST_Z__MSK 0x04 +#define BMA2x2_HIGHG_FIRST_Z__REG BMA2x2_STATUS_ORIENT_HIGH_REG + +#define BMA2x2_HIGHG_SIGN_S__POS 3 +#define BMA2x2_HIGHG_SIGN_S__LEN 1 +#define BMA2x2_HIGHG_SIGN_S__MSK 0x08 +#define BMA2x2_HIGHG_SIGN_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG +#define BMA2x2_ORIENT_S__POS 4 +#define BMA2x2_ORIENT_S__LEN 3 +#define BMA2x2_ORIENT_S__MSK 0x70 +#define BMA2x2_ORIENT_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG + +#define BMA2x2_FLAT_S__POS 7 +#define BMA2x2_FLAT_S__LEN 1 +#define BMA2x2_FLAT_S__MSK 0x80 +#define BMA2x2_FLAT_S__REG BMA2x2_STATUS_ORIENT_HIGH_REG +// FIFO_STATUS + +#define BMA2x2_FIFO_FRAME_COUNTER_S__POS 0 +#define BMA2x2_FIFO_FRAME_COUNTER_S__LEN 7 +#define BMA2x2_FIFO_FRAME_COUNTER_S__MSK 0x7F +#define BMA2x2_FIFO_FRAME_COUNTER_S__REG BMA2x2_STATUS_FIFO_REG + +#define BMA2x2_FIFO_OVERRUN_S__POS 7 +#define BMA2x2_FIFO_OVERRUN_S__LEN 1 +#define BMA2x2_FIFO_OVERRUN_S__MSK 0x80 +#define BMA2x2_FIFO_OVERRUN_S__REG BMA2x2_STATUS_FIFO_REG +#define BMA2x2_RANGE_SEL__POS 0 +#define BMA2x2_RANGE_SEL__LEN 4 +#define BMA2x2_RANGE_SEL__MSK 0x0F +#define BMA2x2_RANGE_SEL__REG BMA2x2_RANGE_SEL_REG +#define BMA2x2_BANDWIDTH__POS 0 +#define BMA2x2_BANDWIDTH__LEN 5 +#define BMA2x2_BANDWIDTH__MSK 0x1F +#define BMA2x2_BANDWIDTH__REG BMA2x2_BW_SEL_REG +#define BMA2x2_SLEEP_DUR__POS 1 +#define BMA2x2_SLEEP_DUR__LEN 4 +#define BMA2x2_SLEEP_DUR__MSK 0x1E +#define BMA2x2_SLEEP_DUR__REG BMA2x2_MODE_CTRL_REG + +#define BMA2x2_MODE_CTRL__POS 5 +#define BMA2x2_MODE_CTRL__LEN 3 +#define BMA2x2_MODE_CTRL__MSK 0xE0 +#define BMA2x2_MODE_CTRL__REG BMA2x2_MODE_CTRL_REG +// ADDED + +#define BMA2x2_EN_LOW_POWER__POS 6 +#define BMA2x2_EN_LOW_POWER__LEN 1 +#define BMA2x2_EN_LOW_POWER__MSK 0x40 +#define BMA2x2_EN_LOW_POWER__REG BMA2x2_MODE_CTRL_REG + +// ADDED + +#define BMA2x2_SLEEP_TIMER__POS 5 +#define BMA2x2_SLEEP_TIMER__LEN 1 +#define BMA2x2_SLEEP_TIMER__MSK 0x20 +#define BMA2x2_SLEEP_TIMER__REG BMA2x2_LOW_NOISE_CTRL_REG + +// ADDED +#define BMA2x2_LOW_POWER_MODE__POS 6 +#define BMA2x2_LOW_POWER_MODE__LEN 1 +#define BMA2x2_LOW_POWER_MODE__MSK 0x40 +#define BMA2x2_LOW_POWER_MODE__REG BMA2x2_LOW_NOISE_CTRL_REG + +/** DISABLE MSB SHADOWING PROCEDURE **/ + +#define BMA2x2_DIS_SHADOW_PROC__POS 6 +#define BMA2x2_DIS_SHADOW_PROC__LEN 1 +#define BMA2x2_DIS_SHADOW_PROC__MSK 0x40 +#define BMA2x2_DIS_SHADOW_PROC__REG BMA2x2_DATA_CTRL_REG + +/** FILTERED OR UNFILTERED ACCELERATION DATA **/ + +#define BMA2x2_EN_DATA_HIGH_BW__POS 7 +#define BMA2x2_EN_DATA_HIGH_BW__LEN 1 +#define BMA2x2_EN_DATA_HIGH_BW__MSK 0x80 +#define BMA2x2_EN_DATA_HIGH_BW__REG BMA2x2_DATA_CTRL_REG + +#define BMA2x2_EN_SOFT_RESET_VALUE 0xB6 +/** INTERRUPT ENABLE REGISTER **/ + +#define BMA2x2_EN_SLOPE_X_INT__POS 0 +#define BMA2x2_EN_SLOPE_X_INT__LEN 1 +#define BMA2x2_EN_SLOPE_X_INT__MSK 0x01 +#define BMA2x2_EN_SLOPE_X_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_SLOPE_Y_INT__POS 1 +#define BMA2x2_EN_SLOPE_Y_INT__LEN 1 +#define BMA2x2_EN_SLOPE_Y_INT__MSK 0x02 +#define BMA2x2_EN_SLOPE_Y_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_SLOPE_Z_INT__POS 2 +#define BMA2x2_EN_SLOPE_Z_INT__LEN 1 +#define BMA2x2_EN_SLOPE_Z_INT__MSK 0x04 +#define BMA2x2_EN_SLOPE_Z_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_DOUBLE_TAP_INT__POS 4 +#define BMA2x2_EN_DOUBLE_TAP_INT__LEN 1 +#define BMA2x2_EN_DOUBLE_TAP_INT__MSK 0x10 +#define BMA2x2_EN_DOUBLE_TAP_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_SINGLE_TAP_INT__POS 5 +#define BMA2x2_EN_SINGLE_TAP_INT__LEN 1 +#define BMA2x2_EN_SINGLE_TAP_INT__MSK 0x20 +#define BMA2x2_EN_SINGLE_TAP_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_ORIENT_INT__POS 6 +#define BMA2x2_EN_ORIENT_INT__LEN 1 +#define BMA2x2_EN_ORIENT_INT__MSK 0x40 +#define BMA2x2_EN_ORIENT_INT__REG BMA2x2_INT_ENABLE1_REG + +#define BMA2x2_EN_FLAT_INT__POS 7 +#define BMA2x2_EN_FLAT_INT__LEN 1 +#define BMA2x2_EN_FLAT_INT__MSK 0x80 +#define BMA2x2_EN_FLAT_INT__REG BMA2x2_INT_ENABLE1_REG +/** INTERRUPT ENABLE REGISTER **/ + +#define BMA2x2_EN_HIGHG_X_INT__POS 0 +#define BMA2x2_EN_HIGHG_X_INT__LEN 1 +#define BMA2x2_EN_HIGHG_X_INT__MSK 0x01 +#define BMA2x2_EN_HIGHG_X_INT__REG BMA2x2_INT_ENABLE2_REG + +#define BMA2x2_EN_HIGHG_Y_INT__POS 1 +#define BMA2x2_EN_HIGHG_Y_INT__LEN 1 +#define BMA2x2_EN_HIGHG_Y_INT__MSK 0x02 +#define BMA2x2_EN_HIGHG_Y_INT__REG BMA2x2_INT_ENABLE2_REG + +#define BMA2x2_EN_HIGHG_Z_INT__POS 2 +#define BMA2x2_EN_HIGHG_Z_INT__LEN 1 +#define BMA2x2_EN_HIGHG_Z_INT__MSK 0x04 +#define BMA2x2_EN_HIGHG_Z_INT__REG BMA2x2_INT_ENABLE2_REG + +#define BMA2x2_EN_LOWG_INT__POS 3 +#define BMA2x2_EN_LOWG_INT__LEN 1 +#define BMA2x2_EN_LOWG_INT__MSK 0x08 +#define BMA2x2_EN_LOWG_INT__REG BMA2x2_INT_ENABLE2_REG + +#define BMA2x2_EN_NEW_DATA_INT__POS 4 +#define BMA2x2_EN_NEW_DATA_INT__LEN 1 +#define BMA2x2_EN_NEW_DATA_INT__MSK 0x10 +#define BMA2x2_EN_NEW_DATA_INT__REG BMA2x2_INT_ENABLE2_REG + +// ADDED +#define BMA2x2_INT_FFULL_EN_INT__POS 5 +#define BMA2x2_INT_FFULL_EN_INT__LEN 1 +#define BMA2x2_INT_FFULL_EN_INT__MSK 0x20 +#define BMA2x2_INT_FFULL_EN_INT__REG BMA2x2_INT_ENABLE2_REG + +#define BMA2x2_INT_FWM_EN_INT__POS 6 +#define BMA2x2_INT_FWM_EN_INT__LEN 1 +#define BMA2x2_INT_FWM_EN_INT__MSK 0x40 +#define BMA2x2_INT_FWM_EN_INT__REG BMA2x2_INT_ENABLE2_REG +// INT SLO NO MOT + +#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__POS 0 +#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__LEN 1 +#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__MSK 0x01 +#define BMA2x2_INT_SLO_NO_MOT_EN_X_INT__REG BMA2x2_INT_SLO_NO_MOT_REG + +#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__POS 1 +#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__LEN 1 +#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__MSK 0x02 +#define BMA2x2_INT_SLO_NO_MOT_EN_Y_INT__REG BMA2x2_INT_SLO_NO_MOT_REG + +#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__POS 2 +#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__LEN 1 +#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__MSK 0x04 +#define BMA2x2_INT_SLO_NO_MOT_EN_Z_INT__REG BMA2x2_INT_SLO_NO_MOT_REG + +#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__POS 3 +#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__LEN 1 +#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__MSK 0x08 +#define BMA2x2_INT_SLO_NO_MOT_EN_SEL_INT__REG BMA2x2_INT_SLO_NO_MOT_REG +#define BMA2x2_EN_INT1_PAD_LOWG__POS 0 +#define BMA2x2_EN_INT1_PAD_LOWG__LEN 1 +#define BMA2x2_EN_INT1_PAD_LOWG__MSK 0x01 +#define BMA2x2_EN_INT1_PAD_LOWG__REG BMA2x2_INT1_PAD_SEL_REG +#define BMA2x2_EN_INT1_PAD_HIGHG__POS 1 +#define BMA2x2_EN_INT1_PAD_HIGHG__LEN 1 +#define BMA2x2_EN_INT1_PAD_HIGHG__MSK 0x02 +#define BMA2x2_EN_INT1_PAD_HIGHG__REG BMA2x2_INT1_PAD_SEL_REG + +#define BMA2x2_EN_INT1_PAD_SLOPE__POS 2 +#define BMA2x2_EN_INT1_PAD_SLOPE__LEN 1 +#define BMA2x2_EN_INT1_PAD_SLOPE__MSK 0x04 +#define BMA2x2_EN_INT1_PAD_SLOPE__REG BMA2x2_INT1_PAD_SEL_REG + +// ADDED +#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__POS 3 +#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__LEN 1 +#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__MSK 0x08 +#define BMA2x2_EN_INT1_PAD_SLO_NO_MOT__REG BMA2x2_INT1_PAD_SEL_REG + +#define BMA2x2_EN_INT1_PAD_DB_TAP__POS 4 +#define BMA2x2_EN_INT1_PAD_DB_TAP__LEN 1 +#define BMA2x2_EN_INT1_PAD_DB_TAP__MSK 0x10 +#define BMA2x2_EN_INT1_PAD_DB_TAP__REG BMA2x2_INT1_PAD_SEL_REG + +#define BMA2x2_EN_INT1_PAD_SNG_TAP__POS 5 +#define BMA2x2_EN_INT1_PAD_SNG_TAP__LEN 1 +#define BMA2x2_EN_INT1_PAD_SNG_TAP__MSK 0x20 +#define BMA2x2_EN_INT1_PAD_SNG_TAP__REG BMA2x2_INT1_PAD_SEL_REG + +#define BMA2x2_EN_INT1_PAD_ORIENT__POS 6 +#define BMA2x2_EN_INT1_PAD_ORIENT__LEN 1 +#define BMA2x2_EN_INT1_PAD_ORIENT__MSK 0x40 +#define BMA2x2_EN_INT1_PAD_ORIENT__REG BMA2x2_INT1_PAD_SEL_REG + +#define BMA2x2_EN_INT1_PAD_FLAT__POS 7 +#define BMA2x2_EN_INT1_PAD_FLAT__LEN 1 +#define BMA2x2_EN_INT1_PAD_FLAT__MSK 0x80 +#define BMA2x2_EN_INT1_PAD_FLAT__REG BMA2x2_INT1_PAD_SEL_REG +#define BMA2x2_EN_INT2_PAD_LOWG__POS 0 +#define BMA2x2_EN_INT2_PAD_LOWG__LEN 1 +#define BMA2x2_EN_INT2_PAD_LOWG__MSK 0x01 +#define BMA2x2_EN_INT2_PAD_LOWG__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_HIGHG__POS 1 +#define BMA2x2_EN_INT2_PAD_HIGHG__LEN 1 +#define BMA2x2_EN_INT2_PAD_HIGHG__MSK 0x02 +#define BMA2x2_EN_INT2_PAD_HIGHG__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_SLOPE__POS 2 +#define BMA2x2_EN_INT2_PAD_SLOPE__LEN 1 +#define BMA2x2_EN_INT2_PAD_SLOPE__MSK 0x04 +#define BMA2x2_EN_INT2_PAD_SLOPE__REG BMA2x2_INT2_PAD_SEL_REG + +// ADDED + +#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__POS 3 +#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__LEN 1 +#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__MSK 0x08 +#define BMA2x2_EN_INT2_PAD_SLO_NO_MOT__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_DB_TAP__POS 4 +#define BMA2x2_EN_INT2_PAD_DB_TAP__LEN 1 +#define BMA2x2_EN_INT2_PAD_DB_TAP__MSK 0x10 +#define BMA2x2_EN_INT2_PAD_DB_TAP__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_SNG_TAP__POS 5 +#define BMA2x2_EN_INT2_PAD_SNG_TAP__LEN 1 +#define BMA2x2_EN_INT2_PAD_SNG_TAP__MSK 0x20 +#define BMA2x2_EN_INT2_PAD_SNG_TAP__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_ORIENT__POS 6 +#define BMA2x2_EN_INT2_PAD_ORIENT__LEN 1 +#define BMA2x2_EN_INT2_PAD_ORIENT__MSK 0x40 +#define BMA2x2_EN_INT2_PAD_ORIENT__REG BMA2x2_INT2_PAD_SEL_REG + +#define BMA2x2_EN_INT2_PAD_FLAT__POS 7 +#define BMA2x2_EN_INT2_PAD_FLAT__LEN 1 +#define BMA2x2_EN_INT2_PAD_FLAT__MSK 0x80 +#define BMA2x2_EN_INT2_PAD_FLAT__REG BMA2x2_INT2_PAD_SEL_REG +#define BMA2x2_EN_INT1_PAD_NEWDATA__POS 0 +#define BMA2x2_EN_INT1_PAD_NEWDATA__LEN 1 +#define BMA2x2_EN_INT1_PAD_NEWDATA__MSK 0x01 +#define BMA2x2_EN_INT1_PAD_NEWDATA__REG BMA2x2_INT_DATA_SEL_REG + +// ADDED +#define BMA2x2_EN_INT1_PAD_FWM__POS 1 +#define BMA2x2_EN_INT1_PAD_FWM__LEN 1 +#define BMA2x2_EN_INT1_PAD_FWM__MSK 0x02 +#define BMA2x2_EN_INT1_PAD_FWM__REG BMA2x2_INT_DATA_SEL_REG + +#define BMA2x2_EN_INT1_PAD_FFULL__POS 2 +#define BMA2x2_EN_INT1_PAD_FFULL__LEN 1 +#define BMA2x2_EN_INT1_PAD_FFULL__MSK 0x04 +#define BMA2x2_EN_INT1_PAD_FFULL__REG BMA2x2_INT_DATA_SEL_REG + +#define BMA2x2_EN_INT2_PAD_FFULL__POS 5 +#define BMA2x2_EN_INT2_PAD_FFULL__LEN 1 +#define BMA2x2_EN_INT2_PAD_FFULL__MSK 0x20 +#define BMA2x2_EN_INT2_PAD_FFULL__REG BMA2x2_INT_DATA_SEL_REG + +#define BMA2x2_EN_INT2_PAD_FWM__POS 6 +#define BMA2x2_EN_INT2_PAD_FWM__LEN 1 +#define BMA2x2_EN_INT2_PAD_FWM__MSK 0x40 +#define BMA2x2_EN_INT2_PAD_FWM__REG BMA2x2_INT_DATA_SEL_REG + +#define BMA2x2_EN_INT2_PAD_NEWDATA__POS 7 +#define BMA2x2_EN_INT2_PAD_NEWDATA__LEN 1 +#define BMA2x2_EN_INT2_PAD_NEWDATA__MSK 0x80 +#define BMA2x2_EN_INT2_PAD_NEWDATA__REG BMA2x2_INT_DATA_SEL_REG +/***** INTERRUPT SOURCE SELECTION *****/ + +#define BMA2x2_UNFILT_INT_SRC_LOWG__POS 0 +#define BMA2x2_UNFILT_INT_SRC_LOWG__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_LOWG__MSK 0x01 +#define BMA2x2_UNFILT_INT_SRC_LOWG__REG BMA2x2_INT_SRC_REG + +#define BMA2x2_UNFILT_INT_SRC_HIGHG__POS 1 +#define BMA2x2_UNFILT_INT_SRC_HIGHG__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_HIGHG__MSK 0x02 +#define BMA2x2_UNFILT_INT_SRC_HIGHG__REG BMA2x2_INT_SRC_REG + +#define BMA2x2_UNFILT_INT_SRC_SLOPE__POS 2 +#define BMA2x2_UNFILT_INT_SRC_SLOPE__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_SLOPE__MSK 0x04 +#define BMA2x2_UNFILT_INT_SRC_SLOPE__REG BMA2x2_INT_SRC_REG + +// ADDED +#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__POS 3 +#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__MSK 0x08 +#define BMA2x2_UNFILT_INT_SRC_SLO_NO_MOT__REG BMA2x2_INT_SRC_REG + +#define BMA2x2_UNFILT_INT_SRC_TAP__POS 4 +#define BMA2x2_UNFILT_INT_SRC_TAP__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_TAP__MSK 0x10 +#define BMA2x2_UNFILT_INT_SRC_TAP__REG BMA2x2_INT_SRC_REG + +#define BMA2x2_UNFILT_INT_SRC_DATA__POS 5 +#define BMA2x2_UNFILT_INT_SRC_DATA__LEN 1 +#define BMA2x2_UNFILT_INT_SRC_DATA__MSK 0x20 +#define BMA2x2_UNFILT_INT_SRC_DATA__REG BMA2x2_INT_SRC_REG +/***** INTERRUPT PAD ACTIVE LEVEL AND OUTPUT TYPE *****/ + +#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__POS 0 +#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__LEN 1 +#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__MSK 0x01 +#define BMA2x2_INT1_PAD_ACTIVE_LEVEL__REG BMA2x2_INT_SET_REG + +#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__POS 2 +#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__LEN 1 +#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__MSK 0x04 +#define BMA2x2_INT2_PAD_ACTIVE_LEVEL__REG BMA2x2_INT_SET_REG + +/***** OUTPUT TYPE IF SET TO 1 IS : OPEN DRIVE , IF NOT SET + IT IS PUSH-PULL *****/ + +#define BMA2x2_INT1_PAD_OUTPUT_TYPE__POS 1 +#define BMA2x2_INT1_PAD_OUTPUT_TYPE__LEN 1 +#define BMA2x2_INT1_PAD_OUTPUT_TYPE__MSK 0x02 +#define BMA2x2_INT1_PAD_OUTPUT_TYPE__REG BMA2x2_INT_SET_REG + +#define BMA2x2_INT2_PAD_OUTPUT_TYPE__POS 3 +#define BMA2x2_INT2_PAD_OUTPUT_TYPE__LEN 1 +#define BMA2x2_INT2_PAD_OUTPUT_TYPE__MSK 0x08 +#define BMA2x2_INT2_PAD_OUTPUT_TYPE__REG BMA2x2_INT_SET_REG +/***** INTERRUPT MODE SELECTION ******/ + +#define BMA2x2_LATCH_INT__POS 0 +#define BMA2x2_LATCH_INT__LEN 4 +#define BMA2x2_LATCH_INT__MSK 0x0F +#define BMA2x2_LATCH_INT__REG BMA2x2_INT_CTRL_REG + +/***** LATCHED INTERRUPT RESET ******/ + +#define BMA2x2_RESET_INT__POS 7 +#define BMA2x2_RESET_INT__LEN 1 +#define BMA2x2_RESET_INT__MSK 0x80 +#define BMA2x2_RESET_INT__REG BMA2x2_INT_CTRL_REG + +/***** LOW-G HYSTERESIS ******/ + +#define BMA2x2_LOWG_HYST__POS 0 +#define BMA2x2_LOWG_HYST__LEN 2 +#define BMA2x2_LOWG_HYST__MSK 0x03 +#define BMA2x2_LOWG_HYST__REG BMA2x2_LOW_HIGH_HYST_REG + +/***** LOW-G INTERRUPT MODE ******/ +/***** IF 1 -- SUM MODE , 0 -- SINGLE MODE ******/ +#define BMA2x2_LOWG_INT_MODE__POS 2 +#define BMA2x2_LOWG_INT_MODE__LEN 1 +#define BMA2x2_LOWG_INT_MODE__MSK 0x04 +#define BMA2x2_LOWG_INT_MODE__REG BMA2x2_LOW_HIGH_HYST_REG + +/***** HIGH-G HYSTERESIS ******/ + +#define BMA2x2_HIGHG_HYST__POS 6 +#define BMA2x2_HIGHG_HYST__LEN 2 +#define BMA2x2_HIGHG_HYST__MSK 0xC0 +#define BMA2x2_HIGHG_HYST__REG BMA2x2_LOW_HIGH_HYST_REG +/***** SLOPE DURATION ******/ + +#define BMA2x2_SLOPE_DUR__POS 0 +#define BMA2x2_SLOPE_DUR__LEN 2 +#define BMA2x2_SLOPE_DUR__MSK 0x03 +#define BMA2x2_SLOPE_DUR__REG BMA2x2_SLOPE_DURN_REG + +// SLO_NO_MOT_DUR ADDED +#define BMA2x2_SLO_NO_MOT_DUR__POS 2 +#define BMA2x2_SLO_NO_MOT_DUR__LEN 6 +#define BMA2x2_SLO_NO_MOT_DUR__MSK 0xFC +#define BMA2x2_SLO_NO_MOT_DUR__REG BMA2x2_SLOPE_DURN_REG + +/***** TAP DURATION ******/ + +#define BMA2x2_TAP_DUR__POS 0 +#define BMA2x2_TAP_DUR__LEN 3 +#define BMA2x2_TAP_DUR__MSK 0x07 +#define BMA2x2_TAP_DUR__REG BMA2x2_TAP_PARAM_REG + +/***** TAP SHOCK DURATION ******/ + +#define BMA2x2_TAP_SHOCK_DURN__POS 6 +#define BMA2x2_TAP_SHOCK_DURN__LEN 1 +#define BMA2x2_TAP_SHOCK_DURN__MSK 0x40 +#define BMA2x2_TAP_SHOCK_DURN__REG BMA2x2_TAP_PARAM_REG + +/***** ADV TAP INT ******/ + +#define BMA2x2_ADV_TAP_INT__POS 5 +#define BMA2x2_ADV_TAP_INT__LEN 1 +#define BMA2x2_ADV_TAP_INT__MSK 0x20 +#define BMA2x2_ADV_TAP_INT__REG BMA2x2_TAP_PARAM_REG + +/***** TAP QUIET DURATION ******/ + +#define BMA2x2_TAP_QUIET_DURN__POS 7 +#define BMA2x2_TAP_QUIET_DURN__LEN 1 +#define BMA2x2_TAP_QUIET_DURN__MSK 0x80 +#define BMA2x2_TAP_QUIET_DURN__REG BMA2x2_TAP_PARAM_REG +/***** TAP THRESHOLD ******/ + +#define BMA2x2_TAP_THRES__POS 0 +#define BMA2x2_TAP_THRES__LEN 5 +#define BMA2x2_TAP_THRES__MSK 0x1F +#define BMA2x2_TAP_THRES__REG BMA2x2_TAP_THRES_REG + +/***** TAP SAMPLES ******/ + +#define BMA2x2_TAP_SAMPLES__POS 6 +#define BMA2x2_TAP_SAMPLES__LEN 2 +#define BMA2x2_TAP_SAMPLES__MSK 0xC0 +#define BMA2x2_TAP_SAMPLES__REG BMA2x2_TAP_THRES_REG +/***** ORIENTATION MODE ******/ + +#define BMA2x2_ORIENT_MODE__POS 0 +#define BMA2x2_ORIENT_MODE__LEN 2 +#define BMA2x2_ORIENT_MODE__MSK 0x03 +#define BMA2x2_ORIENT_MODE__REG BMA2x2_ORIENT_PARAM_REG + +/***** ORIENTATION BLOCKING ******/ + +#define BMA2x2_ORIENT_BLOCK__POS 2 +#define BMA2x2_ORIENT_BLOCK__LEN 2 +#define BMA2x2_ORIENT_BLOCK__MSK 0x0C +#define BMA2x2_ORIENT_BLOCK__REG BMA2x2_ORIENT_PARAM_REG + +/***** ORIENTATION HYSTERESIS ******/ + +#define BMA2x2_ORIENT_HYST__POS 4 +#define BMA2x2_ORIENT_HYST__LEN 3 +#define BMA2x2_ORIENT_HYST__MSK 0x70 +#define BMA2x2_ORIENT_HYST__REG BMA2x2_ORIENT_PARAM_REG +/***** ORIENTATION AXIS SELECTION ******/ +/***** IF SET TO 1 -- X AND Z ARE SWAPPED , Y IS INVERTED */ + +// ADDED +#define BMA2x2_ORIENT_UD_EN__POS 6 +#define BMA2x2_ORIENT_UD_EN__LEN 1 +#define BMA2x2_ORIENT_UD_EN__MSK 0x40 +#define BMA2x2_ORIENT_UD_EN__REG BMA2x2_THETA_BLOCK_REG + +/***** THETA BLOCKING ******/ + +#define BMA2x2_THETA_BLOCK__POS 0 +#define BMA2x2_THETA_BLOCK__LEN 6 +#define BMA2x2_THETA_BLOCK__MSK 0x3F +#define BMA2x2_THETA_BLOCK__REG BMA2x2_THETA_BLOCK_REG +/***** THETA FLAT ******/ + +#define BMA2x2_THETA_FLAT__POS 0 +#define BMA2x2_THETA_FLAT__LEN 6 +#define BMA2x2_THETA_FLAT__MSK 0x3F +#define BMA2x2_THETA_FLAT__REG BMA2x2_THETA_FLAT_REG +/***** FLAT HOLD TIME ******/ + +#define BMA2x2_FLAT_HOLD_TIME__POS 4 +#define BMA2x2_FLAT_HOLD_TIME__LEN 2 +#define BMA2x2_FLAT_HOLD_TIME__MSK 0x30 +#define BMA2x2_FLAT_HOLD_TIME__REG BMA2x2_FLAT_HOLD_TIME_REG +/***** FLAT HYS ******/ + +#define BMA2x2_FLAT_HYS__POS 0 +#define BMA2x2_FLAT_HYS__LEN 3 +#define BMA2x2_FLAT_HYS__MSK 0x07 +#define BMA2x2_FLAT_HYS__REG BMA2x2_FLAT_HOLD_TIME_REG +/***** FIFO WATER MARK LEVEL TRIGGER RETAIN ******/ +// ADDED +#define BMA2x2_FIFO_WML_TRIG_RETAIN__POS 0 +#define BMA2x2_FIFO_WML_TRIG_RETAIN__LEN 6 +#define BMA2x2_FIFO_WML_TRIG_RETAIN__MSK 0x3F +#define BMA2x2_FIFO_WML_TRIG_RETAIN__REG BMA2x2_FIFO_WML_TRIG +/***** ACTIVATE SELF TEST ******/ + +#define BMA2x2_EN_SELF_TEST__POS 0 +#define BMA2x2_EN_SELF_TEST__LEN 2 +#define BMA2x2_EN_SELF_TEST__MSK 0x03 +#define BMA2x2_EN_SELF_TEST__REG BMA2x2_SELF_TEST_REG + +/***** SELF TEST -- NEGATIVE ******/ + +#define BMA2x2_NEG_SELF_TEST__POS 2 +#define BMA2x2_NEG_SELF_TEST__LEN 1 +#define BMA2x2_NEG_SELF_TEST__MSK 0x04 +#define BMA2x2_NEG_SELF_TEST__REG BMA2x2_SELF_TEST_REG + +/***** EEPROM CONTROL ******/ + +/* SETTING THIS BIT UNLOCK'S WRITING SETTING REGISTERS TO EEPROM */ + +#define BMA2x2_UNLOCK_EE_PROG_MODE__POS 0 +#define BMA2x2_UNLOCK_EE_PROG_MODE__LEN 1 +#define BMA2x2_UNLOCK_EE_PROG_MODE__MSK 0x01 +#define BMA2x2_UNLOCK_EE_PROG_MODE__REG BMA2x2_EEPROM_CTRL_REG + +/* SETTING THIS BIT STARTS WRITING SETTING REGISTERS TO EEPROM */ + +#define BMA2x2_START_EE_PROG_TRIG__POS 1 +#define BMA2x2_START_EE_PROG_TRIG__LEN 1 +#define BMA2x2_START_EE_PROG_TRIG__MSK 0x02 +#define BMA2x2_START_EE_PROG_TRIG__REG BMA2x2_EEPROM_CTRL_REG + +/* STATUS OF WRITING TO EEPROM */ + +#define BMA2x2_EE_PROG_READY__POS 2 +#define BMA2x2_EE_PROG_READY__LEN 1 +#define BMA2x2_EE_PROG_READY__MSK 0x04 +#define BMA2x2_EE_PROG_READY__REG BMA2x2_EEPROM_CTRL_REG + +/* UPDATE IMAGE REGISTERS WRITING TO EEPROM */ + +#define BMA2x2_UPDATE_IMAGE__POS 3 +#define BMA2x2_UPDATE_IMAGE__LEN 1 +#define BMA2x2_UPDATE_IMAGE__MSK 0x08 +#define BMA2x2_UPDATE_IMAGE__REG BMA2x2_EEPROM_CTRL_REG + +/* ADDED */ +#define BMA2x2_EE_REMAIN__POS 4 +#define BMA2x2_EE_REMAIN__LEN 4 +#define BMA2x2_EE_REMAIN__MSK 0xF0 +#define BMA2x2_EE_REMAIN__REG BMA2x2_EEPROM_CTRL_REG +/* SPI INTERFACE MODE SELECTION */ + +#define BMA2x2_EN_SPI_MODE_3__POS 0 +#define BMA2x2_EN_SPI_MODE_3__LEN 1 +#define BMA2x2_EN_SPI_MODE_3__MSK 0x01 +#define BMA2x2_EN_SPI_MODE_3__REG BMA2x2_SERIAL_CTRL_REG + +/* I2C WATCHDOG PERIOD SELECTION */ + +#define BMA2x2_I2C_WATCHDOG_PERIOD__POS 1 +#define BMA2x2_I2C_WATCHDOG_PERIOD__LEN 1 +#define BMA2x2_I2C_WATCHDOG_PERIOD__MSK 0x02 +#define BMA2x2_I2C_WATCHDOG_PERIOD__REG BMA2x2_SERIAL_CTRL_REG + +/* I2C WATCHDOG ENABLE */ + +#define BMA2x2_EN_I2C_WATCHDOG__POS 2 +#define BMA2x2_EN_I2C_WATCHDOG__LEN 1 +#define BMA2x2_EN_I2C_WATCHDOG__MSK 0x04 +#define BMA2x2_EN_I2C_WATCHDOG__REG BMA2x2_SERIAL_CTRL_REG +/* SPI INTERFACE MODE SELECTION */ +// ADDED + +/* SETTING THIS BIT UNLOCK'S WRITING TRIMMING REGISTERS TO EEPROM */ + +#define BMA2x2_UNLOCK_EE_WRITE_TRIM__POS 4 +#define BMA2x2_UNLOCK_EE_WRITE_TRIM__LEN 4 +#define BMA2x2_UNLOCK_EE_WRITE_TRIM__MSK 0xF0 +#define BMA2x2_UNLOCK_EE_WRITE_TRIM__REG BMA2x2_CTRL_UNLOCK_REG +/** OFFSET COMPENSATION **/ + +/** SLOW COMPENSATION FOR X,Y,Z AXIS **/ + +#define BMA2x2_EN_SLOW_COMP_X__POS 0 +#define BMA2x2_EN_SLOW_COMP_X__LEN 1 +#define BMA2x2_EN_SLOW_COMP_X__MSK 0x01 +#define BMA2x2_EN_SLOW_COMP_X__REG BMA2x2_OFFSET_CTRL_REG + +#define BMA2x2_EN_SLOW_COMP_Y__POS 1 +#define BMA2x2_EN_SLOW_COMP_Y__LEN 1 +#define BMA2x2_EN_SLOW_COMP_Y__MSK 0x02 +#define BMA2x2_EN_SLOW_COMP_Y__REG BMA2x2_OFFSET_CTRL_REG + +#define BMA2x2_EN_SLOW_COMP_Z__POS 2 +#define BMA2x2_EN_SLOW_COMP_Z__LEN 1 +#define BMA2x2_EN_SLOW_COMP_Z__MSK 0x04 +#define BMA2x2_EN_SLOW_COMP_Z__REG BMA2x2_OFFSET_CTRL_REG + +/** FAST COMPENSATION READY FLAG **/ +// ADDED +#define BMA2x2_FAST_CAL_RDY_S__POS 4 +#define BMA2x2_FAST_CAL_RDY_S__LEN 1 +#define BMA2x2_FAST_CAL_RDY_S__MSK 0x10 +#define BMA2x2_FAST_CAL_RDY_S__REG BMA2x2_OFFSET_CTRL_REG + +/** FAST COMPENSATION FOR X,Y,Z AXIS **/ + +#define BMA2x2_CAL_TRIGGER__POS 5 +#define BMA2x2_CAL_TRIGGER__LEN 2 +#define BMA2x2_CAL_TRIGGER__MSK 0x60 +#define BMA2x2_CAL_TRIGGER__REG BMA2x2_OFFSET_CTRL_REG + +/** RESET OFFSET REGISTERS **/ + +#define BMA2x2_RESET_OFFSET_REGS__POS 7 +#define BMA2x2_RESET_OFFSET_REGS__LEN 1 +#define BMA2x2_RESET_OFFSET_REGS__MSK 0x80 +#define BMA2x2_RESET_OFFSET_REGS__REG BMA2x2_OFFSET_CTRL_REG +/** SLOW COMPENSATION CUTOFF **/ + +#define BMA2x2_COMP_CUTOFF__POS 0 +#define BMA2x2_COMP_CUTOFF__LEN 1 +#define BMA2x2_COMP_CUTOFF__MSK 0x01 +#define BMA2x2_COMP_CUTOFF__REG BMA2x2_OFFSET_PARAMS_REG + +/** COMPENSATION TARGET **/ + +#define BMA2x2_COMP_TARGET_OFFSET_X__POS 1 +#define BMA2x2_COMP_TARGET_OFFSET_X__LEN 2 +#define BMA2x2_COMP_TARGET_OFFSET_X__MSK 0x06 +#define BMA2x2_COMP_TARGET_OFFSET_X__REG BMA2x2_OFFSET_PARAMS_REG + +#define BMA2x2_COMP_TARGET_OFFSET_Y__POS 3 +#define BMA2x2_COMP_TARGET_OFFSET_Y__LEN 2 +#define BMA2x2_COMP_TARGET_OFFSET_Y__MSK 0x18 +#define BMA2x2_COMP_TARGET_OFFSET_Y__REG BMA2x2_OFFSET_PARAMS_REG + +#define BMA2x2_COMP_TARGET_OFFSET_Z__POS 5 +#define BMA2x2_COMP_TARGET_OFFSET_Z__LEN 2 +#define BMA2x2_COMP_TARGET_OFFSET_Z__MSK 0x60 +#define BMA2x2_COMP_TARGET_OFFSET_Z__REG BMA2x2_OFFSET_PARAMS_REG +/** FIFO DATA SELECT **/ +// ADDED + +#define BMA2x2_FIFO_DATA_SELECT__POS 0 +#define BMA2x2_FIFO_DATA_SELECT__LEN 2 +#define BMA2x2_FIFO_DATA_SELECT__MSK 0x03 +#define BMA2x2_FIFO_DATA_SELECT__REG BMA2x2_FIFO_MODE_REG + +// FIFO MODE + +#define BMA2x2_FIFO_MODE__POS 6 +#define BMA2x2_FIFO_MODE__LEN 2 +#define BMA2x2_FIFO_MODE__MSK 0xC0 +#define BMA2x2_FIFO_MODE__REG BMA2x2_FIFO_MODE_REG +#define BMA2x2_GET_BITSLICE(regvar, bitname) \ + (regvar & bitname ## __MSK) >> bitname ## __POS + +#define BMA2x2_SET_BITSLICE(regvar, bitname, val) \ + (regvar & ~bitname ## __MSK) | ((val << bitname ## __POS) & bitname ## __MSK) + +/** \endcond */ + +/* CONSTANTS */ + +#define BMA2x2_STATUS1 0 /**< It refers BMA2x2 STATUS_INT1 */ +#define BMA2x2_STATUS2 1 /**< It refers BMA2x2 STATUS_INT2 */ +#define BMA2x2_STATUS3 2 /**< It refers BMA2x2 STATUS_INT_TAP */ +#define BMA2x2_STATUS4 3 /**< It refers BMA2x2 STATUS_INT_ORIENT */ +#define BMA2x2_STATUS5 4 /**< It refers BMA2x2 STATUS_INT_FIFO */ + +#define E_BMA2x2_OUT_OF_RANGE (char) -2 + +/* range and bandwidth */ + +#define BMA2x2_RANGE_2G 3 /**< sets range to +/- 2G mode \see BMA2x2_set_range() */ +#define BMA2x2_RANGE_4G 5 /**< sets range to +/- 4G mode \see BMA2x2_set_range() */ +#define BMA2x2_RANGE_8G 8 /**< sets range to +/- 8G mode \see BMA2x2_set_range() */ +#define BMA2x2_RANGE_16G 12 /**< sets range to +/- 16G mode \see BMA2x2_set_range() */ + +#define BMA2x2_BW_7_81HZ 0x08 /**< sets bandwidth to LowPass 7.81 HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_15_63HZ 0x09 /**< sets bandwidth to LowPass 15.63 HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_31_25HZ 0x0A /**< sets bandwidth to LowPass 31.25 HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_62_50HZ 0x0B /**< sets bandwidth to LowPass 62.50 HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_125HZ 0x0C /**< sets bandwidth to LowPass 125HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_250HZ 0x0D /**< sets bandwidth to LowPass 250HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_500HZ 0x0E /**< sets bandwidth to LowPass 500HZ \see BMA2x2_set_bandwidth() */ +#define BMA2x2_BW_1000HZ 0x0F /**< sets bandwidth to LowPass 1000HZ \see BMA2x2_set_bandwidth() */ + +/* SLEEP DURATION */ + +#define BMA2x2_SLEEP_DUR_0_5MS 0x05 /* sets sleep duration to 0.5 ms */ +#define BMA2x2_SLEEP_DUR_1MS 0x06 /* sets sleep duration to 1 ms */ +#define BMA2x2_SLEEP_DUR_2MS 0x07 /* sets sleep duration to 2 ms */ +#define BMA2x2_SLEEP_DUR_4MS 0x08 /* sets sleep duration to 4 ms */ +#define BMA2x2_SLEEP_DUR_6MS 0x09 /* sets sleep duration to 6 ms*/ +#define BMA2x2_SLEEP_DUR_10MS 0x0A /* sets sleep duration to 10 ms */ +#define BMA2x2_SLEEP_DUR_25MS 0x0B /* sets sleep duration to 25 ms */ +#define BMA2x2_SLEEP_DUR_50MS 0x0C /* sets sleep duration to 50 ms */ +#define BMA2x2_SLEEP_DUR_100MS 0x0D /* sets sleep duration to 100 ms */ +#define BMA2x2_SLEEP_DUR_500MS 0x0E /* sets sleep duration to 500 ms */ +#define BMA2x2_SLEEP_DUR_1S 0x0F /* sets sleep duration to 1 s */ + +/* LATCH DURATION */ + +#define BMA2x2_LATCH_DUR_NON_LATCH 0x00 /* sets LATCH duration to NON LATCH */ +#define BMA2x2_LATCH_DUR_250MS 0x01 /* sets LATCH duration to 250 ms */ +#define BMA2x2_LATCH_DUR_500MS 0x02 /* sets LATCH duration to 500 ms */ +#define BMA2x2_LATCH_DUR_1S 0x03 /* sets LATCH duration to 1 s */ +#define BMA2x2_LATCH_DUR_2S 0x04 /* sets LATCH duration to 2 s*/ +#define BMA2x2_LATCH_DUR_4S 0x05 /* sets LATCH duration to 4 s */ +#define BMA2x2_LATCH_DUR_8S 0x06 /* sets LATCH duration to 8 s */ +#define BMA2x2_LATCH_DUR_LATCH 0x07 /* sets LATCH duration to LATCH */ +#define BMA2x2_LATCH_DUR_NON_LATCH1 0x08 /* sets LATCH duration to NON LATCH1 */ +#define BMA2x2_LATCH_DUR_250US 0x09 /* sets LATCH duration to 250 Us */ +#define BMA2x2_LATCH_DUR_500US 0x0A /* sets LATCH duration to 500 Us */ +#define BMA2x2_LATCH_DUR_1MS 0x0B /* sets LATCH duration to 1 Ms */ +#define BMA2x2_LATCH_DUR_12_5MS 0x0C /* sets LATCH duration to 12.5 Ms */ +#define BMA2x2_LATCH_DUR_25MS 0x0D /* sets LATCH duration to 25 Ms */ +#define BMA2x2_LATCH_DUR_50MS 0x0E /* sets LATCH duration to 50 Ms */ +#define BMA2x2_LATCH_DUR_LATCH1 0x0F /* sets LATCH duration to LATCH*/ + +/* mode settings */ + +#define BMA2x2_MODE_NORMAL 0 +#define BMA2x2_MODE_LOWPOWER1 1 +#define BMA2x2_MODE_SUSPEND 2 +#define BMA2x2_MODE_DEEP_SUSPEND 3 +#define BMA2x2_MODE_LOWPOWER2 4 +#define BMA2x2_MODE_STANDBY 5 + +/* BMA2x2 AXIS */ + +#define BMA2x2_X_AXIS 0 /**< It refers BMA2x2 X-axis */ +#define BMA2x2_Y_AXIS 1 /**< It refers BMA2x2 Y-axis */ +#define BMA2x2_Z_AXIS 2 /**< It refers BMA2x2 Z-axis */ + +/* INTERRUPT TYPES */ + +#define BMA2x2_Low_G_Interrupt 0 +#define BMA2x2_High_G_X_Interrupt 1 +#define BMA2x2_High_G_Y_Interrupt 2 +#define BMA2x2_High_G_Z_Interrupt 3 +#define BMA2x2_DATA_EN 4 +#define BMA2x2_Slope_X_Interrupt 5 +#define BMA2x2_Slope_Y_Interrupt 6 +#define BMA2x2_Slope_Z_Interrupt 7 +#define BMA2x2_Single_Tap_Interrupt 8 +#define BMA2x2_Double_Tap_Interrupt 9 +#define BMA2x2_Orient_Interrupt 10 +#define BMA2x2_Flat_Interrupt 11 +#define BMA2x2_FFULL_INTERRUPT 12 +#define BMA2x2_FWM_INTERRUPT 13 + +/* INTERRUPTS PADS */ + +#define BMA2x2_INT1_LOWG 0 +#define BMA2x2_INT2_LOWG 1 +#define BMA2x2_INT1_HIGHG 0 +#define BMA2x2_INT2_HIGHG 1 +#define BMA2x2_INT1_SLOPE 0 +#define BMA2x2_INT2_SLOPE 1 +#define BMA2x2_INT1_SLO_NO_MOT 0 +#define BMA2x2_INT2_SLO_NO_MOT 1 +#define BMA2x2_INT1_DTAP 0 +#define BMA2x2_INT2_DTAP 1 +#define BMA2x2_INT1_STAP 0 +#define BMA2x2_INT2_STAP 1 +#define BMA2x2_INT1_ORIENT 0 +#define BMA2x2_INT2_ORIENT 1 +#define BMA2x2_INT1_FLAT 0 +#define BMA2x2_INT2_FLAT 1 +#define BMA2x2_INT1_NDATA 0 +#define BMA2x2_INT2_NDATA 1 +#define BMA2x2_INT1_FWM 0 +#define BMA2x2_INT2_FWM 1 +#define BMA2x2_INT1_FFULL 0 +#define BMA2x2_INT2_FFULL 1 + +/* SOURCE REGISTER */ + +#define BMA2x2_SRC_LOWG 0 +#define BMA2x2_SRC_HIGHG 1 +#define BMA2x2_SRC_SLOPE 2 +#define BMA2x2_SRC_SLO_NO_MOT 3 +#define BMA2x2_SRC_TAP 4 +#define BMA2x2_SRC_DATA 5 + +#define BMA2x2_INT1_OUTPUT 0 +#define BMA2x2_INT2_OUTPUT 1 +#define BMA2x2_INT1_LEVEL 0 +#define BMA2x2_INT2_LEVEL 1 + +/* DURATION */ + +#define BMA2x2_LOW_DURATION 0 +#define BMA2x2_HIGH_DURATION 1 +#define BMA2x2_SLOPE_DURATION 2 +#define BMA2x2_SLO_NO_MOT_DURATION 3 + +/* THRESHOLD */ + +#define BMA2x2_LOW_THRESHOLD 0 +#define BMA2x2_HIGH_THRESHOLD 1 +#define BMA2x2_SLOPE_THRESHOLD 2 +#define BMA2x2_SLO_NO_MOT_THRESHOLD 3 + +#define BMA2x2_LOWG_HYST 0 +#define BMA2x2_HIGHG_HYST 1 + +#define BMA2x2_ORIENT_THETA 0 +#define BMA2x2_FLAT_THETA 1 + +#define BMA2x2_I2C_SELECT 0 +#define BMA2x2_I2C_EN 1 + +/* COMPENSATION */ + +#define BMA2x2_SLOW_COMP_X 0 +#define BMA2x2_SLOW_COMP_Y 1 +#define BMA2x2_SLOW_COMP_Z 2 + +/* OFFSET TRIGGER */ + +#define BMA2x2_CUT_OFF 0 +#define BMA2x2_OFFSET_TRIGGER_X 1 +#define BMA2x2_OFFSET_TRIGGER_Y 2 +#define BMA2x2_OFFSET_TRIGGER_Z 3 + +/* GP REGISTERS */ + +#define BMA2x2_GP0 0 +#define BMA2x2_GP1 1 + +/* SLO NO MOT REGISTER */ + +#define BMA2x2_SLO_NO_MOT_EN_X 0 +#define BMA2x2_SLO_NO_MOT_EN_Y 1 +#define BMA2x2_SLO_NO_MOT_EN_Z 2 +#define BMA2x2_SLO_NO_MOT_EN_SEL 3 + +/* wake up */ + +#define BMA2x2_WAKE_UP_DUR_20MS 0 +#define BMA2x2_WAKE_UP_DUR_80MS 1 +#define BMA2x2_WAKE_UP_DUR_320MS 2 +#define BMA2x2_WAKE_UP_DUR_2560MS 3 + +/* LG/HG thresholds are in LSB and depend on RANGE setting */ +/* no range check on threshold calculation */ + +#define BMA2x2_SELF_TEST0_ON 1 +#define BMA2x2_SELF_TEST1_ON 2 + +#define BMA2x2_EE_W_OFF 0 +#define BMA2x2_EE_W_ON 1 + +/* Resolution Settings */ +#define BMA2x2_RESOLUTION_12_BIT 0 +#define BMA2x2_RESOLUTION_10_BIT 1 +#define BMA2x2_RESOLUTION_8_BIT 2 +#define BMA2x2_RESOLUTION_14_BIT 3 + +#define BMA2x2 0x16 +#define BMA280 0x17 +#define BMA222E 0x18 +#define BMA250E 0x19 +/** Macro to convert floating point low-g-thresholds in G to 8-bit register values.
+ * Example: BMA2x2_LOW_TH_IN_G( 0.3, 2.0) generates the register value for 0.3G threshold in 2G mode. + * \brief convert g-values to 8-bit value + */ +#define BMA2x2_LOW_TH_IN_G(gthres, range) ((256 * gthres ) / range) + +/** Macro to convert floating point high-g-thresholds in G to 8-bit register values.
+ * Example: BMA2x2_HIGH_TH_IN_G( 1.4, 2.0) generates the register value for 1.4G threshold in 2G mode. + * \brief convert g-values to 8-bit value + */ +#define BMA2x2_HIGH_TH_IN_G(gthres, range) ((256 * gthres ) / range) + +/** Macro to convert floating point low-g-hysteresis in G to 8-bit register values.
+ * Example: BMA2x2_LOW_HY_IN_G( 0.2, 2.0) generates the register value for 0.2G threshold in 2G mode. + * \brief convert g-values to 8-bit value + */ +#define BMA2x2_LOW_HY_IN_G(ghyst, range) ((32 * ghyst) / range) + +/** Macro to convert floating point high-g-hysteresis in G to 8-bit register values.
+ * Example: BMA2x2_HIGH_HY_IN_G( 0.2, 2.0) generates the register value for 0.2G threshold in 2G mode. + * \brief convert g-values to 8-bit value + */ +#define BMA2x2_HIGH_HY_IN_G(ghyst, range) ((32 * ghyst) / range) + +/** Macro to convert floating point G-thresholds to 8-bit register values
+ * Example: BMA2x2_SLOPE_TH_IN_G( 1.2, 2.0) generates the register value for 1.2G threshold in 2G mode. + * \brief convert g-values to 8-bit value + */ + +#define BMA2x2_SLOPE_TH_IN_G(gthres, range) ((128 * gthres ) / range) +/*user defined Enums*/ +// Example.. +// enum { +// E_YOURDATA1, /**< */ +// E_YOURDATA2 /**< */ +// }; +// Example... +// struct DUMMY_STRUCT { +// data1, /**< */ +// data2 /**< */ +// }; +/******************************************************************************* + * Description: *//**\brief This API reads the data from the given register + * + * + * + * + * \param unsigned char addr, unsigned char *data + * addr -> Address of the register + * data -> address of the variable, read value will be kept + * \return results of bus communication function + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_burst_read(unsigned char addr, unsigned char *data, unsigned int len); + +int bma2x2_init(bma2x2_t *bma2x2); + +int bma2x2_write_reg(unsigned char addr, unsigned char *data, unsigned char len); + +int bma2x2_read_reg(unsigned char addr, unsigned char *data, unsigned char len); + +int bma2x2_read_accel_x(short *a_x); + +int bma2x2_read_accel_y(short *a_y); + +int bma2x2_read_accel_z(short *a_z); + +int bma2x2_read_accel_xyz(bma2x2acc_t *acc); + +int bma2x2_get_int_tap_status(unsigned char *status_tap); + +int bma2x2_get_int_orient_status(unsigned char *status_orient); + +int bma2x2_get_fifo_status(unsigned char *status_fifo); + +int bma2x2_get_fifo_framecount(unsigned char *framecount); + +int bma2x2_get_fifo_overrun(unsigned char *overrun); + +int bma2x2_get_interrupt_status(unsigned char *status); + +int bma2x2_get_range(unsigned char *Range); + +int bma2x2_set_range(unsigned char Range); + +int bma2x2_get_bandwidth(unsigned char *bw); + +int bma2x2_set_bandwidth(unsigned char bw); + +int bma2x2_get_mode(unsigned char *Mode); + +unsigned char bma2x2_set_mode(unsigned char Mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleep_dur(unsigned char *sleep_dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleep_dur (unsigned char sleep_dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_sleeptmr_mode(unsigned char *sleep_tmr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_sleeptmr_mode (unsigned char sleep_tmr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_high_bw (unsigned char *high_bw); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_high_bw (unsigned char high_bw); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_shadow_dis (unsigned char *shadow_dis); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_shadow_dis (unsigned char shadow_dis); + +int bma2x2_soft_reset(void); + +int bma2x2_update_image(void); + +int bma2x2_set_Int_Enable(unsigned char InterruptType, unsigned char value); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_ffull (unsigned char *ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_ffull (unsigned char ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_fwm (unsigned char *fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_fwm (unsigned char fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slo_no_mot (unsigned char channel, unsigned char *slo_data); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slo_no_mot (unsigned char channel, unsigned char slo_data); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_low (unsigned char channel, unsigned char *int_low); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_low (unsigned char channel, unsigned char int_low); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_high(unsigned char channel, unsigned char *int_high); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_high(unsigned char channel, unsigned char int_high); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slope(unsigned char channel, unsigned char *int_slope); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slope(unsigned char channel, unsigned char int_slope); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_slo_no_mot (unsigned char channel, unsigned char *int_slo_no_mot); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_slo_no_mot (unsigned char channel, unsigned char int_slo_no_mot); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_d_tap (unsigned char channel, unsigned char *int_d_tap); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_d_tap (unsigned char channel, unsigned char int_d_tap); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_s_tap (unsigned char channel, unsigned char *int_s_tap); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_s_tap (unsigned char channel, unsigned char int_s_tap); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_orient (unsigned char channel, unsigned char *int_orient); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_orient (unsigned char channel, unsigned char int_orient); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_flat (unsigned char channel, unsigned char *int_flat); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_flat (unsigned char channel, unsigned char int_flat); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_newdata (unsigned char channel, unsigned char *int_newdata); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_newdata (unsigned char channel, unsigned char int_newdata); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_fwm (unsigned char *int1_fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_fwm (unsigned char int1_fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_fwm (unsigned char *int2_fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_fwm (unsigned char int2_fwm); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int1_ffull (unsigned char *int1_ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int1_ffull (unsigned char int1_ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int2_ffull (unsigned char *int2_ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int2_ffull (unsigned char int2_ffull); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_source (unsigned char channel, unsigned char *int_source); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_source (unsigned char channel, unsigned char int_source); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_od (unsigned char channel, unsigned char *int_od); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_od (unsigned char channel, unsigned char int_od); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_int_lvl (unsigned char channel, unsigned char *int_lvl); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_int_lvl (unsigned char channel, unsigned char int_lvl); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_reset_interrupt (unsigned char reset_int); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_latch_int (unsigned char *latch_int); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_latch_int (unsigned char latch_int); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_dur(unsigned char channel, unsigned char *dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_dur (unsigned char channel, unsigned char dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_thr(unsigned char channel, unsigned char *thr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_thr (unsigned char channel, unsigned char thr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst(unsigned char channel, unsigned char *hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst (unsigned char channel, unsigned char hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_low_high_hyst_mode(unsigned char *mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_low_high_hyst_mode (unsigned char mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_dur (unsigned char *tap_dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_dur (unsigned char tap_dur); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_shock (unsigned char *tap_shock); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_shock (unsigned char tap_shock); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_quiet (unsigned char *tap_quiet); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_quiet (unsigned char tap_quiet); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_thr (unsigned char *tap_thr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_thr (unsigned char tap_thr); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_tap_sample (unsigned char *tap_sample); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_tap_sample (unsigned char tap_sample); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_mode (unsigned char *orient_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_mode (unsigned char orient_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_block (unsigned char *orient_block); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_block (unsigned char orient_block); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_hyst (unsigned char *orient_hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_hyst (unsigned char orient_hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_theta(unsigned char channel, unsigned char *theta); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_theta (unsigned char channel, unsigned char theta); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_orient_en (unsigned char *orient_en); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_orient_en (unsigned char orient_en); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hyst (unsigned char *flat_hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hyst (unsigned char flat_hyst); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_flat_hold_time (unsigned char *flat_hold_time); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_flat_hold_time (unsigned char flat_hold_time); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_wml_trig (unsigned char *fifo_wml_trig); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_wml_trig (unsigned char fifo_wml_trig); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_axis (unsigned char *self_test_axis); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_axis (unsigned char self_test_axis); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_self_test_sign (unsigned char *self_test_sign); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_self_test_sign (unsigned char self_test_sign); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_nvmprog_mode (unsigned char *nvmprog_mode); + +int bma2x2_set_nvmprog_mode(unsigned char prgmode); + +int bma2x2_set_nvprog_trig(unsigned char trig); + +int bma2x2_get_nvmprog_ready(unsigned char *ready); + +int bma2x2_get_nvmprog_remain(unsigned char *remain); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_spi3 (unsigned char *spi3); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_spi3 (unsigned char spi3); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_i2c_wdt (unsigned char channel, unsigned char *prog_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_i2c_wdt (unsigned char channel, unsigned char prog_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_slow_comp(unsigned char channel, unsigned char *slow_comp); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_slow_comp (unsigned char channel, unsigned char slow_comp); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_rdy (unsigned char *rdy); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_rdy (unsigned char rdy); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_cal_trig (unsigned char *cal_trig); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_cal_trig (unsigned char cal_trig); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_reset (unsigned char offset_reset); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset_target(unsigned char channel, unsigned char *offset); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset_target (unsigned char channel, unsigned char offset); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_offset(unsigned char channel, unsigned char *offset); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_offset (unsigned char channel, unsigned char offset); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_gp(unsigned char channel, unsigned char *gp); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_gp (unsigned char channel, unsigned char gp); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_mode (unsigned char *fifo_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_mode (unsigned char fifo_mode); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_sel (unsigned char *data_sel); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_sel (unsigned char data_sel); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_get_fifo_data_out_reg(unsigned char *out_reg); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_fifo_data_out_reg (unsigned char out_reg); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_temperature (signed char *temperature); + +BMA2x2_RETURN_FUNCTION_TYPE bma2x2_read_accel_xyzt(bma2x2acc_data *acc); + +BMA2x2_RETURN_FUNCTION_TYPE bmm050_set_accel_int1_drdy_interrupt \ + (unsigned char enable_disable, + unsigned char active_low0_high1); + +#endif diff --git a/embedded/common/modules/sensor-drivers/bmg160.h b/embedded/common/modules/sensor-drivers/bmg160.h index 153226c..70e4c5a 100644 --- a/embedded/common/modules/sensor-drivers/bmg160.h +++ b/embedded/common/modules/sensor-drivers/bmg160.h @@ -1,4813 +1,4813 @@ -/* - ******************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - ********************************************************************/ -/* Date: 2010/05/31 - * Revision: 1.0 - * Date: 2011/03/15 - * Revision: 1.1 - * Date: 2011/06/27 - * Revision: 1.2 - * Date: 2013/02/19 - * Revision: 1.3 - * Date: 06/05/2013 - * Revision: 1.4 - */ - -/******************************************************************* - * Copyright (C) 2007 Bosch Sensortec GmbH - * - * bmg160.h - * - * Usage: This header file which includes all function declaration - * - ********************************************************************/ -/*******************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. - * They may only be used within the parameters of the respective valid - * product data sheet. Bosch Sensortec products are provided with the - * express understanding that there is no warranty of fitness for a - * particular purpose.They are not fit for use in life-sustaining, - * safety or security sensitive systems or any system or device - * that may lead to bodily harm or property damage if the system - * or device malfunctions. In addition,Bosch Sensortec products are - * not fit for use in products which interact with motor vehicle systems. - * The resale and or use of products are at the purchasers own risk and - * his own responsibility. The examination of fitness for the intended use - * is the sole responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party - * claims, including any claims for incidental, or consequential damages, - * arising from any product use not covered by the parameters of - * the respective valid product data sheet or not approved by - * Bosch Sensortec and reimburse Bosch Sensortec for all costs in - * connection with such claims. - * - * The purchaser must monitor the market for the purchased products, - * particularly with regard to product safety and inform Bosch Sensortec - * without delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). - * Samples may vary from the valid technical specifications of the product - * series. They are therefore not intended or fit for resale to third - * parties or for use in end products. Their sole purpose is internal - * client testing. The testing of an engineering sample may in no way - * replace the testing of a product series. Bosch Sensortec assumes - * no liability for the use of engineering samples. - * By accepting the engineering samples, the Purchaser agrees to indemnify - * Bosch Sensortec from all claims arising from the use of engineering - * samples. - * - * Special: - * This software module (hereinafter called "Software") and any information - * on application-sheets (hereinafter called "Information") is provided - * free of charge for the sole purpose to support your application work. - * The Software and Information is subject to the following - * terms and conditions: - * - * The Software is specifically designed for the exclusive use for - * Bosch Sensortec products by personnel who have special experience - * and training. Do not use this Software if you do not have the - * proper experience or training. - * - * This Software package is provided `` as is `` and without any expressed - * or implied warranties,including without limitation, the implied warranties - * of merchantability and fitness for a particular purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability - * for the functional impairment - * of this Software in terms of fitness, performance and safety. - * Bosch Sensortec and their representatives and agents shall not be liable - * for any direct or indirect damages or injury, except as - * otherwise stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. - * Bosch Sensortec assumes no responsibility for the consequences of use - * of such Information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of Bosch. Specifications mentioned in the Information are - * subject to change without notice. - * - * It is not allowed to deliver the source code of the Software - * to any third party without permission of - * Bosch Sensortec. - */ -/*****************************************************************************/ -/*! \file BMG160.h - \brief Header for BMG160 API */ -/* user defined code to be added here ... */ -#ifndef __BMG160_H__ -#define __BMG160_H__ - -#ifdef __linux__ -#define BMG160_U16 unsigned short /* 16 bit achieved with short */ -#define BMG160_S16 signed short -#define BMG160_S32 signed int /* 32 bit achieved with int */ -#else -#include /*needed to test integer limits */ - -/* find correct data type for signed/unsigned 16 bit variables \ - by checking max of unsigned variant */ -#if USHRT_MAX == 0xFFFF -/* 16 bit achieved with short */ - #define BMG160_U16 unsigned short - #define BMG160_S16 signed short -#elif UINT_MAX == 0xFFFF -/* 16 bit achieved with int */ - #define BMG160_U16 unsigned int - #define BMG160_S16 signed int -#else - #error BMG160_U16 and BMG160_S16 could not be - #error defined automatically, please do so manually -#endif - -/* find correct data type for signed 32 bit variables */ -#if INT_MAX == 0x7FFFFFFF -/* 32 bit achieved with int */ - #define BMG160_S32 signed int -#elif LONG_MAX == 0x7FFFFFFF -/* 32 bit achieved with long int */ - #define BMG160_S32 signed long int -#else - #error BMG160_S32 could not be - #error defined automatically, please do so manually -#endif -#endif - -/**\brief defines the calling parameter types of the BMG160_WR_FUNCTION */ -#define BMG160_BUS_WR_RETURN_TYPE char - -/**\brief links the order of parameters defined in - BMG160_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMG160_BUS_WR_PARAM_TYPES unsigned char, unsigned char, \ - unsigned char *, unsigned char - -/**\brief links the order of parameters defined in - BMG160_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMG160_BUS_WR_PARAM_ORDER(device_addr, register_addr, \ - register_data, wr_len) - -/* never change this line */ -#define BMG160_BUS_WRITE_FUNC(device_addr, register_addr, \ - register_data, wr_len) bus_write(device_addr, register_addr, \ - register_data, wr_len) -/**\brief defines the return parameter type of the BMG160_RD_FUNCTION - */ -#define BMG160_BUS_RD_RETURN_TYPE char -/**\brief defines the calling parameter types of the BMG160_RD_FUNCTION - */ -#define BMG160_BUS_RD_PARAM_TYPES unsigned char, unsigned char, \ - unsigned char *, unsigned char -/**\brief links the order of parameters defined in \ - BMG160_BUS_RD_PARAM_TYPE to function calls used inside the API - */ -#define BMG160_BUS_RD_PARAM_ORDER device_addr, register_addr, \ - register_data -/* never change this line */ -#define BMG160_BUS_READ_FUNC(device_addr, register_addr, \ - register_data, rd_len) bus_read(device_addr, register_addr, \ - register_data, rd_len) -/**\brief defines the return parameter type of the BMG160_RD_FUNCTION - */ -#define BMG160_BURST_RD_RETURN_TYPE char -/**\brief defines the calling parameter types of the BMG160_RD_FUNCTION - */ -#define BMG160_BURST_RD_PARAM_TYPES unsigned char, \ - unsigned char, unsigned char *, signed int -/**\brief links the order of parameters defined in \ - BMG160_BURST_RD_PARAM_TYPE to function calls used inside the API - */ -#define BMG160_BURST_RD_PARAM_ORDER device_addr, register_addr, \ - register_data -/* never change this line */ -#define BMG160_BURST_READ_FUNC(device_addr, register_addr, \ - register_data, rd_len) burst_read(device_addr, \ - register_addr, register_data, rd_len) -/**\brief defines the return parameter type of the BMG160_DELAY_FUNCTION - */ -#define BMG160_DELAY_RETURN_TYPE void -/* never change this line */ -#define BMG160_DELAY_FUNC(delay_in_msec) \ - delay_func(delay_in_msec) -#define BMG160_RETURN_FUNCTION_TYPE int -/**< This refers BMG160 return type as char */ - -/* On the LPC54102 sensor board, the gyro on BMI055 has I2C address 0x69. - * The gyro sensor BMI160 on the LPC54102 has I2C address 0x68 but it's not - * installed on the board. - */ -#define BMG160_I2C_ADDR1 0x68 -#define BMG160_I2C_ADDR2 0x69 // I2C 0x69 is the BMI055 gyro sensor - -#define BMG160_I2C_ADDR (BMG160_I2C_ADDR2) - - - -/*Define of registers*/ - -/* Hard Wired */ -#define BMG160_CHIP_ID_ADDR 0x00 -/**
> bitname ## __POS) - -/* Set bit slice */ -#define BMG160_SET_BITSLICE(regvar, bitname, val) \ - ((regvar & ~bitname ## __MSK) | ((val << bitname ## __POS) & bitname ## __MSK)) -/* Constants */ - -#define BMG160_NULL 0 -/**< constant declaration of NULL */ -#define BMG160_DISABLE 0 -/**< It refers BMG160 disable */ -#define BMG160_ENABLE 1 -/**< It refers BMG160 enable */ -#define BMG160_OFF 0 -/**< It refers BMG160 OFF state */ -#define BMG160_ON 1 -/**< It refers BMG160 ON state */ - -#define BMG160_TURN1 0 -/**< It refers BMG160 TURN1 */ -#define BMG160_TURN2 1 -/**< It refers BMG160 TURN2 */ - -#define BMG160_INT1 0 -/**< It refers BMG160 INT1 */ -#define BMG160_INT2 1 -/**< It refers BMG160 INT2 */ - -#define BMG160_SLOW_OFFSET 0 -/**< It refers BMG160 Slow Offset */ -#define BMG160_AUTO_OFFSET 1 -/**< It refers BMG160 Auto Offset */ -#define BMG160_FAST_OFFSET 2 -/**< It refers BMG160 Fast Offset */ -#define BMG160_S_TAP 0 -/**< It refers BMG160 Single Tap */ -#define BMG160_D_TAP 1 -/**< It refers BMG160 Double Tap */ -#define BMG160_INT1_DATA 0 -/**< It refers BMG160 Int1 Data */ -#define BMG160_INT2_DATA 1 -/**< It refers BMG160 Int2 Data */ -#define BMG160_TAP_UNFILT_DATA 0 -/**< It refers BMG160 Tap unfilt data */ -#define BMG160_HIGH_UNFILT_DATA 1 -/**< It refers BMG160 High unfilt data */ -#define BMG160_CONST_UNFILT_DATA 2 -/**< It refers BMG160 Const unfilt data */ -#define BMG160_ANY_UNFILT_DATA 3 -/**< It refers BMG160 Any unfilt data */ -#define BMG160_SHAKE_UNFILT_DATA 4 -/**< It refers BMG160 Shake unfilt data */ -#define BMG160_SHAKE_TH 0 -/**< It refers BMG160 Shake Threshold */ -#define BMG160_SHAKE_TH2 1 -/**< It refers BMG160 Shake Threshold2 */ -#define BMG160_AUTO_OFFSET_WL 0 -/**< It refers BMG160 Auto Offset word length */ -#define BMG160_FAST_OFFSET_WL 1 -/**< It refers BMG160 Fast Offset word length */ -#define BMG160_I2C_WDT_EN 0 -/**< It refers BMG160 I2C WDT En */ -#define BMG160_I2C_WDT_SEL 1 -/**< It refers BMG160 I2C WDT Sel */ -#define BMG160_EXT_MODE 0 -/**< It refers BMG160 Ext Mode */ -#define BMG160_EXT_PAGE 1 -/**< It refers BMG160 Ext page */ -#define BMG160_START_ADDR 0 -/**< It refers BMG160 Start Address */ -#define BMG160_STOP_ADDR 1 -/**< It refers BMG160 Stop Address */ -#define BMG160_SLOW_CMD 0 -/**< It refers BMG160 Slow Command */ -#define BMG160_FAST_CMD 1 -/**< It refers BMG160 Fast Command */ -#define BMG160_TRIM_VRA 0 -/**< It refers BMG160 Trim VRA */ -#define BMG160_TRIM_VRD 1 -/**< It refers BMG160 Trim VRD */ -#define BMG160_LOGBIT_EM 0 -/**< It refers BMG160 LogBit Em */ -#define BMG160_LOGBIT_VM 1 -/**< It refers BMG160 LogBit VM */ -#define BMG160_GP0 0 -/**< It refers BMG160 GP0 */ -#define BMG160_GP1 1 -/**< It refers BMG160 GP1*/ -#define BMG160_LOW_SPEED 0 -/**< It refers BMG160 Low Speed Oscillator */ -#define BMG160_HIGH_SPEED 1 -/**< It refers BMG160 High Speed Oscillator */ -#define BMG160_DRIVE_OFFSET_P 0 -/**< It refers BMG160 Drive Offset P */ -#define BMG160_DRIVE_OFFSET_N 1 -/**< It refers BMG160 Drive Offset N */ -#define BMG160_TEST_MODE_EN 0 -/**< It refers BMG160 Test Mode Enable */ -#define BMG160_TEST_MODE_REG 1 -/**< It refers BMG160 Test Mode reg */ -#define BMG160_IBIAS_DRIVE_TRIM 0 -/**< It refers BMG160 IBIAS Drive Trim */ -#define BMG160_IBIAS_RATE_TRIM 1 -/**< It refers BMG160 IBIAS Rate Trim */ -#define BMG160_BAA_MODE 0 -/**< It refers BMG160 BAA Mode Trim */ -#define BMG160_BMA_MODE 1 -/**< It refers BMG160 BMA Mode Trim */ -#define BMG160_PI_KP 0 -/**< It refers BMG160 PI KP */ -#define BMG160_PI_KI 1 -/**< It refers BMG160 PI KI */ - -#define C_BMG160_SUCCESS 0 -/**< It refers BMG160 operation is success */ -#define C_BMG160_FAILURE 1 -/**< It refers BMG160 operation is Failure */ - -#define BMG160_SPI_RD_MASK 0x80 -/**< Read mask **/ -#define BMG160_READ_SET 0x01 -/**< Setting for rading data **/ - -#define BMG160_SHIFT_1_POSITION 1 -/**< Shift bit by 1 Position **/ -#define BMG160_SHIFT_2_POSITION 2 -/**< Shift bit by 2 Position **/ -#define BMG160_SHIFT_3_POSITION 3 -/**< Shift bit by 3 Position **/ -#define BMG160_SHIFT_4_POSITION 4 -/**< Shift bit by 4 Position **/ -#define BMG160_SHIFT_5_POSITION 5 -/**< Shift bit by 5 Position **/ -#define BMG160_SHIFT_6_POSITION 6 -/**< Shift bit by 6 Position **/ -#define BMG160_SHIFT_7_POSITION 7 -/**< Shift bit by 7 Position **/ -#define BMG160_SHIFT_8_POSITION 8 -/**< Shift bit by 8 Position **/ -#define BMG160_SHIFT_12_POSITION 12 -/**< Shift bit by 12 Position **/ - -#define C_BMG160_Null_U8X 0 -#define C_BMG160_Zero_U8X 0 -#define C_BMG160_One_U8X 1 -#define C_BMG160_Two_U8X 2 -#define C_BMG160_Three_U8X 3 -#define C_BMG160_Four_U8X 4 -#define C_BMG160_Five_U8X 5 -#define C_BMG160_Six_U8X 6 -#define C_BMG160_Seven_U8X 7 -#define C_BMG160_Eight_U8X 8 -#define C_BMG160_Nine_U8X 9 -#define C_BMG160_Ten_U8X 10 -#define C_BMG160_Eleven_U8X 11 -#define C_BMG160_Twelve_U8X 12 -#define C_BMG160_Thirteen_U8X 13 -#define C_BMG160_Fifteen_U8X 15 -#define C_BMG160_Sixteen_U8X 16 -#define C_BMG160_TwentyTwo_U8X 22 -#define C_BMG160_TwentyThree_U8X 23 -#define C_BMG160_TwentyFour_U8X 24 -#define C_BMG160_TwentyFive_U8X 25 -#define C_BMG160_ThirtyTwo_U8X 32 -#define C_BMG160_Hundred_U8X 100 -#define C_BMG160_OneTwentySeven_U8X 127 -#define C_BMG160_OneTwentyEight_U8X 128 -#define C_BMG160_TwoFiftyFive_U8X 255 -#define C_BMG160_TwoFiftySix_U16X 256 - -#define E_BMG160_NULL_PTR (char) (-127) -#define E_BMG160_COMM_RES (char) (-1) -#define E_BMG160_OUT_OF_RANGE (signed char) (-2) - -#define C_BMG160_No_Filter_U8X 0 -#define C_BMG160_BW_230Hz_U8X 1 -#define C_BMG160_BW_116Hz_U8X 2 -#define C_BMG160_BW_47Hz_U8X 3 -#define C_BMG160_BW_23Hz_U8X 4 -#define C_BMG160_BW_12Hz_U8X 5 -#define C_BMG160_BW_64Hz_U8X 6 -#define C_BMG160_BW_32Hz_U8X 7 - -#define C_BMG160_No_AutoSleepDur_U8X 0 -#define C_BMG160_4ms_AutoSleepDur_U8X 1 -#define C_BMG160_5ms_AutoSleepDur_U8X 2 -#define C_BMG160_8ms_AutoSleepDur_U8X 3 -#define C_BMG160_10ms_AutoSleepDur_U8X 4 -#define C_BMG160_15ms_AutoSleepDur_U8X 5 -#define C_BMG160_20ms_AutoSleepDur_U8X 6 -#define C_BMG160_40ms_AutoSleepDur_U8X 7 - -#define BMG160_WR_FUNC_PTR char (*bus_write) \ - (unsigned char, unsigned char, unsigned char *, unsigned char) -#define BMG160_RD_FUNC_PTR char (*bus_read) \ - (unsigned char, unsigned char, unsigned char *, unsigned char) -#define BMG160_BRD_FUNC_PTR char (*burst_read) \ - (unsigned char, unsigned char, unsigned char *, BMG160_S32) -#define BMG160_MDELAY_DATA_TYPE unsigned int - -/*user defined Structures*/ -struct bmg160_data_t { - BMG160_S16 datax; - BMG160_S16 datay; - BMG160_S16 dataz; - char intstatus[5]; -}; - -struct bmg160_offset_t { - BMG160_U16 datax; - BMG160_U16 datay; - BMG160_U16 dataz; -}; - -struct bmg160_t { - unsigned char chip_id; - unsigned char dev_addr; - BMG160_BRD_FUNC_PTR; - BMG160_WR_FUNC_PTR; - BMG160_RD_FUNC_PTR; - void (*delay_msec)(BMG160_MDELAY_DATA_TYPE); -}; - -/*************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* -* -* \return -* -* -***************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ***************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_init(struct bmg160_t *p_bmg160); - -/*************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* -* -* \return -* -* -***************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataX(BMG160_S16 *data_x); - -/**************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ***************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataY(BMG160_S16 *data_y); - -/*************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -***************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataZ(BMG160_S16 *data_z); - -/************************************************************ - * Description: *//**\brief - * - * - * - * - * \param - * - * - * - * \return - * - * - *************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ***************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZ(struct bmg160_data_t *data); - -/*************************************************************************** - * Description: *//**\brief - * - * - * - * - * \param - * - * - * - * \return - * - * - ****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ********************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZI(struct bmg160_data_t *data); - -/******************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -********************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_Temperature(unsigned char *temperature); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_FIFO_data_reg \ - (unsigned char *FIFO_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_read_register(unsigned char addr, \ - unsigned char *data, unsigned char len); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_burst_read(unsigned char addr, \ - unsigned char *data, BMG160_S32 len); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_write_register(unsigned char addr, \ - unsigned char *data, unsigned char len); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_0 \ - (unsigned char *status0_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_1 \ - (unsigned char *status1_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_2 \ - (unsigned char *status2_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_3 \ - (unsigned char *status3_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ - -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifostatus_reg \ - (unsigned char *fifo_status); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_range_reg \ - (unsigned char *range); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_range_reg \ - (unsigned char range); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_res \ - (unsigned char *high_res); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_res \ - (unsigned char high_res); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_bw(unsigned char *bandwidth); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_bw(unsigned char bandwidth); - -/**************************************************************************** -* Description: *//**\brief -* -* - -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_pmu_ext_tri_sel \ - (unsigned char *pwu_ext_tri_sel); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_pmu_ext_tri_sel \ - (unsigned char pwu_ext_tri_sel); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_bw \ - (unsigned char *high_bw); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_bw \ - (unsigned char high_bw); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_shadow_dis \ - (unsigned char *shadow_dis); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_shadow_dis \ - (unsigned char shadow_dis); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_soft_reset(void); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_data_enable(unsigned char *data_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_data_en(unsigned char data_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_enable(unsigned char *fifo_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_enable(unsigned char fifo_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_enable \ - (unsigned char mode, unsigned char *offset_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_enable \ - (unsigned char mode, unsigned char offset_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_od \ - (unsigned char param, unsigned char *int_od); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_od \ - (unsigned char param, unsigned char int_od); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_lvl \ - (unsigned char param, unsigned char *int_lvl); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_lvl \ - (unsigned char param, unsigned char int_lvl); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_high \ - (unsigned char *int1_high); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_high \ - (unsigned char int1_high); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_any \ - (unsigned char *int1_any); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_any \ - (unsigned char int1_any); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_data \ - (unsigned char axis, unsigned char *int_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_data \ - (unsigned char axis, unsigned char int_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_offset \ - (unsigned char axis, unsigned char *int2_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_offset \ - (unsigned char axis, unsigned char int2_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_offset \ - (unsigned char axis, unsigned char *int1_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_offset \ - (unsigned char axis, unsigned char int1_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_fifo(unsigned char *int_fifo); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_fifo \ - (unsigned char axis, unsigned char int_fifo); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_high \ - (unsigned char *int2_high); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_high \ - (unsigned char int2_high); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_any \ - (unsigned char *int2_any); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_any \ - (unsigned char int2_any); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_unfilt \ - (unsigned char param, unsigned char *offset_unfilt); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_unfilt \ - (unsigned char param, unsigned char offset_unfilt); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_unfilt_data \ - (unsigned char param, unsigned char *unfilt_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_unfilt_data \ - (unsigned char param, unsigned char unfilt_data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_th \ - (unsigned char *any_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_th \ - (unsigned char any_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_awake_dur \ - (unsigned char *awake_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_awake_dur \ - (unsigned char awake_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_dursample \ - (unsigned char *dursample); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_dursample \ - (unsigned char dursample); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_en_ch \ - (unsigned char channel, unsigned char *data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_en_ch \ - (unsigned char channel, unsigned char data); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermark_enable \ - (unsigned char *fifo_wn_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermark_enable \ - (unsigned char fifo_wn_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_reset_int \ - (unsigned char reset_int); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_reset \ - (unsigned char offset_reset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_status \ - (unsigned char *latch_status); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_status \ - (unsigned char latch_status); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_int \ - (unsigned char *latch_int); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_int \ - (unsigned char latch_int); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_hy \ - (unsigned char channel, unsigned char *high_hy); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_hy \ - (unsigned char channel, unsigned char high_hy); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_th \ - (unsigned char channel, unsigned char *high_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_th \ - (unsigned char channel, unsigned char high_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_en_ch \ - (unsigned char channel, unsigned char *high_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_en_ch \ - (unsigned char channel, unsigned char high_en); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_dur_ch \ - (unsigned char channel, unsigned char *high_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_dur_ch \ - (unsigned char channel, unsigned char high_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_th \ - (unsigned char *offset_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_th \ - (unsigned char offset_th); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_dur \ - (unsigned char *offset_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_dur \ - (unsigned char offset_dur); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_en_ch \ - (unsigned char channel, unsigned char *slow_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_en_ch \ - (unsigned char channel, unsigned char slow_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* - -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_wl \ - (unsigned char channel, unsigned char *offset_wl); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_wl \ - (unsigned char channel, unsigned char offset_wl); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en \ - (unsigned char fast_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fast_offset_en_ch \ - (unsigned char *fast_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en_ch \ - (unsigned char channel, unsigned char fast_offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_enable_fast_offset(void); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_remain \ - (unsigned char *nvm_remain); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_load \ - (unsigned char nvm_load); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_rdy \ - (unsigned char *nvm_rdy); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_trig \ - (unsigned char prog_trig); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_prog_mode \ - (unsigned char *prog_mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_mode \ - (unsigned char prog_mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_i2c_wdt \ - (unsigned char i2c_wdt, unsigned char *prog_mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_i2c_wdt \ - (unsigned char i2c_wdt, unsigned char prog_mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_spi3(unsigned char *spi3); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_spi3(unsigned char spi3); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_tag(unsigned char *tag); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_tag(unsigned char tag); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermarklevel \ - (unsigned char *water_mark_level); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermarklevel \ - (unsigned char water_mark_level); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_mode \ - (unsigned char *mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_mode(unsigned char mode); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_data_sel \ - (unsigned char *data_sel); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_data_sel \ - (unsigned char data_sel); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset \ - (unsigned char axis, BMG160_S16 *offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset \ - (unsigned char axis, BMG160_S16 offset); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_gp \ - (unsigned char param, unsigned char *value); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_gp \ - (unsigned char param, unsigned char value); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_framecount \ - (unsigned char *fifo_framecount); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_overrun \ - (unsigned char *fifo_overrun); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_fifo \ - (unsigned char *int_fifo); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_fifo \ - (unsigned char *int_fifo); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_fifo \ - (unsigned char fifo_int2); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_fifo \ - (unsigned char fifo_int1); - -/**************************************************************************** -* Description: *//**\brief -* -* -* -* -* \param -* -* -* \return -* -* -****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_mode(unsigned char *Mode); - -/***************************************************************************** - * Description: *//**\brief - * - * - * - * - * \param - * - * - * \return - * - * - ****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_mode(unsigned char Mode); - -/***************************************************************************** - * Description: *//**\brief - * - * - * - * - * \param - * - * - * \return - * - * - ****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_selftest(unsigned char *result); - -/***************************************************************************** -* Description: *//**\brief This API is used to get data auto sleep duration -* -* -* -* -* \param unsigned char *duration : Address of auto sleep duration -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_autosleepdur(unsigned char *duration); - -/***************************************************************************** -* Description: *//**\brief This API is used to set duration -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* unsigned char bandwidth: -* Value to be written passed as a parameter -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_autosleepdur(unsigned char duration, \ - unsigned char bandwith); - -/***************************************************************************** -* Description: *//**\brief This API is used to get data sleep duration -* -* -* -* -* \param unsigned char *duration : Address of sleep duration -* Pointer to a variable passed as a parameter -* -* -* -* \return -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_sleepdur(unsigned char *duration); - -/***************************************************************************** -* Description: *//**\brief This API is used to set duration -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_sleepdur(unsigned char duration); - -/***************************************************************************** -* Description: *//**\brief This API is used to set auto offset -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_set_auto_offset_en(unsigned char offset_en); - -/***************************************************************************** -* Description: *//**\brief This API is used to get auto offset -* -* -* -* -* \param unsigned char duration: -* Value to be written passed as a parameter -* -* -* -* \return communication results -* -* -*****************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - *****************************************************************************/ -BMG160_RETURN_FUNCTION_TYPE bmg160_get_auto_offset_en( \ - unsigned char *offset_en); - -#endif +/* + ******************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + ********************************************************************/ +/* Date: 2010/05/31 + * Revision: 1.0 + * Date: 2011/03/15 + * Revision: 1.1 + * Date: 2011/06/27 + * Revision: 1.2 + * Date: 2013/02/19 + * Revision: 1.3 + * Date: 06/05/2013 + * Revision: 1.4 + */ + +/******************************************************************* + * Copyright (C) 2007 Bosch Sensortec GmbH + * + * bmg160.h + * + * Usage: This header file which includes all function declaration + * + ********************************************************************/ +/*******************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. + * They may only be used within the parameters of the respective valid + * product data sheet. Bosch Sensortec products are provided with the + * express understanding that there is no warranty of fitness for a + * particular purpose.They are not fit for use in life-sustaining, + * safety or security sensitive systems or any system or device + * that may lead to bodily harm or property damage if the system + * or device malfunctions. In addition,Bosch Sensortec products are + * not fit for use in products which interact with motor vehicle systems. + * The resale and or use of products are at the purchasers own risk and + * his own responsibility. The examination of fitness for the intended use + * is the sole responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party + * claims, including any claims for incidental, or consequential damages, + * arising from any product use not covered by the parameters of + * the respective valid product data sheet or not approved by + * Bosch Sensortec and reimburse Bosch Sensortec for all costs in + * connection with such claims. + * + * The purchaser must monitor the market for the purchased products, + * particularly with regard to product safety and inform Bosch Sensortec + * without delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). + * Samples may vary from the valid technical specifications of the product + * series. They are therefore not intended or fit for resale to third + * parties or for use in end products. Their sole purpose is internal + * client testing. The testing of an engineering sample may in no way + * replace the testing of a product series. Bosch Sensortec assumes + * no liability for the use of engineering samples. + * By accepting the engineering samples, the Purchaser agrees to indemnify + * Bosch Sensortec from all claims arising from the use of engineering + * samples. + * + * Special: + * This software module (hereinafter called "Software") and any information + * on application-sheets (hereinafter called "Information") is provided + * free of charge for the sole purpose to support your application work. + * The Software and Information is subject to the following + * terms and conditions: + * + * The Software is specifically designed for the exclusive use for + * Bosch Sensortec products by personnel who have special experience + * and training. Do not use this Software if you do not have the + * proper experience or training. + * + * This Software package is provided `` as is `` and without any expressed + * or implied warranties,including without limitation, the implied warranties + * of merchantability and fitness for a particular purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability + * for the functional impairment + * of this Software in terms of fitness, performance and safety. + * Bosch Sensortec and their representatives and agents shall not be liable + * for any direct or indirect damages or injury, except as + * otherwise stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. + * Bosch Sensortec assumes no responsibility for the consequences of use + * of such Information nor for any infringement of patents or + * other rights of third parties which may result from its use. + * No license is granted by implication or otherwise under any patent or + * patent rights of Bosch. Specifications mentioned in the Information are + * subject to change without notice. + * + * It is not allowed to deliver the source code of the Software + * to any third party without permission of + * Bosch Sensortec. + */ +/*****************************************************************************/ +/*! \file BMG160.h + \brief Header for BMG160 API */ +/* user defined code to be added here ... */ +#ifndef __BMG160_H__ +#define __BMG160_H__ + +#ifdef __linux__ +#define BMG160_U16 unsigned short /* 16 bit achieved with short */ +#define BMG160_S16 signed short +#define BMG160_S32 signed int /* 32 bit achieved with int */ +#else +#include /*needed to test integer limits */ + +/* find correct data type for signed/unsigned 16 bit variables \ + by checking max of unsigned variant */ +#if USHRT_MAX == 0xFFFF +/* 16 bit achieved with short */ + #define BMG160_U16 unsigned short + #define BMG160_S16 signed short +#elif UINT_MAX == 0xFFFF +/* 16 bit achieved with int */ + #define BMG160_U16 unsigned int + #define BMG160_S16 signed int +#else + #error BMG160_U16 and BMG160_S16 could not be + #error defined automatically, please do so manually +#endif + +/* find correct data type for signed 32 bit variables */ +#if INT_MAX == 0x7FFFFFFF +/* 32 bit achieved with int */ + #define BMG160_S32 signed int +#elif LONG_MAX == 0x7FFFFFFF +/* 32 bit achieved with long int */ + #define BMG160_S32 signed long int +#else + #error BMG160_S32 could not be + #error defined automatically, please do so manually +#endif +#endif + +/**\brief defines the calling parameter types of the BMG160_WR_FUNCTION */ +#define BMG160_BUS_WR_RETURN_TYPE char + +/**\brief links the order of parameters defined in + BMG160_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BMG160_BUS_WR_PARAM_TYPES unsigned char, unsigned char, \ + unsigned char *, unsigned char + +/**\brief links the order of parameters defined in + BMG160_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BMG160_BUS_WR_PARAM_ORDER(device_addr, register_addr, \ + register_data, wr_len) + +/* never change this line */ +#define BMG160_BUS_WRITE_FUNC(device_addr, register_addr, \ + register_data, wr_len) bus_write(device_addr, register_addr, \ + register_data, wr_len) +/**\brief defines the return parameter type of the BMG160_RD_FUNCTION + */ +#define BMG160_BUS_RD_RETURN_TYPE char +/**\brief defines the calling parameter types of the BMG160_RD_FUNCTION + */ +#define BMG160_BUS_RD_PARAM_TYPES unsigned char, unsigned char, \ + unsigned char *, unsigned char +/**\brief links the order of parameters defined in \ + BMG160_BUS_RD_PARAM_TYPE to function calls used inside the API + */ +#define BMG160_BUS_RD_PARAM_ORDER device_addr, register_addr, \ + register_data +/* never change this line */ +#define BMG160_BUS_READ_FUNC(device_addr, register_addr, \ + register_data, rd_len) bus_read(device_addr, register_addr, \ + register_data, rd_len) +/**\brief defines the return parameter type of the BMG160_RD_FUNCTION + */ +#define BMG160_BURST_RD_RETURN_TYPE char +/**\brief defines the calling parameter types of the BMG160_RD_FUNCTION + */ +#define BMG160_BURST_RD_PARAM_TYPES unsigned char, \ + unsigned char, unsigned char *, signed int +/**\brief links the order of parameters defined in \ + BMG160_BURST_RD_PARAM_TYPE to function calls used inside the API + */ +#define BMG160_BURST_RD_PARAM_ORDER device_addr, register_addr, \ + register_data +/* never change this line */ +#define BMG160_BURST_READ_FUNC(device_addr, register_addr, \ + register_data, rd_len) burst_read(device_addr, \ + register_addr, register_data, rd_len) +/**\brief defines the return parameter type of the BMG160_DELAY_FUNCTION + */ +#define BMG160_DELAY_RETURN_TYPE void +/* never change this line */ +#define BMG160_DELAY_FUNC(delay_in_msec) \ + delay_func(delay_in_msec) +#define BMG160_RETURN_FUNCTION_TYPE int +/**< This refers BMG160 return type as char */ + +/* On the LPC54102 sensor board, the gyro on BMI055 has I2C address 0x69. + * The gyro sensor BMI160 on the LPC54102 has I2C address 0x68 but it's not + * installed on the board. + */ +#define BMG160_I2C_ADDR1 0x68 +#define BMG160_I2C_ADDR2 0x69 // I2C 0x69 is the BMI055 gyro sensor + +#define BMG160_I2C_ADDR (BMG160_I2C_ADDR2) + + + +/*Define of registers*/ + +/* Hard Wired */ +#define BMG160_CHIP_ID_ADDR 0x00 +/**
> bitname ## __POS) + +/* Set bit slice */ +#define BMG160_SET_BITSLICE(regvar, bitname, val) \ + ((regvar & ~bitname ## __MSK) | ((val << bitname ## __POS) & bitname ## __MSK)) +/* Constants */ + +#define BMG160_NULL 0 +/**< constant declaration of NULL */ +#define BMG160_DISABLE 0 +/**< It refers BMG160 disable */ +#define BMG160_ENABLE 1 +/**< It refers BMG160 enable */ +#define BMG160_OFF 0 +/**< It refers BMG160 OFF state */ +#define BMG160_ON 1 +/**< It refers BMG160 ON state */ + +#define BMG160_TURN1 0 +/**< It refers BMG160 TURN1 */ +#define BMG160_TURN2 1 +/**< It refers BMG160 TURN2 */ + +#define BMG160_INT1 0 +/**< It refers BMG160 INT1 */ +#define BMG160_INT2 1 +/**< It refers BMG160 INT2 */ + +#define BMG160_SLOW_OFFSET 0 +/**< It refers BMG160 Slow Offset */ +#define BMG160_AUTO_OFFSET 1 +/**< It refers BMG160 Auto Offset */ +#define BMG160_FAST_OFFSET 2 +/**< It refers BMG160 Fast Offset */ +#define BMG160_S_TAP 0 +/**< It refers BMG160 Single Tap */ +#define BMG160_D_TAP 1 +/**< It refers BMG160 Double Tap */ +#define BMG160_INT1_DATA 0 +/**< It refers BMG160 Int1 Data */ +#define BMG160_INT2_DATA 1 +/**< It refers BMG160 Int2 Data */ +#define BMG160_TAP_UNFILT_DATA 0 +/**< It refers BMG160 Tap unfilt data */ +#define BMG160_HIGH_UNFILT_DATA 1 +/**< It refers BMG160 High unfilt data */ +#define BMG160_CONST_UNFILT_DATA 2 +/**< It refers BMG160 Const unfilt data */ +#define BMG160_ANY_UNFILT_DATA 3 +/**< It refers BMG160 Any unfilt data */ +#define BMG160_SHAKE_UNFILT_DATA 4 +/**< It refers BMG160 Shake unfilt data */ +#define BMG160_SHAKE_TH 0 +/**< It refers BMG160 Shake Threshold */ +#define BMG160_SHAKE_TH2 1 +/**< It refers BMG160 Shake Threshold2 */ +#define BMG160_AUTO_OFFSET_WL 0 +/**< It refers BMG160 Auto Offset word length */ +#define BMG160_FAST_OFFSET_WL 1 +/**< It refers BMG160 Fast Offset word length */ +#define BMG160_I2C_WDT_EN 0 +/**< It refers BMG160 I2C WDT En */ +#define BMG160_I2C_WDT_SEL 1 +/**< It refers BMG160 I2C WDT Sel */ +#define BMG160_EXT_MODE 0 +/**< It refers BMG160 Ext Mode */ +#define BMG160_EXT_PAGE 1 +/**< It refers BMG160 Ext page */ +#define BMG160_START_ADDR 0 +/**< It refers BMG160 Start Address */ +#define BMG160_STOP_ADDR 1 +/**< It refers BMG160 Stop Address */ +#define BMG160_SLOW_CMD 0 +/**< It refers BMG160 Slow Command */ +#define BMG160_FAST_CMD 1 +/**< It refers BMG160 Fast Command */ +#define BMG160_TRIM_VRA 0 +/**< It refers BMG160 Trim VRA */ +#define BMG160_TRIM_VRD 1 +/**< It refers BMG160 Trim VRD */ +#define BMG160_LOGBIT_EM 0 +/**< It refers BMG160 LogBit Em */ +#define BMG160_LOGBIT_VM 1 +/**< It refers BMG160 LogBit VM */ +#define BMG160_GP0 0 +/**< It refers BMG160 GP0 */ +#define BMG160_GP1 1 +/**< It refers BMG160 GP1*/ +#define BMG160_LOW_SPEED 0 +/**< It refers BMG160 Low Speed Oscillator */ +#define BMG160_HIGH_SPEED 1 +/**< It refers BMG160 High Speed Oscillator */ +#define BMG160_DRIVE_OFFSET_P 0 +/**< It refers BMG160 Drive Offset P */ +#define BMG160_DRIVE_OFFSET_N 1 +/**< It refers BMG160 Drive Offset N */ +#define BMG160_TEST_MODE_EN 0 +/**< It refers BMG160 Test Mode Enable */ +#define BMG160_TEST_MODE_REG 1 +/**< It refers BMG160 Test Mode reg */ +#define BMG160_IBIAS_DRIVE_TRIM 0 +/**< It refers BMG160 IBIAS Drive Trim */ +#define BMG160_IBIAS_RATE_TRIM 1 +/**< It refers BMG160 IBIAS Rate Trim */ +#define BMG160_BAA_MODE 0 +/**< It refers BMG160 BAA Mode Trim */ +#define BMG160_BMA_MODE 1 +/**< It refers BMG160 BMA Mode Trim */ +#define BMG160_PI_KP 0 +/**< It refers BMG160 PI KP */ +#define BMG160_PI_KI 1 +/**< It refers BMG160 PI KI */ + +#define C_BMG160_SUCCESS 0 +/**< It refers BMG160 operation is success */ +#define C_BMG160_FAILURE 1 +/**< It refers BMG160 operation is Failure */ + +#define BMG160_SPI_RD_MASK 0x80 +/**< Read mask **/ +#define BMG160_READ_SET 0x01 +/**< Setting for rading data **/ + +#define BMG160_SHIFT_1_POSITION 1 +/**< Shift bit by 1 Position **/ +#define BMG160_SHIFT_2_POSITION 2 +/**< Shift bit by 2 Position **/ +#define BMG160_SHIFT_3_POSITION 3 +/**< Shift bit by 3 Position **/ +#define BMG160_SHIFT_4_POSITION 4 +/**< Shift bit by 4 Position **/ +#define BMG160_SHIFT_5_POSITION 5 +/**< Shift bit by 5 Position **/ +#define BMG160_SHIFT_6_POSITION 6 +/**< Shift bit by 6 Position **/ +#define BMG160_SHIFT_7_POSITION 7 +/**< Shift bit by 7 Position **/ +#define BMG160_SHIFT_8_POSITION 8 +/**< Shift bit by 8 Position **/ +#define BMG160_SHIFT_12_POSITION 12 +/**< Shift bit by 12 Position **/ + +#define C_BMG160_Null_U8X 0 +#define C_BMG160_Zero_U8X 0 +#define C_BMG160_One_U8X 1 +#define C_BMG160_Two_U8X 2 +#define C_BMG160_Three_U8X 3 +#define C_BMG160_Four_U8X 4 +#define C_BMG160_Five_U8X 5 +#define C_BMG160_Six_U8X 6 +#define C_BMG160_Seven_U8X 7 +#define C_BMG160_Eight_U8X 8 +#define C_BMG160_Nine_U8X 9 +#define C_BMG160_Ten_U8X 10 +#define C_BMG160_Eleven_U8X 11 +#define C_BMG160_Twelve_U8X 12 +#define C_BMG160_Thirteen_U8X 13 +#define C_BMG160_Fifteen_U8X 15 +#define C_BMG160_Sixteen_U8X 16 +#define C_BMG160_TwentyTwo_U8X 22 +#define C_BMG160_TwentyThree_U8X 23 +#define C_BMG160_TwentyFour_U8X 24 +#define C_BMG160_TwentyFive_U8X 25 +#define C_BMG160_ThirtyTwo_U8X 32 +#define C_BMG160_Hundred_U8X 100 +#define C_BMG160_OneTwentySeven_U8X 127 +#define C_BMG160_OneTwentyEight_U8X 128 +#define C_BMG160_TwoFiftyFive_U8X 255 +#define C_BMG160_TwoFiftySix_U16X 256 + +#define E_BMG160_NULL_PTR (char) (-127) +#define E_BMG160_COMM_RES (char) (-1) +#define E_BMG160_OUT_OF_RANGE (signed char) (-2) + +#define C_BMG160_No_Filter_U8X 0 +#define C_BMG160_BW_230Hz_U8X 1 +#define C_BMG160_BW_116Hz_U8X 2 +#define C_BMG160_BW_47Hz_U8X 3 +#define C_BMG160_BW_23Hz_U8X 4 +#define C_BMG160_BW_12Hz_U8X 5 +#define C_BMG160_BW_64Hz_U8X 6 +#define C_BMG160_BW_32Hz_U8X 7 + +#define C_BMG160_No_AutoSleepDur_U8X 0 +#define C_BMG160_4ms_AutoSleepDur_U8X 1 +#define C_BMG160_5ms_AutoSleepDur_U8X 2 +#define C_BMG160_8ms_AutoSleepDur_U8X 3 +#define C_BMG160_10ms_AutoSleepDur_U8X 4 +#define C_BMG160_15ms_AutoSleepDur_U8X 5 +#define C_BMG160_20ms_AutoSleepDur_U8X 6 +#define C_BMG160_40ms_AutoSleepDur_U8X 7 + +#define BMG160_WR_FUNC_PTR char (*bus_write) \ + (unsigned char, unsigned char, unsigned char *, unsigned char) +#define BMG160_RD_FUNC_PTR char (*bus_read) \ + (unsigned char, unsigned char, unsigned char *, unsigned char) +#define BMG160_BRD_FUNC_PTR char (*burst_read) \ + (unsigned char, unsigned char, unsigned char *, BMG160_S32) +#define BMG160_MDELAY_DATA_TYPE unsigned int + +/*user defined Structures*/ +struct bmg160_data_t { + BMG160_S16 datax; + BMG160_S16 datay; + BMG160_S16 dataz; + char intstatus[5]; +}; + +struct bmg160_offset_t { + BMG160_U16 datax; + BMG160_U16 datay; + BMG160_U16 dataz; +}; + +struct bmg160_t { + unsigned char chip_id; + unsigned char dev_addr; + BMG160_BRD_FUNC_PTR; + BMG160_WR_FUNC_PTR; + BMG160_RD_FUNC_PTR; + void (*delay_msec)(BMG160_MDELAY_DATA_TYPE); +}; + +/*************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* +* +* \return +* +* +***************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_init(struct bmg160_t *p_bmg160); + +/*************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* +* +* \return +* +* +***************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataX(BMG160_S16 *data_x); + +/**************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataY(BMG160_S16 *data_y); + +/*************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +***************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataZ(BMG160_S16 *data_z); + +/************************************************************ + * Description: *//**\brief + * + * + * + * + * \param + * + * + * + * \return + * + * + *************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ***************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZ(struct bmg160_data_t *data); + +/*************************************************************************** + * Description: *//**\brief + * + * + * + * + * \param + * + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ********************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_dataXYZI(struct bmg160_data_t *data); + +/******************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +********************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_Temperature(unsigned char *temperature); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_FIFO_data_reg \ + (unsigned char *FIFO_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_read_register(unsigned char addr, \ + unsigned char *data, unsigned char len); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_burst_read(unsigned char addr, \ + unsigned char *data, BMG160_S32 len); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_write_register(unsigned char addr, \ + unsigned char *data, unsigned char len); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_0 \ + (unsigned char *status0_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_1 \ + (unsigned char *status1_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_2 \ + (unsigned char *status2_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_interrupt_status_reg_3 \ + (unsigned char *status3_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ + +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifostatus_reg \ + (unsigned char *fifo_status); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_range_reg \ + (unsigned char *range); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_range_reg \ + (unsigned char range); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_res \ + (unsigned char *high_res); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_res \ + (unsigned char high_res); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_bw(unsigned char *bandwidth); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_bw(unsigned char bandwidth); + +/**************************************************************************** +* Description: *//**\brief +* +* + +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_pmu_ext_tri_sel \ + (unsigned char *pwu_ext_tri_sel); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_pmu_ext_tri_sel \ + (unsigned char pwu_ext_tri_sel); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_bw \ + (unsigned char *high_bw); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_bw \ + (unsigned char high_bw); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_shadow_dis \ + (unsigned char *shadow_dis); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_shadow_dis \ + (unsigned char shadow_dis); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_soft_reset(void); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_data_enable(unsigned char *data_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_data_en(unsigned char data_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_enable(unsigned char *fifo_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_enable(unsigned char fifo_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_enable \ + (unsigned char mode, unsigned char *offset_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_enable \ + (unsigned char mode, unsigned char offset_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_od \ + (unsigned char param, unsigned char *int_od); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_od \ + (unsigned char param, unsigned char int_od); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_lvl \ + (unsigned char param, unsigned char *int_lvl); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_lvl \ + (unsigned char param, unsigned char int_lvl); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_high \ + (unsigned char *int1_high); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_high \ + (unsigned char int1_high); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_any \ + (unsigned char *int1_any); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_any \ + (unsigned char int1_any); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_data \ + (unsigned char axis, unsigned char *int_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_data \ + (unsigned char axis, unsigned char int_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_offset \ + (unsigned char axis, unsigned char *int2_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_offset \ + (unsigned char axis, unsigned char int2_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_offset \ + (unsigned char axis, unsigned char *int1_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_offset \ + (unsigned char axis, unsigned char int1_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int_fifo(unsigned char *int_fifo); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int_fifo \ + (unsigned char axis, unsigned char int_fifo); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_high \ + (unsigned char *int2_high); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_high \ + (unsigned char int2_high); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_any \ + (unsigned char *int2_any); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_any \ + (unsigned char int2_any); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_unfilt \ + (unsigned char param, unsigned char *offset_unfilt); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_unfilt \ + (unsigned char param, unsigned char offset_unfilt); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_unfilt_data \ + (unsigned char param, unsigned char *unfilt_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_unfilt_data \ + (unsigned char param, unsigned char unfilt_data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_th \ + (unsigned char *any_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_th \ + (unsigned char any_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_awake_dur \ + (unsigned char *awake_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_awake_dur \ + (unsigned char awake_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_dursample \ + (unsigned char *dursample); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_dursample \ + (unsigned char dursample); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_any_en_ch \ + (unsigned char channel, unsigned char *data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_any_en_ch \ + (unsigned char channel, unsigned char data); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermark_enable \ + (unsigned char *fifo_wn_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermark_enable \ + (unsigned char fifo_wn_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_reset_int \ + (unsigned char reset_int); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_reset \ + (unsigned char offset_reset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_status \ + (unsigned char *latch_status); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_status \ + (unsigned char latch_status); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_latch_int \ + (unsigned char *latch_int); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_latch_int \ + (unsigned char latch_int); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_hy \ + (unsigned char channel, unsigned char *high_hy); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_hy \ + (unsigned char channel, unsigned char high_hy); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_th \ + (unsigned char channel, unsigned char *high_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_th \ + (unsigned char channel, unsigned char high_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_en_ch \ + (unsigned char channel, unsigned char *high_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_en_ch \ + (unsigned char channel, unsigned char high_en); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_high_dur_ch \ + (unsigned char channel, unsigned char *high_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_high_dur_ch \ + (unsigned char channel, unsigned char high_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_th \ + (unsigned char *offset_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_th \ + (unsigned char offset_th); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_dur \ + (unsigned char *offset_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_dur \ + (unsigned char offset_dur); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_slow_offset_en_ch \ + (unsigned char channel, unsigned char *slow_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_slow_offset_en_ch \ + (unsigned char channel, unsigned char slow_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* + +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset_wl \ + (unsigned char channel, unsigned char *offset_wl); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset_wl \ + (unsigned char channel, unsigned char offset_wl); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en \ + (unsigned char fast_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fast_offset_en_ch \ + (unsigned char *fast_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fast_offset_en_ch \ + (unsigned char channel, unsigned char fast_offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_enable_fast_offset(void); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_remain \ + (unsigned char *nvm_remain); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_load \ + (unsigned char nvm_load); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_rdy \ + (unsigned char *nvm_rdy); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_trig \ + (unsigned char prog_trig); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_nvm_prog_mode \ + (unsigned char *prog_mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_nvm_prog_mode \ + (unsigned char prog_mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_i2c_wdt \ + (unsigned char i2c_wdt, unsigned char *prog_mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_i2c_wdt \ + (unsigned char i2c_wdt, unsigned char prog_mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_spi3(unsigned char *spi3); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_spi3(unsigned char spi3); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_tag(unsigned char *tag); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_tag(unsigned char tag); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_watermarklevel \ + (unsigned char *water_mark_level); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_watermarklevel \ + (unsigned char water_mark_level); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_mode \ + (unsigned char *mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_mode(unsigned char mode); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_data_sel \ + (unsigned char *data_sel); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_fifo_data_sel \ + (unsigned char data_sel); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_offset \ + (unsigned char axis, BMG160_S16 *offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_offset \ + (unsigned char axis, BMG160_S16 offset); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_gp \ + (unsigned char param, unsigned char *value); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_gp \ + (unsigned char param, unsigned char value); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_framecount \ + (unsigned char *fifo_framecount); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_fifo_overrun \ + (unsigned char *fifo_overrun); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int2_fifo \ + (unsigned char *int_fifo); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_int1_fifo \ + (unsigned char *int_fifo); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int2_fifo \ + (unsigned char fifo_int2); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_int1_fifo \ + (unsigned char fifo_int1); + +/**************************************************************************** +* Description: *//**\brief +* +* +* +* +* \param +* +* +* \return +* +* +****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_mode(unsigned char *Mode); + +/***************************************************************************** + * Description: *//**\brief + * + * + * + * + * \param + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_mode(unsigned char Mode); + +/***************************************************************************** + * Description: *//**\brief + * + * + * + * + * \param + * + * + * \return + * + * + ****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_selftest(unsigned char *result); + +/***************************************************************************** +* Description: *//**\brief This API is used to get data auto sleep duration +* +* +* +* +* \param unsigned char *duration : Address of auto sleep duration +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_autosleepdur(unsigned char *duration); + +/***************************************************************************** +* Description: *//**\brief This API is used to set duration +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* unsigned char bandwidth: +* Value to be written passed as a parameter +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_autosleepdur(unsigned char duration, \ + unsigned char bandwith); + +/***************************************************************************** +* Description: *//**\brief This API is used to get data sleep duration +* +* +* +* +* \param unsigned char *duration : Address of sleep duration +* Pointer to a variable passed as a parameter +* +* +* +* \return +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_sleepdur(unsigned char *duration); + +/***************************************************************************** +* Description: *//**\brief This API is used to set duration +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_sleepdur(unsigned char duration); + +/***************************************************************************** +* Description: *//**\brief This API is used to set auto offset +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_set_auto_offset_en(unsigned char offset_en); + +/***************************************************************************** +* Description: *//**\brief This API is used to get auto offset +* +* +* +* +* \param unsigned char duration: +* Value to be written passed as a parameter +* +* +* +* \return communication results +* +* +*****************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + *****************************************************************************/ +BMG160_RETURN_FUNCTION_TYPE bmg160_get_auto_offset_en( \ + unsigned char *offset_en); + +#endif diff --git a/embedded/common/modules/sensor-drivers/bmm050.c b/embedded/common/modules/sensor-drivers/bmm050.c index 3c28a3c..c6e7a54 100644 --- a/embedded/common/modules/sensor-drivers/bmm050.c +++ b/embedded/common/modules/sensor-drivers/bmm050.c @@ -1,1827 +1,1844 @@ -/* - **************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - ****************************************************************************/ -/* Date: 2013/08/07 - * Revision: 1.1 - * - */ - -/***************************************************************************** - * Copyright (C) 2013 Bosch Sensortec GmbH - * - * bmm050.c - * - * Usage: Sensor Driver for BMM050 - * - ******************************************************************************/ -/*****************************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. They - * may only be used within the parameters of the respective valid product data - * sheet. Bosch Sensortec products are provided with the express understanding - * that there is no warranty of fitness for a particular purpose.They are not - * fit for use in life-sustaining, safety or security sensitive systems or any - * system or device that may lead to bodily harm or property damage if the - * system or device malfunctions. In addition, Bosch Sensortec products are not - * fit for use in products which interact with motor vehicle systems.The resale - * and or use of products are at the purchasers own risk and his own - * responsibility. The examination of fitness for the intended use is the sole - * responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party claims, - * including any claims for incidental, or consequential damages, arising from - * any product use not covered by the parameters of the respective valid product - * data sheet or not approved by Bosch Sensortec and reimburse Bosch - * Sensortec for all costs in connection with such claims. - * - * The purchaser must monitor the market for the purchased products, - * particularly with regard to product safety and inform Bosch Sensortec without - * delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary - * from the valid technical specifications of the product series. They are - * therefore not intended or fit for resale to third parties or for use in end - * products. Their sole purpose is internal client testing. The testing of an - * engineering sample may in no way replace the testing of a product series. - * Bosch Sensortec assumes no liability for the use of engineering samples. By - * accepting the engineering samples, the Purchaser agrees to indemnify Bosch - * Sensortec from all claims arising from the use of engineering samples. - * - * Special: - * This software module (hereinafter called "Software") and any information on - * application-sheets (hereinafter called "Information") is provided free of - * charge for the sole purpose to support your application work. The Software - * and Information is subject to the following terms and conditions: - * - * The Software is specifically designed for the exclusive use for Bosch - * Sensortec products by personnel who have special experience and training. - * Do not use this Software if you do not have the proper experience or - * training. - * - * This Software package is provided `` as is `` and without any expressed or - * implied warranties, including without limitation, the implied warranties of - * merchantability and fitness for a particular purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability for - * the functional impairment of this Software in terms of fitness, performance - * and safety. Bosch Sensortec and their representatives and agents shall not be - * liable for any direct or indirect damages or injury, except as otherwise - * stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. Bosch - * Sensortec assumes no responsibility for the consequences of use of such - * Information nor for any infringement of patents or other rights of third - * parties which may result from its use. No license is granted by implication - * or otherwise under any patent or patent rights of Bosch. Specifications - * mentioned in the Information are subject to change without notice. - * - * It is not allowed to deliver the source code of the Software to any third - * party without permission of Bosch Sensortec. - */ -/****************************************************************************/ -/*! \file - \brief */ - -#include "bmm050.h" -#include "sensorhub.h" -#include "common.h" -#include "mag_common.h" -#include "osp-sensors.h" -#include "sensacq_i2c.h" -#include "board.h" - -static struct bmm050 *p_bmm050; -static struct bmm050 bmm050; -#if 0 -static void mag_activate(bool enable) -{ - if (enable) { - bmm050_set_functional_state(BMM050_NORMAL_MODE); - /* Update the last set data rate */ - bmm050_set_datarate(BMM050_DR_25HZ); - /* Update repititions when activated */ - bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); - bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); - /* Enable Data ready interrupt */ - bmm050_set_mag_drdy_interrupt(enable, 1); - /* Read to clear any pending interrupt */ - Mag_ReadData(NULL); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(MAG_PINT_IRQn); - NVIC_ClearPendingIRQ(MAG_PINT_IRQn); - } - else { - bmm050_set_mag_drdy_interrupt(enable, 1); - bmm050_set_functional_state(BMM050_SLEEP_MODE); - NVIC_DisableIRQ(MAG_PINT_IRQn); - } -} -#endif - -void Mag_HardwareSetup(osp_bool_t enable) -{ - NVIC_SetPriority(MAG_PINT_IRQn, SENSOR_IRQ_PRIORITY); - NVIC_DisableIRQ(MAG_PINT_IRQn); - - /* MAG INT2 irq setup */ - Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT_PORT, MAG_INT_PIN); - Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); /* Configure INMUX block */ - Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH);/* edge sensitive and rising edge interrupt */ - Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH); - Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */ - Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */ - - Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT3_PORT, MAG_INT3_PIN); - -} - - -void Mag_Initialize(void) -{ - bmm050.bus_write = dev_i2c_write; - bmm050.bus_read = dev_i2c_read; - bmm050.delay_msec = dev_i2c_delay; - - D0_printf("MAG INIT 0\r\n"); - bmm050_init(&bmm050); - /* reset the mag */ - D0_printf("MAG INIT 1\r\n"); - dev_i2c_delay(10); - /* mag_setDelay(pSens, 50); */ - bmm050_set_datarate(BMM050_DR_25HZ); - dev_i2c_delay(10); - bmm050_set_mag_drdy_interrupt(true, 1); - bmm050_set_functional_state(BMM050_SLEEP_MODE); - - Mag_ReadData(NULL); - - - /* Note: The mag sensor is configured to SLEEP mode so in order to get sensor data you must set the OpMode to either normal (0x00) or forced mode (0x01) */ - -// mag_activate(true); -} - -void Mag_SetLowPowerMode(void) -{ - bmm050_set_functional_state(BMM050_SLEEP_MODE); -} - -void Mag_ConfigDataInt(osp_bool_t enable) -{ - /* Need to implement: */ - if (enable) { - bmm050_set_functional_state(BMM050_NORMAL_MODE); - /* Update the last set data rate */ - bmm050_set_datarate(BMM050_DR_25HZ); - /* Update repititions when activated */ - bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); - bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); - /* Enable Data ready interrupt */ - bmm050_set_mag_drdy_interrupt(enable, 1); - - /* Enable interrupt in the NVIC */ - NVIC_EnableIRQ(MAG_PINT_IRQn); - dev_i2c_delay(20); - } - else { - bmm050_set_mag_drdy_interrupt(enable, 1); - bmm050_set_functional_state(BMM050_SLEEP_MODE); - NVIC_DisableIRQ(MAG_PINT_IRQn); - } -} - -void Mag_ClearDataInt() -{ - /* Read to clear any pending interrupt */ - Mag_ReadData(NULL); -} - -void Mag_TriggerDataAcq(void) -{ - Mag_ReadData(NULL); - bmm050_set_mag_drdy_interrupt(true, 1); - bmm050_set_functional_state(BMM050_FORCED_MODE); -} - -void Mag_ReadData(MsgMagData *magData) -{ - struct bmm050_mdata mdata; - - bmm050_get_raw_xyz(&mdata); - if (magData) { - magData->X = mdata.datax; - magData->Y = mdata.datay; - magData->Z = mdata.dataz; - } -} -void MAG_IRQHandler(void) -{ - uint32_t currTime = GetCurrentTime(); -#if 0 - uint32_t currTime = g_Timer.GetCurrent(); - PhysicalSensor_t* pSens = g_phySensors[PHYS_MAG_ID]; - pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; - pSens->ts_lastSample = currTime; - - pSens->irq_pending++; - Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH); - ResMgr_IRQDone(); -#else - Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH); - SendDataReadyIndication(MAG_INPUT_SENSOR, currTime); -#endif -} - - -BMM050_RETURN_FUNCTION_TYPE bmm050_init(struct bmm050 *bmm050) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[2]; - p_bmm050 = bmm050; - - p_bmm050->dev_addr = BMM050_I2C_ADDRESS; - - /* set device from suspend into sleep mode */ - bmm050_set_powermode(BMM050_ON); - - /* Perform a software to reset all the registers except the trim registers. - * Soft reset only executes when device is in sleep mode. No execution in suspended mode - */ - bmm050_soft_reset(); - - /*Read CHIP_ID and REv. info */ - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_CHIP_ID, a_data_u8r, 1); - p_bmm050->company_id = a_data_u8r[0]; - D0_printf("Returned: 0x%x\r\n", (uint32_t)(a_data_u8r[0])); - /* Function to initialise trim values */ - bmm050_init_trim_registers(); - bmm050_set_presetmode(BMM050_PRESETMODE_REGULAR); - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_presetmode(unsigned char mode) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - switch (mode) { - case BMM050_PRESETMODE_LOWPOWER: - /* Set the data rate for Low Power mode */ - comres = bmm050_set_datarate(BMM050_LOWPOWER_DR); - /* Set the XY-repetitions number for Low Power mode */ - comres |= bmm050_set_repetitions_XY(BMM050_LOWPOWER_REPXY); - /* Set the Z-repetitions number for Low Power mode */ - comres |= bmm050_set_repetitions_Z(BMM050_LOWPOWER_REPZ); - break; - - case BMM050_PRESETMODE_REGULAR: - /* Set the data rate for Regular mode */ - comres = bmm050_set_datarate(BMM050_REGULAR_DR); - /* Set the XY-repetitions number for Regular mode */ - comres |= bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); - /* Set the Z-repetitions number for Regular mode */ - comres |= bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); - break; - - case BMM050_PRESETMODE_HIGHACCURACY: - /* Set the data rate for High Accuracy mode */ - comres = bmm050_set_datarate(BMM050_HIGHACCURACY_DR); - /* Set the XY-repetitions number for High Accuracy mode */ - comres |= bmm050_set_repetitions_XY(BMM050_HIGHACCURACY_REPXY); - /* Set the Z-repetitions number for High Accuracy mode */ - comres |= bmm050_set_repetitions_Z(BMM050_HIGHACCURACY_REPZ); - break; - - case BMM050_PRESETMODE_ENHANCED: - /* Set the data rate for Enhanced Accuracy mode */ - comres = bmm050_set_datarate(BMM050_ENHANCED_DR); - /* Set the XY-repetitions number for High Enhanced mode */ - comres |= bmm050_set_repetitions_XY(BMM050_ENHANCED_REPXY); - /* Set the Z-repetitions number for High Enhanced mode */ - comres |= bmm050_set_repetitions_Z(BMM050_ENHANCED_REPZ); - break; - - default: - comres = E_BMM050_OUT_OF_RANGE; - break; - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_functional_state \ - (unsigned char functional_state) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - switch (functional_state) { - case BMM050_NORMAL_MODE: - comres = bmm050_get_powermode(&v_data1_u8r); - if (v_data1_u8r == BMM050_OFF) { - comres |= bmm050_set_powermode(BMM050_ON); - p_bmm050->delay_msec( - BMM050_DELAY_SUSPEND_SLEEP); - } - { - comres |= p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_OPMODE, - BMM050_NORMAL_MODE); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - } - break; - - case BMM050_SUSPEND_MODE: - comres = bmm050_set_powermode(BMM050_OFF); - break; - - case BMM050_FORCED_MODE: - comres = bmm050_get_powermode(&v_data1_u8r); - if (v_data1_u8r == BMM050_OFF) { - comres = bmm050_set_powermode(BMM050_ON); - p_bmm050->delay_msec( - BMM050_DELAY_SUSPEND_SLEEP); - } - comres |= p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_OPMODE, BMM050_ON); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - break; - - case BMM050_SLEEP_MODE: - bmm050_get_powermode(&v_data1_u8r); - if (v_data1_u8r == BMM050_OFF) { - comres = bmm050_set_powermode(BMM050_ON); - p_bmm050->delay_msec( - BMM050_DELAY_SUSPEND_SLEEP); - } - comres |= p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_OPMODE, - BMM050_SLEEP_MODE); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data1_u8r, 1); - break; - - default: - comres = E_BMM050_OUT_OF_RANGE; - break; - } - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_functional_state \ - (unsigned char *functional_state) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_OPMODE__REG, - &v_data_u8r, 1); - *functional_state = BMM050_GET_BITSLICE( - v_data_u8r, BMM050_CNTL_OPMODE); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ(struct bmm050_mdata *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DATAX_LSB, a_data_u8r, 8); - - /* Reading data for X axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for Y axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; - } - return comres; -} - -/* In this function X and Y axis is remapped, - * this API is only applicable for BMX055*/ -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ \ - (struct bmm050_remapped_mdata *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ - BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); - - /* Reading data for Y axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for X axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_s32 \ - (struct bmm050_mdata_s32 *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DATAX_LSB, a_data_u8r, 8); - - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_DATAX_LSB_VALUEX); - - raw_dataXYZ.raw_dataX = (BMM050_S16) ( - (((BMM050_U16) a_data_u8r[1]) << BMM050_DATAX_LSB_VALUEX__LEN) | - a_data_u8r[0]); - if (a_data_u8r[1] & 0x80) { - raw_dataXYZ.raw_dataX |= 0xe000; - } - - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_DATAY_LSB_VALUEY); - - raw_dataXYZ.raw_dataY = (BMM050_S16) ( - (((BMM050_U16) a_data_u8r[3]) << BMM050_DATAY_LSB_VALUEY__LEN) | - a_data_u8r[2]); - if (a_data_u8r[3] & 0x80) { - raw_dataXYZ.raw_dataY |= 0xe000; - } - - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - - raw_dataXYZ.raw_dataZ = (BMM050_S16) ( - (((BMM050_U16) a_data_u8r[5]) << BMM050_DATAZ_LSB_VALUEZ__LEN) | - a_data_u8r[4]); - if (a_data_u8r[5] & 0x80) { - raw_dataXYZ.raw_dataZ |= 0x8000; - } - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - - raw_dataXYZ.raw_dataR = (BMM050_S16) ((((BMM050_U16) a_data_u8r[7]) << BMM050_R_LSB_VALUE__LEN) | - a_data_u8r[6]); - if (a_data_u8r[7] & 0x80) { - raw_dataXYZ.raw_dataR |= 0xc000; - } - -#if 1 - mdata->datax = raw_dataXYZ.raw_dataX; - mdata->datay = raw_dataXYZ.raw_dataY; - mdata->dataz = raw_dataXYZ.raw_dataZ; - -#else - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); -#endif -#if 0 - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DATAX_LSB, a_data_u8r, 8); - - /* Reading data for X axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for Y axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; -#endif - } - return comres; -} - -/* In this function X and Y axis is remapped, - * this API is only applicable for BMX055*/ -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_s32 \ - (struct bmm050_remapped_mdata_s32 *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ - BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); - - /* Reading data for Y axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for X axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; - } - return comres; -} - -#ifdef ENABLE_FLOAT -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_float \ - (struct bmm050_mdata_float *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DATAX_LSB, a_data_u8r, 8); - - /* Reading data for X axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for Y axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X_float(raw_dataXYZ.raw_dataX, - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y_float(raw_dataXYZ.raw_dataY, - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z_float(raw_dataXYZ.raw_dataZ, - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; - } - return comres; -} - -#endif - -/* In this function X and Y axis is remapped, - * this API is only applicable for BMX055*/ -#ifdef ENABLE_FLOAT -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_float \ - (struct bmm050_remapped_mdata_float *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - - unsigned char a_data_u8r[8]; - - struct { - BMM050_S16 raw_dataX; - BMM050_S16 raw_dataY; - BMM050_S16 raw_dataZ; - BMM050_U16 raw_dataR; - } raw_dataXYZ; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ - BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); - - /* Reading data for Y axis */ - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); - raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); - - /* Reading data for X axis */ - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); - raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) << - SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); - raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; - - /* Reading data for Z axis */ - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) << - SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); - - /* Reading data for Resistance*/ - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - - /* Compensation for X axis */ - mdata->datax = bmm050_compensate_X_float(raw_dataXYZ.raw_dataX, \ - raw_dataXYZ.raw_dataR); - - /* Compensation for Y axis */ - mdata->datay = bmm050_compensate_Y_float(raw_dataXYZ.raw_dataY, \ - raw_dataXYZ.raw_dataR); - - /* Compensation for Z axis */ - mdata->dataz = bmm050_compensate_Z_float(raw_dataXYZ.raw_dataZ, \ - raw_dataXYZ.raw_dataR); - - /* Output raw resistance value */ - mdata->resistance = raw_dataXYZ.raw_dataR; - } - return comres; -} - -#endif - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_register(unsigned char addr, \ - unsigned char *data, unsigned char len) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres += p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ - addr, data, len); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_write_register(unsigned char addr, \ - unsigned char *data, unsigned char len) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, \ - addr, data, len); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_selftest(unsigned char selftest) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, BMM050_CNTL_S_TEST__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, BMM050_CNTL_S_TEST, selftest); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, BMM050_CNTL_S_TEST__REG, - &v_data1_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_self_test_XYZ \ - (unsigned char *self_testxyz) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[5], v_result_u8r = 0x00; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, BMM050_DATAX_LSB_TESTX__REG, - a_data_u8r, 5); - - v_result_u8r = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_TESTZ); - - v_result_u8r = (v_result_u8r << 1); - v_result_u8r = (v_result_u8r | BMM050_GET_BITSLICE( - a_data_u8r[2], BMM050_DATAY_LSB_TESTY)); - - v_result_u8r = (v_result_u8r << 1); - v_result_u8r = (v_result_u8r | BMM050_GET_BITSLICE( - a_data_u8r[0], BMM050_DATAX_LSB_TESTX)); - - *self_testxyz = v_result_u8r; - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_spi3(unsigned char value) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_POWER_CNTL_SPI3_EN__REG, &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_POWER_CNTL_SPI3_EN, value); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, - BMM050_POWER_CNTL_SPI3_EN__REG, &v_data1_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_datarate(unsigned char data_rate) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_DR__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_CNTL_DR, data_rate); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_DR__REG, - &v_data1_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_datarate(unsigned char *data_rate) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_DR__REG, - &v_data_u8r, 1); - *data_rate = BMM050_GET_BITSLICE(v_data_u8r, - BMM050_CNTL_DR); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_perform_advanced_selftest \ - (BMM050_S16 *diff_z) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - BMM050_S16 result_positive, result_negative; - struct bmm050_mdata mdata; - - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - /* set sleep mode to prepare for forced measurement. - * If sensor is off, this will turn it on - * and respect needed delays. */ - comres = bmm050_set_functional_state(BMM050_SLEEP_MODE); - - /* set normal accuracy mode */ - comres |= bmm050_set_repetitions_Z(BMM050_LOWPOWER_REPZ); - /* 14 repetitions Z in normal accuracy mode */ - - /* disable X, Y channel */ - comres |= bmm050_set_control_measurement_x( - BMM050_CHANNEL_DISABLE); - comres |= bmm050_set_control_measurement_y( - BMM050_CHANNEL_DISABLE); - - /* enable positive current and force a - * measurement with positive field */ - comres |= bmm050_set_adv_selftest( - BMM050_ADVANCED_SELFTEST_POSITIVE); - comres |= bmm050_set_functional_state(BMM050_FORCED_MODE); - /* wait for measurement to complete */ - p_bmm050->delay_msec(4); - - /* read result from positive field measurement */ - comres |= bmm050_read_mdataXYZ(&mdata); - result_positive = mdata.dataz; - - /* enable negative current and force a - * measurement with negative field */ - comres |= bmm050_set_adv_selftest( - BMM050_ADVANCED_SELFTEST_NEGATIVE); - comres |= bmm050_set_functional_state(BMM050_FORCED_MODE); - p_bmm050->delay_msec(4);/* wait for measurement to complete */ - - /* read result from negative field measurement */ - comres |= bmm050_read_mdataXYZ(&mdata); - result_negative = mdata.dataz; - - /* turn off self test current */ - comres |= bmm050_set_adv_selftest( - BMM050_ADVANCED_SELFTEST_OFF); - - /* enable X, Y channel */ - comres |= bmm050_set_control_measurement_x( - BMM050_CHANNEL_ENABLE); - comres |= bmm050_set_control_measurement_y( - BMM050_CHANNEL_ENABLE); - - /* write out difference in positive and negative field. - * This should be ~ 200 mT = 3200 LSB */ - *diff_z = (result_positive - result_negative); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_init_trim_registers(void) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[2]; - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_X1, (unsigned char *) &p_bmm050->dig_x1, 1); - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Y1, (unsigned char *) &p_bmm050->dig_y1, 1); - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_X2, (unsigned char *) &p_bmm050->dig_x2, 1); - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Y2, (unsigned char *) &p_bmm050->dig_y2, 1); - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_XY1, (unsigned char *) &p_bmm050->dig_xy1, 1); - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_XY2, (unsigned char *) &p_bmm050->dig_xy2, 1); - - /* shorts can not be recast into (unsigned char*) - * due to possible mix up between trim data - * arrangement and memory arrangement */ - - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Z1_LSB, a_data_u8r, 2); - p_bmm050->dig_z1 = (BMM050_U16) ((((BMM050_U16) ((unsigned char) - a_data_u8r[1])) << - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Z2_LSB, a_data_u8r, 2); - p_bmm050->dig_z2 = (BMM050_S16) ((((BMM050_S16) ( - (signed char) a_data_u8r[1])) << - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Z3_LSB, a_data_u8r, 2); - p_bmm050->dig_z3 = (BMM050_S16) ((((BMM050_S16) ( - (signed char) a_data_u8r[1])) << - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_Z4_LSB, a_data_u8r, 2); - p_bmm050->dig_z4 = (BMM050_S16) ((((BMM050_S16) ( - (signed char) a_data_u8r[1])) << - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - - comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DIG_XYZ1_LSB, a_data_u8r, 2); - a_data_u8r[1] = BMM050_GET_BITSLICE(a_data_u8r[1], BMM050_DIG_XYZ1_MSB); - p_bmm050->dig_xyz1 = (BMM050_U16) ((((BMM050_U16) - ((unsigned char) a_data_u8r[1])) << - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_adv_selftest \ - (unsigned char adv_selftest) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - switch (adv_selftest) { - case BMM050_ADVANCED_SELFTEST_OFF: - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_ADV_ST, - BMM050_ADVANCED_SELFTEST_OFF); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - break; - - case BMM050_ADVANCED_SELFTEST_POSITIVE: - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_ADV_ST, - BMM050_ADVANCED_SELFTEST_POSITIVE); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - break; - - case BMM050_ADVANCED_SELFTEST_NEGATIVE: - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_CNTL_ADV_ST, - BMM050_ADVANCED_SELFTEST_NEGATIVE); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, - &v_data1_u8r, 1); - break; - - default: - break; - } - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_adv_selftest \ - (unsigned char *adv_selftest) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_CNTL_ADV_ST__REG, &v_data_u8r, 1); - *adv_selftest = BMM050_GET_BITSLICE(v_data_u8r, - BMM050_CNTL_ADV_ST); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_presetmode \ - (unsigned char *mode) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char data_rate = 0; - unsigned char repetitionsxy = 0; - unsigned char repetitionsz = 0; - - /* Get the current data rate */ - comres = bmm050_get_datarate(&data_rate); - /* Get the preset number of XY Repetitions */ - comres |= bmm050_get_repetitions_XY(&repetitionsxy); - /* Get the preset number of Z Repetitions */ - comres |= bmm050_get_repetitions_Z(&repetitionsz); - if ((data_rate == BMM050_LOWPOWER_DR) && ( - repetitionsxy == BMM050_LOWPOWER_REPXY) && ( - repetitionsz == BMM050_LOWPOWER_REPZ)) { - *mode = BMM050_PRESETMODE_LOWPOWER; - } - else { - if ((data_rate == BMM050_REGULAR_DR) && ( - repetitionsxy == BMM050_REGULAR_REPXY) && ( - repetitionsz == BMM050_REGULAR_REPZ)) { - *mode = BMM050_PRESETMODE_REGULAR; - } - else { - if ((data_rate == BMM050_HIGHACCURACY_DR) && ( - repetitionsxy == BMM050_HIGHACCURACY_REPXY) && ( - repetitionsz == BMM050_HIGHACCURACY_REPZ)) { - *mode = BMM050_PRESETMODE_HIGHACCURACY; - } - else { - if ((data_rate == BMM050_ENHANCED_DR) && ( - repetitionsxy == BMM050_ENHANCED_REPXY) && ( - repetitionsz == BMM050_ENHANCED_REPZ)) { - *mode = BMM050_PRESETMODE_ENHANCED; - } - else { - *mode = E_BMM050_UNDEFINED_MODE; - } - } - } - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_powermode(unsigned char *mode) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_PCB__REG, - &v_data_u8r, 1); - *mode = BMM050_GET_BITSLICE(v_data_u8r, - BMM050_POWER_CNTL_PCB); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_powermode(unsigned char mode) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_PCB__REG, - &v_data_u8r, 1); - - v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, - BMM050_POWER_CNTL_PCB, mode); - - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_PCB__REG, - &v_data_u8r, 1); - - /* wait four millisecond for bmc to settle */ - - p_bmm050->delay_msec(BMM050_DELAY_SETTLING_TIME * 4); - - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_PCB__REG, - &v_data_u8r, 1); - - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_XY( - unsigned char *no_repetitions_xy) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_NO_REPETITIONS_XY, - &v_data_u8r, 1); - *no_repetitions_xy = v_data_u8r; - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_XY( - unsigned char no_repetitions_xy) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - v_data_u8r = no_repetitions_xy; - comres = p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_NO_REPETITIONS_XY, - &v_data_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_Z( - unsigned char *no_repetitions_z) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_NO_REPETITIONS_Z, - &v_data_u8r, 1); - *no_repetitions_z = v_data_u8r; - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_Z( - unsigned char no_repetitions_z) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - v_data_u8r = no_repetitions_z; - comres = p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, - BMM050_NO_REPETITIONS_Z, &v_data_u8r, 1); - } - return comres; -} - -BMM050_S16 bmm050_compensate_X(BMM050_S16 mdata_x, BMM050_U16 data_R) -{ - BMM050_S16 inter_retval; - if (mdata_x != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ - ) { - inter_retval = ((BMM050_S16) (((BMM050_U16) - ((((BMM050_S32) p_bmm050->dig_xyz1) << 14) / - (data_R != 0 ? data_R : p_bmm050->dig_xyz1))) - - ((BMM050_U16) 0x4000))); - inter_retval = ((BMM050_S16) ((((BMM050_S32) mdata_x) * - ((((((((BMM050_S32) p_bmm050->dig_xy2) * - ((((BMM050_S32) inter_retval) * - ((BMM050_S32) inter_retval)) >> 7)) + - (((BMM050_S32) inter_retval) * - ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_xy1) - << 7)))) >> 9) + - ((BMM050_S32) 0x100000)) * - ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_x2) + - ((BMM050_S16) 0xA0)))) >> 12)) >> 13)) + - (((BMM050_S16) p_bmm050->dig_x1) << 3); - } - else { - /* overflow */ - inter_retval = BMM050_OVERFLOW_OUTPUT; - } - return inter_retval; -} - -BMM050_S32 bmm050_compensate_X_s32(BMM050_S16 mdata_x, BMM050_U16 data_R) -{ - BMM050_S32 retval; - - retval = bmm050_compensate_X(mdata_x, data_R); - if (retval == (BMM050_S32) BMM050_OVERFLOW_OUTPUT) { - retval = BMM050_OVERFLOW_OUTPUT_S32; - } - return retval; -} - -#ifdef ENABLE_FLOAT -float bmm050_compensate_X_float(BMM050_S16 mdata_x, BMM050_U16 data_R) -{ - float inter_retval; - if (mdata_x != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ - ) { - if (data_R != 0) { - inter_retval = ((((float) p_bmm050->dig_xyz1) * 16384.0f - / data_R) - 16384.0f); - } - else { - inter_retval = 0; - } - inter_retval = (((mdata_x * ((((((float) p_bmm050->dig_xy2) * - (inter_retval * inter_retval / 268435456.0f) + - inter_retval * ((float) p_bmm050->dig_xy1) / 16384.0f)) - + 256.0f) * (((float) p_bmm050->dig_x2) + 160.0f))) - / 8192.0f) + (((float) p_bmm050->dig_x1) * 8.0f)) / 16.0f; - } - else { - inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; - } - return inter_retval; -} - -#endif - -BMM050_S16 bmm050_compensate_Y(BMM050_S16 mdata_y, BMM050_U16 data_R) -{ - BMM050_S16 inter_retval; - if (mdata_y != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ - ) { - inter_retval = ((BMM050_S16) (((BMM050_U16) ((( - (BMM050_S32) p_bmm050->dig_xyz1) << 14) / - (data_R != 0 ? - data_R : p_bmm050->dig_xyz1))) - - ((BMM050_U16) 0x4000))); - inter_retval = ((BMM050_S16) ((((BMM050_S32) mdata_y) * - ((((((((BMM050_S32) - p_bmm050->dig_xy2) * - ((((BMM050_S32) inter_retval) * - ((BMM050_S32) inter_retval)) >> 7)) + - (((BMM050_S32) inter_retval) * - ((BMM050_S32) (((BMM050_S16) - p_bmm050->dig_xy1) << 7)))) >> 9) + - ((BMM050_S32) 0x100000)) * - ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_y2) - + ((BMM050_S16) 0xA0)))) - >> 12)) >> 13)) + - (((BMM050_S16) p_bmm050->dig_y1) << 3); - } - else { - /* overflow */ - inter_retval = BMM050_OVERFLOW_OUTPUT; - } - return inter_retval; -} - -BMM050_S32 bmm050_compensate_Y_s32(BMM050_S16 mdata_y, BMM050_U16 data_R) -{ - BMM050_S32 retval; - - retval = bmm050_compensate_Y(mdata_y, data_R); - if (retval == BMM050_OVERFLOW_OUTPUT) { - retval = BMM050_OVERFLOW_OUTPUT_S32; - } - return retval; -} - -#ifdef ENABLE_FLOAT -float bmm050_compensate_Y_float(BMM050_S16 mdata_y, BMM050_U16 data_R) -{ - float inter_retval; - if (mdata_y != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ - ) { - if (data_R != 0) { - inter_retval = ((((float) p_bmm050->dig_xyz1) * 16384.0f - / data_R) - 16384.0f); - } - else { - inter_retval = 0; - } - inter_retval = (((mdata_y * ((((((float) p_bmm050->dig_xy2) * - (inter_retval * inter_retval / 268435456.0f) + - inter_retval * ((float) p_bmm050->dig_xy1) / 16384.0f)) + - 256.0f) * (((float) p_bmm050->dig_y2) + 160.0f))) - / 8192.0f) + (((float) p_bmm050->dig_y1) * 8.0f)) / 16.0f; - } - else { - /* overflow, set output to 0.0f */ - inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; - } - return inter_retval; -} - -#endif - -BMM050_S16 bmm050_compensate_Z(BMM050_S16 mdata_z, BMM050_U16 data_R) -{ - BMM050_S32 retval; - if ((mdata_z != BMM050_HALL_OVERFLOW_ADCVAL) /* no overflow */ - ) { - retval = (((((BMM050_S32) (mdata_z - p_bmm050->dig_z4)) << 15) - - ((((BMM050_S32) p_bmm050->dig_z3) * - ((BMM050_S32) (((BMM050_S16) data_R) - - ((BMM050_S16) - p_bmm050->dig_xyz1)))) >> 2)) / - (p_bmm050->dig_z2 + - ((BMM050_S16) (((((BMM050_S32) - p_bmm050->dig_z1) * - ((((BMM050_S16) data_R) << 1))) + - (1 << 15)) >> 16)))); - /* saturate result to +/- 2 mT */ - if (retval > BMM050_POSITIVE_SATURATION_Z) { - retval = BMM050_POSITIVE_SATURATION_Z; - } - else { - if (retval < BMM050_NEGATIVE_SATURATION_Z) { - retval = BMM050_NEGATIVE_SATURATION_Z; - } - } - } - else { - /* overflow */ - retval = BMM050_OVERFLOW_OUTPUT; - } - return (BMM050_S16) retval; -} - -BMM050_S32 bmm050_compensate_Z_s32(BMM050_S16 mdata_z, BMM050_U16 data_R) -{ - BMM050_S32 retval; - if (mdata_z != BMM050_HALL_OVERFLOW_ADCVAL) { - retval = (((((BMM050_S32) (mdata_z - p_bmm050->dig_z4)) << 15) - - ((((BMM050_S32) p_bmm050->dig_z3) * - ((BMM050_S32) (((BMM050_S16) data_R) - - ((BMM050_S16) p_bmm050->dig_xyz1)))) >> 2)) / - (p_bmm050->dig_z2 + - ((BMM050_S16) (((((BMM050_S32) p_bmm050->dig_z1) * - ((((BMM050_S16) data_R) << 1))) + (1 << 15)) >> 16)))); - } - else { - retval = BMM050_OVERFLOW_OUTPUT_S32; - } - return retval; -} - -#ifdef ENABLE_FLOAT -float bmm050_compensate_Z_float(BMM050_S16 mdata_z, BMM050_U16 data_R) -{ - float inter_retval; - if (mdata_z != BMM050_HALL_OVERFLOW_ADCVAL /* no overflow */ - ) { - inter_retval = ((((((float) mdata_z) - ((float) p_bmm050->dig_z4)) * - 131072.0f) - (((float) p_bmm050->dig_z3) * (((float) data_R) - - ((float) p_bmm050->dig_xyz1)))) / - ((((float) p_bmm050->dig_z2) + - ((float) - p_bmm050-> - dig_z1) * ((float) data_R) / 32768.0f) * 4.0f)) / 16.0f; - } - else { - /* overflow, set output to 0.0f */ - inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; - } - return inter_retval; -} - -#endif - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_x \ - (unsigned char enable_disable) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_CHANNELX__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_CHANNELX, - enable_disable); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_CHANNELX__REG, - &v_data1_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_y \ - (unsigned char enable_disable) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_CHANNELY__REG, - &v_data1_u8r, 1); - v_data1_u8r = BMM050_SET_BITSLICE( - v_data1_u8r, - BMM050_SENS_CNTL_CHANNELY, - enable_disable); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_CHANNELY__REG, - &v_data1_u8r, 1); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_soft_reset(void) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - v_data_u8r = BMM050_ON; - - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_SRST7__REG, - &v_data_u8r, 1); - v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, - BMM050_POWER_CNTL_SRST7, - BMM050_SOFT_RESET7_ON); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_SRST7__REG, &v_data_u8r, 1); - - comres |= p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_SRST1__REG, - &v_data_u8r, 1); - v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, - BMM050_POWER_CNTL_SRST1, - BMM050_SOFT_RESET1_ON); - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_POWER_CNTL_SRST1__REG, - &v_data_u8r, 1); - - p_bmm050->delay_msec(BMM050_DELAY_SOFTRESET); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_raw_xyz(struct bmm050_mdata *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[8]; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, - BMM050_DATAX_LSB, a_data_u8r, 8); - - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_DATAX_LSB_VALUEX); - mdata->datax = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) - << SHIFT_LEFT_5_POSITION) - | a_data_u8r[0]); - - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_DATAY_LSB_VALUEY); - mdata->datay = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) - << SHIFT_LEFT_5_POSITION) - | a_data_u8r[2]); - - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - mdata->dataz = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) - << SHIFT_LEFT_7_POSITION) - | a_data_u8r[4]); - - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - mdata->resistance = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - } - return comres; -} - -/* In this function X and Y axis is remapped, - * this API is only applicable for BMX055*/ -BMM050_RETURN_FUNCTION_TYPE bmm050_get_bmx055_remapped_raw_xyz \ - (struct bmm050_remapped_mdata *mdata) -{ - BMM050_RETURN_FUNCTION_TYPE comres; - unsigned char a_data_u8r[8]; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ - BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); - - a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], - BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); - mdata->datay = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[1])) - << SHIFT_LEFT_5_POSITION) - | a_data_u8r[0]); - - a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], - BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); - mdata->datax = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[3])) - << SHIFT_LEFT_5_POSITION) - | a_data_u8r[2]); - mdata->datax = -mdata->datax; - - a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], - BMM050_DATAZ_LSB_VALUEZ); - mdata->dataz = (BMM050_S16) ((((BMM050_S16) - ((signed char) a_data_u8r[5])) - << SHIFT_LEFT_7_POSITION) - | a_data_u8r[4]); - - a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], - BMM050_R_LSB_VALUE); - mdata->resistance = (BMM050_U16) ((((BMM050_U16) - a_data_u8r[7]) << - SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); - } - return comres; -} - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_mag_drdy_interrupt \ - (unsigned char enable_disable, - unsigned char active_low0_high1) -{ - BMM050_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data1_u8r; - if (p_bmm050 == BMM050_NULL) { - return E_BMM050_NULL_PTR; - } - else { - p_bmm050->delay_msec(50); - - comres = p_bmm050->BMM050_BUS_READ_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_DRDY_EN__REG, - &v_data1_u8r, 1); - - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_CHANNELX, - (enable_disable ? 0 : 1)); - - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_CHANNELY, - (enable_disable ? 0 : 1)); - - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_CHANNELZ, - (enable_disable ? 0 : 1)); - - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_DR_POLARITY, - (active_low0_high1 ? 1 : 0)); - v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, - BMM050_SENS_CNTL_DRDY_EN, - (enable_disable ? 1 : 0)); - - comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( - p_bmm050->dev_addr, - BMM050_SENS_CNTL_DRDY_EN__REG, - &v_data1_u8r, 1); - } - return comres; -} +/* + **************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + ****************************************************************************/ +/* Date: 2013/08/07 + * Revision: 1.1 + * + */ + +/***************************************************************************** + * Copyright (C) 2013 Bosch Sensortec GmbH + * + * bmm050.c + * + * Usage: Sensor Driver for BMM050 + * + ******************************************************************************/ +/*****************************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. They + * may only be used within the parameters of the respective valid product data + * sheet. Bosch Sensortec products are provided with the express understanding + * that there is no warranty of fitness for a particular purpose.They are not + * fit for use in life-sustaining, safety or security sensitive systems or any + * system or device that may lead to bodily harm or property damage if the + * system or device malfunctions. In addition, Bosch Sensortec products are not + * fit for use in products which interact with motor vehicle systems.The resale + * and or use of products are at the purchasers own risk and his own + * responsibility. The examination of fitness for the intended use is the sole + * responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party claims, + * including any claims for incidental, or consequential damages, arising from + * any product use not covered by the parameters of the respective valid product + * data sheet or not approved by Bosch Sensortec and reimburse Bosch + * Sensortec for all costs in connection with such claims. + * + * The purchaser must monitor the market for the purchased products, + * particularly with regard to product safety and inform Bosch Sensortec without + * delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). Samples may vary + * from the valid technical specifications of the product series. They are + * therefore not intended or fit for resale to third parties or for use in end + * products. Their sole purpose is internal client testing. The testing of an + * engineering sample may in no way replace the testing of a product series. + * Bosch Sensortec assumes no liability for the use of engineering samples. By + * accepting the engineering samples, the Purchaser agrees to indemnify Bosch + * Sensortec from all claims arising from the use of engineering samples. + * + * Special: + * This software module (hereinafter called "Software") and any information on + * application-sheets (hereinafter called "Information") is provided free of + * charge for the sole purpose to support your application work. The Software + * and Information is subject to the following terms and conditions: + * + * The Software is specifically designed for the exclusive use for Bosch + * Sensortec products by personnel who have special experience and training. + * Do not use this Software if you do not have the proper experience or + * training. + * + * This Software package is provided `` as is `` and without any expressed or + * implied warranties, including without limitation, the implied warranties of + * merchantability and fitness for a particular purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability for + * the functional impairment of this Software in terms of fitness, performance + * and safety. Bosch Sensortec and their representatives and agents shall not be + * liable for any direct or indirect damages or injury, except as otherwise + * stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. Bosch + * Sensortec assumes no responsibility for the consequences of use of such + * Information nor for any infringement of patents or other rights of third + * parties which may result from its use. No license is granted by implication + * or otherwise under any patent or patent rights of Bosch. Specifications + * mentioned in the Information are subject to change without notice. + * + * It is not allowed to deliver the source code of the Software to any third + * party without permission of Bosch Sensortec. + */ +/****************************************************************************/ +/*! \file + \brief */ + +#include "bmm050.h" +#include "sensorhub.h" +#include "common.h" +#include "mag_common.h" +#include "osp-sensors.h" +#include "sensacq_i2c.h" +#include "gpio_api.h" +#include "gpio_irq_api.h" + +static struct bmm050 *p_bmm050; +static struct bmm050 bmm050; +#if 0 +static void mag_activate(bool enable) +{ + if (enable) { + bmm050_set_functional_state(BMM050_NORMAL_MODE); + /* Update the last set data rate */ + bmm050_set_datarate(BMM050_DR_25HZ); + /* Update repititions when activated */ + bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); + bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); + /* Enable Data ready interrupt */ + bmm050_set_mag_drdy_interrupt(enable, 1); + /* Read to clear any pending interrupt */ + Mag_ReadData(NULL); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(MAG_PINT_IRQn); + NVIC_ClearPendingIRQ(MAG_PINT_IRQn); + } + else { + bmm050_set_mag_drdy_interrupt(enable, 1); + bmm050_set_functional_state(BMM050_SLEEP_MODE); + NVIC_DisableIRQ(MAG_PINT_IRQn); + } +} +#endif + +void Mag_HardwareSetup(osp_bool_t enable) +{ + gpio_t hostifIrq; + NVIC_SetPriority(MAG_PINT_IRQn, SENSOR_IRQ_PRIORITY); + NVIC_DisableIRQ(MAG_PINT_IRQn); + + /* MAG INT2 irq setup */ + //Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT_PORT, MAG_INT_PIN); + hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN); + gpio_dir(&hostifIrq,PIN_INPUT); + + Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); /* Configure INMUX block */ +// Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH);/* edge sensitive and rising edge interrupt */ +// Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH); + { + gpio_irq_t gpioIrq; + gpioIrq.irq_index = MAG_PINT_CH; + gpioIrq.event = IRQ_EDGE_RISE; + gpio_irq_enable(&gpioIrq); + } + Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */ + Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */ + + //Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT3_PORT, MAG_INT3_PIN); + hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT3_PORT, MAG_INT3_PIN); + gpio_dir(&hostifIrq,PIN_INPUT); + +} + + +void Mag_Initialize(void) +{ + bmm050.bus_write = dev_i2c_write; + bmm050.bus_read = dev_i2c_read; + bmm050.delay_msec = dev_i2c_delay; + + D0_printf("MAG INIT 0\r\n"); + bmm050_init(&bmm050); + /* reset the mag */ + D0_printf("MAG INIT 1\r\n"); + dev_i2c_delay(10); + /* mag_setDelay(pSens, 50); */ + bmm050_set_datarate(BMM050_DR_25HZ); + dev_i2c_delay(10); + bmm050_set_mag_drdy_interrupt(true, 1); + bmm050_set_functional_state(BMM050_SLEEP_MODE); + + Mag_ReadData(NULL); + + + /* Note: The mag sensor is configured to SLEEP mode so in order to get sensor data you must set the OpMode to either normal (0x00) or forced mode (0x01) */ + +// mag_activate(true); +} + +void Mag_SetLowPowerMode(void) +{ + bmm050_set_functional_state(BMM050_SLEEP_MODE); +} + +void Mag_ConfigDataInt(osp_bool_t enable) +{ + /* Need to implement: */ + if (enable) { + bmm050_set_functional_state(BMM050_NORMAL_MODE); + /* Update the last set data rate */ + bmm050_set_datarate(BMM050_DR_25HZ); + /* Update repititions when activated */ + bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); + bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); + /* Enable Data ready interrupt */ + bmm050_set_mag_drdy_interrupt(enable, 1); + + /* Enable interrupt in the NVIC */ + NVIC_EnableIRQ(MAG_PINT_IRQn); + dev_i2c_delay(20); + } + else { + bmm050_set_mag_drdy_interrupt(enable, 1); + bmm050_set_functional_state(BMM050_SLEEP_MODE); + NVIC_DisableIRQ(MAG_PINT_IRQn); + } +} + +void Mag_ClearDataInt() +{ + /* Read to clear any pending interrupt */ + Mag_ReadData(NULL); +} + +void Mag_TriggerDataAcq(void) +{ + Mag_ReadData(NULL); + bmm050_set_mag_drdy_interrupt(true, 1); + bmm050_set_functional_state(BMM050_FORCED_MODE); +} + +void Mag_ReadData(MsgMagData *magData) +{ + struct bmm050_mdata mdata; + + bmm050_get_raw_xyz(&mdata); + if (magData) { + magData->X = mdata.datax; + magData->Y = mdata.datay; + magData->Z = mdata.dataz; + } +} +void MAG_IRQHandler(void) +{ + gpio_irq_t gpioIrq; + uint32_t currTime = GetCurrentTime(); + gpioIrq.irq_index = MAG_PINT_CH; +#if 0 + uint32_t currTime = g_Timer.GetCurrent(); + PhysicalSensor_t* pSens = g_phySensors[PHYS_MAG_ID]; + pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ; + pSens->ts_lastSample = currTime; + + pSens->irq_pending++; +// Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH); + gpio_irq_disable(&gpioIrq); + ResMgr_IRQDone(); +#else +// Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH); + gpio_irq_disable(&gpioIrq); + SendDataReadyIndication(MAG_INPUT_SENSOR, currTime); +#endif +} + + +BMM050_RETURN_FUNCTION_TYPE bmm050_init(struct bmm050 *bmm050) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[2]; + p_bmm050 = bmm050; + + p_bmm050->dev_addr = BMM050_I2C_ADDRESS; + + /* set device from suspend into sleep mode */ + bmm050_set_powermode(BMM050_ON); + + /* Perform a software to reset all the registers except the trim registers. + * Soft reset only executes when device is in sleep mode. No execution in suspended mode + */ + bmm050_soft_reset(); + + /*Read CHIP_ID and REv. info */ + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_CHIP_ID, a_data_u8r, 1); + p_bmm050->company_id = a_data_u8r[0]; + //D0_printf("Returned: 0x%x\r\n", (uint32_t)(a_data_u8r[0])); + /* Function to initialise trim values */ + bmm050_init_trim_registers(); + bmm050_set_presetmode(BMM050_PRESETMODE_REGULAR); + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_presetmode(unsigned char mode) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + switch (mode) { + case BMM050_PRESETMODE_LOWPOWER: + /* Set the data rate for Low Power mode */ + comres = bmm050_set_datarate(BMM050_LOWPOWER_DR); + /* Set the XY-repetitions number for Low Power mode */ + comres |= bmm050_set_repetitions_XY(BMM050_LOWPOWER_REPXY); + /* Set the Z-repetitions number for Low Power mode */ + comres |= bmm050_set_repetitions_Z(BMM050_LOWPOWER_REPZ); + break; + + case BMM050_PRESETMODE_REGULAR: + /* Set the data rate for Regular mode */ + comres = bmm050_set_datarate(BMM050_REGULAR_DR); + /* Set the XY-repetitions number for Regular mode */ + comres |= bmm050_set_repetitions_XY(BMM050_REGULAR_REPXY); + /* Set the Z-repetitions number for Regular mode */ + comres |= bmm050_set_repetitions_Z(BMM050_REGULAR_REPZ); + break; + + case BMM050_PRESETMODE_HIGHACCURACY: + /* Set the data rate for High Accuracy mode */ + comres = bmm050_set_datarate(BMM050_HIGHACCURACY_DR); + /* Set the XY-repetitions number for High Accuracy mode */ + comres |= bmm050_set_repetitions_XY(BMM050_HIGHACCURACY_REPXY); + /* Set the Z-repetitions number for High Accuracy mode */ + comres |= bmm050_set_repetitions_Z(BMM050_HIGHACCURACY_REPZ); + break; + + case BMM050_PRESETMODE_ENHANCED: + /* Set the data rate for Enhanced Accuracy mode */ + comres = bmm050_set_datarate(BMM050_ENHANCED_DR); + /* Set the XY-repetitions number for High Enhanced mode */ + comres |= bmm050_set_repetitions_XY(BMM050_ENHANCED_REPXY); + /* Set the Z-repetitions number for High Enhanced mode */ + comres |= bmm050_set_repetitions_Z(BMM050_ENHANCED_REPZ); + break; + + default: + comres = E_BMM050_OUT_OF_RANGE; + break; + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_functional_state \ + (unsigned char functional_state) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + switch (functional_state) { + case BMM050_NORMAL_MODE: + comres = bmm050_get_powermode(&v_data1_u8r); + if (v_data1_u8r == BMM050_OFF) { + comres |= bmm050_set_powermode(BMM050_ON); + p_bmm050->delay_msec( + BMM050_DELAY_SUSPEND_SLEEP); + } + { + comres |= p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_OPMODE, + BMM050_NORMAL_MODE); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + } + break; + + case BMM050_SUSPEND_MODE: + comres = bmm050_set_powermode(BMM050_OFF); + break; + + case BMM050_FORCED_MODE: + comres = bmm050_get_powermode(&v_data1_u8r); + if (v_data1_u8r == BMM050_OFF) { + comres = bmm050_set_powermode(BMM050_ON); + p_bmm050->delay_msec( + BMM050_DELAY_SUSPEND_SLEEP); + } + comres |= p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_OPMODE, BMM050_ON); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + break; + + case BMM050_SLEEP_MODE: + bmm050_get_powermode(&v_data1_u8r); + if (v_data1_u8r == BMM050_OFF) { + comres = bmm050_set_powermode(BMM050_ON); + p_bmm050->delay_msec( + BMM050_DELAY_SUSPEND_SLEEP); + } + comres |= p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_OPMODE, + BMM050_SLEEP_MODE); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data1_u8r, 1); + break; + + default: + comres = E_BMM050_OUT_OF_RANGE; + break; + } + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_functional_state \ + (unsigned char *functional_state) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_OPMODE__REG, + &v_data_u8r, 1); + *functional_state = BMM050_GET_BITSLICE( + v_data_u8r, BMM050_CNTL_OPMODE); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ(struct bmm050_mdata *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DATAX_LSB, a_data_u8r, 8); + + /* Reading data for X axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for Y axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; + } + return comres; +} + +/* In this function X and Y axis is remapped, + * this API is only applicable for BMX055*/ +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ \ + (struct bmm050_remapped_mdata *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ + BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); + + /* Reading data for Y axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for X axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_s32 \ + (struct bmm050_mdata_s32 *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DATAX_LSB, a_data_u8r, 8); + + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_DATAX_LSB_VALUEX); + + raw_dataXYZ.raw_dataX = (BMM050_S16) ( + (((BMM050_U16) a_data_u8r[1]) << BMM050_DATAX_LSB_VALUEX__LEN) | + a_data_u8r[0]); + if (a_data_u8r[1] & 0x80) { + raw_dataXYZ.raw_dataX |= 0xe000; + } + + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_DATAY_LSB_VALUEY); + + raw_dataXYZ.raw_dataY = (BMM050_S16) ( + (((BMM050_U16) a_data_u8r[3]) << BMM050_DATAY_LSB_VALUEY__LEN) | + a_data_u8r[2]); + if (a_data_u8r[3] & 0x80) { + raw_dataXYZ.raw_dataY |= 0xe000; + } + + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + + raw_dataXYZ.raw_dataZ = (BMM050_S16) ( + (((BMM050_U16) a_data_u8r[5]) << BMM050_DATAZ_LSB_VALUEZ__LEN) | + a_data_u8r[4]); + if (a_data_u8r[5] & 0x80) { + raw_dataXYZ.raw_dataZ |= 0x8000; + } + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + + raw_dataXYZ.raw_dataR = (BMM050_S16) ((((BMM050_U16) a_data_u8r[7]) << BMM050_R_LSB_VALUE__LEN) | + a_data_u8r[6]); + if (a_data_u8r[7] & 0x80) { + raw_dataXYZ.raw_dataR |= 0xc000; + } + +#if 1 + mdata->datax = raw_dataXYZ.raw_dataX; + mdata->datay = raw_dataXYZ.raw_dataY; + mdata->dataz = raw_dataXYZ.raw_dataZ; + +#else + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); +#endif +#if 0 + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DATAX_LSB, a_data_u8r, 8); + + /* Reading data for X axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for Y axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; +#endif + } + return comres; +} + +/* In this function X and Y axis is remapped, + * this API is only applicable for BMX055*/ +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_s32 \ + (struct bmm050_remapped_mdata_s32 *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ + BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); + + /* Reading data for Y axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for X axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X_s32(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y_s32(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z_s32(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; + } + return comres; +} + +#ifdef ENABLE_FLOAT +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_float \ + (struct bmm050_mdata_float *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DATAX_LSB, a_data_u8r, 8); + + /* Reading data for X axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for Y axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X_float(raw_dataXYZ.raw_dataX, + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y_float(raw_dataXYZ.raw_dataY, + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z_float(raw_dataXYZ.raw_dataZ, + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; + } + return comres; +} + +#endif + +/* In this function X and Y axis is remapped, + * this API is only applicable for BMX055*/ +#ifdef ENABLE_FLOAT +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_float \ + (struct bmm050_remapped_mdata_float *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + + unsigned char a_data_u8r[8]; + + struct { + BMM050_S16 raw_dataX; + BMM050_S16 raw_dataY; + BMM050_S16 raw_dataZ; + BMM050_U16 raw_dataR; + } raw_dataXYZ; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ + BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); + + /* Reading data for Y axis */ + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); + raw_dataXYZ.raw_dataY = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[0]); + + /* Reading data for X axis */ + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); + raw_dataXYZ.raw_dataX = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) << + SHIFT_LEFT_5_POSITION) | a_data_u8r[2]); + raw_dataXYZ.raw_dataX = -raw_dataXYZ.raw_dataX; + + /* Reading data for Z axis */ + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + raw_dataXYZ.raw_dataZ = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) << + SHIFT_LEFT_7_POSITION) | a_data_u8r[4]); + + /* Reading data for Resistance*/ + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + raw_dataXYZ.raw_dataR = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + + /* Compensation for X axis */ + mdata->datax = bmm050_compensate_X_float(raw_dataXYZ.raw_dataX, \ + raw_dataXYZ.raw_dataR); + + /* Compensation for Y axis */ + mdata->datay = bmm050_compensate_Y_float(raw_dataXYZ.raw_dataY, \ + raw_dataXYZ.raw_dataR); + + /* Compensation for Z axis */ + mdata->dataz = bmm050_compensate_Z_float(raw_dataXYZ.raw_dataZ, \ + raw_dataXYZ.raw_dataR); + + /* Output raw resistance value */ + mdata->resistance = raw_dataXYZ.raw_dataR; + } + return comres; +} + +#endif + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_register(unsigned char addr, \ + unsigned char *data, unsigned char len) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres += p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ + addr, data, len); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_write_register(unsigned char addr, \ + unsigned char *data, unsigned char len) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, \ + addr, data, len); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_selftest(unsigned char selftest) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, BMM050_CNTL_S_TEST__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, BMM050_CNTL_S_TEST, selftest); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, BMM050_CNTL_S_TEST__REG, + &v_data1_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_self_test_XYZ \ + (unsigned char *self_testxyz) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[5], v_result_u8r = 0x00; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, BMM050_DATAX_LSB_TESTX__REG, + a_data_u8r, 5); + + v_result_u8r = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_TESTZ); + + v_result_u8r = (v_result_u8r << 1); + v_result_u8r = (v_result_u8r | BMM050_GET_BITSLICE( + a_data_u8r[2], BMM050_DATAY_LSB_TESTY)); + + v_result_u8r = (v_result_u8r << 1); + v_result_u8r = (v_result_u8r | BMM050_GET_BITSLICE( + a_data_u8r[0], BMM050_DATAX_LSB_TESTX)); + + *self_testxyz = v_result_u8r; + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_spi3(unsigned char value) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_POWER_CNTL_SPI3_EN__REG, &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_POWER_CNTL_SPI3_EN, value); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, + BMM050_POWER_CNTL_SPI3_EN__REG, &v_data1_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_datarate(unsigned char data_rate) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_DR__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_CNTL_DR, data_rate); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_DR__REG, + &v_data1_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_datarate(unsigned char *data_rate) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_DR__REG, + &v_data_u8r, 1); + *data_rate = BMM050_GET_BITSLICE(v_data_u8r, + BMM050_CNTL_DR); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_perform_advanced_selftest \ + (BMM050_S16 *diff_z) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + BMM050_S16 result_positive, result_negative; + struct bmm050_mdata mdata; + + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + /* set sleep mode to prepare for forced measurement. + * If sensor is off, this will turn it on + * and respect needed delays. */ + comres = bmm050_set_functional_state(BMM050_SLEEP_MODE); + + /* set normal accuracy mode */ + comres |= bmm050_set_repetitions_Z(BMM050_LOWPOWER_REPZ); + /* 14 repetitions Z in normal accuracy mode */ + + /* disable X, Y channel */ + comres |= bmm050_set_control_measurement_x( + BMM050_CHANNEL_DISABLE); + comres |= bmm050_set_control_measurement_y( + BMM050_CHANNEL_DISABLE); + + /* enable positive current and force a + * measurement with positive field */ + comres |= bmm050_set_adv_selftest( + BMM050_ADVANCED_SELFTEST_POSITIVE); + comres |= bmm050_set_functional_state(BMM050_FORCED_MODE); + /* wait for measurement to complete */ + p_bmm050->delay_msec(4); + + /* read result from positive field measurement */ + comres |= bmm050_read_mdataXYZ(&mdata); + result_positive = mdata.dataz; + + /* enable negative current and force a + * measurement with negative field */ + comres |= bmm050_set_adv_selftest( + BMM050_ADVANCED_SELFTEST_NEGATIVE); + comres |= bmm050_set_functional_state(BMM050_FORCED_MODE); + p_bmm050->delay_msec(4);/* wait for measurement to complete */ + + /* read result from negative field measurement */ + comres |= bmm050_read_mdataXYZ(&mdata); + result_negative = mdata.dataz; + + /* turn off self test current */ + comres |= bmm050_set_adv_selftest( + BMM050_ADVANCED_SELFTEST_OFF); + + /* enable X, Y channel */ + comres |= bmm050_set_control_measurement_x( + BMM050_CHANNEL_ENABLE); + comres |= bmm050_set_control_measurement_y( + BMM050_CHANNEL_ENABLE); + + /* write out difference in positive and negative field. + * This should be ~ 200 mT = 3200 LSB */ + *diff_z = (result_positive - result_negative); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_init_trim_registers(void) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[2]; + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_X1, (unsigned char *) &p_bmm050->dig_x1, 1); + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Y1, (unsigned char *) &p_bmm050->dig_y1, 1); + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_X2, (unsigned char *) &p_bmm050->dig_x2, 1); + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Y2, (unsigned char *) &p_bmm050->dig_y2, 1); + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_XY1, (unsigned char *) &p_bmm050->dig_xy1, 1); + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_XY2, (unsigned char *) &p_bmm050->dig_xy2, 1); + + /* shorts can not be recast into (unsigned char*) + * due to possible mix up between trim data + * arrangement and memory arrangement */ + + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Z1_LSB, a_data_u8r, 2); + p_bmm050->dig_z1 = (BMM050_U16) ((((BMM050_U16) ((unsigned char) + a_data_u8r[1])) << + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Z2_LSB, a_data_u8r, 2); + p_bmm050->dig_z2 = (BMM050_S16) ((((BMM050_S16) ( + (signed char) a_data_u8r[1])) << + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Z3_LSB, a_data_u8r, 2); + p_bmm050->dig_z3 = (BMM050_S16) ((((BMM050_S16) ( + (signed char) a_data_u8r[1])) << + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_Z4_LSB, a_data_u8r, 2); + p_bmm050->dig_z4 = (BMM050_S16) ((((BMM050_S16) ( + (signed char) a_data_u8r[1])) << + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + + comres |= p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DIG_XYZ1_LSB, a_data_u8r, 2); + a_data_u8r[1] = BMM050_GET_BITSLICE(a_data_u8r[1], BMM050_DIG_XYZ1_MSB); + p_bmm050->dig_xyz1 = (BMM050_U16) ((((BMM050_U16) + ((unsigned char) a_data_u8r[1])) << + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_adv_selftest \ + (unsigned char adv_selftest) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + switch (adv_selftest) { + case BMM050_ADVANCED_SELFTEST_OFF: + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_ADV_ST, + BMM050_ADVANCED_SELFTEST_OFF); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + break; + + case BMM050_ADVANCED_SELFTEST_POSITIVE: + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_ADV_ST, + BMM050_ADVANCED_SELFTEST_POSITIVE); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + break; + + case BMM050_ADVANCED_SELFTEST_NEGATIVE: + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_CNTL_ADV_ST, + BMM050_ADVANCED_SELFTEST_NEGATIVE); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, + &v_data1_u8r, 1); + break; + + default: + break; + } + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_adv_selftest \ + (unsigned char *adv_selftest) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_CNTL_ADV_ST__REG, &v_data_u8r, 1); + *adv_selftest = BMM050_GET_BITSLICE(v_data_u8r, + BMM050_CNTL_ADV_ST); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_presetmode \ + (unsigned char *mode) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char data_rate = 0; + unsigned char repetitionsxy = 0; + unsigned char repetitionsz = 0; + + /* Get the current data rate */ + comres = bmm050_get_datarate(&data_rate); + /* Get the preset number of XY Repetitions */ + comres |= bmm050_get_repetitions_XY(&repetitionsxy); + /* Get the preset number of Z Repetitions */ + comres |= bmm050_get_repetitions_Z(&repetitionsz); + if ((data_rate == BMM050_LOWPOWER_DR) && ( + repetitionsxy == BMM050_LOWPOWER_REPXY) && ( + repetitionsz == BMM050_LOWPOWER_REPZ)) { + *mode = BMM050_PRESETMODE_LOWPOWER; + } + else { + if ((data_rate == BMM050_REGULAR_DR) && ( + repetitionsxy == BMM050_REGULAR_REPXY) && ( + repetitionsz == BMM050_REGULAR_REPZ)) { + *mode = BMM050_PRESETMODE_REGULAR; + } + else { + if ((data_rate == BMM050_HIGHACCURACY_DR) && ( + repetitionsxy == BMM050_HIGHACCURACY_REPXY) && ( + repetitionsz == BMM050_HIGHACCURACY_REPZ)) { + *mode = BMM050_PRESETMODE_HIGHACCURACY; + } + else { + if ((data_rate == BMM050_ENHANCED_DR) && ( + repetitionsxy == BMM050_ENHANCED_REPXY) && ( + repetitionsz == BMM050_ENHANCED_REPZ)) { + *mode = BMM050_PRESETMODE_ENHANCED; + } + else { + *mode = E_BMM050_UNDEFINED_MODE; + } + } + } + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_powermode(unsigned char *mode) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_PCB__REG, + &v_data_u8r, 1); + *mode = BMM050_GET_BITSLICE(v_data_u8r, + BMM050_POWER_CNTL_PCB); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_powermode(unsigned char mode) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_PCB__REG, + &v_data_u8r, 1); + + v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, + BMM050_POWER_CNTL_PCB, mode); + + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_PCB__REG, + &v_data_u8r, 1); + + /* wait four millisecond for bmc to settle */ + + p_bmm050->delay_msec(BMM050_DELAY_SETTLING_TIME * 4); + + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_PCB__REG, + &v_data_u8r, 1); + + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_XY( + unsigned char *no_repetitions_xy) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_NO_REPETITIONS_XY, + &v_data_u8r, 1); + *no_repetitions_xy = v_data_u8r; + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_XY( + unsigned char no_repetitions_xy) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + v_data_u8r = no_repetitions_xy; + comres = p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_NO_REPETITIONS_XY, + &v_data_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_Z( + unsigned char *no_repetitions_z) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_NO_REPETITIONS_Z, + &v_data_u8r, 1); + *no_repetitions_z = v_data_u8r; + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_Z( + unsigned char no_repetitions_z) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + v_data_u8r = no_repetitions_z; + comres = p_bmm050->BMM050_BUS_WRITE_FUNC(p_bmm050->dev_addr, + BMM050_NO_REPETITIONS_Z, &v_data_u8r, 1); + } + return comres; +} + +BMM050_S16 bmm050_compensate_X(BMM050_S16 mdata_x, BMM050_U16 data_R) +{ + BMM050_S16 inter_retval; + if (mdata_x != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ + ) { + inter_retval = ((BMM050_S16) (((BMM050_U16) + ((((BMM050_S32) p_bmm050->dig_xyz1) << 14) / + (data_R != 0 ? data_R : p_bmm050->dig_xyz1))) - + ((BMM050_U16) 0x4000))); + inter_retval = ((BMM050_S16) ((((BMM050_S32) mdata_x) * + ((((((((BMM050_S32) p_bmm050->dig_xy2) * + ((((BMM050_S32) inter_retval) * + ((BMM050_S32) inter_retval)) >> 7)) + + (((BMM050_S32) inter_retval) * + ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_xy1) + << 7)))) >> 9) + + ((BMM050_S32) 0x100000)) * + ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_x2) + + ((BMM050_S16) 0xA0)))) >> 12)) >> 13)) + + (((BMM050_S16) p_bmm050->dig_x1) << 3); + } + else { + /* overflow */ + inter_retval = BMM050_OVERFLOW_OUTPUT; + } + return inter_retval; +} + +BMM050_S32 bmm050_compensate_X_s32(BMM050_S16 mdata_x, BMM050_U16 data_R) +{ + BMM050_S32 retval; + + retval = bmm050_compensate_X(mdata_x, data_R); + if (retval == (BMM050_S32) BMM050_OVERFLOW_OUTPUT) { + retval = BMM050_OVERFLOW_OUTPUT_S32; + } + return retval; +} + +#ifdef ENABLE_FLOAT +float bmm050_compensate_X_float(BMM050_S16 mdata_x, BMM050_U16 data_R) +{ + float inter_retval; + if (mdata_x != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ + ) { + if (data_R != 0) { + inter_retval = ((((float) p_bmm050->dig_xyz1) * 16384.0f + / data_R) - 16384.0f); + } + else { + inter_retval = 0; + } + inter_retval = (((mdata_x * ((((((float) p_bmm050->dig_xy2) * + (inter_retval * inter_retval / 268435456.0f) + + inter_retval * ((float) p_bmm050->dig_xy1) / 16384.0f)) + + 256.0f) * (((float) p_bmm050->dig_x2) + 160.0f))) + / 8192.0f) + (((float) p_bmm050->dig_x1) * 8.0f)) / 16.0f; + } + else { + inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; + } + return inter_retval; +} + +#endif + +BMM050_S16 bmm050_compensate_Y(BMM050_S16 mdata_y, BMM050_U16 data_R) +{ + BMM050_S16 inter_retval; + if (mdata_y != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ + ) { + inter_retval = ((BMM050_S16) (((BMM050_U16) ((( + (BMM050_S32) p_bmm050->dig_xyz1) << 14) / + (data_R != 0 ? + data_R : p_bmm050->dig_xyz1))) - + ((BMM050_U16) 0x4000))); + inter_retval = ((BMM050_S16) ((((BMM050_S32) mdata_y) * + ((((((((BMM050_S32) + p_bmm050->dig_xy2) * + ((((BMM050_S32) inter_retval) * + ((BMM050_S32) inter_retval)) >> 7)) + + (((BMM050_S32) inter_retval) * + ((BMM050_S32) (((BMM050_S16) + p_bmm050->dig_xy1) << 7)))) >> 9) + + ((BMM050_S32) 0x100000)) * + ((BMM050_S32) (((BMM050_S16) p_bmm050->dig_y2) + + ((BMM050_S16) 0xA0)))) + >> 12)) >> 13)) + + (((BMM050_S16) p_bmm050->dig_y1) << 3); + } + else { + /* overflow */ + inter_retval = BMM050_OVERFLOW_OUTPUT; + } + return inter_retval; +} + +BMM050_S32 bmm050_compensate_Y_s32(BMM050_S16 mdata_y, BMM050_U16 data_R) +{ + BMM050_S32 retval; + + retval = bmm050_compensate_Y(mdata_y, data_R); + if (retval == BMM050_OVERFLOW_OUTPUT) { + retval = BMM050_OVERFLOW_OUTPUT_S32; + } + return retval; +} + +#ifdef ENABLE_FLOAT +float bmm050_compensate_Y_float(BMM050_S16 mdata_y, BMM050_U16 data_R) +{ + float inter_retval; + if (mdata_y != BMM050_FLIP_OVERFLOW_ADCVAL /* no overflow */ + ) { + if (data_R != 0) { + inter_retval = ((((float) p_bmm050->dig_xyz1) * 16384.0f + / data_R) - 16384.0f); + } + else { + inter_retval = 0; + } + inter_retval = (((mdata_y * ((((((float) p_bmm050->dig_xy2) * + (inter_retval * inter_retval / 268435456.0f) + + inter_retval * ((float) p_bmm050->dig_xy1) / 16384.0f)) + + 256.0f) * (((float) p_bmm050->dig_y2) + 160.0f))) + / 8192.0f) + (((float) p_bmm050->dig_y1) * 8.0f)) / 16.0f; + } + else { + /* overflow, set output to 0.0f */ + inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; + } + return inter_retval; +} + +#endif + +BMM050_S16 bmm050_compensate_Z(BMM050_S16 mdata_z, BMM050_U16 data_R) +{ + BMM050_S32 retval; + if ((mdata_z != BMM050_HALL_OVERFLOW_ADCVAL) /* no overflow */ + ) { + retval = (((((BMM050_S32) (mdata_z - p_bmm050->dig_z4)) << 15) - + ((((BMM050_S32) p_bmm050->dig_z3) * + ((BMM050_S32) (((BMM050_S16) data_R) - + ((BMM050_S16) + p_bmm050->dig_xyz1)))) >> 2)) / + (p_bmm050->dig_z2 + + ((BMM050_S16) (((((BMM050_S32) + p_bmm050->dig_z1) * + ((((BMM050_S16) data_R) << 1))) + + (1 << 15)) >> 16)))); + /* saturate result to +/- 2 mT */ + if (retval > BMM050_POSITIVE_SATURATION_Z) { + retval = BMM050_POSITIVE_SATURATION_Z; + } + else { + if (retval < BMM050_NEGATIVE_SATURATION_Z) { + retval = BMM050_NEGATIVE_SATURATION_Z; + } + } + } + else { + /* overflow */ + retval = BMM050_OVERFLOW_OUTPUT; + } + return (BMM050_S16) retval; +} + +BMM050_S32 bmm050_compensate_Z_s32(BMM050_S16 mdata_z, BMM050_U16 data_R) +{ + BMM050_S32 retval; + if (mdata_z != BMM050_HALL_OVERFLOW_ADCVAL) { + retval = (((((BMM050_S32) (mdata_z - p_bmm050->dig_z4)) << 15) - + ((((BMM050_S32) p_bmm050->dig_z3) * + ((BMM050_S32) (((BMM050_S16) data_R) - + ((BMM050_S16) p_bmm050->dig_xyz1)))) >> 2)) / + (p_bmm050->dig_z2 + + ((BMM050_S16) (((((BMM050_S32) p_bmm050->dig_z1) * + ((((BMM050_S16) data_R) << 1))) + (1 << 15)) >> 16)))); + } + else { + retval = BMM050_OVERFLOW_OUTPUT_S32; + } + return retval; +} + +#ifdef ENABLE_FLOAT +float bmm050_compensate_Z_float(BMM050_S16 mdata_z, BMM050_U16 data_R) +{ + float inter_retval; + if (mdata_z != BMM050_HALL_OVERFLOW_ADCVAL /* no overflow */ + ) { + inter_retval = ((((((float) mdata_z) - ((float) p_bmm050->dig_z4)) * + 131072.0f) - (((float) p_bmm050->dig_z3) * (((float) data_R) - + ((float) p_bmm050->dig_xyz1)))) / + ((((float) p_bmm050->dig_z2) + + ((float) + p_bmm050-> + dig_z1) * ((float) data_R) / 32768.0f) * 4.0f)) / 16.0f; + } + else { + /* overflow, set output to 0.0f */ + inter_retval = BMM050_OVERFLOW_OUTPUT_FLOAT; + } + return inter_retval; +} + +#endif + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_x \ + (unsigned char enable_disable) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_CHANNELX__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_CHANNELX, + enable_disable); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_CHANNELX__REG, + &v_data1_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_y \ + (unsigned char enable_disable) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_CHANNELY__REG, + &v_data1_u8r, 1); + v_data1_u8r = BMM050_SET_BITSLICE( + v_data1_u8r, + BMM050_SENS_CNTL_CHANNELY, + enable_disable); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_CHANNELY__REG, + &v_data1_u8r, 1); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_soft_reset(void) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + v_data_u8r = BMM050_ON; + + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_SRST7__REG, + &v_data_u8r, 1); + v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, + BMM050_POWER_CNTL_SRST7, + BMM050_SOFT_RESET7_ON); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_SRST7__REG, &v_data_u8r, 1); + + comres |= p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_SRST1__REG, + &v_data_u8r, 1); + v_data_u8r = BMM050_SET_BITSLICE(v_data_u8r, + BMM050_POWER_CNTL_SRST1, + BMM050_SOFT_RESET1_ON); + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_POWER_CNTL_SRST1__REG, + &v_data_u8r, 1); + + p_bmm050->delay_msec(BMM050_DELAY_SOFTRESET); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_raw_xyz(struct bmm050_mdata *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[8]; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, + BMM050_DATAX_LSB, a_data_u8r, 8); + + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_DATAX_LSB_VALUEX); + mdata->datax = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) + << SHIFT_LEFT_5_POSITION) + | a_data_u8r[0]); + + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_DATAY_LSB_VALUEY); + mdata->datay = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) + << SHIFT_LEFT_5_POSITION) + | a_data_u8r[2]); + + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + mdata->dataz = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) + << SHIFT_LEFT_7_POSITION) + | a_data_u8r[4]); + + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + mdata->resistance = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + } + return comres; +} + +/* In this function X and Y axis is remapped, + * this API is only applicable for BMX055*/ +BMM050_RETURN_FUNCTION_TYPE bmm050_get_bmx055_remapped_raw_xyz \ + (struct bmm050_remapped_mdata *mdata) +{ + BMM050_RETURN_FUNCTION_TYPE comres; + unsigned char a_data_u8r[8]; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + comres = p_bmm050->BMM050_BUS_READ_FUNC(p_bmm050->dev_addr, \ + BMM050_BMX055_REMAPPED_DATAY_LSB, a_data_u8r, 8); + + a_data_u8r[0] = BMM050_GET_BITSLICE(a_data_u8r[0], + BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY); + mdata->datay = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[1])) + << SHIFT_LEFT_5_POSITION) + | a_data_u8r[0]); + + a_data_u8r[2] = BMM050_GET_BITSLICE(a_data_u8r[2], + BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX); + mdata->datax = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[3])) + << SHIFT_LEFT_5_POSITION) + | a_data_u8r[2]); + mdata->datax = -mdata->datax; + + a_data_u8r[4] = BMM050_GET_BITSLICE(a_data_u8r[4], + BMM050_DATAZ_LSB_VALUEZ); + mdata->dataz = (BMM050_S16) ((((BMM050_S16) + ((signed char) a_data_u8r[5])) + << SHIFT_LEFT_7_POSITION) + | a_data_u8r[4]); + + a_data_u8r[6] = BMM050_GET_BITSLICE(a_data_u8r[6], + BMM050_R_LSB_VALUE); + mdata->resistance = (BMM050_U16) ((((BMM050_U16) + a_data_u8r[7]) << + SHIFT_LEFT_6_POSITION) | a_data_u8r[6]); + } + return comres; +} + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_mag_drdy_interrupt \ + (unsigned char enable_disable, + unsigned char active_low0_high1) +{ + BMM050_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data1_u8r; + if (p_bmm050 == BMM050_NULL) { + return E_BMM050_NULL_PTR; + } + else { + p_bmm050->delay_msec(50); + + comres = p_bmm050->BMM050_BUS_READ_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_DRDY_EN__REG, + &v_data1_u8r, 1); + + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_CHANNELX, + (enable_disable ? 0 : 1)); + + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_CHANNELY, + (enable_disable ? 0 : 1)); + + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_CHANNELZ, + (enable_disable ? 0 : 1)); + + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_DR_POLARITY, + (active_low0_high1 ? 1 : 0)); + v_data1_u8r = BMM050_SET_BITSLICE(v_data1_u8r, + BMM050_SENS_CNTL_DRDY_EN, + (enable_disable ? 1 : 0)); + + comres |= p_bmm050->BMM050_BUS_WRITE_FUNC( + p_bmm050->dev_addr, + BMM050_SENS_CNTL_DRDY_EN__REG, + &v_data1_u8r, 1); + } + return comres; +} diff --git a/embedded/common/modules/sensor-drivers/bmm050.h b/embedded/common/modules/sensor-drivers/bmm050.h index 8638cbe..82f2f72 100644 --- a/embedded/common/modules/sensor-drivers/bmm050.h +++ b/embedded/common/modules/sensor-drivers/bmm050.h @@ -1,764 +1,764 @@ -/* - *************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - **************************************************************************/ -/* Date: 2013/08/07 - * Revision: 1.1 - * - */ - -/************************************************************************** - * Copyright (C) 2013 Bosch Sensortec GmbH - * - * bmm050.h - * - * Usage: BMM050 Sensor Driver Support Header File - * - *****************************************************************************/ -/****************************************************************************/ -/* Disclaimer - * - * Common: - * Bosch Sensortec products are developed for the consumer goods industry. - * They may only be used within the parameters of the respective valid - * product data sheet. Bosch Sensortec products are provided with the - * express understanding that there is no warranty of fitness for a - * particular purpose.They are not fit for use in life-sustaining, - * safety or security sensitive systems or any system or device - * that may lead to bodily harm or property damage if the system - * or device malfunctions. In addition,Bosch Sensortec products are - * not fit for use in products which interact with motor vehicle systems. - * The resale and or use of products are at the purchasers own risk and - * his own responsibility. The examination of fitness for the intended use - * is the sole responsibility of the Purchaser. - * - * The purchaser shall indemnify Bosch Sensortec from all third party - * claims, including any claims for incidental, or consequential damages, - * arising from any product use not covered by the parameters of - * the respective valid product data sheet or not approved by - * Bosch Sensortec and reimburse Bosch Sensortec for all costs in - * connection with such claims. - * - * The purchaser must monitor the market for the purchased products, - * particularly with regard to product safety and inform Bosch Sensortec - * without delay of all security relevant incidents. - * - * Engineering Samples are marked with an asterisk (*) or (e). - * Samples may vary from the valid technical specifications of the product - * series. They are therefore not intended or fit for resale to third - * parties or for use in end products. Their sole purpose is internal - * client testing. The testing of an engineering sample may in no way - * replace the testing of a product series. Bosch Sensortec assumes - * no liability for the use of engineering samples. - * By accepting the engineering samples, the Purchaser agrees to indemnify - * Bosch Sensortec from all claims arising from the use of engineering - * samples. - * - * Special: - * This software module (hereinafter called "Software") and any information - * on application-sheets (hereinafter called "Information") is provided - * free of charge for the sole purpose to support your application work. - * The Software and Information is subject to the following - * terms and conditions: - * - * The Software is specifically designed for the exclusive use for - * Bosch Sensortec products by personnel who have special experience - * and training. Do not use this Software if you do not have the - * proper experience or training. - * - * This Software package is provided `` as is `` and without any expressed - * or implied warranties,including without limitation, the implied warranties - * of merchantability and fitness for a particular purpose. - * - * Bosch Sensortec and their representatives and agents deny any liability - * for the functional impairment - * of this Software in terms of fitness, performance and safety. - * Bosch Sensortec and their representatives and agents shall not be liable - * for any direct or indirect damages or injury, except as - * otherwise stipulated in mandatory applicable law. - * - * The Information provided is believed to be accurate and reliable. - * Bosch Sensortec assumes no responsibility for the consequences of use - * of such Information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of Bosch. Specifications mentioned in the Information are - * subject to change without notice. - * - * It is not allowed to deliver the source code of the Software - * to any third party without permission of - * Bosch Sensortec. - */ -/****************************************************************************/ -/*! \file bmm050.h - \brief BMM050 Sensor Driver Support Header File */ - -#ifndef __BMM050_H__ -#define __BMM050_H__ - -/* For Enabling and Disabling the floating point API's */ -#define ENABLE_FLOAT - -#define BMM050_U16 unsigned short -#define BMM050_S16 signed short -#define BMM050_S32 signed int - -#define BMM050_BUS_WR_RETURN_TYPE char -#define BMM050_BUS_WR_PARAM_TYPES \ - unsigned char, unsigned char, unsigned char *, unsigned char -#define BMM050_BUS_WR_PARAM_ORDER \ - (device_addr, register_addr, register_data, wr_len) -#define BMM050_BUS_WRITE_FUNC( \ - device_addr, register_addr, register_data, wr_len) \ - bus_write(device_addr, register_addr, register_data, wr_len) - -#define BMM050_BUS_RD_RETURN_TYPE char - -#define BMM050_BUS_RD_PARAM_TYPES \ - unsigned char, unsigned char, unsigned char *, unsigned char - -#define BMM050_BUS_RD_PARAM_ORDER (device_addr, register_addr, register_data) - -#define BMM050_BUS_READ_FUNC(device_addr, register_addr, register_data, rd_len) \ - bus_read(device_addr, register_addr, register_data, rd_len) - -#define BMM050_DELAY_RETURN_TYPE void - -#define BMM050_DELAY_PARAM_TYPES unsigned int - -#define BMM050_DELAY_FUNC(delay_in_msec) \ - delay_func(delay_in_msec) - -#define BMM050_DELAY_POWEROFF_SUSPEND 1 -#define BMM050_DELAY_SUSPEND_SLEEP 2 -#define BMM050_DELAY_SLEEP_ACTIVE 1 -#define BMM050_DELAY_ACTIVE_SLEEP 1 -#define BMM050_DELAY_SLEEP_SUSPEND 1 -#define BMM050_DELAY_ACTIVE_SUSPEND 1 -#define BMM050_DELAY_SLEEP_POWEROFF 1 -#define BMM050_DELAY_ACTIVE_POWEROFF 1 -#define BMM050_DELAY_SETTLING_TIME 2 - -#define BMM050_RETURN_FUNCTION_TYPE char - -#define BMM050_I2C_ADDRESS (0x12) - -/*General Info datas*/ -#define BMM050_SOFT_RESET7_ON 1 -#define BMM050_SOFT_RESET1_ON 1 -#define BMM050_SOFT_RESET7_OFF 0 -#define BMM050_SOFT_RESET1_OFF 0 -#define BMM050_DELAY_SOFTRESET 1 - -/* Fixed Data Registers */ -#define BMM050_CHIP_ID 0x40 - -/* Data Registers*/ -#define BMM050_DATAX_LSB 0x42 -#define BMM050_DATAX_MSB 0x43 -#define BMM050_DATAY_LSB 0x44 -#define BMM050_DATAY_MSB 0x45 -#define BMM050_DATAZ_LSB 0x46 -#define BMM050_DATAZ_MSB 0x47 -#define BMM050_R_LSB 0x48 -#define BMM050_R_MSB 0x49 - -/* Data Registers for remapped axis(XandY) - * this only applicable for BMX055 */ -#define BMM050_BMX055_REMAPPED_DATAY_LSB 0x42 -#define BMM050_BMX055_REMAPPED_DATAY_MSB 0x43 -#define BMM050_BMX055_REMAPPED_DATAX_LSB 0x44 -#define BMM050_BMX055_REMAPPED_DATAX_MSB 0x45 - -/* Status Registers */ -#define BMM050_INT_STAT 0x4A - -/* Control Registers */ -#define BMM050_POWER_CNTL 0x4B -#define BMM050_CONTROL 0x4C -#define BMM050_INT_CNTL 0x4D -#define BMM050_SENS_CNTL 0x4E -#define BMM050_LOW_THRES 0x4F -#define BMM050_HIGH_THRES 0x50 -#define BMM050_NO_REPETITIONS_XY 0x51 -#define BMM050_NO_REPETITIONS_Z 0x52 - -/* Trim Extended Registers */ -#define BMM050_DIG_X1 0x5D -#define BMM050_DIG_Y1 0x5E -#define BMM050_DIG_Z4_LSB 0x62 -#define BMM050_DIG_Z4_MSB 0x63 -#define BMM050_DIG_X2 0x64 -#define BMM050_DIG_Y2 0x65 -#define BMM050_DIG_Z2_LSB 0x68 -#define BMM050_DIG_Z2_MSB 0x69 -#define BMM050_DIG_Z1_LSB 0x6A -#define BMM050_DIG_Z1_MSB 0x6B -#define BMM050_DIG_XYZ1_LSB 0x6C -#define BMM050_DIG_XYZ1_MSB 0x6D -#define BMM050_DIG_Z3_LSB 0x6E -#define BMM050_DIG_Z3_MSB 0x6F -#define BMM050_DIG_XY2 0x70 -#define BMM050_DIG_XY1 0x71 - -/* Data X LSB Register */ -#define BMM050_DATAX_LSB_VALUEX__POS 3 -#define BMM050_DATAX_LSB_VALUEX__LEN 5 -#define BMM050_DATAX_LSB_VALUEX__MSK 0xF8 -#define BMM050_DATAX_LSB_VALUEX__REG BMM050_DATAX_LSB - -/* Data X SelfTest Register */ -#define BMM050_DATAX_LSB_TESTX__POS 0 -#define BMM050_DATAX_LSB_TESTX__LEN 1 -#define BMM050_DATAX_LSB_TESTX__MSK 0x01 -#define BMM050_DATAX_LSB_TESTX__REG BMM050_DATAX_LSB - -/* Data Y LSB Register */ -#define BMM050_DATAY_LSB_VALUEY__POS 3 -#define BMM050_DATAY_LSB_VALUEY__LEN 5 -#define BMM050_DATAY_LSB_VALUEY__MSK 0xF8 -#define BMM050_DATAY_LSB_VALUEY__REG BMM050_DATAY_LSB - -/* Data Y SelfTest Register */ -#define BMM050_DATAY_LSB_TESTY__POS 0 -#define BMM050_DATAY_LSB_TESTY__LEN 1 -#define BMM050_DATAY_LSB_TESTY__MSK 0x01 -#define BMM050_DATAY_LSB_TESTY__REG BMM050_DATAY_LSB - -/* Data Z LSB Register */ -#define BMM050_DATAZ_LSB_VALUEZ__POS 1 -#define BMM050_DATAZ_LSB_VALUEZ__LEN 7 -#define BMM050_DATAZ_LSB_VALUEZ__MSK 0xFE -#define BMM050_DATAZ_LSB_VALUEZ__REG BMM050_DATAZ_LSB - -/* Data Z SelfTest Register */ -#define BMM050_DATAZ_LSB_TESTZ__POS 0 -#define BMM050_DATAZ_LSB_TESTZ__LEN 1 -#define BMM050_DATAZ_LSB_TESTZ__MSK 0x01 -#define BMM050_DATAZ_LSB_TESTZ__REG BMM050_DATAZ_LSB - -/* Hall Resistance LSB Register */ -#define BMM050_R_LSB_VALUE__POS 2 -#define BMM050_R_LSB_VALUE__LEN 6 -#define BMM050_R_LSB_VALUE__MSK 0xFC -#define BMM050_R_LSB_VALUE__REG BMM050_R_LSB - -#define BMM050_DATA_RDYSTAT__POS 0 -#define BMM050_DATA_RDYSTAT__LEN 1 -#define BMM050_DATA_RDYSTAT__MSK 0x01 -#define BMM050_DATA_RDYSTAT__REG BMM050_R_LSB - -/* Data X LSB Remapped Register only applicable for BMX055 */ -#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__POS 3 -#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__LEN 5 -#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__MSK 0xF8 -#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__REG \ - BMM050_BMX055_REMAPPED_DATAX_LSB - -/* Data Y LSB Remapped Register only applicable for BMX055 */ -#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__POS 3 -#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__LEN 5 -#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__MSK 0xF8 -#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__REG \ - BMM050_BMX055_REMAPPED_DATAY_LSB - -/* Interrupt Status Register */ -#define BMM050_INT_STAT_DOR__POS 7 -#define BMM050_INT_STAT_DOR__LEN 1 -#define BMM050_INT_STAT_DOR__MSK 0x80 -#define BMM050_INT_STAT_DOR__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_OVRFLOW__POS 6 -#define BMM050_INT_STAT_OVRFLOW__LEN 1 -#define BMM050_INT_STAT_OVRFLOW__MSK 0x40 -#define BMM050_INT_STAT_OVRFLOW__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_HIGH_THZ__POS 5 -#define BMM050_INT_STAT_HIGH_THZ__LEN 1 -#define BMM050_INT_STAT_HIGH_THZ__MSK 0x20 -#define BMM050_INT_STAT_HIGH_THZ__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_HIGH_THY__POS 4 -#define BMM050_INT_STAT_HIGH_THY__LEN 1 -#define BMM050_INT_STAT_HIGH_THY__MSK 0x10 -#define BMM050_INT_STAT_HIGH_THY__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_HIGH_THX__POS 3 -#define BMM050_INT_STAT_HIGH_THX__LEN 1 -#define BMM050_INT_STAT_HIGH_THX__MSK 0x08 -#define BMM050_INT_STAT_HIGH_THX__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_LOW_THZ__POS 2 -#define BMM050_INT_STAT_LOW_THZ__LEN 1 -#define BMM050_INT_STAT_LOW_THZ__MSK 0x04 -#define BMM050_INT_STAT_LOW_THZ__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_LOW_THY__POS 1 -#define BMM050_INT_STAT_LOW_THY__LEN 1 -#define BMM050_INT_STAT_LOW_THY__MSK 0x02 -#define BMM050_INT_STAT_LOW_THY__REG BMM050_INT_STAT - -#define BMM050_INT_STAT_LOW_THX__POS 0 -#define BMM050_INT_STAT_LOW_THX__LEN 1 -#define BMM050_INT_STAT_LOW_THX__MSK 0x01 -#define BMM050_INT_STAT_LOW_THX__REG BMM050_INT_STAT - -/* Power Control Register */ -#define BMM050_POWER_CNTL_SRST7__POS 7 -#define BMM050_POWER_CNTL_SRST7__LEN 1 -#define BMM050_POWER_CNTL_SRST7__MSK 0x80 -#define BMM050_POWER_CNTL_SRST7__REG BMM050_POWER_CNTL - -#define BMM050_POWER_CNTL_SPI3_EN__POS 2 -#define BMM050_POWER_CNTL_SPI3_EN__LEN 1 -#define BMM050_POWER_CNTL_SPI3_EN__MSK 0x04 -#define BMM050_POWER_CNTL_SPI3_EN__REG BMM050_POWER_CNTL - -#define BMM050_POWER_CNTL_SRST1__POS 1 -#define BMM050_POWER_CNTL_SRST1__LEN 1 -#define BMM050_POWER_CNTL_SRST1__MSK 0x02 -#define BMM050_POWER_CNTL_SRST1__REG BMM050_POWER_CNTL - -#define BMM050_POWER_CNTL_PCB__POS 0 -#define BMM050_POWER_CNTL_PCB__LEN 1 -#define BMM050_POWER_CNTL_PCB__MSK 0x01 -#define BMM050_POWER_CNTL_PCB__REG BMM050_POWER_CNTL - -/* Control Register */ -#define BMM050_CNTL_ADV_ST__POS 6 -#define BMM050_CNTL_ADV_ST__LEN 2 -#define BMM050_CNTL_ADV_ST__MSK 0xC0 -#define BMM050_CNTL_ADV_ST__REG BMM050_CONTROL - -#define BMM050_CNTL_DR__POS 3 -#define BMM050_CNTL_DR__LEN 3 -#define BMM050_CNTL_DR__MSK 0x38 -#define BMM050_CNTL_DR__REG BMM050_CONTROL - -#define BMM050_CNTL_OPMODE__POS 1 -#define BMM050_CNTL_OPMODE__LEN 2 -#define BMM050_CNTL_OPMODE__MSK 0x06 -#define BMM050_CNTL_OPMODE__REG BMM050_CONTROL - -#define BMM050_CNTL_S_TEST__POS 0 -#define BMM050_CNTL_S_TEST__LEN 1 -#define BMM050_CNTL_S_TEST__MSK 0x01 -#define BMM050_CNTL_S_TEST__REG BMM050_CONTROL - -/* Interrupt Control Register */ -#define BMM050_INT_CNTL_DOR_EN__POS 7 -#define BMM050_INT_CNTL_DOR_EN__LEN 1 -#define BMM050_INT_CNTL_DOR_EN__MSK 0x80 -#define BMM050_INT_CNTL_DOR_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_OVRFLOW_EN__POS 6 -#define BMM050_INT_CNTL_OVRFLOW_EN__LEN 1 -#define BMM050_INT_CNTL_OVRFLOW_EN__MSK 0x40 -#define BMM050_INT_CNTL_OVRFLOW_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_HIGH_THZ_EN__POS 5 -#define BMM050_INT_CNTL_HIGH_THZ_EN__LEN 1 -#define BMM050_INT_CNTL_HIGH_THZ_EN__MSK 0x20 -#define BMM050_INT_CNTL_HIGH_THZ_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_HIGH_THY_EN__POS 4 -#define BMM050_INT_CNTL_HIGH_THY_EN__LEN 1 -#define BMM050_INT_CNTL_HIGH_THY_EN__MSK 0x10 -#define BMM050_INT_CNTL_HIGH_THY_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_HIGH_THX_EN__POS 3 -#define BMM050_INT_CNTL_HIGH_THX_EN__LEN 1 -#define BMM050_INT_CNTL_HIGH_THX_EN__MSK 0x08 -#define BMM050_INT_CNTL_HIGH_THX_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_LOW_THZ_EN__POS 2 -#define BMM050_INT_CNTL_LOW_THZ_EN__LEN 1 -#define BMM050_INT_CNTL_LOW_THZ_EN__MSK 0x04 -#define BMM050_INT_CNTL_LOW_THZ_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_LOW_THY_EN__POS 1 -#define BMM050_INT_CNTL_LOW_THY_EN__LEN 1 -#define BMM050_INT_CNTL_LOW_THY_EN__MSK 0x02 -#define BMM050_INT_CNTL_LOW_THY_EN__REG BMM050_INT_CNTL - -#define BMM050_INT_CNTL_LOW_THX_EN__POS 0 -#define BMM050_INT_CNTL_LOW_THX_EN__LEN 1 -#define BMM050_INT_CNTL_LOW_THX_EN__MSK 0x01 -#define BMM050_INT_CNTL_LOW_THX_EN__REG BMM050_INT_CNTL - -/* Sensor Control Register */ -#define BMM050_SENS_CNTL_DRDY_EN__POS 7 -#define BMM050_SENS_CNTL_DRDY_EN__LEN 1 -#define BMM050_SENS_CNTL_DRDY_EN__MSK 0x80 -#define BMM050_SENS_CNTL_DRDY_EN__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_IE__POS 6 -#define BMM050_SENS_CNTL_IE__LEN 1 -#define BMM050_SENS_CNTL_IE__MSK 0x40 -#define BMM050_SENS_CNTL_IE__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_CHANNELZ__POS 5 -#define BMM050_SENS_CNTL_CHANNELZ__LEN 1 -#define BMM050_SENS_CNTL_CHANNELZ__MSK 0x20 -#define BMM050_SENS_CNTL_CHANNELZ__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_CHANNELY__POS 4 -#define BMM050_SENS_CNTL_CHANNELY__LEN 1 -#define BMM050_SENS_CNTL_CHANNELY__MSK 0x10 -#define BMM050_SENS_CNTL_CHANNELY__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_CHANNELX__POS 3 -#define BMM050_SENS_CNTL_CHANNELX__LEN 1 -#define BMM050_SENS_CNTL_CHANNELX__MSK 0x08 -#define BMM050_SENS_CNTL_CHANNELX__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_DR_POLARITY__POS 2 -#define BMM050_SENS_CNTL_DR_POLARITY__LEN 1 -#define BMM050_SENS_CNTL_DR_POLARITY__MSK 0x04 -#define BMM050_SENS_CNTL_DR_POLARITY__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_INTERRUPT_LATCH__POS 1 -#define BMM050_SENS_CNTL_INTERRUPT_LATCH__LEN 1 -#define BMM050_SENS_CNTL_INTERRUPT_LATCH__MSK 0x02 -#define BMM050_SENS_CNTL_INTERRUPT_LATCH__REG BMM050_SENS_CNTL - -#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__POS 0 -#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__LEN 1 -#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__MSK 0x01 -#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__REG BMM050_SENS_CNTL - -/* Register 6D */ -#define BMM050_DIG_XYZ1_MSB__POS 0 -#define BMM050_DIG_XYZ1_MSB__LEN 7 -#define BMM050_DIG_XYZ1_MSB__MSK 0x7F -#define BMM050_DIG_XYZ1_MSB__REG BMM050_DIG_XYZ1_MSB - -#define BMM050_X_AXIS 0 -#define BMM050_Y_AXIS 1 -#define BMM050_Z_AXIS 2 -#define BMM050_RESISTANCE 3 -#define BMM050_X 1 -#define BMM050_Y 2 -#define BMM050_Z 4 -#define BMM050_XYZ 7 - -/* Constants */ -#define BMM050_NULL 0 -#define BMM050_DISABLE 0 -#define BMM050_ENABLE 1 -#define BMM050_CHANNEL_DISABLE 1 -#define BMM050_CHANNEL_ENABLE 0 -#define BMM050_INTPIN_LATCH_ENABLE 1 -#define BMM050_INTPIN_LATCH_DISABLE 0 -#define BMM050_OFF 0 -#define BMM050_ON 1 - -#define BMM050_NORMAL_MODE 0x00 -#define BMM050_FORCED_MODE 0x01 -#define BMM050_SUSPEND_MODE 0x02 -#define BMM050_SLEEP_MODE 0x03 - -#define BMM050_ADVANCED_SELFTEST_OFF 0 -#define BMM050_ADVANCED_SELFTEST_NEGATIVE 2 -#define BMM050_ADVANCED_SELFTEST_POSITIVE 3 - -#define BMM050_NEGATIVE_SATURATION_Z -32767 -#define BMM050_POSITIVE_SATURATION_Z 32767 - -#define BMM050_SPI_RD_MASK 0x80 -#define BMM050_READ_SET 0x01 - -#define E_BMM050_NULL_PTR ((char) -127) -#define E_BMM050_COMM_RES ((char) -1) -#define E_BMM050_OUT_OF_RANGE ((char) -2) -#define E_BMM050_UNDEFINED_MODE 0 - -#define BMM050_WR_FUNC_PTR \ - char (*bus_write)(unsigned char, unsigned char, \ - unsigned char *, unsigned char) - -#define BMM050_RD_FUNC_PTR \ - char (*bus_read)(unsigned char, unsigned char, \ - unsigned char *, unsigned char) -#define BMM050_MDELAY_DATA_TYPE unsigned int - -/*Shifting Constants*/ -#define SHIFT_RIGHT_1_POSITION 1 -#define SHIFT_RIGHT_2_POSITION 2 -#define SHIFT_RIGHT_3_POSITION 3 -#define SHIFT_RIGHT_4_POSITION 4 -#define SHIFT_RIGHT_5_POSITION 5 -#define SHIFT_RIGHT_6_POSITION 6 -#define SHIFT_RIGHT_7_POSITION 7 -#define SHIFT_RIGHT_8_POSITION 8 - -#define SHIFT_LEFT_1_POSITION 1 -#define SHIFT_LEFT_2_POSITION 2 -#define SHIFT_LEFT_3_POSITION 3 -#define SHIFT_LEFT_4_POSITION 4 -#define SHIFT_LEFT_5_POSITION 5 -#define SHIFT_LEFT_6_POSITION 6 -#define SHIFT_LEFT_7_POSITION 7 -#define SHIFT_LEFT_8_POSITION 8 - -/* Conversion factors*/ -#define BMM050_CONVFACTOR_LSB_UT 6 - -/* get bit slice */ -#define BMM050_GET_BITSLICE(regvar, bitname) \ - ((regvar & bitname ## __MSK) >> bitname ## __POS) - -/* Set bit slice */ -#define BMM050_SET_BITSLICE(regvar, bitname, val) \ - ((regvar & (~bitname ## __MSK)) | (((val) << bitname ## __POS) & bitname ## __MSK)) - -/* compensated output value returned if sensor had overflow */ -#define BMM050_OVERFLOW_OUTPUT -32768 -#define BMM050_OVERFLOW_OUTPUT_S32 ((BMM050_S32) (-2147483647 - 1)) -#define BMM050_OVERFLOW_OUTPUT_FLOAT 0.0f -#define BMM050_FLIP_OVERFLOW_ADCVAL -4096 -#define BMM050_HALL_OVERFLOW_ADCVAL -16384 - -#define BMM050_PRESETMODE_LOWPOWER 1 -#define BMM050_PRESETMODE_REGULAR 2 -#define BMM050_PRESETMODE_HIGHACCURACY 3 -#define BMM050_PRESETMODE_ENHANCED 4 - -/* PRESET MODES - DATA RATES */ -#define BMM050_LOWPOWER_DR BMM050_DR_10HZ -#define BMM050_REGULAR_DR BMM050_DR_10HZ -#define BMM050_HIGHACCURACY_DR BMM050_DR_20HZ -#define BMM050_ENHANCED_DR BMM050_DR_10HZ - -/* PRESET MODES - REPETITIONS-XY RATES */ -#define BMM050_LOWPOWER_REPXY 1 -#define BMM050_REGULAR_REPXY 4 -#define BMM050_HIGHACCURACY_REPXY 23 -#define BMM050_ENHANCED_REPXY 7 - -/* PRESET MODES - REPETITIONS-Z RATES */ -#define BMM050_LOWPOWER_REPZ 2 -#define BMM050_REGULAR_REPZ 14 -#define BMM050_HIGHACCURACY_REPZ 82 -#define BMM050_ENHANCED_REPZ 26 - -/* Data Rates */ - -#define BMM050_DR_10HZ 0 -#define BMM050_DR_02HZ 1 -#define BMM050_DR_06HZ 2 -#define BMM050_DR_08HZ 3 -#define BMM050_DR_15HZ 4 -#define BMM050_DR_20HZ 5 -#define BMM050_DR_25HZ 6 -#define BMM050_DR_30HZ 7 - -/*user defined Structures*/ -struct bmm050_mdata { - BMM050_S16 datax; - BMM050_S16 datay; - BMM050_S16 dataz; - BMM050_U16 resistance; -}; - -struct bmm050_mdata_s32 { - BMM050_S32 datax; - BMM050_S32 datay; - BMM050_S32 dataz; - BMM050_U16 resistance; -}; - -struct bmm050_mdata_float { - float datax; - float datay; - float dataz; - BMM050_U16 resistance; -}; - -/*user defined Structures for remapped functions - * this only applicable for BMX055*/ -struct bmm050_remapped_mdata { - BMM050_S16 datax; - BMM050_S16 datay; - BMM050_S16 dataz; - BMM050_U16 resistance; -}; - -struct bmm050_remapped_mdata_s32 { - BMM050_S32 datax; - BMM050_S32 datay; - BMM050_S32 dataz; - BMM050_U16 resistance; -}; - -struct bmm050_remapped_mdata_float { - float datax; - float datay; - float dataz; - BMM050_U16 resistance; -}; - -struct bmm050 { - unsigned char company_id; - unsigned char dev_addr; - - BMM050_WR_FUNC_PTR; - BMM050_RD_FUNC_PTR; - void (*delay_msec)(BMM050_MDELAY_DATA_TYPE); - - signed char dig_x1; - signed char dig_y1; - - signed char dig_x2; - signed char dig_y2; - - BMM050_U16 dig_z1; - BMM050_S16 dig_z2; - BMM050_S16 dig_z3; - BMM050_S16 dig_z4; - - unsigned char dig_xy1; - signed char dig_xy2; - - BMM050_U16 dig_xyz1; -}; - -BMM050_RETURN_FUNCTION_TYPE bmm050_init(struct bmm050 *p_bmm050); - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ( - struct bmm050_mdata *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_s32( - struct bmm050_mdata_s32 *mdata); - -#ifdef ENABLE_FLOAT -BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_float( - struct bmm050_mdata_float *mdata); - -#endif -BMM050_RETURN_FUNCTION_TYPE bmm050_read_register( - unsigned char addr, unsigned char *data, unsigned char len); - -BMM050_RETURN_FUNCTION_TYPE bmm050_write_register( - unsigned char addr, unsigned char *data, unsigned char len); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_self_test_XYZ( - unsigned char *self_testxyz); - -BMM050_S16 bmm050_compensate_X( - BMM050_S16 mdata_x, BMM050_U16 data_R); - -BMM050_S32 bmm050_compensate_X_s32( - BMM050_S16 mdata_x, BMM050_U16 data_R); - -#ifdef ENABLE_FLOAT -float bmm050_compensate_X_float( - BMM050_S16 mdata_x, BMM050_U16 data_R); - -#endif -BMM050_S16 bmm050_compensate_Y( - BMM050_S16 mdata_y, BMM050_U16 data_R); - -BMM050_S32 bmm050_compensate_Y_s32( - BMM050_S16 mdata_y, BMM050_U16 data_R); - -#ifdef ENABLE_FLOAT -float bmm050_compensate_Y_float( - BMM050_S16 mdata_y, BMM050_U16 data_R); - -#endif -BMM050_S16 bmm050_compensate_Z( - BMM050_S16 mdata_z, BMM050_U16 data_R); - -BMM050_S32 bmm050_compensate_Z_s32( - BMM050_S16 mdata_z, BMM050_U16 data_R); - -#ifdef ENABLE_FLOAT -float bmm050_compensate_Z_float( - BMM050_S16 mdata_z, BMM050_U16 data_R); - -#endif -BMM050_RETURN_FUNCTION_TYPE bmm050_get_raw_xyz( - struct bmm050_mdata *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_init_trim_registers(void); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_spi3( - unsigned char value); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_powermode( - unsigned char *mode); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_powermode( - unsigned char mode); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_adv_selftest( - unsigned char adv_selftest); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_adv_selftest( - unsigned char *adv_selftest); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_datarate( - unsigned char data_rate); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_datarate( - unsigned char *data_rate); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_functional_state( - unsigned char functional_state); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_functional_state( - unsigned char *functional_state); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_selftest( - unsigned char selftest); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_selftest( - unsigned char *selftest); - -BMM050_RETURN_FUNCTION_TYPE bmm050_perform_advanced_selftest( - BMM050_S16 *diff_z); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_XY( - unsigned char *no_repetitions_xy); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_XY( - unsigned char no_repetitions_xy); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_Z( - unsigned char *no_repetitions_z); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_Z( - unsigned char no_repetitions_z); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_presetmode(unsigned char *mode); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_presetmode(unsigned char mode); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_x( - unsigned char enable_disable); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_y( - unsigned char enable_disable); - -BMM050_RETURN_FUNCTION_TYPE bmm050_soft_reset(void); - -BMM050_RETURN_FUNCTION_TYPE bmm050_get_bmx055_remapped_raw_xyz \ - (struct bmm050_remapped_mdata *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_float \ - (struct bmm050_remapped_mdata_float *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_s32 \ - (struct bmm050_remapped_mdata_s32 *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ \ - (struct bmm050_remapped_mdata *mdata); - -BMM050_RETURN_FUNCTION_TYPE bmm050_set_mag_drdy_interrupt \ - (unsigned char enable_disable, - unsigned char active_low0_high1); - -#endif +/* + *************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + **************************************************************************/ +/* Date: 2013/08/07 + * Revision: 1.1 + * + */ + +/************************************************************************** + * Copyright (C) 2013 Bosch Sensortec GmbH + * + * bmm050.h + * + * Usage: BMM050 Sensor Driver Support Header File + * + *****************************************************************************/ +/****************************************************************************/ +/* Disclaimer + * + * Common: + * Bosch Sensortec products are developed for the consumer goods industry. + * They may only be used within the parameters of the respective valid + * product data sheet. Bosch Sensortec products are provided with the + * express understanding that there is no warranty of fitness for a + * particular purpose.They are not fit for use in life-sustaining, + * safety or security sensitive systems or any system or device + * that may lead to bodily harm or property damage if the system + * or device malfunctions. In addition,Bosch Sensortec products are + * not fit for use in products which interact with motor vehicle systems. + * The resale and or use of products are at the purchasers own risk and + * his own responsibility. The examination of fitness for the intended use + * is the sole responsibility of the Purchaser. + * + * The purchaser shall indemnify Bosch Sensortec from all third party + * claims, including any claims for incidental, or consequential damages, + * arising from any product use not covered by the parameters of + * the respective valid product data sheet or not approved by + * Bosch Sensortec and reimburse Bosch Sensortec for all costs in + * connection with such claims. + * + * The purchaser must monitor the market for the purchased products, + * particularly with regard to product safety and inform Bosch Sensortec + * without delay of all security relevant incidents. + * + * Engineering Samples are marked with an asterisk (*) or (e). + * Samples may vary from the valid technical specifications of the product + * series. They are therefore not intended or fit for resale to third + * parties or for use in end products. Their sole purpose is internal + * client testing. The testing of an engineering sample may in no way + * replace the testing of a product series. Bosch Sensortec assumes + * no liability for the use of engineering samples. + * By accepting the engineering samples, the Purchaser agrees to indemnify + * Bosch Sensortec from all claims arising from the use of engineering + * samples. + * + * Special: + * This software module (hereinafter called "Software") and any information + * on application-sheets (hereinafter called "Information") is provided + * free of charge for the sole purpose to support your application work. + * The Software and Information is subject to the following + * terms and conditions: + * + * The Software is specifically designed for the exclusive use for + * Bosch Sensortec products by personnel who have special experience + * and training. Do not use this Software if you do not have the + * proper experience or training. + * + * This Software package is provided `` as is `` and without any expressed + * or implied warranties,including without limitation, the implied warranties + * of merchantability and fitness for a particular purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability + * for the functional impairment + * of this Software in terms of fitness, performance and safety. + * Bosch Sensortec and their representatives and agents shall not be liable + * for any direct or indirect damages or injury, except as + * otherwise stipulated in mandatory applicable law. + * + * The Information provided is believed to be accurate and reliable. + * Bosch Sensortec assumes no responsibility for the consequences of use + * of such Information nor for any infringement of patents or + * other rights of third parties which may result from its use. + * No license is granted by implication or otherwise under any patent or + * patent rights of Bosch. Specifications mentioned in the Information are + * subject to change without notice. + * + * It is not allowed to deliver the source code of the Software + * to any third party without permission of + * Bosch Sensortec. + */ +/****************************************************************************/ +/*! \file bmm050.h + \brief BMM050 Sensor Driver Support Header File */ + +#ifndef __BMM050_H__ +#define __BMM050_H__ + +/* For Enabling and Disabling the floating point API's */ +#define ENABLE_FLOAT + +#define BMM050_U16 unsigned short +#define BMM050_S16 signed short +#define BMM050_S32 signed int + +#define BMM050_BUS_WR_RETURN_TYPE char +#define BMM050_BUS_WR_PARAM_TYPES \ + unsigned char, unsigned char, unsigned char *, unsigned char +#define BMM050_BUS_WR_PARAM_ORDER \ + (device_addr, register_addr, register_data, wr_len) +#define BMM050_BUS_WRITE_FUNC( \ + device_addr, register_addr, register_data, wr_len) \ + bus_write(device_addr, register_addr, register_data, wr_len) + +#define BMM050_BUS_RD_RETURN_TYPE char + +#define BMM050_BUS_RD_PARAM_TYPES \ + unsigned char, unsigned char, unsigned char *, unsigned char + +#define BMM050_BUS_RD_PARAM_ORDER (device_addr, register_addr, register_data) + +#define BMM050_BUS_READ_FUNC(device_addr, register_addr, register_data, rd_len) \ + bus_read(device_addr, register_addr, register_data, rd_len) + +#define BMM050_DELAY_RETURN_TYPE void + +#define BMM050_DELAY_PARAM_TYPES unsigned int + +#define BMM050_DELAY_FUNC(delay_in_msec) \ + delay_func(delay_in_msec) + +#define BMM050_DELAY_POWEROFF_SUSPEND 1 +#define BMM050_DELAY_SUSPEND_SLEEP 2 +#define BMM050_DELAY_SLEEP_ACTIVE 1 +#define BMM050_DELAY_ACTIVE_SLEEP 1 +#define BMM050_DELAY_SLEEP_SUSPEND 1 +#define BMM050_DELAY_ACTIVE_SUSPEND 1 +#define BMM050_DELAY_SLEEP_POWEROFF 1 +#define BMM050_DELAY_ACTIVE_POWEROFF 1 +#define BMM050_DELAY_SETTLING_TIME 2 + +#define BMM050_RETURN_FUNCTION_TYPE char + +#define BMM050_I2C_ADDRESS (0x12) + +/*General Info datas*/ +#define BMM050_SOFT_RESET7_ON 1 +#define BMM050_SOFT_RESET1_ON 1 +#define BMM050_SOFT_RESET7_OFF 0 +#define BMM050_SOFT_RESET1_OFF 0 +#define BMM050_DELAY_SOFTRESET 1 + +/* Fixed Data Registers */ +#define BMM050_CHIP_ID 0x40 + +/* Data Registers*/ +#define BMM050_DATAX_LSB 0x42 +#define BMM050_DATAX_MSB 0x43 +#define BMM050_DATAY_LSB 0x44 +#define BMM050_DATAY_MSB 0x45 +#define BMM050_DATAZ_LSB 0x46 +#define BMM050_DATAZ_MSB 0x47 +#define BMM050_R_LSB 0x48 +#define BMM050_R_MSB 0x49 + +/* Data Registers for remapped axis(XandY) + * this only applicable for BMX055 */ +#define BMM050_BMX055_REMAPPED_DATAY_LSB 0x42 +#define BMM050_BMX055_REMAPPED_DATAY_MSB 0x43 +#define BMM050_BMX055_REMAPPED_DATAX_LSB 0x44 +#define BMM050_BMX055_REMAPPED_DATAX_MSB 0x45 + +/* Status Registers */ +#define BMM050_INT_STAT 0x4A + +/* Control Registers */ +#define BMM050_POWER_CNTL 0x4B +#define BMM050_CONTROL 0x4C +#define BMM050_INT_CNTL 0x4D +#define BMM050_SENS_CNTL 0x4E +#define BMM050_LOW_THRES 0x4F +#define BMM050_HIGH_THRES 0x50 +#define BMM050_NO_REPETITIONS_XY 0x51 +#define BMM050_NO_REPETITIONS_Z 0x52 + +/* Trim Extended Registers */ +#define BMM050_DIG_X1 0x5D +#define BMM050_DIG_Y1 0x5E +#define BMM050_DIG_Z4_LSB 0x62 +#define BMM050_DIG_Z4_MSB 0x63 +#define BMM050_DIG_X2 0x64 +#define BMM050_DIG_Y2 0x65 +#define BMM050_DIG_Z2_LSB 0x68 +#define BMM050_DIG_Z2_MSB 0x69 +#define BMM050_DIG_Z1_LSB 0x6A +#define BMM050_DIG_Z1_MSB 0x6B +#define BMM050_DIG_XYZ1_LSB 0x6C +#define BMM050_DIG_XYZ1_MSB 0x6D +#define BMM050_DIG_Z3_LSB 0x6E +#define BMM050_DIG_Z3_MSB 0x6F +#define BMM050_DIG_XY2 0x70 +#define BMM050_DIG_XY1 0x71 + +/* Data X LSB Register */ +#define BMM050_DATAX_LSB_VALUEX__POS 3 +#define BMM050_DATAX_LSB_VALUEX__LEN 5 +#define BMM050_DATAX_LSB_VALUEX__MSK 0xF8 +#define BMM050_DATAX_LSB_VALUEX__REG BMM050_DATAX_LSB + +/* Data X SelfTest Register */ +#define BMM050_DATAX_LSB_TESTX__POS 0 +#define BMM050_DATAX_LSB_TESTX__LEN 1 +#define BMM050_DATAX_LSB_TESTX__MSK 0x01 +#define BMM050_DATAX_LSB_TESTX__REG BMM050_DATAX_LSB + +/* Data Y LSB Register */ +#define BMM050_DATAY_LSB_VALUEY__POS 3 +#define BMM050_DATAY_LSB_VALUEY__LEN 5 +#define BMM050_DATAY_LSB_VALUEY__MSK 0xF8 +#define BMM050_DATAY_LSB_VALUEY__REG BMM050_DATAY_LSB + +/* Data Y SelfTest Register */ +#define BMM050_DATAY_LSB_TESTY__POS 0 +#define BMM050_DATAY_LSB_TESTY__LEN 1 +#define BMM050_DATAY_LSB_TESTY__MSK 0x01 +#define BMM050_DATAY_LSB_TESTY__REG BMM050_DATAY_LSB + +/* Data Z LSB Register */ +#define BMM050_DATAZ_LSB_VALUEZ__POS 1 +#define BMM050_DATAZ_LSB_VALUEZ__LEN 7 +#define BMM050_DATAZ_LSB_VALUEZ__MSK 0xFE +#define BMM050_DATAZ_LSB_VALUEZ__REG BMM050_DATAZ_LSB + +/* Data Z SelfTest Register */ +#define BMM050_DATAZ_LSB_TESTZ__POS 0 +#define BMM050_DATAZ_LSB_TESTZ__LEN 1 +#define BMM050_DATAZ_LSB_TESTZ__MSK 0x01 +#define BMM050_DATAZ_LSB_TESTZ__REG BMM050_DATAZ_LSB + +/* Hall Resistance LSB Register */ +#define BMM050_R_LSB_VALUE__POS 2 +#define BMM050_R_LSB_VALUE__LEN 6 +#define BMM050_R_LSB_VALUE__MSK 0xFC +#define BMM050_R_LSB_VALUE__REG BMM050_R_LSB + +#define BMM050_DATA_RDYSTAT__POS 0 +#define BMM050_DATA_RDYSTAT__LEN 1 +#define BMM050_DATA_RDYSTAT__MSK 0x01 +#define BMM050_DATA_RDYSTAT__REG BMM050_R_LSB + +/* Data X LSB Remapped Register only applicable for BMX055 */ +#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__POS 3 +#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__LEN 5 +#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__MSK 0xF8 +#define BMM050_BMX055_REMAPPED_DATAX_LSB_VALUEX__REG \ + BMM050_BMX055_REMAPPED_DATAX_LSB + +/* Data Y LSB Remapped Register only applicable for BMX055 */ +#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__POS 3 +#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__LEN 5 +#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__MSK 0xF8 +#define BMM050_BMX055_REMAPPED_DATAY_LSB_VALUEY__REG \ + BMM050_BMX055_REMAPPED_DATAY_LSB + +/* Interrupt Status Register */ +#define BMM050_INT_STAT_DOR__POS 7 +#define BMM050_INT_STAT_DOR__LEN 1 +#define BMM050_INT_STAT_DOR__MSK 0x80 +#define BMM050_INT_STAT_DOR__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_OVRFLOW__POS 6 +#define BMM050_INT_STAT_OVRFLOW__LEN 1 +#define BMM050_INT_STAT_OVRFLOW__MSK 0x40 +#define BMM050_INT_STAT_OVRFLOW__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_HIGH_THZ__POS 5 +#define BMM050_INT_STAT_HIGH_THZ__LEN 1 +#define BMM050_INT_STAT_HIGH_THZ__MSK 0x20 +#define BMM050_INT_STAT_HIGH_THZ__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_HIGH_THY__POS 4 +#define BMM050_INT_STAT_HIGH_THY__LEN 1 +#define BMM050_INT_STAT_HIGH_THY__MSK 0x10 +#define BMM050_INT_STAT_HIGH_THY__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_HIGH_THX__POS 3 +#define BMM050_INT_STAT_HIGH_THX__LEN 1 +#define BMM050_INT_STAT_HIGH_THX__MSK 0x08 +#define BMM050_INT_STAT_HIGH_THX__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_LOW_THZ__POS 2 +#define BMM050_INT_STAT_LOW_THZ__LEN 1 +#define BMM050_INT_STAT_LOW_THZ__MSK 0x04 +#define BMM050_INT_STAT_LOW_THZ__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_LOW_THY__POS 1 +#define BMM050_INT_STAT_LOW_THY__LEN 1 +#define BMM050_INT_STAT_LOW_THY__MSK 0x02 +#define BMM050_INT_STAT_LOW_THY__REG BMM050_INT_STAT + +#define BMM050_INT_STAT_LOW_THX__POS 0 +#define BMM050_INT_STAT_LOW_THX__LEN 1 +#define BMM050_INT_STAT_LOW_THX__MSK 0x01 +#define BMM050_INT_STAT_LOW_THX__REG BMM050_INT_STAT + +/* Power Control Register */ +#define BMM050_POWER_CNTL_SRST7__POS 7 +#define BMM050_POWER_CNTL_SRST7__LEN 1 +#define BMM050_POWER_CNTL_SRST7__MSK 0x80 +#define BMM050_POWER_CNTL_SRST7__REG BMM050_POWER_CNTL + +#define BMM050_POWER_CNTL_SPI3_EN__POS 2 +#define BMM050_POWER_CNTL_SPI3_EN__LEN 1 +#define BMM050_POWER_CNTL_SPI3_EN__MSK 0x04 +#define BMM050_POWER_CNTL_SPI3_EN__REG BMM050_POWER_CNTL + +#define BMM050_POWER_CNTL_SRST1__POS 1 +#define BMM050_POWER_CNTL_SRST1__LEN 1 +#define BMM050_POWER_CNTL_SRST1__MSK 0x02 +#define BMM050_POWER_CNTL_SRST1__REG BMM050_POWER_CNTL + +#define BMM050_POWER_CNTL_PCB__POS 0 +#define BMM050_POWER_CNTL_PCB__LEN 1 +#define BMM050_POWER_CNTL_PCB__MSK 0x01 +#define BMM050_POWER_CNTL_PCB__REG BMM050_POWER_CNTL + +/* Control Register */ +#define BMM050_CNTL_ADV_ST__POS 6 +#define BMM050_CNTL_ADV_ST__LEN 2 +#define BMM050_CNTL_ADV_ST__MSK 0xC0 +#define BMM050_CNTL_ADV_ST__REG BMM050_CONTROL + +#define BMM050_CNTL_DR__POS 3 +#define BMM050_CNTL_DR__LEN 3 +#define BMM050_CNTL_DR__MSK 0x38 +#define BMM050_CNTL_DR__REG BMM050_CONTROL + +#define BMM050_CNTL_OPMODE__POS 1 +#define BMM050_CNTL_OPMODE__LEN 2 +#define BMM050_CNTL_OPMODE__MSK 0x06 +#define BMM050_CNTL_OPMODE__REG BMM050_CONTROL + +#define BMM050_CNTL_S_TEST__POS 0 +#define BMM050_CNTL_S_TEST__LEN 1 +#define BMM050_CNTL_S_TEST__MSK 0x01 +#define BMM050_CNTL_S_TEST__REG BMM050_CONTROL + +/* Interrupt Control Register */ +#define BMM050_INT_CNTL_DOR_EN__POS 7 +#define BMM050_INT_CNTL_DOR_EN__LEN 1 +#define BMM050_INT_CNTL_DOR_EN__MSK 0x80 +#define BMM050_INT_CNTL_DOR_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_OVRFLOW_EN__POS 6 +#define BMM050_INT_CNTL_OVRFLOW_EN__LEN 1 +#define BMM050_INT_CNTL_OVRFLOW_EN__MSK 0x40 +#define BMM050_INT_CNTL_OVRFLOW_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_HIGH_THZ_EN__POS 5 +#define BMM050_INT_CNTL_HIGH_THZ_EN__LEN 1 +#define BMM050_INT_CNTL_HIGH_THZ_EN__MSK 0x20 +#define BMM050_INT_CNTL_HIGH_THZ_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_HIGH_THY_EN__POS 4 +#define BMM050_INT_CNTL_HIGH_THY_EN__LEN 1 +#define BMM050_INT_CNTL_HIGH_THY_EN__MSK 0x10 +#define BMM050_INT_CNTL_HIGH_THY_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_HIGH_THX_EN__POS 3 +#define BMM050_INT_CNTL_HIGH_THX_EN__LEN 1 +#define BMM050_INT_CNTL_HIGH_THX_EN__MSK 0x08 +#define BMM050_INT_CNTL_HIGH_THX_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_LOW_THZ_EN__POS 2 +#define BMM050_INT_CNTL_LOW_THZ_EN__LEN 1 +#define BMM050_INT_CNTL_LOW_THZ_EN__MSK 0x04 +#define BMM050_INT_CNTL_LOW_THZ_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_LOW_THY_EN__POS 1 +#define BMM050_INT_CNTL_LOW_THY_EN__LEN 1 +#define BMM050_INT_CNTL_LOW_THY_EN__MSK 0x02 +#define BMM050_INT_CNTL_LOW_THY_EN__REG BMM050_INT_CNTL + +#define BMM050_INT_CNTL_LOW_THX_EN__POS 0 +#define BMM050_INT_CNTL_LOW_THX_EN__LEN 1 +#define BMM050_INT_CNTL_LOW_THX_EN__MSK 0x01 +#define BMM050_INT_CNTL_LOW_THX_EN__REG BMM050_INT_CNTL + +/* Sensor Control Register */ +#define BMM050_SENS_CNTL_DRDY_EN__POS 7 +#define BMM050_SENS_CNTL_DRDY_EN__LEN 1 +#define BMM050_SENS_CNTL_DRDY_EN__MSK 0x80 +#define BMM050_SENS_CNTL_DRDY_EN__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_IE__POS 6 +#define BMM050_SENS_CNTL_IE__LEN 1 +#define BMM050_SENS_CNTL_IE__MSK 0x40 +#define BMM050_SENS_CNTL_IE__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_CHANNELZ__POS 5 +#define BMM050_SENS_CNTL_CHANNELZ__LEN 1 +#define BMM050_SENS_CNTL_CHANNELZ__MSK 0x20 +#define BMM050_SENS_CNTL_CHANNELZ__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_CHANNELY__POS 4 +#define BMM050_SENS_CNTL_CHANNELY__LEN 1 +#define BMM050_SENS_CNTL_CHANNELY__MSK 0x10 +#define BMM050_SENS_CNTL_CHANNELY__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_CHANNELX__POS 3 +#define BMM050_SENS_CNTL_CHANNELX__LEN 1 +#define BMM050_SENS_CNTL_CHANNELX__MSK 0x08 +#define BMM050_SENS_CNTL_CHANNELX__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_DR_POLARITY__POS 2 +#define BMM050_SENS_CNTL_DR_POLARITY__LEN 1 +#define BMM050_SENS_CNTL_DR_POLARITY__MSK 0x04 +#define BMM050_SENS_CNTL_DR_POLARITY__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_INTERRUPT_LATCH__POS 1 +#define BMM050_SENS_CNTL_INTERRUPT_LATCH__LEN 1 +#define BMM050_SENS_CNTL_INTERRUPT_LATCH__MSK 0x02 +#define BMM050_SENS_CNTL_INTERRUPT_LATCH__REG BMM050_SENS_CNTL + +#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__POS 0 +#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__LEN 1 +#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__MSK 0x01 +#define BMM050_SENS_CNTL_INTERRUPT_POLARITY__REG BMM050_SENS_CNTL + +/* Register 6D */ +#define BMM050_DIG_XYZ1_MSB__POS 0 +#define BMM050_DIG_XYZ1_MSB__LEN 7 +#define BMM050_DIG_XYZ1_MSB__MSK 0x7F +#define BMM050_DIG_XYZ1_MSB__REG BMM050_DIG_XYZ1_MSB + +#define BMM050_X_AXIS 0 +#define BMM050_Y_AXIS 1 +#define BMM050_Z_AXIS 2 +#define BMM050_RESISTANCE 3 +#define BMM050_X 1 +#define BMM050_Y 2 +#define BMM050_Z 4 +#define BMM050_XYZ 7 + +/* Constants */ +#define BMM050_NULL 0 +#define BMM050_DISABLE 0 +#define BMM050_ENABLE 1 +#define BMM050_CHANNEL_DISABLE 1 +#define BMM050_CHANNEL_ENABLE 0 +#define BMM050_INTPIN_LATCH_ENABLE 1 +#define BMM050_INTPIN_LATCH_DISABLE 0 +#define BMM050_OFF 0 +#define BMM050_ON 1 + +#define BMM050_NORMAL_MODE 0x00 +#define BMM050_FORCED_MODE 0x01 +#define BMM050_SUSPEND_MODE 0x02 +#define BMM050_SLEEP_MODE 0x03 + +#define BMM050_ADVANCED_SELFTEST_OFF 0 +#define BMM050_ADVANCED_SELFTEST_NEGATIVE 2 +#define BMM050_ADVANCED_SELFTEST_POSITIVE 3 + +#define BMM050_NEGATIVE_SATURATION_Z -32767 +#define BMM050_POSITIVE_SATURATION_Z 32767 + +#define BMM050_SPI_RD_MASK 0x80 +#define BMM050_READ_SET 0x01 + +#define E_BMM050_NULL_PTR ((char) -127) +#define E_BMM050_COMM_RES ((char) -1) +#define E_BMM050_OUT_OF_RANGE ((char) -2) +#define E_BMM050_UNDEFINED_MODE 0 + +#define BMM050_WR_FUNC_PTR \ + char (*bus_write)(unsigned char, unsigned char, \ + unsigned char *, unsigned char) + +#define BMM050_RD_FUNC_PTR \ + char (*bus_read)(unsigned char, unsigned char, \ + unsigned char *, unsigned char) +#define BMM050_MDELAY_DATA_TYPE unsigned int + +/*Shifting Constants*/ +#define SHIFT_RIGHT_1_POSITION 1 +#define SHIFT_RIGHT_2_POSITION 2 +#define SHIFT_RIGHT_3_POSITION 3 +#define SHIFT_RIGHT_4_POSITION 4 +#define SHIFT_RIGHT_5_POSITION 5 +#define SHIFT_RIGHT_6_POSITION 6 +#define SHIFT_RIGHT_7_POSITION 7 +#define SHIFT_RIGHT_8_POSITION 8 + +#define SHIFT_LEFT_1_POSITION 1 +#define SHIFT_LEFT_2_POSITION 2 +#define SHIFT_LEFT_3_POSITION 3 +#define SHIFT_LEFT_4_POSITION 4 +#define SHIFT_LEFT_5_POSITION 5 +#define SHIFT_LEFT_6_POSITION 6 +#define SHIFT_LEFT_7_POSITION 7 +#define SHIFT_LEFT_8_POSITION 8 + +/* Conversion factors*/ +#define BMM050_CONVFACTOR_LSB_UT 6 + +/* get bit slice */ +#define BMM050_GET_BITSLICE(regvar, bitname) \ + ((regvar & bitname ## __MSK) >> bitname ## __POS) + +/* Set bit slice */ +#define BMM050_SET_BITSLICE(regvar, bitname, val) \ + ((regvar & (~bitname ## __MSK)) | (((val) << bitname ## __POS) & bitname ## __MSK)) + +/* compensated output value returned if sensor had overflow */ +#define BMM050_OVERFLOW_OUTPUT -32768 +#define BMM050_OVERFLOW_OUTPUT_S32 ((BMM050_S32) (-2147483647 - 1)) +#define BMM050_OVERFLOW_OUTPUT_FLOAT 0.0f +#define BMM050_FLIP_OVERFLOW_ADCVAL -4096 +#define BMM050_HALL_OVERFLOW_ADCVAL -16384 + +#define BMM050_PRESETMODE_LOWPOWER 1 +#define BMM050_PRESETMODE_REGULAR 2 +#define BMM050_PRESETMODE_HIGHACCURACY 3 +#define BMM050_PRESETMODE_ENHANCED 4 + +/* PRESET MODES - DATA RATES */ +#define BMM050_LOWPOWER_DR BMM050_DR_10HZ +#define BMM050_REGULAR_DR BMM050_DR_10HZ +#define BMM050_HIGHACCURACY_DR BMM050_DR_20HZ +#define BMM050_ENHANCED_DR BMM050_DR_10HZ + +/* PRESET MODES - REPETITIONS-XY RATES */ +#define BMM050_LOWPOWER_REPXY 1 +#define BMM050_REGULAR_REPXY 4 +#define BMM050_HIGHACCURACY_REPXY 23 +#define BMM050_ENHANCED_REPXY 7 + +/* PRESET MODES - REPETITIONS-Z RATES */ +#define BMM050_LOWPOWER_REPZ 2 +#define BMM050_REGULAR_REPZ 14 +#define BMM050_HIGHACCURACY_REPZ 82 +#define BMM050_ENHANCED_REPZ 26 + +/* Data Rates */ + +#define BMM050_DR_10HZ 0 +#define BMM050_DR_02HZ 1 +#define BMM050_DR_06HZ 2 +#define BMM050_DR_08HZ 3 +#define BMM050_DR_15HZ 4 +#define BMM050_DR_20HZ 5 +#define BMM050_DR_25HZ 6 +#define BMM050_DR_30HZ 7 + +/*user defined Structures*/ +struct bmm050_mdata { + BMM050_S16 datax; + BMM050_S16 datay; + BMM050_S16 dataz; + BMM050_U16 resistance; +}; + +struct bmm050_mdata_s32 { + BMM050_S32 datax; + BMM050_S32 datay; + BMM050_S32 dataz; + BMM050_U16 resistance; +}; + +struct bmm050_mdata_float { + float datax; + float datay; + float dataz; + BMM050_U16 resistance; +}; + +/*user defined Structures for remapped functions + * this only applicable for BMX055*/ +struct bmm050_remapped_mdata { + BMM050_S16 datax; + BMM050_S16 datay; + BMM050_S16 dataz; + BMM050_U16 resistance; +}; + +struct bmm050_remapped_mdata_s32 { + BMM050_S32 datax; + BMM050_S32 datay; + BMM050_S32 dataz; + BMM050_U16 resistance; +}; + +struct bmm050_remapped_mdata_float { + float datax; + float datay; + float dataz; + BMM050_U16 resistance; +}; + +struct bmm050 { + unsigned char company_id; + unsigned char dev_addr; + + BMM050_WR_FUNC_PTR; + BMM050_RD_FUNC_PTR; + void (*delay_msec)(BMM050_MDELAY_DATA_TYPE); + + signed char dig_x1; + signed char dig_y1; + + signed char dig_x2; + signed char dig_y2; + + BMM050_U16 dig_z1; + BMM050_S16 dig_z2; + BMM050_S16 dig_z3; + BMM050_S16 dig_z4; + + unsigned char dig_xy1; + signed char dig_xy2; + + BMM050_U16 dig_xyz1; +}; + +BMM050_RETURN_FUNCTION_TYPE bmm050_init(struct bmm050 *p_bmm050); + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ( + struct bmm050_mdata *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_s32( + struct bmm050_mdata_s32 *mdata); + +#ifdef ENABLE_FLOAT +BMM050_RETURN_FUNCTION_TYPE bmm050_read_mdataXYZ_float( + struct bmm050_mdata_float *mdata); + +#endif +BMM050_RETURN_FUNCTION_TYPE bmm050_read_register( + unsigned char addr, unsigned char *data, unsigned char len); + +BMM050_RETURN_FUNCTION_TYPE bmm050_write_register( + unsigned char addr, unsigned char *data, unsigned char len); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_self_test_XYZ( + unsigned char *self_testxyz); + +BMM050_S16 bmm050_compensate_X( + BMM050_S16 mdata_x, BMM050_U16 data_R); + +BMM050_S32 bmm050_compensate_X_s32( + BMM050_S16 mdata_x, BMM050_U16 data_R); + +#ifdef ENABLE_FLOAT +float bmm050_compensate_X_float( + BMM050_S16 mdata_x, BMM050_U16 data_R); + +#endif +BMM050_S16 bmm050_compensate_Y( + BMM050_S16 mdata_y, BMM050_U16 data_R); + +BMM050_S32 bmm050_compensate_Y_s32( + BMM050_S16 mdata_y, BMM050_U16 data_R); + +#ifdef ENABLE_FLOAT +float bmm050_compensate_Y_float( + BMM050_S16 mdata_y, BMM050_U16 data_R); + +#endif +BMM050_S16 bmm050_compensate_Z( + BMM050_S16 mdata_z, BMM050_U16 data_R); + +BMM050_S32 bmm050_compensate_Z_s32( + BMM050_S16 mdata_z, BMM050_U16 data_R); + +#ifdef ENABLE_FLOAT +float bmm050_compensate_Z_float( + BMM050_S16 mdata_z, BMM050_U16 data_R); + +#endif +BMM050_RETURN_FUNCTION_TYPE bmm050_get_raw_xyz( + struct bmm050_mdata *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_init_trim_registers(void); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_spi3( + unsigned char value); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_powermode( + unsigned char *mode); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_powermode( + unsigned char mode); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_adv_selftest( + unsigned char adv_selftest); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_adv_selftest( + unsigned char *adv_selftest); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_datarate( + unsigned char data_rate); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_datarate( + unsigned char *data_rate); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_functional_state( + unsigned char functional_state); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_functional_state( + unsigned char *functional_state); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_selftest( + unsigned char selftest); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_selftest( + unsigned char *selftest); + +BMM050_RETURN_FUNCTION_TYPE bmm050_perform_advanced_selftest( + BMM050_S16 *diff_z); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_XY( + unsigned char *no_repetitions_xy); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_XY( + unsigned char no_repetitions_xy); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_repetitions_Z( + unsigned char *no_repetitions_z); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_repetitions_Z( + unsigned char no_repetitions_z); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_presetmode(unsigned char *mode); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_presetmode(unsigned char mode); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_x( + unsigned char enable_disable); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_control_measurement_y( + unsigned char enable_disable); + +BMM050_RETURN_FUNCTION_TYPE bmm050_soft_reset(void); + +BMM050_RETURN_FUNCTION_TYPE bmm050_get_bmx055_remapped_raw_xyz \ + (struct bmm050_remapped_mdata *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_float \ + (struct bmm050_remapped_mdata_float *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ_s32 \ + (struct bmm050_remapped_mdata_s32 *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_read_bmx055_remapped_mdataXYZ \ + (struct bmm050_remapped_mdata *mdata); + +BMM050_RETURN_FUNCTION_TYPE bmm050_set_mag_drdy_interrupt \ + (unsigned char enable_disable, + unsigned char active_low0_high1); + +#endif diff --git a/embedded/common/modules/sensor-drivers/bmp280.c b/embedded/common/modules/sensor-drivers/bmp280.c index f30f8ac..c02d81d 100644 --- a/embedded/common/modules/sensor-drivers/bmp280.c +++ b/embedded/common/modules/sensor-drivers/bmp280.c @@ -1,1580 +1,1580 @@ -/* - ***************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - ****************************************************************************/ -/* Date: 2013/05/06 - * Revision: 1.3 (Pressure and Temperature compensation code is revision 1.1) - * - */ - -/***************************************************************************** -* Copyright (C) 2007 Bosch Sensortec GmbH -* -* -* -* Usage: -* -*****************************************************************************/ -/****************************************************************************/ -/* Disclaimer -* -* Common: -* Bosch Sensortec products are developed for the consumer goods industry. -* They may only be used within the parameters of the respective valid -* product data sheet. Bosch Sensortec products are provided with the -* express understanding that there is no warranty of fitness for a -* particular purpose.They are not fit for use in life-sustaining, -* safety or security sensitive systems or any system or device -* that may lead to bodily harm or property damage if the system -* or device malfunctions. In addition,Bosch Sensortec products are -* not fit for use in products which interact with motor vehicle systems. -* The resale and or use of products are at the purchasers own risk and -* his own responsibility. The examination of fitness for the intended use -* is the sole responsibility of the Purchaser. -* -* The purchaser shall indemnify Bosch Sensortec from all third party -* claims, including any claims for incidental, or consequential damages, -* arising from any product use not covered by the parameters of -* the respective valid product data sheet or not approved by -* Bosch Sensortec and reimburse Bosch Sensortec for all costs in -* connection with such claims. -* -* The purchaser must monitor the market for the purchased products, -* particularly with regard to product safety and inform Bosch Sensortec -* without delay of all security relevant incidents. -* -* Engineering Samples are marked with an asterisk (*) or (e). -* Samples may vary from the valid technical specifications of the product -* series. They are therefore not intended or fit for resale to third -* parties or for use in end products. Their sole purpose is internal -* client testing. The testing of an engineering sample may in no way -* replace the testing of a product series. Bosch Sensortec assumes -* no liability for the use of engineering samples. -* By accepting the engineering samples, the Purchaser agrees to indemnify -* Bosch Sensortec from all claims arising from the use of engineering -* samples. -* -* Special: -* This software module (hereinafter called "Software") and any information -* on application-sheets (hereinafter called "Information") is provided -* free of charge for the sole purpose to support your application work. -* The Software and Information is subject to the following -* terms and conditions: -* -* The Software is specifically designed for the exclusive use for -* Bosch Sensortec products by personnel who have special experience -* and training. Do not use this Software if you do not have the -* proper experience or training. -* -* This Software package is provided `` as is `` and without any expressed -* or implied warranties,including without limitation, the implied warranties -* of merchantability and fitness for a particular purpose. -* -* Bosch Sensortec and their representatives and agents deny any liability -* for the functional impairment -* of this Software in terms of fitness, performance and safety. -* Bosch Sensortec and their representatives and agents shall not be liable -* for any direct or indirect damages or injury, except as -* otherwise stipulated in mandatory applicable law. - -* The Information provided is believed to be accurate and reliable. -* Bosch Sensortec assumes no responsibility for the consequences of use -* of such Information nor for any infringement of patents or -* other rights of third parties which may result from its use. -* No license is granted by implication or otherwise under any patent or -* patent rights of Bosch. Specifications mentioned in the Information are -* subject to change without notice. -* -* It is not allowed to deliver the source code of the Software -* to any third party without permission of -* Bosch Sensortec. -*/ -/****************************************************************************/ - -#include "bmp280.h" -#include "sensorhub.h" -#include "common.h" -#include "osp-sensors.h" -#include "sensacq_i2c.h" -#include "pressure_common.h" - -static struct bmp280_t *p_bmp280; /**< pointer to BMP280 */ -/* Compiler Switch if applicable -#ifdef - -#endif -*/ - -static struct bmp280_t bmp280; -void Pressure_HardwareSetup(osp_bool_t enable) -{ -} - -void Pressure_Initialize() -{ - MsgPressData p; - bmp280.bus_write = dev_i2c_write; - bmp280.bus_read = dev_i2c_read; - bmp280.delay_msec = dev_i2c_delay; - - bmp280_init(&bmp280); - bmp280_set_softreset(); - bmp280_set_workmode(BMP280_ULTRALOWPOWER_MODE); - /* pressure_setDelay(pSens, 1000) */ -#if 0 - bmp280_set_mode(BMP280_SLEEP_MODE); -#else - bmp280_set_mode(BMP280_NORMAL_MODE); - Pressure_ReadData(&p); -#endif -} - -void Pressure_ReadData(MsgPressData *pressData) -{ - bmp280_read_pt((uint32_t *)&pressData->X, (int32_t *)&pressData->Z); -} - -/******************************************************************************* - * Description: *//**\brief routine to initialize the function pointers - * - * - * - * - * \param - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - p_bmp280 = bmp280; /* assign BMP280 ptr */ - p_bmp280->dev_addr = BMP280_I2C_ADDRESS; /* preset BMP280 I2C_addr */ - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CHIPID_REG, &v_data_u8r, 1); /* read Chip Id */ - p_bmp280->chip_id = v_data_u8r; - - bmp280_get_calib_param(); /* readout bmp280 calibparam structure */ - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief reads uncompensated temperature - * - * - * - * - * \param unsigned long temperature : Pointer to the data - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_ut(BMP280_S32_t *utemperature) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[3] = {0}; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_TEMPERATURE_MSB_REG, a_data_u8r, 3); - *utemperature = (BMP280_S32_t)((( \ - (BMP280_U32_t) (a_data_u8r[0])) << SHIFT_LEFT_12_POSITION) | \ - (((BMP280_U32_t)(a_data_u8r[1])) << SHIFT_LEFT_4_POSITION) \ - | ((BMP280_U32_t)a_data_u8r[2] >> SHIFT_RIGHT_4_POSITION)); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Reads actual temperature from uncompensated temperature - * and returns the value in 0.01 degree Centigrade - * Output value of "5123" equals 51.23 DegC. - * - * - * - * \param signed long : value of uncompensated temperature - * - * - * - * \return - * signed long : actual temperature - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_S32_t bmp280_compensate_T_int32(BMP280_S32_t adc_T) -{ - BMP280_S32_t v_x1_u32r = 0; - BMP280_S32_t v_x2_u32r = 0; - BMP280_S32_t temperature = 0; - - v_x1_u32r = ((((adc_T >> 3) - ((BMP280_S32_t) - p_bmp280->cal_param.dig_T1 << 1))) * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_T2)) >> 11; - v_x2_u32r = (((((adc_T >> 4) - \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_T1)) * ((adc_T >> 4) - \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_T1))) >> 12) * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_T3)) >> 14; - p_bmp280->cal_param.t_fine = v_x1_u32r + v_x2_u32r; - temperature = (p_bmp280->cal_param.t_fine * 5 + 128) >> 8; - - return temperature; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief reads uncompensated pressure - * - * - * - * - * \param unsigned long pressure : Pointer to the data - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_up(BMP280_S32_t *upressure) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[3] = {0}; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_PRESSURE_MSB_REG, a_data_u8r, 3); - *upressure = (BMP280_S32_t)((((BMP280_U32_t)(a_data_u8r[0])) \ - << SHIFT_LEFT_12_POSITION) | (((BMP280_U32_t)(a_data_u8r[1])) \ - << SHIFT_LEFT_4_POSITION) | ((BMP280_U32_t)a_data_u8r[2] >>\ - SHIFT_RIGHT_4_POSITION)); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Reads actual pressure from uncompensated pressure - * and returns the value in Pascal(Pa) - * Output value of "96386" equals 96386 Pa = - * 963.86 hPa = 963.86 millibar - - * - * - * - * \param signed long : value of uncompensated pressure - * - * - * - * \return - * unsigned long : actual pressure - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -unsigned int bmp280_compensate_P_int32(BMP280_S32_t adc_P) -{ - BMP280_S32_t v_x1_u32r = 0; - BMP280_S32_t v_x2_u32r = 0; - BMP280_U32_t pressure = 0; - - v_x1_u32r = (((BMP280_S32_t)p_bmp280->cal_param.t_fine) >> 1) - \ - (BMP280_S32_t)64000; - v_x2_u32r = (((v_x1_u32r >> 2) * (v_x1_u32r >> 2)) >> 11) * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_P6); - v_x2_u32r = v_x2_u32r + ((v_x1_u32r * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_P5)) << 1); - v_x2_u32r = (v_x2_u32r >> 2) + \ - (((BMP280_S32_t)p_bmp280->cal_param.dig_P4) << 16); - v_x1_u32r = (((p_bmp280->cal_param.dig_P3 * (((v_x1_u32r >> 2) * \ - (v_x1_u32r >> 2)) >> 13)) >> 3) + \ - ((((BMP280_S32_t)p_bmp280->cal_param.dig_P2) * \ - v_x1_u32r) >> 1)) >> 18; - v_x1_u32r = ((((32768+v_x1_u32r)) * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_P1)) >> 15); - if (v_x1_u32r == 0) - return 0; /* Avoid exception caused by division by zero */ - pressure = (((BMP280_U32_t)(((BMP280_S32_t)1048576) - adc_P) - \ - (v_x2_u32r >> 12))) * 3125; - if (pressure < 0x80000000) - pressure = (pressure << 1) / ((BMP280_U32_t)v_x1_u32r); - else - pressure = (pressure / (BMP280_U32_t)v_x1_u32r) * 2; - v_x1_u32r = (((BMP280_S32_t)p_bmp280->cal_param.dig_P9) * \ - ((BMP280_S32_t)(((pressure >> 3) * (pressure >> 3)) >> 13))) \ - >> 12; - v_x2_u32r = (((BMP280_S32_t)(pressure >> 2)) * \ - ((BMP280_S32_t)p_bmp280->cal_param.dig_P8)) >> 13; - pressure = (BMP280_U32_t)((BMP280_S32_t)pressure + \ - ((v_x1_u32r + v_x2_u32r + p_bmp280->cal_param.dig_P7) >> 4)); - - return pressure; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief reads uncompensated pressure and temperature - * - * - * - * - * \param unsigned long utemperature : Address of uncompensated temperature - * unsigned long upressure : Address of uncompensated pressure - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_uput(BMP280_S32_t *upressure,\ - BMP280_S32_t *utemperature) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[6] = {0}; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_PRESSURE_MSB_REG, a_data_u8r, 6); - *upressure = (BMP280_S32_t)((((BMP280_U32_t)(a_data_u8r[0])) \ - << SHIFT_LEFT_12_POSITION) | (((BMP280_U32_t)(a_data_u8r[1])) \ - << SHIFT_LEFT_4_POSITION) | ((BMP280_U32_t)a_data_u8r[2] >>\ - SHIFT_RIGHT_4_POSITION)); - - /* Temperature */ - *utemperature = (BMP280_S32_t)((( \ - (BMP280_U32_t) (a_data_u8r[3])) << SHIFT_LEFT_12_POSITION) | \ - (((BMP280_U32_t)(a_data_u8r[4])) << SHIFT_LEFT_4_POSITION) \ - | ((BMP280_U32_t)a_data_u8r[5] >> SHIFT_RIGHT_4_POSITION)); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief reads pressure and temperature - * - * - * - * - * \param unsigned long temperature : Address of temperature - * unsigned long pressure : Address of pressure - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_pt(BMP280_U32_t *pressure,\ - BMP280_S32_t *temperature) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - BMP280_S32_t upressure = 0; - BMP280_S32_t utemperature = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = bmp280_read_uput(&upressure, &utemperature); - *temperature = bmp280_compensate_T_int32(utemperature); - *pressure = bmp280_compensate_P_int32(upressure); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief reads calibration parameters used for calculation - * - * - * - * - * \param None - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param() -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char a_data_u8r[26] = {0}; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_DIG_T1_LSB_REG, a_data_u8r, 24); - - p_bmp280->cal_param.dig_T1 = (BMP280_U16_t)(((\ - (BMP280_U16_t)((unsigned char)a_data_u8r[1])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); - p_bmp280->cal_param.dig_T2 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[3])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[2]); - p_bmp280->cal_param.dig_T3 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[5])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[4]); - p_bmp280->cal_param.dig_P1 = (BMP280_U16_t)(((\ - (BMP280_U16_t)((unsigned char)a_data_u8r[7])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[6]); - p_bmp280->cal_param.dig_P2 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[9])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[8]); - p_bmp280->cal_param.dig_P3 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[11])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[10]); - p_bmp280->cal_param.dig_P4 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[13])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[12]); - p_bmp280->cal_param.dig_P5 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[15])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[14]); - p_bmp280->cal_param.dig_P6 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[17])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[16]); - p_bmp280->cal_param.dig_P7 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[19])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[18]); - p_bmp280->cal_param.dig_P8 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[21])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[20]); - p_bmp280->cal_param.dig_P9 = (BMP280_S16_t)(((\ - (BMP280_S16_t)((signed char)a_data_u8r[23])) << \ - SHIFT_LEFT_8_POSITION) | a_data_u8r[22]); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to get the Oversampling temperature - * - * - * - * - * \param unsigned char value : Pointer to the osrs_t - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_osrs_t(\ - unsigned char *value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); - *value = BMP280_GET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRST); - - p_bmp280->osrs_t = *value; - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to set the Oversampling temperature - * - * - * - * - * \param unsigned char value : Value of the Oversampling temperature - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_osrs_t(\ - unsigned char value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRST, value); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); - - p_bmp280->osrs_t = value; - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to get the Oversampling pressure - * - * - * - * - * \param * \param unsigned char value : Pointer to the value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_osrs_p(\ - unsigned char *value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); - *value = BMP280_GET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRSP); - - p_bmp280->osrs_p = *value; - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to set the Oversampling pressure - * - * - * - * - * \param unsigned char value : Value of the Oversampling pressure - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_osrs_p(\ - unsigned char value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRSP, value); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); - - p_bmp280->osrs_p = value; - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to get the Operational Mode from the sensor - * - * - * - * - * \param * \param unsigned char mode : Pointer to the value - * 0 -> BMP280_SLEEP_MODE - * 1 and 2 -> BMP280_FORCED_MODE - * 3 -> BMP280_NORMAL_MODE - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_mode(unsigned char *mode) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_mode_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_MODE__REG, &v_mode_u8r, 1); - *mode = BMP280_GET_BITSLICE(v_mode_u8r, \ - BMP280_CTRLMEAS_REG_MODE); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to set the Operational Mode for the sensor - * - * - * - * - * \param unsigned char mode : Value of the mode - * 0 -> BMP280_SLEEP_MODE - * 1 and 2 -> BMP280_FORCED_MODE - * 3 -> BMP280_NORMAL_MODE - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_mode(unsigned char mode) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_mode_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - if (mode < BMA280_Four_U8X) { - v_mode_u8r = (p_bmp280->osrs_t << \ - SHIFT_LEFT_5_POSITION) + (p_bmp280->osrs_p << \ - SHIFT_LEFT_2_POSITION) + mode; - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ - p_bmp280->dev_addr, \ - BMP280_CTRLMEAS_REG_MODE__REG, &v_mode_u8r, 1); - } else { - comres = E_BMP280_OUT_OF_RANGE; - } - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Used to reset the sensor - * - * The value 0xB6 is written to the 0xE0 register the device is reset using the - * complete power-on-reset procedure. - * Soft reset can be easily set using BMP280_SOFT_RESET_CODE . - * Usage Hint : bme280_set_softreset(BMP280_SOFT_RESET_CODE) - * - * \param - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_softreset() -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = BMP280_SOFT_RESET_CODE; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_RESET_REG, &v_data_u8r, 1); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Gets the sensor communication type - * - * - * - * - * \param unsigned char *enable_disable : Pointer to the value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(unsigned char *enable_disable) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); - *enable_disable = BMP280_GET_BITSLICE(v_data_u8r, \ - BMP280_CONFIG_REG_SPI3WEN); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Sets the sensor communication type to 3 wire SPI - * - * - * - * - * \param unsigned char enable_disable : Value of the enable or disable - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(unsigned char enable_disable) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CONFIG_REG_SPI3WEN, enable_disable); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Reads filter setting value - * - * - * - * - * \param * \param unsigned char *value : Pointer to value - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(unsigned char *value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); - *value = BMP280_GET_BITSLICE(v_data_u8r, \ - BMP280_CONFIG_REG_FILTER); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Writes filter setting to sensor - * - * - * - * - * \param unsigned char value : Value of the filter setting - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(unsigned char value) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CONFIG_REG_FILTER, value); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Reads standby duration time from the sensor - * - * \param * \param unsigned char *time : Pointer to the time - * 0x00 - BMP280_STANDBYTIME_1_MS - * 0x01 - BMP280_STANDBYTIME_63_MS - * 0x02 - BMP280_STANDBYTIME_125_MS - * 0x03 - BMP280_STANDBYTIME_250_MS - * 0x04 - BMP280_STANDBYTIME_500_MS - * 0x05 - BMP280_STANDBYTIME_1000_MS - * 0x06 - BMP280_STANDBYTIME_2000_MS - * 0x07 - BMP280_STANDBYTIME_4000_MS - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_standbydur(unsigned char *time) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); - *time = BMP280_GET_BITSLICE(v_data_u8r, BMP280_CONFIG_REG_TSB); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Writes standby duration time from the sensor - * - * Normal mode comprises an automated perpetual cycling between an (active) - * Measurement period and an (inactive) standby period. - * The standby time is determined by the contents of the register t_sb. - * Standby time can be set using BME280_STANDBYTIME_125_MS. - * - * Usage Hint : bme280_set_standbydur(BME280_STANDBYTIME_125_MS) - * - * \param unsigned char time : Value of the standby duration - * 0x00 - BMP280_STANDBYTIME_1_MS - * 0x01 - BMP280_STANDBYTIME_63_MS - * 0x02 - BMP280_STANDBYTIME_125_MS - * 0x03 - BMP280_STANDBYTIME_250_MS - * 0x04 - BMP280_STANDBYTIME_500_MS - * 0x05 - BMP280_STANDBYTIME_1000_MS - * 0x06 - BMP280_STANDBYTIME_2000_MS - * 0x07 - BMP280_STANDBYTIME_4000_MS - * - * - * \param unsigned char time : Value of the standby duration - * - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_standbydur(unsigned char time) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CONFIG_REG_TSB, time); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ - BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Writes the working mode to the sensor - * - * - * - * - * \param unsigned char : Mode to be set - * 0 -> BMP280_ULTRALOWPOWER_MODE - * 1 -> BMP280_LOWPOWER_MODE - * 2 -> BMP280_STANDARDRESOLUTION_MODE - * 3 -> BMP280_HIGHRESOLUTION_MODE - * 4 -> BMP280_ULTRAHIGHRESOLUTION_MODE - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_set_workmode(unsigned char mode) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - if (mode <= BMA280_Four_U8X) { - comres += p_bmp280->BMP280_BUS_READ_FUNC(\ - p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ - &v_data_u8r, 1); - switch (mode) { - case BMP280_ULTRALOWPOWER_MODE: - p_bmp280->osrs_t = BMP280_ULTRALOWPOWER_OSRS_T; - p_bmp280->osrs_p = BMP280_ULTRALOWPOWER_OSRS_P; - break; - case BMP280_LOWPOWER_MODE: - p_bmp280->osrs_t = BMP280_LOWPOWER_OSRS_T; - p_bmp280->osrs_p = BMP280_LOWPOWER_OSRS_P; - break; - case BMP280_STANDARDRESOLUTION_MODE: - p_bmp280->osrs_t = \ - BMP280_STANDARDRESOLUTION_OSRS_T; - p_bmp280->osrs_p = \ - BMP280_STANDARDRESOLUTION_OSRS_P; - break; - case BMP280_HIGHRESOLUTION_MODE: - p_bmp280->osrs_t = BMP280_HIGHRESOLUTION_OSRS_T; - p_bmp280->osrs_p = BMP280_HIGHRESOLUTION_OSRS_P; - break; - case BMP280_ULTRAHIGHRESOLUTION_MODE: - p_bmp280->osrs_t = \ - BMP280_ULTRAHIGHRESOLUTION_OSRS_T; - p_bmp280->osrs_p = \ - BMP280_ULTRAHIGHRESOLUTION_OSRS_P; - break; - } - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRST, p_bmp280->osrs_t); - v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ - BMP280_CTRLMEAS_REG_OSRSP, p_bmp280->osrs_p); - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ - p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ - &v_data_u8r, 1); - } else { - comres = E_BMP280_OUT_OF_RANGE; - } - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief Read both uncompensated temperature and pressure - * in forced mode - * - * - * - * \param unsigned long utemperature : Address of uncompensated temperature - * unsigned long pressure : Address of uncompensated pressure - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_get_forced_uput(BMP280_S32_t *upressure,\ - BMP280_S32_t *utemperature) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - unsigned char v_data_u8r = 0; - unsigned char v_waittime_u8r = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - v_data_u8r = (p_bmp280->osrs_t << SHIFT_LEFT_5_POSITION) + \ - (p_bmp280->osrs_p << SHIFT_LEFT_2_POSITION) + \ - BMP280_FORCED_MODE; - comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ - p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ - &v_data_u8r, 1); - bmp280_compute_wait_time(&v_waittime_u8r); - p_bmp280->delay_msec(v_waittime_u8r); - comres += bmp280_read_uput(upressure, utemperature); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief This API gives data to the given register and - * the data is written in the corresponding register - * address - * - * - * - * \param unsigned char addr, unsigned char data, unsigned char len - * addr -> Address of the register - * data -> Data to be written to the register - * len -> Length of the Data - * - * - * - * \return communication results. - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(unsigned char addr, - unsigned char *data, unsigned char len) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, - addr, data, len); - } - return comres; -} -/* Compiler Switch if applicable -#ifdef - -#endif -*/ -/******************************************************************************* - * Description: *//**\brief This API reads the data from the given register - * address - * - * - * - * \param unsigned char addr, unsigned char *data, unsigned char len - * addr -> Address of the register - * data -> address of the variable, read value will be kept - * len -> Length of the data - * - * - * - * - * \return results of communication routine - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(unsigned char addr, - unsigned char *data, unsigned char len) -{ - BMP280_RETURN_FUNCTION_TYPE comres; - if (p_bmp280 == BMP280_NULL) { - comres = E_BMP280_NULL_PTR; - } else { - comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, - addr, data, len); - } - return comres; -} -#ifdef BMP280_ENABLE_FLOAT -/******************************************************************************* - * Description: *//**\brief Reads actual temperature from uncompensated temperature - * and returns the value in Degree centigrade - * Output value of "51.23" equals 51.23 DegC. - * - * - * - * \param signed long : value of uncompensated temperature - * - * - * - * \return - * double : actual temperature in floating point - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -double bmp280_compensate_T_double(BMP280_S32_t adc_T) -{ - double v_x1_u32r = 0; - double v_x2_u32r = 0; - double temperature = 0; - - v_x1_u32r = (((double)adc_T) / 16384.0 - \ - ((double)p_bmp280->cal_param.dig_T1) / 1024.0) * \ - ((double)p_bmp280->cal_param.dig_T2); - v_x2_u32r = ((((double)adc_T) / 131072.0 - \ - ((double)p_bmp280->cal_param.dig_T1) / 8192.0) * \ - (((double)adc_T) / 131072.0 - \ - ((double)p_bmp280->cal_param.dig_T1) / 8192.0)) * \ - ((double)p_bmp280->cal_param.dig_T3); - p_bmp280->cal_param.t_fine = (BMP280_S32_t)(v_x1_u32r + v_x2_u32r); - temperature = (v_x1_u32r + v_x2_u32r) / 5120.0; - - - return temperature; -} -/******************************************************************************* - * Description: *//**\brief Reads actual pressure from uncompensated pressure - * and returns pressure in Pa as double. - * Output value of "96386.2" - * equals 96386.2 Pa = 963.862 hPa. - * - * - * - * \param signed int : value of uncompensated pressure - * - * - * - * \return - * double : actual pressure in floating point - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -double bmp280_compensate_P_double(BMP280_S32_t adc_P) -{ - double v_x1_u32r = 0; - double v_x2_u32r = 0; - double pressure = 0; - - v_x1_u32r = ((double)p_bmp280->cal_param.t_fine/2.0) - 64000.0; - v_x2_u32r = v_x1_u32r * v_x1_u32r * \ - ((double)p_bmp280->cal_param.dig_P6) / 32768.0; - v_x2_u32r = v_x2_u32r + v_x1_u32r * \ - ((double)p_bmp280->cal_param.dig_P5) * 2.0; - v_x2_u32r = (v_x2_u32r / 4.0) + \ - (((double)p_bmp280->cal_param.dig_P4) * 65536.0); - v_x1_u32r = (((double)p_bmp280->cal_param.dig_P3) * \ - v_x1_u32r * v_x1_u32r / 524288.0 + \ - ((double)p_bmp280->cal_param.dig_P2) * v_x1_u32r) / 524288.0; - v_x1_u32r = (1.0 + v_x1_u32r / 32768.0) * \ - ((double)p_bmp280->cal_param.dig_P1); - if (v_x1_u32r == 0.0) - return 0; /* Avoid exception caused by division by zero */ - pressure = 1048576.0 - (double)adc_P; - pressure = (pressure - (v_x2_u32r / 4096.0)) * 6250.0 / v_x1_u32r; - v_x1_u32r = ((double)p_bmp280->cal_param.dig_P9) * \ - pressure * pressure / 2147483648.0; - v_x2_u32r = pressure * ((double)p_bmp280->cal_param.dig_P8) / 32768.0; - pressure = pressure + (v_x1_u32r + v_x2_u32r + \ - ((double)p_bmp280->cal_param.dig_P7)) / 16.0; - - return pressure; -} -#endif -#if defined(BMP280_ENABLE_INT64) && defined(BMP280_64BITSUPPORT_PRESENT) -/******************************************************************************* - * Description: *//**\brief Reads actual pressure from uncompensated pressure - * and returns the value in Pa as unsigned 32 bit - * integer in Q24.8 format (24 integer bits and - * 8 fractional bits). Output value of "24674867" - * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa - * - * - * - * \param signed long : value of uncompensated temperature - * - * - * - * \return - * unsigned long : actual pressure - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ******************************************************************************/ -BMP280_U32_t bmp280_compensate_P_int64(BMP280_S32_t adc_P) -{ - BMP280_S64_t v_x1_s64r = 0; - BMP280_S64_t v_x2_s64r = 0; - BMP280_S64_t pressure = 0; - v_x1_s64r = ((BMP280_S64_t)p_bmp280->cal_param.t_fine) - 128000; - v_x2_s64r = v_x1_s64r * v_x1_s64r * \ - (BMP280_S64_t)p_bmp280->cal_param.dig_P6; - v_x2_s64r = v_x2_s64r + ((v_x1_s64r * \ - (BMP280_S64_t)p_bmp280->cal_param.dig_P5) << 17); - v_x2_s64r = v_x2_s64r + \ - (((BMP280_S64_t)p_bmp280->cal_param.dig_P4) << 35); - v_x1_s64r = ((v_x1_s64r * v_x1_s64r * \ - (BMP280_S64_t)p_bmp280->cal_param.dig_P3) >> 8) + \ - ((v_x1_s64r * (BMP280_S64_t)p_bmp280->cal_param.dig_P2) << 12); - v_x1_s64r = (((((BMP280_S64_t)1) << 47) + v_x1_s64r)) * \ - ((BMP280_S64_t)p_bmp280->cal_param.dig_P1) >> 33; - if (v_x1_s64r == 0) - return 0; /* Avoid exception caused by division by zero */ - pressure = 1048576 - adc_P; - pressure = (((pressure << 31) - v_x2_s64r) * 3125) / v_x1_s64r; - v_x1_s64r = (((BMP280_S64_t)p_bmp280->cal_param.dig_P9) * \ - (pressure >> 13) * (pressure >> 13)) >> 25; - v_x2_s64r = (((BMP280_S64_t)p_bmp280->cal_param.dig_P8) * \ - pressure) >> 19; - pressure = ((pressure + v_x1_s64r + v_x2_s64r) >> 8) + \ - (((BMP280_S64_t)p_bmp280->cal_param.dig_P7) << 4); - return (BMP280_U32_t)pressure; -} -#endif -/******************************************************************************* - * Description: *//**\brief Computing waiting time for sensor data read - * - * - * - * - * \param - * unsigned char : value of time - * - * - * \return - * - * - ******************************************************************************/ -/* Scheduling: - * - * - * - * Usage guide: - * - * - * Remarks: - * - ****************************************************************************/ -BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(unsigned char \ - *v_delaytime_u8r) -{ - BMP280_RETURN_FUNCTION_TYPE comres = 0; - - *v_delaytime_u8r = (T_INIT_MAX + T_MEASURE_PER_OSRS_MAX * \ - (((1 << p_bmp280->osrs_t) >> 1) + ((1 << p_bmp280->osrs_p) \ - >> 1)) + (p_bmp280->osrs_p ? T_SETUP_PRESSURE_MAX : 0) + 15) \ - / 16; - return comres; -} +/* + ***************************************************************************** + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + ****************************************************************************/ +/* Date: 2013/05/06 + * Revision: 1.3 (Pressure and Temperature compensation code is revision 1.1) + * + */ + +/***************************************************************************** +* Copyright (C) 2007 Bosch Sensortec GmbH +* +* +* +* Usage: +* +*****************************************************************************/ +/****************************************************************************/ +/* Disclaimer +* +* Common: +* Bosch Sensortec products are developed for the consumer goods industry. +* They may only be used within the parameters of the respective valid +* product data sheet. Bosch Sensortec products are provided with the +* express understanding that there is no warranty of fitness for a +* particular purpose.They are not fit for use in life-sustaining, +* safety or security sensitive systems or any system or device +* that may lead to bodily harm or property damage if the system +* or device malfunctions. In addition,Bosch Sensortec products are +* not fit for use in products which interact with motor vehicle systems. +* The resale and or use of products are at the purchasers own risk and +* his own responsibility. The examination of fitness for the intended use +* is the sole responsibility of the Purchaser. +* +* The purchaser shall indemnify Bosch Sensortec from all third party +* claims, including any claims for incidental, or consequential damages, +* arising from any product use not covered by the parameters of +* the respective valid product data sheet or not approved by +* Bosch Sensortec and reimburse Bosch Sensortec for all costs in +* connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety and inform Bosch Sensortec +* without delay of all security relevant incidents. +* +* Engineering Samples are marked with an asterisk (*) or (e). +* Samples may vary from the valid technical specifications of the product +* series. They are therefore not intended or fit for resale to third +* parties or for use in end products. Their sole purpose is internal +* client testing. The testing of an engineering sample may in no way +* replace the testing of a product series. Bosch Sensortec assumes +* no liability for the use of engineering samples. +* By accepting the engineering samples, the Purchaser agrees to indemnify +* Bosch Sensortec from all claims arising from the use of engineering +* samples. +* +* Special: +* This software module (hereinafter called "Software") and any information +* on application-sheets (hereinafter called "Information") is provided +* free of charge for the sole purpose to support your application work. +* The Software and Information is subject to the following +* terms and conditions: +* +* The Software is specifically designed for the exclusive use for +* Bosch Sensortec products by personnel who have special experience +* and training. Do not use this Software if you do not have the +* proper experience or training. +* +* This Software package is provided `` as is `` and without any expressed +* or implied warranties,including without limitation, the implied warranties +* of merchantability and fitness for a particular purpose. +* +* Bosch Sensortec and their representatives and agents deny any liability +* for the functional impairment +* of this Software in terms of fitness, performance and safety. +* Bosch Sensortec and their representatives and agents shall not be liable +* for any direct or indirect damages or injury, except as +* otherwise stipulated in mandatory applicable law. + +* The Information provided is believed to be accurate and reliable. +* Bosch Sensortec assumes no responsibility for the consequences of use +* of such Information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of Bosch. Specifications mentioned in the Information are +* subject to change without notice. +* +* It is not allowed to deliver the source code of the Software +* to any third party without permission of +* Bosch Sensortec. +*/ +/****************************************************************************/ + +#include "bmp280.h" +#include "sensorhub.h" +#include "common.h" +#include "osp-sensors.h" +#include "sensacq_i2c.h" +#include "pressure_common.h" + +static struct bmp280_t *p_bmp280; /**< pointer to BMP280 */ +/* Compiler Switch if applicable +#ifdef + +#endif +*/ + +static struct bmp280_t bmp280; +void Pressure_HardwareSetup(osp_bool_t enable) +{ +} + +void Pressure_Initialize() +{ + MsgPressData p; + bmp280.bus_write = dev_i2c_write; + bmp280.bus_read = dev_i2c_read; + bmp280.delay_msec = dev_i2c_delay; + + bmp280_init(&bmp280); + bmp280_set_softreset(); + bmp280_set_workmode(BMP280_ULTRALOWPOWER_MODE); + /* pressure_setDelay(pSens, 1000) */ +#if 0 + bmp280_set_mode(BMP280_SLEEP_MODE); +#else + bmp280_set_mode(BMP280_NORMAL_MODE); + Pressure_ReadData(&p); +#endif +} + +void Pressure_ReadData(MsgPressData *pressData) +{ + bmp280_read_pt((uint32_t *)&pressData->X, (int32_t *)&pressData->Z); +} + +/******************************************************************************* + * Description: *//**\brief routine to initialize the function pointers + * + * + * + * + * \param + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + p_bmp280 = bmp280; /* assign BMP280 ptr */ + p_bmp280->dev_addr = BMP280_I2C_ADDRESS; /* preset BMP280 I2C_addr */ + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CHIPID_REG, &v_data_u8r, 1); /* read Chip Id */ + p_bmp280->chip_id = v_data_u8r; + + bmp280_get_calib_param(); /* readout bmp280 calibparam structure */ + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief reads uncompensated temperature + * + * + * + * + * \param unsigned long temperature : Pointer to the data + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_read_ut(BMP280_S32_t *utemperature) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[3] = {0}; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_TEMPERATURE_MSB_REG, a_data_u8r, 3); + *utemperature = (BMP280_S32_t)((( \ + (BMP280_U32_t) (a_data_u8r[0])) << SHIFT_LEFT_12_POSITION) | \ + (((BMP280_U32_t)(a_data_u8r[1])) << SHIFT_LEFT_4_POSITION) \ + | ((BMP280_U32_t)a_data_u8r[2] >> SHIFT_RIGHT_4_POSITION)); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Reads actual temperature from uncompensated temperature + * and returns the value in 0.01 degree Centigrade + * Output value of "5123" equals 51.23 DegC. + * + * + * + * \param signed long : value of uncompensated temperature + * + * + * + * \return + * signed long : actual temperature + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_S32_t bmp280_compensate_T_int32(BMP280_S32_t adc_T) +{ + BMP280_S32_t v_x1_u32r = 0; + BMP280_S32_t v_x2_u32r = 0; + BMP280_S32_t temperature = 0; + + v_x1_u32r = ((((adc_T >> 3) - ((BMP280_S32_t) + p_bmp280->cal_param.dig_T1 << 1))) * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_T2)) >> 11; + v_x2_u32r = (((((adc_T >> 4) - \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_T1)) * ((adc_T >> 4) - \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_T1))) >> 12) * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_T3)) >> 14; + p_bmp280->cal_param.t_fine = v_x1_u32r + v_x2_u32r; + temperature = (p_bmp280->cal_param.t_fine * 5 + 128) >> 8; + + return temperature; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief reads uncompensated pressure + * + * + * + * + * \param unsigned long pressure : Pointer to the data + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_read_up(BMP280_S32_t *upressure) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[3] = {0}; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_PRESSURE_MSB_REG, a_data_u8r, 3); + *upressure = (BMP280_S32_t)((((BMP280_U32_t)(a_data_u8r[0])) \ + << SHIFT_LEFT_12_POSITION) | (((BMP280_U32_t)(a_data_u8r[1])) \ + << SHIFT_LEFT_4_POSITION) | ((BMP280_U32_t)a_data_u8r[2] >>\ + SHIFT_RIGHT_4_POSITION)); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Reads actual pressure from uncompensated pressure + * and returns the value in Pascal(Pa) + * Output value of "96386" equals 96386 Pa = + * 963.86 hPa = 963.86 millibar + + * + * + * + * \param signed long : value of uncompensated pressure + * + * + * + * \return + * unsigned long : actual pressure + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +unsigned int bmp280_compensate_P_int32(BMP280_S32_t adc_P) +{ + BMP280_S32_t v_x1_u32r = 0; + BMP280_S32_t v_x2_u32r = 0; + BMP280_U32_t pressure = 0; + + v_x1_u32r = (((BMP280_S32_t)p_bmp280->cal_param.t_fine) >> 1) - \ + (BMP280_S32_t)64000; + v_x2_u32r = (((v_x1_u32r >> 2) * (v_x1_u32r >> 2)) >> 11) * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_P6); + v_x2_u32r = v_x2_u32r + ((v_x1_u32r * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_P5)) << 1); + v_x2_u32r = (v_x2_u32r >> 2) + \ + (((BMP280_S32_t)p_bmp280->cal_param.dig_P4) << 16); + v_x1_u32r = (((p_bmp280->cal_param.dig_P3 * (((v_x1_u32r >> 2) * \ + (v_x1_u32r >> 2)) >> 13)) >> 3) + \ + ((((BMP280_S32_t)p_bmp280->cal_param.dig_P2) * \ + v_x1_u32r) >> 1)) >> 18; + v_x1_u32r = ((((32768+v_x1_u32r)) * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_P1)) >> 15); + if (v_x1_u32r == 0) + return 0; /* Avoid exception caused by division by zero */ + pressure = (((BMP280_U32_t)(((BMP280_S32_t)1048576) - adc_P) - \ + (v_x2_u32r >> 12))) * 3125; + if (pressure < 0x80000000) + pressure = (pressure << 1) / ((BMP280_U32_t)v_x1_u32r); + else + pressure = (pressure / (BMP280_U32_t)v_x1_u32r) * 2; + v_x1_u32r = (((BMP280_S32_t)p_bmp280->cal_param.dig_P9) * \ + ((BMP280_S32_t)(((pressure >> 3) * (pressure >> 3)) >> 13))) \ + >> 12; + v_x2_u32r = (((BMP280_S32_t)(pressure >> 2)) * \ + ((BMP280_S32_t)p_bmp280->cal_param.dig_P8)) >> 13; + pressure = (BMP280_U32_t)((BMP280_S32_t)pressure + \ + ((v_x1_u32r + v_x2_u32r + p_bmp280->cal_param.dig_P7) >> 4)); + + return pressure; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief reads uncompensated pressure and temperature + * + * + * + * + * \param unsigned long utemperature : Address of uncompensated temperature + * unsigned long upressure : Address of uncompensated pressure + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_read_uput(BMP280_S32_t *upressure,\ + BMP280_S32_t *utemperature) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[6] = {0}; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_PRESSURE_MSB_REG, a_data_u8r, 6); + *upressure = (BMP280_S32_t)((((BMP280_U32_t)(a_data_u8r[0])) \ + << SHIFT_LEFT_12_POSITION) | (((BMP280_U32_t)(a_data_u8r[1])) \ + << SHIFT_LEFT_4_POSITION) | ((BMP280_U32_t)a_data_u8r[2] >>\ + SHIFT_RIGHT_4_POSITION)); + + /* Temperature */ + *utemperature = (BMP280_S32_t)((( \ + (BMP280_U32_t) (a_data_u8r[3])) << SHIFT_LEFT_12_POSITION) | \ + (((BMP280_U32_t)(a_data_u8r[4])) << SHIFT_LEFT_4_POSITION) \ + | ((BMP280_U32_t)a_data_u8r[5] >> SHIFT_RIGHT_4_POSITION)); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief reads pressure and temperature + * + * + * + * + * \param unsigned long temperature : Address of temperature + * unsigned long pressure : Address of pressure + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_read_pt(BMP280_U32_t *pressure,\ + BMP280_S32_t *temperature) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + BMP280_S32_t upressure = 0; + BMP280_S32_t utemperature = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = bmp280_read_uput(&upressure, &utemperature); + *temperature = bmp280_compensate_T_int32(utemperature); + *pressure = bmp280_compensate_P_int32(upressure); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief reads calibration parameters used for calculation + * + * + * + * + * \param None + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param() +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char a_data_u8r[26] = {0}; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_DIG_T1_LSB_REG, a_data_u8r, 24); + + p_bmp280->cal_param.dig_T1 = (BMP280_U16_t)(((\ + (BMP280_U16_t)((unsigned char)a_data_u8r[1])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[0]); + p_bmp280->cal_param.dig_T2 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[3])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[2]); + p_bmp280->cal_param.dig_T3 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[5])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[4]); + p_bmp280->cal_param.dig_P1 = (BMP280_U16_t)(((\ + (BMP280_U16_t)((unsigned char)a_data_u8r[7])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[6]); + p_bmp280->cal_param.dig_P2 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[9])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[8]); + p_bmp280->cal_param.dig_P3 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[11])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[10]); + p_bmp280->cal_param.dig_P4 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[13])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[12]); + p_bmp280->cal_param.dig_P5 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[15])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[14]); + p_bmp280->cal_param.dig_P6 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[17])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[16]); + p_bmp280->cal_param.dig_P7 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[19])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[18]); + p_bmp280->cal_param.dig_P8 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[21])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[20]); + p_bmp280->cal_param.dig_P9 = (BMP280_S16_t)(((\ + (BMP280_S16_t)((signed char)a_data_u8r[23])) << \ + SHIFT_LEFT_8_POSITION) | a_data_u8r[22]); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to get the Oversampling temperature + * + * + * + * + * \param unsigned char value : Pointer to the osrs_t + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_osrs_t(\ + unsigned char *value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); + *value = BMP280_GET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRST); + + p_bmp280->osrs_t = *value; + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to set the Oversampling temperature + * + * + * + * + * \param unsigned char value : Value of the Oversampling temperature + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_osrs_t(\ + unsigned char value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRST, value); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRST__REG, &v_data_u8r, 1); + + p_bmp280->osrs_t = value; + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to get the Oversampling pressure + * + * + * + * + * \param * \param unsigned char value : Pointer to the value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_osrs_p(\ + unsigned char *value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); + *value = BMP280_GET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRSP); + + p_bmp280->osrs_p = *value; + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to set the Oversampling pressure + * + * + * + * + * \param unsigned char value : Value of the Oversampling pressure + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_osrs_p(\ + unsigned char value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRSP, value); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_OSRSP__REG, &v_data_u8r, 1); + + p_bmp280->osrs_p = value; + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to get the Operational Mode from the sensor + * + * + * + * + * \param * \param unsigned char mode : Pointer to the value + * 0 -> BMP280_SLEEP_MODE + * 1 and 2 -> BMP280_FORCED_MODE + * 3 -> BMP280_NORMAL_MODE + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_mode(unsigned char *mode) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_mode_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_MODE__REG, &v_mode_u8r, 1); + *mode = BMP280_GET_BITSLICE(v_mode_u8r, \ + BMP280_CTRLMEAS_REG_MODE); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to set the Operational Mode for the sensor + * + * + * + * + * \param unsigned char mode : Value of the mode + * 0 -> BMP280_SLEEP_MODE + * 1 and 2 -> BMP280_FORCED_MODE + * 3 -> BMP280_NORMAL_MODE + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_mode(unsigned char mode) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_mode_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + if (mode < BMA280_Four_U8X) { + v_mode_u8r = (p_bmp280->osrs_t << \ + SHIFT_LEFT_5_POSITION) + (p_bmp280->osrs_p << \ + SHIFT_LEFT_2_POSITION) + mode; + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ + p_bmp280->dev_addr, \ + BMP280_CTRLMEAS_REG_MODE__REG, &v_mode_u8r, 1); + } else { + comres = E_BMP280_OUT_OF_RANGE; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Used to reset the sensor + * + * The value 0xB6 is written to the 0xE0 register the device is reset using the + * complete power-on-reset procedure. + * Soft reset can be easily set using BMP280_SOFT_RESET_CODE . + * Usage Hint : bme280_set_softreset(BMP280_SOFT_RESET_CODE) + * + * \param + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_softreset() +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = BMP280_SOFT_RESET_CODE; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_RESET_REG, &v_data_u8r, 1); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Gets the sensor communication type + * + * + * + * + * \param unsigned char *enable_disable : Pointer to the value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(unsigned char *enable_disable) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); + *enable_disable = BMP280_GET_BITSLICE(v_data_u8r, \ + BMP280_CONFIG_REG_SPI3WEN); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Sets the sensor communication type to 3 wire SPI + * + * + * + * + * \param unsigned char enable_disable : Value of the enable or disable + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(unsigned char enable_disable) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CONFIG_REG_SPI3WEN, enable_disable); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_SPI3WEN__REG, &v_data_u8r, 1); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Reads filter setting value + * + * + * + * + * \param * \param unsigned char *value : Pointer to value + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(unsigned char *value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); + *value = BMP280_GET_BITSLICE(v_data_u8r, \ + BMP280_CONFIG_REG_FILTER); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Writes filter setting to sensor + * + * + * + * + * \param unsigned char value : Value of the filter setting + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(unsigned char value) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CONFIG_REG_FILTER, value); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_FILTER__REG, &v_data_u8r, 1); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Reads standby duration time from the sensor + * + * \param * \param unsigned char *time : Pointer to the time + * 0x00 - BMP280_STANDBYTIME_1_MS + * 0x01 - BMP280_STANDBYTIME_63_MS + * 0x02 - BMP280_STANDBYTIME_125_MS + * 0x03 - BMP280_STANDBYTIME_250_MS + * 0x04 - BMP280_STANDBYTIME_500_MS + * 0x05 - BMP280_STANDBYTIME_1000_MS + * 0x06 - BMP280_STANDBYTIME_2000_MS + * 0x07 - BMP280_STANDBYTIME_4000_MS + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_standbydur(unsigned char *time) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); + *time = BMP280_GET_BITSLICE(v_data_u8r, BMP280_CONFIG_REG_TSB); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Writes standby duration time from the sensor + * + * Normal mode comprises an automated perpetual cycling between an (active) + * Measurement period and an (inactive) standby period. + * The standby time is determined by the contents of the register t_sb. + * Standby time can be set using BME280_STANDBYTIME_125_MS. + * + * Usage Hint : bme280_set_standbydur(BME280_STANDBYTIME_125_MS) + * + * \param unsigned char time : Value of the standby duration + * 0x00 - BMP280_STANDBYTIME_1_MS + * 0x01 - BMP280_STANDBYTIME_63_MS + * 0x02 - BMP280_STANDBYTIME_125_MS + * 0x03 - BMP280_STANDBYTIME_250_MS + * 0x04 - BMP280_STANDBYTIME_500_MS + * 0x05 - BMP280_STANDBYTIME_1000_MS + * 0x06 - BMP280_STANDBYTIME_2000_MS + * 0x07 - BMP280_STANDBYTIME_4000_MS + * + * + * \param unsigned char time : Value of the standby duration + * + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_standbydur(unsigned char time) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CONFIG_REG_TSB, time); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, \ + BMP280_CONFIG_REG_TSB__REG, &v_data_u8r, 1); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Writes the working mode to the sensor + * + * + * + * + * \param unsigned char : Mode to be set + * 0 -> BMP280_ULTRALOWPOWER_MODE + * 1 -> BMP280_LOWPOWER_MODE + * 2 -> BMP280_STANDARDRESOLUTION_MODE + * 3 -> BMP280_HIGHRESOLUTION_MODE + * 4 -> BMP280_ULTRAHIGHRESOLUTION_MODE + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_set_workmode(unsigned char mode) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + if (mode <= BMA280_Four_U8X) { + comres += p_bmp280->BMP280_BUS_READ_FUNC(\ + p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ + &v_data_u8r, 1); + switch (mode) { + case BMP280_ULTRALOWPOWER_MODE: + p_bmp280->osrs_t = BMP280_ULTRALOWPOWER_OSRS_T; + p_bmp280->osrs_p = BMP280_ULTRALOWPOWER_OSRS_P; + break; + case BMP280_LOWPOWER_MODE: + p_bmp280->osrs_t = BMP280_LOWPOWER_OSRS_T; + p_bmp280->osrs_p = BMP280_LOWPOWER_OSRS_P; + break; + case BMP280_STANDARDRESOLUTION_MODE: + p_bmp280->osrs_t = \ + BMP280_STANDARDRESOLUTION_OSRS_T; + p_bmp280->osrs_p = \ + BMP280_STANDARDRESOLUTION_OSRS_P; + break; + case BMP280_HIGHRESOLUTION_MODE: + p_bmp280->osrs_t = BMP280_HIGHRESOLUTION_OSRS_T; + p_bmp280->osrs_p = BMP280_HIGHRESOLUTION_OSRS_P; + break; + case BMP280_ULTRAHIGHRESOLUTION_MODE: + p_bmp280->osrs_t = \ + BMP280_ULTRAHIGHRESOLUTION_OSRS_T; + p_bmp280->osrs_p = \ + BMP280_ULTRAHIGHRESOLUTION_OSRS_P; + break; + } + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRST, p_bmp280->osrs_t); + v_data_u8r = BMP280_SET_BITSLICE(v_data_u8r, \ + BMP280_CTRLMEAS_REG_OSRSP, p_bmp280->osrs_p); + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ + p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ + &v_data_u8r, 1); + } else { + comres = E_BMP280_OUT_OF_RANGE; + } + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief Read both uncompensated temperature and pressure + * in forced mode + * + * + * + * \param unsigned long utemperature : Address of uncompensated temperature + * unsigned long pressure : Address of uncompensated pressure + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_get_forced_uput(BMP280_S32_t *upressure,\ + BMP280_S32_t *utemperature) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + unsigned char v_data_u8r = 0; + unsigned char v_waittime_u8r = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + v_data_u8r = (p_bmp280->osrs_t << SHIFT_LEFT_5_POSITION) + \ + (p_bmp280->osrs_p << SHIFT_LEFT_2_POSITION) + \ + BMP280_FORCED_MODE; + comres += p_bmp280->BMP280_BUS_WRITE_FUNC(\ + p_bmp280->dev_addr, BMP280_CTRLMEAS_REG,\ + &v_data_u8r, 1); + bmp280_compute_wait_time(&v_waittime_u8r); + p_bmp280->delay_msec(v_waittime_u8r); + comres += bmp280_read_uput(upressure, utemperature); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief This API gives data to the given register and + * the data is written in the corresponding register + * address + * + * + * + * \param unsigned char addr, unsigned char data, unsigned char len + * addr -> Address of the register + * data -> Data to be written to the register + * len -> Length of the Data + * + * + * + * \return communication results. + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(unsigned char addr, + unsigned char *data, unsigned char len) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr, + addr, data, len); + } + return comres; +} +/* Compiler Switch if applicable +#ifdef + +#endif +*/ +/******************************************************************************* + * Description: *//**\brief This API reads the data from the given register + * address + * + * + * + * \param unsigned char addr, unsigned char *data, unsigned char len + * addr -> Address of the register + * data -> address of the variable, read value will be kept + * len -> Length of the data + * + * + * + * + * \return results of communication routine + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(unsigned char addr, + unsigned char *data, unsigned char len) +{ + BMP280_RETURN_FUNCTION_TYPE comres; + if (p_bmp280 == BMP280_NULL) { + comres = E_BMP280_NULL_PTR; + } else { + comres += p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr, + addr, data, len); + } + return comres; +} +#ifdef BMP280_ENABLE_FLOAT +/******************************************************************************* + * Description: *//**\brief Reads actual temperature from uncompensated temperature + * and returns the value in Degree centigrade + * Output value of "51.23" equals 51.23 DegC. + * + * + * + * \param signed long : value of uncompensated temperature + * + * + * + * \return + * double : actual temperature in floating point + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +double bmp280_compensate_T_double(BMP280_S32_t adc_T) +{ + double v_x1_u32r = 0; + double v_x2_u32r = 0; + double temperature = 0; + + v_x1_u32r = (((double)adc_T) / 16384.0 - \ + ((double)p_bmp280->cal_param.dig_T1) / 1024.0) * \ + ((double)p_bmp280->cal_param.dig_T2); + v_x2_u32r = ((((double)adc_T) / 131072.0 - \ + ((double)p_bmp280->cal_param.dig_T1) / 8192.0) * \ + (((double)adc_T) / 131072.0 - \ + ((double)p_bmp280->cal_param.dig_T1) / 8192.0)) * \ + ((double)p_bmp280->cal_param.dig_T3); + p_bmp280->cal_param.t_fine = (BMP280_S32_t)(v_x1_u32r + v_x2_u32r); + temperature = (v_x1_u32r + v_x2_u32r) / 5120.0; + + + return temperature; +} +/******************************************************************************* + * Description: *//**\brief Reads actual pressure from uncompensated pressure + * and returns pressure in Pa as double. + * Output value of "96386.2" + * equals 96386.2 Pa = 963.862 hPa. + * + * + * + * \param signed int : value of uncompensated pressure + * + * + * + * \return + * double : actual pressure in floating point + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +double bmp280_compensate_P_double(BMP280_S32_t adc_P) +{ + double v_x1_u32r = 0; + double v_x2_u32r = 0; + double pressure = 0; + + v_x1_u32r = ((double)p_bmp280->cal_param.t_fine/2.0) - 64000.0; + v_x2_u32r = v_x1_u32r * v_x1_u32r * \ + ((double)p_bmp280->cal_param.dig_P6) / 32768.0; + v_x2_u32r = v_x2_u32r + v_x1_u32r * \ + ((double)p_bmp280->cal_param.dig_P5) * 2.0; + v_x2_u32r = (v_x2_u32r / 4.0) + \ + (((double)p_bmp280->cal_param.dig_P4) * 65536.0); + v_x1_u32r = (((double)p_bmp280->cal_param.dig_P3) * \ + v_x1_u32r * v_x1_u32r / 524288.0 + \ + ((double)p_bmp280->cal_param.dig_P2) * v_x1_u32r) / 524288.0; + v_x1_u32r = (1.0 + v_x1_u32r / 32768.0) * \ + ((double)p_bmp280->cal_param.dig_P1); + if (v_x1_u32r == 0.0) + return 0; /* Avoid exception caused by division by zero */ + pressure = 1048576.0 - (double)adc_P; + pressure = (pressure - (v_x2_u32r / 4096.0)) * 6250.0 / v_x1_u32r; + v_x1_u32r = ((double)p_bmp280->cal_param.dig_P9) * \ + pressure * pressure / 2147483648.0; + v_x2_u32r = pressure * ((double)p_bmp280->cal_param.dig_P8) / 32768.0; + pressure = pressure + (v_x1_u32r + v_x2_u32r + \ + ((double)p_bmp280->cal_param.dig_P7)) / 16.0; + + return pressure; +} +#endif +#if defined(BMP280_ENABLE_INT64) && defined(BMP280_64BITSUPPORT_PRESENT) +/******************************************************************************* + * Description: *//**\brief Reads actual pressure from uncompensated pressure + * and returns the value in Pa as unsigned 32 bit + * integer in Q24.8 format (24 integer bits and + * 8 fractional bits). Output value of "24674867" + * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa + * + * + * + * \param signed long : value of uncompensated temperature + * + * + * + * \return + * unsigned long : actual pressure + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ******************************************************************************/ +BMP280_U32_t bmp280_compensate_P_int64(BMP280_S32_t adc_P) +{ + BMP280_S64_t v_x1_s64r = 0; + BMP280_S64_t v_x2_s64r = 0; + BMP280_S64_t pressure = 0; + v_x1_s64r = ((BMP280_S64_t)p_bmp280->cal_param.t_fine) - 128000; + v_x2_s64r = v_x1_s64r * v_x1_s64r * \ + (BMP280_S64_t)p_bmp280->cal_param.dig_P6; + v_x2_s64r = v_x2_s64r + ((v_x1_s64r * \ + (BMP280_S64_t)p_bmp280->cal_param.dig_P5) << 17); + v_x2_s64r = v_x2_s64r + \ + (((BMP280_S64_t)p_bmp280->cal_param.dig_P4) << 35); + v_x1_s64r = ((v_x1_s64r * v_x1_s64r * \ + (BMP280_S64_t)p_bmp280->cal_param.dig_P3) >> 8) + \ + ((v_x1_s64r * (BMP280_S64_t)p_bmp280->cal_param.dig_P2) << 12); + v_x1_s64r = (((((BMP280_S64_t)1) << 47) + v_x1_s64r)) * \ + ((BMP280_S64_t)p_bmp280->cal_param.dig_P1) >> 33; + if (v_x1_s64r == 0) + return 0; /* Avoid exception caused by division by zero */ + pressure = 1048576 - adc_P; + pressure = (((pressure << 31) - v_x2_s64r) * 3125) / v_x1_s64r; + v_x1_s64r = (((BMP280_S64_t)p_bmp280->cal_param.dig_P9) * \ + (pressure >> 13) * (pressure >> 13)) >> 25; + v_x2_s64r = (((BMP280_S64_t)p_bmp280->cal_param.dig_P8) * \ + pressure) >> 19; + pressure = ((pressure + v_x1_s64r + v_x2_s64r) >> 8) + \ + (((BMP280_S64_t)p_bmp280->cal_param.dig_P7) << 4); + return (BMP280_U32_t)pressure; +} +#endif +/******************************************************************************* + * Description: *//**\brief Computing waiting time for sensor data read + * + * + * + * + * \param + * unsigned char : value of time + * + * + * \return + * + * + ******************************************************************************/ +/* Scheduling: + * + * + * + * Usage guide: + * + * + * Remarks: + * + ****************************************************************************/ +BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(unsigned char \ + *v_delaytime_u8r) +{ + BMP280_RETURN_FUNCTION_TYPE comres = 0; + + *v_delaytime_u8r = (T_INIT_MAX + T_MEASURE_PER_OSRS_MAX * \ + (((1 << p_bmp280->osrs_t) >> 1) + ((1 << p_bmp280->osrs_p) \ + >> 1)) + (p_bmp280->osrs_p ? T_SETUP_PRESSURE_MAX : 0) + 15) \ + / 16; + return comres; +} diff --git a/embedded/common/modules/sensor-drivers/bmp280.h b/embedded/common/modules/sensor-drivers/bmp280.h index d81eaad..9294f3d 100644 --- a/embedded/common/modules/sensor-drivers/bmp280.h +++ b/embedded/common/modules/sensor-drivers/bmp280.h @@ -1,469 +1,469 @@ -/* - ***************************************************************************** - * - * (C) All rights reserved by ROBERT BOSCH GMBH - * - ****************************************************************************/ -/* Date: 2013/05/06 - * Revision: 1.3 - * - */ - -/***************************************************************************** -* Copyright (C) 2007 Bosch Sensortec GmbH -* -* -* -* Usage: -* -*****************************************************************************/ -/****************************************************************************/ -/* Disclaimer -* -* Common: -* Bosch Sensortec products are developed for the consumer goods industry. -* They may only be used within the parameters of the respective valid -* product data sheet. Bosch Sensortec products are provided with the -* express understanding that there is no warranty of fitness for a -* particular purpose.They are not fit for use in life-sustaining, -* safety or security sensitive systems or any system or device -* that may lead to bodily harm or property damage if the system -* or device malfunctions. In addition,Bosch Sensortec products are -* not fit for use in products which interact with motor vehicle systems. -* The resale and or use of products are at the purchasers own risk and -* his own responsibility. The examination of fitness for the intended use -* is the sole responsibility of the Purchaser. -* -* The purchaser shall indemnify Bosch Sensortec from all third party -* claims, including any claims for incidental, or consequential damages, -* arising from any product use not covered by the parameters of -* the respective valid product data sheet or not approved by -* Bosch Sensortec and reimburse Bosch Sensortec for all costs in -* connection with such claims. -* -* The purchaser must monitor the market for the purchased products, -* particularly with regard to product safety and inform Bosch Sensortec -* without delay of all security relevant incidents. -* -* Engineering Samples are marked with an asterisk (*) or (e). -* Samples may vary from the valid technical specifications of the product -* series. They are therefore not intended or fit for resale to third -* parties or for use in end products. Their sole purpose is internal -* client testing. The testing of an engineering sample may in no way -* replace the testing of a product series. Bosch Sensortec assumes -* no liability for the use of engineering samples. -* By accepting the engineering samples, the Purchaser agrees to indemnify -* Bosch Sensortec from all claims arising from the use of engineering -* samples. -* -* Special: -* This software module (hereinafter called "Software") and any information -* on application-sheets (hereinafter called "Information") is provided -* free of charge for the sole purpose to support your application work. -* The Software and Information is subject to the following -* terms and conditions: -* -* The Software is specifically designed for the exclusive use for -* Bosch Sensortec products by personnel who have special experience -* and training. Do not use this Software if you do not have the -* proper experience or training. -* -* This Software package is provided `` as is `` and without any expressed -* or implied warranties,including without limitation, the implied warranties -* of merchantability and fitness for a particular purpose. -* -* Bosch Sensortec and their representatives and agents deny any liability -* for the functional impairment -* of this Software in terms of fitness, performance and safety. -* Bosch Sensortec and their representatives and agents shall not be liable -* for any direct or indirect damages or injury, except as -* otherwise stipulated in mandatory applicable law. -* -* The Information provided is believed to be accurate and reliable. -* Bosch Sensortec assumes no responsibility for the consequences of use -* of such Information nor for any infringement of patents or -* other rights of third parties which may result from its use. -* No license is granted by implication or otherwise under any patent or -* patent rights of Bosch. Specifications mentioned in the Information are -* subject to change without notice. -* -* It is not allowed to deliver the source code of the Software -* to any third party without permission of -* Bosch Sensortec. -*/ - -#ifndef __BMP280_H__ -#define __BMP280_H__ - -#include - -/* Find correct data type for signed/unsigned 16 bit variables by - checking max of unsigned variant */ -#if USHRT_MAX == 0xFFFF - /* 16 bit achieved with short */ - #define BMP280_U16_t unsigned short - #define BMP280_S16_t signed short -#elif UINT_MAX == 0xFFFF - /* 16 bit achieved with int */ - #define BMP280_U16_t unsigned int - #define BMP280_S16_t signed int -#else - #error BMP280_U16_t and BMP280_S16_t could not be \ - defined automatically, please do so manually -#endif - -/* Find correct data type for 32 bit variables */ -#if INT_MAX == 0x7FFFFFFF - /* 32 bit achieved with int */ - #define BMP280_U32_t unsigned int - #define BMP280_S32_t signed int -#elif LONG_MAX == 0x7FFFFFFF - /* 32 bit achieved with long int */ - #define BMP280_U32_t unsigned long int - #define BMP280_S32_t signed long int -#else - #error BMP280_S32_t and BMP280_U32_t could not be \ - defined automatically, please do so manually -#endif - -/* Find correct data type for 64 bit variables */ -#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL - #define BMP280_S64_t long int - #define BMP280_64BITSUPPORT_PRESENT -#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) - #define BMP280_S64_t long long int - #define BMP280_64BITSUPPORT_PRESENT -#else - #warning Either the correct data type for signed 64 bit \ - integer could not be found, or 64 bit integers are \ - not supported in your environment. - #warning The API will only offer 32 bit pressure calculation. \ - This will slightly impede accuracy(noise of ~1 Pa RMS \ - will be added to output). - #warning If 64 bit integers are supported on your platform, \ - please set BMP280_S64_t manually and - #define BMP280_64BITSUPPORT_PRESENT manually. -#endif - - - -/* If the user wants to support floating point calculations, please set \ - the following #define. If floating point calculation is not wanted \ - or allowed (e.g. in Linux kernel), please do not set the define. */ -#define BMP280_ENABLE_FLOAT -/* If the user wants to support 64 bit integer calculation (needed for \ - optimal pressure accuracy) please set the following #define. If \ - int64 calculation is not wanted (e.g. because it would include \ - large libraries), please do not set the define. */ -#define BMP280_ENABLE_INT64 - -/** defines the return parameter type of the BMP280_WR_FUNCTION */ -#define BMP280_BUS_WR_RETURN_TYPE signed char - -/**\brief links the order of parameters defined in -BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMP280_BUS_WR_PARAM_TYPES unsigned char, unsigned char,\ - unsigned char *, unsigned char - -/**\brief links the order of parameters defined in -BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ -#define BMP280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\ - register_data, wr_len) - -/* never change this line */ -#define BMP280_BUS_WRITE_FUNC(device_addr, register_addr,\ -register_data, wr_len) bus_write(device_addr, register_addr,\ - register_data, wr_len) - -/**\brief defines the return parameter type of the BMP280_RD_FUNCTION -*/ -#define BMP280_BUS_RD_RETURN_TYPE signed char - -/**\brief defines the calling parameter types of the BMP280_RD_FUNCTION -*/ -#define BMP280_BUS_RD_PARAM_TYPES unsigned char, unsigned char,\ - unsigned char *, unsigned char - -/**\brief links the order of parameters defined in \ -BMP280_BUS_RD_PARAM_TYPE to function calls used inside the API -*/ -#define BMP280_BUS_RD_PARAM_ORDER device_addr, register_addr,\ - register_data - -/* never change this line */ -#define BMP280_BUS_READ_FUNC(device_addr, register_addr,\ - register_data, rd_len)bus_read(device_addr, register_addr,\ - register_data, rd_len) - -/**\brief defines the return parameter type of the BMP280_DELAY_FUNCTION -*/ -#define BMP280_DELAY_RETURN_TYPE void - -/**\brief defines the calling parameter types of the BMP280_DELAY_FUNCTION -*/ -#define BMP280_DELAY_PARAM_TYPES BMP280_U16_t - -/* never change this line */ -#define BMP280_DELAY_FUNC(delay_in_msec)\ - delay_func(delay_in_msec) - -#define BMP280_GET_BITSLICE(regvar, bitname)\ - ((regvar & bitname##__MSK) >> bitname##__POS) - -#define BMP280_SET_BITSLICE(regvar, bitname, val)\ - ((regvar & ~bitname##__MSK) | ((val< +* +* Usage: +* +*****************************************************************************/ +/****************************************************************************/ +/* Disclaimer +* +* Common: +* Bosch Sensortec products are developed for the consumer goods industry. +* They may only be used within the parameters of the respective valid +* product data sheet. Bosch Sensortec products are provided with the +* express understanding that there is no warranty of fitness for a +* particular purpose.They are not fit for use in life-sustaining, +* safety or security sensitive systems or any system or device +* that may lead to bodily harm or property damage if the system +* or device malfunctions. In addition,Bosch Sensortec products are +* not fit for use in products which interact with motor vehicle systems. +* The resale and or use of products are at the purchasers own risk and +* his own responsibility. The examination of fitness for the intended use +* is the sole responsibility of the Purchaser. +* +* The purchaser shall indemnify Bosch Sensortec from all third party +* claims, including any claims for incidental, or consequential damages, +* arising from any product use not covered by the parameters of +* the respective valid product data sheet or not approved by +* Bosch Sensortec and reimburse Bosch Sensortec for all costs in +* connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety and inform Bosch Sensortec +* without delay of all security relevant incidents. +* +* Engineering Samples are marked with an asterisk (*) or (e). +* Samples may vary from the valid technical specifications of the product +* series. They are therefore not intended or fit for resale to third +* parties or for use in end products. Their sole purpose is internal +* client testing. The testing of an engineering sample may in no way +* replace the testing of a product series. Bosch Sensortec assumes +* no liability for the use of engineering samples. +* By accepting the engineering samples, the Purchaser agrees to indemnify +* Bosch Sensortec from all claims arising from the use of engineering +* samples. +* +* Special: +* This software module (hereinafter called "Software") and any information +* on application-sheets (hereinafter called "Information") is provided +* free of charge for the sole purpose to support your application work. +* The Software and Information is subject to the following +* terms and conditions: +* +* The Software is specifically designed for the exclusive use for +* Bosch Sensortec products by personnel who have special experience +* and training. Do not use this Software if you do not have the +* proper experience or training. +* +* This Software package is provided `` as is `` and without any expressed +* or implied warranties,including without limitation, the implied warranties +* of merchantability and fitness for a particular purpose. +* +* Bosch Sensortec and their representatives and agents deny any liability +* for the functional impairment +* of this Software in terms of fitness, performance and safety. +* Bosch Sensortec and their representatives and agents shall not be liable +* for any direct or indirect damages or injury, except as +* otherwise stipulated in mandatory applicable law. +* +* The Information provided is believed to be accurate and reliable. +* Bosch Sensortec assumes no responsibility for the consequences of use +* of such Information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of Bosch. Specifications mentioned in the Information are +* subject to change without notice. +* +* It is not allowed to deliver the source code of the Software +* to any third party without permission of +* Bosch Sensortec. +*/ + +#ifndef __BMP280_H__ +#define __BMP280_H__ + +#include + +/* Find correct data type for signed/unsigned 16 bit variables by + checking max of unsigned variant */ +#if USHRT_MAX == 0xFFFF + /* 16 bit achieved with short */ + #define BMP280_U16_t unsigned short + #define BMP280_S16_t signed short +#elif UINT_MAX == 0xFFFF + /* 16 bit achieved with int */ + #define BMP280_U16_t unsigned int + #define BMP280_S16_t signed int +#else + #error BMP280_U16_t and BMP280_S16_t could not be \ + defined automatically, please do so manually +#endif + +/* Find correct data type for 32 bit variables */ +#if INT_MAX == 0x7FFFFFFF + /* 32 bit achieved with int */ + #define BMP280_U32_t unsigned int + #define BMP280_S32_t signed int +#elif LONG_MAX == 0x7FFFFFFF + /* 32 bit achieved with long int */ + #define BMP280_U32_t unsigned long int + #define BMP280_S32_t signed long int +#else + #error BMP280_S32_t and BMP280_U32_t could not be \ + defined automatically, please do so manually +#endif + +/* Find correct data type for 64 bit variables */ +#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL + #define BMP280_S64_t long int + #define BMP280_64BITSUPPORT_PRESENT +#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) + #define BMP280_S64_t long long int + #define BMP280_64BITSUPPORT_PRESENT +#else + #warning Either the correct data type for signed 64 bit \ + integer could not be found, or 64 bit integers are \ + not supported in your environment. + #warning The API will only offer 32 bit pressure calculation. \ + This will slightly impede accuracy(noise of ~1 Pa RMS \ + will be added to output). + #warning If 64 bit integers are supported on your platform, \ + please set BMP280_S64_t manually and + #define BMP280_64BITSUPPORT_PRESENT manually. +#endif + + + +/* If the user wants to support floating point calculations, please set \ + the following #define. If floating point calculation is not wanted \ + or allowed (e.g. in Linux kernel), please do not set the define. */ +#define BMP280_ENABLE_FLOAT +/* If the user wants to support 64 bit integer calculation (needed for \ + optimal pressure accuracy) please set the following #define. If \ + int64 calculation is not wanted (e.g. because it would include \ + large libraries), please do not set the define. */ +#define BMP280_ENABLE_INT64 + +/** defines the return parameter type of the BMP280_WR_FUNCTION */ +#define BMP280_BUS_WR_RETURN_TYPE signed char + +/**\brief links the order of parameters defined in +BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BMP280_BUS_WR_PARAM_TYPES unsigned char, unsigned char,\ + unsigned char *, unsigned char + +/**\brief links the order of parameters defined in +BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ +#define BMP280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\ + register_data, wr_len) + +/* never change this line */ +#define BMP280_BUS_WRITE_FUNC(device_addr, register_addr,\ +register_data, wr_len) bus_write(device_addr, register_addr,\ + register_data, wr_len) + +/**\brief defines the return parameter type of the BMP280_RD_FUNCTION +*/ +#define BMP280_BUS_RD_RETURN_TYPE signed char + +/**\brief defines the calling parameter types of the BMP280_RD_FUNCTION +*/ +#define BMP280_BUS_RD_PARAM_TYPES unsigned char, unsigned char,\ + unsigned char *, unsigned char + +/**\brief links the order of parameters defined in \ +BMP280_BUS_RD_PARAM_TYPE to function calls used inside the API +*/ +#define BMP280_BUS_RD_PARAM_ORDER device_addr, register_addr,\ + register_data + +/* never change this line */ +#define BMP280_BUS_READ_FUNC(device_addr, register_addr,\ + register_data, rd_len)bus_read(device_addr, register_addr,\ + register_data, rd_len) + +/**\brief defines the return parameter type of the BMP280_DELAY_FUNCTION +*/ +#define BMP280_DELAY_RETURN_TYPE void + +/**\brief defines the calling parameter types of the BMP280_DELAY_FUNCTION +*/ +#define BMP280_DELAY_PARAM_TYPES BMP280_U16_t + +/* never change this line */ +#define BMP280_DELAY_FUNC(delay_in_msec)\ + delay_func(delay_in_msec) + +#define BMP280_GET_BITSLICE(regvar, bitname)\ + ((regvar & bitname##__MSK) >> bitname##__POS) + +#define BMP280_SET_BITSLICE(regvar, bitname, val)\ + ((regvar & ~bitname##__MSK) | ((val<>> ----------------- +// +// Thread Configuration +// ======================= +// +// Number of concurrent running user threads <1-250> +// Defines max. number of user threads that will run at the same time. +// Default: 6 +#ifndef OS_TASKCNT + #define OS_TASKCNT 6 +#endif + +// Default Thread stack size [bytes] <64-4096:8><#/4> +// Defines default stack size for threads with osThreadDef stacksz = 0 +// Default: 200 +#ifndef OS_STKSIZE + #define OS_STKSIZE 1024 // this stack size value is in words +#endif + +// Main Thread stack size [bytes] <64-32768:8><#/4> +// Defines stack size for main thread. +// Default: 200 +#ifndef OS_MAINSTKSIZE + #define OS_MAINSTKSIZE 0x100 // this stack size value is in words +#endif + +// Number of threads with user-provided stack size <0-250> +// Defines the number of threads with user-provided stack size. +// Default: 0 +#ifndef OS_PRIVCNT + #define OS_PRIVCNT NUMBER_OF_TASKS +#endif + +// Total stack size [bytes] for threads with user-provided stack size <0-1048576:8><#/4> +// Defines the combined stack size for threads with user-provided stack size. +// Default: 0 +#ifndef OS_PRIVSTKSIZE + #define OS_PRIVSTKSIZE NUMBER_OF_TASKS * 800 // this stack size value is in words +#endif + +// Stack overflow checking +// Enable stack overflow checks at thread switch. +// Enabling this option increases slightly the execution time of a thread switch. +#ifndef OS_STKCHECK + #define OS_STKCHECK 0 +#endif + +// Stack usage watermark +// Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer. +// Enabling this option increases significantly the execution time of osThreadCreate. +#ifndef OS_STKINIT +#define OS_STKINIT 0 +#endif + +// Processor mode for thread execution +// <0=> Unprivileged mode +// <1=> Privileged mode +// Default: Privileged mode +#ifndef OS_RUNPRIV + #define OS_RUNPRIV 1 +#endif + +// + +// RTX Kernel Timer Tick Configuration +// ====================================== +// Use Cortex-M SysTick timer as RTX Kernel Timer +// Cortex-M processors provide in most cases a SysTick timer that can be used as +// as time-base for RTX. +#ifndef OS_SYSTICK + #define OS_SYSTICK 1 +#endif +// +// RTOS Kernel Timer input clock frequency [Hz] <1-1000000000> +// Defines the input frequency of the RTOS Kernel Timer. +// When the Cortex-M SysTick timer is used, the input clock +// is on most systems identical with the core clock. +#ifndef OS_CLOCK + #define OS_CLOCK 12000000 +#endif + +// RTX Timer tick interval value [us] <1-1000000> +// The RTX Timer tick interval value is used to calculate timeout values. +// When the Cortex-M SysTick timer is enabled, the value also configures the SysTick timer. +// Default: 1000 (1ms) +#ifndef OS_TICK + #define OS_TICK 1000 +#endif + +// + +// System Configuration +// ======================= +// +// Round-Robin Thread switching +// =============================== +// +// Enables Round-Robin Thread switching. +#ifndef OS_ROBIN + #define OS_ROBIN 0 +#endif + +// Round-Robin Timeout [ticks] <1-1000> +// Defines how long a thread will execute before a thread switch. +// Default: 5 +#ifndef OS_ROBINTOUT + #define OS_ROBINTOUT 5 +#endif + +// + +// User Timers +// ============== +// Enables user Timers +#ifndef OS_TIMERS + #define OS_TIMERS 1 +#endif + +// Timer Thread Priority +// <1=> Low +// <2=> Below Normal <3=> Normal <4=> Above Normal +// <5=> High +// <6=> Realtime (highest) +// Defines priority for Timer Thread +// Default: High +#ifndef OS_TIMERPRIO + #define OS_TIMERPRIO 4 +#endif + +// Timer Thread stack size [bytes] <64-4096:8><#/4> +// Defines stack size for Timer thread. +// Default: 200 +#ifndef OS_TIMERSTKSZ + #define OS_TIMERSTKSZ 50 // this stack size value is in words +#endif + +// Timer Callback Queue size <1-32> +// Number of concurrent active timer callback functions. +// Default: 4 +#ifndef OS_TIMERCBQS + #define OS_TIMERCBQS 4 +#endif + +// + +// ISR FIFO Queue size<4=> 4 entries <8=> 8 entries +// <12=> 12 entries <16=> 16 entries +// <24=> 24 entries <32=> 32 entries +// <48=> 48 entries <64=> 64 entries +// <96=> 96 entries +// ISR functions store requests to this buffer, +// when they are called from the interrupt handler. +// Default: 16 entries +#ifndef OS_FIFOSZ + #define OS_FIFOSZ 16 +#endif + +// + +//------------- <<< end of configuration section >>> ----------------------- + +// Standard library system mutexes +// =============================== +// Define max. number system mutexes that are used to protect +// the arm standard runtime library. For microlib they are not used. +#ifndef OS_MUTEXCNT + #define OS_MUTEXCNT 8 +#endif + +/*---------------------------------------------------------------------------- + * RTX User configuration part END + *---------------------------------------------------------------------------*/ + +#define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) + + +/*---------------------------------------------------------------------------- + * Global Functions + *---------------------------------------------------------------------------*/ + +/*--------------------------- os_idle_demon ---------------------------------*/ + +/// \brief The idle demon is running when no other thread is ready to run +void os_idle_demon (void) { + + for (;;) { + /* HERE: include optional user code to be executed when no thread runs.*/ + } +} + +#if (OS_SYSTICK == 0) // Functions for alternative timer as RTX kernel timer + +/*--------------------------- os_tick_init ----------------------------------*/ + +/// \brief Initializes an alternative hardware timer as RTX kernel timer +/// \return IRQ number of the alternative hardware timer +int os_tick_init (void) { + return (-1); /* Return IRQ number of timer (0..239) */ +} + +/*--------------------------- os_tick_val -----------------------------------*/ + +/// \brief Get alternative hardware timer's current value (0 .. OS_TRV) +/// \return Current value of the alternative hardware timer +uint32_t os_tick_val (void) { + return (0); +} + +/*--------------------------- os_tick_ovf -----------------------------------*/ + +/// \brief Get alternative hardware timer's overflow flag +/// \return Overflow flag\n +/// - 1 : overflow +/// - 0 : no overflow +uint32_t os_tick_ovf (void) { + return (0); +} + +/*--------------------------- os_tick_irqack --------------------------------*/ + +/// \brief Acknowledge alternative hardware timer interrupt +void os_tick_irqack (void) { + /* ... */ +} + +#endif // (OS_SYSTICK == 0) + +/*--------------------------- os_error --------------------------------------*/ + +/* OS Error Codes */ +#define OS_ERROR_STACK_OVF 1 +#define OS_ERROR_FIFO_OVF 2 +#define OS_ERROR_MBX_OVF 3 +#define OS_ERROR_TIMER_OVF 4 + +extern osThreadId svcThreadGetId (void); + +/// \brief Called when a runtime error is detected +/// \param[in] error_code actual error code that has been detected +void os_error (uint32_t error_code) { + + /* HERE: include optional code to be executed on runtime error. */ + switch (error_code) { + case OS_ERROR_STACK_OVF: + /* Stack overflow detected for the currently running task. */ + /* Thread can be identified by calling svcThreadGetId(). */ + break; + case OS_ERROR_FIFO_OVF: + /* ISR FIFO Queue buffer overflow detected. */ + break; + case OS_ERROR_MBX_OVF: + /* Mailbox overflow detected. */ + break; + case OS_ERROR_TIMER_OVF: + /* User Timer Callback Queue overflow detected. */ + break; + } + printf("Error Code: %d\n", error_code); + for (;;); +} + + +/*---------------------------------------------------------------------------- + * RTX Configuration Functions + *---------------------------------------------------------------------------*/ + +#include "RTX_CM_lib.h" + +/*---------------------------------------------------------------------------- + * end of file + *---------------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/Keil/RTE/RTE_Components.h b/embedded/projects/osp-lpc54102/Keil/RTE/RTE_Components.h new file mode 100644 index 0000000..12a400e --- /dev/null +++ b/embedded/projects/osp-lpc54102/Keil/RTE/RTE_Components.h @@ -0,0 +1,16 @@ + +/* + * Auto generated Run-Time-Environment Component Configuration File + * *** Do not modify ! *** + * + * Project: 'osp-lpc54102' + * Target: 'OSP-Reference' + */ + +#ifndef RTE_COMPONENTS_H +#define RTE_COMPONENTS_H + +#define RTE_CMSIS_RTOS /* CMSIS-RTOS */ + #define RTE_CMSIS_RTOS_RTX /* CMSIS-RTOS Keil RTX */ + +#endif /* RTE_COMPONENTS_H */ diff --git a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx index f1d53e8..302b7d2 100644 --- a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx +++ b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx @@ -144,7 +144,7 @@ 0 UL2CM3 - -UV0202LFE -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD2000000 -FC1000 -FN1 -FF0LPC54xxx_512.FLM -FS00 -FL080000 -FP0($$Device:LPC54102$Flash\LPC54xxx_512.FLM) + -UV0891UAE -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD2000000 -FC1000 -FN1 -FF0LPC54xxx_512.FLM -FS00 -FL080000 -FP0($$Device:LPC54102$Flash\LPC54xxx_512.FLM) @@ -171,7 +171,7 @@ 0 0 - 0 + 1 0 0 0 @@ -209,7 +209,7 @@ ASF - 1 + 0 0 0 0 @@ -217,7 +217,7 @@ 2 1 1 - 1 + 0 0 0 0 @@ -726,4 +726,59 @@ + + TARGET_LPC54102 + 0 + 0 + 0 + 0 + + 10 + 36 + 1 + 0 + 0 + 0 + 0 + ..\..\..\..\targets\TARGET_LPC54102\gpio_api.c + gpio_api.c + 0 + 0 + + + 10 + 37 + 1 + 0 + 0 + 0 + 0 + ..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c + gpio_irq_api.c + 0 + 0 + + + 10 + 38 + 1 + 0 + 0 + 0 + 0 + ..\..\..\..\targets\TARGET_LPC54102\pinmap.c + pinmap.c + 0 + 0 + + + + + ::CMSIS + 0 + 0 + 0 + 1 + + diff --git a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx index 66386c9..21898cc 100644 --- a/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx +++ b/embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx @@ -175,7 +175,7 @@ 1 BIN\UL2CM3.DLL - + "" () @@ -206,11 +206,11 @@ 1 1 1 - 1 + 0 1 - 1 + 0 1 - 1 + 0 "Cortex-M4" 1 @@ -347,7 +347,7 @@ 1 - 3 + 1 0 0 1 @@ -363,9 +363,9 @@ 0 - INTERNAL_FLASH,BOARD_NXP_LPCXPRESS0_54102,PWRROMD_PRESENT,__FPU_PRESENT=1,CORE_M4,ANDROID_DEMO,DEBUG_BUILD,DEBUG_OUTPUT,ASF_PROFILING,ON_DEMAND_PROFILING + INTERNAL_FLASH,BOARD_NXP_LPCXPRESS0_54102,PWRROMD_PRESENT,__FPU_PRESENT=1,CORE_M4,ANDROID_DEMO,DEBUG_BUILD,DEBUG_OUTPUT,ASF_PROFILING,ON_DEMAND_PROFILING,DEVICE_INTERRUPTIN=1 - ..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;c:\keil_v5\arm\rv31\inc + ..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;..\..\..\..\include\hal;..\..\..\..\targets\TARGET_LPC54102 @@ -437,7 +437,7 @@ 0 0 0 - 2 + 0 2 2 2 @@ -1025,8 +1025,126 @@ + + TARGET_LPC54102 + + + gpio_api.c + 1 + ..\..\..\..\targets\TARGET_LPC54102\gpio_api.c + + + gpio_irq_api.c + 1 + ..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c + + + pinmap.c + 1 + ..\..\..\..\targets\TARGET_LPC54102\pinmap.c + + + + + ::CMSIS + + + 0 + 0 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + 2 + 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + RTE\CMSIS\RTX_Conf_CM.c + + + + + + + + + diff --git a/embedded/projects/osp-lpc54102/sources/HostInterface/SensorPackets.c b/embedded/projects/osp-lpc54102/sources/HostInterface/SensorPackets.c index f8e0169..c83da22 100644 --- a/embedded/projects/osp-lpc54102/sources/HostInterface/SensorPackets.c +++ b/embedded/projects/osp-lpc54102/sources/HostInterface/SensorPackets.c @@ -77,7 +77,7 @@ * @return MQ_SUCCESS or Error code enum corresponding to the error encountered * ***************************************************************************************************/ -static int16_t ParseSensorDataPkt( SensorPacketTypes_t *pOut, uint8_t *pPacket, uint16_t pktSize ) +static int16_t __attribute__((unused)) ParseSensorDataPkt( SensorPacketTypes_t *pOut, uint8_t *pPacket, uint16_t pktSize ) { HostIFPackets_t *pHif = (HostIFPackets_t*)pPacket; int16_t errCode = -MQ_UNSUPPORTED_FEATURE; @@ -664,14 +664,12 @@ int16_t FormatSensorEnableReq( uint8_t *pDest, osp_bool_t enable, ASensorType_t * @return MQ_SUCCESS or Error code enum corresponding to the error encountered * ***************************************************************************************************/ -static int16_t ParseControlRequestPkt( SensorPacketTypes_t *pOut, uint8_t *pPacket, uint16_t pktSize ) +static int16_t __attribute__((unused)) ParseControlRequestPkt( SensorPacketTypes_t *pOut, uint8_t *pPacket, uint16_t pktSize ) { HostIFPackets_t *pHif = (HostIFPackets_t*)pPacket; - int16_t errCode = -MQ_UNSUPPORTED_FEATURE; - uint8_t sensType; - osp_bool_t isPrivateType; - uint8_t seqNum; - int16_t lengthParsed; + uint8_t sensType __attribute__((unused)); + osp_bool_t isPrivateType __attribute__((unused)); + uint8_t seqNum __attribute__((unused)); /* Sanity... */ if ((pOut == NULL) || (pPacket == NULL)) diff --git a/embedded/projects/osp-lpc54102/sources/app/app_tasks.h b/embedded/projects/osp-lpc54102/sources/app/app_tasks.h index 04cbae9..e41344e 100644 --- a/embedded/projects/osp-lpc54102/sources/app/app_tasks.h +++ b/embedded/projects/osp-lpc54102/sources/app/app_tasks.h @@ -1,63 +1,63 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* This file in only included in ASF_Tasks.h and nowhere else */ - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -/** -** ASF_TASK_STATIC ( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) -** This macro declares a static thread that will be created (along with an -** associated queue) automatically by the ASF startup initialization and -** will persist throughout the lifetime of the application. -** -** Parameters: -** ThreadId - User defined C-Style identifier for the thread. -** E.g. MY_THREAD_ID. This identifier will be used in the -** application to access the thread properties and its -** associated queue. -** EntryFunction - Thread entry function name. -** Priority - Thread priority in the range of 51 through 254. Higher value -** implies higher priority. Values 0 through 50 are reserved and -** should not be used. -** StackSize - Thread stack size in bytes. -** QueueSize - This denotes the maximum number of messages that are allowed -** to be queued for the thread. An optimum value should be -** chosen for this parameter to minimize memory wastage. -** -** Example: ASF_TASK_STATIC ( COMM_THREAD, CommThreadEntry, 55, 1024, 10 ) -** -** Entry Function must be declared in the following manner: -** ASF_TASK MyThreadEntry ( ASF_TASK_ARG ) -** { -** ... -** } -** -*/ -/* Declare additional application specific tasks here */ -/* NOTE: STACK_INCREASE can be used to increase the stack size of all tasks by a constant amount. - This value is set in ASF_TaskInit.c file and is normally 0. Use this for Debugging crashes */ -#ifdef ANDROID_DEMO -ASF_TASK_STATIC( I2CSLAVE_COMM_TASK_ID, I2CCommTask, 150, (0x1080+STACK_INCREASE), 64 ) -#endif -ASF_TASK_STATIC( ALGORITHM_TASK_ID, AlgorithmTask, 90, (0x1080+STACK_INCREASE), 64 ) -ASF_TASK_STATIC( ALG_BG_TASK_ID, AlgBackGndTask, 85, (0x1080+STACK_INCREASE), 64 ) - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* This file in only included in ASF_Tasks.h and nowhere else */ + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +/** +** ASF_TASK_STATIC ( ThreadId, EntryFunction, Priority, StackSize, QueueSize ) +** This macro declares a static thread that will be created (along with an +** associated queue) automatically by the ASF startup initialization and +** will persist throughout the lifetime of the application. +** +** Parameters: +** ThreadId - User defined C-Style identifier for the thread. +** E.g. MY_THREAD_ID. This identifier will be used in the +** application to access the thread properties and its +** associated queue. +** EntryFunction - Thread entry function name. +** Priority - Thread priority in the range of 51 through 254. Higher value +** implies higher priority. Values 0 through 50 are reserved and +** should not be used. +** StackSize - Thread stack size in bytes. +** QueueSize - This denotes the maximum number of messages that are allowed +** to be queued for the thread. An optimum value should be +** chosen for this parameter to minimize memory wastage. +** +** Example: ASF_TASK_STATIC ( COMM_THREAD, CommThreadEntry, 55, 1024, 10 ) +** +** Entry Function must be declared in the following manner: +** ASF_TASK MyThreadEntry ( ASF_TASK_ARG ) +** { +** ... +** } +** +*/ +/* Declare additional application specific tasks here */ +/* NOTE: STACK_INCREASE can be used to increase the stack size of all tasks by a constant amount. + This value is set in ASF_TaskInit.c file and is normally 0. Use this for Debugging crashes */ +#ifdef ANDROID_DEMO +ASF_TASK_STATIC( I2CSLAVE_COMM_TASK_ID, I2CCommTask, osPriorityNormal, (0x200+STACK_INCREASE), 64 ) +#endif +ASF_TASK_STATIC( ALGORITHM_TASK_ID, AlgorithmTask, osPriorityNormal, (0x1000+STACK_INCREASE), 64 ) +ASF_TASK_STATIC( ALG_BG_TASK_ID, AlgBackGndTask, osPriorityLow, (0x200+STACK_INCREASE), 64 ) + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/sources/app/hostif.h b/embedded/projects/osp-lpc54102/sources/app/hostif.h index c6d7b85..f7e9b3f 100644 --- a/embedded/projects/osp-lpc54102/sources/app/hostif.h +++ b/embedded/projects/osp-lpc54102/sources/app/hostif.h @@ -33,6 +33,7 @@ #define _HOSTIF_H_ #include "spi-sensor-hub-priv.h" +#include "gpio_api.h" #ifdef __cplusplus extern "C" { @@ -65,7 +66,10 @@ void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic); */ static INLINE void Hostif_AssertIRQ(void) { - Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0); + //Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0); + gpio_t hostifIrq; + hostifIrq.pin = ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN); + gpio_write(&hostifIrq,0); } /** @@ -74,7 +78,10 @@ static INLINE void Hostif_AssertIRQ(void) */ static INLINE void Hostif_DeassertIRQ(void) { - Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1); + //Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1); + gpio_t hostifIrq; + hostifIrq.pin = ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN); + gpio_write(&hostifIrq,1); } /** @@ -83,7 +90,10 @@ static INLINE void Hostif_DeassertIRQ(void) */ static INLINE bool Hostif_IRQActive(void) { - return (Chip_GPIO_GetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN) == false); + //return (Chip_GPIO_GetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN) == false); + gpio_t hostifIrq; + hostifIrq.pin = ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN); + return (gpio_read(&hostifIrq) == false); } /** diff --git a/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c b/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c index 9a9ac22..469d13d 100644 --- a/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c +++ b/embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c @@ -28,7 +28,7 @@ * copyright, permission, and disclaimer notice must appear in all copies of * this code. */ -#include "board.h" +//#include "board.h" #include #include #include "sensorhub.h" @@ -275,8 +275,10 @@ void Hostif_Init(void) memset(&g_hostif, 0, sizeof(Hostif_Ctrl_t)); /* Setup I2C pin mux */ - Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* i2c2 */ - Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* I2C2 */ + //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* i2c2 */ + pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_27), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN)); + //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* I2C2 */ + pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_28), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN)); Chip_Clock_EnablePeriphClock(I2C_HOSTIF_CLK); Chip_SYSCON_PeriphReset(I2C_HOSTIF_RST); @@ -320,12 +322,18 @@ void Hostif_Init(void) ROM_I2CS_Transfer(hI2C, &i2cXfer); /* init host interrupt pin */ - Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN); - - /* de-assert interrupt line to high to indicate Host/AP that - * there is no data to receive - */ - Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1); + //Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN); + { + gpio_t hostifIrq; + hostifIrq.pin = ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN); + gpio_dir(&hostifIrq,PIN_OUTPUT); + + /* de-assert interrupt line to high to indicate Host/AP that + * there is no data to receive + */ + //Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1); + gpio_write(&hostifIrq,1); + } /* Enable the interrupt for the I2C */ NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY); diff --git a/embedded/projects/osp-lpc54102/sources/app/i2c_slavecomm_t.c b/embedded/projects/osp-lpc54102/sources/app/i2c_slavecomm_t.c index f01a1e1..e2ee663 100644 --- a/embedded/projects/osp-lpc54102/sources/app/i2c_slavecomm_t.c +++ b/embedded/projects/osp-lpc54102/sources/app/i2c_slavecomm_t.c @@ -1,726 +1,727 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/*-------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------*/ -#include "board.h" -#include "common.h" -#ifdef ANDROID_COMM_TASK -#include "hostinterface.h" -#include "osp-sensors.h" -#include -#include "sensorhub.h" -#include "SensorPackets.h" -#include "Queue.h" -#include "MQErrorCodes.h" -#include "osp_i2c_map.h" -#include "algorithm-api.h" //Algorithm API to subscribe sensor result - -#define HIF_PACKET_SIZE M_CalcBufferSize(sizeof(HostIFPackets_t)) - -#define FASTDATA_NUM_Q 3 -#define FASTDATA_LEN_Q 4096 - -struct DataBuf { - uint8_t DataChunk[FASTDATA_LEN_Q]; - volatile int length; - volatile int state; -}; - -volatile struct FastData { - struct DataBuf Databuf[FASTDATA_NUM_Q]; - volatile uint8_t write; - volatile uint8_t read; -} FDC; - -static uint8_t PacketMem[HIF_PACKET_SIZE]; - -// FIXME: Since OSP_CONFIG command is not implemented in the host, we need to set this value to 1 so FastData buffer is properly initialized on startup. -static volatile uint8_t ClearQueue = 1; // Original code set this to 0. - - -void Hostif_Init(void); -void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic); -void CHostif_StartTxChained(uint8_t *pBuf, uint16_t size, uint8_t *pBuf_next, uint16_t size_next, int magic); -int FastData_add(volatile struct FastData *FD, Buffer_t *pHIFPkt); - -/*-------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------*/ -/*-------------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------*/ -#define SH_WHO_AM_I 0x54 -#define SH_VERSION0 0x01 -#define SH_VERSION1 0x23 - -static uint32_t SensorState[2]; - -// TODO: Need to call algorithm module to subscribe the enable sensor. -static void SensorEnable(ASensorType_t sen) -{ - int v = (int)sen; - int set; - - if (v < 32) { - set = (1<write = 0; - FD->read = 0; - for (i = 0; i < FASTDATA_NUM_Q; i++) { - FD->Databuf[i].length = 0; - FD->Databuf[i].state = 0; - } -} - -int drops = 0; -static int FastData_add(volatile struct FastData *FD, Buffer_t *pHIFPkt) -{ - volatile struct DataBuf *DB; - static int state = 0; - static uint32_t lastTimeStamp = 0; - uint32_t curTime; - - if (ClearQueue) { - FastData_init(FD); - ClearQueue = 0; - } - - DB = &(FD->Databuf[FD->write]); - if (pHIFPkt->Header.Length+DB->length > FASTDATA_LEN_Q) { - if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { - drops++; - state = 1; - return 1; /* No more Q's available */ - } else { - if (state == 1) { - D0_printf("drops = %i\r\n", drops); - } - state = 0; - FD->write++; - FD->write %= FASTDATA_NUM_Q; - DB = &(FD->Databuf[FD->write]); - DB->length = 0; - DB->state = 0; - } - - } - memcpy(DB->DataChunk + DB->length, &(pHIFPkt->DataStart), pHIFPkt->Header.Length); - DB->length += pHIFPkt->Header.Length; - DB->state++; - curTime = GetCurrentTime(); - - if (lastTimeStamp != 0) { - if ((curTime - lastTimeStamp) > 1000) { - if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { - return 1; - } else { - FD->write++; - FD->write%=FASTDATA_NUM_Q; - DB = &(FD->Databuf[FD->write]); - DB->length = 0; - DB->state = 0; - } - } - } - - lastTimeStamp = curTime; - if (DB->state > 300) { - if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { - return 1; - } else { - FD->write++; - FD->write%=FASTDATA_NUM_Q; - DB = &(FD->Databuf[FD->write]); - DB->length = 0; - DB->state = 0; - } - } - return 0; -} - -static int FastData_get(struct FastData *FD) -{ - if (ClearQueue) return -1; /* Clear in progress */ - if (FD->read == FD->write) return -1; /* No data available */ - return FD->read; -} - -/************************************************************************ - * @fn SH_Slave_init - * Initialize the Sensor Hub I2C Slave register interface - * - ************************************************************************/ -static void SH_Slave_init(void) -{ - memset(&SlaveRegMap, 0, sizeof(SlaveRegMap)); - SlaveRegMap.version0 = SH_VERSION0; - SlaveRegMap.version1 = SH_VERSION1; - SlaveRegMap.whoami = SH_WHO_AM_I; - - SlaveRegMap.irq_cause = SH_MSG_IRQCAUSE_NEWMSG; - SlaveRegMap.read_len = 0; - SlaveRegMap.rd_mem[0] = SH_MSG_TYPE_ABS_ACCEL; -} - -/*************************************************************************** - * @fn SendSensorBoolData - * Sends boolean sensor data over the I2C slave interface - - * Enqueues data only. - * - ***************************************************************************/ - -static void SendSensorBoolData(ASensorType_t sensorType, MsgSensorBoolData *pMsg) -{ - Buffer_t *pHifPacket; - uint8_t *pPayload; - UncalibratedFixP_t UnCalFixPData; - - - /* Create packet and place in queue */ - - pHifPacket = (Buffer_t *)PacketMem; - - pPayload = M_GetBufferDataStart(pHifPacket); -#if 0 // Result to Android is now obsoleted in new OSP API - sensorType = ResultToAndroidTypeMap(sensorId); -#endif - //QUOC: Why need to check sensorType == 12? - if (sensorType == 12) __ASM volatile("BKPT #01"); - - // Do not send data if host did not activate this sensor type - if (GetSensorState(sensorType) == 0) - return; - - SensorHubAssertInt(); /* Assert interrupt to host */ - - /* Process sensor and format into packet */ - switch (sensorType) { - case SENSOR_STEP_DETECTOR: - case SENSOR_SIGNIFICANT_MOTION: - UnCalFixPData.TimeStamp.TS64 = pMsg->timeStamp; - UnCalFixPData.Axis[0] = pMsg->active; - UnCalFixPData.Axis[1] = 0; - UnCalFixPData.Axis[2] = 0; - UnCalFixPData.Offset[0] = 0; - UnCalFixPData.Offset[1] = 0; - UnCalFixPData.Offset[2] = 0; - - pHifPacket->Header.Length = FormatUncalibratedPktFixP(pPayload, - &UnCalFixPData, META_DATA_UNUSED, sensorType); - - break; - default: - return; - } - QueueOverFlow = FastData_add(&FDC, pHifPacket); -} - -/*************************************************************************** - * @fn SendSensorData - * Sends 3-axis sensor data over the I2C slave interface - - * Enqueues data only. - * - ***************************************************************************/ -static void SendSensorData(ASensorType_t sensorType, MsgSensorData *pMsg) -{ - Buffer_t *pHifPacket; - uint8_t *pPayload; - UncalibratedFixP_t UnCalFixPData; - CalibratedFixP_t CalFixPData; - QuaternionFixP_t QuatFixPData; - - /* Create packet and place in queue */ - - pHifPacket = (Buffer_t *)PacketMem; - - pPayload = M_GetBufferDataStart(pHifPacket); - -// sensorType = ResultToAndroidTypeMap(sensorId); -// if (sensorType == 12) __ASM volatile("BKPT #01"); - if (GetSensorState(sensorType) == 0) - return; - - SensorHubAssertInt(); /* Assert interrupt to host */ - - /* Process sensor and format into packet */ - switch (sensorType) { - case AP_PSENSOR_ACCELEROMETER_UNCALIBRATED: - case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: - case SENSOR_GYROSCOPE_UNCALIBRATED: - case SENSOR_PRESSURE: - case SENSOR_STEP_COUNTER: - UnCalFixPData.TimeStamp.TS64 = pMsg->timeStamp; - UnCalFixPData.Axis[0] = pMsg->X; - UnCalFixPData.Axis[1] = pMsg->Y; - UnCalFixPData.Axis[2] = pMsg->Z; - UnCalFixPData.Offset[0] = 0; - UnCalFixPData.Offset[1] = 0; - UnCalFixPData.Offset[2] = 0; - - pHifPacket->Header.Length = FormatUncalibratedPktFixP(pPayload, - &UnCalFixPData, META_DATA_UNUSED, sensorType); - break; - - case SENSOR_ACCELEROMETER: - case SENSOR_MAGNETIC_FIELD: - case SENSOR_GYROSCOPE: - CalFixPData.TimeStamp.TS64 = pMsg->timeStamp; - CalFixPData.Axis[0] = pMsg->X; - CalFixPData.Axis[1] = pMsg->Y; - CalFixPData.Axis[2] = pMsg->Z; - - pHifPacket->Header.Length = FormatCalibratedPktFixP(pPayload, - &CalFixPData, sensorType); - break; - case SENSOR_ROTATION_VECTOR: - case SENSOR_GEOMAGNETIC_ROTATION_VECTOR: - case SENSOR_GAME_ROTATION_VECTOR: - QuatFixPData.TimeStamp.TS64 = pMsg->timeStamp; - QuatFixPData.Quat[0] = pMsg->W; - QuatFixPData.Quat[1] = pMsg->X; - QuatFixPData.Quat[2] = pMsg->Y; - QuatFixPData.Quat[3] = pMsg->Z; - - pHifPacket->Header.Length = FormatQuaternionPktFixP(pPayload, - &QuatFixPData, sensorType); - break; - case SENSOR_ORIENTATION: - case SENSOR_GRAVITY: - case SENSOR_LINEAR_ACCELERATION: - CalFixPData.TimeStamp.TS64 = pMsg->timeStamp; - CalFixPData.Axis[0] = pMsg->X; - CalFixPData.Axis[1] = pMsg->Y; - CalFixPData.Axis[2] = pMsg->Z; - - pHifPacket->Header.Length = FormatCalibratedPktFixP(pPayload, - &CalFixPData, sensorType); - break; - default: - return; - } - - /* Enqueue packet in HIF queue */ - /* status = EnQueue(_HiFQueue, pHifPacket); */ - QueueOverFlow = FastData_add(&FDC, pHifPacket); -} - -extern volatile int i2cdoneflag; - -/*------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*------------------------------------------------------------------------*/ -static int proc_stat = 0; -uint8_t cmdlog[512]; -int cmdidx = 0; -uint8_t process_command(uint8_t *rx_buf, uint16_t length) -{ - uint8_t remain = 0; - int16_t status; - SensorPacketTypes_t Out; - int pack_sz; - int fdq; - - if (length < 1) return 0; - cmdlog[cmdidx] = rx_buf[0]; - cmdidx++; - cmdidx%=512; - switch (rx_buf[0]) { -#if 0 - case OSP_DATA_LEN: /* Get length */ - /* Note - Hostif_StartTx retains the pointer, - * i.e. it does NOT copy the data - */ - Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len), sizeof(SlaveRegMap.read_len), __LINE__); - - break; -#endif - case OSP_DATA_LEN_L: -#if 0 - Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len2), sizeof(SlaveRegMap.read_len2), __LINE__); -#endif - CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.read_len2), sizeof(SlaveRegMap.read_len2), - (uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); - - break; - case OSP_DATA_LEN_H: -#if 0 - Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len2)+1, sizeof(SlaveRegMap.read_len2)-1, __LINE__); -#endif - CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.read_len2)+1, sizeof(SlaveRegMap.read_len2)-1, - (uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); - - break; - case OSP_INT_LEN: - if (QueueOverFlow) { - SlaveRegMap.intlen = OSP_INT_OVER; - } else { - SlaveRegMap.intlen = OSP_INT_NONE; - } - pack_sz = 0; - fdq = FastData_get(&FDC); - if (fdq >= 0) { - SlaveRegMap.intlen = OSP_INT_DRDY; - - memcpy(SlaveRegMap.rd_mem, (void *)(FDC.Databuf[fdq].DataChunk), FDC.Databuf[fdq].length); - pack_sz = FDC.Databuf[fdq].length; - if (pack_sz < 2) { - __ASM volatile("BKPT #01"); - } - FDC.read++; - FDC.read %= FASTDATA_NUM_Q; - } else { - // No data to send so remove host interrupt assert signal - SensorHubDeAssertInt(); - } - SlaveRegMap.intlen |= (pack_sz << 4); - SlaveRegMap.read_len2 = pack_sz; - if (pack_sz == 0) { - Hostif_StartTx((uint8_t *)&(SlaveRegMap.intlen), sizeof(SlaveRegMap.intlen), __LINE__); - } else { - - CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.intlen), sizeof(SlaveRegMap.intlen), - (uint8_t *)SlaveRegMap.rd_mem, pack_sz, __LINE__); -#if 0 - D0_printf("Sending - len %i, pack %i intlen %x state %08x %08x\r\n", - pack_sz, FDC.Databuf[fdq].state, SlaveRegMap.intlen, SensorState[0], SensorState[1]); -#endif - } - break; - case OSP_INT_REASON: - if (QueueOverFlow) { - SlaveRegMap.irq_cause = OSP_INT_OVER; - } else { - SlaveRegMap.irq_cause = OSP_INT_NONE; - } - pack_sz = 0; - fdq = FastData_get(&FDC); - if (fdq >= 0) { - SlaveRegMap.irq_cause = OSP_INT_DRDY; - Hostif_StartTx((uint8_t *)&(SlaveRegMap.irq_cause), sizeof(SlaveRegMap.irq_cause), __LINE__); - - memcpy(SlaveRegMap.rd_mem, (void *)(FDC.Databuf[fdq].DataChunk), FDC.Databuf[fdq].length); - pack_sz = FDC.Databuf[fdq].length; - if (pack_sz < 2) { - __ASM volatile("BKPT #01"); - } - FDC.read++; - FDC.read %= FASTDATA_NUM_Q; - } else { - Hostif_StartTx((uint8_t *)&(SlaveRegMap.irq_cause), sizeof(SlaveRegMap.irq_cause), __LINE__); - SensorHubDeAssertInt(); - } - SlaveRegMap.read_len = pack_sz; - SlaveRegMap.read_len2 = pack_sz; - - break; - case OSP_WHOAMI: /* Who am */ - Hostif_StartTx((uint8_t *)(&SlaveRegMap.whoami), sizeof(SlaveRegMap.whoami), __LINE__); - break; - case OSP_VERSION0: - Hostif_StartTx((uint8_t *)(&SlaveRegMap.version0), sizeof(SlaveRegMap.version0), __LINE__); - break; - case OSP_VERSION1: - Hostif_StartTx((uint8_t *)(&SlaveRegMap.version1), sizeof(SlaveRegMap.version1), __LINE__); - break; - - case OSP_CONFIG: /* Reset, not implemented yet */ - /* Need to flush queue somewhere */ - QueueOverFlow = 0; - ClearQueue = 1; - break; - case OSP_DATA_OUT: /* Read data */ - if (SlaveRegMap.read_len2 == 0) - break; - if (SlaveRegMap.read_len2 < 3 && SlaveRegMap.read_len2 > 0) { - __ASM volatile("BKPT #01"); - } -#if 0 - Hostif_StartTx((uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); -#endif - break; - case OSP_DATA_IN: /* Write data */ - /* Host has written a packet */ - ParseHostIntefacePkt(&Out, &rx_buf[1], length-1); - break; - default: - if (rx_buf[0] >= 0x20 && rx_buf[0] < 0x50) { - /* ENABLE */ - SensorEnable((ASensorType_t)(rx_buf[0]-0x20)); - D0_printf("Enable %i\r\n", rx_buf[0] - 0x20); - } else if (rx_buf[0] >= 0x50 && rx_buf[0] < 0x80) { - /* DISABLE */ - SensorDisable((ASensorType_t)(rx_buf[0]-0x50)); - D0_printf("Disable %i\r\n", rx_buf[0] - 0x50); - } - break; - } - return remain; -} - -/********************************************************************** - * @fn I2CCommTask - * This tasks primary goal is to serialize the communication - * request (sensor results) going over I2C - * - * @param none - * - * @return none - * - **********************************************************************/ -ASF_TASK void I2CCommTask(ASF_TASK_ARG) -{ - MessageBuffer *rcvMsg = NULLP; - - FastData_init(&FDC); - - Hostif_Init(); - /* Active high int, set to in active */ - SensorHubDeAssertInt(); - /* Init register area for slave */ - SH_Slave_init(); - - SensorState[0] = 0; - SensorState[1] = 0; - SensorState[0] = 1 << SENSOR_SIGNIFICANT_MOTION; - - D0_printf("%s-> I2C Slave ready\r\n", __FUNCTION__); - while(1) { - ASFReceiveMessage(I2CSLAVE_COMM_TASK_ID, &rcvMsg ); - - //QLY - // D0_printf("%s-> Received message id: %d\r\n", rcvMsg->msgId); - switch (rcvMsg->msgId) { - case MSG_ACC_DATA: - SendSensorData(AP_PSENSOR_ACCELEROMETER_UNCALIBRATED, - &rcvMsg->msg.msgAccelData); - break; - case MSG_MAG_DATA: - SendSensorData(SENSOR_MAGNETIC_FIELD_UNCALIBRATED, - &rcvMsg->msg.msgMagData); - break; - case MSG_GYRO_DATA: - SendSensorData(SENSOR_GYROSCOPE_UNCALIBRATED, - &rcvMsg->msg.msgGyroData); - break; - case MSG_CAL_ACC_DATA: - SendSensorData(SENSOR_ACCELEROMETER, - &rcvMsg->msg.msgAccelData); - break; - case MSG_CAL_MAG_DATA: - SendSensorData(SENSOR_MAGNETIC_FIELD, - &rcvMsg->msg.msgMagData); - break; - case MSG_CAL_GYRO_DATA: - SendSensorData(SENSOR_GYROSCOPE, - &rcvMsg->msg.msgGyroData); - break; - case MSG_ORIENTATION_DATA: - SendSensorData(SENSOR_ORIENTATION, - &rcvMsg->msg.msgOrientationData); - break; - case MSG_QUATERNION_DATA: - SendSensorData(SENSOR_ROTATION_VECTOR, - &rcvMsg->msg.msgQuaternionData); - break; - case MSG_GEO_QUATERNION_DATA: - SendSensorData(SENSOR_GEOMAGNETIC_ROTATION_VECTOR, - &rcvMsg->msg.msgQuaternionData); - break; - case MSG_GAME_QUATERNION_DATA: - SendSensorData(SENSOR_GAME_ROTATION_VECTOR, - &rcvMsg->msg.msgQuaternionData); - break; - - case MSG_STEP_COUNT_DATA: - SendSensorData(SENSOR_STEP_COUNTER, - &rcvMsg->msg.msgStepCountData); - break; - case MSG_CD_SEGMENT_DATA: - break; - case MSG_LINEAR_ACCELERATION_DATA: - SendSensorData(SENSOR_LINEAR_ACCELERATION, - &rcvMsg->msg.msgLinearAccelerationData); - break; - case MSG_GRAVITY_DATA: - SendSensorData(SENSOR_GRAVITY, - &rcvMsg->msg.msgGravityData); - break; - case MSG_STEP_DETECT_DATA: - SendSensorBoolData(SENSOR_STEP_DETECTOR, - &rcvMsg->msg.msgStepDetData); - break; - case MSG_SIG_MOTION_DATA: - SendSensorBoolData(SENSOR_SIGNIFICANT_MOTION, - &rcvMsg->msg.msgSigMotionData); - D0_printf("SigMotion\n"); - break; - case MSG_PRESS_DATA: - SendSensorData(SENSOR_PRESSURE, - &rcvMsg->msg.msgPressData); - break; - default: - D1_printf("I2C:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); - break; - } - } -} -#endif //ANDROID_COMM_TASK - -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*-------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------*/ +#include "board.h" +#include "common.h" +#ifdef ANDROID_COMM_TASK +#include "hostinterface.h" +#include "osp-sensors.h" +#include +#include "sensorhub.h" +#include "SensorPackets.h" +#include "Queue.h" +#include "MQErrorCodes.h" +#include "osp_i2c_map.h" +#include "algorithm-api.h" //Algorithm API to subscribe sensor result + +#define HIF_PACKET_SIZE M_CalcBufferSize(sizeof(HostIFPackets_t)) + +#define FASTDATA_NUM_Q 3 +#define FASTDATA_LEN_Q 4096 + +struct DataBuf { + uint8_t DataChunk[FASTDATA_LEN_Q]; + volatile int length; + volatile int state; +}; + +volatile struct FastData { + struct DataBuf Databuf[FASTDATA_NUM_Q]; + volatile uint8_t write; + volatile uint8_t read; +} FDC; + +static uint8_t PacketMem[HIF_PACKET_SIZE]; + +// FIXME: Since OSP_CONFIG command is not implemented in the host, we need to set this value to 1 so FastData buffer is properly initialized on startup. +static volatile uint8_t ClearQueue = 1; // Original code set this to 0. + + +void Hostif_Init(void); +void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic); +void CHostif_StartTxChained(uint8_t *pBuf, uint16_t size, uint8_t *pBuf_next, uint16_t size_next, int magic); +int FastData_add(volatile struct FastData *FD, Buffer_t *pHIFPkt); + +/*-------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------*/ +#define SH_WHO_AM_I 0x54 +#define SH_VERSION0 0x01 +#define SH_VERSION1 0x23 + +static uint32_t SensorState[2]; + +// TODO: Need to call algorithm module to subscribe the enable sensor. +static void SensorEnable(ASensorType_t sen) +{ + int v = (int)sen; + int set; + + if (v < 32) { + set = (1<write = 0; + FD->read = 0; + for (i = 0; i < FASTDATA_NUM_Q; i++) { + FD->Databuf[i].length = 0; + FD->Databuf[i].state = 0; + } +} + +int drops = 0; +static int FastData_add(volatile struct FastData *FD, Buffer_t *pHIFPkt) +{ + volatile struct DataBuf *DB; + static int state = 0; + static uint32_t lastTimeStamp = 0; + uint32_t curTime; + + if (ClearQueue) { + FastData_init(FD); + ClearQueue = 0; + } + + DB = &(FD->Databuf[FD->write]); + if (pHIFPkt->Header.Length+DB->length > FASTDATA_LEN_Q) { + if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { + drops++; + state = 1; + return 1; /* No more Q's available */ + } else { + if (state == 1) { + D0_printf("drops = %i\r\n", drops); + } + state = 0; + FD->write++; + FD->write %= FASTDATA_NUM_Q; + DB = &(FD->Databuf[FD->write]); + DB->length = 0; + DB->state = 0; + } + + } + memcpy(DB->DataChunk + DB->length, &(pHIFPkt->DataStart), pHIFPkt->Header.Length); + DB->length += pHIFPkt->Header.Length; + DB->state++; + curTime = GetCurrentTime(); + + if (lastTimeStamp != 0) { + if ((curTime - lastTimeStamp) > 1000) { + if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { + return 1; + } else { + FD->write++; + FD->write%=FASTDATA_NUM_Q; + DB = &(FD->Databuf[FD->write]); + DB->length = 0; + DB->state = 0; + } + } + } + + lastTimeStamp = curTime; + if (DB->state > 300) { + if (((FD->write+1)%FASTDATA_NUM_Q) == FD->read) { + return 1; + } else { + FD->write++; + FD->write%=FASTDATA_NUM_Q; + DB = &(FD->Databuf[FD->write]); + DB->length = 0; + DB->state = 0; + } + } + return 0; +} + +static int FastData_get(struct FastData *FD) +{ + if (ClearQueue) return -1; /* Clear in progress */ + if (FD->read == FD->write) return -1; /* No data available */ + return FD->read; +} + +/************************************************************************ + * @fn SH_Slave_init + * Initialize the Sensor Hub I2C Slave register interface + * + ************************************************************************/ +static void SH_Slave_init(void) +{ + memset(&SlaveRegMap, 0, sizeof(SlaveRegMap)); + SlaveRegMap.version0 = SH_VERSION0; + SlaveRegMap.version1 = SH_VERSION1; + SlaveRegMap.whoami = SH_WHO_AM_I; + + SlaveRegMap.irq_cause = SH_MSG_IRQCAUSE_NEWMSG; + SlaveRegMap.read_len = 0; + SlaveRegMap.rd_mem[0] = SH_MSG_TYPE_ABS_ACCEL; +} + +/*************************************************************************** + * @fn SendSensorBoolData + * Sends boolean sensor data over the I2C slave interface + + * Enqueues data only. + * + ***************************************************************************/ + +static void SendSensorBoolData(ASensorType_t sensorType, MsgSensorBoolData *pMsg) +{ + Buffer_t *pHifPacket; + uint8_t *pPayload; + UncalibratedFixP_t UnCalFixPData; + + + /* Create packet and place in queue */ + + pHifPacket = (Buffer_t *)PacketMem; + + pPayload = M_GetBufferDataStart(pHifPacket); +#if 0 // Result to Android is now obsoleted in new OSP API + sensorType = ResultToAndroidTypeMap(sensorId); +#endif + //QUOC: Why need to check sensorType == 12? + if (sensorType == 12) __ASM volatile("BKPT #01"); + + // Do not send data if host did not activate this sensor type + if (GetSensorState(sensorType) == 0) + return; + + SensorHubAssertInt(); /* Assert interrupt to host */ + + /* Process sensor and format into packet */ + switch (sensorType) { + case SENSOR_STEP_DETECTOR: + case SENSOR_SIGNIFICANT_MOTION: + UnCalFixPData.TimeStamp.TS64 = pMsg->timeStamp; + UnCalFixPData.Axis[0] = pMsg->active; + UnCalFixPData.Axis[1] = 0; + UnCalFixPData.Axis[2] = 0; + UnCalFixPData.Offset[0] = 0; + UnCalFixPData.Offset[1] = 0; + UnCalFixPData.Offset[2] = 0; + + pHifPacket->Header.Length = FormatUncalibratedPktFixP(pPayload, + &UnCalFixPData, META_DATA_UNUSED, sensorType); + + break; + default: + return; + } + QueueOverFlow = FastData_add(&FDC, pHifPacket); +} + +/*************************************************************************** + * @fn SendSensorData + * Sends 3-axis sensor data over the I2C slave interface + + * Enqueues data only. + * + ***************************************************************************/ +static void SendSensorData(ASensorType_t sensorType, MsgSensorData *pMsg) +{ + Buffer_t *pHifPacket; + uint8_t *pPayload; + UncalibratedFixP_t UnCalFixPData; + CalibratedFixP_t CalFixPData; + QuaternionFixP_t QuatFixPData; + + /* Create packet and place in queue */ + + pHifPacket = (Buffer_t *)PacketMem; + + pPayload = M_GetBufferDataStart(pHifPacket); + +// sensorType = ResultToAndroidTypeMap(sensorId); +// if (sensorType == 12) __ASM volatile("BKPT #01"); + if (GetSensorState(sensorType) == 0) + return; + + SensorHubAssertInt(); /* Assert interrupt to host */ + + /* Process sensor and format into packet */ + switch (sensorType) { + case AP_PSENSOR_ACCELEROMETER_UNCALIBRATED: + case SENSOR_MAGNETIC_FIELD_UNCALIBRATED: + case SENSOR_GYROSCOPE_UNCALIBRATED: + case SENSOR_PRESSURE: + case SENSOR_STEP_COUNTER: + UnCalFixPData.TimeStamp.TS64 = pMsg->timeStamp; + UnCalFixPData.Axis[0] = pMsg->X; + UnCalFixPData.Axis[1] = pMsg->Y; + UnCalFixPData.Axis[2] = pMsg->Z; + UnCalFixPData.Offset[0] = 0; + UnCalFixPData.Offset[1] = 0; + UnCalFixPData.Offset[2] = 0; + + pHifPacket->Header.Length = FormatUncalibratedPktFixP(pPayload, + &UnCalFixPData, META_DATA_UNUSED, sensorType); + break; + + case SENSOR_ACCELEROMETER: + case SENSOR_MAGNETIC_FIELD: + case SENSOR_GYROSCOPE: + CalFixPData.TimeStamp.TS64 = pMsg->timeStamp; + CalFixPData.Axis[0] = pMsg->X; + CalFixPData.Axis[1] = pMsg->Y; + CalFixPData.Axis[2] = pMsg->Z; + + pHifPacket->Header.Length = FormatCalibratedPktFixP(pPayload, + &CalFixPData, sensorType); + break; + case SENSOR_ROTATION_VECTOR: + case SENSOR_GEOMAGNETIC_ROTATION_VECTOR: + case SENSOR_GAME_ROTATION_VECTOR: + QuatFixPData.TimeStamp.TS64 = pMsg->timeStamp; + QuatFixPData.Quat[0] = pMsg->W; + QuatFixPData.Quat[1] = pMsg->X; + QuatFixPData.Quat[2] = pMsg->Y; + QuatFixPData.Quat[3] = pMsg->Z; + + pHifPacket->Header.Length = FormatQuaternionPktFixP(pPayload, + &QuatFixPData, sensorType); + break; + case SENSOR_ORIENTATION: + case SENSOR_GRAVITY: + case SENSOR_LINEAR_ACCELERATION: + CalFixPData.TimeStamp.TS64 = pMsg->timeStamp; + CalFixPData.Axis[0] = pMsg->X; + CalFixPData.Axis[1] = pMsg->Y; + CalFixPData.Axis[2] = pMsg->Z; + + pHifPacket->Header.Length = FormatCalibratedPktFixP(pPayload, + &CalFixPData, sensorType); + break; + default: + return; + } + + /* Enqueue packet in HIF queue */ + /* status = EnQueue(_HiFQueue, pHifPacket); */ + QueueOverFlow = FastData_add(&FDC, pHifPacket); +} + +extern volatile int i2cdoneflag; + +/*------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*------------------------------------------------------------------------*/ +static int proc_stat = 0; +uint8_t cmdlog[512]; +int cmdidx = 0; +uint8_t process_command(uint8_t *rx_buf, uint16_t length) +{ + uint8_t remain = 0; + int16_t status; + SensorPacketTypes_t Out; + int pack_sz; + int fdq; + + if (length < 1) return 0; + cmdlog[cmdidx] = rx_buf[0]; + cmdidx++; + cmdidx%=512; + switch (rx_buf[0]) { +#if 0 + case OSP_DATA_LEN: /* Get length */ + /* Note - Hostif_StartTx retains the pointer, + * i.e. it does NOT copy the data + */ + Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len), sizeof(SlaveRegMap.read_len), __LINE__); + + break; +#endif + case OSP_DATA_LEN_L: +#if 0 + Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len2), sizeof(SlaveRegMap.read_len2), __LINE__); +#endif + CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.read_len2), sizeof(SlaveRegMap.read_len2), + (uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); + + break; + case OSP_DATA_LEN_H: +#if 0 + Hostif_StartTx((uint8_t *)(&SlaveRegMap.read_len2)+1, sizeof(SlaveRegMap.read_len2)-1, __LINE__); +#endif + CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.read_len2)+1, sizeof(SlaveRegMap.read_len2)-1, + (uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); + + break; + case OSP_INT_LEN: + if (QueueOverFlow) { + SlaveRegMap.intlen = OSP_INT_OVER; + } else { + SlaveRegMap.intlen = OSP_INT_NONE; + } + pack_sz = 0; + fdq = FastData_get(&FDC); + if (fdq >= 0) { + SlaveRegMap.intlen = OSP_INT_DRDY; + + memcpy(SlaveRegMap.rd_mem, (void *)(FDC.Databuf[fdq].DataChunk), FDC.Databuf[fdq].length); + pack_sz = FDC.Databuf[fdq].length; + if (pack_sz < 2) { + __ASM volatile("BKPT #01"); + } + FDC.read++; + FDC.read %= FASTDATA_NUM_Q; + } else { + // No data to send so remove host interrupt assert signal + SensorHubDeAssertInt(); + } + SlaveRegMap.intlen |= (pack_sz << 4); + SlaveRegMap.read_len2 = pack_sz; + if (pack_sz == 0) { + Hostif_StartTx((uint8_t *)&(SlaveRegMap.intlen), sizeof(SlaveRegMap.intlen), __LINE__); + } else { + + CHostif_StartTxChained((uint8_t *)&(SlaveRegMap.intlen), sizeof(SlaveRegMap.intlen), + (uint8_t *)SlaveRegMap.rd_mem, pack_sz, __LINE__); +#if 0 + D0_printf("Sending - len %i, pack %i intlen %x state %08x %08x\r\n", + pack_sz, FDC.Databuf[fdq].state, SlaveRegMap.intlen, SensorState[0], SensorState[1]); +#endif + } + break; + case OSP_INT_REASON: + if (QueueOverFlow) { + SlaveRegMap.irq_cause = OSP_INT_OVER; + } else { + SlaveRegMap.irq_cause = OSP_INT_NONE; + } + pack_sz = 0; + fdq = FastData_get(&FDC); + if (fdq >= 0) { + SlaveRegMap.irq_cause = OSP_INT_DRDY; + Hostif_StartTx((uint8_t *)&(SlaveRegMap.irq_cause), sizeof(SlaveRegMap.irq_cause), __LINE__); + + memcpy(SlaveRegMap.rd_mem, (void *)(FDC.Databuf[fdq].DataChunk), FDC.Databuf[fdq].length); + pack_sz = FDC.Databuf[fdq].length; + if (pack_sz < 2) { + __ASM volatile("BKPT #01"); + } + FDC.read++; + FDC.read %= FASTDATA_NUM_Q; + } else { + Hostif_StartTx((uint8_t *)&(SlaveRegMap.irq_cause), sizeof(SlaveRegMap.irq_cause), __LINE__); + SensorHubDeAssertInt(); + } + SlaveRegMap.read_len = pack_sz; + SlaveRegMap.read_len2 = pack_sz; + + break; + case OSP_WHOAMI: /* Who am */ + Hostif_StartTx((uint8_t *)(&SlaveRegMap.whoami), sizeof(SlaveRegMap.whoami), __LINE__); + break; + case OSP_VERSION0: + Hostif_StartTx((uint8_t *)(&SlaveRegMap.version0), sizeof(SlaveRegMap.version0), __LINE__); + break; + case OSP_VERSION1: + Hostif_StartTx((uint8_t *)(&SlaveRegMap.version1), sizeof(SlaveRegMap.version1), __LINE__); + break; + + case OSP_CONFIG: /* Reset, not implemented yet */ + /* Need to flush queue somewhere */ + QueueOverFlow = 0; + ClearQueue = 1; + break; + case OSP_DATA_OUT: /* Read data */ + if (SlaveRegMap.read_len2 == 0) + break; + if (SlaveRegMap.read_len2 < 3 && SlaveRegMap.read_len2 > 0) { + __ASM volatile("BKPT #01"); + } +#if 0 + Hostif_StartTx((uint8_t *)SlaveRegMap.rd_mem, SlaveRegMap.read_len2, __LINE__); +#endif + break; + case OSP_DATA_IN: /* Write data */ + /* Host has written a packet */ + ParseHostIntefacePkt(&Out, &rx_buf[1], length-1); + break; + default: + if (rx_buf[0] >= 0x20 && rx_buf[0] < 0x50) { + /* ENABLE */ + SensorEnable((ASensorType_t)(rx_buf[0]-0x20)); + D0_printf("Enable %i\r\n", rx_buf[0] - 0x20); + } else if (rx_buf[0] >= 0x50 && rx_buf[0] < 0x80) { + /* DISABLE */ + SensorDisable((ASensorType_t)(rx_buf[0]-0x50)); + D0_printf("Disable %i\r\n", rx_buf[0] - 0x50); + } + break; + } + return remain; +} + +/********************************************************************** + * @fn I2CCommTask + * This tasks primary goal is to serialize the communication + * request (sensor results) going over I2C + * + * @param none + * + * @return none + * + **********************************************************************/ +ASF_TASK void I2CCommTask(ASF_TASK_ARG) +{ + MessageBuffer *rcvMsg = NULLP; + + FastData_init(&FDC); + + Hostif_Init(); + /* Active high int, set to in active */ + SensorHubDeAssertInt(); + /* Init register area for slave */ + SH_Slave_init(); + + SensorState[0] = 0; + SensorState[1] = 0; + SensorState[0] = 1 << SENSOR_SIGNIFICANT_MOTION; + + D0_printf("%s-> I2C Slave ready\r\n", __FUNCTION__); + while(1) { + ASFReceiveMessage(I2CSLAVE_COMM_TASK_ID, &rcvMsg ); + + //QLY + // D0_printf("%s-> Received message id: %d\r\n", rcvMsg->msgId); + switch (rcvMsg->msgId) { + case MSG_ACC_DATA: + SendSensorData(AP_PSENSOR_ACCELEROMETER_UNCALIBRATED, + &rcvMsg->msg.msgAccelData); + break; + case MSG_MAG_DATA: + SendSensorData(SENSOR_MAGNETIC_FIELD_UNCALIBRATED, + &rcvMsg->msg.msgMagData); + break; + case MSG_GYRO_DATA: + SendSensorData(SENSOR_GYROSCOPE_UNCALIBRATED, + &rcvMsg->msg.msgGyroData); + break; + case MSG_CAL_ACC_DATA: + SendSensorData(SENSOR_ACCELEROMETER, + &rcvMsg->msg.msgAccelData); + break; + case MSG_CAL_MAG_DATA: + SendSensorData(SENSOR_MAGNETIC_FIELD, + &rcvMsg->msg.msgMagData); + break; + case MSG_CAL_GYRO_DATA: + SendSensorData(SENSOR_GYROSCOPE, + &rcvMsg->msg.msgGyroData); + break; + case MSG_ORIENTATION_DATA: + SendSensorData(SENSOR_ORIENTATION, + &rcvMsg->msg.msgOrientationData); + break; + case MSG_QUATERNION_DATA: + SendSensorData(SENSOR_ROTATION_VECTOR, + &rcvMsg->msg.msgQuaternionData); + break; + case MSG_GEO_QUATERNION_DATA: + SendSensorData(SENSOR_GEOMAGNETIC_ROTATION_VECTOR, + &rcvMsg->msg.msgQuaternionData); + break; + case MSG_GAME_QUATERNION_DATA: + SendSensorData(SENSOR_GAME_ROTATION_VECTOR, + &rcvMsg->msg.msgQuaternionData); + break; + + case MSG_STEP_COUNT_DATA: + SendSensorData(SENSOR_STEP_COUNTER, + &rcvMsg->msg.msgStepCountData); + break; + case MSG_CD_SEGMENT_DATA: + break; + case MSG_LINEAR_ACCELERATION_DATA: + SendSensorData(SENSOR_LINEAR_ACCELERATION, + &rcvMsg->msg.msgLinearAccelerationData); + break; + case MSG_GRAVITY_DATA: + SendSensorData(SENSOR_GRAVITY, + &rcvMsg->msg.msgGravityData); + break; + case MSG_STEP_DETECT_DATA: + SendSensorBoolData(SENSOR_STEP_DETECTOR, + &rcvMsg->msg.msgStepDetData); + break; + case MSG_SIG_MOTION_DATA: + SendSensorBoolData(SENSOR_SIGNIFICANT_MOTION, + &rcvMsg->msg.msgSigMotionData); + D0_printf("SigMotion\n"); + break; + case MSG_PRESS_DATA: + SendSensorData(SENSOR_PRESSURE, + &rcvMsg->msg.msgPressData); + break; + default: + D1_printf("I2C:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); + break; + } + ASFDeleteMessage(I2CSLAVE_COMM_TASK_ID, &rcvMsg ); + } +} +#endif //ANDROID_COMM_TASK + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/sources/app/main.c b/embedded/projects/osp-lpc54102/sources/app/main.c index 53aa89b..a50c489 100644 --- a/embedded/projects/osp-lpc54102/sources/app/main.c +++ b/embedded/projects/osp-lpc54102/sources/app/main.c @@ -1,767 +1,792 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/*---------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*---------------------------------------------------------------------*/ -#include "board.h" -#include "common.h" -#include "hw_setup.h" -#include "sensorhub.h" -#include -#include "romapi_uart.h" - - -/*---------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*---------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*---------------------------------------------------------------------*/ -#ifdef DEBUG_BUILD -char _errBuff[ERR_LOG_MSG_SZ]; -#endif -uint32_t g_logging = 0x00; - -/*---------------------------------------------------------------------*\ - | P R I V A T E C O N S T A N T S & M A C R O S -\*---------------------------------------------------------------------*/ -/* UART handle and memory for ROM API */ -//static UART_HANDLE_T uartHandle; - -/* Use a buffer size larger than the expected return value of - uart_get_mem_size() for the static UART handle type */ -//static uint32_t uartHandleMEM[0x10]; - -/* UART Driver context memory */ -#define RAMBLOCK_H 60 -static uint32_t uartHandleMem[RAMBLOCK_H]; - -/* UART ROM Driver Handle */ -static UART_HANDLE_T *hUART; - -#define UART_BAUD_RATE 115200 /* Required UART Baud rate */ -#define UART_BUAD_ERR 1/* Percentage of Error allowed in baud */ - -#define tmsg1(x) "Type chars to echo them back\r\n" -#define tmsg(x) tmsg1(x) -#define RX_SZ 16 -#define msg tmsg(RX_SZ) -#define rmsg "UART received : " - -volatile uint32_t tx_done, rx_done; -/*---------------------------------------------------------------------*\ - | P R I V A T E T Y P E D E F I N I T I O N S -\*---------------------------------------------------------------------*/ -/* PLL clock source, must be one of the following: - * SYSCON_PLLCLKSRC_IRC, SYSCON_PLLCLKSRC_CLKIN, - * SYSCON_PLLCLKSRC_WDTOSC, SYSCON_PLLCLKSRC_RTC. - */ -#define PLLCLOCKSOURCE SYSCON_PLLCLKSRC_IRC - -/*---------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*---------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------*\ - | F O R W A R D F U N C T I O N D E C L A R A T I O N S -\*---------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*---------------------------------------------------------------------*/ -#if 0 // comment out since it is not use -static void errorUART(void) -{ - Board_LED_Set(1, true); - while (1) {} -} -#endif - -/* UART Pin mux function - note that SystemInit() may already setup your - pin muxing at system startup */ -static void UART_PinMuxSetup(void) -{ -#if defined(BOARD_NXP_LPCXPRESSO_54102) - /* Setup UART TX Pin */ - Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); - /* Setup UART RX Pin */ - Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 1, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); - Chip_SYSCON_Enable_ASYNC_Syscon(true); /* Enable Async APB */ - Chip_Clock_SetAsyncSysconClockDiv(1); /* Set Async clock divider to 1 */ -#else -#warning "No UART PIN/CLK setup for this example" -#endif -} - -/* Initialize the UART ROM Driver */ -static int uartrom_init(void) -{ - int sz; - - UART_PinMuxSetup(); - - sz = ROM_UART_GetMemSize(); - - if (RAMBLOCK_H < (sz / 4)) { - while (1) {} - } - - hUART = ROM_UART_Init(uartHandleMem, LPC_USART0_BASE, 0); - - return 0; -} - -#define ABS(x) ((int) (x) < 0 ? -(x) : (x)) -/* Configure UART ROM Driver and pripheral */ -static int uartrom_config(void) -{ - UART_CFG_T cfg; - UART_BAUD_T baud; - - /* Set up baudrate parameters */ - baud.clk = Chip_Clock_GetAsyncSyscon_ClockRate(); /* Clock frequency */ - baud.baud = UART_BAUD_RATE; /* Required baud rate */ - baud.ovr = 0; /* Set the oversampling to the recommended rate */ - baud.mul = baud.div = 0; - - if (ROM_UART_CalBaud(&baud) != LPC_OK) { - /* Unable to calculate the baud rate parameters */ - while (1) {} - } - - /* Set fractional control register */ - Chip_SYSCON_SetUSARTFRGCtrl(baud.mul, 255); - - /* See if the calculated baud is < +/- UART_BUAD_ERR% of the required baud */ - if (ABS(baud.baud - UART_BAUD_RATE) > (UART_BAUD_RATE * UART_BUAD_ERR) / 100) { - /* WARNING: Baud rate is has more than UART_BUAD_ERR percentage */ - /* Try to auto-detect the Oversampling rate by setting baud.ovr to 0 */ - while (1) {} - } - - /* Configure the UART */ - cfg.cfg = UART_CFG_8BIT | UART_CFG_BRKRX; - cfg.div = baud.div; /* Use the calculated div value */ - cfg.ovr = baud.ovr; /* Use oversampling rate from baud */ - cfg.res = UART_BIT_DLY(UART_BAUD_RATE); - - /* Configure the UART */ - ROM_UART_Configure(hUART, &cfg); - NVIC_ClearPendingIRQ(UART0_IRQn); - NVIC_EnableIRQ(UART0_IRQn); - - return 0; -} - - -/* UART ROM error handler */ -static void uartrom_error(UART_HANDLE_T hUART, uint32_t err) -{ - switch (err) { - case UART_ERROR_FRAME: - /* No stop bit in uart frame; mismatched baud(?) or incorrect/short BREAK condition(?) */ - Board_LED_Set(0, 1); - break; - - case UART_ERROR_PARITY: - /* Parity error; mismatched baud(?) */ - while (1) {} - - case UART_ERROR_AUTOBAUD: - /* Autobaud timeout error */ - while (1) {} - - case UART_ERROR_OVERRUN: - /* Uart received character before ROM_UART_Receive() is called */ - Board_LED_Set(1, 1); - break; - - case UART_ERROR_RXNOISE: - /* Typically problem is with the baud rate and or Over sampling count */ - while (1) {} - - default: - /* Control will never reach this */ - break; - } -} - -/* UART ROM event handler */ -static void uartrom_event(UART_HANDLE_T hUART, uint32_t evt) -{ - switch (evt) { - case UART_EVENT_BREAK: - Board_LED_Set(2, 1); /* TURN ON LED_2 when BREAK is received on RX line */ - break; - - case UART_EVENT_NOBREAK: - Board_LED_Set(2, 0); /* TURN OFF LED_2 when RX comes out of break */ - break; - - case UART_EVENT_TXIDLE: - /* Can be used for flow control */ - /* This will be called when the TX shift register is done with - sending the last bit to uart line; event will be called only - after calling ROM_UART_SetCtrl(hUART, UART_TXIDLE_ON), event - can be turned off using ROM_UART_SetCtrl(hUART, UART_TXIDLE_OFF) - */ - break; - - case UART_EVENT_TXPAUSED: - /* Event will happen after ROM_UART_SetCtrl(hUART, UART_TX_PAUSE) is - called. This event does not mean the the TX is idle, meaning, the - TX holding register might contain data (which is not loaded into - TX shift register anymore) and the the TX shift register is done - sending the data that it was sending when UART_TX_PAUSE was called. - */ - /* Can be used to implement flow control or safely send BREAK signal - without createing frame errors in the currently transmitted data - */ - break; - - case UART_EVENT_CTSHI: - /* CTS line went from Low to High */ - /* Could be used for flow control or RS-485 implementations */ - break; - - case UART_EVENT_CTSLO: - /* CTS line went from High to Low */ - /* Could be used for flow control or RS-485 implementations */ - break; - - default: - while (1) {} /* Control will never reach here */ - } -} - -/* Call-back handler for error/event */ -static void uartrom_xfer_errevt(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) -{ - uint32_t val = (uint32_t) arg; - if (evt == UART_EV_ERROR) { - uartrom_error(hUART, val); - } - else if (evt == UART_EV_EVENT) { - uartrom_event(hUART, val); - } - else { - while (1) {}/* Control will never reach this */ - - } -} - -/* UART Transfer done */ -static void uartrom_xfer_done(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) -{ - UART_DATA_T *dat = (UART_DATA_T *) arg; - - switch (evt) { - case UART_TX_DONE: - tx_done = 1; - break; - - case UART_RX_DONE: - rx_done = dat->count; - break; - - default: - while (1) {} /* Control will never reach here */ - } -} - -/* UART transfer start */ -static void uartrom_xfer_start(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) -{ - UART_DATA_T *dat = (UART_DATA_T *) arg; - - (void) *dat; - switch (evt) { - case UART_TX_START: - /* Transmit of new buffer started */ - break; - - case UART_RX_START: - /* Receive of data started; can be used to implement timer logic */ - break; - - default: - while (1) {} /* Control will never reach here */ - } -} - -static void uartrom_rx_prog(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) -{ - UART_DATA_T *dat = (UART_DATA_T *) arg; - - switch (evt) { - case UART_RX_INPROG: - break; - - case UART_RX_NOPROG: - /* In case of frame error restart xfer */ - if (dat->state == UART_ST_ERRFRM) { - dat->offset = 0; - dat->state = UART_ST_BUSY; - } - else { - /* If the received frame has errors don't stop just restart */ - ROM_UART_SetCtrl(hUART, UART_RX_STOP); - } - break; - - default: - break; /* Control should never reach here */ - } -} - -/* Register call-backs */ -static void uartrom_regcb(void) -{ - ROM_UART_RegisterCB(hUART, UART_CB_START, uartrom_xfer_start); /* Start of transfer */ - ROM_UART_RegisterCB(hUART, UART_CB_DONE, uartrom_xfer_done);/* End of transfer */ - ROM_UART_RegisterCB(hUART, UART_CB_ERREVT, uartrom_xfer_errevt);/* Error/Event callbacks */ - ROM_UART_RegisterCB(hUART, UART_CB_RXPROG, uartrom_rx_prog);/* Receive progress callback */ -} - - - -#if 0 -/* Setup UART handle and parameters */ -static void setupUART() -{ - uint32_t frg_mult; - - /* 4*115.2KBPS, 8N1, ASYNC mode, no errors, clock filled in later */ - UART_CONFIG_T cfg = { - 0, /* U_PCLK frequency in Hz */ - 115200*4, /* Baud Rate in Hz */ - 1, /* 8N1 */ - 0, /* Asynchronous Mode */ - NO_ERR_EN /* Enable No Errors */ - }; - - /* Perform a sanity check on the storage allocation */ - if (LPC_UARTD_API->uart_get_mem_size() > sizeof(uartHandleMEM)) { - /* Example only: this should never happen and probably isn't needed for - most UART code. */ - errorUART(); - } - - /* Setup the UART handle */ - uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) &uartHandleMEM); - if (uartHandle == NULL) { - errorUART(); - } - - /* Need to tell UART ROM API function the current UART peripheral clock - speed */ - cfg.sys_clk_in_hz = Chip_Clock_GetAsyncSysconClockRate(); - - /* Initialize the UART with the configuration parameters */ - frg_mult = LPC_UARTD_API->uart_init(uartHandle, &cfg); - if (frg_mult) { - Chip_Clock_EnableAsyncPeriphClock(ASYNC_SYSCTL_CLOCK_FRG); - Chip_SYSCTL_SetUSARTFRGCtrl(frg_mult, 0xFF); - } -} -#endif - -/* Send a string on the UART terminated by a NULL character using - polling mode. */ -void putLineUART(const char *send_data) -{ -#if 0 - UART_PARAM_T param; - - param.buffer = (uint8_t *) send_data; - param.size = strlen(send_data); - - /* Polling mode, do not append CR/LF to sent data */ - param.transfer_mode = TX_MODE_SZERO; - param.driver_mode = DRIVER_MODE_POLLING; - - /* Transmit the data */ - if (LPC_UARTD_API->uart_put_line(uartHandle, ¶m)) { - while(0) errorUART(); - } -#else - //ROM_UART_Send(hUART, send_data, sizeof(send_data) - 1); - Board_UARTPutSTR((char*)send_data); -#endif -} - -void put_u32(uint32_t v) -{ - int i; - uint32_t m; - uint8_t c; - char str[9]; - m = 0xf0000000; - for (i = 0; i < 8; i++) { - c= ((m&v) >> (28-i*4)); - str[i] = (c > 9) ? (c+'a'):(c+'0'); - } - str[8] = '\0'; - putLineUART(str); -} -static uint32_t volatile wdtOCount; -static uint32_t calWdtFreq, upperOfLimit; -static uint8_t volatile timer40HiByte; - -/* Maximum WDT timeout value */ -#define WDTMAXTIMEOUTVAL 0x00FFFFFF - -/* WDT window size */ -#define WDTWINDOWSIZE 512 - -/* WDT timeout value used for this timer. Must be smaller than - (WDTMAXTIMEOUTVAL + window size) */ -#define WDTTIMEOUTVAL (WDTMAXTIMEOUTVAL - (WDTWINDOWSIZE + 1)) -/* Enable this define to lower the kernel timer resolution by the shift - value. Use 1 for /2, 2 for /4, 3 for /8, etc. This won't affect how the - kernel timer works. Use 0 to disable. Maximum is 8. */ -#define KERNELTIMERSHIFT 0 - -#if 1 -/* Calibrate WDT oscillator as best as possible to IRC rate. Assumes the IRC - is already running, but doesn't need to be the main clock source. */ -static void wdt_calOsc(void) -{ - Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_INPUTMUX); - - /* Setup to measure the selected target using the IRC as the reference */ - Chip_INMUX_SetFreqMeasRefClock(FREQMSR_IRC); - Chip_INMUX_SetFreqMeasTargClock(FREQMSR_WDOSC); - - /* Start a measurement cycle and wait for it to complete. */ - Chip_SYSCON_StartFreqMeas(); - while (!Chip_SYSCON_IsFreqMeasComplete()) {} - - /* Get computed frequency */ - calWdtFreq = Chip_SYSCON_GetCompFreqMeas(Chip_Clock_GetIntOscRate()); - - /* Frequency into WDT as a fixed divider of 4 */ - calWdtFreq = calWdtFreq / 4; -} - -static void wdt_init(void) -{ - /* Enable the power to the WDT Oscillator */ - Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_WDT_OSC); - - /* Get WDT oscilaltor rate using frequency measurement */ - wdt_calOsc(); - - /* Adjust kernel frequency by divider */ - calWdtFreq = calWdtFreq >> KERNELTIMERSHIFT; - - /* Determine overflow limit */ - //upperOfLimit = (0xFFFFFFFF / calWdtFreq) - 1; - upperOfLimit = (0xFFFFFFFF / (WDTMAXTIMEOUTVAL >> KERNELTIMERSHIFT)) -1; - -#if 0 /* update thresholds */ - g_Timer.sleep_threshold_us = SLEEP_THRESHOLD_US; - g_Timer.pwrDown_threshold_us = PWRDOWN_THRESHOLD_US; - g_Timer.bgProc_threshold_us = BACKGROUND_THRESHOLD_US; -#endif - /* Initialize WWDT (also enables WWDT clock) */ - Chip_WWDT_Init(LPC_WWDT); - - /* Set watchdog feed time constant (timeout) */ - Chip_WWDT_SetTimeOut(LPC_WWDT, WDTTIMEOUTVAL); - Chip_WWDT_SetWarning(LPC_WWDT, 512); - - /* Clear watchdog timeout interrupt */ - Chip_WWDT_ClearStatusFlag(LPC_WWDT, (WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT)); - - /* Allow WDT to wake from deep sleep */ - Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); - - /* Clear and enable watchdog interrupt */ - NVIC_ClearPendingIRQ(WDT_IRQn); - NVIC_EnableIRQ(WDT_IRQn); - - /* Start watchdog */ - Chip_WWDT_Start(LPC_WWDT); -} -#endif - -/* Returns current WDT count (modified to 32-bit size) based on - calibrated WDT rate (calWdtFreq). */ -static uint32_t wdt_GetCurrent(void) -{ - uint32_t current, lastSecs; - - /* Overflow at 32-bits. Typical overflow is (0xFFFFFFFF/(500K)) - = 8589 seconds (~2-3 hours). */ - - /* Handle WDT count change during read */ - do { - lastSecs = wdtOCount; - /* Counts down, with 6PCLK + 6WDT clock delay */ - current = (lastSecs * (WDTTIMEOUTVAL >> KERNELTIMERSHIFT)) + - ((WDTTIMEOUTVAL >> KERNELTIMERSHIFT) - (Chip_WWDT_GetCurrentCount(LPC_WWDT) >> KERNELTIMERSHIFT)); - } while (wdtOCount != lastSecs); - - return current; -} - -/* Sets the best FLASH clock arte for the passed frequency */ -static void setupFlashClocks(uint32_t freq) -{ - /* v17.0 ROM support only - coarse FLASH clocking timing. - FLASH access is setup based on voltage for v17.1 and later ROMs - as part of the power library. */ - if (Chip_POWER_GetROMVersion() == LPC5410X_ROMVER_0) { - if (freq < 20000000) { - Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_1CYCLE); - } - else if (freq < 48000000) { - Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_2CYCLE); - } - else if (freq < 72000000) { - Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_3CYCLE); - } - else { - Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_4CYCLE); - } - } -} - - - -/***************************************************************************** - * Public functions - ****************************************************************************/ - -/** - * @brief UART interrupt handler - */ -void UART0_IRQHandler(void) -{ - ROM_UART_Handler(hUART); -} - -/** - * @brief watchdog timer Interrupt Handler - * @return Nothing - * @note Handles watchdog timer feed and overflow count - */ -void WDT_IRQHandler(void) -{ - /* A watchdog feed didn't occur prior to warning timeout */ - Chip_WWDT_ClearStatusFlag(LPC_WWDT, (WWDT_WDMOD_WDINT | WWDT_WDMOD_WDTOF)); - - /* Feed WDT or reset will occur */ - Chip_WWDT_Feed(LPC_WWDT); - - /* Will fire every WDT timeout */ - wdtOCount++; - if (wdtOCount > upperOfLimit) { - wdtOCount = 0; - timer40HiByte++; - } -} - - -#define PLL_OUTPUT_CLOCK_RATE (100000000) -static void setupClocking(void) -{ - PLL_CONFIG_T pllConfig; - PLL_SETUP_T pllSetup; - PLL_ERROR_T pllError; - volatile int j; - - - /* Set main clock source to the IRC clock This will drive 24MHz - for the main clock and 24MHz for the system clock */ - Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_IRC); - Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_SYS_PLL); - - /* Make sure the PLL is off */ - Chip_SYSCON_PowerDown(SYSCON_PDRUNCFG_PD_SYS_PLL); - - /* Select the PLL input clock source */ - Chip_Clock_SetSystemPLLSource(PLLCLOCKSOURCE); - - if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { - /* When switching clock sources for the PLL, both the current and new source - must be enabled and requires a small sync time. */ - for (j = 0; j < 0x10000; j++) {} - } - - /* Setup PLL configuration */ - pllConfig.desiredRate = PLL_OUTPUT_CLOCK_RATE; // pll output clock rate in unit of Hz - pllConfig.InputRate = 0;/* Not used unless PLL_CONFIGFLAG_USEINRATE flag is used */ -#if defined(USEPLLPRECISE) - pllConfig.flags = 0; - pllConfig.ss_mf = SS_MF_64; - pllConfig.ss_mr = SS_MR_K3; - pllConfig.ss_mc = SS_MC_RECC; - pllConfig.mfDither = false; -#else - /* Force non-fractional mode */ - pllConfig.flags = PLL_CONFIGFLAG_FORCENOFRACT; -#endif - - pllError = Chip_Clock_SetupPLLData(&pllConfig, &pllSetup); - if (pllError != PLL_ERROR_SUCCESS) { - DEBUGOUT("PLL config error %d\r\n", pllError); - while (1) {} - } - - if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { - /* Disable PLL wait lock flag when using RTC or WDTOSC, since - it will never lock */ - pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_ADGVOLT; - } - else { - /* If using WAITLOCK, powerup is implied, but we set the flag here for - consistency */ -#if defined(USEPLLPRECISE) - /* Don't wait for PLL lock when using SS, it might not lock */ - pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_ADGVOLT; -#else - pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_ADGVOLT; -#endif - } - - pllError = Chip_Clock_SetupSystemPLLPrec(&pllSetup); - if (pllError != PLL_ERROR_SUCCESS) { - DEBUGOUT("PLL setup error %d\r\n", pllError); - while (1) {} - } - - /* Setup FLASH access speed */ - setupFlashClocks(PLL_OUTPUT_CLOCK_RATE); - -#if defined(USEPLLPRECISE) - /* Since PLL lock may not happen when using SS mode, force a small - delay here to let it stabilize. */ - for (j = 0; j < 0x8000; j++) {} -#else - if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { - /* Small delay for PLL lock when using RTC or WDTOSC */ - for (j = 0; j < 0x8000; j++) {} - } -#endif - /* Set system main clock source to the system PLL */ - Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_PLLOUT); - - - /* Set system clock divider to 1. This output of system clock - * divider drives CPU, AHB bus, Sync APB etc... - */ - Chip_Clock_SetSysClockDiv(1); - - /* ASYSNC SYSCON needs to be on or all serial peripheral won't work. - Be careful if PLL is used or not, ASYNC_SYSCON source needs to be - selected carefully. */ - Chip_SYSCON_Enable_ASYNC_Syscon(true); - Chip_Clock_SetAsyncSysconClockDiv(1); - Chip_Clock_SetAsyncSysconClockSource(SYSCON_ASYNC_IRC); - -#if 1 // enable this to pipe system main clock to CLKOUT pin - /* Map P0.21 as CLKOUT pin */ - Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21, - (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); - - /* Setup CLKOUT for main system clock divided by 10 */ - Chip_Clock_SetCLKOUTSource(SYSCON_CLKOUTSRC_MAINCLK, 10); -#endif -} - - -/*---------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N S -\*---------------------------------------------------------------------*/ -uint32_t GetCurrentTime(void) -{ - return 7*wdt_GetCurrent(); -} - -#define SAVE_HARDFAULT -#if defined(SAVE_HARDFAULT) -enum { r0, r1, r2, r3, r12, lr, pc, psr}; -static uint32_t fault_hfsr; -static uint32_t fault_cfsr; -static uint32_t fault_pc; -static uint32_t fault_lr; -static uint32_t fault_r0; -#endif -void HardFault_Handler(uint32_t stack[]) -{ -#if defined(SAVE_HARDFAULT) - fault_hfsr = SCB->HFSR; - fault_cfsr = SCB->CFSR; - fault_pc = stack[pc]; - fault_lr = stack[lr]; - fault_r0 = stack[r0]; -#endif - __ASM volatile("BKPT #01"); - while(1); -} - -/*********************************************************************** - * @fn main - * Main entry point to the application firmware - * - * @param none - * - * @return none - * - ***********************************************************************/ -int main(void) -{ - - uint32_t timer = 0; - - /* Update core clock variables */ - SystemCoreClockUpdate(); - - /* Initialize the pinmux and clocking per board connections */ - Board_Init(); - - // So we know main() is running - D0_printf("%s started\r\n", __FUNCTION__); - - Board_LED_Set(0, false); - Board_LED_Set(1, false); - Board_LED_Set(2, false); - - /* Initialize GPIO pin interrupt module */ - Chip_PININT_Init(LPC_PININT); - - wdt_init(); - - Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN); - - // Use the same setting in the bosch example. Restore to Audience setting later when able to run on the new board - setupClocking(); - - /* Get the OS going - This must be the last call */ - AsfInitialiseTasks(); - - /* If it got here something bad happened */ - ASF_assert_fatal(false); -} - -/*------------------------------------------------------------------*\ - | E N D O F F I L E -\*------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*---------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*---------------------------------------------------------------------*/ +//#include "board.h" +#include "common.h" +#include "hw_setup.h" +#include "sensorhub.h" +#include +#include "romapi_uart.h" +#include "gpio_api.h" +#include "pinmap.h" + +/*---------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*---------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*---------------------------------------------------------------------*/ +#ifdef DEBUG_BUILD +char _errBuff[ERR_LOG_MSG_SZ]; +#endif +uint32_t g_logging = 0x00; + +/*---------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*---------------------------------------------------------------------*/ +/* UART handle and memory for ROM API */ +//static UART_HANDLE_T uartHandle; + +/* Use a buffer size larger than the expected return value of + uart_get_mem_size() for the static UART handle type */ +//static uint32_t uartHandleMEM[0x10]; + +/* UART Driver context memory */ +#define RAMBLOCK_H 60 +static uint32_t uartHandleMem[RAMBLOCK_H]; + +/* UART ROM Driver Handle */ +static UART_HANDLE_T *hUART; + +#define UART_BAUD_RATE 115200 /* Required UART Baud rate */ +#define UART_BUAD_ERR 1/* Percentage of Error allowed in baud */ + +#define tmsg1(x) "Type chars to echo them back\r\n" +#define tmsg(x) tmsg1(x) +#define RX_SZ 16 +#define msg tmsg(RX_SZ) +#define rmsg "UART received : " + +volatile uint32_t tx_done, rx_done; +/*---------------------------------------------------------------------*\ + | P R I V A T E T Y P E D E F I N I T I O N S +\*---------------------------------------------------------------------*/ +/* PLL clock source, must be one of the following: + * SYSCON_PLLCLKSRC_IRC, SYSCON_PLLCLKSRC_CLKIN, + * SYSCON_PLLCLKSRC_WDTOSC, SYSCON_PLLCLKSRC_RTC. + */ +#define PLLCLOCKSOURCE SYSCON_PLLCLKSRC_IRC + +/*---------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*---------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------*\ + | F O R W A R D F U N C T I O N D E C L A R A T I O N S +\*---------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*---------------------------------------------------------------------*/ +#if 0 // comment out since it is not use +static void errorUART(void) +{ + Board_LED_Set(1, true); + while (1) {} +} +#endif + +/* UART Pin mux function - note that SystemInit() may already setup your + pin muxing at system startup */ +static void UART_PinMuxSetup(void) +{ +#if defined(BOARD_NXP_LPCXPRESSO_54102) + /* Setup UART TX Pin */ + //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); + pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_0), (PINMAP_FUNC1 | PINMAP_MODE_INACT | PINMAP_DIGITAL_EN)); + /* Setup UART RX Pin */ + //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 1, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); + pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_1), (PINMAP_FUNC1 | PINMAP_MODE_INACT | PINMAP_DIGITAL_EN)); + Chip_SYSCON_Enable_ASYNC_Syscon(true); /* Enable Async APB */ + Chip_Clock_SetAsyncSysconClockDiv(1); /* Set Async clock divider to 1 */ +#else +#warning "No UART PIN/CLK setup for this example" +#endif +} + +/* Initialize the UART ROM Driver */ +static int __attribute__((unused)) uartrom_init(void) +{ + int sz; + + UART_PinMuxSetup(); + + sz = ROM_UART_GetMemSize(); + + if (RAMBLOCK_H < (sz / 4)) { + while (1) {} + } + + hUART = ROM_UART_Init(uartHandleMem, LPC_USART0_BASE, 0); + + return 0; +} + +#define ABS(x) ((int) (x) < 0 ? -(x) : (x)) +/* Configure UART ROM Driver and pripheral */ +static int __attribute__((unused)) uartrom_config(void) +{ + UART_CFG_T cfg; + UART_BAUD_T baud; + + /* Set up baudrate parameters */ + baud.clk = Chip_Clock_GetAsyncSyscon_ClockRate(); /* Clock frequency */ + baud.baud = UART_BAUD_RATE; /* Required baud rate */ + baud.ovr = 0; /* Set the oversampling to the recommended rate */ + baud.mul = baud.div = 0; + + if (ROM_UART_CalBaud(&baud) != LPC_OK) { + /* Unable to calculate the baud rate parameters */ + while (1) {} + } + + /* Set fractional control register */ + Chip_SYSCON_SetUSARTFRGCtrl(baud.mul, 255); + + /* See if the calculated baud is < +/- UART_BUAD_ERR% of the required baud */ + if (ABS(baud.baud - UART_BAUD_RATE) > (UART_BAUD_RATE * UART_BUAD_ERR) / 100) { + /* WARNING: Baud rate is has more than UART_BUAD_ERR percentage */ + /* Try to auto-detect the Oversampling rate by setting baud.ovr to 0 */ + while (1) {} + } + + /* Configure the UART */ + cfg.cfg = UART_CFG_8BIT | UART_CFG_BRKRX; + cfg.div = baud.div; /* Use the calculated div value */ + cfg.ovr = baud.ovr; /* Use oversampling rate from baud */ + cfg.res = UART_BIT_DLY(UART_BAUD_RATE); + + /* Configure the UART */ + ROM_UART_Configure(hUART, &cfg); + NVIC_ClearPendingIRQ(UART0_IRQn); + NVIC_EnableIRQ(UART0_IRQn); + + return 0; +} + + +/* UART ROM error handler */ +static void uartrom_error(UART_HANDLE_T hUART, uint32_t err) +{ + switch (err) { + case UART_ERROR_FRAME: + /* No stop bit in uart frame; mismatched baud(?) or incorrect/short BREAK condition(?) */ + Board_LED_Set(0, 1); + break; + + case UART_ERROR_PARITY: + /* Parity error; mismatched baud(?) */ + while (1) {} + + case UART_ERROR_AUTOBAUD: + /* Autobaud timeout error */ + while (1) {} + + case UART_ERROR_OVERRUN: + /* Uart received character before ROM_UART_Receive() is called */ + Board_LED_Set(1, 1); + break; + + case UART_ERROR_RXNOISE: + /* Typically problem is with the baud rate and or Over sampling count */ + while (1) {} + + default: + /* Control will never reach this */ + break; + } +} + +/* UART ROM event handler */ +static void uartrom_event(UART_HANDLE_T hUART, uint32_t evt) +{ + switch (evt) { + case UART_EVENT_BREAK: + Board_LED_Set(2, 1); /* TURN ON LED_2 when BREAK is received on RX line */ + break; + + case UART_EVENT_NOBREAK: + Board_LED_Set(2, 0); /* TURN OFF LED_2 when RX comes out of break */ + break; + + case UART_EVENT_TXIDLE: + /* Can be used for flow control */ + /* This will be called when the TX shift register is done with + sending the last bit to uart line; event will be called only + after calling ROM_UART_SetCtrl(hUART, UART_TXIDLE_ON), event + can be turned off using ROM_UART_SetCtrl(hUART, UART_TXIDLE_OFF) + */ + break; + + case UART_EVENT_TXPAUSED: + /* Event will happen after ROM_UART_SetCtrl(hUART, UART_TX_PAUSE) is + called. This event does not mean the the TX is idle, meaning, the + TX holding register might contain data (which is not loaded into + TX shift register anymore) and the the TX shift register is done + sending the data that it was sending when UART_TX_PAUSE was called. + */ + /* Can be used to implement flow control or safely send BREAK signal + without createing frame errors in the currently transmitted data + */ + break; + + case UART_EVENT_CTSHI: + /* CTS line went from Low to High */ + /* Could be used for flow control or RS-485 implementations */ + break; + + case UART_EVENT_CTSLO: + /* CTS line went from High to Low */ + /* Could be used for flow control or RS-485 implementations */ + break; + + default: + while (1) {} /* Control will never reach here */ + } +} + +/* Call-back handler for error/event */ +static void uartrom_xfer_errevt(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) +{ + uint32_t val = (uint32_t) arg; + if (evt == UART_EV_ERROR) { + uartrom_error(hUART, val); + } + else if (evt == UART_EV_EVENT) { + uartrom_event(hUART, val); + } + else { + while (1) {}/* Control will never reach this */ + + } +} + +/* UART Transfer done */ +static void uartrom_xfer_done(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) +{ + UART_DATA_T *dat = (UART_DATA_T *) arg; + + switch (evt) { + case UART_TX_DONE: + tx_done = 1; + break; + + case UART_RX_DONE: + rx_done = dat->count; + break; + + default: + while (1) {} /* Control will never reach here */ + } +} + +/* UART transfer start */ +static void uartrom_xfer_start(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) +{ + UART_DATA_T *dat = (UART_DATA_T *) arg; + + (void) *dat; + switch (evt) { + case UART_TX_START: + /* Transmit of new buffer started */ + break; + + case UART_RX_START: + /* Receive of data started; can be used to implement timer logic */ + break; + + default: + while (1) {} /* Control will never reach here */ + } +} + +static void uartrom_rx_prog(UART_HANDLE_T hUART, UART_EVENT_T evt, void *arg) +{ + UART_DATA_T *dat = (UART_DATA_T *) arg; + + switch (evt) { + case UART_RX_INPROG: + break; + + case UART_RX_NOPROG: + /* In case of frame error restart xfer */ + if (dat->state == UART_ST_ERRFRM) { + dat->offset = 0; + dat->state = UART_ST_BUSY; + } + else { + /* If the received frame has errors don't stop just restart */ + ROM_UART_SetCtrl(hUART, UART_RX_STOP); + } + break; + + default: + break; /* Control should never reach here */ + } +} + +/* Register call-backs */ +static __attribute__((unused)) void uartrom_regcb(void) +{ + ROM_UART_RegisterCB(hUART, UART_CB_START, uartrom_xfer_start); /* Start of transfer */ + ROM_UART_RegisterCB(hUART, UART_CB_DONE, uartrom_xfer_done);/* End of transfer */ + ROM_UART_RegisterCB(hUART, UART_CB_ERREVT, uartrom_xfer_errevt);/* Error/Event callbacks */ + ROM_UART_RegisterCB(hUART, UART_CB_RXPROG, uartrom_rx_prog);/* Receive progress callback */ +} + + + +#if 0 +/* Setup UART handle and parameters */ +static void setupUART() +{ + uint32_t frg_mult; + + /* 4*115.2KBPS, 8N1, ASYNC mode, no errors, clock filled in later */ + UART_CONFIG_T cfg = { + 0, /* U_PCLK frequency in Hz */ + 115200*4, /* Baud Rate in Hz */ + 1, /* 8N1 */ + 0, /* Asynchronous Mode */ + NO_ERR_EN /* Enable No Errors */ + }; + + /* Perform a sanity check on the storage allocation */ + if (LPC_UARTD_API->uart_get_mem_size() > sizeof(uartHandleMEM)) { + /* Example only: this should never happen and probably isn't needed for + most UART code. */ + errorUART(); + } + + /* Setup the UART handle */ + uartHandle = LPC_UARTD_API->uart_setup((uint32_t) LPC_USART0, (uint8_t *) &uartHandleMEM); + if (uartHandle == NULL) { + errorUART(); + } + + /* Need to tell UART ROM API function the current UART peripheral clock + speed */ + cfg.sys_clk_in_hz = Chip_Clock_GetAsyncSysconClockRate(); + + /* Initialize the UART with the configuration parameters */ + frg_mult = LPC_UARTD_API->uart_init(uartHandle, &cfg); + if (frg_mult) { + Chip_Clock_EnableAsyncPeriphClock(ASYNC_SYSCTL_CLOCK_FRG); + Chip_SYSCTL_SetUSARTFRGCtrl(frg_mult, 0xFF); + } +} +#endif + +/* Send a string on the UART terminated by a NULL character using + polling mode. */ +void putLineUART(const char *send_data) +{ +#if 0 + UART_PARAM_T param; + + param.buffer = (uint8_t *) send_data; + param.size = strlen(send_data); + + /* Polling mode, do not append CR/LF to sent data */ + param.transfer_mode = TX_MODE_SZERO; + param.driver_mode = DRIVER_MODE_POLLING; + + /* Transmit the data */ + if (LPC_UARTD_API->uart_put_line(uartHandle, ¶m)) { + while(0) errorUART(); + } +#else + //ROM_UART_Send(hUART, send_data, sizeof(send_data) - 1); + Board_UARTPutSTR((char*)send_data); +#endif +} + +void put_u32(uint32_t v) +{ + int i; + uint32_t m; + uint8_t c; + char str[9]; + m = 0xf0000000; + for (i = 0; i < 8; i++) { + c= ((m&v) >> (28-i*4)); + str[i] = (c > 9) ? (c+'a'):(c+'0'); + } + str[8] = '\0'; + putLineUART(str); +} +static uint32_t volatile wdtOCount; +static uint32_t calWdtFreq, upperOfLimit; +static uint8_t volatile timer40HiByte; + +/* Maximum WDT timeout value */ +#define WDTMAXTIMEOUTVAL 0x00FFFFFF + +/* WDT window size */ +#define WDTWINDOWSIZE 512 + +/* WDT timeout value used for this timer. Must be smaller than + (WDTMAXTIMEOUTVAL + window size) */ +#define WDTTIMEOUTVAL (WDTMAXTIMEOUTVAL - (WDTWINDOWSIZE + 1)) +/* Enable this define to lower the kernel timer resolution by the shift + value. Use 1 for /2, 2 for /4, 3 for /8, etc. This won't affect how the + kernel timer works. Use 0 to disable. Maximum is 8. */ +#define KERNELTIMERSHIFT 0 + +#if 1 +/* Calibrate WDT oscillator as best as possible to IRC rate. Assumes the IRC + is already running, but doesn't need to be the main clock source. */ +static void wdt_calOsc(void) +{ + Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_INPUTMUX); + + /* Setup to measure the selected target using the IRC as the reference */ + Chip_INMUX_SetFreqMeasRefClock(FREQMSR_IRC); + Chip_INMUX_SetFreqMeasTargClock(FREQMSR_WDOSC); + + /* Start a measurement cycle and wait for it to complete. */ + Chip_SYSCON_StartFreqMeas(); + while (!Chip_SYSCON_IsFreqMeasComplete()) {} + + /* Get computed frequency */ + calWdtFreq = Chip_SYSCON_GetCompFreqMeas(Chip_Clock_GetIntOscRate()); + + /* Frequency into WDT as a fixed divider of 4 */ + calWdtFreq = calWdtFreq / 4; +} + +static void wdt_init(void) +{ + /* Enable the power to the WDT Oscillator */ + Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_WDT_OSC); + + /* Get WDT oscilaltor rate using frequency measurement */ + wdt_calOsc(); + + /* Adjust kernel frequency by divider */ + calWdtFreq = calWdtFreq >> KERNELTIMERSHIFT; + + /* Determine overflow limit */ + //upperOfLimit = (0xFFFFFFFF / calWdtFreq) - 1; + upperOfLimit = (0xFFFFFFFF / (WDTMAXTIMEOUTVAL >> KERNELTIMERSHIFT)) -1; + +#if 0 /* update thresholds */ + g_Timer.sleep_threshold_us = SLEEP_THRESHOLD_US; + g_Timer.pwrDown_threshold_us = PWRDOWN_THRESHOLD_US; + g_Timer.bgProc_threshold_us = BACKGROUND_THRESHOLD_US; +#endif + /* Initialize WWDT (also enables WWDT clock) */ + Chip_WWDT_Init(LPC_WWDT); + + /* Set watchdog feed time constant (timeout) */ + Chip_WWDT_SetTimeOut(LPC_WWDT, WDTTIMEOUTVAL); + Chip_WWDT_SetWarning(LPC_WWDT, 512); + + /* Clear watchdog timeout interrupt */ + Chip_WWDT_ClearStatusFlag(LPC_WWDT, (WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT)); + + /* Allow WDT to wake from deep sleep */ + Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); + + /* Clear and enable watchdog interrupt */ + NVIC_ClearPendingIRQ(WDT_IRQn); + NVIC_EnableIRQ(WDT_IRQn); + + /* Start watchdog */ + Chip_WWDT_Start(LPC_WWDT); +} +#endif + +/* Returns current WDT count (modified to 32-bit size) based on + calibrated WDT rate (calWdtFreq). */ +static uint32_t wdt_GetCurrent(void) +{ + uint32_t current, lastSecs; + + /* Overflow at 32-bits. Typical overflow is (0xFFFFFFFF/(500K)) + = 8589 seconds (~2-3 hours). */ + + /* Handle WDT count change during read */ + do { + lastSecs = wdtOCount; + /* Counts down, with 6PCLK + 6WDT clock delay */ + current = (lastSecs * (WDTTIMEOUTVAL >> KERNELTIMERSHIFT)) + + ((WDTTIMEOUTVAL >> KERNELTIMERSHIFT) - (Chip_WWDT_GetCurrentCount(LPC_WWDT) >> KERNELTIMERSHIFT)); + } while (wdtOCount != lastSecs); + + return current; +} + +/* Sets the best FLASH clock arte for the passed frequency */ +static void setupFlashClocks(uint32_t freq) +{ + /* v17.0 ROM support only - coarse FLASH clocking timing. + FLASH access is setup based on voltage for v17.1 and later ROMs + as part of the power library. */ + if (Chip_POWER_GetROMVersion() == LPC5410X_ROMVER_0) { + if (freq < 20000000) { + Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_1CYCLE); + } + else if (freq < 48000000) { + Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_2CYCLE); + } + else if (freq < 72000000) { + Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_3CYCLE); + } + else { + Chip_SYSCON_SetFLASHAccess(SYSCON_FLASH_4CYCLE); + } + } +} + + + +/***************************************************************************** + * Public functions + ****************************************************************************/ + +/** + * @brief UART interrupt handler + */ +void UART0_IRQHandler(void) +{ + ROM_UART_Handler(hUART); +} + +/** + * @brief watchdog timer Interrupt Handler + * @return Nothing + * @note Handles watchdog timer feed and overflow count + */ +void WDT_IRQHandler(void) +{ + /* A watchdog feed didn't occur prior to warning timeout */ + Chip_WWDT_ClearStatusFlag(LPC_WWDT, (WWDT_WDMOD_WDINT | WWDT_WDMOD_WDTOF)); + + /* Feed WDT or reset will occur */ + Chip_WWDT_Feed(LPC_WWDT); + + /* Will fire every WDT timeout */ + wdtOCount++; + if (wdtOCount > upperOfLimit) { + wdtOCount = 0; + timer40HiByte++; + } +} + + +#define PLL_OUTPUT_CLOCK_RATE (100000000) +static void setupClocking(void) +{ + PLL_CONFIG_T pllConfig; + PLL_SETUP_T pllSetup; + PLL_ERROR_T pllError; + volatile int j; + + + /* Set main clock source to the IRC clock This will drive 24MHz + for the main clock and 24MHz for the system clock */ + Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_IRC); + Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_SYS_PLL); + + /* Make sure the PLL is off */ + Chip_SYSCON_PowerDown(SYSCON_PDRUNCFG_PD_SYS_PLL); + + /* Select the PLL input clock source */ + Chip_Clock_SetSystemPLLSource(PLLCLOCKSOURCE); + + if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { + /* When switching clock sources for the PLL, both the current and new source + must be enabled and requires a small sync time. */ + for (j = 0; j < 0x10000; j++) {} + } + + /* Setup PLL configuration */ + pllConfig.desiredRate = PLL_OUTPUT_CLOCK_RATE; // pll output clock rate in unit of Hz + pllConfig.InputRate = 0;/* Not used unless PLL_CONFIGFLAG_USEINRATE flag is used */ +#if defined(USEPLLPRECISE) + pllConfig.flags = 0; + pllConfig.ss_mf = SS_MF_64; + pllConfig.ss_mr = SS_MR_K3; + pllConfig.ss_mc = SS_MC_RECC; + pllConfig.mfDither = false; +#else + /* Force non-fractional mode */ + pllConfig.flags = PLL_CONFIGFLAG_FORCENOFRACT; +#endif + + pllError = Chip_Clock_SetupPLLData(&pllConfig, &pllSetup); + if (pllError != PLL_ERROR_SUCCESS) { + DEBUGOUT("PLL config error %d\r\n", pllError); + while (1) {} + } + + if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { + /* Disable PLL wait lock flag when using RTC or WDTOSC, since + it will never lock */ + pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_ADGVOLT; + } + else { + /* If using WAITLOCK, powerup is implied, but we set the flag here for + consistency */ +#if defined(USEPLLPRECISE) + /* Don't wait for PLL lock when using SS, it might not lock */ + pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_ADGVOLT; +#else + pllSetup.flags = PLL_SETUPFLAG_POWERUP | PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_ADGVOLT; +#endif + } + + pllError = Chip_Clock_SetupSystemPLLPrec(&pllSetup); + if (pllError != PLL_ERROR_SUCCESS) { + DEBUGOUT("PLL setup error %d\r\n", pllError); + while (1) {} + } + + /* Setup FLASH access speed */ + setupFlashClocks(PLL_OUTPUT_CLOCK_RATE); + +#if defined(USEPLLPRECISE) + /* Since PLL lock may not happen when using SS mode, force a small + delay here to let it stabilize. */ + for (j = 0; j < 0x8000; j++) {} +#else + if ((PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_RTC) || (PLLCLOCKSOURCE == SYSCON_PLLCLKSRC_WDTOSC)) { + /* Small delay for PLL lock when using RTC or WDTOSC */ + for (j = 0; j < 0x8000; j++) {} + } +#endif + /* Set system main clock source to the system PLL */ + Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_PLLOUT); + + + /* Set system clock divider to 1. This output of system clock + * divider drives CPU, AHB bus, Sync APB etc... + */ + Chip_Clock_SetSysClockDiv(1); + + /* ASYSNC SYSCON needs to be on or all serial peripheral won't work. + Be careful if PLL is used or not, ASYNC_SYSCON source needs to be + selected carefully. */ + Chip_SYSCON_Enable_ASYNC_Syscon(true); + Chip_Clock_SetAsyncSysconClockDiv(1); + Chip_Clock_SetAsyncSysconClockSource(SYSCON_ASYNC_IRC); + +#if 1 // enable this to pipe system main clock to CLKOUT pin + /* Map P0.21 as CLKOUT pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21, + (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)); + + /* Setup CLKOUT for main system clock divided by 10 */ + Chip_Clock_SetCLKOUTSource(SYSCON_CLKOUTSRC_MAINCLK, 10); +#endif +} + + +/*---------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N S +\*---------------------------------------------------------------------*/ +uint32_t GetCurrentTime(void) +{ + return 7*wdt_GetCurrent(); +} + +#define SAVE_HARDFAULT +#if defined(SAVE_HARDFAULT) +enum { r0, r1, r2, r3, r12, lr, pc, psr}; +static uint32_t fault_hfsr __attribute__((unused)); +static uint32_t fault_cfsr __attribute__((unused)); +static uint32_t fault_pc __attribute__((unused)); +static uint32_t fault_lr __attribute__((unused)); +static uint32_t fault_r0 __attribute__((unused)); +#endif +void HardFault_Handler(uint32_t stack[]) +{ +#if defined(SAVE_HARDFAULT) + fault_hfsr = SCB->HFSR; + fault_cfsr = SCB->CFSR; + fault_pc = stack[pc]; + fault_lr = stack[lr]; + fault_r0 = stack[r0]; +#endif + __ASM volatile("BKPT #01"); + while(1); +} + +/*********************************************************************** + * @fn main + * Main entry point to the application firmware + * + * @param none + * + * @return none + * + ***********************************************************************/ +int main(void) +{ + + /* Update core clock variables */ + SystemCoreClockUpdate(); + + /* Initialize the pinmux and clocking per board connections */ + Board_Init(); + + // So we know main() is running + D0_printf("%s started\r\n", __FUNCTION__); + + Board_LED_Set(0, false); + Board_LED_Set(1, false); + Board_LED_Set(2, false); + + /* Initialize GPIO pin interrupt module */ + //Chip_PININT_Init(LPC_PININT); + gpio_init((gpio_t *)NULL,(PinName)NULL); + + wdt_init(); + + //Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN); + { + gpio_t hostifIrq; + hostifIrq.pin = ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN); + gpio_dir(&hostifIrq,PIN_OUTPUT); + } + + // Use the same setting in the bosch example. Restore to Audience setting later when able to run on the new board + setupClocking(); + + /* Get the OS going - This must be the last call */ + AsfInitialiseTasks(); + + /* If it got here something bad happened */ + ASF_assert_fatal(false); +} + +#ifdef __MICROLIB +/*********************************************************************** + * @fn exit + * Main Exit point from the application firmware + * This function is required if microlib is used + * + * @param Error code + * + * @return none + * + ***********************************************************************/ +void exit(uint32_t error) +{ + __ASM volatile("BKPT #01"); + while(1); +} +#endif + +/*------------------------------------------------------------------*\ + | E N D O F F I L E +\*------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/sources/app/main.h b/embedded/projects/osp-lpc54102/sources/app/main.h index 969953f..3d71439 100644 --- a/embedded/projects/osp-lpc54102/sources/app/main.h +++ b/embedded/projects/osp-lpc54102/sources/app/main.h @@ -1,161 +1,162 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2013 Sensor Platforms Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if !defined (MAIN_H) -#define MAIN_H - -#define I2C_DRIVER /* Include I2C Driver */ -#define INTERRUPT_BASED_SAMPLING /* Sensor sampling is interrupt driver */ -#undef TRIGGERED_MAG_SAMPLING /* Magnetometer sampling is software triggered */ - -/*-------------------------------------------------------------------------------------------------*\ - | I N C L U D E F I L E S -\*-------------------------------------------------------------------------------------------------*/ -#include "appversion.h" -#include - -/*-------------------------------------------------------------------------------------------------*\ - | C O N S T A N T S & M A C R O S -\*-------------------------------------------------------------------------------------------------*/ -#ifdef ANDROID_DEMO -# define ANDROID_COMM_TASK I2CSLAVE_COMM_TASK_ID -#endif -#define ALGORITHM_TASK ALGORITHM_TASK_ID - -#ifdef DEBUG_BUILD -# ifndef DEBUG_OUTPUT -# define DEBUG_OUTPUT -# endif -#endif - -//#define RESET_ON_ASSERT - -#ifdef RESET_ON_ASSERT -# define SysRESET() NVIC_SystemReset() -#else -# define SysRESET() while(1) -#endif - - -#if 0 -#define MAX_SYSTEM_MESSAGES 1200 ///< Max number of queued messages in the system -#else -#define MAX_SYSTEM_MESSAGES 600 // QLY change from 600 to 300 ///< Max number of queued messages in the system -#endif -/* All timer references (arbitrary unique identifiers for each timer)*/ -#define TIMER_REF_RTC_UPDATE 0x55A5 -#define TIMER_REF_SENSOR_READ 0x55B0 -#define TIMER_REF_PRESSURE_READ 0x55ca - -/* Printf and assert support for debugging */ -#ifdef DEBUG_OUTPUT -# define DEBUG_LVL 1 -#else -# ifndef DEBUG_LVL -# define DEBUG_LVL 0 -# endif -#endif - -#if (DEBUG_LVL > 0) -# ifdef UART_DMA_ENABLE -# define MAX_DPRINTF_MESSAGES 30 ///< Max printf messages allowed at a given time -# else -# define TX_BUFFER_SIZE 512 -# endif -# define RX_BUFFER_SIZE 32 -# define DPRINTF_BUFF_SIZE 200 - -#else //DEBUG_LVL = 0 - -# ifndef UART_DMA_ENABLE -# define TX_BUFFER_SIZE 512 -# endif -# define RX_BUFFER_SIZE 200 -# define MAX_DPRINTF_MESSAGES 10 ///< Max printf messages allowed at a given time -# define DPRINTF_BUFF_SIZE 100 - -#endif - -/* Defines for command handler */ -#define COMMAND_LINE_SIZE 32 - -/* Sensor acquisition related definitions */ - -#if !defined INTERRUPT_BASED_SAMPLING -# define SENSOR_SAMPLE_PERIOD MSEC_TO_TICS(20) //tick -# define MAG_DECIMATE_FACTOR 1 -# define ACCEL_SAMPLE_DECIMATE 1 -# define GYRO_SAMPLE_DECIMATE 1 -#else -# define MAG_DECIMATE_FACTOR 1 -# define ACCEL_SAMPLE_DECIMATE 1 -# define GYRO_SAMPLE_DECIMATE 1 -#endif - -#define PRESSURE_SAMPLE_PERIOD MSEC_TO_TICS(40) - -#ifdef TRIGGERED_MAG_SAMPLING -# define MAG_TRIGGER_RATE_DECIMATE 1 //1/2 of Accel ODR -#endif - -/*-------------------------------------------------------------------------------------------------*\ - | T Y P E D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Serial command parser tokens */ -enum ParserTokensTag { - TOKEN_NULL = 0, - TOKEN_1 = 'l', - TOKEN_2 = 'o', - TOKEN_3 = 'g', - TOKEN_4 = '=', - TOKEN_STATS = '\r', - TOKEN_PARAM = 0xAA -}; - -/* RTC clock */ -typedef struct RtcClockTag -{ - uint16_t hours; - uint8_t minutes; - uint8_t seconds; - uint16_t msec; -} RtcClock_t; - -typedef MsgAccelData AccelData_t; - -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -//extern RCC_ClocksTypeDef gRccClockInfo; -//extern uint32_t g_logging; - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------------------------------------*\ - | P U B L I C F U N C T I O N D E C L A R A T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Updates RTC counter based on system tick counter */ -void UpdateRTC( void ); -int Print_LIPS( const char *fmt, ... ); //Serial protocol for data results out - - -#endif /* MAIN_H */ -/*-------------------------------------------------------------------------------------------------*\ - | E N D O F F I L E -\*-------------------------------------------------------------------------------------------------*/ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2013 Sensor Platforms Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if !defined (MAIN_H) +#define MAIN_H + +#define I2C_DRIVER /* Include I2C Driver */ +#define INTERRUPT_BASED_SAMPLING /* Sensor sampling is interrupt driver */ +#undef TRIGGERED_MAG_SAMPLING /* Magnetometer sampling is software triggered */ + +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ +#include "appversion.h" +#include + +/*-------------------------------------------------------------------------------------------------*\ + | C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#ifdef ANDROID_DEMO +# define ANDROID_COMM_TASK I2CSLAVE_COMM_TASK_ID +#endif +#define ALGORITHM_TASK ALGORITHM_TASK_ID + +#ifdef DEBUG_BUILD +# ifndef DEBUG_OUTPUT +# define DEBUG_OUTPUT +# endif +#endif + +//#define RESET_ON_ASSERT + +#ifdef RESET_ON_ASSERT +# define SysRESET() NVIC_SystemReset() +#else +# define SysRESET() while(1) +#endif + + +#if 0 +#define MAX_SYSTEM_MESSAGES 1200 ///< Max number of queued messages in the system +#else +/* PG: Reduced the number of queued messages to 200 to prevent memory wastage. */ +#define MAX_SYSTEM_MESSAGES 200 // QLY change from 600 to 300 ///< Max number of queued messages in the system +#endif +/* All timer references (arbitrary unique identifiers for each timer)*/ +#define TIMER_REF_RTC_UPDATE 0x55A5 +#define TIMER_REF_SENSOR_READ 0x55B0 +#define TIMER_REF_PRESSURE_READ 0x55ca + +/* Printf and assert support for debugging */ +#ifdef DEBUG_OUTPUT +# define DEBUG_LVL 1 +#else +# ifndef DEBUG_LVL +# define DEBUG_LVL 0 +# endif +#endif + +#if (DEBUG_LVL > 0) +# ifdef UART_DMA_ENABLE +# define MAX_DPRINTF_MESSAGES 30 ///< Max printf messages allowed at a given time +# else +# define TX_BUFFER_SIZE 512 +# endif +# define RX_BUFFER_SIZE 32 +# define DPRINTF_BUFF_SIZE 200 + +#else //DEBUG_LVL = 0 + +# ifndef UART_DMA_ENABLE +# define TX_BUFFER_SIZE 512 +# endif +# define RX_BUFFER_SIZE 200 +# define MAX_DPRINTF_MESSAGES 10 ///< Max printf messages allowed at a given time +# define DPRINTF_BUFF_SIZE 100 + +#endif + +/* Defines for command handler */ +#define COMMAND_LINE_SIZE 32 + +/* Sensor acquisition related definitions */ + +#if !defined INTERRUPT_BASED_SAMPLING +# define SENSOR_SAMPLE_PERIOD (20) //time in ms +# define MAG_DECIMATE_FACTOR 1 +# define ACCEL_SAMPLE_DECIMATE 1 +# define GYRO_SAMPLE_DECIMATE 1 +#else +# define MAG_DECIMATE_FACTOR 1 +# define ACCEL_SAMPLE_DECIMATE 1 +# define GYRO_SAMPLE_DECIMATE 1 +#endif + +#define PRESSURE_SAMPLE_PERIOD (40) + +#ifdef TRIGGERED_MAG_SAMPLING +# define MAG_TRIGGER_RATE_DECIMATE 1 //1/2 of Accel ODR +#endif + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Serial command parser tokens */ +enum ParserTokensTag { + TOKEN_NULL = 0, + TOKEN_1 = 'l', + TOKEN_2 = 'o', + TOKEN_3 = 'g', + TOKEN_4 = '=', + TOKEN_STATS = '\r', + TOKEN_PARAM = 0xAA +}; + +/* RTC clock */ +typedef struct RtcClockTag +{ + uint16_t hours; + uint8_t minutes; + uint8_t seconds; + uint16_t msec; +} RtcClock_t; + +typedef MsgAccelData AccelData_t; + +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +//extern RCC_ClocksTypeDef gRccClockInfo; +//extern uint32_t g_logging; + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------------------------------*\ + | P U B L I C F U N C T I O N D E C L A R A T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Updates RTC counter based on system tick counter */ +void UpdateRTC( void ); +int Print_LIPS( const char *fmt, ... ); //Serial protocol for data results out + + +#endif /* MAIN_H */ +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.c b/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.c index 8d27f05..a5bfbde 100644 --- a/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.c +++ b/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.c @@ -1,349 +1,349 @@ -/* - * @brief I2CM driver used by Sensor acquisition task - * - * @note - * Copyright(C) NXP Semiconductors, 2014 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#include "board.h" -#include -#include "sensorhub.h" -#include "sensacq_i2c.h" -#include "common.h" - -/***************************************************************************** - * Private types/enumerations/variables - ****************************************************************************/ - -/* ROM driver handle for I2C master */ -static ROM_I2CM_HANDLE_T i2cmHandle; - -/* I2CM transfer record */ -static ROM_I2CM_XFER_T i2cmXferRec; -static uint8_t g_i2cmTxBuf[CFG_MAX_SA_TX_BUFFER]; - - -#if defined(I2CM_DMA_BASED) -/* DMA descriptors must be aligned to 16 bytes */ -#if defined(__CC_ARM) -__align(16) static DMA_CHDESC_T dmaI2CMDesc; -#endif /* defined (__CC_ARM) */ - -/* IAR support */ -#if defined(__ICCARM__) -#pragma data_alignment=16 -static DMA_CHDESC_T dmaI2CMDesc; -#endif /* defined (__ICCARM__) */ - -#if defined( __GNUC__ ) -static DMA_CHDESC_T dmaI2CMDesc __attribute__ ((aligned(16))); -#endif /* defined (__GNUC__) */ -#endif /* defined(I2CM_DMA_BASED) */ - -/***************************************************************************** - * Public types/enumerations/variables - ****************************************************************************/ -extern uint8_t timeStampExtender; - -/***************************************************************************** - * Private functions - ****************************************************************************/ - -/* Setup I2C */ -static void setupI2CMaster(void) -{ - ROM_I2CM_INIT_T i2cmInit; - static uint32_t i2cmContextData[16]; - - /* Enable I2C clock and reset I2C peripheral */ - Chip_Clock_EnablePeriphClock(I2C_SENSOR_CLOCK); - Chip_SYSCON_PeriphReset(I2C_SENSOR_RESET); - - - //Chip_I2C_Init(I2C_SENSOR_BUS); - /* Initialize driver */ - i2cmInit.pUserData = NULL; - i2cmInit.base = (uint32_t) I2C_SENSOR_BUS; - i2cmHandle = ROM_I2CM_Init(i2cmContextData, &i2cmInit); - if (i2cmHandle == NULL) { - /* Error initializing I2C */ - /* FIXME implement some sort of error indicator */ - } - - /* Setup I2CM transfer rate */ - //Chip_I2CM_SetBusSpeed(I2C_SENSOR_BUS, I2C_MCLOCK_SPEED); - ROM_I2CM_SetClockRate(i2cmHandle, - Chip_Clock_GetAsyncSyscon_ClockRate(), I2C_MCLOCK_SPEED); - - - /* Enable I2C master interface */ - // Chip_I2CM_Enable(I2C_SENSOR_BUS); - -#if defined(I2CM_DMA_BASED) - /* Setup I2C0 slave channel for the following configuration: - - Peripheral DMA request - - Single transfer - - High channel priority */ - Chip_DMA_EnableChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); - Chip_DMA_EnableIntChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); - Chip_DMA_SetupChannelConfig(LPC_DMA, I2C_SENSOR_BUS_DMAID, - (DMA_CFG_PERIPHREQEN | DMA_CFG_TRIGBURST_SNGL | DMA_CFG_CHPRIORITY(0))); -#endif -} - -#ifdef I2CM_IRQ_BASED -/* Function to wait for I2CM transfer completion */ -static void WaitForI2cXferComplete(I2CM_XFER_T *xferRecPtr) -{ - /* Are we still transferring data ? */ - while (xferRecPtr->status == I2CM_STATUS_BUSY) { - /* Sleep until next interrupt */ - __WFI(); - } -} -#endif - -#if defined(I2CM_DMA_BASED) -/* Setup and start a DMA transfer */ -static setupI2CDMAXfer(void *buff, uint8_t bytes, bool tx) -{ - /* Enable DMA for I2C controller */ - I2C_SENSOR_BUS->MSTCTL = I2C_MSTCTL_MSTDMA; - - /* Master to slave */ - if (tx) { - dmaI2CMDesc.source = DMA_ADDR(buff) + bytes - 1; - dmaI2CMDesc.dest = DMA_ADDR(&I2C_SENSOR_BUS->MSTDAT); - dmaI2CMDesc.next = DMA_ADDR(0); - dmaI2CMDesc.xfercfg = DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | - DMA_XFERCFG_SWTRIG | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_1 | - DMA_XFERCFG_DSTINC_0 | DMA_XFERCFG_XFERCOUNT(bytes); - } - else { - dmaI2CMDesc.source = DMA_ADDR(&I2C_SENSOR_BUS->MSTDAT); - dmaI2CMDesc.dest = DMA_ADDR(buff) + bytes - 1; - dmaI2CMDesc.next = DMA_ADDR(0); - dmaI2CMDesc.xfercfg = DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | - DMA_XFERCFG_SWTRIG | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_0 | - DMA_XFERCFG_DSTINC_1 | DMA_XFERCFG_XFERCOUNT(bytes); - } - - /* Setup transfer descriptor and validate it */ - Chip_DMA_SetupTranChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID, &dmaI2CMDesc); - - /* Setup data transfer */ - Chip_DMA_SetupChannelTransfer(LPC_DMA, I2C_SENSOR_BUS_DMAID, dmaI2CMDesc.xfercfg); - - Chip_DMA_SetValidChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); -} -#endif - -/***************************************************************************** - * Public functions - ****************************************************************************/ - -/* DMA error handler and notification for I2C */ -void dev_i2cm_dma_callback(bool error) -{ - /* ##KW## What do we do here for errors? */ - if (error) { - /* Nothing to do here. I2C will terminate the trasnfer. */ - ; - } - - I2C_SENSOR_BUS->MSTCTL = 0; -} - -/** - * @brief Handle I2C1 interrupt by calling I2CM interrupt transfer handler - * @return Nothing - */ -void I2C_SENSOR_BUS_IRQHandler(void) -{ -#if 1 // Use ROM API handler - /* Call I2CM transfer handler function */ - ROM_I2CM_TransferHandler(i2cmHandle); -#else // this is the old nxp board -#if defined(I2CM_DMA_BASED) - uint32_t cState; -#endif - uint32_t state = Chip_I2C_GetPendingInt(I2C_SENSOR_BUS); - - /* Error handling */ - if (state & (I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR)) { - Chip_I2CM_ClearStatus(I2C_SENSOR_BUS, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR); - } - - if (state & I2C_INTENSET_MSTPENDING) { -#if defined(I2CM_DMA_BASED) - /* DMA may still be active, but the transfer might of completed due to - a NAK or error. Handle the error here before queueing up the DMA - transfer. */ - cState = Chip_I2CM_GetMasterState(I2C_SENSOR_BUS); - if (cState == I2C_STAT_MSTCODE_RXREADY) { - if (i2cmXferRec.rxSz > I2C_SENSOR_BUS_DMABYTELIM) { - /* Master receive */ - setupI2CDMAXfer((void *) i2cmXferRec.rxBuff, i2cmXferRec.rxSz, false); - i2cmXferRec.rxSz = 0; - } else { - Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); - } - } - else if (cState == I2C_STAT_MSTCODE_TXREADY) { - if (i2cmXferRec.txSz > I2C_SENSOR_BUS_DMABYTELIM) { - /* Master transmit */ - setupI2CDMAXfer((void *) i2cmXferRec.txBuff, i2cmXferRec.txSz, true); - i2cmXferRec.txSz = 0; - } else { - /* Transistion to read state */ - Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); - } - } else { - /* Not in a transfer state, so handle using the normal I2C handler */ - Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); - } -#else - Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); -#endif - } - - /* If transfer is no longer in progress, disable interrupts */ - if (i2cmXferRec.status != ERR_I2C_BUSY) { - Chip_I2C_DisableInt(I2C_SENSOR_BUS, I2C_INTENSET_MSTPENDING | - I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR); - } -#endif -} - -/** - * @brief Initialize I2C bus connected sensors - * @return True if initalized - */ -osp_bool_t dev_i2c_init(void) -{ - static bool init = false; - - if (init == false) { - /* Setup I2C and master */ - setupI2CMaster(); - -#ifdef I2CM_IRQ_BASED - NVIC_SetPriority(I2C_SENSOR_BUS_IRQn, SENSOR_I2C_PRIORITY); - /* Enable the interrupt for the I2C */ - NVIC_EnableIRQ(I2C_SENSOR_BUS_IRQn); -#endif - init = true; - } - return init; -} - -/** - * @brief adaptation of the Bosch API functions to the - * BOARD specific function - * @return Nothing - */ -void dev_i2c_delay(unsigned int msec) -{ - /* Will WFI for the entire sleep duration. If an interrupt - occurs that wakes the device, the sleep handler will - automatically re-enter WFI until the duration has expired. */ - os_dly_wait(MSEC_TO_TICS(msec)); /* Allow startup time for sensors */ -} - -/** - * @brief adaptation of the Bosch API functions to the BOARD specific function - * @return Nothing - */ -char dev_i2c_write(unsigned char dev_addr, unsigned char reg_addr, - unsigned char *reg_data, unsigned char cnt) -{ - /* Setup I2C transfer record */ - g_i2cmTxBuf[0] = reg_addr; - if (cnt == 1) { - g_i2cmTxBuf[1] = reg_data[0]; - } - else if ((cnt > 0) && (cnt < CFG_MAX_SA_TX_BUFFER)) { - memcpy(&g_i2cmTxBuf[1], reg_data, cnt); - } - - memset(&i2cmXferRec, 0, sizeof(i2cmXferRec)); - - i2cmXferRec.slaveAddr = dev_addr; - i2cmXferRec.status = LPC_OK; - i2cmXferRec.txSz = cnt + 1; - i2cmXferRec.rxSz = 0; - i2cmXferRec.txBuff = &g_i2cmTxBuf[0]; - i2cmXferRec.rxBuff = 0; - -#ifdef I2CM_IRQ_BASED - /* Start transfer and wait for completion */ - ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); - /* Wait for transfer completion */ - WaitForI2cXferComplete(&i2cmXferRec); -#else - /* I2C master driver will block if blocking flag is used */ - i2cmXferRec.flags = ROM_I2CM_FLAG_BLOCKING; - - /* Start transfer and wait for completion */ - ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); - -#endif - return LPC_OK; -} - -/** - * @brief adaptation of the Bosch API functions to the - * BOARD specific function - * @return Nothing - */ -char dev_i2c_read(unsigned char dev_addr, unsigned char reg_addr, - unsigned char *reg_data, unsigned char cnt) -{ - memset(&i2cmXferRec, 0, sizeof(i2cmXferRec)); - /* Setup I2C transfer record */ - i2cmXferRec.slaveAddr = dev_addr; - i2cmXferRec.status = LPC_OK; - i2cmXferRec.txSz = 1; - i2cmXferRec.rxSz = cnt; - i2cmXferRec.txBuff = ®_addr; - i2cmXferRec.rxBuff = reg_data; - -#ifdef I2CM_IRQ_BASED - /* Start transfer and wait for completion */ - ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); - /* Wait for transfer completion */ - WaitForI2cXferComplete(&i2cmXferRec); -#else - /* I2C master driver will block if blocking flag is used */ - i2cmXferRec.flags = ROM_I2CM_FLAG_BLOCKING; - - /* Start transfer and wait for completion */ - ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); -#endif - - return LPC_OK; -} +/* + * @brief I2CM driver used by Sensor acquisition task + * + * @note + * Copyright(C) NXP Semiconductors, 2014 + * All rights reserved. + * + * @par + * Software that is described herein is for illustrative purposes only + * which provides customers with programming information regarding the + * LPC products. This software is supplied "AS IS" without any warranties of + * any kind, and NXP Semiconductors and its licensor disclaim any and + * all warranties, express or implied, including all implied warranties of + * merchantability, fitness for a particular purpose and non-infringement of + * intellectual property rights. NXP Semiconductors assumes no responsibility + * or liability for the use of the software, conveys no license or rights under any + * patent, copyright, mask work right, or any other intellectual property rights in + * or to any products. NXP Semiconductors reserves the right to make changes + * in the software without notification. NXP Semiconductors also makes no + * representation or warranty that such application will be suitable for the + * specified use without further testing or modification. + * + * @par + * Permission to use, copy, modify, and distribute this software and its + * documentation is hereby granted, under NXP Semiconductors' and its + * licensor's relevant copyrights in the software, without fee, provided that it + * is used in conjunction with NXP Semiconductors microcontrollers. This + * copyright, permission, and disclaimer notice must appear in all copies of + * this code. + */ + +#include "board.h" +#include +#include "sensorhub.h" +#include "sensacq_i2c.h" +#include "common.h" + +/***************************************************************************** + * Private types/enumerations/variables + ****************************************************************************/ + +/* ROM driver handle for I2C master */ +static ROM_I2CM_HANDLE_T i2cmHandle; + +/* I2CM transfer record */ +static ROM_I2CM_XFER_T i2cmXferRec; +static uint8_t g_i2cmTxBuf[CFG_MAX_SA_TX_BUFFER]; + + +#if defined(I2CM_DMA_BASED) +/* DMA descriptors must be aligned to 16 bytes */ +#if defined(__CC_ARM) +__align(16) static DMA_CHDESC_T dmaI2CMDesc; +#endif /* defined (__CC_ARM) */ + +/* IAR support */ +#if defined(__ICCARM__) +#pragma data_alignment=16 +static DMA_CHDESC_T dmaI2CMDesc; +#endif /* defined (__ICCARM__) */ + +#if defined( __GNUC__ ) +static DMA_CHDESC_T dmaI2CMDesc __attribute__ ((aligned(16))); +#endif /* defined (__GNUC__) */ +#endif /* defined(I2CM_DMA_BASED) */ + +/***************************************************************************** + * Public types/enumerations/variables + ****************************************************************************/ +extern uint8_t timeStampExtender; + +/***************************************************************************** + * Private functions + ****************************************************************************/ + +/* Setup I2C */ +static void setupI2CMaster(void) +{ + ROM_I2CM_INIT_T i2cmInit; + static uint32_t i2cmContextData[16]; + + /* Enable I2C clock and reset I2C peripheral */ + Chip_Clock_EnablePeriphClock(I2C_SENSOR_CLOCK); + Chip_SYSCON_PeriphReset(I2C_SENSOR_RESET); + + + //Chip_I2C_Init(I2C_SENSOR_BUS); + /* Initialize driver */ + i2cmInit.pUserData = NULL; + i2cmInit.base = (uint32_t) I2C_SENSOR_BUS; + i2cmHandle = ROM_I2CM_Init(i2cmContextData, &i2cmInit); + if (i2cmHandle == NULL) { + /* Error initializing I2C */ + /* FIXME implement some sort of error indicator */ + } + + /* Setup I2CM transfer rate */ + //Chip_I2CM_SetBusSpeed(I2C_SENSOR_BUS, I2C_MCLOCK_SPEED); + ROM_I2CM_SetClockRate(i2cmHandle, + Chip_Clock_GetAsyncSyscon_ClockRate(), I2C_MCLOCK_SPEED); + + + /* Enable I2C master interface */ + // Chip_I2CM_Enable(I2C_SENSOR_BUS); + +#if defined(I2CM_DMA_BASED) + /* Setup I2C0 slave channel for the following configuration: + - Peripheral DMA request + - Single transfer + - High channel priority */ + Chip_DMA_EnableChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); + Chip_DMA_EnableIntChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); + Chip_DMA_SetupChannelConfig(LPC_DMA, I2C_SENSOR_BUS_DMAID, + (DMA_CFG_PERIPHREQEN | DMA_CFG_TRIGBURST_SNGL | DMA_CFG_CHPRIORITY(0))); +#endif +} + +#ifdef I2CM_IRQ_BASED +/* Function to wait for I2CM transfer completion */ +static void WaitForI2cXferComplete(I2CM_XFER_T *xferRecPtr) +{ + /* Are we still transferring data ? */ + while (xferRecPtr->status == I2CM_STATUS_BUSY) { + /* Sleep until next interrupt */ + __WFI(); + } +} +#endif + +#if defined(I2CM_DMA_BASED) +/* Setup and start a DMA transfer */ +static setupI2CDMAXfer(void *buff, uint8_t bytes, bool tx) +{ + /* Enable DMA for I2C controller */ + I2C_SENSOR_BUS->MSTCTL = I2C_MSTCTL_MSTDMA; + + /* Master to slave */ + if (tx) { + dmaI2CMDesc.source = DMA_ADDR(buff) + bytes - 1; + dmaI2CMDesc.dest = DMA_ADDR(&I2C_SENSOR_BUS->MSTDAT); + dmaI2CMDesc.next = DMA_ADDR(0); + dmaI2CMDesc.xfercfg = DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | + DMA_XFERCFG_SWTRIG | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_1 | + DMA_XFERCFG_DSTINC_0 | DMA_XFERCFG_XFERCOUNT(bytes); + } + else { + dmaI2CMDesc.source = DMA_ADDR(&I2C_SENSOR_BUS->MSTDAT); + dmaI2CMDesc.dest = DMA_ADDR(buff) + bytes - 1; + dmaI2CMDesc.next = DMA_ADDR(0); + dmaI2CMDesc.xfercfg = DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | + DMA_XFERCFG_SWTRIG | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_0 | + DMA_XFERCFG_DSTINC_1 | DMA_XFERCFG_XFERCOUNT(bytes); + } + + /* Setup transfer descriptor and validate it */ + Chip_DMA_SetupTranChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID, &dmaI2CMDesc); + + /* Setup data transfer */ + Chip_DMA_SetupChannelTransfer(LPC_DMA, I2C_SENSOR_BUS_DMAID, dmaI2CMDesc.xfercfg); + + Chip_DMA_SetValidChannel(LPC_DMA, I2C_SENSOR_BUS_DMAID); +} +#endif + +/***************************************************************************** + * Public functions + ****************************************************************************/ + +/* DMA error handler and notification for I2C */ +void dev_i2cm_dma_callback(bool error) +{ + /* ##KW## What do we do here for errors? */ + if (error) { + /* Nothing to do here. I2C will terminate the trasnfer. */ + ; + } + + I2C_SENSOR_BUS->MSTCTL = 0; +} + +/** + * @brief Handle I2C1 interrupt by calling I2CM interrupt transfer handler + * @return Nothing + */ +void I2C_SENSOR_BUS_IRQHandler(void) +{ +#if 1 // Use ROM API handler + /* Call I2CM transfer handler function */ + ROM_I2CM_TransferHandler(i2cmHandle); +#else // this is the old nxp board +#if defined(I2CM_DMA_BASED) + uint32_t cState; +#endif + uint32_t state = Chip_I2C_GetPendingInt(I2C_SENSOR_BUS); + + /* Error handling */ + if (state & (I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR)) { + Chip_I2CM_ClearStatus(I2C_SENSOR_BUS, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR); + } + + if (state & I2C_INTENSET_MSTPENDING) { +#if defined(I2CM_DMA_BASED) + /* DMA may still be active, but the transfer might of completed due to + a NAK or error. Handle the error here before queueing up the DMA + transfer. */ + cState = Chip_I2CM_GetMasterState(I2C_SENSOR_BUS); + if (cState == I2C_STAT_MSTCODE_RXREADY) { + if (i2cmXferRec.rxSz > I2C_SENSOR_BUS_DMABYTELIM) { + /* Master receive */ + setupI2CDMAXfer((void *) i2cmXferRec.rxBuff, i2cmXferRec.rxSz, false); + i2cmXferRec.rxSz = 0; + } else { + Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); + } + } + else if (cState == I2C_STAT_MSTCODE_TXREADY) { + if (i2cmXferRec.txSz > I2C_SENSOR_BUS_DMABYTELIM) { + /* Master transmit */ + setupI2CDMAXfer((void *) i2cmXferRec.txBuff, i2cmXferRec.txSz, true); + i2cmXferRec.txSz = 0; + } else { + /* Transistion to read state */ + Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); + } + } else { + /* Not in a transfer state, so handle using the normal I2C handler */ + Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); + } +#else + Chip_I2CM_XferHandler(I2C_SENSOR_BUS, &i2cmXferRec); +#endif + } + + /* If transfer is no longer in progress, disable interrupts */ + if (i2cmXferRec.status != ERR_I2C_BUSY) { + Chip_I2C_DisableInt(I2C_SENSOR_BUS, I2C_INTENSET_MSTPENDING | + I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR); + } +#endif +} + +/** + * @brief Initialize I2C bus connected sensors + * @return True if initalized + */ +osp_bool_t dev_i2c_init(void) +{ + static bool init = false; + + if (init == false) { + /* Setup I2C and master */ + setupI2CMaster(); + +#ifdef I2CM_IRQ_BASED + NVIC_SetPriority(I2C_SENSOR_BUS_IRQn, SENSOR_I2C_PRIORITY); + /* Enable the interrupt for the I2C */ + NVIC_EnableIRQ(I2C_SENSOR_BUS_IRQn); +#endif + init = true; + } + return init; +} + +/** + * @brief adaptation of the Bosch API functions to the + * BOARD specific function + * @return Nothing + */ +void dev_i2c_delay(unsigned int msec) +{ + /* Will WFI for the entire sleep duration. If an interrupt + occurs that wakes the device, the sleep handler will + automatically re-enter WFI until the duration has expired. */ + osDelay(msec); /* Allow startup time for sensors */ +} + +/** + * @brief adaptation of the Bosch API functions to the BOARD specific function + * @return Nothing + */ +char dev_i2c_write(unsigned char dev_addr, unsigned char reg_addr, + unsigned char *reg_data, unsigned char cnt) +{ + /* Setup I2C transfer record */ + g_i2cmTxBuf[0] = reg_addr; + if (cnt == 1) { + g_i2cmTxBuf[1] = reg_data[0]; + } + else if ((cnt > 0) && (cnt < CFG_MAX_SA_TX_BUFFER)) { + memcpy(&g_i2cmTxBuf[1], reg_data, cnt); + } + + memset(&i2cmXferRec, 0, sizeof(i2cmXferRec)); + + i2cmXferRec.slaveAddr = dev_addr; + i2cmXferRec.status = LPC_OK; + i2cmXferRec.txSz = cnt + 1; + i2cmXferRec.rxSz = 0; + i2cmXferRec.txBuff = &g_i2cmTxBuf[0]; + i2cmXferRec.rxBuff = 0; + +#ifdef I2CM_IRQ_BASED + /* Start transfer and wait for completion */ + ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); + /* Wait for transfer completion */ + WaitForI2cXferComplete(&i2cmXferRec); +#else + /* I2C master driver will block if blocking flag is used */ + i2cmXferRec.flags = ROM_I2CM_FLAG_BLOCKING; + + /* Start transfer and wait for completion */ + ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); + +#endif + return LPC_OK; +} + +/** + * @brief adaptation of the Bosch API functions to the + * BOARD specific function + * @return Nothing + */ +char dev_i2c_read(unsigned char dev_addr, unsigned char reg_addr, + unsigned char *reg_data, unsigned char cnt) +{ + memset(&i2cmXferRec, 0, sizeof(i2cmXferRec)); + /* Setup I2C transfer record */ + i2cmXferRec.slaveAddr = dev_addr; + i2cmXferRec.status = LPC_OK; + i2cmXferRec.txSz = 1; + i2cmXferRec.rxSz = cnt; + i2cmXferRec.txBuff = ®_addr; + i2cmXferRec.rxBuff = reg_data; + +#ifdef I2CM_IRQ_BASED + /* Start transfer and wait for completion */ + ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); + /* Wait for transfer completion */ + WaitForI2cXferComplete(&i2cmXferRec); +#else + /* I2C master driver will block if blocking flag is used */ + i2cmXferRec.flags = ROM_I2CM_FLAG_BLOCKING; + + /* Start transfer and wait for completion */ + ROM_I2CM_Transfer(i2cmHandle, &i2cmXferRec); +#endif + + return LPC_OK; +} diff --git a/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.h b/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.h index 0a40152..7105490 100644 --- a/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.h +++ b/embedded/projects/osp-lpc54102/sources/boardsupport/sensacq_i2c.h @@ -1,43 +1,43 @@ -/* - * @brief Adaptation layer for Bosch Drivers - * - * @note - * Copyright(C) NXP Semiconductors, 2014 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __SENSACQ_I2C_H -#define __SENSACQ_I2C_H -#include "osp-types.h" -osp_bool_t dev_i2c_init(void); - -void dev_i2c_delay(unsigned int msec); - -char dev_i2c_write(unsigned char dev_addr, unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt); - -char dev_i2c_read(unsigned char dev_addr, unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt); - -#endif /* __SENSACQ_I2C_H */ +/* + * @brief Adaptation layer for Bosch Drivers + * + * @note + * Copyright(C) NXP Semiconductors, 2014 + * All rights reserved. + * + * @par + * Software that is described herein is for illustrative purposes only + * which provides customers with programming information regarding the + * LPC products. This software is supplied "AS IS" without any warranties of + * any kind, and NXP Semiconductors and its licensor disclaim any and + * all warranties, express or implied, including all implied warranties of + * merchantability, fitness for a particular purpose and non-infringement of + * intellectual property rights. NXP Semiconductors assumes no responsibility + * or liability for the use of the software, conveys no license or rights under any + * patent, copyright, mask work right, or any other intellectual property rights in + * or to any products. NXP Semiconductors reserves the right to make changes + * in the software without notification. NXP Semiconductors also makes no + * representation or warranty that such application will be suitable for the + * specified use without further testing or modification. + * + * @par + * Permission to use, copy, modify, and distribute this software and its + * documentation is hereby granted, under NXP Semiconductors' and its + * licensor's relevant copyrights in the software, without fee, provided that it + * is used in conjunction with NXP Semiconductors microcontrollers. This + * copyright, permission, and disclaimer notice must appear in all copies of + * this code. + */ + +#ifndef __SENSACQ_I2C_H +#define __SENSACQ_I2C_H +#include "osp-types.h" +osp_bool_t dev_i2c_init(void); + +void dev_i2c_delay(unsigned int msec); + +char dev_i2c_write(unsigned char dev_addr, unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt); + +char dev_i2c_read(unsigned char dev_addr, unsigned char reg_addr, unsigned char *reg_data, unsigned char cnt); + +#endif /* __SENSACQ_I2C_H */ diff --git a/embedded/projects/osp-lpc54102/sources/config/rtx_conf_cm.c b/embedded/projects/osp-lpc54102/sources/config/rtx_conf_cm.c index 0f9fe2e..d8f4247 100644 --- a/embedded/projects/osp-lpc54102/sources/config/rtx_conf_cm.c +++ b/embedded/projects/osp-lpc54102/sources/config/rtx_conf_cm.c @@ -1,207 +1,409 @@ -/*---------------------------------------------------------------------------- - * RL-ARM - RTX - *---------------------------------------------------------------------------- - * Name: RTX_CONFIG.C - * Purpose: Configuration of RTX Kernel for Cortex-M - * Rev.: V4.70 - *---------------------------------------------------------------------------- - * This code is part of the RealView Run-Time Library. - * Copyright (c) 2004-2013 KEIL - An ARM Company. All rights reserved. - *---------------------------------------------------------------------------*/ - -#include "rtl.h" -#include "board.h" -#include "common.h" - -/*---------------------------------------------------------------------------- - * RTX User configuration part BEGIN - *---------------------------------------------------------------------------*/ - -//-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- -// -// Task Configuration -// ===================== -// -// Number of concurrent running tasks <0-250> -// Define max. number of tasks that will run at the same time. -// Default: 6 -#ifndef OS_TASKCNT - #define OS_TASKCNT NUMBER_OF_TASKS -#endif - -// Number of tasks with user-provided stack <0-250> -// Define the number of tasks that will use a bigger stack. -// The memory space for the stack is provided by the user. -// Default: 0 -#ifndef OS_PRIVCNT - #define OS_PRIVCNT NUMBER_OF_TASKS -#endif - -// Task stack size [bytes] <20-4096:8><#/4> -// Set the stack size for tasks which is assigned by the system. -// Default: 200 -#ifndef OS_STKSIZE - #define OS_STKSIZE 32 -#endif -const U16 C_gOsStkSize = OS_STKSIZE*4; - -// Check for the stack overflow -// =============================== -// Include the stack checking code for a stack overflow. -// Note that additional code reduces the Kernel performance. -#ifndef OS_STKCHECK - #define OS_STKCHECK 0 -#endif - -// Run in privileged mode -// ========================= -// Run all Tasks in privileged mode. -// Default: Unprivileged -#ifndef OS_RUNPRIV - #define OS_RUNPRIV 1 -#endif - -// -// Tick Timer Configuration -// ============================= -// Hardware timer <0=> Core SysTick <1=> Peripheral Timer -// Define the on-chip timer used as a time-base for RTX. -// Default: Core SysTick -#ifndef OS_TIMER - #define OS_TIMER 0 -#endif - -// Timer clock value [Hz] <1-1000000000> -// Set the timer clock value for selected timer. -// Default: 6000000 (6MHz) -#ifndef OS_CLOCK - #define OS_CLOCK SYSTEM_CLOCK_FREQ -#endif - -// Timer tick value [us] <1-1000000> -// Set the timer tick value for selected timer. -// Default: 10000 (10ms) -#ifndef OS_TICK - #define OS_TICK USEC_PER_TICK -#endif - -// - -// System Configuration -// ======================= -// Round-Robin Task switching -// ============================= -// Enable Round-Robin Task switching. -#ifndef OS_ROBIN - #define OS_ROBIN 0 -#endif - -// Round-Robin Timeout [ticks] <1-1000> -// Define how long a task will execute before a task switch. -// Default: 5 -#ifndef OS_ROBINTOUT - #define OS_ROBINTOUT 5 -#endif - -// - -// Number of user timers <0-250> -// Define max. number of user timers that will run at the same time. -// Default: 0 (User timers disabled) -#ifndef OS_TIMERCNT - #define OS_TIMERCNT 8 -#endif - -// ISR FIFO Queue size<4=> 4 entries <8=> 8 entries -// <12=> 12 entries <16=> 16 entries -// <24=> 24 entries <32=> 32 entries -// <48=> 48 entries <64=> 64 entries -// <96=> 96 entries -// ISR functions store requests to this buffer, -// when they are called from the iterrupt handler. -// Default: 16 entries -#ifndef OS_FIFOSZ - #define OS_FIFOSZ 16 -#endif - -// - -//------------- <<< end of configuration section >>> ----------------------- - -// Standard library system mutexes -// =============================== -// Define max. number system mutexes that are used to protect -// the arm standard runtime library. For microlib they are not used. -#ifndef OS_MUTEXCNT - #define OS_MUTEXCNT 8 -#endif - -/*---------------------------------------------------------------------------- - * RTX User configuration part END - *---------------------------------------------------------------------------*/ - -#define OS_TRV ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) - -/*---------------------------------------------------------------------------- - * Global Functions - *---------------------------------------------------------------------------*/ - -/*--------------------------- os_idle_demon ---------------------------------*/ - -__task void os_idle_demon (void) { - /* The idle demon is a system task, running when no other task is ready */ - /* to run. The 'os_xxx' function calls are not allowed from this task. */ - for (;;) { - __WFI(); - } -} - -/*--------------------------- os_tick_init ----------------------------------*/ - -#if (OS_TIMER != 0) -int os_tick_init (void) { - /* Initialize hardware timer as system tick timer. */ - /* ... */ - return (-1); /* Return IRQ number of timer (0..239) */ -} -#endif - -/*--------------------------- os_tick_irqack --------------------------------*/ - -#if (OS_TIMER != 0) -void os_tick_irqack (void) { - /* Acknowledge timer interrupt. */ - /* ... */ -} -#endif - -/*--------------------------- os_tmr_call -----------------------------------*/ - -void os_tmr_call (U16 info) { - /* This function is called when the user timer has expired. Parameter */ - /* 'info' holds the value, defined when the timer was created. */ - ASFTimerExpiry( info ); - -} - -/*--------------------------- os_error --------------------------------------*/ - -void os_error (U32 err_code) { - /* This function is called when a runtime error is detected. Parameter */ - /* 'err_code' holds the runtime error code (defined in RTL.H). */ - - /* HERE: include optional code to be executed on runtime error. */ - ASF_assert_var( false, err_code, 0, 0 ); - //for (;;); -} - - -/*---------------------------------------------------------------------------- - * RTX Configuration Functions - *---------------------------------------------------------------------------*/ - -#include "rtx_lib.c" - -/*---------------------------------------------------------------------------- - * end of file - *---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------- + * RL-ARM - RTX + *---------------------------------------------------------------------------- + * Name: RTX_CONFIG.C + * Purpose: Configuration of RTX Kernel for Cortex-M + * Rev.: V4.70 + *---------------------------------------------------------------------------- + * This code is part of the RealView Run-Time Library. + * Copyright (c) 2004-2013 KEIL - An ARM Company. All rights reserved. + *---------------------------------------------------------------------------*/ + +#include "rtl.h" +#include "board.h" +#include "common.h" + +/*---------------------------------------------------------------------------- + * RTX User configuration part BEGIN + *---------------------------------------------------------------------------*/ + +//-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- +// +// Thread Configuration +// ======================= +// +// Number of concurrent running threads <0-250> +// Defines max. number of threads that will run at the same time. +// Default: 6 +#ifndef OS_TASKCNT + #define OS_TASKCNT NUMBER_OF_TASKS + /* This should be NUMBER_OF_TASKS but code size surprisingly increases if OS_TASKCNT is reduced.*/ +#endif + +// Task stack size [bytes] <20-4096:8><#/4> +// Set the stack size for tasks which is assigned by the system. +// Default: 200 +#ifndef OS_STKSIZE + #define OS_STKSIZE 0x500 +#endif + +// Main Thread stack size [bytes] <64-4096:8><#/4> +// Defines stack size for main thread. +// Default: 200 +#ifndef OS_MAINSTKSIZE +#define OS_MAINSTKSIZE 0x200 +#endif + +// Number of tasks with user-provided stack <0-250> +// Define the number of tasks that will use a bigger stack. +// The memory space for the stack is provided by the user. +// Default: 0 +#ifndef OS_PRIVCNT + #define OS_PRIVCNT 0 +#endif + +// Total stack size [bytes] for threads with user-provided stack size <0-4096:8><#/4> +// Defines the combined stack size for threads with user-provided stack size. +// Default: 0 +#ifndef OS_PRIVSTKSIZE +#define OS_PRIVSTKSIZE OS_PRIVCNT*0x600 +#endif + +// Check for the stack overflow +// =============================== +// Include the stack checking code for a stack overflow. +// Note that additional code reduces the Kernel performance. +#ifndef OS_STKCHECK + #define OS_STKCHECK 1 +#endif + +// Stack usage watermark +// Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer. +// Enabling this option increases significantly the execution time of osThreadCreate. +#ifndef OS_STKINIT +#define OS_STKINIT 0 +#endif + +// Run in privileged mode +// ========================= +// Run all Tasks in privileged mode. +// Default: Unprivileged +#ifndef OS_RUNPRIV + #define OS_RUNPRIV 1 +#endif + +// Timer Thread stack size [bytes] <64-4096:8><#/4> +// Defines stack size for Timer thread. +// Default: 200 +#ifndef OS_TIMERSTKSZ +#define OS_TIMERSTKSZ 0x100 +#endif + +#if (OS_TIMERS != 0) +#define OS_TASK_CNT (OS_TASKCNT + 1) +#define OS_PRIV_CNT (OS_PRIVCNT + 2) +#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ)) +#else +#define OS_TASK_CNT OS_TASKCNT +#define OS_PRIV_CNT (OS_PRIVCNT + 1) +#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE)) +#endif + +const U16 C_gOsStkSize = OS_STKSIZE*4; + +// +// Tick Timer Configuration +// ============================= +// Hardware timer <0=> Core SysTick <1=> Peripheral Timer +// Define the on-chip timer used as a time-base for RTX. +// Default: Core SysTick +#ifndef OS_TIMER + #define OS_TIMER 0 +#endif + +// Timer clock value [Hz] <1-1000000000> +// Set the timer clock value for selected timer. +// Default: 6000000 (6MHz) +#ifndef OS_CLOCK + #define OS_CLOCK SYSTEM_CLOCK_FREQ +#endif + +// Timer tick value [us] <1-1000000> +// Set the timer tick value for selected timer. +// Default: 10000 (10ms) +#ifndef OS_TICK + #define OS_TICK USEC_PER_TICK +#endif + +// + +// System Configuration +// ======================= +// Round-Robin Task switching +// ============================= +// Enable Round-Robin Task switching. +#ifndef OS_ROBIN + #define OS_ROBIN 0 +#endif + +// Round-Robin Timeout [ticks] <1-1000> +// Define how long a task will execute before a task switch. +// Default: 5 +#ifndef OS_ROBINTOUT + #define OS_ROBINTOUT 5 +#endif + +// + +// Number of user timers <0-250> +// Define max. number of user timers that will run at the same time. +// Default: 0 (User timers disabled) +#ifndef OS_TIMERCNT + #define OS_TIMERCNT 8 +#endif + +/* Memory pool for user specified stack allocation (+main, +timer) */ +uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)]; +uint32_t const os_stack_sz = sizeof(os_stack_mem); + +/* User Timers Resources */ +#if (OS_TIMERS != 0) +extern void osTimerThread (void const *argument); +osThreadDef(osTimerThread, osPriorityNormal-2, 1, 4*OS_TIMERSTKSZ); +osThreadId osThreadId_osTimerThread; +osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *); +osMessageQId osMessageQId_osTimerMessageQ; + +#else +osThreadDef_t os_thread_def_osTimerThread = { NULL }; +osThreadId osThreadId_osTimerThread; +osMessageQDef(osTimerMessageQ, 0, void *); +osMessageQId osMessageQId_osTimerMessageQ; +#endif + +// ISR FIFO Queue size<4=> 4 entries <8=> 8 entries +// <12=> 12 entries <16=> 16 entries +// <24=> 24 entries <32=> 32 entries +// <48=> 48 entries <64=> 64 entries +// <96=> 96 entries +// ISR functions store requests to this buffer, +// when they are called from the iterrupt handler. +// Default: 16 entries +#ifndef OS_FIFOSZ + #define OS_FIFOSZ 16 +#endif + +// + +//------------- <<< end of configuration section >>> ----------------------- + +// Standard library system mutexes +// =============================== +// Define max. number system mutexes that are used to protect +// the arm standard runtime library. For microlib they are not used. +#ifndef OS_MUTEXCNT + #define OS_MUTEXCNT 8 +#endif + +/*---------------------------------------------------------------------------- + * RTX User configuration part END + *---------------------------------------------------------------------------*/ + +#define OS_TRV ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) + +/*---------------------------------------------------------------------------- + * Global Functions + *---------------------------------------------------------------------------*/ + +/*--------------------------- os_idle_demon ---------------------------------*/ + +__task void os_idle_demon (void) { + /* The idle demon is a system task, running when no other task is ready */ + /* to run. The 'os_xxx' function calls are not allowed from this task. */ + for (;;) { + __WFI(); + } +} + +/*--------------------------- os_tick_init ----------------------------------*/ + +#if (OS_TIMER != 0) +int os_tick_init (void) { + /* Initialize hardware timer as system tick timer. */ + /* ... */ + return (-1); /* Return IRQ number of timer (0..239) */ +} +#endif + +/*--------------------------- os_tick_irqack --------------------------------*/ + +#if (OS_TIMER != 0) +void os_tick_irqack (void) { + /* Acknowledge timer interrupt. */ + /* ... */ +} +#endif + +/*--------------------------- os_tmr_call -----------------------------------*/ + +void os_tmr_call (U16 info) { + /* This function is called when the user timer has expired. Parameter */ + /* 'info' holds the value, defined when the timer was created. */ + ASFTimerExpiry( info ); + +} + +/*--------------------------- os_error --------------------------------------*/ + +void os_error (U32 err_code) { + /* This function is called when a runtime error is detected. Parameter */ + /* 'err_code' holds the runtime error code (defined in RTL.H). */ + + /* HERE: include optional code to be executed on runtime error. */ + ASF_assert_var( false, err_code, 0, 0 ); + //for (;;); +} + + +/*---------------------------------------------------------------------------- + * RTX Configuration Functions + *---------------------------------------------------------------------------*/ + +#include "rtx_lib.c" + +/*---------------------------------------------------------------------------- + * RTX Startup + *---------------------------------------------------------------------------*/ + +/* Main Thread definition */ +extern int main (void); +osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE }; + + +#if defined (__CC_ARM) + +#ifdef __MICROLIB +void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); +void _main_init (void) { + osKernelInitialize(); + osThreadCreate(&os_thread_def_main, NULL); + osKernelStart(); + for (;;); +} +#else +__asm void __rt_entry (void) { + + IMPORT __user_setup_stackheap + IMPORT __rt_lib_init + IMPORT os_thread_def_main + IMPORT osKernelInitialize + IMPORT osKernelStart + IMPORT osThreadCreate + IMPORT exit + + BL __user_setup_stackheap + MOV R1,R2 + BL __rt_lib_init + BL osKernelInitialize + LDR R0,=os_thread_def_main + MOVS R1,#0 + BL osThreadCreate + BL osKernelStart + BL exit + + ALIGN +} +#endif + +#elif defined (__GNUC__) + +#ifdef __CS3__ + +/* CS3 start_c routine. + * + * Copyright (c) 2006, 2007 CodeSourcery Inc + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ + +#include "cs3.h" + +extern void __libc_init_array (void); + +__attribute ((noreturn)) void __cs3_start_c (void){ + unsigned regions = __cs3_region_num; + const struct __cs3_region *rptr = __cs3_regions; + + /* Initialize memory */ + for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) { + long long *src = (long long *)rptr->init; + long long *dst = (long long *)rptr->data; + unsigned limit = rptr->init_size; + unsigned count; + + if (src != dst) + for (count = 0; count != limit; count += sizeof (long long)) + *dst++ = *src++; + else + dst = (long long *)((char *)dst + limit); + limit = rptr->zero_size; + for (count = 0; count != limit; count += sizeof (long long)) + *dst++ = 0; + } + + /* Run initializers. */ + __libc_init_array (); + + osKernelInitialize(); + osThreadCreate(&os_thread_def_main, NULL); + osKernelStart(); + for (;;); +} + +#else + +__attribute__((naked)) void software_init_hook (void) { + __asm ( + ".syntax unified\n" + ".thumb\n" + "movs r0,#0\n" + "movs r1,#0\n" + "mov r4,r0\n" + "mov r5,r1\n" + "ldr r0,= __libc_fini_array\n" + "bl atexit\n" + "bl __libc_init_array\n" + "mov r0,r4\n" + "mov r1,r5\n" + "bl osKernelInitialize\n" + "ldr r0,=os_thread_def_main\n" + "movs r1,#0\n" + "bl osThreadCreate\n" + "bl osKernelStart\n" + "bl exit\n" + ); +} + +#endif + +#elif defined (__ICCARM__) + +extern int __low_level_init(void); +extern void __iar_data_init3(void); +extern void exit(int arg); + +__noreturn __stackless void __cmain(void) { + int a; + + if (__low_level_init() != 0) { + __iar_data_init3(); + } + osKernelInitialize(); + osThreadCreate(&os_thread_def_main, NULL); + a = osKernelStart(); + exit(a); +} + +#endif + +/*---------------------------------------------------------------------------- + * end of file + *---------------------------------------------------------------------------*/ diff --git a/embedded/projects/osp-lpc54102/sources/lpcopen/applications/lpc5410x/startup/keil_startup_lpc5410x.s b/embedded/projects/osp-lpc54102/sources/lpcopen/applications/lpc5410x/startup/keil_startup_lpc5410x.s index 942981f..5389553 100644 --- a/embedded/projects/osp-lpc54102/sources/lpcopen/applications/lpc5410x/startup/keil_startup_lpc5410x.s +++ b/embedded/projects/osp-lpc54102/sources/lpcopen/applications/lpc5410x/startup/keil_startup_lpc5410x.s @@ -1,392 +1,392 @@ -;/* -; * @brief LPC5410x startup code for Keil -; * -; * @note -; * Copyright(C) NXP Semiconductors, 2014 -; * All rights reserved. -; * -; * @par -; * Software that is described herein is for illustrative purposes only -; * which provides customers with programming information regarding the -; * LPC products. This software is supplied "AS IS" without any warranties of -; * any kind, and NXP Semiconductors and its licensor disclaim any and -; * all warranties, express or implied, including all implied warranties of -; * merchantability, fitness for a particular purpose and non-infringement of -; * intellectual property rights. NXP Semiconductors assumes no responsibility -; * or liability for the use of the software, conveys no license or rights under any -; * patent, copyright, mask work right, or any other intellectual property rights in -; * or to any products. NXP Semiconductors reserves the right to make changes -; * in the software without notification. NXP Semiconductors also makes no -; * representation or warranty that such application will be suitable for the -; * specified use without further testing or modification. -; * -; * @par -; * Permission to use, copy, modify, and distribute this software and its -; * documentation is hereby granted, under NXP Semiconductors' and its -; * licensor's relevant copyrights in the software, without fee, provided that it -; * is used in conjunction with NXP Semiconductors microcontrollers. This -; * copyright, permission, and disclaimer notice must appear in all copies of -; * this code. -; */ - -; Stack Configuration -; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> -; - -; original stack size was set to 0x200 - EXPORT Stack_Size -Stack_Size EQU 0x00000400 - - EXPORT Stack_Mem - AREA STACK, NOINIT, READWRITE, ALIGN=3 -Stack_Mem SPACE Stack_Size -__initial_sp - - -; Heap Configuration -; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> -; - -; Original heap size was set to 0x100 -Heap_Size EQU 0x00006000 - - AREA HEAP, NOINIT, READWRITE, ALIGN=3 -__heap_base -Heap_Mem SPACE Heap_Size -__heap_limit - - PRESERVE8 - THUMB - -; Vector Table Mapped to Address 0 at Reset - AREA RESET, DATA, READONLY - EXPORT __Vectors - -__Vectors DCD __initial_sp ; Top of Stack - DCD Reset_Handler ; Reset Handler - - DCD NMI_Handler - DCD HardFault_Handler - DCD MemManage_Handler - DCD BusFault_Handler - DCD UsageFault_Handler -__vector_table_0x1c - DCD 0 ; Checksum of the first 7 words - DCD 0 - DCD 0 ; Enhanced image marker, set to 0x0 for legacy boot - DCD 0 ; Pointer to enhanced boot block, set to 0x0 for legacy boot - DCD SVC_Handler - DCD DebugMon_Handler - DCD 0 - DCD PendSV_Handler - DCD SysTick_Handler - - ; External Interrupts - DCD WDT_IRQHandler ; Watchdog - DCD BOD_IRQHandler ; Brown Out Detect - DCD Reserved_IRQHandler ; Reserved - DCD DMA_IRQHandler ; DMA Controller - DCD GINT0_IRQHandler ; GPIO Group0 Interrupt - DCD PIN_INT0_IRQHandler ; PIO INT0 - DCD PIN_INT1_IRQHandler ; PIO INT1 - DCD PIN_INT2_IRQHandler ; PIO INT2 - DCD PIN_INT3_IRQHandler ; PIO INT3 - DCD UTICK_IRQHandler ; UTICK timer - DCD MRT_IRQHandler ; Multi-Rate Timer - DCD CT32B0_IRQHandler ; CT32B0 - DCD CT32B1_IRQHandler ; CT32B1 - DCD CT32B2_IRQHandler ; CT32B2 - DCD CT32B3_IRQHandler ; CT32B3 - DCD CT32B4_IRQHandler ; CT32B4 - DCD SCT0_IRQHandler ; Smart Counter Timer - DCD UART0_IRQHandler ; UART0 - DCD UART1_IRQHandler ; UART1 - DCD UART2_IRQHandler ; UART2 - DCD UART3_IRQHandler ; UART3 - DCD I2C0_IRQHandler ; I2C0 controller - DCD I2C1_IRQHandler ; I2C1 controller - DCD I2C2_IRQHandler ; I2C2 controller - DCD SPI0_IRQHandler ; SPI0 controller - DCD SPI1_IRQHandler ; SPI1 controller - DCD ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt - DCD ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt - DCD ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed - DCD RTC_IRQHandler ; RTC Timer - DCD Reserved_IRQHandler ; Reserved - DCD MAILBOX_IRQHandler ; Mailbox - DCD GINT1_IRQHandler ; GPIO Group1 Interrupt - DCD PIN_INT4_IRQHandler ; PIO INT4 - DCD PIN_INT5_IRQHandler ; PIO INT5 - DCD PIN_INT6_IRQHandler ; PIO INT6 - DCD PIN_INT7_IRQHandler ; PIO INT7 - DCD Reserved_IRQHandler ; Reserved - DCD Reserved_IRQHandler ; Reserved - DCD Reserved_IRQHandler ; Reserved - DCD RIT_IRQHandler ; RITimer - DCD Reserved41_IRQHandler ; Reserved - DCD Reserved42_IRQHandler ; Reserved - DCD Reserved43_IRQHandler ; Reserved - DCD Reserved44_IRQHandler ; Reserved - -;// Code Read Protection level (CRP) -;// CRP_Level: -;// <0xFFFFFFFF=> Disabled -;// <0x4E697370=> NO_ISP -;// <0x12345678=> CRP1 -;// <0x87654321=> CRP2 -;// <0x43218765=> CRP3 (Are you sure?) -;// -CRP_Level EQU 0xFFFFFFFF - - IF :LNOT::DEF:NO_CRP - AREA |.ARM.__at_0x02FC|, CODE, READONLY -CRP_Key DCD 0xFFFFFFFF - ENDIF - - AREA |.text|, CODE, READONLY - -cpu_id EQU 0xE000ED00 -cpu_ctrl EQU 0x40000300 -coproc_boot EQU 0x40000304 -coproc_stack EQU 0x40000308 - -rel_vals - DCD cpu_id, cpu_ctrl, coproc_boot, coproc_stack - DCW 0xFFF, 0xC24 - -; Reset Handler - shared for both cores -Reset_Handler PROC - EXPORT Reset_Handler [WEAK] - EXPORT SystemInit [WEAK] - IMPORT __main - - IF :LNOT::DEF:SLAVEBOOT - ; Both the M0+ and M4 core come via this shared startup code, - ; but the M0+ and M4 core have different vector tables. - ; Determine if the core executing this code is the master or - ; the slave and handle each core state individually. -shared_boot_entry - LDR r6, =rel_vals - MOVS r4, #0 ; Flag for slave core (0) - MOVS r5, #1 - - ; Determine which core (M0+ or M4) this code is running on - ; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24) -get_current_core_id - LDR r0, [r6, #0] - LDR r1, [r0] ; r1 = CPU ID status - LSRS r1, r1, #4 ; Right justify 12 CPU ID bits - LDRH r2, [r6, #16] ; Mask for CPU ID bits - ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID - LDRH r3, [r6, #18] ; Mask for CPU ID bits - CMP r3, r2 ; Core ID matches M4 identifier - BNE get_master_status - MOV r4, r5 ; Set flag for master core (1) - - ; Determine if M4 core is the master or slave - ; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4) -get_master_status - LDR r0, [r6, #4] - LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status - ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave) - - ; Select boot based on selected master core and core ID -select_boot - EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave) - BNE slave_boot - B normal_boot - - ; Slave boot -slave_boot - LDR r0, [r6, #8] - LDR r2, [r0] ; r1 = SYSCON co-processor boot address - CMP r2, #0 ; Slave boot address = 0 (not set up)? - BEQ cpu_sleep - LDR r0, [r6, #12] - LDR r1, [r0] ; r5 = SYSCON co-processor stack address - MOV sp, r1 ; Update slave CPU stack pointer - ; Be sure to update VTOR for the slave MCU to point to the - ; slave vector table in boot memory - BX r2 ; Jump to slave boot address - - ; Slave isn't yet setup for system boot from the master - ; so sleep until the master sets it up and then reboots it -cpu_sleep - MOV sp, r5 ; Will force exception if something happens -cpu_sleep_wfi - WFI ; Sleep forever until master reboots - B cpu_sleep_wfi - ENDIF - - ; Normal boot for master/slave -normal_boot - LDR r0, =SystemInit - BLX r0 - LDR r0, =__main - BX r0 - ENDP - -; For cores with SystemInit() or __main(), the code will sleep the MCU -SystemInit PROC - EXPORT SystemInit [WEAK] - BX lr - ENDP - -; Dummy Exception Handlers (infinite loops which can be modified) -NMI_Handler PROC - EXPORT NMI_Handler [WEAK] - B . - ENDP -HardFault_Handler\ - PROC - EXPORT HardFault_Handler [WEAK] - B . - ENDP -MemManage_Handler PROC - EXPORT MemManage_Handler [WEAK] - B . - ENDP -BusFault_Handler PROC - EXPORT BusFault_Handler [WEAK] - B . - ENDP -UsageFault_Handler PROC - EXPORT UsageFault_Handler [WEAK] - B . - ENDP -SVC_Handler PROC - EXPORT SVC_Handler [WEAK] - B . - ENDP -DebugMon_Handler PROC - EXPORT DebugMon_Handler [WEAK] - B . - ENDP -PendSV_Handler PROC - EXPORT PendSV_Handler [WEAK] - B . - ENDP -SysTick_Handler PROC - EXPORT SysTick_Handler [WEAK] - B . - ENDP - -Default_Handler PROC - EXPORT WDT_IRQHandler [WEAK] ; Watchdog - EXPORT BOD_IRQHandler [WEAK] ; Brown Out Detect - EXPORT DMA_IRQHandler [WEAK] ; DMA Controller - EXPORT GINT0_IRQHandler [WEAK] ; GPIO Group0 Interrupt - EXPORT PIN_INT0_IRQHandler [WEAK] ; PIO INT0 - EXPORT PIN_INT1_IRQHandler [WEAK] ; PIO INT1 - EXPORT PIN_INT2_IRQHandler [WEAK] ; PIO INT2 - EXPORT PIN_INT3_IRQHandler [WEAK] ; PIO INT3 - EXPORT UTICK_IRQHandler [WEAK] ; UTICK timer - EXPORT MRT_IRQHandler [WEAK] ; Multi-Rate Timer - EXPORT CT32B0_IRQHandler [WEAK] ; CT32B0 - EXPORT CT32B1_IRQHandler [WEAK] ; CT32B1 - EXPORT CT32B2_IRQHandler [WEAK] ; CT32B2 - EXPORT CT32B3_IRQHandler [WEAK] ; CT32B3 - EXPORT CT32B4_IRQHandler [WEAK] ; CT32B4 - EXPORT UART0_IRQHandler [WEAK] ; UART0 - EXPORT SCT0_IRQHandler [WEAK] ; Smart Counter Timer - EXPORT UART1_IRQHandler [WEAK] ; UART1 - EXPORT UART2_IRQHandler [WEAK] ; UART2 - EXPORT UART3_IRQHandler [WEAK] ; UART3 - EXPORT I2C0_IRQHandler [WEAK] ; I2C0 controller - EXPORT I2C1_IRQHandler [WEAK] ; I2C1 controller - EXPORT I2C2_IRQHandler [WEAK] ; I2C2 controller - EXPORT SPI0_IRQHandler [WEAK] ; SPI0 controller - EXPORT SPI1_IRQHandler [WEAK] ; SPI1 controller - EXPORT ADC_SEQA_IRQHandler [WEAK] ; ADC0 A sequence (A/D Converter) interrupt - EXPORT ADC_SEQB_IRQHandler [WEAK] ; ADC0 B sequence (A/D Converter) interrupt - EXPORT ADC_THCMP_IRQHandler [WEAK] ; ADC THCMP and OVERRUN ORed - EXPORT RTC_IRQHandler [WEAK] ; RTC Timer - EXPORT MAILBOX_IRQHandler [WEAK] ; Mailbox - EXPORT GINT1_IRQHandler [WEAK] ; GPIO Group1 Interrupt - EXPORT PIN_INT4_IRQHandler [WEAK] ; PIO INT4 - EXPORT PIN_INT5_IRQHandler [WEAK] ; PIO INT5 - EXPORT PIN_INT6_IRQHandler [WEAK] ; PIO INT6 - EXPORT PIN_INT7_IRQHandler [WEAK] ; PIO INT7 - EXPORT RIT_IRQHandler [WEAK] ; RITimer - EXPORT Reserved41_IRQHandler [WEAK] ; Reserved - EXPORT Reserved42_IRQHandler [WEAK] ; Reserved - EXPORT Reserved43_IRQHandler [WEAK] ; Reserved - EXPORT Reserved44_IRQHandler [WEAK] ; Reserved - EXPORT Reserved_IRQHandler [WEAK] ; Reserved - -WDT_IRQHandler ; Watchdog -BOD_IRQHandler ; Brown Out Detect -DMA_IRQHandler ; DMA Controller -GINT0_IRQHandler ; GPIO Group0 Interrupt -PIN_INT0_IRQHandler ; PIO INT0 -PIN_INT1_IRQHandler ; PIO INT1 -PIN_INT2_IRQHandler ; PIO INT2 -PIN_INT3_IRQHandler ; PIO INT3 -UTICK_IRQHandler ; UTICK timer -MRT_IRQHandler ; Multi-Rate Timer -CT32B0_IRQHandler ; CT32B0 -CT32B1_IRQHandler ; CT32B1 -CT32B2_IRQHandler ; CT32B2 -CT32B3_IRQHandler ; CT32B3 -CT32B4_IRQHandler ; CT32B4 -UART0_IRQHandler ; UART0 -SCT0_IRQHandler ; Smart Counter Timer -UART1_IRQHandler ; UART1 -UART2_IRQHandler ; UART2 -UART3_IRQHandler ; UART3 -I2C0_IRQHandler ; I2C0 controller -I2C1_IRQHandler ; I2C1 controller -I2C2_IRQHandler ; I2C2 controller -SPI0_IRQHandler ; SPI0 controller -SPI1_IRQHandler ; SPI1 controller -ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt -ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt -ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed -RTC_IRQHandler ; RTC Timer -MAILBOX_IRQHandler ; Mailbox -GINT1_IRQHandler ; GPIO Group1 Interrupt -PIN_INT4_IRQHandler ; PIO INT4 -PIN_INT5_IRQHandler ; PIO INT5 -PIN_INT6_IRQHandler ; PIO INT6 -PIN_INT7_IRQHandler ; PIO INT7 -RIT_IRQHandler ; RITimer -Reserved41_IRQHandler ; Reserved -Reserved42_IRQHandler ; Reserved -Reserved43_IRQHandler ; Reserved -Reserved44_IRQHandler ; Reserved -Reserved_IRQHandler ; Reserved - - B . - - ENDP - - - ALIGN - - -; User Initial Stack & Heap - - IF :DEF:__MICROLIB - - EXPORT __initial_sp - EXPORT __heap_base - EXPORT __heap_limit - - ELSE - - IMPORT __use_two_region_memory - EXPORT __user_initial_stackheap -__user_initial_stackheap - - LDR R0, = Heap_Mem - LDR R1, =(Stack_Mem + Stack_Size) - LDR R2, = (Heap_Mem + Heap_Size) - LDR R3, = Stack_Mem - BX LR - - ALIGN - - ENDIF - - - END +;/* +; * @brief LPC5410x startup code for Keil +; * +; * @note +; * Copyright(C) NXP Semiconductors, 2014 +; * All rights reserved. +; * +; * @par +; * Software that is described herein is for illustrative purposes only +; * which provides customers with programming information regarding the +; * LPC products. This software is supplied "AS IS" without any warranties of +; * any kind, and NXP Semiconductors and its licensor disclaim any and +; * all warranties, express or implied, including all implied warranties of +; * merchantability, fitness for a particular purpose and non-infringement of +; * intellectual property rights. NXP Semiconductors assumes no responsibility +; * or liability for the use of the software, conveys no license or rights under any +; * patent, copyright, mask work right, or any other intellectual property rights in +; * or to any products. NXP Semiconductors reserves the right to make changes +; * in the software without notification. NXP Semiconductors also makes no +; * representation or warranty that such application will be suitable for the +; * specified use without further testing or modification. +; * +; * @par +; * Permission to use, copy, modify, and distribute this software and its +; * documentation is hereby granted, under NXP Semiconductors' and its +; * licensor's relevant copyrights in the software, without fee, provided that it +; * is used in conjunction with NXP Semiconductors microcontrollers. This +; * copyright, permission, and disclaimer notice must appear in all copies of +; * this code. +; */ + +; Stack Configuration +; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +; original stack size was set to 0x200 + EXPORT Stack_Size +Stack_Size EQU 0x00000200 + + EXPORT Stack_Mem + AREA STACK, NOINIT, READWRITE, ALIGN=3 +Stack_Mem SPACE Stack_Size +__initial_sp + + +; Heap Configuration +; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> +; + +; Original heap size was set to 0x100 +Heap_Size EQU 0x100 + + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +__heap_base +Heap_Mem SPACE Heap_Size +__heap_limit + + PRESERVE8 + THUMB + +; Vector Table Mapped to Address 0 at Reset + AREA RESET, DATA, READONLY + EXPORT __Vectors + +__Vectors DCD __initial_sp ; Top of Stack + DCD Reset_Handler ; Reset Handler + + DCD NMI_Handler + DCD HardFault_Handler + DCD MemManage_Handler + DCD BusFault_Handler + DCD UsageFault_Handler +__vector_table_0x1c + DCD 0 ; Checksum of the first 7 words + DCD 0 + DCD 0 ; Enhanced image marker, set to 0x0 for legacy boot + DCD 0 ; Pointer to enhanced boot block, set to 0x0 for legacy boot + DCD SVC_Handler + DCD DebugMon_Handler + DCD 0 + DCD PendSV_Handler + DCD SysTick_Handler + + ; External Interrupts + DCD WDT_IRQHandler ; Watchdog + DCD BOD_IRQHandler ; Brown Out Detect + DCD Reserved_IRQHandler ; Reserved + DCD DMA_IRQHandler ; DMA Controller + DCD GINT0_IRQHandler ; GPIO Group0 Interrupt + DCD PIN_INT0_IRQHandler ; PIO INT0 + DCD PIN_INT1_IRQHandler ; PIO INT1 + DCD PIN_INT2_IRQHandler ; PIO INT2 + DCD PIN_INT3_IRQHandler ; PIO INT3 + DCD UTICK_IRQHandler ; UTICK timer + DCD MRT_IRQHandler ; Multi-Rate Timer + DCD CT32B0_IRQHandler ; CT32B0 + DCD CT32B1_IRQHandler ; CT32B1 + DCD CT32B2_IRQHandler ; CT32B2 + DCD CT32B3_IRQHandler ; CT32B3 + DCD CT32B4_IRQHandler ; CT32B4 + DCD SCT0_IRQHandler ; Smart Counter Timer + DCD UART0_IRQHandler ; UART0 + DCD UART1_IRQHandler ; UART1 + DCD UART2_IRQHandler ; UART2 + DCD UART3_IRQHandler ; UART3 + DCD I2C0_IRQHandler ; I2C0 controller + DCD I2C1_IRQHandler ; I2C1 controller + DCD I2C2_IRQHandler ; I2C2 controller + DCD SPI0_IRQHandler ; SPI0 controller + DCD SPI1_IRQHandler ; SPI1 controller + DCD ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt + DCD ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt + DCD ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed + DCD RTC_IRQHandler ; RTC Timer + DCD Reserved_IRQHandler ; Reserved + DCD MAILBOX_IRQHandler ; Mailbox + DCD GINT1_IRQHandler ; GPIO Group1 Interrupt + DCD PIN_INT4_IRQHandler ; PIO INT4 + DCD PIN_INT5_IRQHandler ; PIO INT5 + DCD PIN_INT6_IRQHandler ; PIO INT6 + DCD PIN_INT7_IRQHandler ; PIO INT7 + DCD Reserved_IRQHandler ; Reserved + DCD Reserved_IRQHandler ; Reserved + DCD Reserved_IRQHandler ; Reserved + DCD RIT_IRQHandler ; RITimer + DCD Reserved41_IRQHandler ; Reserved + DCD Reserved42_IRQHandler ; Reserved + DCD Reserved43_IRQHandler ; Reserved + DCD Reserved44_IRQHandler ; Reserved + +;// Code Read Protection level (CRP) +;// CRP_Level: +;// <0xFFFFFFFF=> Disabled +;// <0x4E697370=> NO_ISP +;// <0x12345678=> CRP1 +;// <0x87654321=> CRP2 +;// <0x43218765=> CRP3 (Are you sure?) +;// +CRP_Level EQU 0xFFFFFFFF + + IF :LNOT::DEF:NO_CRP + AREA |.ARM.__at_0x02FC|, CODE, READONLY +CRP_Key DCD 0xFFFFFFFF + ENDIF + + AREA |.text|, CODE, READONLY + +cpu_id EQU 0xE000ED00 +cpu_ctrl EQU 0x40000300 +coproc_boot EQU 0x40000304 +coproc_stack EQU 0x40000308 + +rel_vals + DCD cpu_id, cpu_ctrl, coproc_boot, coproc_stack + DCW 0xFFF, 0xC24 + +; Reset Handler - shared for both cores +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + EXPORT SystemInit [WEAK] + IMPORT __main + + IF :LNOT::DEF:SLAVEBOOT + ; Both the M0+ and M4 core come via this shared startup code, + ; but the M0+ and M4 core have different vector tables. + ; Determine if the core executing this code is the master or + ; the slave and handle each core state individually. +shared_boot_entry + LDR r6, =rel_vals + MOVS r4, #0 ; Flag for slave core (0) + MOVS r5, #1 + + ; Determine which core (M0+ or M4) this code is running on + ; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24) +get_current_core_id + LDR r0, [r6, #0] + LDR r1, [r0] ; r1 = CPU ID status + LSRS r1, r1, #4 ; Right justify 12 CPU ID bits + LDRH r2, [r6, #16] ; Mask for CPU ID bits + ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID + LDRH r3, [r6, #18] ; Mask for CPU ID bits + CMP r3, r2 ; Core ID matches M4 identifier + BNE get_master_status + MOV r4, r5 ; Set flag for master core (1) + + ; Determine if M4 core is the master or slave + ; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4) +get_master_status + LDR r0, [r6, #4] + LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status + ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave) + + ; Select boot based on selected master core and core ID +select_boot + EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave) + BNE slave_boot + B normal_boot + + ; Slave boot +slave_boot + LDR r0, [r6, #8] + LDR r2, [r0] ; r1 = SYSCON co-processor boot address + CMP r2, #0 ; Slave boot address = 0 (not set up)? + BEQ cpu_sleep + LDR r0, [r6, #12] + LDR r1, [r0] ; r5 = SYSCON co-processor stack address + MOV sp, r1 ; Update slave CPU stack pointer + ; Be sure to update VTOR for the slave MCU to point to the + ; slave vector table in boot memory + BX r2 ; Jump to slave boot address + + ; Slave isn't yet setup for system boot from the master + ; so sleep until the master sets it up and then reboots it +cpu_sleep + MOV sp, r5 ; Will force exception if something happens +cpu_sleep_wfi + WFI ; Sleep forever until master reboots + B cpu_sleep_wfi + ENDIF + + ; Normal boot for master/slave +normal_boot + LDR r0, =SystemInit + BLX r0 + LDR r0, =__main + BX r0 + ENDP + +; For cores with SystemInit() or __main(), the code will sleep the MCU +SystemInit PROC + EXPORT SystemInit [WEAK] + BX lr + ENDP + +; Dummy Exception Handlers (infinite loops which can be modified) +NMI_Handler PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP +MemManage_Handler PROC + EXPORT MemManage_Handler [WEAK] + B . + ENDP +BusFault_Handler PROC + EXPORT BusFault_Handler [WEAK] + B . + ENDP +UsageFault_Handler PROC + EXPORT UsageFault_Handler [WEAK] + B . + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +DebugMon_Handler PROC + EXPORT DebugMon_Handler [WEAK] + B . + ENDP +PendSV_Handler PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP +SysTick_Handler PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +Default_Handler PROC + EXPORT WDT_IRQHandler [WEAK] ; Watchdog + EXPORT BOD_IRQHandler [WEAK] ; Brown Out Detect + EXPORT DMA_IRQHandler [WEAK] ; DMA Controller + EXPORT GINT0_IRQHandler [WEAK] ; GPIO Group0 Interrupt + EXPORT PIN_INT0_IRQHandler [WEAK] ; PIO INT0 + EXPORT PIN_INT1_IRQHandler [WEAK] ; PIO INT1 + EXPORT PIN_INT2_IRQHandler [WEAK] ; PIO INT2 + EXPORT PIN_INT3_IRQHandler [WEAK] ; PIO INT3 + EXPORT UTICK_IRQHandler [WEAK] ; UTICK timer + EXPORT MRT_IRQHandler [WEAK] ; Multi-Rate Timer + EXPORT CT32B0_IRQHandler [WEAK] ; CT32B0 + EXPORT CT32B1_IRQHandler [WEAK] ; CT32B1 + EXPORT CT32B2_IRQHandler [WEAK] ; CT32B2 + EXPORT CT32B3_IRQHandler [WEAK] ; CT32B3 + EXPORT CT32B4_IRQHandler [WEAK] ; CT32B4 + EXPORT UART0_IRQHandler [WEAK] ; UART0 + EXPORT SCT0_IRQHandler [WEAK] ; Smart Counter Timer + EXPORT UART1_IRQHandler [WEAK] ; UART1 + EXPORT UART2_IRQHandler [WEAK] ; UART2 + EXPORT UART3_IRQHandler [WEAK] ; UART3 + EXPORT I2C0_IRQHandler [WEAK] ; I2C0 controller + EXPORT I2C1_IRQHandler [WEAK] ; I2C1 controller + EXPORT I2C2_IRQHandler [WEAK] ; I2C2 controller + EXPORT SPI0_IRQHandler [WEAK] ; SPI0 controller + EXPORT SPI1_IRQHandler [WEAK] ; SPI1 controller + EXPORT ADC_SEQA_IRQHandler [WEAK] ; ADC0 A sequence (A/D Converter) interrupt + EXPORT ADC_SEQB_IRQHandler [WEAK] ; ADC0 B sequence (A/D Converter) interrupt + EXPORT ADC_THCMP_IRQHandler [WEAK] ; ADC THCMP and OVERRUN ORed + EXPORT RTC_IRQHandler [WEAK] ; RTC Timer + EXPORT MAILBOX_IRQHandler [WEAK] ; Mailbox + EXPORT GINT1_IRQHandler [WEAK] ; GPIO Group1 Interrupt + EXPORT PIN_INT4_IRQHandler [WEAK] ; PIO INT4 + EXPORT PIN_INT5_IRQHandler [WEAK] ; PIO INT5 + EXPORT PIN_INT6_IRQHandler [WEAK] ; PIO INT6 + EXPORT PIN_INT7_IRQHandler [WEAK] ; PIO INT7 + EXPORT RIT_IRQHandler [WEAK] ; RITimer + EXPORT Reserved41_IRQHandler [WEAK] ; Reserved + EXPORT Reserved42_IRQHandler [WEAK] ; Reserved + EXPORT Reserved43_IRQHandler [WEAK] ; Reserved + EXPORT Reserved44_IRQHandler [WEAK] ; Reserved + EXPORT Reserved_IRQHandler [WEAK] ; Reserved + +WDT_IRQHandler ; Watchdog +BOD_IRQHandler ; Brown Out Detect +DMA_IRQHandler ; DMA Controller +GINT0_IRQHandler ; GPIO Group0 Interrupt +PIN_INT0_IRQHandler ; PIO INT0 +PIN_INT1_IRQHandler ; PIO INT1 +PIN_INT2_IRQHandler ; PIO INT2 +PIN_INT3_IRQHandler ; PIO INT3 +UTICK_IRQHandler ; UTICK timer +MRT_IRQHandler ; Multi-Rate Timer +CT32B0_IRQHandler ; CT32B0 +CT32B1_IRQHandler ; CT32B1 +CT32B2_IRQHandler ; CT32B2 +CT32B3_IRQHandler ; CT32B3 +CT32B4_IRQHandler ; CT32B4 +UART0_IRQHandler ; UART0 +SCT0_IRQHandler ; Smart Counter Timer +UART1_IRQHandler ; UART1 +UART2_IRQHandler ; UART2 +UART3_IRQHandler ; UART3 +I2C0_IRQHandler ; I2C0 controller +I2C1_IRQHandler ; I2C1 controller +I2C2_IRQHandler ; I2C2 controller +SPI0_IRQHandler ; SPI0 controller +SPI1_IRQHandler ; SPI1 controller +ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt +ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt +ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed +RTC_IRQHandler ; RTC Timer +MAILBOX_IRQHandler ; Mailbox +GINT1_IRQHandler ; GPIO Group1 Interrupt +PIN_INT4_IRQHandler ; PIO INT4 +PIN_INT5_IRQHandler ; PIO INT5 +PIN_INT6_IRQHandler ; PIO INT6 +PIN_INT7_IRQHandler ; PIO INT7 +RIT_IRQHandler ; RITimer +Reserved41_IRQHandler ; Reserved +Reserved42_IRQHandler ; Reserved +Reserved43_IRQHandler ; Reserved +Reserved44_IRQHandler ; Reserved +Reserved_IRQHandler ; Reserved + + B . + + ENDP + + + ALIGN + + +; User Initial Stack & Heap + + IF :DEF:__MICROLIB + + EXPORT __initial_sp + EXPORT __heap_base + EXPORT __heap_limit + + ELSE + + IMPORT __use_two_region_memory + EXPORT __user_initial_stackheap +__user_initial_stackheap + + LDR R0, = Heap_Mem + LDR R1, =(Stack_Mem + Stack_Size) + LDR R2, = (Heap_Mem + Heap_Size) + LDR R3, = Stack_Mem + BX LR + + ALIGN + + ENDIF + + + END diff --git a/include/hal/gpio_api.h b/include/hal/gpio_api.h new file mode 100644 index 0000000..4dfe8b3 --- /dev/null +++ b/include/hal/gpio_api.h @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GPIO_API_H +#define GPIO_API_H + +#include "common.h" +#include "PinNames.h" +#include "Gpio_object.h" +#include "port_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Set the given pin as GPIO + * @param pin The pin to be set as GPIO + * @return The GPIO port mask for this pin + **/ +uint32_t gpio_set(PinName pin); + +/* Checks if gpio object is connected (pin was not initialized with NC) + * @param pin The pin to be set as GPIO + * @return 0 if port is initialized with NC + **/ +int gpio_is_connected(const gpio_t *obj); + +/* GPIO object */ +void gpio_init(gpio_t *obj, PinName pin); + +void gpio_mode (gpio_t *obj, PinMode mode); +void gpio_dir (gpio_t *obj, PinDirection direction); + +void gpio_write(gpio_t *obj, int value); +int gpio_read (gpio_t *obj); + +// the following set of functions are generic and are implemented in the common gpio.c file +void gpio_init_in(gpio_t* gpio, PinName pin); +void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode); +void gpio_init_out(gpio_t* gpio, PinName pin); +void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value); +void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/hal/gpio_irq_api.h b/include/hal/gpio_irq_api.h new file mode 100644 index 0000000..1c55dbe --- /dev/null +++ b/include/hal/gpio_irq_api.h @@ -0,0 +1,59 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GPIO_IRQ_API_H +#define GPIO_IRQ_API_H + +#include "common.h" +#include "PinNames.h" +#include "Objects.h" + +#if DEVICE_INTERRUPTIN + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + IRQ_EDGE_RISE, + IRQ_EDGE_FALL, + IRQ_LEVEL_HIGH, + IRQ_LEVEL_LOW +} gpio_irq_event; + +typedef enum { + EXTI_ACCEL_ID=0, + EXTI_GYRO_ID, + EXTI_MAG_ID, + EXTI_MAX_ID +}EXTI_id_e; + +typedef struct gpio_irq_s gpio_irq_t; + +typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event); + +int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); +void gpio_irq_free(gpio_irq_t *obj); +void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); +void gpio_irq_enable(gpio_irq_t *obj); +void gpio_irq_disable(gpio_irq_t *obj); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif diff --git a/include/hal/i2c_api.h b/include/hal/i2c_api.h new file mode 100644 index 0000000..9c29d8a --- /dev/null +++ b/include/hal/i2c_api.h @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef I2C_API_H +#define I2C_API_H + +#include "device.h" + +#if DEVICE_I2C + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct i2c_s i2c_t; + +enum { + I2C_ERROR_NO_SLAVE = -1, + I2C_ERROR_BUS_BUSY = -2 +}; + +void i2c_init (i2c_t *obj, PinName sda, PinName scl); +void i2c_frequency (i2c_t *obj, int hz); +int i2c_start (i2c_t *obj); +int i2c_stop (i2c_t *obj); +int i2c_read (i2c_t *obj, int address, char *data, int length, int stop); +int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop); +void i2c_reset (i2c_t *obj); +int i2c_byte_read (i2c_t *obj, int last); +int i2c_byte_write (i2c_t *obj, int data); + +#if DEVICE_I2CSLAVE +void i2c_slave_mode (i2c_t *obj, int enable_slave); +int i2c_slave_receive(i2c_t *obj); +int i2c_slave_read (i2c_t *obj, char *data, int length); +int i2c_slave_write (i2c_t *obj, const char *data, int length); +int i2c_slave_byte_read(i2c_t *obj, int last); +int i2c_slave_byte_write(i2c_t *obj, int data); +void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/include/hal/pinmap.h b/include/hal/pinmap.h new file mode 100644 index 0000000..9c98d17 --- /dev/null +++ b/include/hal/pinmap.h @@ -0,0 +1,43 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PINMAP_H +#define PINMAP_H + +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + int peripheral; + int function; +} PinMap; + +void pin_function(PinName pin, uint32_t function); +void pin_mode (PinName pin, PinMode mode); + +uint32_t pinmap_peripheral(PinName pin, const PinMap* map); +uint32_t pinmap_merge (uint32_t a, uint32_t b); +void pinmap_pinout (PinName pin, const PinMap *map); +uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/hal/port_api.h b/include/hal/port_api.h new file mode 100644 index 0000000..b0ae6df --- /dev/null +++ b/include/hal/port_api.h @@ -0,0 +1,42 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PORTMAP_H +#define PORTMAP_H + +#include "common.h" + +#if DEVICE_PORTIN || DEVICE_PORTOUT + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct port_s port_t; + +PinName port_pin(PortName port, int pin_n); + +void port_init (port_t *obj, PortName port, int mask, PinDirection dir); +void port_mode (port_t *obj, PinMode mode); +void port_dir (port_t *obj, PinDirection dir); +void port_write(port_t *obj, int value); +int port_read (port_t *obj); + +#ifdef __cplusplus +} +#endif +#endif + +#endif diff --git a/include/hal/rtc_api.h b/include/hal/rtc_api.h new file mode 100644 index 0000000..2c06cc5 --- /dev/null +++ b/include/hal/rtc_api.h @@ -0,0 +1,42 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RTC_API_H +#define RTC_API_H + +#include "device.h" + +#if DEVICE_RTC + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void rtc_init(void); +void rtc_free(void); +int rtc_isenabled(void); + +time_t rtc_read(void); +void rtc_write(time_t t); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif diff --git a/include/hal/serial_api.h b/include/hal/serial_api.h new file mode 100644 index 0000000..a2f86e4 --- /dev/null +++ b/include/hal/serial_api.h @@ -0,0 +1,78 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SERIAL_API_H +#define SERIAL_API_H + +#include "device.h" + +#if DEVICE_SERIAL + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + ParityNone = 0, + ParityOdd = 1, + ParityEven = 2, + ParityForced1 = 3, + ParityForced0 = 4 +} SerialParity; + +typedef enum { + RxIrq, + TxIrq +} SerialIrq; + +typedef enum { + FlowControlNone, + FlowControlRTS, + FlowControlCTS, + FlowControlRTSCTS +} FlowControl; + +typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event); + +typedef struct serial_s serial_t; + +void serial_init (serial_t *obj, PinName tx, PinName rx); +void serial_free (serial_t *obj); +void serial_baud (serial_t *obj, int baudrate); +void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits); + +void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id); +void serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable); + +int serial_getc (serial_t *obj); +void serial_putc (serial_t *obj, int c); +int serial_readable (serial_t *obj); +int serial_writable (serial_t *obj); +void serial_clear (serial_t *obj); + +void serial_break_set (serial_t *obj); +void serial_break_clear(serial_t *obj); + +void serial_pinout_tx(PinName tx); + +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/include/hal/sleep_api.h b/include/hal/sleep_api.h new file mode 100644 index 0000000..0e81985 --- /dev/null +++ b/include/hal/sleep_api.h @@ -0,0 +1,64 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SLEEP_API_H +#define SLEEP_API_H + +#include "device.h" + +#if DEVICE_SLEEP + +#ifdef __cplusplus +extern "C" { +#endif + +/** Send the microcontroller to sleep + * + * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the + * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates + * dynamic power used by the processor, memory systems and buses. The processor, peripheral and + * memory state are maintained, and the peripherals continue to work and can generate interrupts. + * + * The processor can be woken up by any internal peripheral interrupt or external pin interrupt. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void sleep(void); + +/** Send the microcontroller to deep sleep + * + * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode + * has the same sleep features as sleep plus it powers down peripherals and clocks. All state + * is still maintained. + * + * The processor can only be woken up by an external interrupt on a pin or a watchdog timer. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void deepsleep(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/include/hal/spi_api.h b/include/hal/spi_api.h new file mode 100644 index 0000000..7bf7f43 --- /dev/null +++ b/include/hal/spi_api.h @@ -0,0 +1,45 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SPI_API_H +#define SPI_API_H + +#include "device.h" + +#if DEVICE_SPI + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct spi_s spi_t; + +void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel); +void spi_free (spi_t *obj); +void spi_format (spi_t *obj, int bits, int mode, int slave); +void spi_frequency (spi_t *obj, int hz); +int spi_master_write (spi_t *obj, int value); +int spi_slave_receive(spi_t *obj); +int spi_slave_read (spi_t *obj); +void spi_slave_write (spi_t *obj, int value); +int spi_busy (spi_t *obj); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/include/hal/us_ticker_api.h b/include/hal/us_ticker_api.h new file mode 100644 index 0000000..8754101 --- /dev/null +++ b/include/hal/us_ticker_api.h @@ -0,0 +1,40 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef US_TICKER_API_H +#define US_TICKER_API_H + +#include "device.h" + +#if DEVICE_SPI + +#ifdef __cplusplus +extern "C" { +#endif + +void us_ticker_init(void); +uint32_t us_ticker_read(void); +void us_ticker_set_interrupt(timestamp_t timestamp); +void us_ticker_disable_interrupt(void); +void us_ticker_clear_interrupt(void); + +#ifdef __cplusplus + +} +#endif + +#endif + +#endif diff --git a/targets/TARGET_LPC54102/PinNames.h b/targets/TARGET_LPC54102/PinNames.h new file mode 100644 index 0000000..6feb781 --- /dev/null +++ b/targets/TARGET_LPC54102/PinNames.h @@ -0,0 +1,147 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef PINNAMES_H +#define PINNAMES_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// MODE (see GPIOMode_TypeDef structure) +// AFNUM (see AF_mapping constant table) +#define ENCODE_PIN_DATA(MODE, AFNUM) (((MODE) << 8) | (AFNUM)) +#define DECODE_PIN_MODE(X) ((X) >> 8) +#define DECODE_PIN_AFNUM(X) ((X) & 0xFF) + +// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H) +// Low nibble = pin number +#define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) +#define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) +#define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +typedef enum { + Pin_0 = 0x00, + Pin_1 = 0x01, + Pin_2 = 0x02, + Pin_3 = 0x03, + Pin_4 = 0x04, + Pin_5 = 0x05, + Pin_6 = 0x06, + Pin_7 = 0x07, + Pin_8 = 0x08, + Pin_9 = 0x09, + Pin_10 = 0x0A, + Pin_11 = 0x0B, + Pin_12 = 0x0C, + Pin_13 = 0x0D, + Pin_14 = 0x0E, + Pin_15 = 0x0F, + Pin_16 = 0x10, + Pin_17 = 0x11, + Pin_18 = 0x12, + Pin_19 = 0x13, + Pin_20 = 0x14, + Pin_21 = 0x15, + Pin_22 = 0x16, + Pin_23 = 0x17, + Pin_24 = 0x18, + Pin_25 = 0x19, + Pin_26 = 0x1A, + Pin_27 = 0x1B, + Pin_28 = 0x1C, + Pin_29 = 0x1D, + Pin_30 = 0x1E, + Pin_31 = 0x1F, + Pin_All= 0xFFFF +} PinNumber; + +typedef enum { + Port_0 = 0x00, + Port_1 = 0x01, + Port_2 = 0x02, + Port_3 = 0x03, + Port_4 = 0x04, + Port_5 = 0x05, + Port_6 = 0x06, + Port_7 = 0x07, + Port_All= 0xFFFF +} PortNumber; + +#define NC (int)0xFFFFFFFF +typedef int32_t PinName; + +/** + * PIN function and mode selection definitions + * Might need to be changed while porting to different platform + */ +typedef int32_t PinMode; + +typedef enum { + PINMAP_FUNC0 = 0x0, /*!< Selects pin function 0 */ + PINMAP_FUNC1 = 0x1, /*!< Selects pin function 1 */ + PINMAP_FUNC2 = 0x2, /*!< Selects pin function 2 */ + PINMAP_FUNC3 = 0x3, /*!< Selects pin function 3 */ + PINMAP_FUNC4 = 0x4, /*!< Selects pin function 4 */ + PINMAP_FUNC5 = 0x5, /*!< Selects pin function 5 */ + PINMAP_FUNC6 = 0x6, /*!< Selects pin function 6 */ + PINMAP_FUNC7 = 0x7 /*!< Selects pin function 7 */ +} PINMAP_FUNC; + +typedef enum{ + PINMAP_MODE_INACT = (0x0 << 3), /*!< No addition pin function */ + PINMAP_MODE_PULLDOWN = (0x1 << 3), /*!< Selects pull-down function */ + PINMAP_MODE_PULLUP = (0x2 << 3), /*!< Selects pull-up function */ + PINMAP_MODE_REPEATER = (0x3 << 3) /*!< Selects pin repeater function */ +} PINMAP_MODE; + +#define PINMAP_HYS_EN (0x1 << 5) /*!< Enables hysteresis */ +#define PINMAP_GPIO_MODE (0x1 << 5) /*!< GPIO Mode */ +#define PINMAP_I2C_SLEW (0x1 << 5) /*!< I2C Slew Rate Control */ +#define PINMAP_INV_EN (0x1 << 6) /*!< Enables invert function on input */ +#define PINMAP_ANALOG_EN (0x0 << 7) /*!< Enables analog function by setting 0 to bit 7 */ +#define PINMAP_DIGITAL_EN (0x1 << 7) /*!< Enables digital function by setting 1 to bit 7(default) */ +#define PINMAP_STDI2C_EN (0x1 << 8) /*!< I2C standard mode/fast-mode */ +#define PINMAP_FASTI2C_EN (0x3 << 8) /*!< I2C Fast-mode Plus and high-speed slave */ +#define PINMAP_INPFILT_OFF (0x1 << 8) /*!< Input filter Off for GPIO pins */ +#define PINMAP_INPFILT_ON (0x0 << 8) /*!< Input filter On for GPIO pins */ +#define PINMAP_OPENDRAIN_EN (0x1 << 10) /*!< Enables open-drain function */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_LPC54102/PortNames.h b/targets/TARGET_LPC54102/PortNames.h new file mode 100644 index 0000000..27b668f --- /dev/null +++ b/targets/TARGET_LPC54102/PortNames.h @@ -0,0 +1,48 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef PORTNAMES_H +#define PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PortA = 0, + PortB = 1, + PortC = 2, + PortD = 3, + PortE = 4 +} PortName; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/targets/TARGET_LPC54102/device.h b/targets/TARGET_LPC54102/device.h new file mode 100644 index 0000000..7396349 --- /dev/null +++ b/targets/TARGET_LPC54102/device.h @@ -0,0 +1,71 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef DEVICE_H +#define DEVICE_H + +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 + +#define DEVICE_INTERRUPTIN 1 + +#define DEVICE_ANALOGIN 1 +#define DEVICE_ANALOGOUT 0 + +#define DEVICE_SERIAL 1 + +#define DEVICE_I2C 1 +#define DEVICE_I2CSLAVE 0 + +#define DEVICE_SPI 1 +#define DEVICE_SPISLAVE 0 + +#define DEVICE_RTC 1 + +#define DEVICE_PWMOUT 1 + +#define DEVICE_SLEEP 1 + +#define DEVICE_ERROR_PATTERN 1 //fast blink green and blue leds on error +//======================================= + +#define DEVICE_SEMIHOST 0 +#define DEVICE_LOCALFILESYSTEM 0 +#define DEVICE_ID_LENGTH 24 + +#define DEVICE_DEBUG_AWARENESS 0 + +#define DEVICE_STDIO_MESSAGES 1 + +//#define DEVICE_ERROR_RED 0 + +#include "objects.h" + +#endif diff --git a/targets/TARGET_LPC54102/gpio_api.c b/targets/TARGET_LPC54102/gpio_api.c new file mode 100644 index 0000000..9590f68 --- /dev/null +++ b/targets/TARGET_LPC54102/gpio_api.c @@ -0,0 +1,61 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +/* #include "mbed_assert.h" */ +#include "gpio_api.h" +#include "pinmap.h" +#include "Gpio_object.h" + +extern uint32_t Set_GPIO_Clock(uint32_t port_idx); + +uint32_t gpio_set(PinName pin) { +/* ASF_assert(pin != (PinName)NC); + + pin_function(pin, ENCODE_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask +*/ return 0; +} + +void gpio_init(gpio_t __attribute__((unused)) *obj, PinName __attribute__((unused)) pin) { + Chip_PININT_Init(LPC_PININT); +} + +void gpio_mode(gpio_t *obj, PinMode mode) { + //pin_mode(obj->pin, mode); +} + +void gpio_dir(gpio_t *obj, PinDirection direction) { + ASF_assert(obj->pin != (PinName)NC); + if (direction == PIN_OUTPUT) { + Chip_GPIO_SetPinDIROutput(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin)); + } + else { // PIN_INPUT + Chip_GPIO_SetPinDIRInput(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin)); + } +} diff --git a/targets/TARGET_LPC54102/gpio_irq_api.c b/targets/TARGET_LPC54102/gpio_irq_api.c new file mode 100644 index 0000000..e3ceebd --- /dev/null +++ b/targets/TARGET_LPC54102/gpio_irq_api.c @@ -0,0 +1,216 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#include +#include "common.h" + +#include "gpio_irq_api.h" +#include "pinmap.h" + +#define EDGE_NONE (0) +#define EDGE_RISE (1) +#define EDGE_FALL (2) +#define EDGE_BOTH (3) + +#define CHANNEL_NUM (16) + +#if 0 +static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +static gpio_irq_handler irq_handler; + +typedef struct { + EXTITrigger_TypeDef EXTI_Trigger; + uint8_t NVIC_IRQChannel; + uint8_t NVIC_IRQChannelPreemptionPriority; + uint8_t NVIC_IRQChannelSubPriority; +}Gpio_irq_init_t; + +static Gpio_irq_init_t tGpio_irq_init[EXTI_MAX_ID] = { + //EXTI_Trigger ,NVIC_IRQChannel ,NVIC_IRQChannelPreemptionPriority, NVIC_IRQChannelSubPriority + {EXTI_Trigger_Rising ,ACCEL_INT_IRQChannel,ACCEL_A_INT_PREEMPT_PRIO ,ACCEL_A_INT_SUB_PRIORITY }, //Accel + {EXTI_Trigger_Rising ,GYRO_RDY_IRQCHANNEL ,GYRO_DRDY_INT_PREEMPT_PRIORITY,GYRO_DRDY_INT_SUB_PRIORITY }, //Gyro + {EXTI_Trigger_Falling,MAG_RDY_IRQCHANNEL ,MAG_DRDY_INT_PREEMPT_PRIORITY ,MAG_DRDY_INT_SUB_PRIORITY } //Mag +}; +#endif + +static void __attribute__((unused)) handle_interrupt_in(uint32_t irq_index) { +#if 0 + //if irq_index==5 loop exti 5 to 9 + //if irq_index==10 loop exti 10 to 15 + //else exti loop one irq_index + uint32_t to_irq_index=(irq_index==5)?9:((irq_index==10)?15:irq_index); + GPIO_TypeDef *gpio; + uint32_t pin; + do{ + // Retrieve the gpio and pin that generate the irq + gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]); + pin = (uint32_t)(1 << channel_pin[irq_index]); + // Clear interrupt flag + if (EXTI_GetITStatus(pin) != RESET) + { + EXTI_ClearITPendingBit(pin); + if (channel_ids[irq_index] == 0) return; + // Check which edge has generated the irq + if ((gpio->IDR & pin) == 0) { + irq_handler(channel_ids[irq_index], IRQ_FALL); + } else { + irq_handler(channel_ids[irq_index], IRQ_RISE); + } + } + }while(irq_index++ < to_irq_index); +#endif +} + +// The irq_index is passed to the function +//static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0 +//static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1 +//static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2 +//static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3 +//static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4 +//static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9 +//static void gpio_irq6(void) {handle_interrupt_in(10);} // EXTI lines 10 to 15 + +int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { + +#if 0 + uint32_t port_index = DECODE_PORT(pin); + uint32_t pin_index = DECODE_PIN(pin); + + if (pin == NC) return -1; + + // Connect EXTI line to pin + GPIO_EXTILineConfig(port_index, pin_index); + + EXTI_ClearFlag(MAG_RDY_INT_EXTI_LINE); + + // Configure EXTI line + EXTI_InitTypeDef EXTI_InitStructure; + EXTI_InitStructure.EXTI_Line = (uint32_t)(1 << pin_index); + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = tGpio_irq_init[id].EXTI_Trigger; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_Init(&EXTI_InitStructure); + + // Enable and set EXTI interrupt to the lowest priority + NVIC_InitTypeDef NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = tGpio_irq_init[id].NVIC_IRQChannel; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = tGpio_irq_init[id].NVIC_IRQChannelPreemptionPriority; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = tGpio_irq_init[id].NVIC_IRQChannelSubPriority; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +#endif + return 0; +} + +void gpio_irq_free(gpio_irq_t *obj) { +#if 0 + channel_ids[obj->irq_index] = 0; + channel_gpio[obj->irq_index] = 0; + channel_pin[obj->irq_index] = 0; + // Disable EXTI line + EXTI_InitTypeDef EXTI_InitStructure; + EXTI_StructInit(&EXTI_InitStructure); + EXTI_Init(&EXTI_InitStructure); + obj->event = EDGE_NONE; +#endif +} + +void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { +#if 0 + EXTI_InitTypeDef EXTI_InitStructure; + + uint32_t pin_index = channel_pin[obj->irq_index]; + + EXTI_InitStructure.EXTI_Line = (uint32_t)(1 << pin_index); + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + + if (event == IRQ_RISE) { + if ((obj->event == EDGE_FALL) || (obj->event == EDGE_BOTH)) { + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; + obj->event = EDGE_BOTH; + } + else { // NONE or RISE + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + obj->event = EDGE_RISE; + } + } + + if (event == IRQ_FALL) { + if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) { + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; + obj->event = EDGE_BOTH; + } + else { // NONE or FALL + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; + obj->event = EDGE_FALL; + } + } + + if (enable) { + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + } + else { + EXTI_InitStructure.EXTI_LineCmd = DISABLE; + } + + EXTI_Init(&EXTI_InitStructure); +#endif +} + +void gpio_irq_enable(gpio_irq_t *obj) { + switch(obj->event){ + case IRQ_EDGE_RISE: + Chip_PININT_SetPinModeEdge(LPC_PININT, obj->irq_index); /* edge sensitive */ + Chip_PININT_EnableIntHigh(LPC_PININT, obj->irq_index); /* Rising edge interrupt */ + break; + case IRQ_EDGE_FALL: + Chip_PININT_SetPinModeEdge(LPC_PININT, obj->irq_index); /* Edge sensitive */ + Chip_PININT_EnableIntLow(LPC_PININT, obj->irq_index); /* Falling edge interrupt */ + break; + case IRQ_LEVEL_HIGH: + Chip_PININT_SetPinModeLevel(LPC_PININT, obj->irq_index); /* Level sensitive */ + Chip_PININT_EnableIntHigh(LPC_PININT, obj->irq_index); /* High level interrupt */ + break; + case IRQ_LEVEL_LOW: + Chip_PININT_SetPinModeLevel(LPC_PININT, obj->irq_index); /* Level sensitive */ + Chip_PININT_EnableIntLow(LPC_PININT, obj->irq_index); /* Low level interrupt */ + break; + default: + D1_printf("GPIO_IRQ_ENABLE: Bad IRQ Mode: %d\r\n", obj->irq_index); + while(1){}; + } +} + +void gpio_irq_disable(gpio_irq_t *obj) { + Chip_PININT_ClearIntStatus(LPC_PININT, obj->irq_index); +} diff --git a/targets/TARGET_LPC54102/gpio_object.h b/targets/TARGET_LPC54102/gpio_object.h new file mode 100644 index 0000000..2b0be15 --- /dev/null +++ b/targets/TARGET_LPC54102/gpio_object.h @@ -0,0 +1,70 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef GPIO_OBJECT_H +#define GPIO_OBJECT_H + +/* #include "mbed_assert.h" */ +#include "common.h" +#include "PortNames.h" +//#include "PeripheralNames.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + uint32_t mask; + __IO uint32_t *reg_in; + __IO uint32_t *reg_set; + __IO uint32_t *reg_clr; +} gpio_t; + +static __inline void gpio_write(gpio_t *obj, int value) { + ASF_assert(obj->pin != (PinName)NC); + Chip_GPIO_SetPinState(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin), (bool)value); +} + +static __inline int gpio_read(gpio_t *obj) { + ASF_assert(obj->pin != (PinName)NC); + return (Chip_GPIO_GetPinState(LPC_GPIO, DECODE_PORT(obj->pin), DECODE_PIN(obj->pin))); +} + +static __inline int gpio_is_connected(const gpio_t *obj) { + //return obj->pin != (PinName)NC; + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_LPC54102/objects.h b/targets/TARGET_LPC54102/objects.h new file mode 100644 index 0000000..c357bc9 --- /dev/null +++ b/targets/TARGET_LPC54102/objects.h @@ -0,0 +1,98 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +#ifndef OBJECTS_H +#define OBJECTS_H + +#include "common.h" +#include "PortNames.h" +//#include "PeripheralNames.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_irq_s { + IRQn_Type irq_n; + uint32_t irq_index; + uint32_t event; +}; + +struct port_s { + PortName port; + uint32_t mask; + PinDirection direction; + __IO uint32_t *reg_in; + __IO uint32_t *reg_out; +}; + +struct analogin_s { +// ADCName adc; + PinName pin; +}; + +struct serial_s { +// UARTName uart; + int index; // Used by irq + uint32_t baudrate; + uint32_t databits; + uint32_t stopbits; + uint32_t parity; +}; + +struct spi_s { +// SPIName spi; + uint32_t bits; + uint32_t cpol; + uint32_t cpha; + uint32_t mode; + uint32_t nss; + uint32_t br_presc; +}; + +struct i2c_s { +// I2CName i2c; + uint32_t i2c; //TBD: DUMMY - Please remove +}; + +struct pwmout_s { +// PWMName pwm; + PinName pin; + uint32_t period; + uint32_t pulse; +}; + +#include "gpio_object.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/targets/TARGET_LPC54102/pinmap.c b/targets/TARGET_LPC54102/pinmap.c new file mode 100644 index 0000000..cefd316 --- /dev/null +++ b/targets/TARGET_LPC54102/pinmap.c @@ -0,0 +1,145 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ +/* #include "mbed_assert.h" */ +#include "device.h" +#include "pinmap.h" + +// Alternate-function mapping +#if 0 +static const uint32_t AF_mapping[] = { + 0, // 0 = No AF + GPIO_Remap_SPI1, // 1 + GPIO_Remap_I2C1, // 2 + GPIO_Remap_USART1, // 3 + GPIO_Remap_USART2, // 4 + GPIO_FullRemap_TIM2, // 5 + GPIO_FullRemap_TIM3, // 6 + GPIO_PartialRemap_TIM3, // 7 + GPIO_Remap_I2C1 // 8 +}; +#endif + +// Enable GPIO clock and return GPIO base address +uint32_t Set_GPIO_Clock(uint32_t port_idx) { +#if 0 + uint32_t gpio_add = 0; + switch (port_idx) { + case PortA: + gpio_add = GPIOA_BASE; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + break; + case PortB: + gpio_add = GPIOB_BASE; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + break; + case PortC: + gpio_add = GPIOC_BASE; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); + break; + case PortD: + gpio_add = GPIOD_BASE; + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); + break; + default: + D1_printf("Port number is not correct."); + break; + } + return gpio_add; +#endif + return 0; +} + +/** + * Configure pin (input, output, alternate function or analog) + output speed + AF + */ +void pin_function(PinName pin, uint32_t data) { + + uint32_t port_index = DECODE_PORT(pin); + uint32_t pin_index = DECODE_PIN(pin); + + ASF_assert(pin != (PinName)NC); + + // Configure GPIO + Chip_IOCON_PinMuxSet(LPC_IOCON, port_index, pin_index, data); +} + +/** + * Configure pin pull-up/pull-down + */ +void pin_mode(PinName pin, PinMode mode) { +#if 0 + ASF_assert(pin != (PinName)NC); + GPIO_InitTypeDef GPIO_InitStructure; + + uint32_t port_index = STM_PORT(pin); + uint32_t pin_index = STM_PIN(pin); + + // Enable GPIO clock + uint32_t gpio_add = Set_GPIO_Clock(port_index); + GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; + + // Configure open-drain and pull-up/down + switch (mode) { + case AnalogInput: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + break; + case Floating: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + break; + case PullUp: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + break; + case PullDown: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; + break; + case OpenDrain: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + break; + case PushPullOutput: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + break; + case OpenDrainOutputAF: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; + break; + case PushPullOutputAF: + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + break; + default: + D1_printf("PINMAP: Bad GPIO Mode: %d\r\n", mode); + break; + } + + // Configure GPIO + GPIO_InitStructure.GPIO_Pin = (uint16_t)pin_index; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(gpio, &GPIO_InitStructure); +#endif +} +