From 5ca7c285f58d9ddf6d729571005f3af153f14973 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 10 Jan 2021 05:17:49 +0000 Subject: [PATCH 1/5] moved neopixel to its own files with additional features --- hw/bsp/double_m33_express/board.mk | 2 + .../double_m33_express/double_m33_express.c | 182 +++---------- hw/bsp/double_m33_express/neopixel.c | 245 ++++++++++++++++++ hw/bsp/double_m33_express/neopixel.h | 53 ++++ 4 files changed, 340 insertions(+), 142 deletions(-) create mode 100644 hw/bsp/double_m33_express/neopixel.c create mode 100644 hw/bsp/double_m33_express/neopixel.h diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk index df42ad4cc..7ab9b7bf3 100644 --- a/hw/bsp/double_m33_express/board.mk +++ b/hw/bsp/double_m33_express/board.mk @@ -28,6 +28,8 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_flexcomm.c INC += \ + $(TOP)/hw/bsp/ \ + $(TOP)/hw/bsp/$(BOARD) \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ $(TOP)/$(MCU_DIR)/drivers diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index 187313a41..41f70453b 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -29,7 +29,9 @@ #include "fsl_gpio.h" #include "fsl_power.h" #include "fsl_iocon.h" +#include "fsl_usart.h" #include "fsl_sctimer.h" +#include "neopixel.h" //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler @@ -60,6 +62,7 @@ void USB1_IRQHandler(void) #define NEOPIXEL_NUMBER 2 #define NEOPIXEL_PORT 0 #define NEOPIXEL_PIN 27 +#define NEOPIXEL_CH 6 // UART #define UART_DEV USART0 @@ -80,142 +83,10 @@ void USB1_IRQHandler(void) #define IOCON_PIO_DIG_FUNC4_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC4) /*!<@brief Digital pin function 2 enabled */ #define IOCON_PIO_DIG_FUNC7_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC7) /*!<@brief Digital pin function 2 enabled */ -//--------------------------------------------------------------------+ -// Neopixel Driver -//--------------------------------------------------------------------+ -#define NEO_SCT SCT0 -#define NEO_MATCH_PERIOD 0 -#define NEO_MATCH_0 1 -#define NEO_MATCH_1 2 -#define NEO_EVENT_RISE 2 -#define NEO_EVENT_FALL_0 0 -#define NEO_EVENT_FALL_1 1 -#define NEO_EVENT_NEXT 3 -#define NEO_EVENT_START 4 -#define NEO_SCT_OUTPUT 6 -#define NEO_STATE_IDLE 24 -//#define NEO_ARRAY_SIZE (3 * NEOPIXEL_NUMBER) -//volatile uint32_t _neopixel_array[NEO_ARRAY_SIZE] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60}; -volatile uint32_t _neopixel_array[NEOPIXEL_NUMBER] = {0x404040, 0x202020}; -volatile uint32_t _neopixel_count = 0; - -void neopixel_int_handler(void){ - uint32_t eventFlag = NEO_SCT->EVFLAG; - if (eventFlag & (1 << NEO_EVENT_NEXT)) { - _neopixel_count += 1; - if (_neopixel_count < (NEOPIXEL_NUMBER)) { - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[_neopixel_count]); - NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); - } - } - NEO_SCT->EVFLAG = eventFlag; -} - -void SCT0_DriverIRQHandler(void){ - neopixel_int_handler(); - SDK_ISR_EXIT_BARRIER; -} - -void neopixel_set(uint32_t pixel, uint32_t color){ - if (pixel < NEOPIXEL_NUMBER) { - _neopixel_array[pixel] = color; - } -} - -void neopixel_update(void){ -// while (NEO_SCT->CTRL & SCT_CTRL_HALT_L_MASK); - _neopixel_count = 0; - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[0]); - NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); -} - - -/* -void neopixel_int_handler(void){ - uint32_t eventFlag = NEO_SCT->EVFLAG; -// if ((eventFlag & (1 << NEO_EVENT_NEXT)) && (_neopixel_count < (NEO_ARRAY_SIZE))) { -// NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[_neopixel_count]); - if ((eventFlag & (1 << NEO_EVENT_NEXT)) && (_neopixel_count < (NEOPIXEL_NUMBER))) { - _neopixel_count += 1; - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[_neopixel_count]); - NEO_SCT->EVFLAG = eventFlag; - NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); - } else { - NEO_SCT->EVFLAG = eventFlag; - } -} - -void SCT0_DriverIRQHandler(void){ - neopixel_int_handler(); - SDK_ISR_EXIT_BARRIER; -} - -void neopixel_update(uint32_t pixel, uint32_t color){ - if (pixel < NEOPIXEL_NUMBER) { - _neopixel_array[pixel] = color; - _neopixel_count = 0; -// NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[0]); - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[0]); - NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); - } -} -*/ -void neopixel_init(void) { - CLOCK_EnableClock(kCLOCK_Sct0); - RESET_PeripheralReset(kSCT0_RST_SHIFT_RSTn); - - NEO_SCT->CONFIG = ( - SCT_CONFIG_UNIFY(1) | - SCT_CONFIG_CLKMODE(kSCTIMER_System_ClockMode) | - SCT_CONFIG_NORELOAD_L(1) ); - NEO_SCT->CTRL = ( - SCT_CTRL_HALT_L(1) | - SCT_CTRL_CLRCTR_L(1) ); - - NEO_SCT->MATCH[NEO_MATCH_PERIOD] = 120; - NEO_SCT->MATCH[NEO_MATCH_0] = 30; - NEO_SCT->MATCH[NEO_MATCH_1] = 60; - NEO_SCT->EV[NEO_EVENT_START].STATE = (1 << NEO_STATE_IDLE); - NEO_SCT->EV[NEO_EVENT_START].CTRL = ( - kSCTIMER_OutputLowEvent | SCT_EV_CTRL_IOSEL(NEO_SCT_OUTPUT) | - SCT_EV_CTRL_STATELD(1) | SCT_EV_CTRL_STATEV(23)); -// NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFE; - NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFFFFFE; - NEO_SCT->EV[NEO_EVENT_RISE].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) | - SCT_EV_CTRL_STATELD(0) | SCT_EV_CTRL_STATEV(31)); - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0x0; - NEO_SCT->EV[NEO_EVENT_FALL_0].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) | - SCT_EV_CTRL_STATELD(0) ); -// NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFF; - NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFFFFFF; - NEO_SCT->EV[NEO_EVENT_FALL_1].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_1) | - SCT_EV_CTRL_STATELD(0) ); - NEO_SCT->EV[NEO_EVENT_NEXT].STATE = 0x1; - NEO_SCT->EV[NEO_EVENT_NEXT].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) | - SCT_EV_CTRL_STATELD(1) | SCT_EV_CTRL_STATEV(NEO_STATE_IDLE)); - - NEO_SCT->LIMIT = (1 << NEO_EVENT_START) | (1 << NEO_EVENT_RISE) | (1 << NEO_EVENT_NEXT); - NEO_SCT->HALT = (1 << NEO_EVENT_NEXT); - NEO_SCT->START = (1 << NEO_EVENT_START); - - NEO_SCT->OUT[NEO_SCT_OUTPUT].SET = (1 << NEO_EVENT_START) | (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[NEO_SCT_OUTPUT].CLR = (1 << NEO_EVENT_FALL_0) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_NEXT); - - NEO_SCT->STATE = NEO_STATE_IDLE; - NEO_SCT->OUTPUT = 0x0; - NEO_SCT->RES = SCT_RES_O6RES(0x2); - NEO_SCT->EVEN = (1 << NEO_EVENT_NEXT); - EnableIRQ(SCT0_IRQn); - - neopixel_set(0, 0x101000); - neopixel_set(1, 0x101000); - neopixel_update(); -} +// Global Variables +uint32_t pixelData[NEOPIXEL_NUMBER]; +neopixel_config_t neoConfig; /**************************************************************** @@ -282,7 +153,34 @@ void board_init(void) /* PORT0 PIN27 configured as SCT0_OUT6 */ IOCON_PinMuxSet(IOCON, NEOPIXEL_PORT, NEOPIXEL_PIN, IOCON_PIO_DIG_FUNC4_EN); - neopixel_init(); + neoConfig.pixelData[0] = NULL; + neoConfig.pixelCnt[0] = 0; + neoConfig.pixelData[1] = NULL; + neoConfig.pixelCnt[1] = 0; + neoConfig.pixelData[2] = NULL; + neoConfig.pixelCnt[2] = 0; + neoConfig.pixelData[3] = NULL; + neoConfig.pixelCnt[3] = 0; + neoConfig.pixelData[4] = NULL; + neoConfig.pixelCnt[4] = 0; + neoConfig.pixelData[5] = NULL; + neoConfig.pixelCnt[5] = 0; + neoConfig.pixelData[6] = NULL; + neoConfig.pixelCnt[6] = 0; + neoConfig.pixelData[7] = NULL; + neoConfig.pixelCnt[7] = 0; + neoConfig.pixelData[8] = NULL; + neoConfig.pixelCnt[8] = 0; + neoConfig.pixelData[9] = NULL; + neoConfig.pixelCnt[9] = 0; + neoConfig.pixelData[NEOPIXEL_CH] = pixelData; + neoConfig.pixelCnt[NEOPIXEL_CH] = NEOPIXEL_NUMBER; + neoConfig.syncUpdate = true; + neopixel_init(&neoConfig); + neopixel_setPixel(NEOPIXEL_CH, 0, 0x100010); + neopixel_setPixel(NEOPIXEL_CH, 1, 0x100010); + neopixel_refresh(); + // Button /* PORT0 PIN5 configured as PIO0_5 */ @@ -302,7 +200,7 @@ void board_init(void) CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0); usart_config_t uart_config; USART_GetDefaultConfig(&uart_config); - uart_config.baudRate_Bps = BOARD_UART_BAUDRATE; + uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE; uart_config.enableTx = true; uart_config.enableRx = true; USART_Init(UART_DEV, &uart_config, 12000000); @@ -359,13 +257,13 @@ void board_led_write(bool state) { GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); if (state) { - neopixel_set(0, 0x100000); - neopixel_set(1, 0x101010); + neopixel_setPixel(NEOPIXEL_CH, 0, 0x100000); + neopixel_setPixel(NEOPIXEL_CH, 1, 0x101010); } else { - neopixel_set(0, 0x001000); - neopixel_set(1, 0x000010); + neopixel_setPixel(NEOPIXEL_CH, 0, 0x001000); + neopixel_setPixel(NEOPIXEL_CH, 1, 0x000010); } - neopixel_update(); + neopixel_refresh(); } uint32_t board_button_read(void) diff --git a/hw/bsp/double_m33_express/neopixel.c b/hw/bsp/double_m33_express/neopixel.c new file mode 100644 index 000000000..8be01d35a --- /dev/null +++ b/hw/bsp/double_m33_express/neopixel.c @@ -0,0 +1,245 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Greg Steiert + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include "neopixel.h" +#include "board.h" +#include "fsl_device_registers.h" +#include "fsl_sctimer.h" + + +//--------------------------------------------------------------------+ +// Neopixel Driver +//--------------------------------------------------------------------+ +#define NEO_SCT SCT0 +#define NEO_MATCH_RISE 12 +#define NEO_MATCH_PERIOD 13 +#define NEO_MATCH_RESET 15 +#define NEO_MATCH_0 0 +#define NEO_MATCH_1 11 +#define NEO_EVENT_RISE 12 +#define NEO_EVENT_CH_0 0 +#define NEO_EVENT_CH_1 1 +#define NEO_EVENT_CH_2 2 +#define NEO_EVENT_CH_3 3 +#define NEO_EVENT_CH_4 4 +#define NEO_EVENT_CH_5 5 +#define NEO_EVENT_CH_6 6 +#define NEO_EVENT_CH_7 7 +#define NEO_EVENT_CH_8 8 +#define NEO_EVENT_CH_9 9 +#define NEO_EVENT_FALL_1 11 +#define NEO_EVENT_NEXT 13 +#define NEO_EVENT_LAST 14 +#define NEO_EVENT_RESET 15 +#define NEO_SCT_OUTPUT 6 +#define NEO_COUNT_RISE 1 +#define NEO_COUNT_FALL0 31 +#define NEO_COUNT_FALL1 61 +#define NEO_COUNT_PERIOD 120 +#define NEO_COUNT_RESET 8120 +#define NEO_FIRST_BIT 23 + +neopixel_config_t *neo; +uint32_t _neopixel_max_count = 0; +volatile uint32_t _neopixel_count = 0; +volatile bool _neopixel_busy = false; + +void neopixel_int_handler(void){ + uint32_t eventFlag = NEO_SCT->EVFLAG; + if (eventFlag & (1 << NEO_EVENT_RESET)) { + _neopixel_busy = false; + } else if (eventFlag & (1 << NEO_EVENT_LAST)) { + _neopixel_count += 1; + if (_neopixel_count < _neopixel_max_count) { + NEO_SCT->STATE = NEO_FIRST_BIT; + if (_neopixel_count < neo->pixelCnt[0]) { + NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[0][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[1]) { + NEO_SCT->EV[NEO_EVENT_CH_1].STATE = (~neo->pixelData[1][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[2]) { + NEO_SCT->EV[NEO_EVENT_CH_2].STATE = (~neo->pixelData[2][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[3]) { + NEO_SCT->EV[NEO_EVENT_CH_3].STATE = (~neo->pixelData[3][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[4]) { + NEO_SCT->EV[NEO_EVENT_CH_4].STATE = (~neo->pixelData[4][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[5]) { + NEO_SCT->EV[NEO_EVENT_CH_5].STATE = (~neo->pixelData[5][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[6]) { + NEO_SCT->EV[NEO_EVENT_CH_6].STATE = (~neo->pixelData[6][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[7]) { + NEO_SCT->EV[NEO_EVENT_CH_7].STATE = (~neo->pixelData[7][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[8]) { + NEO_SCT->EV[NEO_EVENT_CH_8].STATE = (~neo->pixelData[8][_neopixel_count]); } + if (_neopixel_count < neo->pixelCnt[9]) { + NEO_SCT->EV[NEO_EVENT_CH_9].STATE = (~neo->pixelData[9][_neopixel_count]); } + NEO_SCT->CTRL = SCT_CTRL_CLRCTR_L_MASK; + } else { + NEO_SCT->CTRL = 0x0; + } + } + NEO_SCT->EVFLAG = eventFlag; +} + +void SCT0_DriverIRQHandler(void){ + neopixel_int_handler(); + SDK_ISR_EXIT_BARRIER; +} + +void neopixel_setPixel(uint32_t ch, uint32_t pixel, uint32_t color){ + if (ch < 10) { + if (pixel < neo->pixelCnt[ch]) { + if (neo->syncUpdate) { + while (_neopixel_busy) { __NOP(); } + } + neo->pixelData[ch][pixel] = color; + } + } +} + +void neopixel_refresh(void){ +// while (NEO_SCT->CTRL & SCT_CTRL_HALT_L_MASK); + while (_neopixel_busy) {__NOP();} + _neopixel_busy = true; + _neopixel_count = 0; + NEO_SCT->STATE = NEO_FIRST_BIT; + if (neo->pixelCnt[0]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[0][0]); } + if (neo->pixelCnt[1]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[1][0]); } + if (neo->pixelCnt[2]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[2][0]); } + if (neo->pixelCnt[3]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[3][0]); } + if (neo->pixelCnt[4]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[4][0]); } + if (neo->pixelCnt[5]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[5][0]); } + if (neo->pixelCnt[6]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[6][0]); } + if (neo->pixelCnt[7]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[7][0]); } + if (neo->pixelCnt[8]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[8][0]); } + if (neo->pixelCnt[9]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[9][0]); } + NEO_SCT->CTRL = SCT_CTRL_CLRCTR_L_MASK; +} + +void neopixel_init(neopixel_config_t *config) { + neo = config; + CLOCK_EnableClock(kCLOCK_Sct0); + RESET_PeripheralReset(kSCT0_RST_SHIFT_RSTn); + + _neopixel_max_count = 0; + for (uint32_t i=0; i < 10; i++) { + if (_neopixel_max_count < neo->pixelCnt[i]) { + _neopixel_max_count = neo->pixelCnt[i]; + } + } + + NEO_SCT->CONFIG = ( + SCT_CONFIG_UNIFY(1) | + SCT_CONFIG_CLKMODE(kSCTIMER_System_ClockMode) | + SCT_CONFIG_NORELOAD_L(1) ); + NEO_SCT->CTRL = ( + SCT_CTRL_HALT_L(1) | + SCT_CTRL_CLRCTR_L(1) ); + + NEO_SCT->MATCH[NEO_MATCH_RISE] = NEO_COUNT_RISE; + NEO_SCT->MATCH[NEO_MATCH_PERIOD] = NEO_COUNT_PERIOD; + NEO_SCT->MATCH[NEO_MATCH_0] = NEO_COUNT_FALL0; + NEO_SCT->MATCH[NEO_MATCH_1] = NEO_COUNT_FALL1; + NEO_SCT->MATCH[NEO_MATCH_RESET] = NEO_COUNT_RESET; + NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFFFFFFFF; + NEO_SCT->EV[NEO_EVENT_RISE].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_RISE) ); + NEO_SCT->EV[NEO_EVENT_CH_0].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_0].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_1].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_1].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_2].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_2].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_3].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_3].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_4].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_4].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_5].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_5].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_6].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_6].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_7].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_7].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_8].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_8].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_CH_9].STATE = 0xF0F0F0F0; + NEO_SCT->EV[NEO_EVENT_CH_9].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); + NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFFFFFFFF; + NEO_SCT->EV[NEO_EVENT_FALL_1].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_1) ); + NEO_SCT->EV[NEO_EVENT_NEXT].STATE = 0xFFFFFFFE; + NEO_SCT->EV[NEO_EVENT_NEXT].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) | + SCT_EV_CTRL_STATELD(0) | SCT_EV_CTRL_STATEV(31)); + NEO_SCT->EV[NEO_EVENT_LAST].STATE = 0x1; + NEO_SCT->EV[NEO_EVENT_LAST].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) ); + NEO_SCT->EV[NEO_EVENT_RESET].STATE = 0xFFFFFFFF; + NEO_SCT->EV[NEO_EVENT_RESET].CTRL = ( + kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_RESET) ); + + NEO_SCT->LIMIT = (1 << NEO_EVENT_NEXT) | (1 << NEO_EVENT_RESET); + NEO_SCT->HALT = (1 << NEO_EVENT_LAST) | (1 << NEO_EVENT_RESET); + NEO_SCT->START = 0x0; + + NEO_SCT->OUT[0].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[0].CLR = (1 << NEO_EVENT_CH_0) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[1].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[1].CLR = (1 << NEO_EVENT_CH_1) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[2].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[2].CLR = (1 << NEO_EVENT_CH_2) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[3].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[3].CLR = (1 << NEO_EVENT_CH_3) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[4].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[4].CLR = (1 << NEO_EVENT_CH_4) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[5].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[5].CLR = (1 << NEO_EVENT_CH_5) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[6].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[6].CLR = (1 << NEO_EVENT_CH_6) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[7].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[7].CLR = (1 << NEO_EVENT_CH_7) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[8].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[8].CLR = (1 << NEO_EVENT_CH_8) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + NEO_SCT->OUT[9].SET = (1 << NEO_EVENT_RISE); + NEO_SCT->OUT[9].CLR = (1 << NEO_EVENT_CH_9) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); + + NEO_SCT->OUTPUT = 0x0; + NEO_SCT->RES = SCT_RES_O6RES(0x2); + NEO_SCT->EVEN = (1 << NEO_EVENT_LAST) | (1 << NEO_EVENT_RESET); + EnableIRQ(SCT0_IRQn); + +// neopixel_setPixel(0, 0x101000); +// neopixel_setPixel(1, 0x101000); +// neopixel_refresh(); +} diff --git a/hw/bsp/double_m33_express/neopixel.h b/hw/bsp/double_m33_express/neopixel.h new file mode 100644 index 000000000..a444a354c --- /dev/null +++ b/hw/bsp/double_m33_express/neopixel.h @@ -0,0 +1,53 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Greg Steiert + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef _SCT_NEOPIXEL_H_ +#define _SCT_NEOPIXEL_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include +#include + +typedef struct _neopixel_config { + uint32_t *pixelData[10]; + uint32_t pixelCnt[10]; + uint32_t pixelType; + bool syncUpdate; +} neopixel_config_t; + +void neopixel_init(neopixel_config_t *config); +void neopixel_refresh(void); +void neopixel_setPixel(uint32_t ch, uint32_t pixel, uint32_t color); + + + +#ifdef __cplusplus + } +#endif + +#endif \ No newline at end of file From f4300afb1ce12a6f63c1e31d2e413f59e304ce77 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 10 Jan 2021 18:31:40 +0000 Subject: [PATCH 2/5] moving sct neopixel driver to shared library --- .gitmodules | 3 + hw/bsp/double_m33_express/board.mk | 4 +- .../double_m33_express/double_m33_express.c | 47 +--- hw/bsp/double_m33_express/neopixel.c | 245 ------------------ hw/bsp/double_m33_express/neopixel.h | 53 ---- lib/sct_neopixel | 1 + 6 files changed, 19 insertions(+), 334 deletions(-) delete mode 100644 hw/bsp/double_m33_express/neopixel.c delete mode 100644 hw/bsp/double_m33_express/neopixel.h create mode 160000 lib/sct_neopixel diff --git a/.gitmodules b/.gitmodules index dd55bdc0c..1fefa13f0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -109,3 +109,6 @@ [submodule "lib/CMSIS_5"] path = lib/CMSIS_5 url = https://github.com/ARM-software/CMSIS_5.git +[submodule "lib/sct_neopixel"] + path = lib/sct_neopixel + url = https://github.com/gsteiert/sct_neopixel diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk index 7ab9b7bf3..6cc2495de 100644 --- a/hw/bsp/double_m33_express/board.mk +++ b/hw/bsp/double_m33_express/board.mk @@ -25,11 +25,13 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_power.c \ $(MCU_DIR)/drivers/fsl_reset.c \ $(MCU_DIR)/drivers/fsl_usart.c \ - $(MCU_DIR)/drivers/fsl_flexcomm.c + $(MCU_DIR)/drivers/fsl_flexcomm.c \ + $(TOP)/lib/sct_neopixel/sct_neopixel.c INC += \ $(TOP)/hw/bsp/ \ $(TOP)/hw/bsp/$(BOARD) \ + $(TOP)/lib/sct_neopixel \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ $(TOP)/$(MCU_DIR)/drivers diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index 41f70453b..655f23cc0 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -31,7 +31,7 @@ #include "fsl_iocon.h" #include "fsl_usart.h" #include "fsl_sctimer.h" -#include "neopixel.h" +#include "sct_neopixel.h" //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler @@ -63,6 +63,7 @@ void USB1_IRQHandler(void) #define NEOPIXEL_PORT 0 #define NEOPIXEL_PIN 27 #define NEOPIXEL_CH 6 +#define NEOPIXEL_TYPE 0 // UART #define UART_DEV USART0 @@ -86,8 +87,6 @@ void USB1_IRQHandler(void) // Global Variables uint32_t pixelData[NEOPIXEL_NUMBER]; -neopixel_config_t neoConfig; - /**************************************************************** name: BOARD_BootClockFROHF96M @@ -153,33 +152,11 @@ void board_init(void) /* PORT0 PIN27 configured as SCT0_OUT6 */ IOCON_PinMuxSet(IOCON, NEOPIXEL_PORT, NEOPIXEL_PIN, IOCON_PIO_DIG_FUNC4_EN); - neoConfig.pixelData[0] = NULL; - neoConfig.pixelCnt[0] = 0; - neoConfig.pixelData[1] = NULL; - neoConfig.pixelCnt[1] = 0; - neoConfig.pixelData[2] = NULL; - neoConfig.pixelCnt[2] = 0; - neoConfig.pixelData[3] = NULL; - neoConfig.pixelCnt[3] = 0; - neoConfig.pixelData[4] = NULL; - neoConfig.pixelCnt[4] = 0; - neoConfig.pixelData[5] = NULL; - neoConfig.pixelCnt[5] = 0; - neoConfig.pixelData[6] = NULL; - neoConfig.pixelCnt[6] = 0; - neoConfig.pixelData[7] = NULL; - neoConfig.pixelCnt[7] = 0; - neoConfig.pixelData[8] = NULL; - neoConfig.pixelCnt[8] = 0; - neoConfig.pixelData[9] = NULL; - neoConfig.pixelCnt[9] = 0; - neoConfig.pixelData[NEOPIXEL_CH] = pixelData; - neoConfig.pixelCnt[NEOPIXEL_CH] = NEOPIXEL_NUMBER; - neoConfig.syncUpdate = true; - neopixel_init(&neoConfig); - neopixel_setPixel(NEOPIXEL_CH, 0, 0x100010); - neopixel_setPixel(NEOPIXEL_CH, 1, 0x100010); - neopixel_refresh(); + sctpix_init(NEOPIXEL_TYPE); + sctpix_addCh(NEOPIXEL_CH, pixelData, NEOPIXEL_NUMBER); + sctpix_setPixel(NEOPIXEL_CH, 0, 0x100010); + sctpix_setPixel(NEOPIXEL_CH, 1, 0x100010); + sctpix_show(); // Button @@ -257,13 +234,13 @@ void board_led_write(bool state) { GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); if (state) { - neopixel_setPixel(NEOPIXEL_CH, 0, 0x100000); - neopixel_setPixel(NEOPIXEL_CH, 1, 0x101010); + sctpix_setPixel(NEOPIXEL_CH, 0, 0x100000); + sctpix_setPixel(NEOPIXEL_CH, 1, 0x101010); } else { - neopixel_setPixel(NEOPIXEL_CH, 0, 0x001000); - neopixel_setPixel(NEOPIXEL_CH, 1, 0x000010); + sctpix_setPixel(NEOPIXEL_CH, 0, 0x001000); + sctpix_setPixel(NEOPIXEL_CH, 1, 0x000010); } - neopixel_refresh(); + sctpix_show(); } uint32_t board_button_read(void) diff --git a/hw/bsp/double_m33_express/neopixel.c b/hw/bsp/double_m33_express/neopixel.c deleted file mode 100644 index 8be01d35a..000000000 --- a/hw/bsp/double_m33_express/neopixel.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Greg Steiert - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#include "neopixel.h" -#include "board.h" -#include "fsl_device_registers.h" -#include "fsl_sctimer.h" - - -//--------------------------------------------------------------------+ -// Neopixel Driver -//--------------------------------------------------------------------+ -#define NEO_SCT SCT0 -#define NEO_MATCH_RISE 12 -#define NEO_MATCH_PERIOD 13 -#define NEO_MATCH_RESET 15 -#define NEO_MATCH_0 0 -#define NEO_MATCH_1 11 -#define NEO_EVENT_RISE 12 -#define NEO_EVENT_CH_0 0 -#define NEO_EVENT_CH_1 1 -#define NEO_EVENT_CH_2 2 -#define NEO_EVENT_CH_3 3 -#define NEO_EVENT_CH_4 4 -#define NEO_EVENT_CH_5 5 -#define NEO_EVENT_CH_6 6 -#define NEO_EVENT_CH_7 7 -#define NEO_EVENT_CH_8 8 -#define NEO_EVENT_CH_9 9 -#define NEO_EVENT_FALL_1 11 -#define NEO_EVENT_NEXT 13 -#define NEO_EVENT_LAST 14 -#define NEO_EVENT_RESET 15 -#define NEO_SCT_OUTPUT 6 -#define NEO_COUNT_RISE 1 -#define NEO_COUNT_FALL0 31 -#define NEO_COUNT_FALL1 61 -#define NEO_COUNT_PERIOD 120 -#define NEO_COUNT_RESET 8120 -#define NEO_FIRST_BIT 23 - -neopixel_config_t *neo; -uint32_t _neopixel_max_count = 0; -volatile uint32_t _neopixel_count = 0; -volatile bool _neopixel_busy = false; - -void neopixel_int_handler(void){ - uint32_t eventFlag = NEO_SCT->EVFLAG; - if (eventFlag & (1 << NEO_EVENT_RESET)) { - _neopixel_busy = false; - } else if (eventFlag & (1 << NEO_EVENT_LAST)) { - _neopixel_count += 1; - if (_neopixel_count < _neopixel_max_count) { - NEO_SCT->STATE = NEO_FIRST_BIT; - if (_neopixel_count < neo->pixelCnt[0]) { - NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[0][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[1]) { - NEO_SCT->EV[NEO_EVENT_CH_1].STATE = (~neo->pixelData[1][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[2]) { - NEO_SCT->EV[NEO_EVENT_CH_2].STATE = (~neo->pixelData[2][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[3]) { - NEO_SCT->EV[NEO_EVENT_CH_3].STATE = (~neo->pixelData[3][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[4]) { - NEO_SCT->EV[NEO_EVENT_CH_4].STATE = (~neo->pixelData[4][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[5]) { - NEO_SCT->EV[NEO_EVENT_CH_5].STATE = (~neo->pixelData[5][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[6]) { - NEO_SCT->EV[NEO_EVENT_CH_6].STATE = (~neo->pixelData[6][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[7]) { - NEO_SCT->EV[NEO_EVENT_CH_7].STATE = (~neo->pixelData[7][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[8]) { - NEO_SCT->EV[NEO_EVENT_CH_8].STATE = (~neo->pixelData[8][_neopixel_count]); } - if (_neopixel_count < neo->pixelCnt[9]) { - NEO_SCT->EV[NEO_EVENT_CH_9].STATE = (~neo->pixelData[9][_neopixel_count]); } - NEO_SCT->CTRL = SCT_CTRL_CLRCTR_L_MASK; - } else { - NEO_SCT->CTRL = 0x0; - } - } - NEO_SCT->EVFLAG = eventFlag; -} - -void SCT0_DriverIRQHandler(void){ - neopixel_int_handler(); - SDK_ISR_EXIT_BARRIER; -} - -void neopixel_setPixel(uint32_t ch, uint32_t pixel, uint32_t color){ - if (ch < 10) { - if (pixel < neo->pixelCnt[ch]) { - if (neo->syncUpdate) { - while (_neopixel_busy) { __NOP(); } - } - neo->pixelData[ch][pixel] = color; - } - } -} - -void neopixel_refresh(void){ -// while (NEO_SCT->CTRL & SCT_CTRL_HALT_L_MASK); - while (_neopixel_busy) {__NOP();} - _neopixel_busy = true; - _neopixel_count = 0; - NEO_SCT->STATE = NEO_FIRST_BIT; - if (neo->pixelCnt[0]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[0][0]); } - if (neo->pixelCnt[1]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[1][0]); } - if (neo->pixelCnt[2]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[2][0]); } - if (neo->pixelCnt[3]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[3][0]); } - if (neo->pixelCnt[4]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[4][0]); } - if (neo->pixelCnt[5]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[5][0]); } - if (neo->pixelCnt[6]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[6][0]); } - if (neo->pixelCnt[7]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[7][0]); } - if (neo->pixelCnt[8]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[8][0]); } - if (neo->pixelCnt[9]) { NEO_SCT->EV[NEO_EVENT_CH_0].STATE = (~neo->pixelData[9][0]); } - NEO_SCT->CTRL = SCT_CTRL_CLRCTR_L_MASK; -} - -void neopixel_init(neopixel_config_t *config) { - neo = config; - CLOCK_EnableClock(kCLOCK_Sct0); - RESET_PeripheralReset(kSCT0_RST_SHIFT_RSTn); - - _neopixel_max_count = 0; - for (uint32_t i=0; i < 10; i++) { - if (_neopixel_max_count < neo->pixelCnt[i]) { - _neopixel_max_count = neo->pixelCnt[i]; - } - } - - NEO_SCT->CONFIG = ( - SCT_CONFIG_UNIFY(1) | - SCT_CONFIG_CLKMODE(kSCTIMER_System_ClockMode) | - SCT_CONFIG_NORELOAD_L(1) ); - NEO_SCT->CTRL = ( - SCT_CTRL_HALT_L(1) | - SCT_CTRL_CLRCTR_L(1) ); - - NEO_SCT->MATCH[NEO_MATCH_RISE] = NEO_COUNT_RISE; - NEO_SCT->MATCH[NEO_MATCH_PERIOD] = NEO_COUNT_PERIOD; - NEO_SCT->MATCH[NEO_MATCH_0] = NEO_COUNT_FALL0; - NEO_SCT->MATCH[NEO_MATCH_1] = NEO_COUNT_FALL1; - NEO_SCT->MATCH[NEO_MATCH_RESET] = NEO_COUNT_RESET; - NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFFFFFFFF; - NEO_SCT->EV[NEO_EVENT_RISE].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_RISE) ); - NEO_SCT->EV[NEO_EVENT_CH_0].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_0].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_1].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_1].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_2].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_2].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_3].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_3].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_4].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_4].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_5].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_5].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_6].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_6].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_7].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_7].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_8].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_8].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_CH_9].STATE = 0xF0F0F0F0; - NEO_SCT->EV[NEO_EVENT_CH_9].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) ); - NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFFFFFFFF; - NEO_SCT->EV[NEO_EVENT_FALL_1].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_1) ); - NEO_SCT->EV[NEO_EVENT_NEXT].STATE = 0xFFFFFFFE; - NEO_SCT->EV[NEO_EVENT_NEXT].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) | - SCT_EV_CTRL_STATELD(0) | SCT_EV_CTRL_STATEV(31)); - NEO_SCT->EV[NEO_EVENT_LAST].STATE = 0x1; - NEO_SCT->EV[NEO_EVENT_LAST].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) ); - NEO_SCT->EV[NEO_EVENT_RESET].STATE = 0xFFFFFFFF; - NEO_SCT->EV[NEO_EVENT_RESET].CTRL = ( - kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_RESET) ); - - NEO_SCT->LIMIT = (1 << NEO_EVENT_NEXT) | (1 << NEO_EVENT_RESET); - NEO_SCT->HALT = (1 << NEO_EVENT_LAST) | (1 << NEO_EVENT_RESET); - NEO_SCT->START = 0x0; - - NEO_SCT->OUT[0].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[0].CLR = (1 << NEO_EVENT_CH_0) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[1].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[1].CLR = (1 << NEO_EVENT_CH_1) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[2].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[2].CLR = (1 << NEO_EVENT_CH_2) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[3].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[3].CLR = (1 << NEO_EVENT_CH_3) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[4].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[4].CLR = (1 << NEO_EVENT_CH_4) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[5].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[5].CLR = (1 << NEO_EVENT_CH_5) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[6].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[6].CLR = (1 << NEO_EVENT_CH_6) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[7].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[7].CLR = (1 << NEO_EVENT_CH_7) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[8].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[8].CLR = (1 << NEO_EVENT_CH_8) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - NEO_SCT->OUT[9].SET = (1 << NEO_EVENT_RISE); - NEO_SCT->OUT[9].CLR = (1 << NEO_EVENT_CH_9) | (1 << NEO_EVENT_FALL_1) | (1 << NEO_EVENT_LAST); - - NEO_SCT->OUTPUT = 0x0; - NEO_SCT->RES = SCT_RES_O6RES(0x2); - NEO_SCT->EVEN = (1 << NEO_EVENT_LAST) | (1 << NEO_EVENT_RESET); - EnableIRQ(SCT0_IRQn); - -// neopixel_setPixel(0, 0x101000); -// neopixel_setPixel(1, 0x101000); -// neopixel_refresh(); -} diff --git a/hw/bsp/double_m33_express/neopixel.h b/hw/bsp/double_m33_express/neopixel.h deleted file mode 100644 index a444a354c..000000000 --- a/hw/bsp/double_m33_express/neopixel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Greg Steiert - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef _SCT_NEOPIXEL_H_ -#define _SCT_NEOPIXEL_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#include -#include - -typedef struct _neopixel_config { - uint32_t *pixelData[10]; - uint32_t pixelCnt[10]; - uint32_t pixelType; - bool syncUpdate; -} neopixel_config_t; - -void neopixel_init(neopixel_config_t *config); -void neopixel_refresh(void); -void neopixel_setPixel(uint32_t ch, uint32_t pixel, uint32_t color); - - - -#ifdef __cplusplus - } -#endif - -#endif \ No newline at end of file diff --git a/lib/sct_neopixel b/lib/sct_neopixel new file mode 160000 index 000000000..e73e04ca6 --- /dev/null +++ b/lib/sct_neopixel @@ -0,0 +1 @@ +Subproject commit e73e04ca63495672d955f9268e003cffe168fcd8 From 8fa083d79e1325c19f2bc0af894fdf7f8ab5e84c Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:46:29 +0900 Subject: [PATCH 3/5] added support for cmd.exe as a shell on make. --- examples/make.mk | 5 +++++ examples/rules.mk | 10 ++++++++++ tools/top.mk | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/make.mk b/examples/make.mk index 6743044fd..ee4ed640e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -34,9 +34,14 @@ CXX = $(CROSS_COMPILE)g++ OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size MKDIR = mkdir +ifeq ($(UNAME),Windows) +CP = copy +RM = del +else SED = sed CP = cp RM = rm +endif #-------------- Source files and compiler flags -------------- diff --git a/examples/rules.mk b/examples/rules.mk index 37e0e7a19..a445f0339 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -81,7 +81,11 @@ uf2: $(BUILD)/$(BOARD)-firmware.uf2 OBJ_DIRS = $(sort $(dir $(OBJ))) $(OBJ): | $(OBJ_DIRS) $(OBJ_DIRS): +ifeq ($(UNAME),Windows) + @$(MKDIR) $(subst /,\,$@) +else @$(MKDIR) -p $@ +endif $(BUILD)/$(BOARD)-firmware.elf: $(OBJ) @echo LINK $@ @@ -107,6 +111,7 @@ vpath %.c . $(TOP) $(BUILD)/obj/%.o: %.c @echo CC $(notdir $@) @$(CC) $(CFLAGS) -c -MD -o $@ $< +ifneq ($(UNAME),Windows) @# The following fixes the dependency file. @# See http://make.paulandlesley.org/autodep.html for details. @# Regex adjusted from the above to play better with Windows paths, etc. @@ -114,6 +119,7 @@ $(BUILD)/obj/%.o: %.c $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ $(RM) $(@:.o=.d) +endif # ASM sources lower case .s vpath %.s . $(TOP) @@ -134,7 +140,11 @@ size: $(BUILD)/$(BOARD)-firmware.elf .PHONY: clean clean: +ifeq ($(UNAME),Windows) + rd /S /Q $(subst /,\,$(BUILD)) +else $(RM) -rf $(BUILD) +endif # Print out the value of a make variable. # https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile diff --git a/tools/top.mk b/tools/top.mk index be51b3f4f..d276f5814 100644 --- a/tools/top.mk +++ b/tools/top.mk @@ -2,6 +2,12 @@ ifneq ($(lastword a b),b) $(error This Makefile require make 3.81 or newer) endif +# Detect windows or not +# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 +ifeq '$(findstring ;,$(PATH))' ';' +UNAME := Windows +endif + # Set TOP to be the path to get from the current directory (where make was # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns # the name of this makefile relative to where make was invoked. @@ -9,9 +15,16 @@ endif THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) +ifeq ($(UNAME),Windows) +TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) +else TOP := $(shell realpath $(TOP)) - +endif #$(info Top directory is $(TOP)) +ifeq ($(UNAME),Windows) +CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) +else CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) +endif #$(info Path from top is $(CURRENT_PATH)) From fc69dd70cf3c669308240bb0a6bb05d6eda51487 Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Tue, 12 Jan 2021 01:02:17 +0900 Subject: [PATCH 4/5] Changed some source file paths for SRC_C to relative paths. Added statements to validate GCCVERSION on Windows Command Prompt. --- hw/bsp/adafruit_clue/board.mk | 6 ++++++ hw/bsp/arduino_nano33_ble/board.mk | 6 ++++++ hw/bsp/circuitplayground_bluefruit/board.mk | 6 ++++++ hw/bsp/da14695_dk_usb/board.mk | 2 +- hw/bsp/da1469x_dk_pro/board.mk | 2 +- hw/bsp/double_m33_express/board.mk | 2 +- hw/bsp/feather_nrf52840_express/board.mk | 6 ++++++ hw/bsp/feather_nrf52840_sense/board.mk | 6 ++++++ hw/bsp/itsybitsy_nrf52840/board.mk | 6 ++++++ hw/bsp/nrf52840_mdk_dongle/board.mk | 6 ++++++ hw/bsp/pca10056/board.mk | 6 ++++++ hw/bsp/pca10059/board.mk | 6 ++++++ hw/bsp/pca10100/board.mk | 6 ++++++ hw/bsp/raytac_mdbt50q_rx/board.mk | 6 ++++++ 14 files changed, 69 insertions(+), 3 deletions(-) diff --git a/hw/bsp/adafruit_clue/board.mk b/hw/bsp/adafruit_clue/board.mk index d5f7c7cd4..ef6e093f5 100644 --- a/hw/bsp/adafruit_clue/board.mk +++ b/hw/bsp/adafruit_clue/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld diff --git a/hw/bsp/arduino_nano33_ble/board.mk b/hw/bsp/arduino_nano33_ble/board.mk index d1d62bdf2..63d1550d1 100644 --- a/hw/bsp/arduino_nano33_ble/board.mk +++ b/hw/bsp/arduino_nano33_ble/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. #LD_FILE = hw/bsp/$(BOARD)/linker_script.ld diff --git a/hw/bsp/circuitplayground_bluefruit/board.mk b/hw/bsp/circuitplayground_bluefruit/board.mk index d5f7c7cd4..ef6e093f5 100644 --- a/hw/bsp/circuitplayground_bluefruit/board.mk +++ b/hw/bsp/circuitplayground_bluefruit/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld diff --git a/hw/bsp/da14695_dk_usb/board.mk b/hw/bsp/da14695_dk_usb/board.mk index 8fef7d10f..b097262dc 100644 --- a/hw/bsp/da14695_dk_usb/board.mk +++ b/hw/bsp/da14695_dk_usb/board.mk @@ -21,7 +21,7 @@ SRC_C += \ $(MCU_FAMILY_DIR)/src/da1469x_clock.c \ $(MCU_FAMILY_DIR)/src/hal_gpio.c \ -SRC_S += $(TOP)/hw/bsp/$(BOARD)/gcc_startup_da1469x.S +SRC_S += hw/bsp/$(BOARD)/gcc_startup_da1469x.S INC += \ $(TOP)/hw/bsp/$(BOARD) \ diff --git a/hw/bsp/da1469x_dk_pro/board.mk b/hw/bsp/da1469x_dk_pro/board.mk index 60a62378c..16bd6de6b 100644 --- a/hw/bsp/da1469x_dk_pro/board.mk +++ b/hw/bsp/da1469x_dk_pro/board.mk @@ -21,7 +21,7 @@ SRC_C += \ $(MCU_FAMILY_DIR)/src/da1469x_clock.c \ $(MCU_FAMILY_DIR)/src/hal_gpio.c \ -SRC_S += $(TOP)/hw/bsp/$(BOARD)/gcc_startup_da1469x.S +SRC_S += hw/bsp/$(BOARD)/gcc_startup_da1469x.S INC += \ $(TOP)/hw/bsp/$(BOARD) \ diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk index 6cc2495de..c3401e5b2 100644 --- a/hw/bsp/double_m33_express/board.mk +++ b/hw/bsp/double_m33_express/board.mk @@ -26,7 +26,7 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_reset.c \ $(MCU_DIR)/drivers/fsl_usart.c \ $(MCU_DIR)/drivers/fsl_flexcomm.c \ - $(TOP)/lib/sct_neopixel/sct_neopixel.c + lib/sct_neopixel/sct_neopixel.c INC += \ $(TOP)/hw/bsp/ \ diff --git a/hw/bsp/feather_nrf52840_express/board.mk b/hw/bsp/feather_nrf52840_express/board.mk index 6cc972835..2feb070a8 100644 --- a/hw/bsp/feather_nrf52840_express/board.mk +++ b/hw/bsp/feather_nrf52840_express/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld diff --git a/hw/bsp/feather_nrf52840_sense/board.mk b/hw/bsp/feather_nrf52840_sense/board.mk index d5f7c7cd4..ef6e093f5 100644 --- a/hw/bsp/feather_nrf52840_sense/board.mk +++ b/hw/bsp/feather_nrf52840_sense/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld diff --git a/hw/bsp/itsybitsy_nrf52840/board.mk b/hw/bsp/itsybitsy_nrf52840/board.mk index 6cc972835..2feb070a8 100644 --- a/hw/bsp/itsybitsy_nrf52840/board.mk +++ b/hw/bsp/itsybitsy_nrf52840/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld diff --git a/hw/bsp/nrf52840_mdk_dongle/board.mk b/hw/bsp/nrf52840_mdk_dongle/board.mk index 8ce8929b8..baa4cc22e 100644 --- a/hw/bsp/nrf52840_mdk_dongle/board.mk +++ b/hw/bsp/nrf52840_mdk_dongle/board.mk @@ -13,9 +13,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/$(BOARD).ld diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index 8f4887dcb..3ea85983d 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf52840_xxaa.ld diff --git a/hw/bsp/pca10059/board.mk b/hw/bsp/pca10059/board.mk index bd7a80c0e..e9bc890cf 100644 --- a/hw/bsp/pca10059/board.mk +++ b/hw/bsp/pca10059/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/bsp/$(BOARD)/$(BOARD).ld diff --git a/hw/bsp/pca10100/board.mk b/hw/bsp/pca10100/board.mk index 4b5be082e..0b4d42f22 100644 --- a/hw/bsp/pca10100/board.mk +++ b/hw/bsp/pca10100/board.mk @@ -14,9 +14,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf52833_xxaa.ld diff --git a/hw/bsp/raytac_mdbt50q_rx/board.mk b/hw/bsp/raytac_mdbt50q_rx/board.mk index e153aab0b..6ff079dd7 100644 --- a/hw/bsp/raytac_mdbt50q_rx/board.mk +++ b/hw/bsp/raytac_mdbt50q_rx/board.mk @@ -13,9 +13,15 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) +ifeq ($(UNAME),Windows) +ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) +CFLAGS += -Wno-error=cast-function-type +endif +else ifeq ($(shell expr $(GCCVERSION) \>= 8), 1) CFLAGS += -Wno-error=cast-function-type endif +endif # All source paths should be relative to the top level. LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf52840_xxaa.ld From d7cfd8b91db127459d61aa8b8d091cb08e732208 Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Thu, 14 Jan 2021 01:19:43 +0900 Subject: [PATCH 5/5] replaced variable name to CMDEXE from UNAME. removed the rule that .d files are converted to .P files. --- examples/make.mk | 2 +- examples/rules.mk | 13 ++----------- hw/bsp/adafruit_clue/board.mk | 2 +- hw/bsp/arduino_nano33_ble/board.mk | 2 +- hw/bsp/circuitplayground_bluefruit/board.mk | 2 +- hw/bsp/feather_nrf52840_express/board.mk | 2 +- hw/bsp/feather_nrf52840_sense/board.mk | 2 +- hw/bsp/itsybitsy_nrf52840/board.mk | 2 +- hw/bsp/nrf52840_mdk_dongle/board.mk | 2 +- hw/bsp/pca10056/board.mk | 2 +- hw/bsp/pca10059/board.mk | 2 +- hw/bsp/pca10100/board.mk | 2 +- hw/bsp/raytac_mdbt50q_rx/board.mk | 2 +- tools/top.mk | 8 ++++---- 14 files changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/make.mk b/examples/make.mk index ee4ed640e..992a4e60e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -34,7 +34,7 @@ CXX = $(CROSS_COMPILE)g++ OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size MKDIR = mkdir -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) CP = copy RM = del else diff --git a/examples/rules.mk b/examples/rules.mk index a445f0339..2274d1cd2 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -81,7 +81,7 @@ uf2: $(BUILD)/$(BOARD)-firmware.uf2 OBJ_DIRS = $(sort $(dir $(OBJ))) $(OBJ): | $(OBJ_DIRS) $(OBJ_DIRS): -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) @$(MKDIR) $(subst /,\,$@) else @$(MKDIR) -p $@ @@ -111,15 +111,6 @@ vpath %.c . $(TOP) $(BUILD)/obj/%.o: %.c @echo CC $(notdir $@) @$(CC) $(CFLAGS) -c -MD -o $@ $< -ifneq ($(UNAME),Windows) - @# The following fixes the dependency file. - @# See http://make.paulandlesley.org/autodep.html for details. - @# Regex adjusted from the above to play better with Windows paths, etc. - @$(CP) $(@:.o=.d) $(@:.o=.P); \ - $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ - -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ - $(RM) $(@:.o=.d) -endif # ASM sources lower case .s vpath %.s . $(TOP) @@ -140,7 +131,7 @@ size: $(BUILD)/$(BOARD)-firmware.elf .PHONY: clean clean: -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) rd /S /Q $(subst /,\,$(BUILD)) else $(RM) -rf $(BUILD) diff --git a/hw/bsp/adafruit_clue/board.mk b/hw/bsp/adafruit_clue/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/adafruit_clue/board.mk +++ b/hw/bsp/adafruit_clue/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/arduino_nano33_ble/board.mk b/hw/bsp/arduino_nano33_ble/board.mk index 63d1550d1..1ee8867e6 100644 --- a/hw/bsp/arduino_nano33_ble/board.mk +++ b/hw/bsp/arduino_nano33_ble/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/circuitplayground_bluefruit/board.mk b/hw/bsp/circuitplayground_bluefruit/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/circuitplayground_bluefruit/board.mk +++ b/hw/bsp/circuitplayground_bluefruit/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/feather_nrf52840_express/board.mk b/hw/bsp/feather_nrf52840_express/board.mk index 2feb070a8..059e55dff 100644 --- a/hw/bsp/feather_nrf52840_express/board.mk +++ b/hw/bsp/feather_nrf52840_express/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/feather_nrf52840_sense/board.mk b/hw/bsp/feather_nrf52840_sense/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/feather_nrf52840_sense/board.mk +++ b/hw/bsp/feather_nrf52840_sense/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/itsybitsy_nrf52840/board.mk b/hw/bsp/itsybitsy_nrf52840/board.mk index 2feb070a8..059e55dff 100644 --- a/hw/bsp/itsybitsy_nrf52840/board.mk +++ b/hw/bsp/itsybitsy_nrf52840/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/nrf52840_mdk_dongle/board.mk b/hw/bsp/nrf52840_mdk_dongle/board.mk index baa4cc22e..3c44e402c 100644 --- a/hw/bsp/nrf52840_mdk_dongle/board.mk +++ b/hw/bsp/nrf52840_mdk_dongle/board.mk @@ -13,7 +13,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index 3ea85983d..b8691525b 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10059/board.mk b/hw/bsp/pca10059/board.mk index e9bc890cf..178f09474 100644 --- a/hw/bsp/pca10059/board.mk +++ b/hw/bsp/pca10059/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10100/board.mk b/hw/bsp/pca10100/board.mk index 0b4d42f22..8ada94ba0 100644 --- a/hw/bsp/pca10100/board.mk +++ b/hw/bsp/pca10100/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/raytac_mdbt50q_rx/board.mk b/hw/bsp/raytac_mdbt50q_rx/board.mk index 6ff079dd7..2c29acfa6 100644 --- a/hw/bsp/raytac_mdbt50q_rx/board.mk +++ b/hw/bsp/raytac_mdbt50q_rx/board.mk @@ -13,7 +13,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/tools/top.mk b/tools/top.mk index d276f5814..84523a557 100644 --- a/tools/top.mk +++ b/tools/top.mk @@ -2,10 +2,10 @@ ifneq ($(lastword a b),b) $(error This Makefile require make 3.81 or newer) endif -# Detect windows or not +# Detect whether shell style is windows or not # https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 ifeq '$(findstring ;,$(PATH))' ';' -UNAME := Windows +CMDEXE := 1 endif # Set TOP to be the path to get from the current directory (where make was @@ -15,14 +15,14 @@ endif THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) else TOP := $(shell realpath $(TOP)) endif #$(info Top directory is $(TOP)) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) else CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`)