Merge pull request #34 from tannewt/rework_leds
Rework leds, add Travis and add Particle boards
This commit is contained in:
commit
a1ed09c4d8
1
.gitignore
vendored
1
.gitignore
vendored
@ -53,3 +53,4 @@ dkms.conf
|
||||
|
||||
src/segger/Output
|
||||
_build-*/
|
||||
bin/
|
||||
|
33
.travis.yml
Normal file
33
.travis.yml
Normal file
@ -0,0 +1,33 @@
|
||||
sudo: required
|
||||
dist: xenial
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: "HGfSIgVPX8O+Wfs3E1l/qI8tJZ6wwEgFg3EO6E1+6eGZolr+LW+ANpMUTqcKy18VzbnSx+AH5Ktu8bw4XuPQRPaAvEIMDEZSbj//WE/nqo+p+SccxUy+mKK6x/gb4aiWUw8gYebeLNvWkU+JVupRqMkUdFOJJRZiIvp1usX+jNU8vTt07INNi90LZ8I/KvDEkvHJ/2nOBKW519rlp5XM0a5j8Bv+9gt5wgfl/hFW42JA4Gmj/nacZtro/3pYJWAZ4ZNLOsupMDPZGFX/Ndb+TqseBAkCLl2bvBZ5gFg4NvtaSRFZW532EXDmdCthUBLUGjw7V3VWq8shgHSi6Iq/5lL9t2jawkJPfp5JdiTPTLkUIZ8BfwwrbHp2qiTOGQHbN8kkfjtcQopjVdaPvavr4oaUN+ju6JNsTNc47FIcKivMi1TV6IUT4byjIWZ7ioV0X7KEdoD5WspjIYVhi1vwOBOLT0CEDMtPwIisZ3QuQGJ5clDMJ82ZU9LBfffzvBkeQNmMCM5L412FN7LP2lVNL5eafuJvFZS9Bpbp9uUhzHsDbbpLnz8TFa5rIMzKQXf1KbLnKZ7LHsieB2NleUE6OUxltNm1PwmWWxZKEZeRYxZSMgzbAOrl/Jl2F7zCU7RWCFRnvC73vVJAXaFJ3/DYBF21ew8NyOgMrRLOeH0s5rg="
|
||||
file:
|
||||
- $(ls -d1 bin/*/* | tr "\n" ":")
|
||||
skip_cleanup: true
|
||||
draft: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
before_script:
|
||||
- (wget https://s3.amazonaws.com/adafruit-circuit-python/gcc-arm-embedded_7-2018q2-1~xenial1_amd64.deb && sudo dpkg -i gcc-arm-embedded*_amd64.deb)
|
||||
- (wget https://www.nordicsemi.com/api/sitecore/Products/DownloadPlatform --post-data=fileid=8F19D314130548209E75EFFADD9348DB -O cli-tools.tar && tar -xv -f cli-tools.tar && mv mergehex mergehex_all && mv mergehex_all/mergehex .)
|
||||
- export PATH=.:$PATH
|
||||
- mergehex --version
|
||||
|
||||
# report some good version numbers to the build
|
||||
- gcc --version
|
||||
- arm-none-eabi-gcc --version
|
||||
- python3 --version
|
||||
- python --version
|
||||
- sudo apt-get install -y python3-pip python3-setuptools
|
||||
- pip3 install --user adafruit-nrfutil
|
||||
|
||||
script:
|
||||
- python3 tools/build_all.py
|
59
Makefile
59
Makefile
@ -5,7 +5,6 @@
|
||||
#
|
||||
# - SD_NAME : e.g s132, s140
|
||||
# - SD_VER1, SD_VER2, SD_VER3: SoftDevice version e.g 6.0.0
|
||||
# - SD_VER4 : is build number for bootloader
|
||||
# - SD_HEX : to bootloader hex binary
|
||||
#******************************************************************************
|
||||
SRC_PATH = src
|
||||
@ -20,10 +19,9 @@ NRFX_PATH = lib/nrfx
|
||||
SD_VER1 = 6
|
||||
SD_VER2 = 1
|
||||
SD_VER3 = 1
|
||||
SD_VER4 = 0
|
||||
|
||||
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
|
||||
SD_VERSION_FULL = $(SD_VERSION)r$(SD_VER4)
|
||||
SD_VERSION_FULL = $(SD_VERSION)
|
||||
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
|
||||
|
||||
|
||||
@ -31,14 +29,17 @@ SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
|
||||
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
|
||||
|
||||
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
|
||||
OUTPUT_FILENAME = $(BOARD)_bootloader
|
||||
|
||||
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION_FULL)
|
||||
RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION_FULL)
|
||||
|
||||
|
||||
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION) r$(SD_VER4)"
|
||||
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)"
|
||||
|
||||
GIT_VERSION = $(shell git describe --dirty --always --tags)
|
||||
GIT_SUBMODULE_VERSIONS = $(shell git submodule status | cut -d' ' -f3,4 | paste -s -d" " -)
|
||||
|
||||
OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION)
|
||||
#******************************************************************************
|
||||
# Tool configure
|
||||
#******************************************************************************
|
||||
@ -53,9 +54,7 @@ endif
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
PROGFILES = C:/Program Files (x86)
|
||||
GNU_INSTALL_ROOT = $(PROGFILES)/GNU Tools ARM Embedded/7 2018-q2-update
|
||||
else
|
||||
GNU_INSTALL_ROOT = /usr
|
||||
GNU_INSTALL_ROOT = $(PROGFILES)/GNU Tools ARM Embedded/7 2018-q2-update/bin/
|
||||
endif
|
||||
|
||||
MK := mkdir
|
||||
@ -70,14 +69,14 @@ endif
|
||||
GNU_PREFIX = arm-none-eabi
|
||||
|
||||
# Toolchain commands
|
||||
CC := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
|
||||
AS := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
|
||||
AR := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
|
||||
LD := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
|
||||
NM := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
|
||||
OBJDUMP := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
|
||||
OBJCOPY := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
|
||||
SIZE := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'
|
||||
CC := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gcc'
|
||||
AS := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-as'
|
||||
AR := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ar' -r
|
||||
LD := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ld'
|
||||
NM := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm'
|
||||
OBJDUMP := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump'
|
||||
OBJCOPY := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy'
|
||||
SIZE := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size'
|
||||
|
||||
#function for removing duplicates in a list
|
||||
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
|
||||
@ -87,7 +86,7 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
|
||||
#*********************************
|
||||
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*.h))))
|
||||
|
||||
NRF52840_BOARDLIST = pca10056 pca10059 feather_nrf52840_express
|
||||
NRF52840_BOARDLIST = pca10056 pca10059 feather_nrf52840_express particle_argon particle_boron particle_xenon
|
||||
IS_NRF52840 = $(filter $(BOARD),$(NRF52840_BOARDLIST))
|
||||
|
||||
ifeq ($(filter $(MAKECMDGOALS),all-board all-release help),)
|
||||
@ -255,7 +254,7 @@ CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
|
||||
CFLAGS += -fno-builtin --short-enums -fstack-usage
|
||||
|
||||
# Defined Symbol (MACROS)
|
||||
CFLAGS += -DMK_BOOTLOADER_VERSION=0x0$(SD_VER1)0$(SD_VER2)0$(SD_VER3)0$(SD_VER4)UL
|
||||
CFLAGS += -DMK_BOOTLOADER_VERSION=0x0$(SD_VER1)0$(SD_VER2)0$(SD_VER3)UL
|
||||
|
||||
CFLAGS += -D__HEAP_SIZE=0
|
||||
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
||||
@ -267,6 +266,8 @@ CFLAGS += -DFLOAT_ABI_HARD
|
||||
CFLAGS += -DMK_DIS_FIRMWARE='$(MK_DIS_FIRMWARE)'
|
||||
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
|
||||
|
||||
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"'
|
||||
|
||||
CFLAGS += -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
ifneq ($(IS_NRF52840),)
|
||||
@ -353,7 +354,7 @@ endif
|
||||
.phony: all clean size flash sd erase
|
||||
|
||||
# default target to build
|
||||
all: $(BUILD)/$(OUTPUT_FILENAME).out size
|
||||
all: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out size
|
||||
|
||||
# Rule using BOARD_LIST, nl is newline
|
||||
define nl
|
||||
@ -399,7 +400,7 @@ __check_defined = \
|
||||
ifeq ($(VERSION),)
|
||||
|
||||
# Flash the compiled
|
||||
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
|
||||
flash: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
|
||||
@echo Flashing: $<
|
||||
$(NRFJPROG) --program $< --sectoranduicrerase -f nrf52 --reset
|
||||
|
||||
@ -454,11 +455,11 @@ $(BUILD)/%.o: %.S
|
||||
$(QUIET)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
|
||||
|
||||
# Link
|
||||
$(BUILD)/$(OUTPUT_FILENAME).out: $(BUILD) $(OBJECTS)
|
||||
@echo LD $(OUTPUT_FILENAME).out
|
||||
$(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(BUILD)/$(OUTPUT_FILENAME).out
|
||||
$(BUILD)/$(OUTPUT_FILENAME)-nosd.out: $(BUILD) $(OBJECTS)
|
||||
@echo LD $(OUTPUT_FILENAME)-nosd.out
|
||||
$(QUIET)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $@
|
||||
|
||||
size: $(BUILD)/$(OUTPUT_FILENAME).out
|
||||
size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
|
||||
-@echo ''
|
||||
$(QUIET)$(SIZE) $<
|
||||
-@echo ''
|
||||
@ -468,24 +469,24 @@ size: $(BUILD)/$(OUTPUT_FILENAME).out
|
||||
.phony: genhex genpkg release
|
||||
|
||||
## Create binary .hex file from the .out file
|
||||
genhex: $(BUILD)/$(OUTPUT_FILENAME).hex
|
||||
genhex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
|
||||
|
||||
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).out
|
||||
@echo CR $(OUTPUT_FILENAME).hex
|
||||
$(BUILD)/$(OUTPUT_FILENAME)-nosd.hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
|
||||
@echo CR $(OUTPUT_FILENAME)-nosd.hex
|
||||
$(QUIET)$(OBJCOPY) -O ihex $< $@
|
||||
|
||||
|
||||
# merge bootloader and sd hex together
|
||||
combinehex: $(BUILD)/$(MERGED_FNAME).hex
|
||||
|
||||
$(BUILD)/$(MERGED_FNAME).hex: $(BUILD)/$(OUTPUT_FILENAME).hex
|
||||
$(BUILD)/$(MERGED_FNAME).hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
|
||||
@echo CR $(MERGED_FNAME).hex
|
||||
@mergehex -q -m $< $(SD_HEX) -o $@
|
||||
|
||||
## Create pkg file for bootloader+SD combo to use with DFU
|
||||
genpkg: $(BUILD)/$(MERGED_FNAME).zip
|
||||
|
||||
$(BUILD)/$(MERGED_FNAME).zip: $(BUILD)/$(OUTPUT_FILENAME).hex
|
||||
$(BUILD)/$(MERGED_FNAME).zip: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
|
||||
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@
|
||||
|
||||
# Create SD+bootloader combo with hex & dfu package at release folder
|
||||
|
24
README.md
24
README.md
@ -1,11 +1,14 @@
|
||||
# Adafruit Bluefruit nRF52 Bootloader
|
||||
|
||||
This is a CDC/DFU/UF2 bootloader for Adafruit nRF52 boards and Nordic development boards.
|
||||
This is a CDC/DFU/UF2 bootloader for nRF52 boards.
|
||||
|
||||
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
|
||||
- Adafruit Feather nRF52840 Express
|
||||
- Nordic nRF52840DK PCA10056
|
||||
- Nordic nRF52840DK PCA10059 ("Dongle")
|
||||
- Particle Argon
|
||||
- Particle Boron
|
||||
- Particle Xenon
|
||||
|
||||
UF2 is an easy-to-use bootloader that appears as a flash drive. You can just copy `.uf2`-format
|
||||
application images to the flash drive to load new firmware.
|
||||
@ -84,24 +87,7 @@ To upgrade with dfu serial
|
||||
make BOARD=feather_nrf52840_express VERSION=6.1.1r0 dfu-flash
|
||||
```
|
||||
|
||||
Pre-builtin binaries are in the `bin` directory:
|
||||
|
||||
```
|
||||
bin/feather_nrf52832/
|
||||
2.0.1
|
||||
5.0.0
|
||||
6.1.0r0
|
||||
|
||||
bin/feather_nrf52840_express
|
||||
6.1.0r0
|
||||
|
||||
bin/pca10056:
|
||||
6.1.0r0
|
||||
|
||||
bin/pca10059:
|
||||
6.1.0r0
|
||||
```
|
||||
|
||||
Pre-builtin binaries are available on GitHub releases.
|
||||
|
||||
Note: The bootloader can be downgraded. Since the binary release is a merged version of
|
||||
of both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to any version you like.
|
||||
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -136,6 +136,8 @@ static void wait_for_events(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
led_tick();
|
||||
|
||||
if ((m_update_status == BOOTLOADER_COMPLETE) ||
|
||||
(m_update_status == BOOTLOADER_TIMEOUT) ||
|
||||
(m_update_status == BOOTLOADER_RESET) )
|
||||
@ -467,4 +469,3 @@ void bootloader_settings_get(bootloader_settings_t * const p_settings)
|
||||
p_settings->app_image_size = p_bootloader_settings->app_image_size;
|
||||
p_settings->sd_image_start = p_bootloader_settings->sd_image_start;
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ static void on_dfu_evt(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt)
|
||||
break;
|
||||
|
||||
case BLE_DFU_PACKET_WRITE:
|
||||
led_red_blink_fast(true);
|
||||
led_state(STATE_WRITING_STARTED);
|
||||
on_dfu_pkt_write(p_dfu, p_evt);
|
||||
break;
|
||||
|
||||
@ -741,6 +741,7 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
|
||||
m_is_advertising = false;
|
||||
led_state(STATE_BLE_CONNECTED);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
@ -750,7 +751,7 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
|
||||
|
||||
m_direct_adv_cnt = APP_DIRECTED_ADV_TIMEOUT;
|
||||
|
||||
led_red_blink_fast(false);
|
||||
led_state(STATE_BLE_DISCONNECTED);
|
||||
|
||||
err_code = sd_ble_gatts_sys_attr_get(m_conn_handle,
|
||||
sys_attr,
|
||||
|
@ -227,14 +227,14 @@ static void process_dfu_packet(void * p_event_data, uint16_t event_size)
|
||||
retval = dfu_init_pkt_complete();
|
||||
APP_ERROR_CHECK(retval);
|
||||
|
||||
led_red_blink_fast(true);
|
||||
led_state(STATE_WRITING_STARTED);
|
||||
break;
|
||||
|
||||
case STOP_DATA_PACKET:
|
||||
(void)dfu_image_validate();
|
||||
(void)dfu_image_activate();
|
||||
|
||||
led_red_blink_fast(false);
|
||||
led_state(STATE_WRITING_FINISHED);
|
||||
|
||||
// Break the loop by returning.
|
||||
return;
|
||||
@ -311,4 +311,3 @@ uint32_t dfu_transport_serial_close(void)
|
||||
|
||||
return hci_transport_close();
|
||||
}
|
||||
|
||||
|
227
src/boards.c
227
src/boards.c
@ -45,21 +45,11 @@
|
||||
#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. */
|
||||
|
||||
/* use PWM for blinky to prevent inconsistency due to MCU blocking in flash operation
|
||||
* clock = 125khz --> resolution = 8us
|
||||
* top value = 25000 -> period = 200 ms
|
||||
* Mode up -> toggle every 100 ms = fast blink
|
||||
* Mode up and down = 400 ms = slow blink
|
||||
*/
|
||||
#define PWM_MAXCOUNT 25000
|
||||
#define PWM_CHANNEL_NUM 4
|
||||
|
||||
|
||||
uint16_t _pwm_red_seq [PWM_CHANNEL_NUM] = { PWM_MAXCOUNT/2, 0, 0 , 0 };
|
||||
uint16_t _pwm_blue_seq[PWM_CHANNEL_NUM] = { PWM_MAXCOUNT/2, 0, 0 , 0 };
|
||||
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
|
||||
void neopixel_write(uint8_t *pixels);
|
||||
#endif
|
||||
|
||||
//------------- IMPLEMENTATION -------------//
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
// stop LF clock just in case we jump from application without reset
|
||||
@ -73,22 +63,16 @@ void board_init(void)
|
||||
button_init(BUTTON_FRESET);
|
||||
NRFX_DELAY_US(100); // wait for the pin state is stable
|
||||
|
||||
// LED init
|
||||
nrf_gpio_cfg_output(LED_RED);
|
||||
nrf_gpio_cfg_output(LED_BLUE);
|
||||
led_off(LED_RED);
|
||||
led_off(LED_BLUE);
|
||||
|
||||
// use PMW0 for LED RED
|
||||
led_pwm_init(LED_RED);
|
||||
led_pwm_init(LED_PRIMARY, LED_PRIMARY_PIN);
|
||||
#if LEDS_NUMBER > 1
|
||||
led_pwm_init(LED_SECONDARY, LED_SECONDARY_PIN);
|
||||
#endif
|
||||
|
||||
// use neopixel for use enumeration
|
||||
#ifdef LED_NEOPIXEL
|
||||
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
|
||||
extern void neopixel_init(void);
|
||||
neopixel_init();
|
||||
|
||||
uint8_t grb[3] = { 0, 32, 0 };
|
||||
neopixel_write(grb);
|
||||
#endif
|
||||
|
||||
// Init scheduler
|
||||
@ -100,17 +84,13 @@ void board_init(void)
|
||||
|
||||
void board_teardown(void)
|
||||
{
|
||||
// Disable and reset PWM for LED
|
||||
led_pwm_teardown(LED_RED);
|
||||
// Disable and reset PWM for LEDs
|
||||
led_pwm_teardown();
|
||||
|
||||
#ifdef LED_NEOPIXEL
|
||||
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
|
||||
extern void neopixel_teardown(void);
|
||||
neopixel_teardown();
|
||||
#endif
|
||||
|
||||
led_off(LED_BLUE);
|
||||
led_off(LED_RED);
|
||||
|
||||
// Button
|
||||
|
||||
// Stop RTC1 used by app_timer
|
||||
@ -146,58 +126,138 @@ void pwm_teardown(NRF_PWM_Type* pwm )
|
||||
pwm->SEQ[0].CNT = 0;
|
||||
}
|
||||
|
||||
void led_pwm_init(uint32_t led_pin)
|
||||
{
|
||||
NRF_PWM_Type* pwm = (led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1;
|
||||
static uint16_t led_duty_cycles[PWM0_CH_NUM];
|
||||
|
||||
pwm->MODE = PWM_MODE_UPDOWN_UpAndDown;
|
||||
pwm->COUNTERTOP = PWM_MAXCOUNT;
|
||||
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_128;
|
||||
#if LEDS_NUMBER > PWM0_CH_NUM
|
||||
#error "Only " PWM0_CH_NUM " concurrent status LEDs are supported."
|
||||
#endif
|
||||
|
||||
void led_pwm_init(uint32_t led_index, uint32_t led_pin)
|
||||
{
|
||||
NRF_PWM_Type* pwm = NRF_PWM0;
|
||||
|
||||
nrf_gpio_cfg_output(led_pin);
|
||||
pwm->PSEL.OUT[led_index] = led_pin;
|
||||
|
||||
pwm->ENABLE = 1;
|
||||
pwm->MODE = PWM_MODE_UPDOWN_Up;
|
||||
pwm->COUNTERTOP = 0xff;
|
||||
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_16;
|
||||
pwm->DECODER = PWM_DECODER_LOAD_Individual;
|
||||
pwm->LOOP = 0;
|
||||
|
||||
pwm->SEQ[0].PTR = (uint32_t) (led_pin == LED_RED ? _pwm_red_seq : _pwm_blue_seq);
|
||||
pwm->SEQ[0].CNT = PWM_CHANNEL_NUM; // default mode is Individual --> count must be 4
|
||||
pwm->SEQ[0].PTR = (uint32_t) (led_duty_cycles);
|
||||
pwm->SEQ[0].CNT = 4; // default mode is Individual --> count must be 4
|
||||
pwm->SEQ[0].REFRESH = 0;
|
||||
pwm->SEQ[0].ENDDELAY = 0;
|
||||
|
||||
pwm->PSEL.OUT[0] = led_pin;
|
||||
|
||||
pwm->ENABLE = 1;
|
||||
pwm->LOOP = 0;
|
||||
pwm->TASKS_SEQSTART[0] = 1;
|
||||
}
|
||||
|
||||
void led_pwm_teardown(uint32_t led_pin)
|
||||
void led_pwm_teardown(void)
|
||||
{
|
||||
pwm_teardown ((led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1);
|
||||
pwm_teardown(NRF_PWM0);
|
||||
}
|
||||
|
||||
void led_pwm_disable(uint32_t led_pin)
|
||||
void led_pwm_duty_cycle(uint32_t led_index, uint16_t duty_cycle)
|
||||
{
|
||||
NRF_PWM_Type* pwm = (led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1;
|
||||
|
||||
pwm->TASKS_SEQSTART[0] = 0;
|
||||
pwm->ENABLE = 0;
|
||||
led_duty_cycles[led_index] = duty_cycle;
|
||||
nrf_pwm_event_clear(NRF_PWM0, NRF_PWM_EVENT_SEQEND0);
|
||||
nrf_pwm_task_trigger(NRF_PWM0, NRF_PWM_TASK_SEQSTART0);
|
||||
}
|
||||
|
||||
void led_pwm_enable(uint32_t led_pin)
|
||||
{
|
||||
NRF_PWM_Type* pwm = (led_pin == LED_RED) ? NRF_PWM0 : NRF_PWM1;
|
||||
static uint32_t primary_cycle_length;
|
||||
#ifdef LED_SECONDARY_PIN
|
||||
static uint32_t secondary_cycle_length;
|
||||
#endif
|
||||
void led_tick() {
|
||||
uint32_t millis = tusb_hal_millis();
|
||||
|
||||
pwm->ENABLE = 1;
|
||||
pwm->TASKS_SEQSTART[0] = 1;
|
||||
uint32_t cycle = millis % primary_cycle_length;
|
||||
uint32_t half_cycle = primary_cycle_length / 2;
|
||||
if (cycle > half_cycle) {
|
||||
cycle = primary_cycle_length - cycle;
|
||||
}
|
||||
uint16_t duty_cycle = 0x4f * cycle / half_cycle;
|
||||
#if LED_STATE_ON == 1
|
||||
duty_cycle = 0xff - duty_cycle;
|
||||
#endif
|
||||
led_pwm_duty_cycle(LED_PRIMARY, duty_cycle);
|
||||
|
||||
#ifdef LED_SECONDARY_PIN
|
||||
cycle = millis % secondary_cycle_length;
|
||||
half_cycle = secondary_cycle_length / 2;
|
||||
if (cycle > half_cycle) {
|
||||
cycle = secondary_cycle_length - cycle;
|
||||
}
|
||||
duty_cycle = 0x8f * cycle / half_cycle;
|
||||
#if LED_STATE_ON == 1
|
||||
duty_cycle = 0xff - duty_cycle;
|
||||
#endif
|
||||
led_pwm_duty_cycle(LED_SECONDARY, duty_cycle);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void led_red_blink_fast(bool enable)
|
||||
static uint32_t rgb_color;
|
||||
static bool temp_color_active = false;
|
||||
void led_state(uint32_t state)
|
||||
{
|
||||
if ( enable )
|
||||
{
|
||||
NRF_PWM0->MODE = PWM_MODE_UPDOWN_Up;
|
||||
}else
|
||||
{
|
||||
NRF_PWM0->MODE = PWM_MODE_UPDOWN_UpAndDown;
|
||||
uint32_t new_rgb_color = rgb_color;
|
||||
uint32_t temp_color = 0;
|
||||
switch (state) {
|
||||
case STATE_USB_MOUNTED:
|
||||
new_rgb_color = 0x00ff00;
|
||||
primary_cycle_length = 4000;
|
||||
break;
|
||||
case STATE_BOOTLOADER_STARTED:
|
||||
case STATE_USB_UNMOUNTED:
|
||||
new_rgb_color = 0xff0000;
|
||||
primary_cycle_length = 300;
|
||||
break;
|
||||
case STATE_WRITING_STARTED:
|
||||
temp_color = 0xff0000;
|
||||
break;
|
||||
case STATE_WRITING_FINISHED:
|
||||
// Empty means to unset any temp colors.
|
||||
break;
|
||||
case STATE_BLE_CONNECTED:
|
||||
new_rgb_color = 0x0000ff;
|
||||
#ifdef LED_SECONDARY_PIN
|
||||
secondary_cycle_length = 500;
|
||||
#else
|
||||
primary_cycle_length = 500;
|
||||
#endif
|
||||
break;
|
||||
case STATE_BLE_DISCONNECTED:
|
||||
new_rgb_color = 0xff00ff;
|
||||
#ifdef LED_SECONDARY_PIN
|
||||
secondary_cycle_length = 300;
|
||||
#else
|
||||
primary_cycle_length = 300;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
uint8_t* final_color = NULL;
|
||||
new_rgb_color &= BOARD_RGB_BRIGHTNESS;
|
||||
if (temp_color != 0){
|
||||
temp_color &= BOARD_RGB_BRIGHTNESS;
|
||||
final_color = (uint8_t*)&temp_color;
|
||||
temp_color_active = true;
|
||||
} else if (new_rgb_color != rgb_color) {
|
||||
final_color = (uint8_t*)&new_rgb_color;
|
||||
rgb_color = new_rgb_color;
|
||||
} else if (temp_color_active) {
|
||||
final_color = (uint8_t*)&rgb_color;
|
||||
}
|
||||
#if LED_NEOPIXEL || defined(LED_RGB_RED_PIN)
|
||||
if (final_color != NULL) {
|
||||
neopixel_write(final_color);
|
||||
}
|
||||
#else
|
||||
(void) final_color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LED_NEOPIXEL
|
||||
@ -267,10 +327,11 @@ void neopixel_teardown(void)
|
||||
// write 3 bytes color to a built-in neopixel
|
||||
void neopixel_write (uint8_t *pixels)
|
||||
{
|
||||
uint8_t grb[NEO_NUMBYTE] = {pixels[1], pixels[2], pixels[0]};
|
||||
uint16_t pos = 0; // bit position
|
||||
for ( uint16_t n = 0; n < NEO_NUMBYTE; n++ )
|
||||
{
|
||||
uint8_t pix = pixels[n];
|
||||
uint8_t pix = grb[n];
|
||||
|
||||
for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 )
|
||||
{
|
||||
@ -280,8 +341,8 @@ void neopixel_write (uint8_t *pixels)
|
||||
}
|
||||
|
||||
// Zero padding to indicate the end of sequence
|
||||
pixels_pattern[++pos] = 0 | (0x8000); // Seq end
|
||||
pixels_pattern[++pos] = 0 | (0x8000); // Seq end
|
||||
pixels_pattern[pos++] = 0 | (0x8000); // Seq end
|
||||
pixels_pattern[pos++] = 0 | (0x8000); // Seq end
|
||||
|
||||
|
||||
NRF_PWM_Type* pwm = NRF_PWM2;
|
||||
@ -293,3 +354,37 @@ void neopixel_write (uint8_t *pixels)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LED_RGB_RED_PIN) && defined(LED_RGB_GREEN_PIN) && defined(LED_RGB_BLUE_PIN)
|
||||
|
||||
#ifdef LED_SECONDARY_PIN
|
||||
#error "Cannot use secondary LED at the same time as an RGB status LED."
|
||||
#endif
|
||||
|
||||
#define LED_RGB_RED 1
|
||||
#define LED_RGB_BLUE 2
|
||||
#define LED_RGB_GREEN 3
|
||||
|
||||
void neopixel_init(void)
|
||||
{
|
||||
led_pwm_init(LED_RGB_RED, LED_RGB_RED_PIN);
|
||||
led_pwm_init(LED_RGB_GREEN, LED_RGB_GREEN_PIN);
|
||||
led_pwm_init(LED_RGB_BLUE, LED_RGB_BLUE_PIN);
|
||||
}
|
||||
|
||||
void neopixel_teardown(void)
|
||||
{
|
||||
uint8_t grb[3] = { 0, 0, 0 };
|
||||
neopixel_write(grb);
|
||||
nrf_gpio_cfg_default(LED_RGB_RED_PIN);
|
||||
nrf_gpio_cfg_default(LED_RGB_GREEN_PIN);
|
||||
nrf_gpio_cfg_default(LED_RGB_BLUE_PIN);
|
||||
}
|
||||
|
||||
// write 3 bytes color to a built-in neopixel
|
||||
void neopixel_write (uint8_t *pixels)
|
||||
{
|
||||
led_pwm_duty_cycle(LED_RGB_RED, pixels[2]);
|
||||
led_pwm_duty_cycle(LED_RGB_GREEN, pixels[1]);
|
||||
led_pwm_duty_cycle(LED_RGB_BLUE, pixels[0]);
|
||||
}
|
||||
#endif
|
||||
|
66
src/boards.h
66
src/boards.h
@ -25,15 +25,38 @@
|
||||
#include "boards/pca10056.h"
|
||||
#elif defined BOARD_PCA10059
|
||||
#include "boards/pca10059.h"
|
||||
#elif defined BOARD_PARTICLE_ARGON
|
||||
#include "boards/particle_argon.h"
|
||||
#elif defined BOARD_PARTICLE_BORON
|
||||
#include "boards/particle_boron.h"
|
||||
#elif defined BOARD_PARTICLE_XENON
|
||||
#include "boards/particle_xenon.h"
|
||||
#else
|
||||
#error No boards defined
|
||||
#endif
|
||||
|
||||
#ifndef BUTTON_DFU
|
||||
#define BUTTON_DFU BUTTON_1
|
||||
#endif
|
||||
#ifndef BUTTON_FRESET
|
||||
#define BUTTON_FRESET BUTTON_2
|
||||
#endif
|
||||
|
||||
#define LED_RED LED_1
|
||||
#define LED_BLUE LED_2
|
||||
// The primary LED is usually Red but not in all cases.
|
||||
#define LED_PRIMARY 0
|
||||
// The secondary LED, when available, is usually blue.
|
||||
#define LED_SECONDARY 1
|
||||
|
||||
// Its more common for LEDs to be sinking to the MCU pin. Setting is only for individual LEDs, not
|
||||
// RGB LEDs.
|
||||
#ifndef LED_STATE_ON
|
||||
#define LED_STATE_ON 0
|
||||
#endif
|
||||
|
||||
// Internal status colors are masked by this brightness setting.
|
||||
#ifndef BOARD_RGB_BRIGHTNESS
|
||||
#define BOARD_RGB_BRIGHTNESS 0x101010
|
||||
#endif
|
||||
|
||||
// Helper function
|
||||
#define memclr(buffer, size) memset(buffer, 0, size)
|
||||
@ -50,31 +73,22 @@ void board_teardown(void);
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
static inline void led_control(uint32_t pin, bool state)
|
||||
{
|
||||
nrf_gpio_pin_write(pin, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
#define STATE_BOOTLOADER_STARTED 0
|
||||
#define STATE_USB_MOUNTED 1
|
||||
#define STATE_USB_UNMOUNTED 2
|
||||
#define STATE_FACTORY_RESET_STARTED 3
|
||||
#define STATE_FACTORY_RESET_FINISHED 4
|
||||
#define STATE_WRITING_STARTED 5
|
||||
#define STATE_WRITING_FINISHED 6
|
||||
#define STATE_BLE_CONNECTED 7
|
||||
#define STATE_BLE_DISCONNECTED 8
|
||||
|
||||
static inline void led_on(uint32_t pin)
|
||||
{
|
||||
led_control(pin, true);
|
||||
}
|
||||
|
||||
static inline void led_off(uint32_t pin)
|
||||
{
|
||||
led_control(pin, false);
|
||||
}
|
||||
|
||||
void led_pwm_init(uint32_t led_pin);
|
||||
void led_pwm_teardown(uint32_t led_pin);
|
||||
void led_pwm_disable(uint32_t led_pin);
|
||||
void led_pwm_enable(uint32_t led_pin);
|
||||
|
||||
void led_red_blink_fast(bool enable);
|
||||
|
||||
#ifdef LED_NEOPIXEL
|
||||
void neopixel_write(uint8_t *pixels);
|
||||
#endif
|
||||
void led_pwm_init(uint32_t led_index, uint32_t led_pin);
|
||||
void led_pwm_teardown(void);
|
||||
void led_pwm_disable(uint32_t led_index);
|
||||
void led_pwm_enable(uint32_t led_index);
|
||||
void led_state(uint32_t state);
|
||||
void led_tick(void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BUTTONS
|
||||
|
@ -41,8 +41,8 @@
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 2
|
||||
#define LED_1 17
|
||||
#define LED_2 19
|
||||
#define LED_PRIMARY_PIN 17 // Red
|
||||
#define LED_SECONDARY_PIN 19 // Blue
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@ -66,4 +66,6 @@
|
||||
#define DIS_MANUFACTURER "Adafruit Industries"
|
||||
#define DIS_MODEL "Bluefruit Feather nRF52832"
|
||||
|
||||
#define PRODUCT_NAME "Adafruit Bluefruit Feather nRF52832"
|
||||
|
||||
#endif // _FEATHER52832_H
|
||||
|
@ -43,9 +43,10 @@
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 2
|
||||
#define LED_1 _PINNUM(1, 15)
|
||||
#define LED_2 _PINNUM(1, 10)
|
||||
#define LED_PRIMARY_PIN _PINNUM(1, 15)
|
||||
#define LED_SECONDARY_PIN _PINNUM(1, 10)
|
||||
#define LED_NEOPIXEL 16
|
||||
#define BOARD_RGB_BRIGHTNESS 0x040404
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@ -69,4 +70,7 @@
|
||||
#define DIS_MANUFACTURER "Adafruit Industries"
|
||||
#define DIS_MODEL "Bluefruit Feather nRF52840 Express"
|
||||
|
||||
#define PRODUCT_NAME "Adafruit Feather nRF52840 Express"
|
||||
#define VOLUME_LABEL "FTHR840BOOT"
|
||||
|
||||
#endif // _FEATHER52840_H
|
||||
|
81
src/boards/particle_argon.h
Normal file
81
src/boards/particle_argon.h
Normal file
@ -0,0 +1,81 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file particle_argon.h
|
||||
@author Scott Shawcroft
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Scott Shawcroft for Adafruit Industries (adafruit.com)
|
||||
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 holders 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 ''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 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 _PARTICLE_ARGON_H
|
||||
#define _PARTICLE_ARGON_H
|
||||
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 1
|
||||
#define LED_PRIMARY_PIN _PINNUM(1, 12)
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define LED_RGB_RED_PIN _PINNUM(0, 13)
|
||||
#define LED_RGB_GREEN_PIN _PINNUM(0, 14)
|
||||
#define LED_RGB_BLUE_PIN _PINNUM(0, 15)
|
||||
#define BOARD_RGB_BRIGHTNESS 0x202020
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* BUTTON
|
||||
*------------------------------------------------------------------*/
|
||||
#define BUTTONS_NUMBER 2
|
||||
#define BUTTON_DFU _PINNUM(0, 11)
|
||||
#define BUTTON_FRESET _PINNUM(0, 03) // A0
|
||||
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* UART
|
||||
*------------------------------------------------------------------*/
|
||||
#define RX_PIN_NUMBER 8
|
||||
#define TX_PIN_NUMBER 6
|
||||
#define CTS_PIN_NUMBER 0
|
||||
#define RTS_PIN_NUMBER 0
|
||||
#define HWFC false
|
||||
|
||||
// Used as model string in OTA mode
|
||||
#define DIS_MANUFACTURER "Particle Industries"
|
||||
#define DIS_MODEL "Argon"
|
||||
|
||||
#define VOLUME_LABEL "ARGONBOOT "
|
||||
|
||||
#define BOARD_ID "Particle-Argon-v1"
|
||||
|
||||
#define INDEX_URL "https://www.particle.io/mesh/"
|
||||
|
||||
#endif // _PARTICLE_ARGON_H
|
81
src/boards/particle_boron.h
Normal file
81
src/boards/particle_boron.h
Normal file
@ -0,0 +1,81 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file particle_boron.h
|
||||
@author Scott Shawcroft
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Scott Shawcroft for Adafruit Industries (adafruit.com)
|
||||
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 holders 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 ''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 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 _PARTICLE_BORON_H
|
||||
#define _PARTICLE_BORON_H
|
||||
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 1
|
||||
#define LED_PRIMARY_PIN _PINNUM(1, 12)
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define LED_RGB_RED_PIN _PINNUM(0, 13)
|
||||
#define LED_RGB_GREEN_PIN _PINNUM(0, 14)
|
||||
#define LED_RGB_BLUE_PIN _PINNUM(0, 15)
|
||||
#define BOARD_RGB_BRIGHTNESS 0x202020
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* BUTTON
|
||||
*------------------------------------------------------------------*/
|
||||
#define BUTTONS_NUMBER 2
|
||||
#define BUTTON_DFU _PINNUM(0, 11)
|
||||
#define BUTTON_FRESET _PINNUM(0, 03) // A0
|
||||
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* UART
|
||||
*------------------------------------------------------------------*/
|
||||
#define RX_PIN_NUMBER 8
|
||||
#define TX_PIN_NUMBER 6
|
||||
#define CTS_PIN_NUMBER 0
|
||||
#define RTS_PIN_NUMBER 0
|
||||
#define HWFC false
|
||||
|
||||
// Used as model string in OTA mode
|
||||
#define DIS_MANUFACTURER "Particle Industries"
|
||||
#define DIS_MODEL "Boron"
|
||||
|
||||
#define VOLUME_LABEL "BORONBOOT "
|
||||
|
||||
#define BOARD_ID "Particle-Boron-v1"
|
||||
|
||||
#define INDEX_URL "https://www.particle.io/mesh/"
|
||||
|
||||
#endif // _PARTICLE_BORON_H
|
81
src/boards/particle_xenon.h
Normal file
81
src/boards/particle_xenon.h
Normal file
@ -0,0 +1,81 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file particle_xenon.h
|
||||
@author Scott Shawcroft
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Scott Shawcroft for Adafruit Industries (adafruit.com)
|
||||
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 holders 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 ''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 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 _PARTICLE_XENON_H
|
||||
#define _PARTICLE_XENON_H
|
||||
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 1
|
||||
#define LED_PRIMARY_PIN _PINNUM(1, 12)
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define LED_RGB_RED_PIN _PINNUM(0, 13)
|
||||
#define LED_RGB_GREEN_PIN _PINNUM(0, 14)
|
||||
#define LED_RGB_BLUE_PIN _PINNUM(0, 15)
|
||||
#define BOARD_RGB_BRIGHTNESS 0x202020
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* BUTTON
|
||||
*------------------------------------------------------------------*/
|
||||
#define BUTTONS_NUMBER 2
|
||||
#define BUTTON_DFU _PINNUM(0, 11)
|
||||
#define BUTTON_FRESET _PINNUM(0, 03) // A0
|
||||
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* UART
|
||||
*------------------------------------------------------------------*/
|
||||
#define RX_PIN_NUMBER 8
|
||||
#define TX_PIN_NUMBER 6
|
||||
#define CTS_PIN_NUMBER 0
|
||||
#define RTS_PIN_NUMBER 0
|
||||
#define HWFC false
|
||||
|
||||
// Used as model string in OTA mode
|
||||
#define DIS_MANUFACTURER "Particle Industries"
|
||||
#define DIS_MODEL "Xenon"
|
||||
|
||||
#define VOLUME_LABEL "XENONBOOT "
|
||||
|
||||
#define BOARD_ID "Particle-Xenon-v1"
|
||||
|
||||
#define INDEX_URL "https://www.particle.io/mesh/"
|
||||
|
||||
#endif // _PARTICLE_XENON_H
|
@ -41,8 +41,8 @@
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 2
|
||||
#define LED_1 13
|
||||
#define LED_2 14
|
||||
#define LED_PRIMARY_PIN 13
|
||||
#define LED_SECONDARY_PIN 14
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
@ -41,10 +41,8 @@
|
||||
/* LED
|
||||
*------------------------------------------------------------------*/
|
||||
#define LEDS_NUMBER 2
|
||||
// LED_RED
|
||||
#define LED_1 6
|
||||
// LED_BLUE
|
||||
#define LED_2 12
|
||||
#define LED_PRIMARY_PIN 6 // Red
|
||||
#define LED_SECONDARY_PIN 12 // Blue
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
28
src/main.c
28
src/main.c
@ -170,12 +170,12 @@ int main(void)
|
||||
// When updating SoftDevice, bootloader will reset before swapping SD
|
||||
if (bootloader_dfu_sd_in_progress())
|
||||
{
|
||||
led_red_blink_fast(true);
|
||||
led_state(STATE_WRITING_STARTED);
|
||||
|
||||
APP_ERROR_CHECK( bootloader_dfu_sd_update_continue() );
|
||||
APP_ERROR_CHECK( bootloader_dfu_sd_update_finalize() );
|
||||
|
||||
led_red_blink_fast(false);
|
||||
led_state(STATE_WRITING_FINISHED);
|
||||
}
|
||||
|
||||
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
|
||||
@ -209,18 +209,19 @@ int main(void)
|
||||
|
||||
(*dbl_reset_mem) = 0;
|
||||
|
||||
led_state(STATE_BOOTLOADER_STARTED);
|
||||
|
||||
if ( dfu_start || !valid_app )
|
||||
{
|
||||
if ( _ota_dfu )
|
||||
{
|
||||
// Enable BLE if in OTA
|
||||
led_pwm_init(LED_BLUE);
|
||||
|
||||
led_state(STATE_BLE_DISCONNECTED);
|
||||
softdev_init(!sd_inited);
|
||||
sd_inited = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_state(STATE_USB_UNMOUNTED);
|
||||
// otherwise USB for Serial & UF2
|
||||
usb_init(serial_only_dfu);
|
||||
}
|
||||
@ -230,9 +231,6 @@ int main(void)
|
||||
|
||||
if ( _ota_dfu )
|
||||
{
|
||||
led_pwm_teardown(LED_BLUE);
|
||||
led_off(LED_BLUE);
|
||||
|
||||
sd_softdevice_disable();
|
||||
}else
|
||||
{
|
||||
@ -267,9 +265,7 @@ int main(void)
|
||||
// Perform factory reset to erase Application + Data
|
||||
void adafruit_factory_reset(void)
|
||||
{
|
||||
// Blink fast RED and turn on BLUE when erasing
|
||||
led_red_blink_fast(true);
|
||||
led_on(LED_BLUE);
|
||||
led_state(STATE_FACTORY_RESET_STARTED);
|
||||
|
||||
// clear all App Data if any
|
||||
if ( DFU_APP_DATA_RESERVED )
|
||||
@ -281,8 +277,7 @@ void adafruit_factory_reset(void)
|
||||
nrf_nvmc_page_erase(DFU_BANK_0_REGION_START);
|
||||
|
||||
// back to normal
|
||||
led_red_blink_fast(false);
|
||||
led_off(LED_BLUE);
|
||||
led_state(STATE_FACTORY_RESET_FINISHED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -394,13 +389,12 @@ uint32_t proc_ble(void)
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
_ota_connected = true;
|
||||
led_pwm_disable(LED_BLUE);
|
||||
led_on(LED_BLUE);
|
||||
led_state(STATE_BLE_CONNECTED);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
_ota_connected = false;
|
||||
led_pwm_enable(LED_BLUE); // LED Blink
|
||||
led_state(STATE_BLE_DISCONNECTED);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@ -455,5 +449,3 @@ void SD_EVT_IRQHandler(void)
|
||||
// Use App Scheduler to defer handling code in non-isr context
|
||||
app_sched_event_put(NULL, 0, ada_sd_task);
|
||||
}
|
||||
|
||||
|
||||
|
@ -235,7 +235,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
|
||||
/** uf2 upgrade complete -> inform bootloader to update setting and reset */
|
||||
static void uf2_write_complete(uint32_t numBlocks)
|
||||
{
|
||||
led_red_blink_fast(false);
|
||||
led_state(STATE_WRITING_FINISHED);
|
||||
|
||||
dfu_update_status_t update_status;
|
||||
|
||||
@ -285,7 +285,7 @@ int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *stat
|
||||
static bool first_write = true;
|
||||
if ( first_write ) {
|
||||
first_write = false;
|
||||
led_red_blink_fast(true);
|
||||
led_state(STATE_WRITING_STARTED);
|
||||
}
|
||||
|
||||
flash_nrf5x_write(bl->targetAddr, bl->data, bl->payloadSize, true);
|
||||
@ -318,4 +318,3 @@ int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *stat
|
||||
|
||||
return 512;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,25 @@
|
||||
#define UF2_VERSION "1.00"
|
||||
#include "boards.h"
|
||||
|
||||
#ifdef BOARD_PCA10056
|
||||
#ifndef PRODUCT_NAME
|
||||
#define PRODUCT_NAME DIS_MODEL
|
||||
#else
|
||||
#define PRODUCT_NAME "Adafruit " DIS_MODEL
|
||||
#endif
|
||||
|
||||
#ifndef BOARD_ID
|
||||
#define BOARD_ID "NRF52-Bluefruit-v0"
|
||||
#define INDEX_URL "https://www.adafruit.com/product/0000"
|
||||
#endif
|
||||
|
||||
#ifndef INDEX_URL
|
||||
#define INDEX_URL "https://www.adafruit.com/"
|
||||
#endif
|
||||
|
||||
#define BOOTLOADER_ID MK_DIS_FIRMWARE
|
||||
|
||||
#define UF2_NUM_BLOCKS 8000 // at least 4,1 MB for FAT16
|
||||
|
||||
#ifndef VOLUME_LABEL
|
||||
#define VOLUME_LABEL "NRF52BOOT "
|
||||
#endif
|
||||
|
||||
#define FLASH_SIZE (USER_FLASH_END-USER_FLASH_START) // Max flash size
|
||||
|
||||
// Only allow to write application TODO dynamic depending on SD size
|
||||
|
@ -157,17 +157,10 @@ void usb_teardown(void)
|
||||
//--------------------------------------------------------------------+
|
||||
void tud_mount_cb(void)
|
||||
{
|
||||
#ifdef LED_NEOPIXEL
|
||||
uint8_t grb[3] = { 32, 0, 0 };
|
||||
neopixel_write(grb);
|
||||
#endif
|
||||
led_state(STATE_USB_MOUNTED);
|
||||
}
|
||||
|
||||
void tud_umount_cb(void)
|
||||
{
|
||||
#ifdef LED_NEOPIXEL
|
||||
uint8_t grb[3] = { 0, 32, 0 };
|
||||
neopixel_write(grb);
|
||||
#endif
|
||||
led_state(STATE_USB_UNMOUNTED);
|
||||
}
|
||||
|
||||
|
55
tools/build_all.py
Normal file
55
tools/build_all.py
Normal file
@ -0,0 +1,55 @@
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
subprocess.run("rm -rf _build*", shell=True)
|
||||
subprocess.run("rm -rf bin/*", shell=True)
|
||||
|
||||
PARALLEL = "-j 5"
|
||||
travis = False
|
||||
if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
|
||||
PARALLEL="-j 2"
|
||||
travis = True
|
||||
|
||||
exit_status = 0
|
||||
|
||||
all_boards = []
|
||||
for entry in os.scandir("src/boards"):
|
||||
if not entry.name.endswith(".h"):
|
||||
print("Misplaced file in src/boards: {}\n".format(entry.name))
|
||||
exit_status = 1
|
||||
continue
|
||||
all_boards.append(entry.name[:-2])
|
||||
|
||||
#sha, version = build_info.get_version_info()
|
||||
|
||||
for board in all_boards:
|
||||
bin_directory = "bin/{}/".format(board)
|
||||
os.makedirs(bin_directory, exist_ok=True)
|
||||
|
||||
start_time = time.monotonic()
|
||||
make_result = subprocess.run("make BOARD={} combinehex genpkg".format(board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
build_duration = time.monotonic() - start_time
|
||||
success = "\033[32msucceeded\033[0m"
|
||||
if make_result.returncode != 0:
|
||||
exit_status = make_result.returncode
|
||||
success = "\033[31mfailed\033[0m"
|
||||
|
||||
for entry in os.scandir("_build-{}".format(board)):
|
||||
for extension in ["zip", "hex"]:
|
||||
if entry.name.endswith(extension) and "nosd" not in entry.name:
|
||||
shutil.copy(entry.path, bin_directory)
|
||||
|
||||
if travis:
|
||||
print('travis_fold:start:build-{}\\r'.format(board))
|
||||
print("Build {} took {:.2f}s and {}".format(board, build_duration, success))
|
||||
if make_result.returncode != 0:
|
||||
print(make_result.stdout.decode("utf-8"))
|
||||
if travis:
|
||||
print('travis_fold:end:build-{}\\r'.format(board))
|
||||
|
||||
print()
|
||||
|
||||
sys.exit(exit_status)
|
Loading…
Reference in New Issue
Block a user