diff --git a/.cproject b/.cproject index 36e2054..15ee0ed 100644 --- a/.cproject +++ b/.cproject @@ -1,235 +1,245 @@ - + - + - - - - - - + + + + + + - - - - - - + + + + + + - + - + - - - - - - + + + + + + - - - - - - + + + + + + - + - + - + - + - + - + - + - + diff --git a/.mxproject b/.mxproject index bd3a298..968ef60 100644 --- a/.mxproject +++ b/.mxproject @@ -5,7 +5,7 @@ SourcePath=D:/GoogleDrive/Blog msalamon.pl/Materialy do wpisow/6. Adresowalne di SourceFiles=gpio.c;dma.c;spi.c;stm32f1xx_it.c;stm32f1xx_hal_msp.c;main.c;usb_device.c;usbd_conf.c;usbd_desc.c;usbd_cdc_if.c; [PreviousLibFiles] -LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h;Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h; +LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h;Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h;Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h; [PreviousUsedSW4STM32Files] SourceFiles=..\Src\main.c;..\Src\gpio.c;..\Src\dma.c;..\Src\spi.c;..\Src\usb_device.c;..\Src\usbd_conf.c;..\Src\usbd_desc.c;..\Src\usbd_cdc_if.c;..\Src\stm32f1xx_it.c;..\Src\stm32f1xx_hal_msp.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c;../\Src/system_stm32f1xx.c;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;null;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c;../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c; diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 68fc1f6..5d596ff 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h b/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h similarity index 98% rename from Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h rename to Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h index 0a3ae2a..9ff8ad6 100644 --- a/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h +++ b/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file stm32f103x6.h + * @file stm32f103xb.h * @author MCD Application Team * @version V4.2.0 * @date 31-March-2017 @@ -48,12 +48,12 @@ * @{ */ -/** @addtogroup stm32f103x6 +/** @addtogroup stm32f103xb * @{ */ -#ifndef __STM32F103x6_H -#define __STM32F103x6_H +#ifndef __STM32F103xB_H +#define __STM32F103xB_H #ifdef __cplusplus extern "C" { @@ -128,11 +128,16 @@ typedef enum TIM1_CC_IRQn = 27, /*!< TIM1 Capture Compare Interrupt */ TIM2_IRQn = 28, /*!< TIM2 global Interrupt */ TIM3_IRQn = 29, /*!< TIM3 global Interrupt */ + TIM4_IRQn = 30, /*!< TIM4 global Interrupt */ I2C1_EV_IRQn = 31, /*!< I2C1 Event Interrupt */ I2C1_ER_IRQn = 32, /*!< I2C1 Error Interrupt */ + I2C2_EV_IRQn = 33, /*!< I2C2 Event Interrupt */ + I2C2_ER_IRQn = 34, /*!< I2C2 Error Interrupt */ SPI1_IRQn = 35, /*!< SPI1 global Interrupt */ + SPI2_IRQn = 36, /*!< SPI2 global Interrupt */ USART1_IRQn = 37, /*!< USART1 global Interrupt */ USART2_IRQn = 38, /*!< USART2 global Interrupt */ + USART3_IRQn = 39, /*!< USART3 global Interrupt */ EXTI15_10_IRQn = 40, /*!< External Line[15:10] Interrupts */ RTC_Alarm_IRQn = 41, /*!< RTC Alarm through EXTI Line Interrupt */ USBWakeUp_IRQn = 42, /*!< USB Device WakeUp from suspend through EXTI Line Interrupt */ @@ -612,7 +617,7 @@ typedef struct #define FLASH_BASE 0x08000000U /*!< FLASH base address in the alias region */ -#define FLASH_BANK1_END 0x08007FFFU /*!< FLASH END address of bank1 */ +#define FLASH_BANK1_END 0x0801FFFFU /*!< FLASH END address of bank1 */ #define SRAM_BASE 0x20000000U /*!< SRAM base address in the alias region */ #define PERIPH_BASE 0x40000000U /*!< Peripheral base address in the alias region */ @@ -627,11 +632,15 @@ typedef struct #define TIM2_BASE (APB1PERIPH_BASE + 0x00000000U) #define TIM3_BASE (APB1PERIPH_BASE + 0x00000400U) +#define TIM4_BASE (APB1PERIPH_BASE + 0x00000800U) #define RTC_BASE (APB1PERIPH_BASE + 0x00002800U) #define WWDG_BASE (APB1PERIPH_BASE + 0x00002C00U) #define IWDG_BASE (APB1PERIPH_BASE + 0x00003000U) +#define SPI2_BASE (APB1PERIPH_BASE + 0x00003800U) #define USART2_BASE (APB1PERIPH_BASE + 0x00004400U) +#define USART3_BASE (APB1PERIPH_BASE + 0x00004800U) #define I2C1_BASE (APB1PERIPH_BASE + 0x00005400U) +#define I2C2_BASE (APB1PERIPH_BASE + 0x5800) #define CAN1_BASE (APB1PERIPH_BASE + 0x00006400U) #define BKP_BASE (APB1PERIPH_BASE + 0x00006C00U) #define PWR_BASE (APB1PERIPH_BASE + 0x00007000U) @@ -641,6 +650,7 @@ typedef struct #define GPIOB_BASE (APB2PERIPH_BASE + 0x00000C00U) #define GPIOC_BASE (APB2PERIPH_BASE + 0x00001000U) #define GPIOD_BASE (APB2PERIPH_BASE + 0x00001400U) +#define GPIOE_BASE (APB2PERIPH_BASE + 0x00001800U) #define ADC1_BASE (APB2PERIPH_BASE + 0x00002400U) #define ADC2_BASE (APB2PERIPH_BASE + 0x00002800U) #define TIM1_BASE (APB2PERIPH_BASE + 0x00002C00U) @@ -684,11 +694,15 @@ typedef struct #define TIM2 ((TIM_TypeDef *)TIM2_BASE) #define TIM3 ((TIM_TypeDef *)TIM3_BASE) +#define TIM4 ((TIM_TypeDef *)TIM4_BASE) #define RTC ((RTC_TypeDef *)RTC_BASE) #define WWDG ((WWDG_TypeDef *)WWDG_BASE) #define IWDG ((IWDG_TypeDef *)IWDG_BASE) +#define SPI2 ((SPI_TypeDef *)SPI2_BASE) #define USART2 ((USART_TypeDef *)USART2_BASE) +#define USART3 ((USART_TypeDef *)USART3_BASE) #define I2C1 ((I2C_TypeDef *)I2C1_BASE) +#define I2C2 ((I2C_TypeDef *)I2C2_BASE) #define USB ((USB_TypeDef *)USB_BASE) #define CAN1 ((CAN_TypeDef *)CAN1_BASE) #define BKP ((BKP_TypeDef *)BKP_BASE) @@ -699,6 +713,7 @@ typedef struct #define GPIOB ((GPIO_TypeDef *)GPIOB_BASE) #define GPIOC ((GPIO_TypeDef *)GPIOC_BASE) #define GPIOD ((GPIO_TypeDef *)GPIOD_BASE) +#define GPIOE ((GPIO_TypeDef *)GPIOE_BASE) #define ADC1 ((ADC_TypeDef *)ADC1_BASE) #define ADC2 ((ADC_TypeDef *)ADC2_BASE) #define ADC12_COMMON ((ADC_Common_TypeDef *)ADC1_BASE) @@ -1226,6 +1241,9 @@ typedef struct #define RCC_APB2RSTR_USART1RST RCC_APB2RSTR_USART1RST_Msk /*!< USART1 reset */ +#define RCC_APB2RSTR_IOPERST_Pos (6U) +#define RCC_APB2RSTR_IOPERST_Msk (0x1U << RCC_APB2RSTR_IOPERST_Pos) /*!< 0x00000040 */ +#define RCC_APB2RSTR_IOPERST RCC_APB2RSTR_IOPERST_Msk /*!< I/O port E reset */ @@ -1258,6 +1276,18 @@ typedef struct #define RCC_APB1RSTR_PWRRST_Msk (0x1U << RCC_APB1RSTR_PWRRST_Pos) /*!< 0x10000000 */ #define RCC_APB1RSTR_PWRRST RCC_APB1RSTR_PWRRST_Msk /*!< Power interface reset */ +#define RCC_APB1RSTR_TIM4RST_Pos (2U) +#define RCC_APB1RSTR_TIM4RST_Msk (0x1U << RCC_APB1RSTR_TIM4RST_Pos) /*!< 0x00000004 */ +#define RCC_APB1RSTR_TIM4RST RCC_APB1RSTR_TIM4RST_Msk /*!< Timer 4 reset */ +#define RCC_APB1RSTR_SPI2RST_Pos (14U) +#define RCC_APB1RSTR_SPI2RST_Msk (0x1U << RCC_APB1RSTR_SPI2RST_Pos) /*!< 0x00004000 */ +#define RCC_APB1RSTR_SPI2RST RCC_APB1RSTR_SPI2RST_Msk /*!< SPI 2 reset */ +#define RCC_APB1RSTR_USART3RST_Pos (18U) +#define RCC_APB1RSTR_USART3RST_Msk (0x1U << RCC_APB1RSTR_USART3RST_Pos) /*!< 0x00040000 */ +#define RCC_APB1RSTR_USART3RST RCC_APB1RSTR_USART3RST_Msk /*!< USART 3 reset */ +#define RCC_APB1RSTR_I2C2RST_Pos (22U) +#define RCC_APB1RSTR_I2C2RST_Msk (0x1U << RCC_APB1RSTR_I2C2RST_Pos) /*!< 0x00400000 */ +#define RCC_APB1RSTR_I2C2RST RCC_APB1RSTR_I2C2RST_Msk /*!< I2C 2 reset */ #define RCC_APB1RSTR_USBRST_Pos (23U) #define RCC_APB1RSTR_USBRST_Msk (0x1U << RCC_APB1RSTR_USBRST_Pos) /*!< 0x00800000 */ @@ -1320,6 +1350,9 @@ typedef struct #define RCC_APB2ENR_USART1EN RCC_APB2ENR_USART1EN_Msk /*!< USART1 clock enable */ +#define RCC_APB2ENR_IOPEEN_Pos (6U) +#define RCC_APB2ENR_IOPEEN_Msk (0x1U << RCC_APB2ENR_IOPEEN_Pos) /*!< 0x00000040 */ +#define RCC_APB2ENR_IOPEEN RCC_APB2ENR_IOPEEN_Msk /*!< I/O port E clock enable */ @@ -1352,6 +1385,18 @@ typedef struct #define RCC_APB1ENR_PWREN_Msk (0x1U << RCC_APB1ENR_PWREN_Pos) /*!< 0x10000000 */ #define RCC_APB1ENR_PWREN RCC_APB1ENR_PWREN_Msk /*!< Power interface clock enable */ +#define RCC_APB1ENR_TIM4EN_Pos (2U) +#define RCC_APB1ENR_TIM4EN_Msk (0x1U << RCC_APB1ENR_TIM4EN_Pos) /*!< 0x00000004 */ +#define RCC_APB1ENR_TIM4EN RCC_APB1ENR_TIM4EN_Msk /*!< Timer 4 clock enable */ +#define RCC_APB1ENR_SPI2EN_Pos (14U) +#define RCC_APB1ENR_SPI2EN_Msk (0x1U << RCC_APB1ENR_SPI2EN_Pos) /*!< 0x00004000 */ +#define RCC_APB1ENR_SPI2EN RCC_APB1ENR_SPI2EN_Msk /*!< SPI 2 clock enable */ +#define RCC_APB1ENR_USART3EN_Pos (18U) +#define RCC_APB1ENR_USART3EN_Msk (0x1U << RCC_APB1ENR_USART3EN_Pos) /*!< 0x00040000 */ +#define RCC_APB1ENR_USART3EN RCC_APB1ENR_USART3EN_Msk /*!< USART 3 clock enable */ +#define RCC_APB1ENR_I2C2EN_Pos (22U) +#define RCC_APB1ENR_I2C2EN_Msk (0x1U << RCC_APB1ENR_I2C2EN_Pos) /*!< 0x00400000 */ +#define RCC_APB1ENR_I2C2EN RCC_APB1ENR_I2C2EN_Msk /*!< I2C 2 clock enable */ #define RCC_APB1ENR_USBEN_Pos (23U) #define RCC_APB1ENR_USBEN_Msk (0x1U << RCC_APB1ENR_USBEN_Pos) /*!< 0x00800000 */ @@ -2040,6 +2085,20 @@ typedef struct #define AFIO_MAPR_USART2_REMAP_Msk (0x1U << AFIO_MAPR_USART2_REMAP_Pos) /*!< 0x00000008 */ #define AFIO_MAPR_USART2_REMAP AFIO_MAPR_USART2_REMAP_Msk /*!< USART2 remapping */ +#define AFIO_MAPR_USART3_REMAP_Pos (4U) +#define AFIO_MAPR_USART3_REMAP_Msk (0x3U << AFIO_MAPR_USART3_REMAP_Pos) /*!< 0x00000030 */ +#define AFIO_MAPR_USART3_REMAP AFIO_MAPR_USART3_REMAP_Msk /*!< USART3_REMAP[1:0] bits (USART3 remapping) */ +#define AFIO_MAPR_USART3_REMAP_0 (0x1U << AFIO_MAPR_USART3_REMAP_Pos) /*!< 0x00000010 */ +#define AFIO_MAPR_USART3_REMAP_1 (0x2U << AFIO_MAPR_USART3_REMAP_Pos) /*!< 0x00000020 */ + +/* USART3_REMAP configuration */ +#define AFIO_MAPR_USART3_REMAP_NOREMAP 0x00000000U /*!< No remap (TX/PB10, RX/PB11, CK/PB12, CTS/PB13, RTS/PB14) */ +#define AFIO_MAPR_USART3_REMAP_PARTIALREMAP_Pos (4U) +#define AFIO_MAPR_USART3_REMAP_PARTIALREMAP_Msk (0x1U << AFIO_MAPR_USART3_REMAP_PARTIALREMAP_Pos) /*!< 0x00000010 */ +#define AFIO_MAPR_USART3_REMAP_PARTIALREMAP AFIO_MAPR_USART3_REMAP_PARTIALREMAP_Msk /*!< Partial remap (TX/PC10, RX/PC11, CK/PC12, CTS/PB13, RTS/PB14) */ +#define AFIO_MAPR_USART3_REMAP_FULLREMAP_Pos (4U) +#define AFIO_MAPR_USART3_REMAP_FULLREMAP_Msk (0x3U << AFIO_MAPR_USART3_REMAP_FULLREMAP_Pos) /*!< 0x00000030 */ +#define AFIO_MAPR_USART3_REMAP_FULLREMAP AFIO_MAPR_USART3_REMAP_FULLREMAP_Msk /*!< Full remap (TX/PD8, RX/PD9, CK/PD10, CTS/PD11, RTS/PD12) */ #define AFIO_MAPR_TIM1_REMAP_Pos (6U) #define AFIO_MAPR_TIM1_REMAP_Msk (0x3U << AFIO_MAPR_TIM1_REMAP_Pos) /*!< 0x000000C0 */ @@ -2089,6 +2148,9 @@ typedef struct #define AFIO_MAPR_TIM3_REMAP_FULLREMAP_Msk (0x3U << AFIO_MAPR_TIM3_REMAP_FULLREMAP_Pos) /*!< 0x00000C00 */ #define AFIO_MAPR_TIM3_REMAP_FULLREMAP AFIO_MAPR_TIM3_REMAP_FULLREMAP_Msk /*!< Full remap (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9) */ +#define AFIO_MAPR_TIM4_REMAP_Pos (12U) +#define AFIO_MAPR_TIM4_REMAP_Msk (0x1U << AFIO_MAPR_TIM4_REMAP_Pos) /*!< 0x00001000 */ +#define AFIO_MAPR_TIM4_REMAP AFIO_MAPR_TIM4_REMAP_Msk /*!< TIM4_REMAP bit (TIM4 remapping) */ #define AFIO_MAPR_CAN_REMAP_Pos (13U) #define AFIO_MAPR_CAN_REMAP_Msk (0x3U << AFIO_MAPR_CAN_REMAP_Pos) /*!< 0x00006000 */ @@ -10001,12 +10063,18 @@ typedef struct #define DBGMCU_CR_DBG_TIM3_STOP_Pos (12U) #define DBGMCU_CR_DBG_TIM3_STOP_Msk (0x1U << DBGMCU_CR_DBG_TIM3_STOP_Pos) /*!< 0x00001000 */ #define DBGMCU_CR_DBG_TIM3_STOP DBGMCU_CR_DBG_TIM3_STOP_Msk /*!< TIM3 counter stopped when core is halted */ +#define DBGMCU_CR_DBG_TIM4_STOP_Pos (13U) +#define DBGMCU_CR_DBG_TIM4_STOP_Msk (0x1U << DBGMCU_CR_DBG_TIM4_STOP_Pos) /*!< 0x00002000 */ +#define DBGMCU_CR_DBG_TIM4_STOP DBGMCU_CR_DBG_TIM4_STOP_Msk /*!< TIM4 counter stopped when core is halted */ #define DBGMCU_CR_DBG_CAN1_STOP_Pos (14U) #define DBGMCU_CR_DBG_CAN1_STOP_Msk (0x1U << DBGMCU_CR_DBG_CAN1_STOP_Pos) /*!< 0x00004000 */ #define DBGMCU_CR_DBG_CAN1_STOP DBGMCU_CR_DBG_CAN1_STOP_Msk /*!< Debug CAN1 stopped when Core is halted */ #define DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT_Pos (15U) #define DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT_Msk (0x1U << DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT_Pos) /*!< 0x00008000 */ #define DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT DBGMCU_CR_DBG_I2C1_SMBUS_TIMEOUT_Msk /*!< SMBUS timeout mode stopped when Core is halted */ +#define DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT_Pos (16U) +#define DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT_Msk (0x1U << DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT_Pos) /*!< 0x00010000 */ +#define DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT DBGMCU_CR_DBG_I2C2_SMBUS_TIMEOUT_Msk /*!< SMBUS timeout mode stopped when Core is halted */ /******************************************************************************/ /* */ @@ -10179,6 +10247,30 @@ typedef struct #define FLASH_WRP0_nWRP0_Msk (0xFFU << FLASH_WRP0_nWRP0_Pos) /*!< 0x0000FF00 */ #define FLASH_WRP0_nWRP0 FLASH_WRP0_nWRP0_Msk /*!< Flash memory write protection complemented option bytes */ +/****************** Bit definition for FLASH_WRP1 register ******************/ +#define FLASH_WRP1_WRP1_Pos (16U) +#define FLASH_WRP1_WRP1_Msk (0xFFU << FLASH_WRP1_WRP1_Pos) /*!< 0x00FF0000 */ +#define FLASH_WRP1_WRP1 FLASH_WRP1_WRP1_Msk /*!< Flash memory write protection option bytes */ +#define FLASH_WRP1_nWRP1_Pos (24U) +#define FLASH_WRP1_nWRP1_Msk (0xFFU << FLASH_WRP1_nWRP1_Pos) /*!< 0xFF000000 */ +#define FLASH_WRP1_nWRP1 FLASH_WRP1_nWRP1_Msk /*!< Flash memory write protection complemented option bytes */ + +/****************** Bit definition for FLASH_WRP2 register ******************/ +#define FLASH_WRP2_WRP2_Pos (0U) +#define FLASH_WRP2_WRP2_Msk (0xFFU << FLASH_WRP2_WRP2_Pos) /*!< 0x000000FF */ +#define FLASH_WRP2_WRP2 FLASH_WRP2_WRP2_Msk /*!< Flash memory write protection option bytes */ +#define FLASH_WRP2_nWRP2_Pos (8U) +#define FLASH_WRP2_nWRP2_Msk (0xFFU << FLASH_WRP2_nWRP2_Pos) /*!< 0x0000FF00 */ +#define FLASH_WRP2_nWRP2 FLASH_WRP2_nWRP2_Msk /*!< Flash memory write protection complemented option bytes */ + +/****************** Bit definition for FLASH_WRP3 register ******************/ +#define FLASH_WRP3_WRP3_Pos (16U) +#define FLASH_WRP3_WRP3_Msk (0xFFU << FLASH_WRP3_WRP3_Pos) /*!< 0x00FF0000 */ +#define FLASH_WRP3_WRP3 FLASH_WRP3_WRP3_Msk /*!< Flash memory write protection option bytes */ +#define FLASH_WRP3_nWRP3_Pos (24U) +#define FLASH_WRP3_nWRP3_Msk (0xFFU << FLASH_WRP3_nWRP3_Pos) /*!< 0xFF000000 */ +#define FLASH_WRP3_nWRP3 FLASH_WRP3_nWRP3_Msk /*!< Flash memory write protection complemented option bytes */ + /** @@ -10224,7 +10316,8 @@ typedef struct #define IS_GPIO_ALL_INSTANCE(INSTANCE) (((INSTANCE) == GPIOA) || \ ((INSTANCE) == GPIOB) || \ ((INSTANCE) == GPIOC) || \ - ((INSTANCE) == GPIOD)) + ((INSTANCE) == GPIOD) || \ + ((INSTANCE) == GPIOE)) /**************************** GPIO Alternate Function Instances ***************/ #define IS_GPIO_AF_INSTANCE(INSTANCE) IS_GPIO_ALL_INSTANCE(INSTANCE) @@ -10233,7 +10326,8 @@ typedef struct #define IS_GPIO_LOCK_INSTANCE(INSTANCE) IS_GPIO_ALL_INSTANCE(INSTANCE) /******************************** I2C Instances *******************************/ -#define IS_I2C_ALL_INSTANCE(INSTANCE) ((INSTANCE) == I2C1) +#define IS_I2C_ALL_INSTANCE(INSTANCE) (((INSTANCE) == I2C1) || \ + ((INSTANCE) == I2C2)) /******************************* SMBUS Instances ******************************/ #define IS_SMBUS_ALL_INSTANCE IS_I2C_ALL_INSTANCE @@ -10242,86 +10336,102 @@ typedef struct #define IS_IWDG_ALL_INSTANCE(INSTANCE) ((INSTANCE) == IWDG) /******************************** SPI Instances *******************************/ -#define IS_SPI_ALL_INSTANCE(INSTANCE) ((INSTANCE) == SPI1) +#define IS_SPI_ALL_INSTANCE(INSTANCE) (((INSTANCE) == SPI1) || \ + ((INSTANCE) == SPI2)) /****************************** START TIM Instances ***************************/ /****************************** TIM Instances *********************************/ #define IS_TIM_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_ADVANCED_INSTANCE(INSTANCE) ((INSTANCE) == TIM1) #define IS_TIM_CC1_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CC2_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CC3_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CC4_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CLOCKSOURCE_TIX_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_OCXREF_CLEAR_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_ENCODER_INTERFACE_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_XOR_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_MASTER_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_SLAVE_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_DMABURST_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_BREAK_INSTANCE(INSTANCE)\ ((INSTANCE) == TIM1) @@ -10340,6 +10450,12 @@ typedef struct ((CHANNEL) == TIM_CHANNEL_4))) \ || \ (((INSTANCE) == TIM3) && \ + (((CHANNEL) == TIM_CHANNEL_1) || \ + ((CHANNEL) == TIM_CHANNEL_2) || \ + ((CHANNEL) == TIM_CHANNEL_3) || \ + ((CHANNEL) == TIM_CHANNEL_4))) \ + || \ + (((INSTANCE) == TIM4) && \ (((CHANNEL) == TIM_CHANNEL_1) || \ ((CHANNEL) == TIM_CHANNEL_2) || \ ((CHANNEL) == TIM_CHANNEL_3) || \ @@ -10354,7 +10470,8 @@ typedef struct #define IS_TIM_COUNTER_MODE_SELECT_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_REPETITION_COUNTER_INSTANCE(INSTANCE)\ ((INSTANCE) == TIM1) @@ -10362,28 +10479,33 @@ typedef struct #define IS_TIM_CLOCK_DIVISION_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_DMA_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_DMA_CC_INSTANCE(INSTANCE)\ (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_COMMUTATION_EVENT_INSTANCE(INSTANCE)\ ((INSTANCE) == TIM1) #define IS_TIM_ETR_INSTANCE(INSTANCE) (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(INSTANCE) (((INSTANCE) == TIM1) || \ ((INSTANCE) == TIM2) || \ - ((INSTANCE) == TIM3)) + ((INSTANCE) == TIM3) || \ + ((INSTANCE) == TIM4)) #define IS_TIM_32B_COUNTER_INSTANCE(INSTANCE) 0U @@ -10392,39 +10514,48 @@ typedef struct /******************** USART Instances : Synchronous mode **********************/ #define IS_USART_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2)) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /******************** UART Instances : Asynchronous mode **********************/ #define IS_UART_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /******************** UART Instances : Half-Duplex mode **********************/ #define IS_UART_HALFDUPLEX_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /******************** UART Instances : LIN mode **********************/ #define IS_UART_LIN_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /****************** UART Instances : Hardware Flow control ********************/ #define IS_UART_HWFLOW_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /********************* UART Instances : Smard card mode ***********************/ #define IS_SMARTCARD_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /*********************** UART Instances : IRDA mode ***************************/ #define IS_IRDA_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /***************** UART Instances : Multi-Processor mode **********************/ #define IS_UART_MULTIPROCESSOR_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2) ) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /***************** UART Instances : DMA mode available **********************/ #define IS_UART_DMA_INSTANCE(INSTANCE) (((INSTANCE) == USART1) || \ - ((INSTANCE) == USART2)) + ((INSTANCE) == USART2) || \ + ((INSTANCE) == USART3)) /****************************** RTC Instances *********************************/ #define IS_RTC_ALL_INSTANCE(INSTANCE) ((INSTANCE) == RTC) @@ -10504,7 +10635,7 @@ typedef struct } #endif /* __cplusplus */ -#endif /* __STM32F103x6_H */ +#endif /* __STM32F103xB_H */ diff --git a/Inc/usb_parsing.h b/Inc/usb_parsing.h new file mode 100644 index 0000000..9552235 --- /dev/null +++ b/Inc/usb_parsing.h @@ -0,0 +1,16 @@ +/* + * usb_parsing.h + * + * The MIT License. + * Created on: 15.11.2018 + * Author: Mateusz Salamon + * www.msalamon.pl + * mateusz@msalamon.pl + */ + +#ifndef USB_PARSING_H_ +#define USB_PARSING_H_ + +void USB_Parsing(void); + +#endif /* USB_PARSING_H_ */ diff --git a/Inc/ws2812b_fx.h b/Inc/ws2812b_fx.h index bd3c275..31ad19a 100644 --- a/Inc/ws2812b_fx.h +++ b/Inc/ws2812b_fx.h @@ -21,10 +21,6 @@ #define DEFAULT_SPEED 150 #define SPEED_MAX 65535 -#define BRIGHTNESS_MIN 0 -#define DEFAULT_BRIGHTNESS 50 -#define BRIGHTNESS_MAX 255 - #define MODE_COUNT 58 #define DEFAULT_MODE 0 @@ -43,6 +39,11 @@ #define ORANGE (uint32_t)0xFF3000 #define PINK (uint32_t)0xFF1493 +typedef enum { + FX_OK = 0, + FX_ERROR = 1 +} FX_STATUS; + typedef enum { FX_MODE_STATIC, FX_MODE_WHITE_TO_COLOR, @@ -104,93 +105,47 @@ FX_MODE_TRICOLOR_CHASE, FX_MODE_ICU, } fx_mode; +FX_STATUS WS2812BFX_Init(uint8_t Segments); +FX_STATUS WS2812BFX_SegmentIncrease(void); +FX_STATUS WS2812BFX_SegmentDecrease(void); +uint8_t WS2812BFX_GetSegmentsQuantity(void); + void WS2812BFX_SysTickCallback(void); void WS2812BFX_Callback(void); -void WS2812BFX_Start(void); -void WS2812BFX_Stop(void); -void WS2812BFX_SetMode(fx_mode mode); -void WS2812BFX_NextMode(void); -void WS2812BFX_PrevMode(void); +FX_STATUS WS2812BFX_Start(uint8_t Segment); +FX_STATUS WS2812BFX_Stop(uint8_t Segment); +FX_STATUS WS2812BFX_IsRunning(uint8_t Segment, uint8_t *Running); + +FX_STATUS WS2812BFX_SetMode(uint8_t Segment, fx_mode Mode); +FX_STATUS WS2812BFX_GetMode(uint8_t Segment, fx_mode *Mode); +FX_STATUS WS2812BFX_NextMode(uint8_t Segment); +FX_STATUS WS2812BFX_PrevMode(uint8_t Segment); +FX_STATUS WS2812BFX_SetReverse(uint8_t Segment, uint8_t Reverse); +FX_STATUS WS2812BFX_GetReverse(uint8_t Segment, uint8_t *Reverse); -void WS2812BFX_SetSpeed(uint16_t Speed); -void WS2812BFX_IncreaseSpeed(uint16_t Speed); -void WS2812BFX_DecreaseSpeed(uint16_t Speed); +FX_STATUS WS2812BFX_SetSegmentSize(uint8_t Segment, uint16_t Start, uint16_t Stop); +FX_STATUS WS2812BFX_GetSegmentSize(uint8_t Segment, uint16_t *Start, uint16_t *Stop); +FX_STATUS WS2812BFX_SegmentIncreaseEnd(uint8_t Segment); +FX_STATUS WS2812BFX_SegmentDecreaseEnd(uint8_t Segment); +FX_STATUS WS2812BFX_SegmentIncreaseStart(uint8_t Segment); +FX_STATUS WS2812BFX_SegmentDecreaseStart(uint8_t Segment); + +FX_STATUS WS2812BFX_SetSpeed(uint8_t Segment, uint16_t Speed); +FX_STATUS WS2812BFX_GetSpeed(uint8_t Segment, uint16_t *Speed); +FX_STATUS WS2812BFX_IncreaseSpeed(uint8_t Segment, uint16_t Speed); +FX_STATUS WS2812BFX_DecreaseSpeed(uint8_t Segment, uint16_t Speed); void WS2812BFX_SetColorStruct(uint8_t id, ws2812b_color c); void WS2812BFX_SetColorRGB(uint8_t id, uint8_t r, uint8_t g, uint8_t b); +FX_STATUS WS2812BFX_GetColorRGB(uint8_t id, uint8_t *r, uint8_t *g, uint8_t *b); void WS2812BFX_SetColorHSV(uint8_t id, uint16_t h, uint8_t s, uint8_t v); void WS2812BFX_SetColor(uint8_t id, uint32_t c); -void WS2812BFX_SetAll(uint32_t c); -void WS2812BFX_SetAllRGB(uint8_t r, uint8_t g, uint8_t b); + +FX_STATUS WS2812BFX_SetAll(uint8_t Segment, uint32_t c); +FX_STATUS WS2812BFX_SetAllRGB(uint8_t Segment, uint8_t r, uint8_t g, uint8_t b); void WS2812BFX_RGBtoHSV(uint8_t r, uint8_t g, uint8_t b, uint16_t *h, uint8_t *s, uint8_t *v); void WS2812BFX_HSVtoRGB(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b); -/* - * - * MODES - * - * */ -void -strip_off(void), -mode_static(void), -mode_white_to_color(void), -mode_black_to_color(void), -mode_blink(void), -mode_blink_rainbow(void), -mode_strobe(void), -mode_strobe_rainbow(void), -mode_breath(void), -mode_color_wipe(void), -mode_color_wipe_inv(void), -mode_color_wipe_rev(void), -mode_color_wipe_rev_inv(void), -mode_color_wipe_random(void), -mode_color_sweep_random(void), -mode_random_color(void), -mode_single_dynamic(void), -mode_multi_dynamic(void), -mode_rainbow(void), -mode_rainbow_cycle(void), -mode_fade(void), -mode_scan(void), -mode_dual_scan(void), -mode_theater_chase(void), -mode_theater_chase_rainbow(void), -mode_running_lights(void), -mode_twinkle(void), -mode_twinkle_random(void), -mode_twinkle_fade(void), -mode_twinkle_fade_random(void), -mode_sparkle(void), -mode_flash_sparkle(void), -mode_hyper_sparkle(void), -mode_multi_strobe(void), -mode_chase_white(void), -mode_chase_color(void), -mode_chase_random(void), -mode_chase_rainbow(void), -mode_chase_flash(void), -mode_chase_flash_random(void), -mode_chase_rainbow_white(void), -mode_chase_blackout(void), -mode_chase_blackout_rainbow(void), -mode_running_color(void), -mode_running_red_blue(void), -mode_running_random(void), -mode_larson_scanner(void), -mode_comet(void), -mode_fireworks(void), -mode_fireworks_random(void), -mode_merry_christmas(void), -mode_fire_flicker(void), -mode_fire_flicker_soft(void), -mode_fire_flicker_intense(void), -mode_circus_combustus(void), -mode_halloween(void), -mode_bicolor_chase(void), -mode_tricolor_chase(void), -mode_icu(void) -; #endif /* WS2812B_FX_H_ */ diff --git a/STM32F103C6Tx_FLASH.ld b/STM32F103C8Tx_FLASH.ld similarity index 94% rename from STM32F103C6Tx_FLASH.ld rename to STM32F103C8Tx_FLASH.ld index 8f7b116..55d753a 100644 --- a/STM32F103C6Tx_FLASH.ld +++ b/STM32F103C8Tx_FLASH.ld @@ -4,8 +4,8 @@ ** File : LinkerScript.ld ** -** Abstract : Linker script for STM32F103C6Tx Device with -** 32KByte FLASH, 10KByte RAM +** Abstract : Linker script for STM32F103C8Tx Device with +** 64KByte FLASH, 20KByte RAM ** ** Set heap size, stack size and stack location according ** to application requirements. @@ -33,7 +33,7 @@ ENTRY(Reset_Handler) /* Highest address of the user mode stack */ -_estack = 0x20002800; /* end of RAM */ +_estack = 0x20005000; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ @@ -41,8 +41,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 32K +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K } /* Define output sections */ diff --git a/Src/main.c b/Src/main.c index faad4f5..f7ab260 100644 --- a/Src/main.c +++ b/Src/main.c @@ -55,22 +55,16 @@ #include "gpio.h" /* USER CODE BEGIN Includes */ +#include #include "ws2812b.h" #include "ws2812b_fx.h" -#include "usbd_cdc_if.h" +#include "usb_parsing.h" -#define MODE_DELAY 15000 /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ -uint8_t USBDataTX[40]; // Array for transmission USB messages -uint8_t USBDataLength; // USB message length - -volatile uint16_t ModeTimer; -uint8_t Mode; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -82,7 +76,7 @@ void SystemClock_Config(void); /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ - +void USB_Parsing(void); /* USER CODE END 0 */ /** @@ -119,48 +113,44 @@ int main(void) MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ WS2812B_Init(&hspi1); - WS2812BFX_SetSpeed(150); - WS2812BFX_SetColorRGB(0, 0,0,0); - WS2812BFX_SetColorRGB(1, 64,0,0); - WS2812BFX_SetColorRGB(2, 0,0,64); - Mode = 0; - WS2812BFX_SetMode(Mode); - WS2812BFX_Start(); - WS2812BFX_SetColorRGB(0, 0, 64,0); + WS2812BFX_Init(3); // Start 3 segments + + WS2812BFX_SetSpeed(0, 5000); // Speed of segment 0 + WS2812BFX_SetSpeed(1, 2000); // Speed of segment 1 + WS2812BFX_SetSpeed(2, 500); // Speed of segment 2 + WS2812BFX_SetColorRGB(0, 32,0,64); // Set color 0 + WS2812BFX_SetColorRGB(1, 32,0,0); // Set color 1 + WS2812BFX_SetColorRGB(2, 0,64,0); // Set color 2 + WS2812BFX_SetMode(0, FX_MODE_WHITE_TO_COLOR); // Set mode segment 0 + + WS2812BFX_SetColorRGB(0, 16,64,0); + WS2812BFX_SetColorRGB(1, 0,32,64); + WS2812BFX_SetColorRGB(2, 64,0,0); + WS2812BFX_SetMode(1, FX_MODE_BLACK_TO_COLOR); // Set mode segment 1 + + WS2812BFX_SetColorRGB(0, 16,64,0); + WS2812BFX_SetColorRGB(1, 0,32,64); + WS2812BFX_SetColorRGB(2, 64,0,0); + WS2812BFX_SetMode(2, FX_MODE_COLOR_WIPE); // Set mode segment 2 + + WS2812BFX_Start(0); // Start segment 0 + WS2812BFX_Start(1); // Start segment 1 + WS2812BFX_Start(2); // Start segment 2 + HAL_Delay(200); - ModeTimer = MODE_DELAY; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { + WS2812BFX_Callback(); // FX effects calllback + + USB_Parsing(); // USB communication parsing /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - WS2812BFX_Callback(); - - if(!ModeTimer) - { - for(uint8_t i = 0; i < WS2812B_LEDS; i++) - WS2812B_SetDiodeColor(i, 0); - WS2812B_Refresh(); - - USBDataLength = sprintf((char*)USBDataTX, "Mode number: %d\n\r", Mode); - CDC_Transmit_FS(USBDataTX, USBDataLength); - if(Mode == 1 || Mode == 2) - WS2812BFX_SetSpeed(3000); - else - WS2812BFX_SetSpeed(200); - - WS2812BFX_SetMode(Mode); - - if(Mode < MODE_COUNT - 1) Mode++; - else Mode = 0; - - ModeTimer = MODE_DELAY; - } } /* USER CODE END 3 */ @@ -228,8 +218,7 @@ void SystemClock_Config(void) /* USER CODE BEGIN 4 */ void HAL_SYSTICK_Callback(void) { - WS2812BFX_SysTickCallback(); - if(ModeTimer) ModeTimer--; + WS2812BFX_SysTickCallback(); // FX effects software timers } /* USER CODE END 4 */ diff --git a/Src/usb_parsing.c b/Src/usb_parsing.c new file mode 100644 index 0000000..47c77ac --- /dev/null +++ b/Src/usb_parsing.c @@ -0,0 +1,313 @@ +/* + * usb_parsing.c + * + * The MIT License. + * Created on: 15.11.2018 + * Author: Mateusz Salamon + * www.msalamon.pl + * mateusz@msalamon.pl + */ + +#include "stm32f1xx_hal.h" +#include "usbd_cdc_if.h" +#include +#include + +#include "ws2812b.h" +#include "ws2812b_fx.h" +#include "usb_parsing.h" + +uint8_t USBDataRX[40]; // Array for receive USB messages +uint8_t USBReceivedDataFlag; // Received USB data flag +uint8_t USBDataTX[40]; // Array for transmission USB messages +uint8_t USBDataLength; // USB message length + +void UnknownCommand(void) +{ + USBDataLength = sprintf((char*)USBDataTX, "Unknown command\n\r"); +} + +void ColorControl(void) +{ + char *buf; + int16_t Seg; + uint8_t Color[3]; + + if((buf = strtok((char*)USBDataRX+1, ","))) // Segment number + { + Seg = atoi(buf); + + for(uint8_t i = 0; i < 3; i++) + { + if((buf = strtok(NULL, ","))) // Speed + { + Color[i] = atoi(buf); + } + else + { + USBDataLength = sprintf((char*)USBDataTX, "Color command error\n\r"); + return; + } + } + + WS2812BFX_SetColorRGB(Seg, Color[0], Color[1], Color[2]); + USBDataLength = sprintf((char*)USBDataTX, "ColorID:%d Value:%dR, %dG, %dB\n\r", Seg, Color[0], Color[1], Color[2]); + return; + } + USBDataLength = sprintf((char*)USBDataTX, "Color command error\n\r"); +} + +void SpeedControl(void) +{ + char *buf; + int16_t Seg; + uint16_t Speed; + + if((buf = strtok((char*)USBDataRX+1, ","))) // Segment number + { + Seg = atoi(buf); + + if((buf = strtok(NULL, ","))) // Speed + { + if((Speed = atoi(buf)) > 0) + { + WS2812BFX_SetSpeed(Seg, Speed); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Speed:%d\n\r", Seg, Speed); + return; + } + } + } + USBDataLength = sprintf((char*)USBDataTX, "Speed command error\n\r"); +} + +void ModeControl(void) +{ + char *buf; + int16_t Seg; + int16_t Mode; + + buf = strtok((char*)USBDataRX+1, ","); // Segment number + Seg = atoi(buf); + + if((buf = strtok(NULL, ","))) + { + if(buf[0] == 'S') + { + WS2812BFX_Start(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Start\n\r", Seg); + return; + } + else if(buf[0] == 'T') + { + WS2812BFX_Stop(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Stop\n\r", Seg); + return; + } + else // Mode + { + if((Mode = atoi(buf)) > 0) + { + WS2812BFX_SetMode(Seg, Mode); + + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Mode:%d\n\r", Seg, Mode); + return; + } + } + } + USBDataLength = sprintf((char*)USBDataTX, "mode command error\n\r"); +} + +void SegmentsControl(void) +{ + int16_t Seg; + uint8_t mode_tmp; + if(USBDataRX[1] == '-') + { + WS2812BFX_SegmentDecrease(); + } + else if(USBDataRX[1] == '+') + { + WS2812BFX_SegmentIncrease(); + WS2812BFX_SetMode(WS2812BFX_GetSegmentsQuantity() - 1, rand()%MODE_COUNT); + WS2812BFX_Start(WS2812BFX_GetSegmentsQuantity() - 1); + } + else if((Seg = atoi((char*)(USBDataRX+1))) > 0) + { + WS2812BFX_Init(Seg); + } + else + { + USBDataLength = sprintf((char*)USBDataTX, "Segment command error\n\r"); + return; + } + WS2812BFX_GetMode(WS2812BFX_GetSegmentsQuantity()-1, &mode_tmp); + USBDataLength = sprintf((char*)USBDataTX, "Segments:%d Last mode:%d\n\r", WS2812BFX_GetSegmentsQuantity(), mode_tmp); +} + +void SegmentRangeControl(void) +{ + char *buf; + int16_t Seg; + int16_t Start; + int16_t End; + + buf = strtok((char*)USBDataRX+1, ","); // Segment number + Seg = atoi(buf); + + if((buf = strtok(NULL, ","))) + { + if(buf[0] == 'R') // Range (Stanrt and Stop) + { + if((buf = strtok(NULL, ","))) // Speed + { + if((Start = atoi(buf)) > 0) + { + if((buf = strtok(NULL, ","))) // Speed + { + if((End = atoi(buf)) > 0) + { + WS2812BFX_SetSegmentSize(Seg, Start, End); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Range:%d - %d\n\r", Seg, Start, End); + return; + } + else + USBDataLength = sprintf((char*)USBDataTX, "Segment range End error\n\r"); + return; + } + } + else + USBDataLength = sprintf((char*)USBDataTX, "Segment range Start error\n\r"); + return; + } + } + else if(buf[0] == 'S') //Start + { + if(buf[1] == '+') + { + WS2812BFX_SegmentIncreaseStart(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Start increase\n\r", Seg); + return; + } + if(buf[1] == '-') + { + WS2812BFX_SegmentDecreaseStart(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d Start decrease\n\r", Seg); + return; + } + + } + else if(buf[0] == 'E') //END + { + if(buf[1] == '+') + { + WS2812BFX_SegmentIncreaseEnd(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d End increase\n\r", Seg); + return; + } + if(buf[1] == '-') + { + WS2812BFX_SegmentDecreaseEnd(Seg); + USBDataLength = sprintf((char*)USBDataTX, "Segment:%d End decrease\n\r", Seg); + return; + } + } + } + USBDataLength = sprintf((char*)USBDataTX, "Segment range command error\n\r"); +} + +void PrintHelp(void) +{ + + USBDataLength = sprintf((char*)USBDataTX, "\033[2J\033[0;0H"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "==============HELP=============\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "Change Segments quantity:\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Sx' Set x segments(1 - LEDs/2)\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'S+' add one segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'S-' remove one segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "Change Segments length:\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Rx,S+' Increase start point x "); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Rx,S-' Decrease start point x "); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Rx,E+' Increase end point x "); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Rx,E-' Decrease end point x "); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Rx,R,y,z' Set start(y) and stop(z) po"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "int x segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "Change segment's mode:\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Mx,S' Start segment x\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Mx,T' Stop segment x\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Mx,y' Set y mode for x segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "Change segment's speed:\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Vx,y' Set y speed for x segment\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "Set color:\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, " 'Cx,r,g,b' x - ColorID, rgb values\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); + USBDataLength = sprintf((char*)USBDataTX, "===============================\n\r"); + while(USBD_BUSY == CDC_Transmit_FS(USBDataTX, USBDataLength)); +} + +void USB_Parsing(void) +{ + if(USBReceivedDataFlag == 1) + { + USBReceivedDataFlag = 0; + + switch (USBDataRX[0]) + { + case 'C': + ColorControl(); + break; + + case 'V': + SpeedControl(); + break; + + case 'M': + ModeControl(); + break; + + case 'S': + SegmentsControl(); + break; + + case 'R': + SegmentRangeControl(); + break; + + case 'H': + PrintHelp(); + break; + default: + UnknownCommand(); + break; + } + + CDC_Transmit_FS(USBDataTX, USBDataLength); // Send confirmation message + } +} diff --git a/Src/usbd_cdc_if.c b/Src/usbd_cdc_if.c index daa2db6..4e8fb5f 100644 --- a/Src/usbd_cdc_if.c +++ b/Src/usbd_cdc_if.c @@ -93,8 +93,8 @@ /* USER CODE BEGIN PRIVATE_DEFINES */ /* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ -#define APP_RX_DATA_SIZE 1000 -#define APP_TX_DATA_SIZE 1000 +#define APP_RX_DATA_SIZE 40 +#define APP_TX_DATA_SIZE 40 /* USER CODE END PRIVATE_DEFINES */ /** @@ -293,6 +293,18 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) /* USER CODE BEGIN 6 */ USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS); + + extern uint8_t USBDataRX[40]; // Array for receive USB messages + extern uint8_t USBReceivedDataFlag; // Received USB data flag + + for(uint8_t i = 0; i < 40; i++) + { + USBDataRX[i] = 0; // Clear the RX buffer + } + + strlcpy(USBDataRX, Buf, (*Len) + 1); // Copy data to receive buffer + USBReceivedDataFlag = 1; // Set the receive flag + return (USBD_OK); /* USER CODE END 6 */ } diff --git a/Src/ws2812b_fx.c b/Src/ws2812b_fx.c index 4ef3931..80387cb 100644 --- a/Src/ws2812b_fx.c +++ b/Src/ws2812b_fx.c @@ -19,29 +19,115 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)<(b))?(b):(a)) -uint8_t mMode_index = DEFAULT_MODE; -uint16_t mSpeed = DEFAULT_SPEED; -uint8_t mBrightness = DEFAULT_BRIGHTNESS; +#define SEGMENT_LENGTH (Ws28b12b_Segments[mActualSegment].IdStop - Ws28b12b_Segments[mActualSegment].IdStart + 1) +#define IS_REVERSE Ws28b12b_Segments[mActualSegment].Reverse + uint8_t mRunning; uint8_t mTriggered; +uint8_t mActualSegment; -volatile uint32_t iModeDelay; -uint8_t mActualMode; -uint32_t mCounterModeCall; -uint32_t mCounterModeStep; -unsigned long mModeLastCallTime; +uint8_t mSegments; uint32_t mColor[NUM_COLORS]; -uint32_t mModeColor[NUM_COLORS]; ws2812b_color mColor_w[NUM_COLORS]; -ws2812b_color mModeColor_w[NUM_COLORS]; -uint8_t mAuxParam; -uint16_t mAuxParam16b; -uint8_t mCycle; +typedef struct ws2812bfx_s +{ + volatile uint32_t ModeDelay; // Segment SW timer counter + + uint16_t IdStart; // Start segment point + uint16_t IdStop; // End segment point + + uint8_t Running : 1; // Is sector running + uint8_t ActualMode; // Sector mode setting + uint8_t Reverse : 1; // Is reverted mode + uint32_t CounterModeCall; // Numbers of calls + uint32_t CounterModeStep; // Call step + + uint16_t Speed; // Segment speed + + uint32_t ModeColor[NUM_COLORS]; // Mode color 32 bit representation + ws2812b_color ModeColor_w[NUM_COLORS]; // Mode color struct representation + + uint8_t AuxParam; // Computing variable + uint16_t AuxParam16b; // Computing variable + uint8_t Cycle : 1; // Cycle variable + + void (*mModeCallback)(void); // Sector mode callback +} ws2812bfx_s; + +ws2812bfx_s *Ws28b12b_Segments = NULL; void (*mModeCallback)(void); + +/* + * + * MODES + * + * */ +void +strip_off(void), +mode_static(void), +mode_white_to_color(void), +mode_black_to_color(void), +mode_blink(void), +mode_blink_rainbow(void), +mode_strobe(void), +mode_strobe_rainbow(void), +mode_breath(void), +mode_color_wipe(void), +mode_color_wipe_inv(void), +mode_color_wipe_rev(void), +mode_color_wipe_rev_inv(void), +mode_color_wipe_random(void), +mode_color_sweep_random(void), +mode_random_color(void), +mode_single_dynamic(void), +mode_multi_dynamic(void), +mode_rainbow(void), +mode_rainbow_cycle(void), +mode_fade(void), +mode_scan(void), +mode_dual_scan(void), +mode_theater_chase(void), +mode_theater_chase_rainbow(void), +mode_running_lights(void), +mode_twinkle(void), +mode_twinkle_random(void), +mode_twinkle_fade(void), +mode_twinkle_fade_random(void), +mode_sparkle(void), +mode_flash_sparkle(void), +mode_hyper_sparkle(void), +mode_multi_strobe(void), +mode_chase_white(void), +mode_chase_color(void), +mode_chase_random(void), +mode_chase_rainbow(void), +mode_chase_flash(void), +mode_chase_flash_random(void), +mode_chase_rainbow_white(void), +mode_chase_blackout(void), +mode_chase_blackout_rainbow(void), +mode_running_color(void), +mode_running_red_blue(void), +mode_running_random(void), +mode_larson_scanner(void), +mode_comet(void), +mode_fireworks(void), +mode_fireworks_random(void), +mode_merry_christmas(void), +mode_fire_flicker(void), +mode_fire_flicker_soft(void), +mode_fire_flicker_intense(void), +mode_circus_combustus(void), +mode_halloween(void), +mode_bicolor_chase(void), +mode_tricolor_chase(void), +mode_icu(void) +; + void (*mMode[MODE_COUNT])(void) = { mode_static, @@ -104,92 +190,333 @@ void (*mMode[MODE_COUNT])(void) = mode_icu }; +FX_STATUS WS2812BFX_Init(uint8_t Segments) +{ + if(Segments == 0 || Segments >= (WS2812B_LEDS / 2)) return FX_ERROR; + + uint16_t div = 0; + ws2812bfx_s *SegmentsTmp = NULL; + + SegmentsTmp = calloc(Segments, sizeof(ws2812bfx_s)); // Assign the space for new segments + + if(SegmentsTmp == NULL) return FX_ERROR; // If assigning failed + + if(Ws28b12b_Segments == NULL) + { + mSegments = Segments; + + for(uint8_t i = 0; i < mSegments; i++) + { + SegmentsTmp[i].Speed = DEFAULT_SPEED; + SegmentsTmp[i].Running = DEFAULT_MODE; + + SegmentsTmp[i].IdStart = div; + div += ((WS2812B_LEDS + 1) / Segments) - 1; + SegmentsTmp[i].IdStop = div; + if(SegmentsTmp[i].IdStop >= WS2812B_LEDS) Ws28b12b_Segments[i].IdStop = WS2812B_LEDS - 1; + div++; + } + } + else // Ws28b12b_Segments was before initialized + { + for(uint8_t i = 0; i < (Segments>mSegments?mSegments:Segments); i++) + { + SegmentsTmp[i].ModeDelay = Ws28b12b_Segments[i].ModeDelay; + + SegmentsTmp[i].IdStart = div; + div += ((WS2812B_LEDS + 1) / Segments) - 1; + SegmentsTmp[i].IdStop = div; + if(SegmentsTmp[i].IdStop >= WS2812B_LEDS) Ws28b12b_Segments[i].IdStop = WS2812B_LEDS - 1; + div++; + + SegmentsTmp[i].Running = Ws28b12b_Segments[i].Running; + SegmentsTmp[i].ActualMode = Ws28b12b_Segments[i].ActualMode; + SegmentsTmp[i].Reverse = Ws28b12b_Segments[i].Reverse; + SegmentsTmp[i].CounterModeCall = Ws28b12b_Segments[i].CounterModeCall; + SegmentsTmp[i].CounterModeStep = Ws28b12b_Segments[i].CounterModeStep; + SegmentsTmp[i].Speed = Ws28b12b_Segments[i].Speed; + for(uint8_t j = 0; j < NUM_COLORS; j++) + { + SegmentsTmp[i].ModeColor[j] = Ws28b12b_Segments[i].ModeColor[j]; + SegmentsTmp[i].ModeColor_w[j] = Ws28b12b_Segments[i].ModeColor_w[j]; + } + SegmentsTmp[i].AuxParam = Ws28b12b_Segments[i].AuxParam; + SegmentsTmp[i].AuxParam16b = Ws28b12b_Segments[i].AuxParam16b; + SegmentsTmp[i].Cycle = Ws28b12b_Segments[i].Cycle; + SegmentsTmp[i].mModeCallback = Ws28b12b_Segments[i].mModeCallback; + } + + if(Segments > mSegments) // Add new Segment + { + SegmentsTmp[Segments - 1].Speed = DEFAULT_SPEED; + SegmentsTmp[Segments - 1].ActualMode = DEFAULT_MODE; + SegmentsTmp[Segments - 1].Running = 0; // Sany new segment is stopped by default + + SegmentsTmp[Segments - 1].IdStart = div; + div += ((WS2812B_LEDS + 1) / Segments) - 1; + SegmentsTmp[Segments - 1].IdStop = WS2812B_LEDS - 1; + } + + mSegments = Segments; + } + + free(Ws28b12b_Segments); // Free previous array if reinit + Ws28b12b_Segments = SegmentsTmp; + return FX_OK; +} + +uint8_t WS2812BFX_GetSegmentsQuantity(void) +{ + return mSegments; +} + +FX_STATUS WS2812BFX_SegmentIncrease(void) +{ + if(mSegments < (WS2812B_LEDS - 1)) + { + WS2812BFX_Init(mSegments + 1); + return FX_OK; + } + return FX_ERROR; +} + +FX_STATUS WS2812BFX_SegmentDecrease(void) +{ + if(mSegments > 1) + { + WS2812BFX_Init(mSegments - 1); + return FX_OK; + } + return FX_ERROR; +} + void WS2812BFX_SysTickCallback(void) { - if(iModeDelay > 0) iModeDelay--; + for(uint8_t i = 0; i < mSegments; i++) + if(Ws28b12b_Segments[i].ModeDelay > 0) Ws28b12b_Segments[i].ModeDelay--; } -void WS2812BFX_Callback(void) +void WS2812BFX_Callback() { + static uint8_t trig = 0;; if(mRunning || mTriggered) { - if(!iModeDelay) + for(uint8_t i = 0; i < mSegments; i++) + { + if(Ws28b12b_Segments[i].ModeDelay == 0) + { + if(Ws28b12b_Segments[i].Running) + { + mActualSegment = i; + Ws28b12b_Segments[i].mModeCallback(); + Ws28b12b_Segments[i].CounterModeCall++; + trig = 1; + } + } + } + if(trig) { - mModeCallback(); WS2812B_Refresh(); - mCounterModeCall++; + trig = 0; } } } -void WS2812BFX_SetMode(fx_mode mode) +FX_STATUS WS2812BFX_SetMode(uint8_t Segment, fx_mode Mode) { - mCounterModeCall = 0; - mCounterModeStep = 0; - mModeLastCallTime = 0; - mActualMode = mode; - mCycle = 0; - mModeCallback = mMode[mActualMode]; + if(Segment >= mSegments) return FX_ERROR; + Ws28b12b_Segments[Segment].CounterModeCall = 0; + Ws28b12b_Segments[Segment].CounterModeStep = 0; + Ws28b12b_Segments[Segment].ActualMode = Mode; + Ws28b12b_Segments[Segment].mModeCallback = mMode[Mode]; for(uint8_t i = 0; i < NUM_COLORS; i++) { - mModeColor[i] = mColor[i]; - mModeColor_w[i].red = mColor_w[i].red; - mModeColor_w[i].green = mColor_w[i].green; - mModeColor_w[i].blue = mColor_w[i].blue; + Ws28b12b_Segments[Segment].ModeColor[i] = mColor[i]; + Ws28b12b_Segments[Segment].ModeColor_w[i].red = mColor_w[i].red; + Ws28b12b_Segments[Segment].ModeColor_w[i].green = mColor_w[i].green; + Ws28b12b_Segments[Segment].ModeColor_w[i].blue = mColor_w[i].blue; } + return FX_OK; } -void WS2812BFX_NextMode(void) +FX_STATUS WS2812BFX_GetMode(uint8_t Segment, fx_mode *Mode) { - mCounterModeCall = 0; - mCounterModeStep = 0; - mModeLastCallTime = 0; - mActualMode++; - mCycle = 0; - if(mActualMode >= MODE_COUNT) mActualMode = 0; - mModeCallback = mMode[mActualMode]; - for(uint8_t i = 0; i < NUM_COLORS; i++) + if(Segment >= mSegments) return FX_ERROR; + *Mode = Ws28b12b_Segments[Segment].ActualMode; + return FX_OK; +} + +FX_STATUS WS2812BFX_NextMode(uint8_t Segment) +{ + if(Segment >= mSegments) return FX_ERROR; + Ws28b12b_Segments[Segment].CounterModeCall = 0; + Ws28b12b_Segments[Segment].CounterModeStep = 0; + Ws28b12b_Segments[Segment].ActualMode++; + if(Ws28b12b_Segments[Segment].ActualMode >= MODE_COUNT) Ws28b12b_Segments[mActualSegment].ActualMode = 0; + Ws28b12b_Segments[Segment].mModeCallback = mMode[Ws28b12b_Segments[mActualSegment].ActualMode]; + return FX_OK; +} + +FX_STATUS WS2812BFX_PrevMode(uint8_t Segment) +{ + if(Segment >= mSegments) return FX_ERROR; + Ws28b12b_Segments[Segment].CounterModeCall = 0; + Ws28b12b_Segments[Segment].CounterModeStep = 0; + Ws28b12b_Segments[Segment].ActualMode--; + if(Ws28b12b_Segments[Segment].ActualMode == 0) Ws28b12b_Segments[mActualSegment].ActualMode = MODE_COUNT; + Ws28b12b_Segments[Segment].mModeCallback = mMode[Ws28b12b_Segments[mActualSegment].ActualMode]; + return FX_OK; +} + +FX_STATUS WS2812BFX_SetReverse(uint8_t Segment, uint8_t Reverse) +{ + if(Segment >= mSegments) return FX_ERROR; + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + if(Reverse > 1) Reverse = 1; + + Ws28b12b_Segments[Segment].Reverse = Reverse; + return FX_OK; +} + +FX_STATUS WS2812BFX_GetReverse(uint8_t Segment, uint8_t *Reverse) +{ + if(Segment >= mSegments) return FX_ERROR; + *Reverse = Ws28b12b_Segments[Segment].Reverse; + return FX_OK; +} + +FX_STATUS WS2812BFX_SegmentIncreaseStart(uint8_t Segment) +{ + if(Segment >= mSegments) return FX_ERROR; + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + if((Ws28b12b_Segments[Segment].IdStop - Ws28b12b_Segments[Segment].IdStart) > 0) { - mModeColor[i] = mColor[i]; - mModeColor_w[i].red = mColor_w[i].red; - mModeColor_w[i].green = mColor_w[i].green; - mModeColor_w[i].blue = mColor_w[i].blue; + Ws28b12b_Segments[Segment].IdStart++; } + return FX_OK; } -void WS2812BFX_PrevMode(void) +FX_STATUS WS2812BFX_SegmentDecreaseStart(uint8_t Segment) { - mCounterModeCall = 0; - mCounterModeStep = 0; - mModeLastCallTime = 0; - mCycle = 0; - if(mActualMode == 0) mActualMode = MODE_COUNT; - else mActualMode--; - mModeCallback = mMode[mActualMode]; - for(uint8_t i = 0; i < NUM_COLORS; i++) + if(Segment >= mSegments) return FX_ERROR; + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + if(Segment > 0) { - mModeColor[i] = mColor[i]; - mModeColor_w[i].red = mColor_w[i].red; - mModeColor_w[i].green = mColor_w[i].green; - mModeColor_w[i].blue = mColor_w[i].blue; + if(Ws28b12b_Segments[Segment-1].IdStop < (Ws28b12b_Segments[Segment].IdStart - 1)) + { + Ws28b12b_Segments[Segment].IdStart--; + } } + else // Segment == 0 + { + if(0 < Ws28b12b_Segments[Segment].IdStart) + { + Ws28b12b_Segments[Segment].IdStart--; + } + } + return FX_OK; } -void WS2812BFX_Start() +FX_STATUS WS2812BFX_SegmentIncreaseEnd(uint8_t Segment) { - mCounterModeCall = 0; - mCounterModeStep = 0; - mModeLastCallTime = 0; - iModeDelay = 0; + if(Segment >= mSegments) return FX_ERROR; + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + if(Segment < (mSegments - 1)) + { + if(Ws28b12b_Segments[Segment].IdStop < (Ws28b12b_Segments[Segment+1].IdStart - 1)) + { + Ws28b12b_Segments[Segment].IdStop++; + } + + } + else // last Segment + { + if(Ws28b12b_Segments[Segment].IdStop < (WS2812B_LEDS - 1)) + { + Ws28b12b_Segments[Segment].IdStop++; + + } + } + return FX_OK; +} + +FX_STATUS WS2812BFX_SegmentDecreaseEnd(uint8_t Segment) +{ + if(Segment >= mSegments) return FX_ERROR; + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + if((Ws28b12b_Segments[Segment].IdStop - Ws28b12b_Segments[Segment].IdStart) > 0) + { + Ws28b12b_Segments[Segment].IdStop--; + } + return FX_OK; +} + +FX_STATUS WS2812BFX_SetSegmentSize(uint8_t Segment, uint16_t Start, uint16_t Stop) +{ + if(Segment >= mSegments) return FX_ERROR; + if(Start >= (WS2812B_LEDS - 1)) return FX_ERROR; + if(Stop >= (WS2812B_LEDS - 1)) return FX_ERROR; + if(Start > Stop) return FX_ERROR; + + WS2812BFX_SetAll(Segment, BLACK); // Set all 'old' segment black + + Ws28b12b_Segments[Segment].IdStart = Start; + Ws28b12b_Segments[Segment].IdStop = Stop; + return FX_OK; +} + +FX_STATUS WS2812BFX_GetSegmentSize(uint8_t Segment, uint16_t *Start, uint16_t *Stop) +{ + if(Segment >= mSegments) return FX_ERROR; + *Start = Ws28b12b_Segments[Segment].IdStart; + *Stop = Ws28b12b_Segments[Segment].IdStop; + return FX_OK; +} + +FX_STATUS WS2812BFX_Start(uint8_t Segment) +{ + if(Segment >= mSegments) return FX_ERROR; + Ws28b12b_Segments[Segment].CounterModeCall = 0; + Ws28b12b_Segments[Segment].CounterModeStep = 0; + Ws28b12b_Segments[Segment].ModeDelay = 0; + Ws28b12b_Segments[Segment].Running = 1; mRunning = 1; + return FX_OK; +} + +uint8_t WS2812BFX_IsAnyRunning(void) +{ + for(uint8_t i = 0; i < mSegments; i++) + { + if(Ws28b12b_Segments[i].Running != 0) + return 1; + } + + return 0; } -void WS2812BFX_Stop() +FX_STATUS WS2812BFX_Stop(uint8_t Segment) { - mRunning = 0; + if(Segment >= mSegments) return FX_ERROR; + Ws28b12b_Segments[Segment].Running = 0; + if(!WS2812BFX_IsAnyRunning()) + mRunning = 0; + return FX_OK; // strip_off(); } +FX_STATUS WS2812BFX_IsRunning(uint8_t Segment, uint8_t *Running) +{ + if(Segment >= mSegments) return FX_ERROR; + *Running = Ws28b12b_Segments[Segment].Running; + return FX_OK; +} + void WS2812BFX_SetColorStruct(uint8_t id, ws2812b_color c) { mColor[id] = ((c.red<<16)|(c.green<<8)|c.blue); @@ -204,45 +531,16 @@ void WS2812BFX_SetColorRGB(uint8_t id, uint8_t r, uint8_t g, uint8_t b) mColor_w[id].red = r; mColor_w[id].green = g; mColor_w[id].blue = b; -} -// -// Set color with HSV model -// -// Hue 0-359 -// Saturation 0-255 -// Value 0-255 -// -void WS2812BFX_SetColorHSV(uint8_t id, uint16_t h, uint8_t s, uint8_t v) -{ - - WS2812BFX_HSVtoRGB(h, s, v, &mColor_w[id].red, &mColor_w[id].green, &mColor_w[id].blue); - mColor[id] = ((mColor_w[id].red<<16)|(mColor_w[id].green<<8)|mColor_w[id]. blue); } -void WS2812BFX_SetColor(uint8_t id, uint32_t c) +FX_STATUS WS2812BFX_GetColorRGB(uint8_t id, uint8_t *r, uint8_t *g, uint8_t *b) { - mColor[id] = c; - mColor_w[id].red = ((c>>16)&0x000000FF); - mColor_w[id].green = ((c>>8)&0x000000FF); - mColor_w[id].blue = (c&0x000000FF); -} - -void WS2812BFX_SetAll(uint32_t c) -{ - - for(uint16_t i = 0; i < WS2812B_LEDS; i++) - { - WS2812B_SetDiodeRGB(i, ((c>>16)&0xFF), ((c>>8)&0xFF), (c&0xFF)); - } -} - -void WS2812BFX_SetAllRGB(uint8_t r, uint8_t g, uint8_t b) -{ - for(uint16_t i = 0; i < WS2812B_LEDS; i++) - { - WS2812B_SetDiodeRGB(i, r, g, b); - } + if(id >= NUM_COLORS) return FX_ERROR; + *r = mColor_w[id].red; + *g = mColor_w[id].green; + *b = mColor_w[id].blue; + return FX_OK; } void WS2812BFX_RGBtoHSV(uint8_t r, uint8_t g, uint8_t b, uint16_t *h, uint8_t *s, uint8_t *v) @@ -308,6 +606,7 @@ void WS2812BFX_HSVtoRGB(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g if(s == 0) { + *r = v; *g = v; *b = v; @@ -359,62 +658,72 @@ void WS2812BFX_HSVtoRGB(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g } } -uint8_t WS2812BFX_IsRunning() -{ - return mRunning; -} - -uint8_t WS2812BFX_GetMode(void) -{ - return mMode_index; -} - -uint8_t WS2812BFX_GetSpeed(void) +// +// Set color with HSV model +// +// Hue 0-359 +// Saturation 0-255 +// Value 0-255 +// +void WS2812BFX_SetColorHSV(uint8_t id, uint16_t h, uint8_t s, uint8_t v) { - return mSpeed; + WS2812BFX_HSVtoRGB(h, s, v, &mColor_w[id].red, &mColor_w[id].green, &mColor_w[id].blue); + mColor[id] = ((mColor_w[id].red<<16)|(mColor_w[id].green<<8)|mColor_w[id]. blue); } -uint8_t WS2812BFX_GetBrightness(void) +void WS2812BFX_SetColor(uint8_t id, uint32_t c) { - return mBrightness; + mColor[id] = c; + mColor_w[id].red = ((c>>16)&0x000000FF); + mColor_w[id].green = ((c>>8)&0x000000FF); + mColor_w[id].blue = (c&0x000000FF); } -uint16_t WS2812BFX_GetLength(void) +FX_STATUS WS2812BFX_SetAll(uint8_t Segment, uint32_t c) { - return WS2812B_LEDS; + if(Segment >= mSegments) return FX_ERROR; + for(uint16_t i = 0; i < (Ws28b12b_Segments[Segment].IdStop - Ws28b12b_Segments[Segment].IdStart + 1); i++) + { + WS2812B_SetDiodeRGB(Ws28b12b_Segments[Segment].IdStart + i, ((c>>16)&0xFF), ((c>>8)&0xFF), (c&0xFF)); + } + return FX_OK; } -uint8_t WS2812BFX_GetModeCount(void) +FX_STATUS WS2812BFX_SetAllRGB(uint8_t Segment, uint8_t r, uint8_t g, uint8_t b) { - return MODE_COUNT; + if(Segment >= mSegments) return FX_ERROR; + for(uint16_t i = 0; i < SEGMENT_LENGTH; i++) + { + WS2812B_SetDiodeRGB(Ws28b12b_Segments[Segment].IdStart + i, r, g, b); + } + return FX_OK; } -ws2812b_color WS2812BFX_GetColorStruct(uint8_t id) +FX_STATUS WS2812BFX_SetSpeed(uint8_t Segment, uint16_t Speed) { - return mColor_w[id]; -} + if(Segment >= mSegments) return FX_ERROR; + if(Speed < SPEED_MIN) Speed = SPEED_MIN; + if(Speed > SPEED_MAX) Speed = SPEED_MAX; -uint32_t WS2812BFX_GetColor(uint8_t id) -{ - return mColor[id]; + Ws28b12b_Segments[Segment].Speed = Speed; + return FX_OK; } -void WS2812BFX_SetSpeed(uint16_t Speed) +FX_STATUS WS2812BFX_GetSpeed(uint8_t Segment, uint16_t *Speed) { - if(Speed < SPEED_MIN) Speed = SPEED_MIN; - if(Speed > SPEED_MAX) Speed = SPEED_MAX; - - mSpeed = Speed; + if(Segment >= mSegments) return FX_ERROR; + *Speed = Ws28b12b_Segments[Segment].Speed; + return FX_OK; } -void WS2812BFX_IncreaseSpeed(uint16_t Speed) +FX_STATUS WS2812BFX_IncreaseSpeed(uint8_t Segment, uint16_t Speed) { - WS2812BFX_SetSpeed(mSpeed + Speed); + return WS2812BFX_SetSpeed(Segment, Ws28b12b_Segments[mActualSegment].Speed + Speed); } -void WS2812BFX_DecreaseSpeed(uint16_t Speed) +FX_STATUS WS2812BFX_DecreaseSpeed(uint8_t Segment, uint16_t Speed) { - WS2812BFX_SetSpeed(mSpeed - Speed); + return WS2812BFX_SetSpeed(Segment, Ws28b12b_Segments[mActualSegment].Speed - Speed); } // @@ -483,12 +792,14 @@ void fade_out() { uint8_t rateH = rateMapH[rate]; uint8_t rateL = rateMapL[rate]; - uint32_t color = mModeColor[1]; // target color + uint32_t color = Ws28b12b_Segments[mActualSegment].ModeColor[1]; // target color + int r2 = (color >> 16) & 0xff; int g2 = (color >> 8) & 0xff; int b2 = color & 0xff; - for(uint16_t i=0; i <= WS2812B_LEDS; i++) { + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { + color = WS2812B_GetColor(i); if(rate == 0) { // old fade-to-black algorithm WS2812B_SetDiodeColor(i, (color >> 1) & 0x7F7F7F7F); @@ -542,11 +853,13 @@ uint32_t color_blend(uint32_t color1, uint32_t color2, uint8_t blend) /* * No blinking. Just plain old static light. */ -void mode_static(void) { - for(uint16_t i=0; i < WS2812B_LEDS; i++) { - WS2812B_SetDiodeColorStruct(i, mModeColor_w[0]); +void mode_static(void) +{ + + for(uint16_t i = Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { + WS2812B_SetDiodeColorStruct(i, Ws28b12b_Segments[mActualSegment].ModeColor_w[0]); } - iModeDelay = 250; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } // @@ -558,50 +871,47 @@ void to_color(uint8_t from) uint16_t h; uint8_t s, v, r, g, b; - WS2812BFX_RGBtoHSV(mModeColor_w[0].red, mModeColor_w[0].green, mModeColor_w[0].blue, &h, &s, &v); + WS2812BFX_RGBtoHSV(Ws28b12b_Segments[mActualSegment].ModeColor_w[0].red, Ws28b12b_Segments[mActualSegment].ModeColor_w[0].green, Ws28b12b_Segments[mActualSegment].ModeColor_w[0].blue, &h, &s, &v); if(from) - WS2812BFX_HSVtoRGB(h, s - mCounterModeStep, v, &r, &g, &b); + WS2812BFX_HSVtoRGB(h, s - Ws28b12b_Segments[mActualSegment].CounterModeStep, v, &r, &g, &b); else - WS2812BFX_HSVtoRGB(h, s, v - mCounterModeStep, &r, &g, &b); + WS2812BFX_HSVtoRGB(h, s, v - Ws28b12b_Segments[mActualSegment].CounterModeStep, &r, &g, &b); - for(uint16_t i = 0; i < WS2812B_LEDS; i++) - { - WS2812B_SetDiodeRGB(i, r, g, b); - } + WS2812BFX_SetAllRGB(mActualSegment, r, g, b); - if(!mCycle) + if(!Ws28b12b_Segments[mActualSegment].Cycle) { if(from) { - if(mCounterModeStep < s) - mCounterModeStep++; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep < s) + Ws28b12b_Segments[mActualSegment].CounterModeStep++; else - mCycle = 1; + Ws28b12b_Segments[mActualSegment].Cycle = 1; } else { - if(mCounterModeStep < v) - mCounterModeStep++; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep < v) + Ws28b12b_Segments[mActualSegment].CounterModeStep++; else - mCycle = 1; + Ws28b12b_Segments[mActualSegment].Cycle = 1; } } else { - if(mCounterModeStep > 0) - mCounterModeStep--; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep > 0) + Ws28b12b_Segments[mActualSegment].CounterModeStep--; else - mCycle = 0; + Ws28b12b_Segments[mActualSegment].Cycle = 0; } if(from) { - iModeDelay = mSpeed / s / 2; + Ws28b12b_Segments[mActualSegment].ModeDelay = (Ws28b12b_Segments[mActualSegment].Speed / s / 2); } else { - iModeDelay = mSpeed / v / 2; + Ws28b12b_Segments[mActualSegment].ModeDelay = (Ws28b12b_Segments[mActualSegment].Speed / v / 2); } } @@ -621,33 +931,34 @@ void mode_black_to_color(void) // void blink(uint32_t color1, uint32_t color2, uint8_t strobe) { - uint32_t color = ((mCounterModeCall & 1) == 0) ? color1 : color2; - WS2812BFX_SetAll(color); - if((mCounterModeCall & 1) == 0) - iModeDelay = strobe ? 20 : mSpeed / 2; + uint32_t color = ((Ws28b12b_Segments[mActualSegment].CounterModeCall & 1) == 0) ? color1 : color2; + WS2812BFX_SetAll(mActualSegment, color); + if((Ws28b12b_Segments[mActualSegment].CounterModeCall & 1) == 0) + Ws28b12b_Segments[mActualSegment].ModeDelay = strobe ? 20 : Ws28b12b_Segments[mActualSegment].Speed / 2; else - iModeDelay = strobe? mSpeed - 20 : (mSpeed / 2); + Ws28b12b_Segments[mActualSegment].ModeDelay = strobe? Ws28b12b_Segments[mActualSegment].Speed - 20 : (Ws28b12b_Segments[mActualSegment].Speed / 2); } /* * Normal blinking. 50% on/off time. */ -void mode_blink(void) { - blink(mModeColor[0], mModeColor[1], 0); +void mode_blink(void) +{ + blink(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], 0); } void mode_blink_rainbow(void) { - blink(color_wheel(mCounterModeCall & 0xFF), mModeColor[1], 0); + blink(color_wheel(Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF), Ws28b12b_Segments[mActualSegment].ModeColor[1], 0); } void mode_strobe(void) { - blink(mModeColor[0], mModeColor[1], 1); + blink(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], 1); } void mode_strobe_rainbow(void) { - blink(color_wheel(mCounterModeCall & 0xFF), mModeColor[1], 1); + blink(color_wheel(Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF), Ws28b12b_Segments[mActualSegment].ModeColor[1], 1); } /* @@ -655,7 +966,7 @@ void mode_strobe_rainbow(void) */ void mode_breath(void) { - uint32_t lum = mCounterModeStep; + uint32_t lum = Ws28b12b_Segments[mActualSegment].CounterModeStep; if(lum > 255) lum = 511 - lum; uint16_t delay; @@ -668,14 +979,14 @@ void mode_breath(void) else if(lum <= 150) delay = 11; // 5 else delay = 10; // 4 - uint8_t r = mModeColor_w[0].red * lum / 256; - uint8_t g = mModeColor_w[0].green * lum / 256; - uint8_t b = mModeColor_w[0].blue * lum / 256; + uint8_t r = Ws28b12b_Segments[mActualSegment].ModeColor_w[0].red * lum / 256; + uint8_t g = Ws28b12b_Segments[mActualSegment].ModeColor_w[0].green * lum / 256; + uint8_t b = Ws28b12b_Segments[mActualSegment].ModeColor_w[0].blue * lum / 256; - WS2812BFX_SetAllRGB(r, g, b); - mCounterModeStep += 2; - if(mCounterModeStep > (512-15)) mCounterModeStep = 15; - iModeDelay = delay; + WS2812BFX_SetAllRGB(mActualSegment, r, g, b); + Ws28b12b_Segments[mActualSegment].CounterModeStep += 2; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep > (512-15)) Ws28b12b_Segments[mActualSegment].CounterModeStep = 15; + Ws28b12b_Segments[mActualSegment].ModeDelay = delay; } /* @@ -685,33 +996,33 @@ void mode_breath(void) */ void color_wipe(uint32_t color1, uint32_t color2, uint8_t rev) { - if(mCounterModeStep < WS2812B_LEDS) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep < SEGMENT_LENGTH) { - uint32_t led_offset = mCounterModeStep; + uint32_t led_offset = Ws28b12b_Segments[mActualSegment].CounterModeStep; if(rev) { - WS2812B_SetDiodeColor(WS2812B_LEDS - led_offset, color1); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - led_offset, color1); } else { - WS2812B_SetDiodeColor(0 + led_offset, color1); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + led_offset, color1); } } else { - uint32_t led_offset = mCounterModeStep - WS2812B_LEDS; + uint32_t led_offset = Ws28b12b_Segments[mActualSegment].CounterModeStep - SEGMENT_LENGTH; if(rev) { - WS2812B_SetDiodeColor(WS2812B_LEDS - led_offset, color2); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - led_offset, color2); } else { - WS2812B_SetDiodeColor(0 + led_offset, color2); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + led_offset, color2); } } - mCounterModeStep = (mCounterModeStep + 1) % (WS2812B_LEDS * 2); - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % (SEGMENT_LENGTH * 2); + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -719,34 +1030,34 @@ void color_wipe(uint32_t color1, uint32_t color2, uint8_t rev) */ void mode_color_wipe(void) { - color_wipe(mModeColor[0], mModeColor[1], 0); + color_wipe(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], 0); } void mode_color_wipe_inv(void) { - color_wipe(mModeColor[1], mModeColor[0], 0); + color_wipe(Ws28b12b_Segments[mActualSegment].ModeColor[1], Ws28b12b_Segments[mActualSegment].ModeColor[0], 0); } void mode_color_wipe_rev(void) { - color_wipe(mModeColor[0], mModeColor[1], 1); + color_wipe(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], 1); } void mode_color_wipe_rev_inv(void) { - color_wipe(mModeColor[1], mModeColor[0], 1); + color_wipe(Ws28b12b_Segments[mActualSegment].ModeColor[1], Ws28b12b_Segments[mActualSegment].ModeColor[0], 1); } void mode_color_wipe_random(void) +{ + if(Ws28b12b_Segments[mActualSegment].CounterModeStep % SEGMENT_LENGTH == 0) { - if(mCounterModeStep % WS2812B_LEDS == 0) - { - mAuxParam = get_random_wheel_index(mAuxParam); + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); } - uint32_t color = color_wheel(mAuxParam); + uint32_t color = color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam); color_wipe(color, color, 0); - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -754,11 +1065,11 @@ void mode_color_wipe_random(void) */ void mode_color_sweep_random(void) { - if(mCounterModeStep % WS2812B_LEDS == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index - mAuxParam = get_random_wheel_index(mAuxParam); + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); } - uint32_t color = color_wheel(mAuxParam); + uint32_t color = color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam); color_wipe(color, color, 1); } @@ -768,9 +1079,9 @@ void mode_color_sweep_random(void) */ void mode_random_color(void) { - mAuxParam = get_random_wheel_index(mAuxParam); // aux_param will store our random color wheel index - WS2812BFX_SetAll(color_wheel(mAuxParam)); - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); // aux_param will store our random color wheel index + WS2812BFX_SetAll(mActualSegment, color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam)); + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -779,16 +1090,16 @@ void mode_random_color(void) */ void mode_single_dynamic(void) { - if(mCounterModeCall == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeCall == 0) { - for(uint16_t i = 0; i < WS2812B_LEDS; i++) + for(uint16_t i = Ws28b12b_Segments[mActualSegment].IdStop; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { WS2812B_SetDiodeColor(i, color_wheel(rand()%256)); } } - WS2812B_SetDiodeColor(0 + rand() % WS2812B_LEDS, color_wheel(rand()%256)); - iModeDelay = mSpeed; + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + rand() % SEGMENT_LENGTH, color_wheel(rand()%256)); + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -798,11 +1109,11 @@ void mode_single_dynamic(void) */ void mode_multi_dynamic(void) { - for(uint16_t i = 0; i < WS2812B_LEDS; i++) + for(uint16_t i = Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { WS2812B_SetDiodeColor(i, color_wheel(rand()%256)); } - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -810,14 +1121,14 @@ void mode_multi_dynamic(void) */ void mode_rainbow(void) { - uint32_t color = color_wheel(mCounterModeStep); - for(uint16_t i = 0; i < WS2812B_LEDS; i++) + uint32_t color = color_wheel(Ws28b12b_Segments[mActualSegment].CounterModeStep); + for(uint16_t i = Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { WS2812B_SetDiodeColor(i, color); } - mCounterModeStep = (mCounterModeStep + 1) & 0xFF; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) & 0xFF; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -826,14 +1137,14 @@ void mode_rainbow(void) */ void mode_rainbow_cycle(void) { - for(uint16_t i=0; i < WS2812B_LEDS; i++) + for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - uint32_t color = color_wheel(((i * 256 / WS2812B_LEDS) + mCounterModeStep) & 0xFF); - WS2812B_SetDiodeColor(0 + i, color); + uint32_t color = color_wheel(((i * 256 / SEGMENT_LENGTH) + Ws28b12b_Segments[mActualSegment].CounterModeStep) & 0xFF); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, color); } - mCounterModeStep = (mCounterModeStep + 1) & 0xFF; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) & 0xFF; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -841,18 +1152,18 @@ void mode_rainbow_cycle(void) * Fades the LEDs between two colors */ void mode_fade(void) { - int lum = mCounterModeStep; + int lum = Ws28b12b_Segments[mActualSegment].CounterModeStep; if(lum > 255) lum = 511 - lum; // lum = 0 -> 255 -> 0 - uint32_t color = color_blend(mModeColor[0], mModeColor[1], lum); + uint32_t color = color_blend(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], lum); - for(uint16_t i=0; i 511) mCounterModeStep = 0; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep += 4; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep > 511) Ws28b12b_Segments[mActualSegment].CounterModeStep = 0; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -860,23 +1171,26 @@ void mode_fade(void) { * Runs a single pixel back and forth. */ void mode_scan(void) { - if(mCounterModeStep > (WS2812B_LEDS * 2) - 3) { - mCounterModeStep = 0; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep > (SEGMENT_LENGTH * 2) - 3) { + Ws28b12b_Segments[mActualSegment].CounterModeStep = 0; } - for(uint16_t i=0; i (WS2812B_LEDS * 2) - 3) { - mCounterModeStep = 0; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep > (SEGMENT_LENGTH * 2) - 3) + { + Ws28b12b_Segments[mActualSegment].CounterModeStep = 0; } - for(uint16_t i=0; i > 16) & 0xFF); - uint8_t g = ((mModeColor[0] >> 8) & 0xFF); - uint8_t b = (mModeColor[0] & 0xFF); + uint8_t r = ((Ws28b12b_Segments[mActualSegment].ModeColor[0] >> 16) & 0xFF); + uint8_t g = ((Ws28b12b_Segments[mActualSegment].ModeColor[0] >> 8) & 0xFF); + uint8_t b = (Ws28b12b_Segments[mActualSegment].ModeColor[0] & 0xFF); uint8_t sineIncr = MAX(1, (256 / WS2812B_LEDS)); - for(uint16_t i=0; i < WS2812B_LEDS; i++) { - int lum = (int)sine8(((i + mCounterModeStep) * sineIncr)); -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(0 + i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256, (w * lum) / 256); -// } else { - WS2812B_SetDiodeRGB(WS2812B_LEDS - i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256); -// } + for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { + int lum = (int)sine8(((i + Ws28b12b_Segments[mActualSegment].CounterModeStep) * sineIncr)); + if(IS_REVERSE) { + WS2812B_SetDiodeRGB(Ws28b12b_Segments[mActualSegment].IdStart + i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256); + } else { + WS2812B_SetDiodeRGB(Ws28b12b_Segments[mActualSegment].IdStop - i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256); + } } - mCounterModeStep = (mCounterModeStep + 1) % 256; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % 256; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -975,37 +1292,39 @@ void mode_running_lights(void) { */ void twinkle(uint32_t color1, uint32_t color2) { - if(mCounterModeStep == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep == 0) { - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { WS2812B_SetDiodeColor(i, color2); } uint16_t min_leds = MAX(1, WS2812B_LEDS / 5); // make sure, at least one LED is on uint16_t max_leds = MAX(1, WS2812B_LEDS / 2); // make sure, at least one LED is on - mCounterModeStep = rand() % (max_leds + 1 - min_leds) + min_leds; + Ws28b12b_Segments[mActualSegment].CounterModeStep = rand() % (max_leds + 1 - min_leds) + min_leds; } - WS2812B_SetDiodeColor(0 + rand() % WS2812B_LEDS, color1); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + rand() % SEGMENT_LENGTH, color1); - mCounterModeStep--; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep--; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* * Blink several LEDs on, reset, repeat. * Inspired by www.tweaking4all.com/hardware/arduino/arduino-led-strip-effects/ */ -void mode_twinkle(void) { - return twinkle(mModeColor[0], mModeColor[1]); +void mode_twinkle(void) +{ + return twinkle(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1]); } /* * Blink several LEDs in random colors on, reset, repeat. * Inspired by www.tweaking4all.com/hardware/arduino/arduino-led-strip-effects/ */ -void mode_twinkle_random(void) { - return twinkle(color_wheel(rand() % 256), mModeColor[1]); +void mode_twinkle_random(void) +{ + return twinkle(color_wheel(rand() % 256), Ws28b12b_Segments[mActualSegment].ModeColor[1]); } /* @@ -1017,9 +1336,9 @@ void twinkle_fade(uint32_t color) if((rand() %3) == 0) { - WS2812B_SetDiodeColor(0 + rand() % WS2812B_LEDS, color); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + rand() % SEGMENT_LENGTH, color); } - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1028,7 +1347,7 @@ void twinkle_fade(uint32_t color) */ void mode_twinkle_fade(void) { - twinkle_fade(mModeColor[0]); + twinkle_fade(Ws28b12b_Segments[mActualSegment].ModeColor[0]); } @@ -1046,10 +1365,10 @@ void mode_twinkle_fade_random(void) */ void mode_sparkle(void) { - WS2812B_SetDiodeColor(0 + mAuxParam16b, mModeColor[1]); - mAuxParam16b = rand() % WS2812B_LEDS; // aux_param3 stores the random led index - WS2812B_SetDiodeColor(0 + mAuxParam16b, mModeColor[0]); - iModeDelay = mSpeed; + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].AuxParam16b, Ws28b12b_Segments[mActualSegment].ModeColor[1]); + Ws28b12b_Segments[mActualSegment].AuxParam16b = rand() % SEGMENT_LENGTH; // aux_param3 stores the random led index + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].AuxParam16b, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1057,23 +1376,25 @@ void mode_sparkle(void) * Lights all LEDs in the color. Flashes single white pixels randomly. * Inspired by www.tweaking4all.com/hardware/arduino/arduino-led-strip-effects/ */ -void mode_flash_sparkle(void) { - if(mCounterModeCall == 0) { - for(uint16_t i=0; i <= WS2812B_LEDS; i++) +void mode_flash_sparkle(void) +{ + if(Ws28b12b_Segments[mActualSegment].CounterModeCall == 0) + { + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { - WS2812B_SetDiodeColor(i, mModeColor[0]); + WS2812B_SetDiodeColor(i, Ws28b12b_Segments[mActualSegment].ModeColor[0]); } } - WS2812B_SetDiodeColor(0 + mAuxParam16b, mModeColor[0]); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].AuxParam16b, Ws28b12b_Segments[mActualSegment].ModeColor[0]); if(rand() % 5 == 0) { - mAuxParam16b = rand() % WS2812B_LEDS; // aux_param3 stores the random led index - WS2812B_SetDiodeColor(0 + mAuxParam16b, WHITE); - iModeDelay = 20; + Ws28b12b_Segments[mActualSegment].AuxParam16b = rand() % SEGMENT_LENGTH; // aux_param3 stores the random led index + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].AuxParam16b, WHITE); + Ws28b12b_Segments[mActualSegment].ModeDelay = 20; } - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1083,20 +1404,20 @@ void mode_flash_sparkle(void) { */ void mode_hyper_sparkle(void) { - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { - WS2812B_SetDiodeColor(i, mModeColor[0]); + WS2812B_SetDiodeColor(i, Ws28b12b_Segments[mActualSegment].ModeColor[0]); } if(rand() % 5 < 2) { - for(uint16_t i=0; i < MAX(1, WS2812B_LEDS/3); i++) + for(uint16_t i=0; i < MAX(1, SEGMENT_LENGTH/3); i++) { - WS2812B_SetDiodeColor(0 + rand() % WS2812B_LEDS, WHITE); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + rand() % SEGMENT_LENGTH, WHITE); } - iModeDelay = 20; + Ws28b12b_Segments[mActualSegment].ModeDelay = 20; } - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -1104,20 +1425,20 @@ void mode_hyper_sparkle(void) */ void mode_multi_strobe(void) { - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { WS2812B_SetDiodeColor(i, BLACK); } - uint16_t delay = 200 + ((9 - (mSpeed % 10)) * 100); - uint16_t count = 2 * ((mSpeed / 100) + 1); - if(mCounterModeStep < count) + uint16_t delay = 200 + ((9 - (Ws28b12b_Segments[mActualSegment].Speed % 10)) * 100); + uint16_t count = 2 * ((Ws28b12b_Segments[mActualSegment].Speed / 100) + 1); + if(Ws28b12b_Segments[mActualSegment].CounterModeStep < count) { - if((mCounterModeStep & 1) == 0) + if((Ws28b12b_Segments[mActualSegment].CounterModeStep & 1) == 0) { - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { - WS2812B_SetDiodeColor(i, mModeColor[0]); + WS2812B_SetDiodeColor(i, Ws28b12b_Segments[mActualSegment].ModeColor[0]); } delay = 20; } @@ -1126,8 +1447,8 @@ void mode_multi_strobe(void) delay = 50; } } - mCounterModeStep = (mCounterModeStep + 1) % (count + 1); - iModeDelay = delay; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % (count + 1); + Ws28b12b_Segments[mActualSegment].ModeDelay = delay; } /* @@ -1137,24 +1458,24 @@ void mode_multi_strobe(void) */ void chase(uint32_t color1, uint32_t color2, uint32_t color3) { - uint16_t a = mCounterModeStep; - uint16_t b = (a + 1) % WS2812B_LEDS; - uint16_t c = (b + 1) % WS2812B_LEDS; -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS - a, color1); -// WS2812B_SetDiodeColor(WS2812B_LEDS - b, color2); -// WS2812B_SetDiodeColor(WS2812B_LEDS - c, color3); -// } else { - WS2812B_SetDiodeColor(0 + a, color1); - WS2812B_SetDiodeColor(0 + b, color2); - WS2812B_SetDiodeColor(0 + c, color3); -// } + uint16_t a = Ws28b12b_Segments[mActualSegment].CounterModeStep; + uint16_t b = (a + 1) % SEGMENT_LENGTH; + uint16_t c = (b + 1) % SEGMENT_LENGTH; + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - a, color1); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - b, color2); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - c, color3); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + a, color1); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + b, color2); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + c, color3); + } - if(b == 0) mCycle = 1; - else mCycle = 0; + if(b == 0) Ws28b12b_Segments[mActualSegment].Cycle = 1; + else Ws28b12b_Segments[mActualSegment].Cycle = 0; - mCounterModeStep = (mCounterModeStep + 1) % WS2812B_LEDS; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % WS2812B_LEDS; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1163,7 +1484,7 @@ void chase(uint32_t color1, uint32_t color2, uint32_t color3) */ void mode_bicolor_chase(void) { - return chase(mModeColor[0], mModeColor[1], mModeColor[2]); + return chase(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], Ws28b12b_Segments[mActualSegment].ModeColor[2]); } @@ -1172,7 +1493,7 @@ void mode_bicolor_chase(void) */ void mode_chase_color(void) { - return chase(mModeColor[0], WHITE, WHITE); + return chase(Ws28b12b_Segments[mActualSegment].ModeColor[0], WHITE, WHITE); } @@ -1181,7 +1502,7 @@ void mode_chase_color(void) */ void mode_chase_blackout(void) { - return chase(mModeColor[0], BLACK, BLACK); + return chase(Ws28b12b_Segments[mActualSegment].ModeColor[0], BLACK, BLACK); } @@ -1190,7 +1511,7 @@ void mode_chase_blackout(void) */ void mode_chase_white(void) { - return chase(WHITE, mModeColor[0], mModeColor[0]); + return chase(WHITE, Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[0]); } @@ -1199,11 +1520,11 @@ void mode_chase_white(void) */ void mode_chase_random(void) { - if(mCounterModeStep == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep == 0) { - mAuxParam = get_random_wheel_index(mAuxParam); + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); } - return chase(color_wheel(mAuxParam), WHITE, WHITE); + return chase(color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam), WHITE, WHITE); } @@ -1212,10 +1533,10 @@ void mode_chase_random(void) */ void mode_chase_rainbow_white(void) { - uint16_t n = mCounterModeStep; - uint16_t m = (mCounterModeStep + 1) % WS2812B_LEDS; - uint32_t color2 = color_wheel(((n * 256 / WS2812B_LEDS) + (mCounterModeCall & 0xFF)) & 0xFF); - uint32_t color3 = color_wheel(((m * 256 / WS2812B_LEDS) + (mCounterModeCall & 0xFF)) & 0xFF); + uint16_t n = Ws28b12b_Segments[mActualSegment].CounterModeStep; + uint16_t m = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % WS2812B_LEDS; + uint32_t color2 = color_wheel(((n * 256 / SEGMENT_LENGTH) + (Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF)) & 0xFF); + uint32_t color3 = color_wheel(((m * 256 / SEGMENT_LENGTH) + (Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF)) & 0xFF); return chase(WHITE, color2, color3); } @@ -1226,9 +1547,9 @@ void mode_chase_rainbow_white(void) */ void mode_chase_rainbow(void) { - uint8_t color_sep = 256 / WS2812B_LEDS; - uint8_t color_index = mCounterModeCall & 0xFF; - uint32_t color = color_wheel(((mCounterModeStep * color_sep) + color_index) & 0xFF); + uint8_t color_sep = 256 / SEGMENT_LENGTH; + uint8_t color_index = Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF; + uint32_t color = color_wheel(((Ws28b12b_Segments[mActualSegment].CounterModeStep * color_sep) + color_index) & 0xFF); return chase(color, WHITE, WHITE); } @@ -1239,9 +1560,9 @@ void mode_chase_rainbow(void) */ void mode_chase_blackout_rainbow(void) { - uint8_t color_sep = 256 / WS2812B_LEDS; - uint8_t color_index = mCounterModeCall & 0xFF; - uint32_t color = color_wheel(((mCounterModeStep * color_sep) + color_index) & 0xFF); + uint8_t color_sep = 256 / SEGMENT_LENGTH; + uint8_t color_index = Ws28b12b_Segments[mActualSegment].CounterModeCall & 0xFF; + uint32_t color = color_wheel(((Ws28b12b_Segments[mActualSegment].CounterModeStep * color_sep) + color_index) & 0xFF); return chase(color, 0, 0); } @@ -1252,30 +1573,30 @@ void mode_chase_blackout_rainbow(void) void mode_chase_flash(void) { const static uint8_t flash_count = 4; - uint8_t flash_step = mCounterModeCall % ((flash_count * 2) + 1); + uint8_t flash_step = Ws28b12b_Segments[mActualSegment].CounterModeCall % ((flash_count * 2) + 1); - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { - WS2812B_SetDiodeColor(i, mModeColor[0]); + WS2812B_SetDiodeColor(i, Ws28b12b_Segments[mActualSegment].ModeColor[0]); } - uint16_t delay = mSpeed; + uint16_t delay = Ws28b12b_Segments[mActualSegment].Speed; if(flash_step < (flash_count * 2)) { if(flash_step % 2 == 0) { - uint16_t n = mCounterModeStep; - uint16_t m = (mCounterModeStep + 1) % WS2812B_LEDS; -// if(IS_REVERSE) -// { -// WS2812B_SetDiodeColor(WS2812B_LEDS - n, WHITE); -// WS2812B_SetDiodeColor(WS2812B_LEDS - m, WHITE); -// } -// else -// { - WS2812B_SetDiodeColor(0 + n, WHITE); - WS2812B_SetDiodeColor(0 + m, WHITE); -// } + uint16_t n = Ws28b12b_Segments[mActualSegment].CounterModeStep; + uint16_t m = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % SEGMENT_LENGTH; + if(IS_REVERSE) + { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - n, WHITE); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - m, WHITE); + } + else + { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + n, WHITE); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + m, WHITE); + } delay = 20; } else @@ -1285,9 +1606,9 @@ void mode_chase_flash(void) } else { - mCounterModeStep = (mCounterModeStep + 1) % WS2812B_LEDS; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % SEGMENT_LENGTH; } - iModeDelay = delay; + Ws28b12b_Segments[mActualSegment].ModeDelay = delay; } @@ -1297,41 +1618,41 @@ void mode_chase_flash(void) void mode_chase_flash_random(void) { const static uint8_t flash_count = 4; - uint8_t flash_step = mCounterModeCall % ((flash_count * 2) + 1); + uint8_t flash_step = Ws28b12b_Segments[mActualSegment].CounterModeCall % ((flash_count * 2) + 1); - for(uint16_t i=0; i < mCounterModeStep; i++) + for(uint16_t i=0; i < Ws28b12b_Segments[mActualSegment].CounterModeStep; i++) { - WS2812B_SetDiodeColor(0 + i, color_wheel(mAuxParam)); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam)); } - uint16_t delay = mSpeed; + uint16_t delay = Ws28b12b_Segments[mActualSegment].Speed; if(flash_step < (flash_count * 2)) { - uint16_t n = mCounterModeStep; - uint16_t m = (mCounterModeStep + 1) % WS2812B_LEDS; + uint16_t n = Ws28b12b_Segments[mActualSegment].CounterModeStep; + uint16_t m = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % SEGMENT_LENGTH; if(flash_step % 2 == 0) { - WS2812B_SetDiodeColor(0 + n, WHITE); - WS2812B_SetDiodeColor(0 + m, WHITE); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + n, WHITE); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + m, WHITE); delay = 20; } else { - WS2812B_SetDiodeColor(0 + n, color_wheel(mAuxParam)); - WS2812B_SetDiodeColor(0 + m, BLACK); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + n, color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam)); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + m, BLACK); delay = 30; } } else { - mCounterModeStep = (mCounterModeStep + 1) % WS2812B_LEDS; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % SEGMENT_LENGTH; - if(mCounterModeStep == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep == 0) { - mAuxParam = get_random_wheel_index(mAuxParam); + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); } } - iModeDelay = delay; + Ws28b12b_Segments[mActualSegment].ModeDelay = delay; } @@ -1340,26 +1661,26 @@ void mode_chase_flash_random(void) */ void running(uint32_t color1, uint32_t color2) { - for(uint16_t i=0; i < WS2812B_LEDS; i++) + for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - if((i + mCounterModeStep) % 4 < 2) + if((i + Ws28b12b_Segments[mActualSegment].CounterModeStep) % 4 < 2) { -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(0 + i, color1); -// } else { - WS2812B_SetDiodeColor(WS2812B_LEDS - i, color1); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, color1); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - i, color1); + } } else { -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(0 + i, color2); -// } else { - WS2812B_SetDiodeColor(WS2812B_LEDS - i, color2); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, color1); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - i, color2); + } } } - mCounterModeStep = (mCounterModeStep + 1) & 0x3; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) & 0x3; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -1367,7 +1688,7 @@ void running(uint32_t color1, uint32_t color2) */ void mode_running_color(void) { - return running(mModeColor[0], WHITE); + return running(Ws28b12b_Segments[mActualSegment].ModeColor[0], WHITE); } @@ -1396,31 +1717,30 @@ void mode_halloween(void) return running(PURPLE, ORANGE); } - /* * Random colored pixels running. */ void mode_running_random(void) { - for(uint16_t i=WS2812B_LEDS-1; i > 0; i--) { -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS - i, Adafruit_NeoPixel::getPixelColor(WS2812B_LEDS - i + 1)); -// } else { - WS2812B_SetDiodeColor(0 + i, WS2812B_GetColor(0 + i - 1)); -// } + for(uint16_t i=SEGMENT_LENGTH-1; i > 0; i--) { + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - i, WS2812B_GetColor(Ws28b12b_Segments[mActualSegment].IdStop - i + 1)); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, WS2812B_GetColor(Ws28b12b_Segments[mActualSegment].IdStart + i - 1)); + } } - if(mCounterModeStep == 0) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep == 0) { - mAuxParam = get_random_wheel_index(mAuxParam); -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS, color_wheel(mAuxParam)); -// } else { - WS2812B_SetDiodeColor(0, color_wheel(mAuxParam)); -// } + Ws28b12b_Segments[mActualSegment].AuxParam = get_random_wheel_index(Ws28b12b_Segments[mActualSegment].AuxParam); + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop, color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam)); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart, color_wheel(Ws28b12b_Segments[mActualSegment].AuxParam)); + } } - mCounterModeStep = (mCounterModeStep == 0) ? 1 : 0; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep == 0) ? 1 : 0; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1430,28 +1750,28 @@ void mode_running_random(void) { void mode_larson_scanner(void) { fade_out(); - if(mCounterModeStep < WS2812B_LEDS) + if(Ws28b12b_Segments[mActualSegment].CounterModeStep < SEGMENT_LENGTH) { -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS - mCounterModeStep, mModeColor[0]); -// } else { - WS2812B_SetDiodeColor(0 + mCounterModeStep, mModeColor[0]); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - Ws28b12b_Segments[mActualSegment].CounterModeStep, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].CounterModeStep, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } } else { -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS - ((WS2812B_LEDS * 2) - mCounterModeStep) + 2, mModeColor[0]); -// } else { - WS2812B_SetDiodeColor(0 + ((WS2812B_LEDS * 2) - mCounterModeStep) - 2, mModeColor[0]); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - ((SEGMENT_LENGTH * 2) - Ws28b12b_Segments[mActualSegment].CounterModeStep) + 2, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + ((SEGMENT_LENGTH * 2) - Ws28b12b_Segments[mActualSegment].CounterModeStep) - 2, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } } - if(mCounterModeStep % WS2812B_LEDS == 0) mCycle = 1; - else mCycle = 1; + if(Ws28b12b_Segments[mActualSegment].CounterModeStep % SEGMENT_LENGTH == 0) Ws28b12b_Segments[mActualSegment].Cycle = 1; + else Ws28b12b_Segments[mActualSegment].Cycle = 1; - mCounterModeStep = (mCounterModeStep + 1) % ((WS2812B_LEDS * 2) - 2); - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % ((SEGMENT_LENGTH * 2) - 2); + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1461,14 +1781,14 @@ void mode_larson_scanner(void) { void mode_comet(void) { fade_out(); -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(WS2812B_LEDS - mCounterModeStep, mModeColor[0]); -// } else { - WS2812B_SetDiodeColor(0 + mCounterModeStep, mModeColor[0]); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - Ws28b12b_Segments[mActualSegment].CounterModeStep, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + Ws28b12b_Segments[mActualSegment].CounterModeStep, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + } - mCounterModeStep = (mCounterModeStep + 1) % WS2812B_LEDS; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep = (Ws28b12b_Segments[mActualSegment].CounterModeStep + 1) % SEGMENT_LENGTH; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1492,8 +1812,8 @@ void fireworks(uint32_t color) { // the new way, manipulate the Adafruit_NeoPixels pixels[] array directly, about 5x faster uint8_t *pixels = WS2812B_GetPixels(); uint8_t pixelsPerLed = 3; - uint16_t startPixel = 0 * pixelsPerLed + pixelsPerLed; - uint16_t stopPixel = WS2812B_LEDS * pixelsPerLed ; + uint16_t startPixel = Ws28b12b_Segments[mActualSegment].IdStart * pixelsPerLed + pixelsPerLed; + uint16_t stopPixel = Ws28b12b_Segments[mActualSegment].IdStop * pixelsPerLed ; for(uint16_t i=startPixel; i > 2) + @@ -1508,18 +1828,18 @@ void fireworks(uint32_t color) { { if(rand()%10 == 0) { - WS2812B_SetDiodeColor(0 + rand() % WS2812B_LEDS, color); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + rand() % SEGMENT_LENGTH, color); } } } else { - for(uint16_t i=0; i> 16) & 0xFF; - uint8_t g = (mModeColor[0] >> 8) & 0xFF; - uint8_t b = (mModeColor[0] & 0xFF); + uint8_t r = (Ws28b12b_Segments[mActualSegment].ModeColor[0] >> 16) & 0xFF; + uint8_t g = (Ws28b12b_Segments[mActualSegment].ModeColor[0] >> 8) & 0xFF; + uint8_t b = (Ws28b12b_Segments[mActualSegment].ModeColor[0] & 0xFF); uint8_t lum = MAX(r, MAX(g, b)) / rev_intensity; - for(uint16_t i=0; i <= WS2812B_LEDS; i++) + for(uint16_t i=Ws28b12b_Segments[mActualSegment].IdStart; i <= Ws28b12b_Segments[mActualSegment].IdStop; i++) { int flicker = rand()%lum; WS2812B_SetDiodeRGB(i, MAX(r - flicker, 0), MAX(g - flicker, 0), MAX(b - flicker, 0)); } - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } /* @@ -1586,8 +1906,8 @@ void mode_fire_flicker_intense(void) */ void tricolor_chase(uint32_t color1, uint32_t color2, uint32_t color3) { - uint16_t index = mCounterModeStep % 6; - for(uint16_t i=0; i < WS2812B_LEDS; i++, index++) + uint16_t index = Ws28b12b_Segments[mActualSegment].CounterModeStep % 6; + for(uint16_t i=0; i < SEGMENT_LENGTH; i++, index++) { if(index > 5) index = 0; @@ -1595,15 +1915,15 @@ void tricolor_chase(uint32_t color1, uint32_t color2, uint32_t color3) if(index < 2) color = color1; else if(index < 4) color = color2; -// if(IS_REVERSE) { -// WS2812B_SetDiodeColor(0 + i, color); -// } else { - WS2812B_SetDiodeColor(WS2812B_LEDS - i, color); -// } + if(IS_REVERSE) { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + i, color); + } else { + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStop - i, color); + } } - mCounterModeStep++; - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].CounterModeStep++; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } @@ -1612,7 +1932,7 @@ void tricolor_chase(uint32_t color1, uint32_t color2, uint32_t color3) */ void mode_tricolor_chase(void) { - return tricolor_chase(mModeColor[0], mModeColor[1], mModeColor[2]); + return tricolor_chase(Ws28b12b_Segments[mActualSegment].ModeColor[0], Ws28b12b_Segments[mActualSegment].ModeColor[1], Ws28b12b_Segments[mActualSegment].ModeColor[2]); } @@ -1629,38 +1949,38 @@ void mode_circus_combustus(void) */ void mode_icu(void) { - uint16_t dest = mCounterModeStep & 0xFFFF; + uint16_t dest = Ws28b12b_Segments[mActualSegment].CounterModeStep & 0xFFFF; - WS2812B_SetDiodeColor(0 + dest, mModeColor[0]); - WS2812B_SetDiodeColor(0 + dest + WS2812B_LEDS/2, mModeColor[0]); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest + WS2812B_LEDS/2, Ws28b12b_Segments[mActualSegment].ModeColor[0]); - if(mAuxParam16b == dest) + if(Ws28b12b_Segments[mActualSegment].AuxParam16b == dest) { // pause between eye movements if(rand()%6 == 0) { // blink once in a while - WS2812B_SetDiodeColor(0 + dest, BLACK); - WS2812B_SetDiodeColor(0 + dest + WS2812B_LEDS/2, BLACK); - iModeDelay = 200; + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest, BLACK); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest + SEGMENT_LENGTH/2, BLACK); + Ws28b12b_Segments[mActualSegment].ModeDelay = 200; } - mAuxParam16b = rand() %(WS2812B_LEDS/2); - iModeDelay = 1000 + rand() %2000; + Ws28b12b_Segments[mActualSegment].AuxParam16b = rand() %(SEGMENT_LENGTH/2); + Ws28b12b_Segments[mActualSegment].ModeDelay = 1000 + rand() %2000; } - WS2812B_SetDiodeColor(0 + dest, BLACK); - WS2812B_SetDiodeColor(0 + dest + WS2812B_LEDS/2, BLACK); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest, BLACK); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest + SEGMENT_LENGTH/2, BLACK); - if(mAuxParam16b > mCounterModeStep) + if(Ws28b12b_Segments[mActualSegment].AuxParam16b > Ws28b12b_Segments[mActualSegment].CounterModeStep) { - mCounterModeStep++; + Ws28b12b_Segments[mActualSegment].CounterModeStep++; dest++; - } else if (mAuxParam16b < mCounterModeStep) + } else if (Ws28b12b_Segments[mActualSegment].AuxParam16b < Ws28b12b_Segments[mActualSegment].CounterModeStep) { - mCounterModeStep--; + Ws28b12b_Segments[mActualSegment].CounterModeStep--; dest--; } - WS2812B_SetDiodeColor(0 + dest, mModeColor[0]); - WS2812B_SetDiodeColor(0 + dest + WS2812B_LEDS/2, mModeColor[0]); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest, Ws28b12b_Segments[mActualSegment].ModeColor[0]); + WS2812B_SetDiodeColor(Ws28b12b_Segments[mActualSegment].IdStart + dest + SEGMENT_LENGTH/2, Ws28b12b_Segments[mActualSegment].ModeColor[0]); - iModeDelay = mSpeed; + Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed; } diff --git a/startup/startup_stm32f103x6.s b/startup/startup_stm32f103xb.s similarity index 93% rename from startup/startup_stm32f103x6.s rename to startup/startup_stm32f103xb.s index 3b9a953..3a0a3b9 100644 --- a/startup/startup_stm32f103x6.s +++ b/startup/startup_stm32f103xb.s @@ -1,10 +1,10 @@ /** *************** (C) COPYRIGHT 2017 STMicroelectronics ************************ - * @file startup_stm32f103x6.s + * @file startup_stm32f103xb.s * @author MCD Application Team * @version V4.2.0 * @date 31-March-2017 - * @brief STM32F103x6 Devices vector table for Atollic toolchain. + * @brief STM32F103xB Devices vector table for Atollic toolchain. * This module performs: * - Set the initial SP * - Set the initial PC == Reset_Handler, @@ -188,16 +188,16 @@ g_pfnVectors: .word TIM1_CC_IRQHandler .word TIM2_IRQHandler .word TIM3_IRQHandler - .word 0 + .word TIM4_IRQHandler .word I2C1_EV_IRQHandler .word I2C1_ER_IRQHandler - .word 0 - .word 0 + .word I2C2_EV_IRQHandler + .word I2C2_ER_IRQHandler .word SPI1_IRQHandler - .word 0 + .word SPI2_IRQHandler .word USART1_IRQHandler .word USART2_IRQHandler - .word 0 + .word USART3_IRQHandler .word EXTI15_10_IRQHandler .word RTC_Alarm_IRQHandler .word USBWakeUp_IRQHandler @@ -208,8 +208,8 @@ g_pfnVectors: .word 0 .word 0 .word 0 - .word BootRAM /* @0x108. This is for boot in RAM mode for - STM32F10x Low Density devices.*/ + .word BootRAM /* @0x108. This is for boot in RAM mode for + STM32F10x Medium Density devices. */ /******************************************************************************* * @@ -336,21 +336,36 @@ g_pfnVectors: .weak TIM3_IRQHandler .thumb_set TIM3_IRQHandler,Default_Handler + .weak TIM4_IRQHandler + .thumb_set TIM4_IRQHandler,Default_Handler + .weak I2C1_EV_IRQHandler .thumb_set I2C1_EV_IRQHandler,Default_Handler .weak I2C1_ER_IRQHandler .thumb_set I2C1_ER_IRQHandler,Default_Handler + .weak I2C2_EV_IRQHandler + .thumb_set I2C2_EV_IRQHandler,Default_Handler + + .weak I2C2_ER_IRQHandler + .thumb_set I2C2_ER_IRQHandler,Default_Handler + .weak SPI1_IRQHandler .thumb_set SPI1_IRQHandler,Default_Handler + .weak SPI2_IRQHandler + .thumb_set SPI2_IRQHandler,Default_Handler + .weak USART1_IRQHandler .thumb_set USART1_IRQHandler,Default_Handler .weak USART2_IRQHandler .thumb_set USART2_IRQHandler,Default_Handler + .weak USART3_IRQHandler + .thumb_set USART3_IRQHandler,Default_Handler + .weak EXTI15_10_IRQHandler .thumb_set EXTI15_10_IRQHandler,Default_Handler @@ -361,3 +376,4 @@ g_pfnVectors: .thumb_set USBWakeUp_IRQHandler,Default_Handler /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +