Skip to content

Commit

Permalink
Merge pull request #1225 from spark/feature/system_led_fixes
Browse files Browse the repository at this point in the history
LED signaling fixes
  • Loading branch information
technobly committed Jan 13, 2017
2 parents d30e03f + b85c021 commit d09c747
Show file tree
Hide file tree
Showing 42 changed files with 4,161 additions and 3,549 deletions.
2 changes: 1 addition & 1 deletion bootloader/import.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BOOTLOADER_MODULE_PATH ?= $(PROJECT_ROOT)/bootloader
BOOTLOADER_VERSION ?= 10
BOOTLOADER_VERSION ?= 11
BOOTLOADER_BUILD_PATH_EXT = $(BUILD_TARGET_PLATFORM)

# bring in the include folders from inc and src/<platform> is includes
Expand Down
2 changes: 1 addition & 1 deletion bootloader/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BOOTLOADER_MODULE_PATH=.
PLATFORM_DFU=0x8000000
BUILD_PATH_EXT = $(BOOTLOADER_BUILD_PATH_EXT)

DEPENDENCIES = platform hal services dynalib
DEPENDENCIES = platform hal services system dynalib
MAKE_DEPENDENCIES = platform services
# dependent on HAL headers, but not the library
LIBS += $(MAKE_DEPENDENCIES)
Expand Down
25 changes: 20 additions & 5 deletions bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#include "rgbled.h"
#include "button.h"

#if (PLATFORM_ID == 6) || (PLATFORM_ID == 10) || (PLATFORM_ID == 8)
#include "led_signal.h"
#define USE_LED_THEME
#endif

void platform_startup();


Expand All @@ -55,6 +60,11 @@ volatile uint32_t TimingBUTTON;
volatile uint32_t TimingLED;
volatile uint32_t TimingIWDGReload;

// Customizable LED colors
static uint32_t FirmwareUpdateColor = RGB_COLOR_MAGENTA;
static uint32_t SafeModeColor = RGB_COLOR_MAGENTA;
static uint32_t DFUModeColor = RGB_COLOR_YELLOW;

/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
Expand All @@ -64,7 +74,7 @@ void flashModulesCallback(bool isUpdating)
if(isUpdating)
{
OTA_FLASH_AVAILABLE = 1;
LED_SetRGBColor(RGB_COLOR_MAGENTA);
LED_SetRGBColor(FirmwareUpdateColor);
}
else
{
Expand Down Expand Up @@ -151,6 +161,11 @@ int main(void)
features = 0xFF; // ignore - corrupt. Top 4 bits should be the inverse of the bottom 4
}

#ifdef USE_LED_THEME
// Load LED theme colors
get_led_theme_colors(&FirmwareUpdateColor, &SafeModeColor, &DFUModeColor);
#endif

//--------------------------------------------------------------------------

