Skip to content

Commit

Permalink
Merge pull request #1204 from spark/feature/rgb-led-mirror
Browse files Browse the repository at this point in the history
RGB LED mirroring
  • Loading branch information
technobly committed Dec 17, 2016
2 parents 68b7467 + 0b9e2d3 commit 273b422
Show file tree
Hide file tree
Showing 33 changed files with 893 additions and 191 deletions.
38 changes: 19 additions & 19 deletions bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ int main(void)
// Else check if the system has resumed from IWDG reset
else if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
{
REFLASH_FROM_BACKUP = 0;
OTA_FLASH_AVAILABLE = 0;
USB_DFU_MODE = 0;
FACTORY_RESET_MODE = 0;
// These are still initialized to zero, no need to do it again.
// REFLASH_FROM_BACKUP = 0;
// OTA_FLASH_AVAILABLE = 0;
// USB_DFU_MODE = 0;
// FACTORY_RESET_MODE = 0;

switch(BKP_DR1_Value)
{
Expand All @@ -228,9 +229,6 @@ int main(void)
USB_DFU_MODE = 1;
// fall through - No break at the end of case

default:
BKP_DR1_Value = 0xFFFF;
break;
// toDO create a location in vector table for bootloadr->app - app->bootloader API.
// add version number to build, and mode (debug,release etc) in vector table
// Then make informed decisions on what to do on WDT timeouts
Expand All @@ -241,6 +239,8 @@ int main(void)
case ENTERED_Loop:
case RAN_Loop:
case PRESERVE_APP:

default:
BKP_DR1_Value = 0xFFFF;
break;
}
Expand Down Expand Up @@ -274,7 +274,7 @@ int main(void)
bool factory_reset_available = (features & BL_FEATURE_FACTORY_RESET) && FLASH_IsFactoryResetAvailable();

TimingBUTTON = TIMING_ALL;
uint8_t factory_reset = 0;
// uint8_t factory_reset = 0;
while (BUTTON_Is_Pressed(BUTTON1) && TimingBUTTON)
{
if(BUTTON_Pressed_Time(BUTTON1) > TIMING_RESET_MODE)
Expand All @@ -284,12 +284,12 @@ int main(void)
LED_SetRGBColor(RGB_COLOR_WHITE);
SYSTEM_FLAG(NVMEM_SPARK_Reset_SysFlag) = 0x0001;
}
else if(!factory_reset && BUTTON_Pressed_Time(BUTTON1) > TIMING_RESTORE_MODE)
else if(!FACTORY_RESET_MODE && BUTTON_Pressed_Time(BUTTON1) > TIMING_RESTORE_MODE)
{
// if pressed for > 6.5 sec, enter firmware reset
LED_SetRGBColor(RGB_COLOR_GREEN);
SYSTEM_FLAG(NVMEM_SPARK_Reset_SysFlag) = 0x0000;
factory_reset = 1;
FACTORY_RESET_MODE = 1;
}
else if(!USB_DFU_MODE && BUTTON_Pressed_Time(BUTTON1) >= TIMING_DFU_MODE)
{
Expand All @@ -315,12 +315,12 @@ int main(void)
}
}

if (factory_reset || USB_DFU_MODE || SAFE_MODE) {
// now set the factory reset mode (to change the LED to rapid blinking.))
FACTORY_RESET_MODE = factory_reset;
USB_DFU_MODE &= !factory_reset;
SAFE_MODE &= !USB_DFU_MODE;
}
// if (factory_reset || USB_DFU_MODE || SAFE_MODE) {
// // now set the factory reset mode (to change the LED to rapid blinking.))
// FACTORY_RESET_MODE = factory_reset;
// USB_DFU_MODE &= !factory_reset;
// SAFE_MODE &= !USB_DFU_MODE;
// }
}

if (SAFE_MODE) {
Expand Down Expand Up @@ -407,9 +407,9 @@ int main(void)
}
// Otherwise enters DFU mode to allow user to program his application

