From 22abd06132445a55a1a0266897920f26634825c1 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:38:10 +0100 Subject: digital/beacon: remove obsolete bitcloud stack --- .../Components/BSP/MESHBEAN/src/battery.c | 168 -------- .../Components/BSP/MESHBEAN/src/bspTaskManager.c | 121 ------ .../Components/BSP/MESHBEAN/src/buttons.c | 239 ----------- .../Components/BSP/MESHBEAN/src/fakeBSP.c | 359 ---------------- .../Components/BSP/MESHBEAN/src/leds.c | 139 ------- .../Components/BSP/MESHBEAN/src/lm73.c | 184 --------- .../Components/BSP/MESHBEAN/src/pwrCtrl.c | 91 ---- .../Components/BSP/MESHBEAN/src/sensors.c | 196 --------- .../Components/BSP/MESHBEAN/src/sliders.c | 59 --- .../Components/BSP/MESHBEAN/src/tsl2550.c | 457 --------------------- 10 files changed, 2013 deletions(-) delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/battery.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/bspTaskManager.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/buttons.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/fakeBSP.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/leds.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/lm73.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/pwrCtrl.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sensors.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sliders.c delete mode 100644 digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/tsl2550.c (limited to 'digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src') diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/battery.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/battery.c deleted file mode 100644 index 63facdb3..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/battery.c +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************//** -\file battery.c - -\brief This module is used for measurment battery voltage. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/06/07 E. Ivanov - Created -******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include -#include - -#if BSP_MNZB_EVB_SUPPORT == 1 - -/****************************************************************************** - Define(s) section -******************************************************************************/ -#define BATTERY_AMOUNT_DISPERSION 2 -#define MAX_AMOUNT_COUNTER 20 - -/****************************************************************************** - Types section -******************************************************************************/ -// battery states -typedef enum -{ - IDLE, // idle - BUSY, // opened and ready to be used - DATA // performs request -} batteryStates_t; - -// battery descriptor -typedef struct -{ - uint8_t batteryData; - BspBatteryCb_t batteryCallback; // callback -} BatteryControl_t; - -/****************************************************************************** - Global variables section -******************************************************************************/ -// Monitors current state -static batteryStates_t batteryState = IDLE; -static BatteryControl_t batteryControl; -static HAL_AdcParams_t adcParam; -static uint8_t batExpectation; -static uint8_t batAmountCnt; - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Callback about ADC request was completed. -\param[in] - data - result of ADC. -******************************************************************************/ -void batteryCallback(void) -{ - batAmountCnt++; - if ((batteryControl.batteryData > (batExpectation + BATTERY_AMOUNT_DISPERSION)) || - (batteryControl.batteryData < (batExpectation - BATTERY_AMOUNT_DISPERSION))) - { - batExpectation = batteryControl.batteryData; - batAmountCnt = 0; - } - - if (MAX_AMOUNT_COUNTER == batAmountCnt) - { - batAmountCnt = 0; - batExpectation = 0; - bspPostTask(BSP_BATTERY); - return; - } - - batteryState = BUSY; - readBatteryData(batteryControl.batteryCallback); -} - -/**************************************************************************//** -\brief Opens the component to use. -\return - BC_SUCCESS - the component is ready to been use. \n - BC_FAIL - otherwise. -******************************************************************************/ -result_t openBattery(void) -{ - if (IDLE == batteryState) - { - adcParam.bufferPointer = &(batteryControl.batteryData); - adcParam.callback = batteryCallback; - adcParam.resolution = RESOLUTION_8_BIT; - adcParam.sampleRate = ADC_4800SPS; - adcParam.selectionsAmount = 1; - adcParam.voltageReference = AREF; - batteryState = BUSY; - HAL_OpenAdc(&adcParam); - return BC_SUCCESS; - } - return BC_FAIL; -} - -/**************************************************************************//** -\brief Closes component. -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t closeBattery(void) -{ - if (IDLE == batteryState) - return BC_FAIL; - batteryState = IDLE; - HAL_CloseAdc(); - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Starts ADC request on battery channel. -\param[in] - data - sensor data. -\return - BC_FAIL - battery component was not opened. \n - BC_SUCCESS - other case. -******************************************************************************/ -result_t readBatteryData(BspBatteryCb_t cb) -{ - if (BUSY != batteryState) - return BC_FAIL; - batteryState = DATA; - batteryControl.batteryCallback = cb; - HAL_ReadAdc(HAL_ADC_CHANNEL0); - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP battery handler. -******************************************************************************/ -void bspBatteryHandler(void) -{ - int16_t value; - - // 1250 - 1.25 V reference voltage expressed in mV (1250 mV) - // 3 - battery voltage is divided by 3 on the MeshBean board - // 256 - steps for 8 bit ADC - // Resulting value is a true battery voltage expressed in mV - value = (batteryControl.batteryData * 1250ul * 3ul) / 256ul; - - batteryState = BUSY; - batteryControl.batteryCallback(value); -} -#endif /* BSP_MNZB_EVB_SUPPORT */ - -#endif // APP_DISABLE_BSP != 1 - -// eof battery.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/bspTaskManager.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/bspTaskManager.c deleted file mode 100644 index d63f62da..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/bspTaskManager.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************//** -\file bspTaskManager.c - -\brief Implemenattion of BSP task manager. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/05/07 E. Ivanov - Created -******************************************************************************/ -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include - -/****************************************************************************** - Prototypes section -******************************************************************************/ -/**************************************************************************//** -\brief BSP button handler. -******************************************************************************/ -void bspButtonsHandler(void); - -/**************************************************************************//** -\brief BSP lm73 handler. -******************************************************************************/ -void bspLM73Handler(void); -void bspTemperatureSensorHandler(void); - -/**************************************************************************//** -\brief BSP tsl2550 handler. -******************************************************************************/ -void bspTsl2550Handler(void); -void bspLightSensorHandler(void); - -/**************************************************************************//** -\brief BSP battery handler. -******************************************************************************/ -void bspBatteryHandler(void); -void bspEmptyBatteryHandler(void); - -/****************************************************************************** - Global variables section -******************************************************************************/ -volatile uint8_t bspTaskFlags = 0; - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief BSP task handler. -******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -void BSP_TaskHandler(void) -{ - if (bspTaskFlags & BSP_BUTTONS) - { - bspTaskFlags &= (~BSP_BUTTONS); - bspButtonsHandler(); - } - if (bspTaskFlags & BSP_TEMPERATURE) - { - bspTaskFlags &= (~BSP_TEMPERATURE); - bspLM73Handler(); - } - if (bspTaskFlags & BSP_LIGHT) - { - bspTaskFlags &= (~BSP_LIGHT); - bspTsl2550Handler(); - } - if (bspTaskFlags & BSP_BATTERY) - { - bspTaskFlags &= (~BSP_BATTERY); -#if BSP_MNZB_EVB_SUPPORT == 1 - bspBatteryHandler(); -#else - bspEmptyBatteryHandler(); -#endif // BSP_MNZB_EVB_SUPPORT == 1 - } - if (bspTaskFlags) - { - SYS_PostTask(BSP_TASK_ID); - } -} - -#else // APP_DISABLE_BSP != 1 - -void BSP_TaskHandler(void) -{ - if (bspTaskFlags & BSP_TEMPERATURE) - { - bspTaskFlags &= (~BSP_TEMPERATURE); - bspTemperatureSensorHandler(); - } - if (bspTaskFlags & BSP_LIGHT) - { - bspTaskFlags &= (~BSP_LIGHT); - bspLightSensorHandler(); - } - if (bspTaskFlags & BSP_BATTERY) - { - bspTaskFlags &= (~BSP_BATTERY); - bspEmptyBatteryHandler(); - } - if (bspTaskFlags) - { - SYS_PostTask(BSP_TASK_ID); - } -} - -#endif // APP_DISABLE_BSP != 1 - -// eof bspTaskManager.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/buttons.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/buttons.c deleted file mode 100644 index 8867a82b..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/buttons.c +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************//** -\file buttons.c - -\brief Implementation of buttons interface. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 30/05/08 A. Khromykh - Created -*******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include -#include -#include -#include - -/****************************************************************************** - Define(s) section -******************************************************************************/ -#define BSP_readKEY0() GPIO_IRQ_6_read() -#define BSP_readKEY1() GPIO_IRQ_7_read() -#define PRESSED 1 -#define RELEASED 0 -#define BSP_BUTTONS_IDLE 0 -#define BSP_BUTTONS_BUSY 1 - -/****************************************************************************** - Types section -******************************************************************************/ -typedef struct -{ - uint8_t currentState0 : 1; - uint8_t currentState1 : 1; - uint8_t wasPressed0 : 1; - uint8_t wasPressed1 : 1; - uint8_t waitReleased0 : 1; - uint8_t waitReleased1 : 1; -} BSP_buttonsAction_t; - -/****************************************************************************** - Prototypes section -******************************************************************************/ -/**************************************************************************//** -\brief HAL's event handlers about KEY 0 has changed state. -******************************************************************************/ -void bspKey0InterruptHandler(void); - -/**************************************************************************//** -\brief HAL's event handlers about KEY 1 has changed state. -******************************************************************************/ -void bspKey1InterruptHandler(void); - -/****************************************************************************** - Global variables section -******************************************************************************/ -static uint8_t state = BSP_BUTTONS_IDLE; -static volatile BSP_buttonsAction_t buttonsAction; -static BSP_ButtonsEventFunc_t bspButtonPressHandle; // callback -static BSP_ButtonsEventFunc_t bspButtonReleaseHandle; // callback - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Initializes buttons module. -******************************************************************************/ -static void bspInitButtons(void) -{ - HAL_RegisterIrq(IRQ_6, IRQ_LOW_LEVEL, bspKey0InterruptHandler); - HAL_RegisterIrq(IRQ_7, IRQ_LOW_LEVEL, bspKey1InterruptHandler); - - if (BSP_readKEY0()) - buttonsAction.currentState0 = RELEASED; - else - buttonsAction.currentState0 = PRESSED; - - if (BSP_readKEY1()) - buttonsAction.currentState1 = RELEASED; - else - buttonsAction.currentState1 = PRESSED; - - HAL_EnableIrq(IRQ_6); - HAL_EnableIrq(IRQ_7); -} - -/**************************************************************************//** -\brief Registers handlers for button events. - -\param[in] - pressed - the handler to process pressing the button -\param[in] - released - the handler to process releasing the button -\param[in] - bn - button number. -\return - BC_FAIL - buttons module is busy, \n - BC_SUCCESS in other case. -******************************************************************************/ -result_t BSP_OpenButtons(void (*pressed)(uint8_t bn), void (*released)(uint8_t bn)) -{ - if (state != BSP_BUTTONS_IDLE) - return BC_FAIL; - state = BSP_BUTTONS_BUSY; - bspButtonPressHandle = pressed; - bspButtonReleaseHandle = released; - bspInitButtons(); - return BC_SUCCESS; -}; - -/**************************************************************************//** -\brief Cancel buttons handlers. -\return - BC_FAIL - buttons module was not opened, \n - BC_SUCCESS in other case. -******************************************************************************/ -result_t BSP_CloseButtons(void) -{ - if (state != BSP_BUTTONS_BUSY) - return BC_FAIL; - HAL_UnregisterIrq(IRQ_6); - HAL_UnregisterIrq(IRQ_7); - bspButtonPressHandle = NULL; - bspButtonReleaseHandle = NULL; - state = BSP_BUTTONS_IDLE; - return BC_SUCCESS; -}; - -/**************************************************************************//** -\brief Reads state of buttons. - -\return - Current buttons state in a binary way. \n - Bit 0 defines state of the button 1, \n - bit 1 defines state of the button 2. -******************************************************************************/ -uint8_t BSP_ReadButtonsState(void) -{ - uint8_t state = 0; - - if (buttonsAction.currentState0) - state = 0x01; - - if (buttonsAction.currentState1) - state |= 0x02; - - return state; -} - -/**************************************************************************//** -\brief HAL's event about KEY has changed state. -******************************************************************************/ -void bspKey0InterruptHandler(void) -{ - HAL_DisableIrq(IRQ_6); - buttonsAction.currentState0 = PRESSED; - buttonsAction.wasPressed0 = 1; - bspPostTask(BSP_BUTTONS); -} - -/**************************************************************************//** -\brief HAL's event about KEY has changed state. -******************************************************************************/ -void bspKey1InterruptHandler(void) -{ - HAL_DisableIrq(IRQ_7); - buttonsAction.currentState1 = PRESSED; - buttonsAction.wasPressed1 = 1; - bspPostTask(BSP_BUTTONS); -} - -/**************************************************************************//** -\brief BSP's event about KEY has changed state. -******************************************************************************/ -void bspButtonsHandler(void) -{ - if (buttonsAction.wasPressed0) - { - buttonsAction.wasPressed0 = 0; - buttonsAction.waitReleased0 = 1; - if (NULL != bspButtonPressHandle) - bspButtonPressHandle(BSP_KEY0); - } - - if (buttonsAction.waitReleased0) - { - if (BSP_readKEY0()) - { - buttonsAction.waitReleased0 = 0; - buttonsAction.currentState0 = RELEASED; - if (NULL != bspButtonReleaseHandle) - bspButtonReleaseHandle(BSP_KEY0); - HAL_EnableIrq(IRQ_6); - } - else - { - bspPostTask(BSP_BUTTONS); - } - } - - if (buttonsAction.wasPressed1) - { - buttonsAction.wasPressed1 = 0; - buttonsAction.waitReleased1 = 1; - if (NULL != bspButtonPressHandle) - bspButtonPressHandle(BSP_KEY1); - } - - if (buttonsAction.waitReleased1) - { - if (BSP_readKEY1()) - { - buttonsAction.waitReleased1 = 0; - buttonsAction.currentState1 = RELEASED; - if (NULL != bspButtonReleaseHandle) - bspButtonReleaseHandle(BSP_KEY1); - HAL_EnableIrq(IRQ_7); - } - else - { - bspPostTask(BSP_BUTTONS); - } - } -} - -#endif // APP_DISABLE_BSP != 1 - -// end of buttons.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/fakeBSP.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/fakeBSP.c deleted file mode 100644 index 77aa9c51..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/fakeBSP.c +++ /dev/null @@ -1,359 +0,0 @@ -/***************************************************************************//** -\file fakeBSP.c - -\brief Implementation of fake board-specific periphery. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 28/04/11 A. Malkin - Created -*******************************************************************************/ - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include - -/****************************************************************************** - Global variables section -******************************************************************************/ -#if (APP_DISABLE_BSP == 1) || (BSP_MNZB_EVB_SUPPORT != 1) -void(* readBatteryDataCallback)(int16_t data); -#endif //(APP_DISABLE_BSP == 1) || (BSP_MNZB_EVB_SUPPORT != 1) -#if APP_DISABLE_BSP == 1 -void(* readTemperatureDataCallback)(bool error, int16_t data); -void(* readLightDataCallback)(bool error, int16_t data); - -/****************************************************************************** - Implementations section -******************************************************************************/ -/****************************************************************************** - Buttons -******************************************************************************/ -/**************************************************************************//** -\brief Registers handlers for button events. - -\param[in] - pressed - the handler to process pressing the button -\param[in] - released - the handler to process releasing the button -\param[in] - bn - button number. - -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t BSP_OpenButtons(void (*pressed)(uint8_t bn), void (*released)(uint8_t bn)) -{ - (void)pressed; - (void)released; - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Cancel buttons handlers. - -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t BSP_CloseButtons(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Reads state of buttons. - -\return - Current buttons state in a binary way. \n - Bit 0 defines state of the button 1, \n - bit 1 defines state of the button 2. -******************************************************************************/ -uint8_t BSP_ReadButtonsState(void) -{ - return 0; -} - -/****************************************************************************** - Sensors -******************************************************************************/ -/***************************************************************************//** -\brief Opens temperature sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_OpenTemperatureSensor(void) -{ - return BC_SUCCESS; -} - -/***************************************************************************//** -\brief Closes the temperature sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_CloseTemperatureSensor(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Reads data from the temperature sensor. -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. - -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t BSP_ReadTemperatureData(void (*f)(bool result, int16_t data)) -{ - readTemperatureDataCallback = f; - - bspPostTask(BSP_TEMPERATURE); - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP task handler for temperature sensor. -******************************************************************************/ -void bspTemperatureSensorHandler(void) -{ - readTemperatureDataCallback(true, 0); -} - -/***************************************************************************//** -\brief Opens the light sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_OpenLightSensor(void) -{ - return BC_SUCCESS; -} - -/***************************************************************************//** -\brief Closes the light sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_CloseLightSensor(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Reads data from the light sensor. -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. - -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t BSP_ReadLightData(void (*f)(bool result, int16_t data)) -{ - readLightDataCallback = f; - - bspPostTask(BSP_LIGHT); - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP task handler for light sensor. -******************************************************************************/ -void bspLightSensorHandler(void) -{ - readLightDataCallback(true, 0); -} - -/****************************************************************************** - Leds -******************************************************************************/ -/**************************************************************************//** -\brief Opens leds module to use. - -\return - operation state -******************************************************************************/ -result_t BSP_OpenLeds(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Closes leds module. - -\return - operation state -******************************************************************************/ -result_t BSP_CloseLeds(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Turns on the LED. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_OnLed(uint8_t id) -{ - (void)id; -} - -/**************************************************************************//** -\brief Turns off the LED. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_OffLed(uint8_t id) -{ - (void)id; -} - -/**************************************************************************//** -\brief Changes the LED state to opposite. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_ToggleLed(uint8_t id) -{ - (void)id; -} - -/****************************************************************************** - Sliders -******************************************************************************/ -/**************************************************************************//** -\brief Reads the sliders. - -\return - state of 3 on-board DIP-switches.User can uses SLIDER0, SLIDER1, SLIDER2 - defines to test state. Value 1 indicates that slider is on. -******************************************************************************/ -uint8_t BSP_ReadSliders(void) -{ - return 0; -} - -#endif // APP_DISABLE_BSP == 1 - -/****************************************************************************** - Joystick -******************************************************************************/ -/****************************************************************************** -\brief Registers handler for joystick events. - -\param[in] - state - joystick state. - -\return - BC_FAIL - joystick module is busy, - BC_SUCCESS in other cases. -******************************************************************************/ -result_t BSP_OpenJoystick(void (*generalHandler)(BSP_JoystickState_t state)) -{ - (void)generalHandler; - - return BC_SUCCESS; -} - -/****************************************************************************** -\brief Cancel joystick handlers. - -\return - BC_FAIL - joystick module was not opened, - BC_SUCCESS in other cases. -******************************************************************************/ -result_t BSP_CloseJoystick(void) -{ - return BC_SUCCESS; -} - -/****************************************************************************** -\brief Reads state of joystick. - -\return - Current joystick state. -******************************************************************************/ -BSP_JoystickState_t BSP_ReadJoystickState(void) -{ - return 0; -} - -#if (APP_DISABLE_BSP == 1) || (BSP_MNZB_EVB_SUPPORT != 1) -/***************************************************************************//** -\brief Opens the battery sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_OpenBatterySensor(void) -{ - return BC_SUCCESS; -} - -/***************************************************************************//** -\brief Closes the battery sensor. - -\return - BC_SUCCESS - always. -*******************************************************************************/ -result_t BSP_CloseBatterySensor(void) -{ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Reads data from battery sensor. - -\param[in] - data - sensor data. - -\return - BC_SUCCESS - always. -******************************************************************************/ -result_t BSP_ReadBatteryData(void (*f)(int16_t data)) -{ - readBatteryDataCallback = f; - - bspPostTask(BSP_BATTERY); - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP task handler for battery sensor. -******************************************************************************/ -void bspEmptyBatteryHandler(void) -{ - readBatteryDataCallback(0); -} -#endif //(APP_DISABLE_BSP == 1) || (BSP_MNZB_EVB_SUPPORT != 1) - -// eof fakeBSP.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/leds.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/leds.c deleted file mode 100644 index d03e7154..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/leds.c +++ /dev/null @@ -1,139 +0,0 @@ -/***************************************************************************//** -\file leds.c - -\brief The module to access to the leds. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/05/07 E. Ivanov - Created -*******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Inits LEDs control module. -******************************************************************************/ -static void initLeds(void) -{ - halInitRedLed(); - halInitYellowLed(); - halInitGreenLed(); -} - -/**************************************************************************//** -\brief Opens leds module to use. - -\return - operation state -******************************************************************************/ -result_t BSP_OpenLeds(void) -{ - initLeds(); -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOnPeriphery(SENSOR_LED); -#endif /* BSP_MNZB_EVB_SUPPORT */ - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Closes leds module. - -\return - operation state -******************************************************************************/ -result_t BSP_CloseLeds(void) -{ -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOffPeriphery(SENSOR_LED); -#endif /* BSP_MNZB_EVB_SUPPORT */ - halUnInitRedLed(); - halUnInitYellowLed(); - halUnInitGreenLed(); - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief Turns on the LED. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_OnLed(uint8_t id) -{ - switch (id) - { - case LED_RED: - halOnRedLed(); - break; - case LED_GREEN: - halOnGreenLed(); - break; - case LED_YELLOW: - halOnYellowLed(); - break; - } -} - -/**************************************************************************//** -\brief Turns off the LED. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_OffLed(uint8_t id) -{ - switch (id) - { - case LED_RED: - halOffRedLed(); - break; - case LED_GREEN: - halOffGreenLed(); - break; - case LED_YELLOW: - halOffYellowLed(); - break; - } -} - -/**************************************************************************//** -\brief Changes the LED state to opposite. - -\param[in] - id - number of led -******************************************************************************/ -void BSP_ToggleLed(uint8_t id) -{ - switch (id) - { - case LED_RED: - halToggleRedLed(); - break; - case LED_GREEN: - halToggleGreenLed(); - break; - case LED_YELLOW: - halToggleYellowLed(); - break; - } -} - -#endif // APP_DISABLE_BSP != 1 - -// eof leds.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/lm73.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/lm73.c deleted file mode 100644 index bc31454f..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/lm73.c +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************//** -\file lm73.c - -\brief This module provides access to lm73 the sensor. \n - Continues conversion released only. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/05/07 E. Ivanov - Created -******************************************************************************/ -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include - -/****************************************************************************** - Define(s) section -******************************************************************************/ -// device address on i2c bus -#define LM73_DEVICE_ADDRESS (0x92 >> 1) - -// device registers internal address -#define LM73_DATA_REGISTER 0x00 -#define LM73_CONFIGURATION_REGISTER 0x01 -#define LM73_UPPER_LIMIT_REGISTER 0x02 -#define LM73_LOWER_LIMIT_REGISTER 0x03 -#define LM73_CONTROL_STATUS_REGISTER 0x04 -#define LM73_IDENTIFICATION_REGISTER 0x07 - -/****************************************************************************** - Types section -******************************************************************************/ -// states -typedef enum -{ - IDLE, // idle - DATA // performs request -} Lm73States_t; - -typedef struct -{ - int32_t lm73Data; // Contains the result of sampling - bool lm73Result; // Result of operation. true - there are no errors, false - in other case. - void(* lm73Callback)(bool error, int16_t data); // callback -} Lm73Control_t; - -/****************************************************************************** - Global variables section -******************************************************************************/ -Lm73States_t lm73State = IDLE; // Monitors current state -Lm73Control_t lm73Control; - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Opens the component to use. - -\return - BC_SUCCESS - the component is ready to been use. \n - BC_FAIL - otherwise. -******************************************************************************/ -result_t openLm73(void) -{ - if (IDLE == lm73State) - return BC_SUCCESS; - - return BC_FAIL; -} - -/**************************************************************************//** -\brief Performs the test if the component have completed request. - -\return - BC_FAIL - the previous request is not completed. \n - BC_SUCCESS - otherwise. -******************************************************************************/ -result_t closeLm73(void) -{ - if (IDLE == lm73State) - return BC_SUCCESS; - - return BC_FAIL; -} - -/**************************************************************************//** -\brief The notice on that the packet has been read. - -\param[in] - result - the result of operation -******************************************************************************/ -void lm73I2cPacketReadDone(bool result) -{ - int16_t i; - - lm73Control.lm73Result = result; // stores the result of operation - if (false == lm73Control.lm73Result) - { // there were some errors on the i2c interface - lm73Control.lm73Data = 0; - bspPostTask(BSP_TEMPERATURE); - return; - } - - if (DATA == lm73State) - { - i = (uint8_t)lm73Control.lm73Data; - i <<= 8; - i |= ((lm73Control.lm73Data >> 8) & 0x00FF); - lm73Control.lm73Data = (i >> 7); - bspPostTask(BSP_TEMPERATURE); - } -} - -/**************************************************************************//** -\brief Reads data from lm73 sensor. - -\param[in] - f - callback method. -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. - -\return - BC_FAIL - the previous request was not completed, - the address of callback is 0, i2c interface is busy, - there is error on i2c interface. \n - BC_SUCCESS - other case. -******************************************************************************/ -result_t readLm73Data(void (*f)(bool result, int16_t data)) -{ - HAL_i2cMode_t i2cMode; - HAL_I2cParams_t i2cParam; - - if (IDLE != lm73State) - return BC_FAIL; - - if (!f) - return BC_FAIL; - - i2cMode.clockrate = I2C_CLOCK_RATE_62; - if (-1 == HAL_OpenI2cPacket(&i2cMode)) - return BC_FAIL; - lm73State = DATA; - lm73Control.lm73Callback = f; - - i2cParam.data = (uint8_t*)(&lm73Control.lm73Data); - i2cParam.f = lm73I2cPacketReadDone; - i2cParam.id = LM73_DEVICE_ADDRESS; - i2cParam.length = 2; - i2cParam.lengthAddr = HAL_NO_INTERNAL_ADDRESS; - - if (-1 == HAL_ReadI2cPacket(&i2cParam)) - { - lm73State = IDLE; - HAL_CloseI2cPacket(); - return BC_FAIL; - } - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP task handler. -******************************************************************************/ -void bspLM73Handler(void) -{ - HAL_CloseI2cPacket(); // free - lm73State = IDLE; - lm73Control.lm73Callback(lm73Control.lm73Result, lm73Control.lm73Data); -} - -// eof lm73.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/pwrCtrl.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/pwrCtrl.c deleted file mode 100644 index 305b80a2..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/pwrCtrl.c +++ /dev/null @@ -1,91 +0,0 @@ -/***************************************************************************//** -\file pwrCtrl.c - -\brief The module to control the power on periphery. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/05/07 E. Ivanov - Created -*******************************************************************************/ -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include - -#if BSP_MNZB_EVB_SUPPORT == 1 -/****************************************************************************** - Prototypes section -******************************************************************************/ -/**************************************************************************//** -\brief Checks if amplifier is used. -\return true - is used, \n - false - is not used. -******************************************************************************/ -bool HAL_IsAmplifierUsed(void); - -/****************************************************************************** - Global variables section -******************************************************************************/ -uint8_t bspPowerControl = 0; - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Powers on periphery. - -\param[in] - id - periphery id. -******************************************************************************/ -void bspOnPeriphery(uint8_t id) -{ - if (!bspPowerControl) - { - GPIO_8_make_out(); - - if (HAL_IsAmplifierUsed()) - GPIO_8_clr(); - else - GPIO_8_set(); - - GPIO_7_make_out(); - GPIO_7_set(); - } - bspPowerControl |= (1 << id); -} - - -/**************************************************************************//** -\brief Powers off periphery. - -\param[in] - id - periphery id. -******************************************************************************/ -void bspOffPeriphery(uint8_t id) -{ - bspPowerControl &= ~(1 << id); - if (bspPowerControl) - return; - - GPIO_8_make_out(); - - if (HAL_IsAmplifierUsed()) - GPIO_8_set(); - else - GPIO_8_clr(); - - GPIO_7_make_out(); - GPIO_7_clr(); -} - -#endif /* BSP_MNZB_EVB_SUPPORT */ -// eof pwrCtrl.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sensors.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sensors.c deleted file mode 100644 index 7e0eae1c..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sensors.c +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************//** -\file sensors.h - -\brief Implementation of sensors interface. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 12/05/08 A. Khromykh - Created -*******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include -#include -#include - -/****************************************************************************** - Implementations section -******************************************************************************/ -/***************************************************************************//** -\brief Opens temperature sensor. - -\return - BC_FAIL - sensor has been already open. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_OpenTemperatureSensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = openLm73())) - { -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOnPeriphery(SENSOR_TEMPERATURE); -#endif /* BSP_MNZB_EVB_SUPPORT */ - } - return result; -} - -/***************************************************************************//** -\brief Closes the temperature sensor. - -\return - BC_FAIL - if a hardware error has occured or - there is uncompleted ReadData request. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_CloseTemperatureSensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = closeLm73())) - { -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOffPeriphery(SENSOR_TEMPERATURE); -#endif /* BSP_MNZB_EVB_SUPPORT */ - } - return result; -} - -/**************************************************************************//** -\brief Reads data from the temperature sensor. -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. -\return - BC_FAIL - previous request was not completed. \n - BC_SUCCESS - otherwise. -******************************************************************************/ -result_t BSP_ReadTemperatureData(void (*f)(bool result, int16_t data)) -{ - return readLm73Data(f); -} - -/***************************************************************************//** -\brief Opens the light sensor. -\return - BC_FAIL - sensor has been already open. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_OpenLightSensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = openTsl2550())) - { -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOnPeriphery(SENSOR_LIGHT); -#endif /* BSP_MNZB_EVB_SUPPORT */ - } - return result; -} - -/***************************************************************************//** -\brief Closes the light sensor. -\return - BC_FAIL - if a hardware error has occured or - there is uncompleted ReadData request. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_CloseLightSensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = closeTsl2550())) - { -#if BSP_MNZB_EVB_SUPPORT == 1 - bspOffPeriphery(SENSOR_LIGHT); -#endif /* BSP_MNZB_EVB_SUPPORT */ - } - return result; -} - -/**************************************************************************//** -\brief Reads data from the light sensor. -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. -\return - BC_FAIL - previous request was not completed. \n - BC_SUCCESS - otherwise. -******************************************************************************/ -result_t BSP_ReadLightData(void (*f)(bool result, int16_t data)) -{ - return readTsl2550Data(f); -} - -#if BSP_MNZB_EVB_SUPPORT == 1 -/***************************************************************************//** -\brief Opens the battery sensor. -\return - BC_FAIL - sensor has been already open. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_OpenBatterySensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = openBattery())) - { - bspOnPeriphery(SENSOR_BATTERY); - } - return result; -} - -/***************************************************************************//** -\brief Closes the battery sensor. -\return - BC_FAIL - sensor was not opened. \n - BC_SUCCESS - otherwise. -*******************************************************************************/ -result_t BSP_CloseBatterySensor(void) -{ - result_t result; - - if (BC_SUCCESS == (result = closeBattery())) - { - bspOffPeriphery(SENSOR_BATTERY); - } - return result; -} - -/**************************************************************************//** -\brief Reads data from battery sensor. -\param[in] - data - sensor data. -\return - BC_FAIL - previous request was not completed, or sensor was not opened. \n - BC_SUCCESS - otherwise. -******************************************************************************/ -result_t BSP_ReadBatteryData(BspBatteryCb_t cb) -{ - return readBatteryData(cb); -} -#endif /* BSP_MNZB_EVB_SUPPORT */ - -#endif // APP_DISABLE_BSP != 1 - -//end of sensors.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sliders.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sliders.c deleted file mode 100644 index db417cdb..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sliders.c +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************//** -\file sliders.h - -\brief Implementation of the sliders. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/06/07 E. Ivanov - Created -******************************************************************************/ -#if APP_DISABLE_BSP != 1 - -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include - -/****************************************************************************** - Implementations section -******************************************************************************/ -/**************************************************************************//** -\brief Reads the sliders. - -\return - state of 3 on­board DIP­switches.User can uses SLIDER0, SLIDER1, SLIDER2 - defines to test state. Value 1 indicates that slider is on. -******************************************************************************/ -uint8_t BSP_ReadSliders(void) -{ - uint8_t result; - - GPIO_3_make_in(); GPIO_3_make_pullup(); - GPIO_4_make_in(); GPIO_4_make_pullup(); - GPIO_5_make_in(); GPIO_5_make_pullup(); - /* NOP was added for correct work on 8 MHz frequency. - clck i\o is not equal clck cpu. - CPU must wait for I\O system 1 clock for synchronization. */ - NOP; - result = GPIO_3_read() * SLIDER0; - result |= GPIO_4_read() * SLIDER1; - result |= GPIO_5_read() * SLIDER2; - GPIO_3_make_in(); - GPIO_4_make_in(); - GPIO_5_make_in(); - - return (~result) & 0x07; -} - -#endif // APP_DISABLE_BSP != 1 - -// end of sliders.c diff --git a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/tsl2550.c b/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/tsl2550.c deleted file mode 100644 index 9011c6fd..00000000 --- a/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/tsl2550.c +++ /dev/null @@ -1,457 +0,0 @@ -/**************************************************************************//** -\file tsl2550.c - -\brief Implementation of access to tsl2550 the sensor, light sensor. - -\author - Atmel Corporation: http://www.atmel.com \n - Support email: avr@atmel.com - - Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. - Licensed under Atmel's Limited License Agreement (BitCloudTM). - -\internal - History: - 29/06/07 E. Ivanov - Created -******************************************************************************/ -/****************************************************************************** - Includes section -******************************************************************************/ -#include -#include -#include -#include -#include - -/****************************************************************************** - Definitions section -******************************************************************************/ -// device address on i2c bus -#define TSL_DEVICE_ADDRESS 0x39 - -// device registers internal address -#define TSL_READ_CHANNEL0_COMMAND 0x43 -#define TSL_READ_CHANNEL1_COMMAND 0x83 -#define TSL_POWERDOWN_COMMAND 0x00 -#define TSL_POWERUP_COMMAND 0x03 -#define TSL_EXTENDED_RANGE_COMMAND 0x1D -#define TSL_STANDARD_RANGE_COMMAND 0x18 - -// standard mode max -#define TSL_MAX_LUX_VALUE 1846 - -// Conversion time (400ms typ by datasheet). Choose a little more to be on a safe side. -#define TSL_CONVERSION_TIME 500 - -/****************************************************************************** - Types section -******************************************************************************/ -// states -typedef enum -{ - OFF, - IDLE, - POWERUP, - POWERUP_ERR, - DATA, - DATA_ERR, -} Tsl2550States_t; - -typedef struct -{ - Tsl2550States_t state; - uint8_t ch0; - uint8_t ch1; - void(* callback)(bool result, int16_t data); // data callback pointer -} Tsl2550Control_t; - -/****************************************************************************** - Constants section -******************************************************************************/ -PROGMEM_DECLARE(const uint8_t tsl2550Ratio[129]) = -{ -100,100,100,100,100,100,100,100, -100,100,100,100,100,100, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 98, 98, 98, 98, 98, - 98, 98, 97, 97, 97, 97, 97, 96, - 96, 96, 96, 95, 95, 95, 94, 94, - 93, 93, 93, 92, 92, 91, 91, 90, - 89, 89, 88, 87, 87, 86, 85, 84, - 83, 82, 81, 80, 79, 78, 77, 75, - 74, 73, 71, 69, 68, 66, 64, 62, - 60, 58, 56, 54, 52, 49, 47, 44, - 42, 41, 40, 40, 39, 39, 38, 38, - 37, 37, 37, 36, 36, 36, 35, 35, - 35, 35, 34, 34, 34, 34, 33, 33, - 33, 33, 32, 32, 32, 32, 32, 31, - 31, 31, 31, 31, 30, 30, 30, 30, - 30 -}; - -PROGMEM_DECLARE(const uint16_t tsl2550Count[128]) = -{ - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, - 49, 53, 57, 61, 65, 69, 73, 77, - 81, 85, 89, 93, 97, 101, 105, 109, - 115, 123, 131, 139, 147, 155, 163, 171, - 179, 187, 195, 203, 211, 219, 227, 235, - 247, 263, 279, 295, 311, 327, 343, 359, - 375, 391, 407, 423, 439, 455, 471, 487, - 511, 543, 575, 607, 639, 671, 703, 735, - 767, 799, 831, 863, 895, 927, 959, 991, -1039,1103,1167,1231,1295,1359,1423,1487, -1551,1615,1679,1743,1807,1871,1935,1999, -2095,2223,2351,2479,2607,2735,2863,2991, -3119,3247,3375,3503,3631,3759,3887,4015 -}; - -/****************************************************************************** - Static function prototypes section -******************************************************************************/ -static bool tsl2550StartReading(void); -static void tsl2550StartFirstReading(void); -static void tsl2550I2cPacketReadDoneCh1(bool result); -static void tsl2550I2cPacketWriteDoneCh1(bool result); -static void tsl2550I2cPacketReadDoneCh0(bool result); -static void tsl2550I2cPacketWriteDoneCh0(bool result); -static void tsl2550I2cPowerupDone(bool result); -static bool tsl2550StartPowerup(void); - -/****************************************************************************** - Implementations section -******************************************************************************/ - -static Tsl2550Control_t tsl2550Control = {.state = OFF}; - -/**************************************************************************//** -\brief Opens the component to use. - -\return - BC_SUCCESS - the component is ready to be used. \n - BC_FAIL - otherwise. -******************************************************************************/ -result_t openTsl2550(void) -{ - if (IDLE == tsl2550Control.state || OFF == tsl2550Control.state) - return BC_SUCCESS; - - return BC_FAIL; -} - -/**************************************************************************//** -\brief Performs the test if the component have completed request. - -\return - BC_FAIL - the previous request is not completed. \n - BC_SUCCES - otherwise. -******************************************************************************/ -result_t closeTsl2550(void) -{ - if (IDLE == tsl2550Control.state || OFF == tsl2550Control.state) - return BC_SUCCESS; - - return BC_FAIL; -} - -/**************************************************************************//** -\brief Reads data from tsl2550 sensor. - -\param[in] - f - callback method -\param[in] - result - the result of the requested operation. - true - operation finished successfully, false - some error has - occured. -\param[in] - data - sensor data. - -\return - BC_FAIL - the previous request was not completed, - the address of callback is 0, i2c interface is busy, - there is error on i2c interface. \n - BC_SUCCESS - in other case. -******************************************************************************/ -result_t readTsl2550Data(void (*f)(bool result, int16_t data)) -{ - HAL_i2cMode_t i2cMode = {.clockrate = I2C_CLOCK_RATE_62}; - - if (NULL == f) - return BC_FAIL; - - if (OFF == tsl2550Control.state) // Sensor is in powerdown mode, powerup it before reading - { - if (-1 == HAL_OpenI2cPacket(&i2cMode)) - return BC_FAIL; - - if (false == tsl2550StartPowerup()) - { - HAL_CloseI2cPacket(); - return BC_FAIL; - } - tsl2550Control.state = POWERUP; - } - else if (IDLE == tsl2550Control.state) - { - if (-1 == HAL_OpenI2cPacket(&i2cMode)) - return BC_FAIL; - - if (false == tsl2550StartReading()) - { - HAL_CloseI2cPacket(); - return BC_FAIL; - } - tsl2550Control.state = DATA; - } - else - { - return BC_FAIL; - } - - tsl2550Control.callback = f; - - return BC_SUCCESS; -} - -/**************************************************************************//** -\brief BSP tsl2550 handler. -******************************************************************************/ -void bspTsl2550Handler(void) -{ - uint8_t result = false; - uint16_t lux = 0; - - HAL_CloseI2cPacket(); // free - - switch (tsl2550Control.state) - { - case POWERUP_ERR: - tsl2550Control.state = OFF; - break; - - case DATA_ERR: - tsl2550Control.state = IDLE; - break; - - case DATA: - { - uint32_t count0 = 0, count1 = 0; - uint8_t ratio = 128; // default scaling factor - uint8_t R; - - tsl2550Control.state = IDLE; - - if (tsl2550Control.ch0 & tsl2550Control.ch1 & 0x80) - { - memcpy_P(&count0, &tsl2550Count[tsl2550Control.ch0 & 0x7F], sizeof(uint16_t)); - memcpy_P(&count1, &tsl2550Count[tsl2550Control.ch1 & 0x7F], sizeof(uint16_t)); - - if (!count0 || (count0 <= count1)) // count1 cannot be greater than count0 - break; - - ratio = ((uint32_t)(count1 * 128ul) / count0); - // calculate lux - // the "256" is a scaling factor - memcpy_P(&R, &tsl2550Ratio[ratio], sizeof(uint8_t)); - lux = ((count0 - count1) * R) / 256; - // range check lux - if (lux > TSL_MAX_LUX_VALUE) - lux = TSL_MAX_LUX_VALUE; - - result = true; - } - } - break; - - default: - ASSERT(false, TSL2550_UNEXPECTED_STATE); - tsl2550Control.state = IDLE; - break; - } - - tsl2550Control.callback(result, lux); -} - -/**************************************************************************//** -\brief Callback that reading from tsl2550 was completed. - -\param[in] - result - contains result of operation. - if result is false there was problem on i2c interface. -******************************************************************************/ -static void tsl2550I2cPacketReadDoneCh1(bool result) -{ - if (false == result) - tsl2550Control.state = DATA_ERR; - - bspPostTask(BSP_LIGHT); -} - -/**************************************************************************//** -\brief Callback that writing command to tsl2550 was completed. - -\param[in] - result - contains result of operation. - if result is false there was problem on i2c interface. -******************************************************************************/ -static void tsl2550I2cPacketWriteDoneCh1(bool result) -{ - HAL_I2cParams_t i2cParam = - { - .data = &tsl2550Control.ch1, - .f = tsl2550I2cPacketReadDoneCh1, - .id = TSL_DEVICE_ADDRESS, - .length = 1, - .lengthAddr = HAL_NO_INTERNAL_ADDRESS, - }; - - if ((false == result) || (-1 == HAL_ReadI2cPacket(&i2cParam))) - { - tsl2550Control.state = DATA_ERR; - bspPostTask(BSP_LIGHT); - } -} - -/**************************************************************************//** -\brief Callback that reading from tsl2550 was completed. - -\param[in] - result - contains result of operation. - if result is false there was problem on i2c interface. -******************************************************************************/ -static void tsl2550I2cPacketReadDoneCh0(bool result) -{ - HAL_I2cParams_t i2cParam = - { - .data = &tsl2550Control.ch1, - .f = tsl2550I2cPacketWriteDoneCh1, - .id = TSL_DEVICE_ADDRESS, - .length = 1, - .lengthAddr = HAL_NO_INTERNAL_ADDRESS, - }; - - tsl2550Control.ch1 = TSL_READ_CHANNEL1_COMMAND; - - if ((false == result) || (-1 == HAL_WriteI2cPacket(&i2cParam))) - { - tsl2550Control.state = DATA_ERR; - bspPostTask(BSP_LIGHT); - } -} - -/**************************************************************************//** -\brief Callback that writing command to tsl2550 was completed. - -\param[in] - result - contains result of operation. - if result is false there was problem on i2c interface. -******************************************************************************/ -static void tsl2550I2cPacketWriteDoneCh0(bool result) -{ - HAL_I2cParams_t i2cParam = - { - .data = &tsl2550Control.ch0, - .f = tsl2550I2cPacketReadDoneCh0, - .id = TSL_DEVICE_ADDRESS, - .length = 1, - .lengthAddr = HAL_NO_INTERNAL_ADDRESS, - }; - - if ((false == result) || (-1 == HAL_ReadI2cPacket(&i2cParam))) - { - tsl2550Control.state = DATA_ERR; - bspPostTask(BSP_LIGHT); - } -} - -/**************************************************************************//** -\brief Start tsl2550 read sequence. - -\return - false - i2c packet wasn't sent - true - in other case. -******************************************************************************/ -static bool tsl2550StartReading(void) -{ - HAL_I2cParams_t i2cParam = - { - .data = &tsl2550Control.ch0, - .f = tsl2550I2cPacketWriteDoneCh0, - .id = TSL_DEVICE_ADDRESS, - .length = 1, - .lengthAddr = HAL_NO_INTERNAL_ADDRESS, - }; - - tsl2550Control.ch0 = TSL_READ_CHANNEL0_COMMAND; - - return (-1 != HAL_WriteI2cPacket(&i2cParam)) ? true : false; -} - -/**************************************************************************//** -\brief Callback on completion of tsl2550's delay after powerup. -******************************************************************************/ -static void tsl2550StartFirstReading(void) -{ - if (false == tsl2550StartReading()) - { - tsl2550Control.state = DATA_ERR; - bspPostTask(BSP_LIGHT); - return; - } - - tsl2550Control.state = DATA; -} - -/**************************************************************************//** -\brief Callback on completion of tsl2550 powerup. - -\param[in] - result - contains result of operation. - if result is false there was problem on i2c interface. -******************************************************************************/ -static void tsl2550I2cPowerupDone(bool result) -{ - static HAL_AppTimer_t tsl2550PowerupTimer = - { - .interval = TSL_CONVERSION_TIME * 2, // Wait for conversions on two channels one-after-one - .mode = TIMER_ONE_SHOT_MODE, - .callback = tsl2550StartFirstReading, - }; - - if (false == result) - { - tsl2550Control.state = POWERUP_ERR; - bspPostTask(BSP_LIGHT); - return; - } - - HAL_StartAppTimer(&tsl2550PowerupTimer); -} - -/**************************************************************************//** -\brief Start tsl2550 powerup sequence. - -\return - false - i2c packet wasn't sent - true - in other case. -******************************************************************************/ -static bool tsl2550StartPowerup(void) -{ - HAL_I2cParams_t i2cParam = - { - .data = &tsl2550Control.ch0, - .f = tsl2550I2cPowerupDone, - .id = TSL_DEVICE_ADDRESS, - .length = 1, - .lengthAddr = HAL_NO_INTERNAL_ADDRESS, - }; - - tsl2550Control.ch0 = TSL_POWERUP_COMMAND; - - return (-1 != HAL_WriteI2cPacket(&i2cParam)) ? true : false; -} - -// eof tsl2550.c -- cgit v1.2.3