From ab74be4811ee462f6af126e0aaa3e4af342abb83 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 19 Jul 2024 13:02:31 +0700 Subject: [PATCH] correct itsybitsy dotstar --- Makefile | 9 +- src/boards/boards.c | 14 +- .../itsybitsy_nrf52840_express/board.cmake | 1 + src/boards/itsybitsy_nrf52840_express/board.h | 11 +- src/nrfx_config.h | 1 + src/nrfx_log.h | 135 ++++++++++++++++++ 6 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 src/boards/itsybitsy_nrf52840_express/board.cmake create mode 100644 src/nrfx_log.h diff --git a/Makefile b/Makefile index 497831d3..32359873 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ OUT_NAME = $(BOARD)_bootloader-$(GIT_VERSION) # merged file = compiled + sd MERGED_FILE = $(OUT_NAME)_$(SD_NAME)_$(SD_VERSION) +UF2_FAMILY_ID_BOOTLOADER = 0xd663823c + #------------------------------------------------------------------------------ # Tool Configure #------------------------------------------------------------------------------ @@ -435,7 +437,7 @@ $(BUILD)/$(OUT_NAME)_nosd.hex: $(BUILD)/$(OUT_NAME).hex # Bootolader self-update uf2 $(BUILD)/update-$(OUT_NAME)_nosd.uf2: $(BUILD)/$(OUT_NAME)_nosd.hex @echo Create $(notdir $@) - @python3 lib/uf2/utils/uf2conv.py -f 0xd663823c -c -o $@ $^ + @python3 lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) -c -o $@ $^ # merge bootloader and sd hex together $(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_NAME).hex @@ -488,6 +490,11 @@ flash-mbr: @echo Flashing: $(MBR_HEX) $(call FLASH_NOUICR_CMD,$(MBR_HEX)) +# flash using uf2 +flash-uf2: $(BUILD)/update-$(OUT_NAME)_nosd.uf2 + @echo Flashing: $(notdir $<) + python lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) --deploy $< + # dfu with adafruit-nrfutil using CDC interface dfu-flash: flash-dfu flash-dfu: $(BUILD)/$(MERGED_FILE).zip diff --git a/src/boards/boards.c b/src/boards/boards.c index e1b39f37..ea1f4b32 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -27,14 +27,14 @@ #include "app_scheduler.h" #include "app_timer.h" -#ifdef LED_APA102 +#ifdef LED_APA102_CLK #include "nrf_spim.h" #endif #define SCHED_MAX_EVENT_DATA_SIZE sizeof(app_timer_event_t) /**< Maximum size of scheduler events. */ #define SCHED_QUEUE_SIZE 30 /**< Maximum number of events in the scheduler queue. */ -#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102) +#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102_CLK) void neopixel_init(void); void neopixel_write(uint8_t* pixels); void neopixel_teardown(void); @@ -86,7 +86,7 @@ void board_init(void) { #endif #endif -#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102) +#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102_CLK) // use neopixel for use enumeration #ifdef NEOPIXEL_POWER_PIN nrf_gpio_cfg_output(NEOPIXEL_POWER_PIN); @@ -147,7 +147,7 @@ void board_teardown(void) { led_pwm_teardown(); #endif -#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102) +#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102_CLK) neopixel_teardown(); #endif @@ -362,7 +362,7 @@ static uint32_t primary_cycle_length; static uint32_t secondary_cycle_length; #endif -void led_tick() { +void led_tick(void) { uint32_t millis = _systick_count; uint32_t cycle = millis % primary_cycle_length; @@ -452,7 +452,7 @@ void led_state(uint32_t state) { final_color = (uint8_t*) &rgb_color; } -#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102) +#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102_CLK) if (final_color != NULL) { neopixel_write(final_color); } @@ -560,7 +560,7 @@ void neopixel_write(uint8_t* pixels) { #endif -#ifdef LED_APA102 +#ifdef LED_APA102_CLK #define BYTE_PER_PIXEL 4 // 4 zero bytes are required to initiate update diff --git a/src/boards/itsybitsy_nrf52840_express/board.cmake b/src/boards/itsybitsy_nrf52840_express/board.cmake new file mode 100644 index 00000000..25daf71d --- /dev/null +++ b/src/boards/itsybitsy_nrf52840_express/board.cmake @@ -0,0 +1 @@ +set(MCU_VARIANT nrf52840) diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index 2bc82e0a..a3b6c08b 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -34,9 +34,14 @@ #define LED_PRIMARY_PIN _PINNUM(0, 6) #define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 8) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_APA102_CLK _PINNUM(1, 9) +#define LED_APA102_DATA _PINNUM(0, 8) +#define LED_APA102_BRIGHTNESS 0x1 +#define APA102_NUMBER 1 + +// For dotstart set to max for colour information is not masked off +#define BOARD_RGB_BRIGHTNESS 0xffffffff + /*------------------------------------------------------------------*/ /* BUTTON diff --git a/src/nrfx_config.h b/src/nrfx_config.h index 74e5fdbc..23b3d83a 100644 --- a/src/nrfx_config.h +++ b/src/nrfx_config.h @@ -10,6 +10,7 @@ #define NRFX_PRS_ENABLED 0 +// PWM #define NRFX_PWM_ENABLED 0 #define NRFX_PWM0_ENABLED 0 #define NRFX_PWM1_ENABLED 0 diff --git a/src/nrfx_log.h b/src/nrfx_log.h new file mode 100644 index 00000000..3bc1b424 --- /dev/null +++ b/src/nrfx_log.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017 - 2019, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NRFX_LOG_H__ +#define NRFX_LOG_H__ + +// THIS IS A TEMPLATE FILE. +// It should be copied to a suitable location within the host environment into +// which nrfx is integrated, and the following macros should be provided with +// appropriate implementations. +// And this comment should be removed from the customized file. + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup nrfx_log nrfx_log.h + * @{ + * @ingroup nrfx + * + * @brief This file contains macros that should be implemented according to + * the needs of the host environment into which @em nrfx is integrated. + */ + +/** + * @brief Macro for logging a message with the severity level ERROR. + * + * @param format printf-style format string, optionally followed by arguments + * to be formatted and inserted in the resulting string. + */ +#define NRFX_LOG_ERROR(format, ...) + +/** + * @brief Macro for logging a message with the severity level WARNING. + * + * @param format printf-style format string, optionally followed by arguments + * to be formatted and inserted in the resulting string. + */ +#define NRFX_LOG_WARNING(format, ...) + +/** + * @brief Macro for logging a message with the severity level INFO. + * + * @param format printf-style format string, optionally followed by arguments + * to be formatted and inserted in the resulting string. + */ +#define NRFX_LOG_INFO(format, ...) + +/** + * @brief Macro for logging a message with the severity level DEBUG. + * + * @param format printf-style format string, optionally followed by arguments + * to be formatted and inserted in the resulting string. + */ +#define NRFX_LOG_DEBUG(format, ...) + + +/** + * @brief Macro for logging a memory dump with the severity level ERROR. + * + * @param[in] p_memory Pointer to the memory region to be dumped. + * @param[in] length Length of the memory region in bytes. + */ +#define NRFX_LOG_HEXDUMP_ERROR(p_memory, length) + +/** + * @brief Macro for logging a memory dump with the severity level WARNING. + * + * @param[in] p_memory Pointer to the memory region to be dumped. + * @param[in] length Length of the memory region in bytes. + */ +#define NRFX_LOG_HEXDUMP_WARNING(p_memory, length) + +/** + * @brief Macro for logging a memory dump with the severity level INFO. + * + * @param[in] p_memory Pointer to the memory region to be dumped. + * @param[in] length Length of the memory region in bytes. + */ +#define NRFX_LOG_HEXDUMP_INFO(p_memory, length) + +/** + * @brief Macro for logging a memory dump with the severity level DEBUG. + * + * @param[in] p_memory Pointer to the memory region to be dumped. + * @param[in] length Length of the memory region in bytes. + */ +#define NRFX_LOG_HEXDUMP_DEBUG(p_memory, length) + + +/** + * @brief Macro for getting the textual representation of a given error code. + * + * @param[in] error_code Error code. + * + * @return String containing the textual representation of the error code. + */ +#define NRFX_LOG_ERROR_STRING_GET(error_code) + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif // NRFX_LOG_H__