FACTORY_RESET_MODE = 0; // ensure the LED is slow
OTA_FLASH_AVAILABLE = 0;
REFLASH_FROM_BACKUP = 0;
FACTORY_RESET_MODE = 0; // ensure the LED is slow flashing (100)
OTA_FLASH_AVAILABLE = 0; // |
REFLASH_FROM_BACKUP = 0; // |

LED_SetRGBColor(RGB_COLOR_YELLOW);

Expand Down
4 changes: 2 additions & 2 deletions bootloader/src/stm32f2xx/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void BUTTON_Init_Ext() {
const button_config_t* conf = (const button_config_t*)dct_read_app_data(DCT_MODE_BUTTON_MIRROR_OFFSET);

if (conf->active == 0xAA && conf->debounce_time == 0xBBCC) {
int32_t state = HAL_disable_irq();
//int32_t state = HAL_disable_irq();
memcpy((void*)&HAL_Buttons[BUTTON1_MIRROR], (void*)conf, sizeof(button_config_t));
HAL_Buttons[BUTTON1_MIRROR].active = 0;
HAL_Buttons[BUTTON1_MIRROR].debounce_time = 0;
BUTTON_Init(BUTTON1_MIRROR, BUTTON_MODE_EXTI);
HAL_enable_irq(state);
//HAL_enable_irq(state);
}

if (BUTTON_Debounce())
Expand Down
4 changes: 3 additions & 1 deletion ci/enumerate_build_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ NO_COLOR="\033[0m"
# "" means execute execute the $MAKE command without that var specified
DEBUG_BUILD=( y n )
PLATFORM=( core photon P1 electron )
# P1 bootloader built with gcc 4.8.4 doesn't fit flash, disabling for now
PLATFORM_BOOTLOADER=( core photon electron )
SPARK_CLOUD=( y n )
# TODO: Once FIRM-161 is fixed, change APP to this: APP=( "" tinker product_id_and_version )
APP=( "" tinker )
Expand Down Expand Up @@ -116,7 +118,7 @@ do
done

cd ../bootloader
for p in "${PLATFORM[@]}"
for p in "${PLATFORM_BOOTLOADER[@]}"
do
echo
echo '-----------------------------------------------------------------------'
Expand Down
1 change: 1 addition & 0 deletions hal-dynalib/src/hal_rgbled.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "hal_dynalib_rgbled.h"
3 changes: 3 additions & 0 deletions hal/inc/core_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ int HAL_System_Backup_Restore(size_t offset, void* buffer, size_t max_length, si
void HAL_Core_Button_Mirror_Pin(uint16_t pin, InterruptMode mode, uint8_t bootloader, uint8_t button, void* reserved);
void HAL_Core_Button_Mirror_Pin_Disable(uint8_t bootloader, uint8_t button, void* reserved);

void HAL_Core_Led_Mirror_Pin(uint8_t led, pin_t pin, uint32_t flags, uint8_t bootloader, void* reserved);
void HAL_Core_Led_Mirror_Pin_Disable(uint8_t led, uint8_t bootloader, void* reserved);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion hal/inc/hal_dynalib_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ DYNALIB_FN(26, hal_core, HAL_Core_System_Reset_Ex, void(int, uint32_t, void*))
DYNALIB_FN(27, hal_core, HAL_Core_Get_Last_Reset_Info, int(int*, uint32_t*, void*))
DYNALIB_FN(28, hal_core, HAL_Core_Button_Mirror_Pin, void(uint16_t, InterruptMode, uint8_t, uint8_t, void*))
DYNALIB_FN(29, hal_core, HAL_Core_Button_Mirror_Pin_Disable, void(uint8_t, uint8_t, void*))

DYNALIB_FN(30, hal_core, HAL_Core_Led_Mirror_Pin, void(uint8_t, pin_t, uint32_t, uint8_t, void*))
DYNALIB_FN(31, hal_core, HAL_Core_Led_Mirror_Pin_Disable, void(uint8_t, uint8_t, void*))
DYNALIB_END(hal_core)


Expand Down
47 changes: 47 additions & 0 deletions hal/inc/hal_dynalib_rgbled.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
******************************************************************************
Copyright (c) 2016 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#ifndef HAL_DYNALIB_RGB_H
#define HAL_DYNALIB_RGB_H

#include "dynalib.h"

#ifdef DYNALIB_EXPORT
#include "rgbled_hal.h"
#endif

// WARNING
// The order of functions must not be changed or older applications will break
// when used with newer system firmware.
// Function signatures shouldn't be changed other than changing pointer types.
// New HAL functions must be added to the end of this list.
// GNINRAW

DYNALIB_BEGIN(hal_rgbled)

DYNALIB_FN(0, hal_rgbled, HAL_Led_Rgb_Set_Values, void(uint16_t, uint16_t, uint16_t, void*))
DYNALIB_FN(1, hal_rgbled, HAL_Led_Rgb_Get_Values, void(uint16_t*, void*))
DYNALIB_FN(2, hal_rgbled, HAL_Led_Rgb_Get_Max_Value, uint32_t(void*))
DYNALIB_FN(3, hal_rgbled, HAL_Led_User_Set, void(uint8_t, void*))
DYNALIB_FN(4, hal_rgbled, HAL_Led_User_Toggle, void(void*))

DYNALIB_END(hal_rgbled)

#endif /* HAL_DYNALIB_GPIO_H */

13 changes: 13 additions & 0 deletions hal/inc/rgbled_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ extern "C" {
#endif

#include <stdint.h>
typedef struct led_config_t led_config_t;

void HAL_Led_Rgb_Set_Values(uint16_t r, uint16_t g, uint16_t b, void* reserved);
void HAL_Led_Rgb_Get_Values(uint16_t* rgb, void* reserved);
uint32_t HAL_Led_Rgb_Get_Max_Value(void* reserved);
void HAL_Led_User_Set(uint8_t state, void* reserved);
void HAL_Led_User_Toggle(void* reserved);

led_config_t* HAL_Led_Set_Configuration(uint8_t led, led_config_t* conf, void* reserved);
led_config_t* HAL_Led_Get_Configuration(uint8_t led, void* reserved);

void HAL_Led_Init(uint8_t led, led_config_t* conf, void* reserved);

// This is the low-level api to the LED
// Deprecated, not exported in HAL
void Set_RGB_LED_Values(uint16_t r, uint16_t g, uint16_t b);
void Get_RGB_LED_Values(uint16_t* rgb);
void Set_User_LED(uint8_t state);
Expand Down
8 changes: 8 additions & 0 deletions hal/src/core/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,11 @@ void HAL_Core_Button_Mirror_Pin_Disable(uint8_t bootloader, uint8_t button, void
void HAL_Core_Button_Mirror_Pin(uint16_t pin, InterruptMode mode, uint8_t bootloader, uint8_t button, void *reserved)
{
}

void HAL_Core_Led_Mirror_Pin_Disable(uint8_t led, uint8_t bootloader, void* reserved)
{
}

void HAL_Core_Led_Mirror_Pin(uint8_t led, pin_t pin, uint32_t flags, uint8_t bootloader, void* reserved)
{
}
35 changes: 35 additions & 0 deletions hal/src/gcc/rgbled_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,38 @@ uint16_t Get_RGB_LED_Max_Value(void)
{
return 65535;
}

void HAL_Led_Rgb_Set_Values(uint16_t r, uint16_t g, uint16_t b, void* reserved)
{
}

void HAL_Led_Rgb_Get_Values(uint16_t* rgb, void* reserved)
{
}

uint32_t HAL_Led_Rgb_Get_Max_Value(void* reserved)
{
return 65535;
}

void HAL_Led_User_Set(uint8_t state, void* reserved)
{
}

void HAL_Led_User_Toggle(void* reserved)
{
}

led_config_t* HAL_Led_Set_Configuration(uint8_t led, led_config_t* conf, void* reserved)
{
return nullptr;
}

led_config_t* HAL_Led_Get_Configuration(uint8_t led, void* reserved)
{
return nullptr;
}

void HAL_Led_Init(uint8_t led, led_config_t* conf, void* reserved)
{
}
Loading

0 comments on commit 273b422

Please sign in to comment.