/*
Expand Down Expand Up @@ -295,7 +310,7 @@ int main(void)
{
// if pressed for > 3 sec, enter USB DFU Mode
if (features&BL_FEATURE_DFU_MODE) {
LED_SetRGBColor(RGB_COLOR_YELLOW);
LED_SetRGBColor(DFUModeColor);
USB_DFU_MODE = 1; // stay in DFU mode until the button is released so we have slow-led blinking
}
if (!factory_reset_available)
Expand All @@ -309,7 +324,7 @@ int main(void)

if (features&BL_FEATURE_SAFE_MODE) {
// if pressed for > 1 sec, enter Safe Mode
LED_SetRGBColor(RGB_COLOR_MAGENTA);
LED_SetRGBColor(SafeModeColor);
SAFE_MODE = 1;
}
}
Expand All @@ -332,7 +347,7 @@ int main(void)

if (OTA_FLASH_AVAILABLE == 1)
{
LED_SetRGBColor(RGB_COLOR_MAGENTA);
LED_SetRGBColor(FirmwareUpdateColor);
// Load the OTA Firmware from external flash
OTA_Flash_Reset();
}
Expand Down Expand Up @@ -411,7 +426,7 @@ int main(void)
OTA_FLASH_AVAILABLE = 0; // |
REFLASH_FROM_BACKUP = 0; // |

LED_SetRGBColor(RGB_COLOR_YELLOW);
LED_SetRGBColor(DFUModeColor);

USB_DFU_MODE = 1;

Expand Down
2 changes: 1 addition & 1 deletion bootloader/src/photon/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ HAL_LIB_COREV2 = $(HAL_SRC_COREV2_PATH)/lib
WICED_LIBS = Platform_$(PLATFORM_NET) SPI_Flash_Library_$(PLATFORM_NET)

WICED_LIB_FILES = $(addprefix $(HAL_LIB_COREV2)/,$(addsuffix .a,$(WICED_LIBS)))
WICED_LIB_FILES = $(HAL_LIB_COREV2)/FreeRTOS/STM32F2xx.a
WICED_LIB_FILES = $(HAL_LIB_COREV2)/FreeRTOS/STM32F2xx_bootloader.a

LIBS_EXT += -Wl,--whole-archive $(WICED_LIB_FILES) -Wl,--no-whole-archive

28 changes: 28 additions & 0 deletions bootloader/src/stm32f2xx/led_signal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "led_signal.h"

#include "system_led_signal.h"

#include "dct.h"

// See system_led_signal.cpp for the description of the LED theme data format
STATIC_ASSERT(led_theme_version_has_changed, LED_SIGNAL_THEME_VERSION == 1);

#define UNPACK_COLOR_COMPONENT(_value) \
((((_value) & 0x0f) << 4) | ((_value) & 0x0f)) /* 0 -> 0, 1 -> 17, 2 -> 34, ..., 15 -> 255 */ \

static uint32_t led_signal_color(int signal, const uint8_t* data) {
data += signal * 3 + 1; // 3 bytes per signal; first byte is reserved for a version number
return ((uint32_t)UNPACK_COLOR_COMPONENT(*data >> 4) << 16) | // R
((uint32_t)UNPACK_COLOR_COMPONENT(*data & 0x0f) << 8) | // G
(uint32_t)UNPACK_COLOR_COMPONENT(*(data + 1) >> 4); // B
}

void get_led_theme_colors(uint32_t* firmware_update, uint32_t* safe_mode, uint32_t* dfu_mode) {
// Check if theme data is initialized in DCT
const uint8_t* d = (const char*)dct_read_app_data(DCT_LED_THEME_OFFSET);
if (d && *d == LED_SIGNAL_THEME_VERSION) {
*firmware_update = led_signal_color(LED_SIGNAL_FIRMWARE_UPDATE, d);
*safe_mode = led_signal_color(LED_SIGNAL_SAFE_MODE, d);
*dfu_mode = led_signal_color(LED_SIGNAL_DFU_MODE, d);
}
}
9 changes: 9 additions & 0 deletions bootloader/src/stm32f2xx/led_signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef LED_SIGNAL_H
#define LED_SIGNAL_H

#include <stdint.h>

// Loads some of the colors used for LED signaling from DCT
void get_led_theme_colors(uint32_t* firmware_update, uint32_t* safe_mode, uint32_t* dfu_mode);

#endif // LED_SIGNAL_H
19 changes: 19 additions & 0 deletions hal/inc/core_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ void HAL_Core_Button_Mirror_Pin_Disable(uint8_t bootloader, uint8_t button, void
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);

/**
* HAL event type.
*/
typedef enum {
HAL_EVENT_GENERATE_DEVICE_KEY = 10 // Fired when HAL attempts to generate device keys
} HAL_Event;

/**
* HAL event flags.
*/
typedef enum {
HAL_EVENT_FLAG_START = 0x01, // Event started
HAL_EVENT_FLAG_STOP = 0x02 // Event stopped
} HAL_Event_Flag;

typedef void(*HAL_Event_Callback)(int event, int flags, void* data);

