From 2bbfc56bd8b52c9d5f6cdcfb1ab76cd868ddacd7 Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Fri, 27 Nov 2020 00:49:25 +0900 Subject: added support for frdm_kl25z --- hw/bsp/board_mcu.h | 2 +- hw/bsp/frdm_kl25z/board.mk | 46 +++++++++++++ hw/bsp/frdm_kl25z/frdm_kl25z.c | 148 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 hw/bsp/frdm_kl25z/board.mk create mode 100644 hw/bsp/frdm_kl25z/frdm_kl25z.c (limited to 'hw') diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h index eedae43f7..1cf0ad03c 100644 --- a/hw/bsp/board_mcu.h +++ b/hw/bsp/board_mcu.h @@ -46,7 +46,7 @@ #include "chip.h" #elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ - CFG_TUSB_MCU == OPT_MCU_LPC55XX + CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX #include "fsl_device_registers.h" #elif CFG_TUSB_MCU == OPT_MCU_NRF5X diff --git a/hw/bsp/frdm_kl25z/board.mk b/hw/bsp/frdm_kl25z/board.mk new file mode 100644 index 000000000..9d86c4542 --- /dev/null +++ b/hw/bsp/frdm_kl25z/board.mk @@ -0,0 +1,46 @@ +CFLAGS += \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m0plus \ + -DCPU_MKL25Z128VLK4 \ + -DCFG_TUSB_MCU=OPT_MCU_MKL25ZXX + +# mcu driver cause following warnings +CFLAGS += -Wno-error=unused-parameter + +MCU_DIR = hw/mcu/nxp/sdk/devices/MKL25Z4 + +# All source paths should be relative to the top level. +LD_FILE = $(MCU_DIR)/gcc/MKL25Z128xxx4_flash.ld + +SRC_C += \ + $(MCU_DIR)/system_MKL25Z4.c \ + $(MCU_DIR)/project_template/clock_config.c \ + $(MCU_DIR)/drivers/fsl_clock.c \ + $(MCU_DIR)/drivers/fsl_gpio.c \ + $(MCU_DIR)/drivers/fsl_lpsci.c + +INC += \ + $(TOP)/hw/bsp/$(BOARD) \ + $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ + $(TOP)/$(MCU_DIR) \ + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(MCU_DIR)/project_template \ + +SRC_S += $(MCU_DIR)/gcc/startup_MKL25Z4.S + +# For TinyUSB port source +VENDOR = nxp +CHIP_FAMILY = khci + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM0 + +# For flash-jlink target +JLINK_DEVICE = MKL25Z128xxx4 + +# For flash-pyocd target +PYOCD_TARGET = mkl25zl128 + +# flash using pyocd +flash: flash-pyocd diff --git a/hw/bsp/frdm_kl25z/frdm_kl25z.c b/hw/bsp/frdm_kl25z/frdm_kl25z.c new file mode 100644 index 000000000..7d3a173ed --- /dev/null +++ b/hw/bsp/frdm_kl25z/frdm_kl25z.c @@ -0,0 +1,148 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018, hathach (tinyusb.org) + * Copyright (c) 2020, Koji Kitayama + * + * 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. + * + * This file is part of the TinyUSB stack. + */ + +#include "../board.h" +#include "fsl_device_registers.h" +#include "fsl_gpio.h" +#include "fsl_port.h" +#include "fsl_clock.h" +#include "fsl_lpsci.h" + +#include "clock_config.h" + +//--------------------------------------------------------------------+ +// Forward USB interrupt events to TinyUSB IRQ Handler +//--------------------------------------------------------------------+ +void USB0_IRQHandler(void) +{ + tud_int_handler(0); +} + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ +// LED +#define LED_PINMUX IOMUXC_GPIO_AD_B0_09_GPIO1_IO09 +#define LED_PORT GPIOB +#define LED_PIN_CLOCK kCLOCK_PortB +#define LED_PIN_PORT PORTB +#define LED_PIN 19U +#define LED_PIN_FUNCTION kPORT_MuxAsGpio +#define LED_STATE_ON 0 + +// UART +#define UART_PORT UART0 +#define UART_PIN_CLOCK kCLOCK_PortA +#define UART_PIN_PORT PORTA +#define UART_PIN_RX 1u +#define UART_PIN_TX 2u +#define UART_PIN_FUNCTION kPORT_MuxAlt2 +#define SOPT5_UART0RXSRC_UART_RX 0x00u /*!< UART0 receive data source select: UART0_RX pin */ +#define SOPT5_UART0TXSRC_UART_TX 0x00u /*!< UART0 transmit data source select: UART0_TX pin */ + +const uint8_t dcd_data[] = { 0x00 }; + +void board_init(void) +{ + BOARD_BootClockRUN(); + SystemCoreClockUpdate(); + +#if CFG_TUSB_OS == OPT_OS_NONE + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); +#elif CFG_TUSB_OS == OPT_OS_FREERTOS + // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) + NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); +#endif + + // LED + CLOCK_EnableClock(LED_PIN_CLOCK); + PORT_SetPinMux(LED_PIN_PORT, LED_PIN, LED_PIN_FUNCTION); + gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0 }; + GPIO_PinInit(LED_PORT, LED_PIN, &led_config); + board_led_write(true); + + // UART + CLOCK_EnableClock(UART_PIN_CLOCK); + PORT_SetPinMux(UART_PIN_PORT, UART_PIN_RX, UART_PIN_FUNCTION); + PORT_SetPinMux(UART_PIN_PORT, UART_PIN_TX, UART_PIN_FUNCTION); + SIM->SOPT5 = ((SIM->SOPT5 & + (~(SIM_SOPT5_UART0TXSRC_MASK | SIM_SOPT5_UART0RXSRC_MASK))) + | SIM_SOPT5_UART0TXSRC(SOPT5_UART0TXSRC_UART_TX) + | SIM_SOPT5_UART0RXSRC(SOPT5_UART0RXSRC_UART_RX) + ); + + lpsci_config_t uart_config; + CLOCK_SetLpsci0Clock(1); + LPSCI_GetDefaultConfig(&uart_config); + uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE; + uart_config.enableTx = true; + uart_config.enableRx = true; + LPSCI_Init(UART_PORT, &uart_config, CLOCK_GetPllFllSelClkFreq()); + + // USB + CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); +} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +void board_led_write(bool state) +{ + GPIO_WritePinOutput(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); +} + +uint32_t board_button_read(void) +{ + return 0; +} + +int board_uart_read(uint8_t* buf, int len) +{ + LPSCI_ReadBlocking(UART_PORT, buf, len); + return len; +} + +int board_uart_write(void const * buf, int len) +{ + LPSCI_WriteBlocking(UART_PORT, (uint8_t*)buf, len); + return len; +} + +#if CFG_TUSB_OS == OPT_OS_NONE +volatile uint32_t system_ticks = 0; +void SysTick_Handler(void) +{ + system_ticks++; +} + +uint32_t board_millis(void) +{ + return system_ticks; +} +#endif -- cgit v1.3.1 From 3951a940fd78f19665092f4f7aa80391d8b0c543 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 25 Dec 2020 23:10:57 +0700 Subject: update readme, contributor and doc for new port KL25 update nxp_driver --- CONTRIBUTORS.md | 3 +++ README.md | 5 +++-- docs/boards.md | 4 ++++ hw/mcu/nxp | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'hw') diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index bcd6959e9..8acbd69e2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -31,6 +31,9 @@ - **[Kay Sievers](https://github.com/kaysievers)** - Improve MIDI driver with packet API +- **[Koji KITAYAMA](https://github.com/kkitayam)** + - Add new DCD port for **NXP Kinetis KL25** + - **[Nathan Conrad](https://github.com/pigrew)** - Add new DCD port for **STM32 fsdev** Fullspeed device for STM32 L0, F0, F1, F3 etc ... - Add new class driver for **USB Test and Measurement Class (USBTMC)** diff --git a/README.md b/README.md index 372b52c18..0ed84e9e8 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,10 @@ The stack supports the following MCUs: - **MicroChip:** SAMD11, SAMD21, SAMD51, SAME5x, SAMG55 - **NordicSemi:** nRF52833, nRF52840 - **Nuvoton:** NUC120, NUC121/NUC125, NUC126, NUC505 -- **NXP:** - - LPC Series: 11Uxx, 13xx, 175x_6x, 177x_8x, 18xx, 40xx, 43xx, 51Uxx, 54xxx, 55xx +- **NXP:** - iMX RT Series: RT1011, RT1015, RT1021, RT1052, RT1062, RT1064 + - Kinetis: KL25 + - LPC Series: 11Uxx, 13xx, 175x_6x, 177x_8x, 18xx, 40xx, 43xx, 51Uxx, 54xxx, 55xx - **Sony:** CXD56 - **ST:** STM32 series: L0, F0, F1, F2, F3, F4, F7, H7 both FullSpeed and HighSpeed - **TI:** MSP430 diff --git a/docs/boards.md b/docs/boards.md index 59f6905ea..da8deb72a 100644 --- a/docs/boards.md +++ b/docs/boards.md @@ -68,6 +68,10 @@ This code base already had supported for a handful of following boards (sorted a - [MIMX RT1064 Evaluation Kit](https://www.nxp.com/design/development-boards/i.mx-evaluation-and-development-boards/mimxrt1064-evk-i.mx-rt1064-evaluation-kit:MIMXRT1064-EVK) - [Teensy 4.0 Development Board](https://www.pjrc.com/store/teensy40.html) +### NXP Kinetis + +- [FRDM-KL25Z](https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-kinetis-kl14-kl15-kl24-kl25-mcus:FRDM-KL25Z) + ### NXP LPC - [ARM mbed LPC1768](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpc1700-cortex-m3/arm-mbed-lpc1768-board:OM11043) diff --git a/hw/mcu/nxp b/hw/mcu/nxp index b618cb1d5..587c65766 160000 --- a/hw/mcu/nxp +++ b/hw/mcu/nxp @@ -1 +1 @@ -Subproject commit b618cb1d521cc9e133bdcd0fca154dee2d925dfe +Subproject commit 587c65766538a5e1cfb6188ac611ded61f2eb859 -- cgit v1.3.1 From 56acdf67ba8c119f19d3c7fc2650e76f2873f091 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sat, 2 Jan 2021 22:53:15 +0000 Subject: adding double_m33_express board --- .../double_m33_express/LPC55S69_cm33_core0_uf2.ld | 234 +++++++++++++++++++++ hw/bsp/double_m33_express/board.mk | 49 +++++ hw/bsp/double_m33_express/double_m33_express.c | 227 ++++++++++++++++++++ 3 files changed, 510 insertions(+) create mode 100644 hw/bsp/double_m33_express/LPC55S69_cm33_core0_uf2.ld create mode 100644 hw/bsp/double_m33_express/board.mk create mode 100644 hw/bsp/double_m33_express/double_m33_express.c (limited to 'hw') diff --git a/hw/bsp/double_m33_express/LPC55S69_cm33_core0_uf2.ld b/hw/bsp/double_m33_express/LPC55S69_cm33_core0_uf2.ld new file mode 100644 index 000000000..6b5d852aa --- /dev/null +++ b/hw/bsp/double_m33_express/LPC55S69_cm33_core0_uf2.ld @@ -0,0 +1,234 @@ +/* +** ################################################################### +** Processors: LPC55S69JBD100_cm33_core0 +** LPC55S69JBD64_cm33_core0 +** LPC55S69JEV98_cm33_core0 +** +** Compiler: GNU C Compiler +** Reference manual: LPC55S6x/LPC55S2x/LPC552x User manual(UM11126) Rev.1.3 16 May 2019 +** Version: rev. 1.1, 2019-05-16 +** Build: b191008 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright 2016 Freescale Semiconductor, Inc. +** Copyright 2016-2019 NXP +** All rights reserved. +** +** SPDX-License-Identifier: BSD-3-Clause +** +** http: www.nxp.com +** mail: support@nxp.com +** +** ################################################################### +*/ + + + +/* Entry Point */ +ENTRY(Reset_Handler) + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400; +STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0800; +RPMSG_SHMEM_SIZE = DEFINED(__use_shmem__) ? 0x1800 : 0; + +/* Specify the memory areas */ +MEMORY +{ + m_interrupts (RX) : ORIGIN = 0x00010000, LENGTH = 0x00000200 + m_text (RX) : ORIGIN = 0x00010200, LENGTH = 0x0007FE00 + m_core1_image (RX) : ORIGIN = 0x00090000, LENGTH = 0x00008000 + m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00033000 - RPMSG_SHMEM_SIZE + rpmsg_sh_mem (RW) : ORIGIN = 0x20033000 - RPMSG_SHMEM_SIZE, LENGTH = RPMSG_SHMEM_SIZE + m_usb_sram (RW) : ORIGIN = 0x40100000, LENGTH = 0x00004000 +} + +/* Define output sections */ +SECTIONS +{ + /* section for storing the secondary core image */ + .m0code : + { + . = ALIGN(4) ; + KEEP (*(.m0code)) + *(.m0code*) + . = ALIGN(4) ; + } > m_core1_image + + /* NOINIT section for rpmsg_sh_mem */ + .noinit_rpmsg_sh_mem (NOLOAD) : ALIGN(4) + { + __RPMSG_SH_MEM_START__ = .; + *(.noinit.$rpmsg_sh_mem*) + . = ALIGN(4) ; + __RPMSG_SH_MEM_END__ = .; + } > rpmsg_sh_mem + + /* The startup code goes first into internal flash */ + .interrupts : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + /* The program code and other data goes into internal flash */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.ramfunc*) /* for functions in ram */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __DATA_END = __DATA_ROM + (__data_end__ - __data_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; /* Add for _sbrk */ + } > m_data + + .stack : + { + . = ALIGN(8); + . += STACK_SIZE; + } > m_data + + m_usb_bdt (NOLOAD) : + { + . = ALIGN(512); + *(m_usb_bdt) + } > m_usb_sram + + m_usb_global (NOLOAD) : + { + *(m_usb_global) + } > m_usb_sram + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(m_data) + LENGTH(m_data); + __StackLimit = __StackTop - STACK_SIZE; + PROVIDE(__stack = __StackTop); + + .ARM.attributes 0 : { *(.ARM.attributes) } + + ASSERT(__StackLimit >= __HeapLimit, "region m_data overflowed with stack and heap") +} + diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk new file mode 100644 index 000000000..5b297cc3e --- /dev/null +++ b/hw/bsp/double_m33_express/board.mk @@ -0,0 +1,49 @@ +CFLAGS += \ + -flto \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m33 \ + -mfloat-abi=hard \ + -mfpu=fpv5-sp-d16 \ + -DCPU_LPC55S69JBD100_cm33_core0 \ + -DCFG_TUSB_MCU=OPT_MCU_LPC55XX \ + -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \ + -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' + +# mcu driver cause following warnings +CFLAGS += -Wno-error=unused-parameter -Wno-error=float-equal + +MCU_DIR = hw/mcu/nxp/sdk/devices/LPC55S69 + +# All source paths should be relative to the top level. +LD_FILE = hw/bsp/$(BOARD)/LPC55S69_cm33_core0_uf2.ld + +SRC_C += \ + $(MCU_DIR)/system_LPC55S69_cm33_core0.c \ + $(MCU_DIR)/drivers/fsl_clock.c \ + $(MCU_DIR)/drivers/fsl_gpio.c \ + $(MCU_DIR)/drivers/fsl_power.c \ + $(MCU_DIR)/drivers/fsl_reset.c + +INC += \ + $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ + $(TOP)/$(MCU_DIR) \ + $(TOP)/$(MCU_DIR)/drivers + +SRC_S += $(MCU_DIR)/gcc/startup_LPC55S69_cm33_core0.S + +LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_hardabi.a + +# For TinyUSB port source +VENDOR = nxp +CHIP_FAMILY = lpc_ip3511 + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM33_NTZ/non_secure + +# For flash-jlink target +JLINK_DEVICE = LPC55S69 + +# flash using pyocd +flash: $(BUILD)/$(BOARD)-firmware.hex + pyocd flash -t LPC55S69 $< diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c new file mode 100644 index 000000000..3d4a8f53d --- /dev/null +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -0,0 +1,227 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018, hathach (tinyusb.org) + * + * 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. + * + * This file is part of the TinyUSB stack. + */ + +#include "../board.h" +#include "fsl_device_registers.h" +#include "fsl_gpio.h" +#include "fsl_power.h" +#include "fsl_iocon.h" + +//--------------------------------------------------------------------+ +// Forward USB interrupt events to TinyUSB IRQ Handler +//--------------------------------------------------------------------+ +void USB0_IRQHandler(void) +{ + tud_int_handler(0); +} + +void USB1_IRQHandler(void) +{ + tud_int_handler(1); +} + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM +//--------------------------------------------------------------------+ +#define LED_PORT 0 +#define LED_PIN 1 +#define LED_STATE_ON 1 + +// WAKE button +#define BUTTON_PORT 0 +#define BUTTON_PIN 5 +#define BUTTON_STATE_ACTIVE 0 + +// IOCON pin mux +#define IOCON_PIO_DIGITAL_EN 0x0100u /*!<@brief Enables digital function */ +#define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */ +#define IOCON_PIO_FUNC1 0x01u /*!<@brief Selects pin function 1 */ +#define IOCON_PIO_FUNC7 0x07u /*!<@brief Selects pin function 7 */ +#define IOCON_PIO_INV_DI 0x00u /*!<@brief Input function is not inverted */ +#define IOCON_PIO_MODE_INACT 0x00u /*!<@brief No addition pin function */ +#define IOCON_PIO_OPENDRAIN_DI 0x00u /*!<@brief Open drain is disabled */ +#define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */ + +/**************************************************************** +name: BOARD_BootClockFROHF96M +outputs: +- {id: SYSTICK_clock.outFreq, value: 96 MHz} +- {id: System_clock.outFreq, value: 96 MHz} +settings: +- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf} +sources: +- {id: SYSCON.fro_hf.outFreq, value: 96 MHz} +******************************************************************/ +void BootClockFROHF96M(void) +{ + /*!< Set up the clock sources */ + /*!< Set up FRO */ + POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */ + CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */ + CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without + accidentally being below the voltage for current speed */ + + CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */ + + POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */ + CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */ + + /*!< Set up dividers */ + CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */ + + /*!< Set up clock selectors - Attach clocks to the peripheries */ + CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */ + + /*!< Set SystemCoreClock variable. */ + SystemCoreClock = 96000000U; +} + +void board_init(void) +{ + // Enable IOCON clock + CLOCK_EnableClock(kCLOCK_Iocon); + + // Init 96 MHz clock + BootClockFROHF96M(); + +#if CFG_TUSB_OS == OPT_OS_NONE + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); +#elif CFG_TUSB_OS == OPT_OS_FREERTOS + // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) + NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); +#endif + + GPIO_PortInit(GPIO, LED_PORT); + GPIO_PortInit(GPIO, BUTTON_PORT); + + // LED + gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; + GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); + board_led_write(true); + + // Button + const uint32_t port1_pin18_config = ( + IOCON_PIO_FUNC0 | /* Pin is configured as PIO1_18 */ + IOCON_PIO_MODE_INACT | /* No addition pin function */ + IOCON_PIO_SLEW_STANDARD | /* Standard mode, output slew rate control is enabled */ + IOCON_PIO_INV_DI | /* Input function is not inverted */ + IOCON_PIO_DIGITAL_EN | /* Enables digital function */ + IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ + ); + /* PORT1 PIN18 (coords: 64) is configured as PIO1_18 */ + IOCON_PinMuxSet(IOCON, 1U, 18U, port1_pin18_config); + + gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; + GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); + + // USB VBUS + const uint32_t port0_pin22_config = ( + IOCON_PIO_FUNC7 | /* Pin is configured as USB0_VBUS */ + IOCON_PIO_MODE_INACT | /* No addition pin function */ + IOCON_PIO_SLEW_STANDARD | /* Standard mode, output slew rate control is enabled */ + IOCON_PIO_INV_DI | /* Input function is not inverted */ + IOCON_PIO_DIGITAL_EN | /* Enables digital function */ + IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ + ); + /* PORT0 PIN22 (coords: 78) is configured as USB0_VBUS */ + IOCON_PinMuxSet(IOCON, 0U, 22U, port0_pin22_config); + + // USB Controller + POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB0 Phy */ + POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY); /*< Turn on USB1 Phy */ + + /* reset the IP to make sure it's in reset state. */ + RESET_PeripheralReset(kUSB0D_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB0HSL_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB0HMR_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB1H_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB1D_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB1_RST_SHIFT_RSTn); + RESET_PeripheralReset(kUSB1RAM_RST_SHIFT_RSTn); + +#if (defined USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS) + CLOCK_EnableClock(kCLOCK_Usbh1); + /* Put PHY powerdown under software control */ + *((uint32_t *)(USBHSH_BASE + 0x50)) = USBHSH_PORTMODE_SW_PDCOM_MASK; + /* According to reference mannual, device mode setting has to be set by access usb host register */ + *((uint32_t *)(USBHSH_BASE + 0x50)) |= USBHSH_PORTMODE_DEV_ENABLE_MASK; + /* enable usb1 host clock */ + CLOCK_DisableClock(kCLOCK_Usbh1); +#endif + +#if 1 || (defined USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS) + CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false); + CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); + /* enable usb0 host clock */ + CLOCK_EnableClock(kCLOCK_Usbhsl0); + /*According to reference mannual, device mode setting has to be set by access usb host register */ + *((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK; + /* disable usb0 host clock */ + CLOCK_DisableClock(kCLOCK_Usbhsl0); + CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbfsSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB Device clock */ +#endif +} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +void board_led_write(bool state) +{ + GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); +} + +uint32_t board_button_read(void) +{ + // active low + return BUTTON_STATE_ACTIVE == GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); +} + +int board_uart_read(uint8_t* buf, int len) +{ + (void) buf; (void) len; + return 0; +} + +int board_uart_write(void const * buf, int len) +{ + (void) buf; (void) len; + return 0; +} + +#if CFG_TUSB_OS == OPT_OS_NONE +volatile uint32_t system_ticks = 0; +void SysTick_Handler(void) +{ + system_ticks++; +} + +uint32_t board_millis(void) +{ + return system_ticks; +} +#endif -- cgit v1.3.1 From 06642910f4e1d5c333d0a18388428e1799d230e9 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 3 Jan 2021 18:11:13 +0000 Subject: neopixel driver one byte at a time non-func --- hw/bsp/double_m33_express/board.mk | 4 +- hw/bsp/double_m33_express/double_m33_express.c | 183 +++++++++++++++++++++---- 2 files changed, 157 insertions(+), 30 deletions(-) (limited to 'hw') diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk index 5b297cc3e..df42ad4cc 100644 --- a/hw/bsp/double_m33_express/board.mk +++ b/hw/bsp/double_m33_express/board.mk @@ -23,7 +23,9 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_clock.c \ $(MCU_DIR)/drivers/fsl_gpio.c \ $(MCU_DIR)/drivers/fsl_power.c \ - $(MCU_DIR)/drivers/fsl_reset.c + $(MCU_DIR)/drivers/fsl_reset.c \ + $(MCU_DIR)/drivers/fsl_usart.c \ + $(MCU_DIR)/drivers/fsl_flexcomm.c INC += \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index 3d4a8f53d..7992f424c 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -29,6 +29,7 @@ #include "fsl_gpio.h" #include "fsl_power.h" #include "fsl_iocon.h" +#include "fsl_sctimer.h" //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler @@ -55,16 +56,128 @@ void USB1_IRQHandler(void) #define BUTTON_PIN 5 #define BUTTON_STATE_ACTIVE 0 +// Number of neopixels +#define NEOPIXEL_NUMBER 2 +#define NEOPIXEL_PORT 0 +#define NEOPIXEL_PIN 27 + +// UART +#define UART_DEV USART0 + // IOCON pin mux #define IOCON_PIO_DIGITAL_EN 0x0100u /*!<@brief Enables digital function */ #define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */ #define IOCON_PIO_FUNC1 0x01u /*!<@brief Selects pin function 1 */ +#define IOCON_PIO_FUNC4 0x04u /*!<@brief Selects pin function 4 */ #define IOCON_PIO_FUNC7 0x07u /*!<@brief Selects pin function 7 */ #define IOCON_PIO_INV_DI 0x00u /*!<@brief Input function is not inverted */ #define IOCON_PIO_MODE_INACT 0x00u /*!<@brief No addition pin function */ #define IOCON_PIO_OPENDRAIN_DI 0x00u /*!<@brief Open drain is disabled */ #define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */ +#define IOCON_PIO_DIG_FUNC0_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC0) /*!<@brief Digital pin function 0 enabled */ +#define IOCON_PIO_DIG_FUNC1_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC1) /*!<@brief Digital pin function 1 enabled */ +#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 8 + +volatile uint8_t _neopixel_array[3*NEOPIXEL_NUMBER] = {0}; +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 < (3*NEOPIXEL_NUMBER))) { + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[_neopixel_count]); + _neopixel_count += 1; + } + NEO_SCT->EVFLAG = eventFlag; + NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); +} + +void SCT0_DriverIRQHandler(void){ + neopixel_int_handler(); + SDK_ISR_EXIT_BARRIER; +} + +void neopixel_update(uint32_t pixel, uint32_t color){ + if (pixel < NEOPIXEL_NUMBER) { + uint32_t index = 3*pixel; + _neopixel_array[index++] = color>>8; // green first + _neopixel_array[index++] = color>>16; // red + _neopixel_array[index] = color; // blue + _neopixel_count = 0; + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_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 << 24U); + 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(7)); + 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) | SCT_EV_CTRL_STATEV(31)); + 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) | SCT_EV_CTRL_STATEV(31)); + 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); + 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); + + 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_update(0, 0x404040); +} + + /**************************************************************** name: BOARD_BootClockFROHF96M outputs: @@ -115,40 +228,49 @@ void board_init(void) NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); #endif - GPIO_PortInit(GPIO, LED_PORT); - GPIO_PortInit(GPIO, BUTTON_PORT); + GPIO_PortInit(GPIO, 0); + GPIO_PortInit(GPIO, 1); // LED - gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; + /* PORT0 PIN1 configured as PIO0_1 */ + IOCON_PinMuxSet(IOCON, 0U, 1U, IOCON_PIO_DIG_FUNC0_EN); + + gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 1}; GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); - board_led_write(true); + + // Neopixel + /* PORT0 PIN27 configured as SCT0_OUT6 */ + IOCON_PinMuxSet(IOCON, 0U, 27U, IOCON_PIO_DIG_FUNC4_EN); + + neopixel_init(); // Button - const uint32_t port1_pin18_config = ( - IOCON_PIO_FUNC0 | /* Pin is configured as PIO1_18 */ - IOCON_PIO_MODE_INACT | /* No addition pin function */ - IOCON_PIO_SLEW_STANDARD | /* Standard mode, output slew rate control is enabled */ - IOCON_PIO_INV_DI | /* Input function is not inverted */ - IOCON_PIO_DIGITAL_EN | /* Enables digital function */ - IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ - ); - /* PORT1 PIN18 (coords: 64) is configured as PIO1_18 */ - IOCON_PinMuxSet(IOCON, 1U, 18U, port1_pin18_config); + /* PORT0 PIN5 configured as PIO0_5 */ + IOCON_PinMuxSet(IOCON, 0U, 5U, IOCON_PIO_DIG_FUNC0_EN); gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); + // UART + /* PORT0 PIN29 (coords: 92) is configured as FC0_RXD_SDA_MOSI_DATA */ + IOCON_PinMuxSet(IOCON, 0U, 29U, IOCON_PIO_DIG_FUNC1_EN); + /* PORT0 PIN30 (coords: 94) is configured as FC0_TXD_SCL_MISO_WS */ + IOCON_PinMuxSet(IOCON, 0U, 30U, IOCON_PIO_DIG_FUNC1_EN); + +#if defined(UART_DEV) && CFG_TUSB_DEBUG + // Enable UART when debug log is on + CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0); + usart_config_t uart_config; + USART_GetDefaultConfig(&uart_config); + uart_config.baudRate_Bps = BOARD_UART_BAUDRATE; + uart_config.enableTx = true; + uart_config.enableRx = true; + USART_Init(UART_DEV, &uart_config, 12000000); +#endif + // USB VBUS - const uint32_t port0_pin22_config = ( - IOCON_PIO_FUNC7 | /* Pin is configured as USB0_VBUS */ - IOCON_PIO_MODE_INACT | /* No addition pin function */ - IOCON_PIO_SLEW_STANDARD | /* Standard mode, output slew rate control is enabled */ - IOCON_PIO_INV_DI | /* Input function is not inverted */ - IOCON_PIO_DIGITAL_EN | /* Enables digital function */ - IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ - ); - /* PORT0 PIN22 (coords: 78) is configured as USB0_VBUS */ - IOCON_PinMuxSet(IOCON, 0U, 22U, port0_pin22_config); + /* PORT0 PIN22 configured as USB0_VBUS */ + IOCON_PinMuxSet(IOCON, 0U, 22U, IOCON_PIO_DIG_FUNC7_EN); // USB Controller POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB0 Phy */ @@ -163,27 +285,30 @@ void board_init(void) RESET_PeripheralReset(kUSB1_RST_SHIFT_RSTn); RESET_PeripheralReset(kUSB1RAM_RST_SHIFT_RSTn); -#if (defined USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS) +#if (defined CFG_TUSB_RHPORT1_MODE) && (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) CLOCK_EnableClock(kCLOCK_Usbh1); /* Put PHY powerdown under software control */ - *((uint32_t *)(USBHSH_BASE + 0x50)) = USBHSH_PORTMODE_SW_PDCOM_MASK; + USBHSH->PORTMODE = USBHSH_PORTMODE_SW_PDCOM_MASK; /* According to reference mannual, device mode setting has to be set by access usb host register */ - *((uint32_t *)(USBHSH_BASE + 0x50)) |= USBHSH_PORTMODE_DEV_ENABLE_MASK; + USBHSH->PORTMODE |= USBHSH_PORTMODE_DEV_ENABLE_MASK; /* enable usb1 host clock */ CLOCK_DisableClock(kCLOCK_Usbh1); #endif -#if 1 || (defined USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS) +#if (defined CFG_TUSB_RHPORT0_MODE) && (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) + // Enable USB Clock Adjustments to trim the FRO for the full speed controller + ANACTRL->FRO192M_CTRL |= ANACTRL_FRO192M_CTRL_USBCLKADJ_MASK; CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false); CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); /* enable usb0 host clock */ CLOCK_EnableClock(kCLOCK_Usbhsl0); /*According to reference mannual, device mode setting has to be set by access usb host register */ - *((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK; + USBFSH->PORTMODE |= USBFSH_PORTMODE_DEV_ENABLE_MASK; /* disable usb0 host clock */ CLOCK_DisableClock(kCLOCK_Usbhsl0); CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbfsSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB Device clock */ #endif + } //--------------------------------------------------------------------+ -- cgit v1.3.1 From 7f98d114547865a65e95376252a624e89f36f0a6 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 3 Jan 2021 18:31:45 +0000 Subject: 24 state implementation, only upsdates first LED --- hw/bsp/double_m33_express/double_m33_express.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'hw') diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index 7992f424c..d0a097bf0 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -93,15 +93,15 @@ void USB1_IRQHandler(void) #define NEO_EVENT_NEXT 3 #define NEO_EVENT_START 4 #define NEO_SCT_OUTPUT 6 -#define NEO_STATE_IDLE 8 +#define NEO_STATE_IDLE 24 -volatile uint8_t _neopixel_array[3*NEOPIXEL_NUMBER] = {0}; +volatile uint32_t _neopixel_array[NEOPIXEL_NUMBER] = {0x202020, 0x101010}; 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 < (3*NEOPIXEL_NUMBER))) { - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[_neopixel_count]); + if ((eventFlag == (1 << NEO_EVENT_NEXT)) && (_neopixel_count < (NEOPIXEL_NUMBER))) { + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[_neopixel_count]); _neopixel_count += 1; } NEO_SCT->EVFLAG = eventFlag; @@ -115,12 +115,15 @@ void SCT0_DriverIRQHandler(void){ void neopixel_update(uint32_t pixel, uint32_t color){ if (pixel < NEOPIXEL_NUMBER) { +/* uint32_t index = 3*pixel; _neopixel_array[index++] = color>>8; // green first _neopixel_array[index++] = color>>16; // red _neopixel_array[index] = color; // blue +*/ + _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); } } @@ -140,10 +143,10 @@ void neopixel_init(void) { 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 << 24U); + 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(7)); + SCT_EV_CTRL_STATELD(1) | SCT_EV_CTRL_STATEV(23)); NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFFFFFE; NEO_SCT->EV[NEO_EVENT_RISE].CTRL = ( kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_PERIOD) | @@ -240,13 +243,13 @@ void board_init(void) // Neopixel /* PORT0 PIN27 configured as SCT0_OUT6 */ - IOCON_PinMuxSet(IOCON, 0U, 27U, IOCON_PIO_DIG_FUNC4_EN); + IOCON_PinMuxSet(IOCON, NEOPIXEL_PORT, NEOPIXEL_PIN, IOCON_PIO_DIG_FUNC4_EN); neopixel_init(); // Button /* PORT0 PIN5 configured as PIO0_5 */ - IOCON_PinMuxSet(IOCON, 0U, 5U, IOCON_PIO_DIG_FUNC0_EN); + IOCON_PinMuxSet(IOCON, BUTTON_PORT, BUTTON_PIN, IOCON_PIO_DIG_FUNC0_EN); gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); -- cgit v1.3.1 From f44c588dd75eceb2191efb13069123d59e3770bd Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 3 Jan 2021 18:53:55 +0000 Subject: 8 state implementation, still not working --- hw/bsp/double_m33_express/double_m33_express.c | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'hw') diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index d0a097bf0..190f74066 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -93,19 +93,22 @@ void USB1_IRQHandler(void) #define NEO_EVENT_NEXT 3 #define NEO_EVENT_START 4 #define NEO_SCT_OUTPUT 6 -#define NEO_STATE_IDLE 24 +#define NEO_STATE_IDLE 8 +#define NEO_ARRAY_SIZE (3 * NEOPIXEL_NUMBER) -volatile uint32_t _neopixel_array[NEOPIXEL_NUMBER] = {0x202020, 0x101010}; +volatile uint32_t _neopixel_array[NEO_ARRAY_SIZE] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60}; 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 < (NEOPIXEL_NUMBER))) { - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[_neopixel_count]); + if ((eventFlag == (1 << NEO_EVENT_NEXT)) && (_neopixel_count < (NEO_ARRAY_SIZE))) { + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[_neopixel_count]); _neopixel_count += 1; + NEO_SCT->EVFLAG = eventFlag; + NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); + } else { + NEO_SCT->EVFLAG = eventFlag; } - NEO_SCT->EVFLAG = eventFlag; - NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); } void SCT0_DriverIRQHandler(void){ @@ -115,15 +118,13 @@ void SCT0_DriverIRQHandler(void){ void neopixel_update(uint32_t pixel, uint32_t color){ if (pixel < NEOPIXEL_NUMBER) { -/* uint32_t index = 3*pixel; _neopixel_array[index++] = color>>8; // green first _neopixel_array[index++] = color>>16; // red _neopixel_array[index] = color; // blue -*/ - _neopixel_array[pixel] = color; +// _neopixel_array[pixel] = color; _neopixel_count = 0; - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[0]); + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[0]); NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); } } @@ -146,8 +147,8 @@ void neopixel_init(void) { 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 = 0xFFFFFE; + SCT_EV_CTRL_STATELD(1) | SCT_EV_CTRL_STATEV(7)); + NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFE; 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)); @@ -155,7 +156,7 @@ void neopixel_init(void) { NEO_SCT->EV[NEO_EVENT_FALL_0].CTRL = ( kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_0) | SCT_EV_CTRL_STATELD(0) | SCT_EV_CTRL_STATEV(31)); - NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFFFFFF; + NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFF; NEO_SCT->EV[NEO_EVENT_FALL_1].CTRL = ( kSCTIMER_MatchEventOnly | SCT_EV_CTRL_MATCHSEL(NEO_MATCH_1) | SCT_EV_CTRL_STATELD(0) | SCT_EV_CTRL_STATEV(31)); -- cgit v1.3.1 From 33f0d4b314ec02a3bc4e825fd853cf1e2db4a957 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 3 Jan 2021 23:01:18 +0000 Subject: working neopixel --- hw/bsp/double_m33_express/double_m33_express.c | 38 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'hw') diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index 190f74066..a93cee669 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -93,17 +93,20 @@ void USB1_IRQHandler(void) #define NEO_EVENT_NEXT 3 #define NEO_EVENT_START 4 #define NEO_SCT_OUTPUT 6 -#define NEO_STATE_IDLE 8 -#define NEO_ARRAY_SIZE (3 * NEOPIXEL_NUMBER) +#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[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 < (NEO_ARRAY_SIZE))) { - NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[_neopixel_count]); +// 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 { @@ -118,13 +121,16 @@ void SCT0_DriverIRQHandler(void){ void neopixel_update(uint32_t pixel, uint32_t color){ if (pixel < NEOPIXEL_NUMBER) { + /* uint32_t index = 3*pixel; _neopixel_array[index++] = color>>8; // green first _neopixel_array[index++] = color>>16; // red _neopixel_array[index] = color; // blue -// _neopixel_array[pixel] = color; + */ + _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 = 0xFF & (~_neopixel_array[0]); + NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFFFFFF & (~_neopixel_array[0]); NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); } } @@ -147,30 +153,32 @@ void neopixel_init(void) { 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(7)); - NEO_SCT->EV[NEO_EVENT_RISE].STATE = 0xFE; + 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) | SCT_EV_CTRL_STATEV(31)); - NEO_SCT->EV[NEO_EVENT_FALL_1].STATE = 0xFF; + 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) | SCT_EV_CTRL_STATEV(31)); + 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); + 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); + 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; @@ -322,6 +330,8 @@ void board_init(void) void board_led_write(bool state) { GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); + _neopixel_array[1] = _neopixel_array[0]; + neopixel_update(0, state ? 0x001000 : 0x100000); } uint32_t board_button_read(void) -- cgit v1.3.1 From 0f11858b0e18bc3ccd789fd7bdd2bfa123d68ee0 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 3 Jan 2021 23:26:54 +0000 Subject: working neopixel minor refactor --- hw/bsp/double_m33_express/double_m33_express.c | 54 +++++++++++++++++++++----- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'hw') diff --git a/hw/bsp/double_m33_express/double_m33_express.c b/hw/bsp/double_m33_express/double_m33_express.c index a93cee669..187313a41 100644 --- a/hw/bsp/double_m33_express/double_m33_express.c +++ b/hw/bsp/double_m33_express/double_m33_express.c @@ -100,6 +100,38 @@ void USB1_IRQHandler(void) 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))) { @@ -121,12 +153,6 @@ void SCT0_DriverIRQHandler(void){ void neopixel_update(uint32_t pixel, uint32_t color){ if (pixel < NEOPIXEL_NUMBER) { - /* - uint32_t index = 3*pixel; - _neopixel_array[index++] = color>>8; // green first - _neopixel_array[index++] = color>>16; // red - _neopixel_array[index] = color; // blue - */ _neopixel_array[pixel] = color; _neopixel_count = 0; // NEO_SCT->EV[NEO_EVENT_FALL_0].STATE = 0xFF & (~_neopixel_array[0]); @@ -134,7 +160,7 @@ void neopixel_update(uint32_t pixel, uint32_t color){ NEO_SCT->CTRL &= ~(SCT_CTRL_HALT_L_MASK); } } - +*/ void neopixel_init(void) { CLOCK_EnableClock(kCLOCK_Sct0); RESET_PeripheralReset(kSCT0_RST_SHIFT_RSTn); @@ -186,7 +212,9 @@ void neopixel_init(void) { NEO_SCT->EVEN = (1 << NEO_EVENT_NEXT); EnableIRQ(SCT0_IRQn); - neopixel_update(0, 0x404040); + neopixel_set(0, 0x101000); + neopixel_set(1, 0x101000); + neopixel_update(); } @@ -330,8 +358,14 @@ void board_init(void) void board_led_write(bool state) { GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); - _neopixel_array[1] = _neopixel_array[0]; - neopixel_update(0, state ? 0x001000 : 0x100000); + if (state) { + neopixel_set(0, 0x100000); + neopixel_set(1, 0x101010); + } else { + neopixel_set(0, 0x001000); + neopixel_set(1, 0x000010); + } + neopixel_update(); } uint32_t board_button_read(void) -- cgit v1.3.1 From 5ca7c285f58d9ddf6d729571005f3af153f14973 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 10 Jan 2021 05:17:49 +0000 Subject: moved neopixel to its own files with additional features --- hw/bsp/double_m33_express/board.mk | 2 + hw/bsp/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 (limited to 'hw') 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 -- cgit v1.3.1 From f4300afb1ce12a6f63c1e31d2e413f59e304ce77 Mon Sep 17 00:00:00 2001 From: Greg Steiert Date: Sun, 10 Jan 2021 18:31:40 +0000 Subject: moving sct neopixel driver to shared library --- .gitmodules | 3 + hw/bsp/double_m33_express/board.mk | 4 +- hw/bsp/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 (limited to 'hw') 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 -- cgit v1.3.1 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: 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(-) (limited to 'hw') 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 -- cgit v1.3.1 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: 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(-) (limited to 'hw') 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`) -- cgit v1.3.1