void HAL_Set_Event_Callback(HAL_Event_Callback callback, void* reserved);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 2 additions & 4 deletions hal/inc/hal_dynalib_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ DYNALIB_FN(28, hal_core, HAL_Core_Button_Mirror_Pin, void(uint16_t, InterruptMod
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)



DYNALIB_FN(32, hal_core, HAL_Set_Event_Callback, void(HAL_Event_Callback, void*))

DYNALIB_END(hal_core)

#endif /* HAL_DYNALIB_CORE_H */

4 changes: 2 additions & 2 deletions hal/inc/wlan_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ extern uint32_t lastEvent;
WLAN_SMART_CONFIG_FINISHED,WLAN_SERIAL_CONFIG_DONE,WLAN_CONNECTED,WLAN_DHCP,WLAN_CAN_SHUTDOWN); \
DEBUG("\r\nSPARK_WLAN_RESET=%d\r\nSPARK_WLAN_SLEEP=%d\r\nSPARK_WLAN_STARTED=%d\r\nSPARK_CLOUD_CONNECT=%d", \
SPARK_WLAN_RESET,SPARK_WLAN_SLEEP,SPARK_WLAN_STARTED,SPARK_CLOUD_CONNECT); \
DEBUG("\r\nSPARK_CLOUD_SOCKETED=%d\r\nSPARK_CLOUD_CONNECTED=%d\r\nSPARK_FLASH_UPDATE=%d\r\nSPARK_LED_FADE=%d\r\n", \
SPARK_CLOUD_SOCKETED,SPARK_CLOUD_CONNECTED,SPARK_FLASH_UPDATE,SPARK_LED_FADE); \
DEBUG("\r\nSPARK_CLOUD_SOCKETED=%d\r\nSPARK_CLOUD_CONNECTED=%d\r\nSPARK_FLASH_UPDATE=%d\r\n", \
SPARK_CLOUD_SOCKETED,SPARK_CLOUD_CONNECTED,SPARK_FLASH_UPDATE); \
} while(0)

#define ON_EVENT_DELTA() do { if (lastEvent != 0) { uint32_t l; GET_LAST_EVENT(l); DEBUG("\r\nAsyncEvent 0x%04x", l); DUMP_STATE();}} while(0)
Expand Down
34 changes: 34 additions & 0 deletions hal/shared/hal_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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_EVENT_H
#define HAL_EVENT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "core_hal.h"

// Generates HAL event. See HAL_Event enum for the list of defined events
void hal_notify_event(int event, int flags, void* data);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // HAL_EVENT_H
26 changes: 0 additions & 26 deletions hal/shared/ledcontrol.h

This file was deleted.

12 changes: 12 additions & 0 deletions hal/src/gcc/core_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,15 @@ 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)
{
}

static HAL_Event_Callback eventCallback = nullptr;

void HAL_Set_Event_Callback(HAL_Event_Callback callback, void* reserved) {
eventCallback = callback;
}

void hal_notify_event(int event, int flags, void* data) {
if (eventCallback) {
eventCallback(event, flags, data);
}
}
Binary file not shown.
7 changes: 7 additions & 0 deletions hal/src/photon/wiced.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ update lib $PHOTON_WICED_REPO_PATH/build/demo_soft_ap-BCM9WCDUSI09-FreeRTOS-LwIP
update lib/FreeRTOS $PHOTON_WICED_REPO_PATH/build/demo_soft_ap-BCM9WCDUSI14-FreeRTOS-LwIP-SDIO/libraries
update lib/FreeRTOS $PHOTON_WICED_REPO_PATH/build/demo_soft_ap-BCM9WCDUSI09-FreeRTOS-LwIP-SDIO/libraries

# Bootloader optimized build
pushd $PHOTON_WICED_REPO_PATH
# We have to clean anyway, otherwise PARTICLE_FLASH_SPACE_OPTIMIZE=y will not take effect
./make clean
./make demo.soft_ap-BCM9WCDUSI09-FreeRTOS-LwIP-SDIO $OPTS PARTICLE_FLASH_SPACE_OPTIMIZE=y
popd

cp $PHOTON_WICED_REPO_PATH/build/demo_soft_ap-BCM9WCDUSI09-FreeRTOS-LwIP-SDIO/libraries/STM32F2xx.a lib/FreeRTOS/STM32F2xx_bootloader.a
34 changes: 34 additions & 0 deletions hal/src/stm32/hal_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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/>.
*/

#include "hal_event.h"

namespace {

HAL_Event_Callback eventCallback = nullptr;

}

void HAL_Set_Event_Callback(HAL_Event_Callback callback, void* reserved) {
eventCallback = callback;
}

void hal_notify_event(int event, int flags, void* data) {
if (eventCallback) {
eventCallback(event, flags, data);
}
}
Loading

0 comments on commit d09c747

Please sign in to comment.