From 52614b429467b6a300849ca6cc3b798fe36deeba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Thu, 2 Apr 2020 15:16:41 +0200 Subject: [PATCH 01/22] Update .gitignore Ignoring S340 SD specific license-bound files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6a29bac3..89ce25bd 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ # Ignore local overrides of platform.txt and boards.txt, /boards.local.txt /platform.local.txt +bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.hex +bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.zip +cores/nRF5/nordic/softdevice/s340_nrf52_6.1.1_API/* From 51925d20faee32dc43241ceeca3852583bba3bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Thu, 7 May 2020 10:04:02 +0200 Subject: [PATCH 02/22] making bluefruit multiprotocol friendly --- libraries/Bluefruit52Lib/src/bluefruit.cpp | 11 +++++++++++ libraries/Bluefruit52Lib/src/bluefruit.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 363ab68d..707e86e1 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -162,6 +162,7 @@ AdafruitBluefruit::AdafruitBluefruit(void) _ble_event_sem = NULL; _soc_event_sem = NULL; + _mprot_event_sem = NULL; _led_blink_th = NULL; _led_conn = true; @@ -310,7 +311,15 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count) #error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h #endif + /*------------------------------------------------------------------*/ + /* BLE only Softdevices have 2-args sd_softdevice_enable() + /* BLE & ANT+ Softdevices have 3-args sd_softdevice_enable() + /*------------------------------------------------------------------*/ +#ifdef ANT_LICENSE_KEY + VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false ); +#else //#ifdef ANT_LICENSE_KEY VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb), false ); +#endif //#ifdef ANT_LICENSE_KEY #ifdef USE_TINYUSB usb_softdevice_post_enable(); @@ -676,6 +685,8 @@ void SD_EVT_IRQHandler(void) // Notify both BLE & SOC Task xSemaphoreGiveFromISR(Bluefruit._soc_event_sem, NULL); xSemaphoreGiveFromISR(Bluefruit._ble_event_sem, NULL); + // Notify parallel multiprotocol Task, if any + if (Bluefruit._mprot_event_sem!=NULL) xSemaphoreGiveFromISR(*Bluefruit._mprot_event_sem, NULL); } /** diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 521dea5c..14a800cd 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -178,6 +178,15 @@ class AdafruitBluefruit BLEConnection* Connection(uint16_t conn_hdl); + /*------------------------------------------------------------------* + * Optional semaphore for additional event handlers for SD event. + * It can be used for handling non-BLE SD events + *------------------------------------------------------------------*/ + void setMultiprotocolSemaphore(SemaphoreHandle_t* p_mprot_event_semaphore) + { + _mprot_event_sem= p_mprot_event_semaphore; + } + /*------------------------------------------------------------------*/ /* Callbacks *------------------------------------------------------------------*/ @@ -222,6 +231,8 @@ class AdafruitBluefruit SemaphoreHandle_t _ble_event_sem; SemaphoreHandle_t _soc_event_sem; + SemaphoreHandle_t* _mprot_event_sem; + TimerHandle_t _led_blink_th; bool _led_conn; From ff32fcf29549b0263662c3b1b81a19013697bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Sun, 10 May 2020 19:44:39 +0200 Subject: [PATCH 03/22] Fixing wildcard in .gitignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 89ce25bd..0065dfb1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ # Ignore local overrides of platform.txt and boards.txt, /boards.local.txt /platform.local.txt -bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.hex -bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.zip + +# Ignore S340 SoftDevice due to license restrictions +bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-*s340* cores/nRF5/nordic/softdevice/s340_nrf52_6.1.1_API/* From 180ef771c264705f05ec43f599bf3802dfcc7302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Sun, 10 May 2020 19:45:42 +0200 Subject: [PATCH 04/22] Fixing pgm_read_ptr(addr) macro --- cores/nRF5/avr/pgmspace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/nRF5/avr/pgmspace.h b/cores/nRF5/avr/pgmspace.h index 68ff4971..c1fd7910 100644 --- a/cores/nRF5/avr/pgmspace.h +++ b/cores/nRF5/avr/pgmspace.h @@ -102,7 +102,7 @@ typedef const void* uint_farptr_t; #define pgm_read_word(addr) (*(const unsigned short *)(addr)) #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) #define pgm_read_float(addr) (*(const float *)(addr)) -#define pgm_read_ptr(addr) (*(const void *)(addr)) +#define pgm_read_ptr(addr) (*(const void* *)(addr)) #define pgm_read_byte_near(addr) pgm_read_byte(addr) #define pgm_read_word_near(addr) pgm_read_word(addr) From 7d80eabeedc8fdc86219dc9fc0f796c0027f1faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Sun, 10 May 2020 20:04:36 +0200 Subject: [PATCH 05/22] fixing warning: '/*' within comment [-Wcomment] --- libraries/Bluefruit52Lib/src/bluefruit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 707e86e1..6a3c177f 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -312,8 +312,8 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count) #endif /*------------------------------------------------------------------*/ - /* BLE only Softdevices have 2-args sd_softdevice_enable() - /* BLE & ANT+ Softdevices have 3-args sd_softdevice_enable() + // BLE only Softdevices have 2-args sd_softdevice_enable() + // BLE & ANT+ Softdevices have 3-args sd_softdevice_enable() /*------------------------------------------------------------------*/ #ifdef ANT_LICENSE_KEY VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false ); From b5475ca2632a4c0197a6755ac8ac7940b25ff036 Mon Sep 17 00:00:00 2001 From: orrmany Date: Fri, 5 Jun 2020 18:31:42 +0200 Subject: [PATCH 06/22] Update .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 89ce25bd..6a29bac3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,3 @@ # Ignore local overrides of platform.txt and boards.txt, /boards.local.txt /platform.local.txt -bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.hex -bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.zip -cores/nRF5/nordic/softdevice/s340_nrf52_6.1.1_API/* From ed1cdc6c1e8eb984acf07e72ba44a720d9861ca8 Mon Sep 17 00:00:00 2001 From: orrmany Date: Mon, 15 Jun 2020 10:37:38 +0200 Subject: [PATCH 07/22] Update .gitignore Removing .gitignore changes irrelevant to issue #502 --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0065dfb1..6a29bac3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,3 @@ # Ignore local overrides of platform.txt and boards.txt, /boards.local.txt /platform.local.txt - -# Ignore S340 SoftDevice due to license restrictions -bootloader/feather_nrf52840_express/feather_nrf52840_express_bootloader-*s340* -cores/nRF5/nordic/softdevice/s340_nrf52_6.1.1_API/* From ff12326ecf6bafa2584286a67e5372593f2fb1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Ziegler?= Date: Mon, 15 Jun 2020 11:45:46 +0200 Subject: [PATCH 08/22] Adding compile guards --- libraries/Bluefruit52Lib/src/bluefruit.cpp | 18 +++++++++++------- libraries/Bluefruit52Lib/src/bluefruit.h | 8 +++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 6a3c177f..4850a725 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -162,7 +162,9 @@ AdafruitBluefruit::AdafruitBluefruit(void) _ble_event_sem = NULL; _soc_event_sem = NULL; - _mprot_event_sem = NULL; +#ifdef ANT_LICENSE_KEY + _mprot_event_sem = NULL; //additiona semaphore for multiprotocol +#endif _led_blink_th = NULL; _led_conn = true; @@ -311,11 +313,11 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count) #error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h #endif - /*------------------------------------------------------------------*/ - // BLE only Softdevices have 2-args sd_softdevice_enable() - // BLE & ANT+ Softdevices have 3-args sd_softdevice_enable() - /*------------------------------------------------------------------*/ -#ifdef ANT_LICENSE_KEY + /*------------------------------------------------------------------ + ** BLE only Softdevices have 2-args sd_softdevice_enable() + ** BLE & ANT+ Softdevices have 3-args sd_softdevice_enable() + */ + #ifdef ANT_LICENSE_KEY VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false ); #else //#ifdef ANT_LICENSE_KEY VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb), false ); @@ -685,8 +687,10 @@ void SD_EVT_IRQHandler(void) // Notify both BLE & SOC Task xSemaphoreGiveFromISR(Bluefruit._soc_event_sem, NULL); xSemaphoreGiveFromISR(Bluefruit._ble_event_sem, NULL); +#ifdef ANT_LICENSE_KEY // Notify parallel multiprotocol Task, if any - if (Bluefruit._mprot_event_sem!=NULL) xSemaphoreGiveFromISR(*Bluefruit._mprot_event_sem, NULL); + if (Bluefruit._mprot_event_sem) xSemaphoreGiveFromISR(Bluefruit._mprot_event_sem, NULL); +#endif } /** diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 14a800cd..f4a4a318 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -178,6 +178,7 @@ class AdafruitBluefruit BLEConnection* Connection(uint16_t conn_hdl); +#ifdef ANT_LICENSE_KEY /*------------------------------------------------------------------* * Optional semaphore for additional event handlers for SD event. * It can be used for handling non-BLE SD events @@ -186,6 +187,7 @@ class AdafruitBluefruit { _mprot_event_sem= p_mprot_event_semaphore; } +#endif /*------------------------------------------------------------------*/ /* Callbacks @@ -231,8 +233,12 @@ class AdafruitBluefruit SemaphoreHandle_t _ble_event_sem; SemaphoreHandle_t _soc_event_sem; +#ifdef ANT_LICENSE_KEY + /* Optional semaphore for additional event handlers for SD event. + * It can be used for handling non-BLE SD events + */ SemaphoreHandle_t* _mprot_event_sem; - +#endif TimerHandle_t _led_blink_th; bool _led_conn; From 3c6c2b7d557caed074f3f73bc573aaec60e9afcf Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 10 Jul 2020 18:48:14 +0700 Subject: [PATCH 09/22] remove BLECharateristic write(int32_t) fix #520 --- .../src/services/BLEAdafruitSensor.cpp | 8 +- .../src/services/BLEAdafruitSensor.h | 10 +- .../Bluefruit52Lib/src/BLECharacteristic.cpp | 5 - .../Bluefruit52Lib/src/BLECharacteristic.h | 1 - tools/build_all_travis.py | 149 ------------------ 5 files changed, 9 insertions(+), 164 deletions(-) delete mode 100644 tools/build_all_travis.py diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp index be3b7a86..d4e06df3 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.cpp @@ -36,7 +36,7 @@ BLEAdafruitSensor::BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid) _notify_cb = NULL; } -err_t BLEAdafruitSensor::_begin(int32_t ms) +err_t BLEAdafruitSensor::_begin(int ms) { // Invoke base class begin() VERIFY_STATUS( BLEService::begin() ); @@ -59,19 +59,19 @@ err_t BLEAdafruitSensor::_begin(int32_t ms) return ERROR_NONE; } -err_t BLEAdafruitSensor::begin(measure_callback_t fp, int32_t ms) +err_t BLEAdafruitSensor::begin(measure_callback_t fp, int ms) { _measure_cb = fp; return _begin(ms); } -err_t BLEAdafruitSensor::begin(Adafruit_Sensor* sensor, int32_t ms) +err_t BLEAdafruitSensor::begin(Adafruit_Sensor* sensor, int ms) { _sensor = sensor; return _begin(ms); } -void BLEAdafruitSensor::setPeriod(int32_t period_ms) +void BLEAdafruitSensor::setPeriod(int period_ms) { _period.write32(period_ms); _update_timer(period_ms); diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h index e7003286..a934508b 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h @@ -30,17 +30,17 @@ class BLEAdafruitSensor : public BLEService { public: - static const int32_t DEFAULT_PERIOD = 1000; + static const int DEFAULT_PERIOD = 1000; typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled); typedef uint16_t (*measure_callback_t )(uint8_t* buf, uint16_t bufsize); BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid); - virtual err_t begin(measure_callback_t fp, int32_t ms = DEFAULT_PERIOD); - virtual err_t begin(Adafruit_Sensor* sensor, int32_t ms = DEFAULT_PERIOD); + virtual err_t begin(measure_callback_t fp, int ms = DEFAULT_PERIOD); + virtual err_t begin(Adafruit_Sensor* sensor, int ms = DEFAULT_PERIOD); - void setPeriod(int32_t period_ms); + void setPeriod(int period_ms); void setNotifyCallback(notify_callback_t fp); protected: @@ -54,7 +54,7 @@ class BLEAdafruitSensor : public BLEService SoftwareTimer _timer; - err_t _begin(int32_t ms); + err_t _begin(int ms); virtual void _update_timer(int32_t ms); virtual void _measure_handler(void); diff --git a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp index 338fb84c..e38f2796 100644 --- a/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp +++ b/libraries/Bluefruit52Lib/src/BLECharacteristic.cpp @@ -564,11 +564,6 @@ uint16_t BLECharacteristic::write32(int num) return write32( (uint32_t) num ); } -uint16_t BLECharacteristic::write32(int32_t num) -{ - return write32( (uint32_t) num ); -} - /*------------------------------------------------------------------*/ /* READ *------------------------------------------------------------------*/ diff --git a/libraries/Bluefruit52Lib/src/BLECharacteristic.h b/libraries/Bluefruit52Lib/src/BLECharacteristic.h index 992001fe..d0ca796a 100644 --- a/libraries/Bluefruit52Lib/src/BLECharacteristic.h +++ b/libraries/Bluefruit52Lib/src/BLECharacteristic.h @@ -129,7 +129,6 @@ class BLECharacteristic uint16_t write16 (uint16_t num); uint16_t write32 (uint32_t num); uint16_t write32 (int num); - uint16_t write32 (int32_t num); /*------------- Read -------------*/ uint16_t read (void* buffer, uint16_t bufsize, uint16_t offset = 0); diff --git a/tools/build_all_travis.py b/tools/build_all_travis.py deleted file mode 100644 index 0b01f55f..00000000 --- a/tools/build_all_travis.py +++ /dev/null @@ -1,149 +0,0 @@ -import os -import glob -import sys -import subprocess -import time - -travis = False -if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true": - travis = True - -all_warnings = False -if "ALL_WARNINGS" in os.environ and os.environ["ALL_WARNINGS"] == "true": - all_warnings = True - -ENV_VARIABLE_NAME = 'VARIANT' - - -exit_status = 0 -success_count = 0 -fail_count = 0 - -build_format = '| {:20} | {:30} | {:9} ' -build_separator = '-' * 78 - -variants_dict = { - 'feather52840': 'Feather nRF52840 Express', - 'cplaynrf52840': 'Circuit Playground Bluefruit Express', - 'itsybitsy52840': 'ItsyBitsy nRF52840 Express', - 'cluenrf52840': 'Clue nRF52840', - 'feather52832': 'Feather nRF52832' -} - -# STDERR receives output that starts with the following text, none of which should be considered a warning or error... -output_to_ignore = ( - 'Picked up JAVA_TOOL_OPTIONS:', - 'Loading configuration...', - 'Initializing packages...', - 'Preparing boards...', - 'Verifying...', -) - -def errorOutputFilter(line): - if len(line) == 0: - return False - if line.isspace(): # Note: empty string does not match here! - return False - if line.startswith(output_to_ignore): # alternatively, can trim() each line, but that would create lots of short-lived strings... - return False - # TODO: additional items to remove? - return True - - -def build_examples(variant): - global exit_status, success_count, fail_count, build_format, build_separator - - print('\n') - print(build_separator) - print('| {:^74} |'.format(variants_dict[variant])) - print(build_separator) - print((build_format + '| {:6} |').format('Library', 'Example', 'Result', 'Time')) - print(build_separator) - subprocess.run("arduino --board adafruit:nrf52:{}:softdevice={},debug=l0 --save-prefs".format(variant, 's140v6' if variant != 'feather52832' else 's132v6'), shell=True, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - if all_warnings: - subprocess.run("arduino --pref 'compiler.warning_level=all' --save-prefs", shell=True, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - for sketch in glob.iglob('libraries/**/*.ino', recursive=True): - start_time = time.monotonic() - - # skip if example contains: ".skip" or ".skip.variant" - # however ".build.variant" file can overwrite ".skip", used to build a specific variant only - sketchdir = os.path.dirname(sketch) - if ( (os.path.exists(sketchdir + '/.skip') or os.path.exists(sketchdir + '/.skip.' + variant)) and - not os.path.exists(sketchdir + '/.build.' + variant)): - success = "skipped" - else: - # TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR. - # preferably, would use Python logging handler to get both distinct outputs and one merged output - # for now, split STDERR when building with all warnings enabled, so can detect warning/error output. - if all_warnings: - build_result = subprocess.run("arduino --verify {}".format(sketch), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - else: - build_result = subprocess.run("arduino --verify {}".format(sketch), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - # get stderr into a form where len(warningLines) indicates a true warning was output to stderr - warningLines = []; - if all_warnings and build_result.stderr: - tmpWarningLines = build_result.stderr.decode("utf-8").splitlines() - warningLines = list(filter(errorOutputFilter, (tmpWarningLines))) - - if build_result.returncode != 0: - exit_status = build_result.returncode - success = "\033[31mfailed\033[0m " - fail_count += 1 - elif len(warningLines) != 0: - exit_status = -1 - success = "\033[31mwarnings\033[0m " - fail_count += 1 - else: - success = "\033[32msucceeded\033[0m" - success_count += 1 - - build_duration = time.monotonic() - start_time - - if travis: - print('travis_fold:start:build-{}\\r'.format(sketch)) - - print((build_format + '| {:5.2f}s |').format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, build_duration)) - - if success != "skipped": - if build_result.returncode != 0: - print(build_result.stdout.decode("utf-8")) - if (build_result.stderr): - print(build_result.stderr.decode("utf-8")) - if len(warningLines) != 0: - for line in warningLines: - print(line) - - if travis: - print('travis_fold:end:build-{}\\r'.format(sketch)) - - -build_time = time.monotonic() - - -# build only one variant if the environment variable is specified -if (ENV_VARIABLE_NAME in os.environ): - variant = os.environ.get(ENV_VARIABLE_NAME) - # only use the environment variable if the variant exists in the dictionary - if (variant in variants_dict): - build_examples(variant) - else: - print('\033[31INTERNAL ERR\033[0m - invalid variant name "{}"'.format(variant)) - fail_count += 1 - exit_status = -1 - -else: # no environment variable specified, so build all variants - for var in variants_dict: - build_examples(var) - - -print(build_separator) -build_time = time.monotonic() - build_time -print("Build Summary: {} \033[32msucceeded\033[0m, {} \033[31mfailed\033[0m and took {:.2f}s".format(success_count, fail_count, build_time)) -print(build_separator) - -sys.exit(exit_status) From 6e86d16a606d8636b51f9e69162404dc90ea4099 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 11 Jul 2020 00:24:19 +0700 Subject: [PATCH 10/22] use firmata master to fix build with gcc v9 --- .github/workflows/githubci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index ab86777e..b5e1ce8e 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -47,15 +47,24 @@ jobs: arduino-cli core update-index arduino-cli core update-index --additional-urls $BSP_URL arduino-cli core install adafruit:nrf52 --additional-urls $BSP_URL + # Repalce release BSP with our code BSP_VERSION=`eval ls $HOME/$BSP_PATH` rm -r $HOME/$BSP_PATH/* ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION + # Install library dependency - arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "Firmata" "SdFat - Adafruit Fork" - + arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "SdFat - Adafruit Fork" + # TODO update to support MIDI version 5 later on arduino-cli lib install "MIDI Library"@4.3.1 + # TODO use firmata master to prevent build error with gcc v9 (should be remove after 2.5.9 is released) + # https://github.com/firmata/arduino/pull/438 + git clone -depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata + + # Library summary + arduino-cli lib list + - name: Build examples run: python3 tools/build_all.py ${{ matrix.arduino-platform }} From 4f59fe06758aa06959a33b2cf09506b0e922240d Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 11 Jul 2020 00:28:44 +0700 Subject: [PATCH 11/22] correct git depth --- .github/workflows/githubci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index b5e1ce8e..dce1d02a 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -61,7 +61,7 @@ jobs: # TODO use firmata master to prevent build error with gcc v9 (should be remove after 2.5.9 is released) # https://github.com/firmata/arduino/pull/438 - git clone -depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata + git clone --depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata # Library summary arduino-cli lib list From ceca3f28fd7168d6320374171788f26ad8641c85 Mon Sep 17 00:00:00 2001 From: Hudson Date: Sun, 12 Jul 2020 21:30:11 -0600 Subject: [PATCH 12/22] Add missing LED pin defines for PCA10056 There are actually 4 onboard LEDs, not 2 for PCA10056 --- variants/pca10056/variant.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variants/pca10056/variant.h b/variants/pca10056/variant.h index e9aa38db..ed0b2c13 100644 --- a/variants/pca10056/variant.h +++ b/variants/pca10056/variant.h @@ -45,6 +45,8 @@ extern "C" // LEDs #define PIN_LED1 (13) #define PIN_LED2 (14) +#define PIN_LED3 (15) +#define PIN_LED4 (16) #define LED_BUILTIN PIN_LED1 #define LED_CONN PIN_LED2 From 21924d106456c610b5bd433a835542e2fe277663 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 13 Jul 2020 17:54:33 +0700 Subject: [PATCH 13/22] fix typo --- libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp b/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp index 68830b85..f0eb7c44 100644 --- a/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp +++ b/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp @@ -153,7 +153,7 @@ bool BLEClientCharacteristic::_discoverDescriptor(uint16_t conn_handle, ble_gatt if ( disc_rsp.descs[i].uuid.type == BLE_UUID_TYPE_BLE && disc_rsp.descs[i].uuid.uuid == BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG ) { - LOG_LV2("DISC", "Found CCDD: handle = %d", disc_rsp.descs[i].handle); + LOG_LV2("DISC", "Found CCCD: handle = %d", disc_rsp.descs[i].handle); _cccd_handle = disc_rsp.descs[i].handle; break; From d41dda9b104dd2c8645530ecd7d1a6d140842468 Mon Sep 17 00:00:00 2001 From: Steven James Date: Mon, 13 Jul 2020 15:18:07 -0400 Subject: [PATCH 14/22] Fix BLE Characteristic discovery when the central device returns more than 4 Characteristics in a discovery request --- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index 84276889..193e534f 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -109,7 +109,8 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar // We could found more characteristic than we looking for. Buffer must be large enough enum { MAX_DISC_CHARS = 4 }; - uint16_t bufsize = sizeof(ble_gattc_evt_char_disc_rsp_t) + (MAX_DISC_CHARS-1)*sizeof(ble_gattc_char_t); + // -1 because the first ble_gattc_char_t is built in to ble_gattc_evt_char_disc_rsp_t + uint16_t bufsize = sizeof(ble_gattc_evt_char_disc_rsp_t) + (MAX_DISC_CHARS-1)*sizeof(ble_gattc_char_t); ble_gattc_evt_char_disc_rsp_t* disc_chr = (ble_gattc_evt_char_disc_rsp_t*) rtos_malloc( bufsize ); uint8_t found = 0; @@ -129,6 +130,9 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar // timeout or has no data (due to GATT Error) if ( bytecount <= 0 ) break; + if ( disc_chr->count > MAX_DISC_CHARS ) // if we truncated the response, adjust the count to match + disc_chr->count = MAX_DISC_CHARS; + // Look for matched uuid in the discovered list for(uint8_t d=0 ; dcount; d++) { From 8e38fcd0074750d68b4bb3b295444f44d150e3a3 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Tue, 14 Jul 2020 14:49:38 +0700 Subject: [PATCH 15/22] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c0da5fb9..b156f207 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -10,23 +10,20 @@ assignees: '' **Describe the bug** A clear and concise description of what the bug is. -**Set up (please complete the following information)** - - Your Board and BSP version - - Your OS (mac/windows/linux) and its version - - Serial debug log (enable IDE's Debug Mode Level to 1 or 2) +**Set up (mandatory)** + - **PC & IDE** : Arduino 1.8.13 on Ubuntu 18.04 / Windows 10/ macOS 10.15 + - **BSP** : 0.20.0 + - **Board** : Feather nRF52840 Express + - **Sketch**: Bluefruit52Lib/examples/Peripheral/bleuart. If it is a custom sketch, please provide a minimal sketch within codeblock **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. +3. See error **Screenshots** If applicable, add screenshots to help explain your problem. -**Additional context** -Add any other context about the problem here. +**Serial Log** +Serial output when IDE's Debug Mode Level to 1 or 2 From 38127c2fa33da4d0f66579ae8d9841729752cdb4 Mon Sep 17 00:00:00 2001 From: Steven James Date: Thu, 16 Jul 2020 13:59:55 -0400 Subject: [PATCH 16/22] Clean up formatting --- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index 193e534f..0e2b487e 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -130,8 +130,8 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar // timeout or has no data (due to GATT Error) if ( bytecount <= 0 ) break; - if ( disc_chr->count > MAX_DISC_CHARS ) // if we truncated the response, adjust the count to match - disc_chr->count = MAX_DISC_CHARS; + // if we truncated the response, adjust the count to match + if ( disc_chr->count > MAX_DISC_CHARS ) disc_chr->count = MAX_DISC_CHARS; // Look for matched uuid in the discovered list for(uint8_t d=0 ; dcount; d++) From df5f6c48a9479ba7602b6f99d5facab7bbde982d Mon Sep 17 00:00:00 2001 From: Steven James Date: Thu, 16 Jul 2020 14:00:30 -0400 Subject: [PATCH 17/22] MAX_DISC_CHARS = 8 to avoid excessive OTA queries for discovery. --- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index 0e2b487e..880d7097 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -107,7 +107,7 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc, uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientCharacteristic* chr[], uint8_t count) { // We could found more characteristic than we looking for. Buffer must be large enough - enum { MAX_DISC_CHARS = 4 }; + enum { MAX_DISC_CHARS = 8 }; // -1 because the first ble_gattc_char_t is built in to ble_gattc_evt_char_disc_rsp_t uint16_t bufsize = sizeof(ble_gattc_evt_char_disc_rsp_t) + (MAX_DISC_CHARS-1)*sizeof(ble_gattc_char_t); From cfcc1c486f90a551d53b8f131b5f01c3eb55837f Mon Sep 17 00:00:00 2001 From: Hudson Date: Sun, 19 Jul 2020 20:38:01 -0600 Subject: [PATCH 18/22] Init all onboard LEDs for pca10056 Need to init the 2 missing onboard LEDs for pca10056. --- variants/pca10056/variant.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/variants/pca10056/variant.cpp b/variants/pca10056/variant.cpp index bd85e971..1ea45f32 100644 --- a/variants/pca10056/variant.cpp +++ b/variants/pca10056/variant.cpp @@ -39,11 +39,17 @@ const uint32_t g_ADigitalPinMap[] = void initVariant() { - // LED1 & LED2 + // init all 4 onboard LEDs pinMode(PIN_LED1, OUTPUT); ledOff(PIN_LED1); pinMode(PIN_LED2, OUTPUT); - ledOff(PIN_LED2);; + ledOff(PIN_LED2); + + pinMode(PIN_LED3, OUTPUT); + ledOff(PIN_LED3); + + pinMode(PIN_LED4, OUTPUT); + ledOff(PIN_LED4); } From 81a78d74ed1dd6860b9ab83da6cbf01b6686fdbe Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 22 Jul 2020 21:54:55 +0700 Subject: [PATCH 19/22] update TinyUSB core to commit 11d669b4d2a40eb2fc5e51b2a9707a6de9d42363 Note: due to osal_freertos changes https://github.com/hathach/tinyusb/pull/468 the Adafruit_TinyUSB_Core_init() should be near the task scheduler (or better inside loop task) to prevent calling portYIELD_FROM_ISR() when scheduler not started --- cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore | 2 +- cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp | 2 +- cores/nRF5/main.cpp | 8 ++++---- platform.txt | 2 +- tools/build_all.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore index 07490772..11d669b4 160000 --- a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore +++ b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore @@ -1 +1 @@ -Subproject commit 07490772a559b2b0cac8aa187566aff4bec7376a +Subproject commit 11d669b4d2a40eb2fc5e51b2a9707a6de9d42363 diff --git a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp index 919e89a8..1873e3fc 100644 --- a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp +++ b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp @@ -42,7 +42,7 @@ extern "C" void USBD_IRQHandler(void) tud_int_handler(0); #if CFG_SYSVIEW - SEGGER_SYSVIEW_RecordExitISR(); + SEGGER_SYSVIEW_RecordExitISR(); #endif } diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 1998345e..c3ac0894 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -72,10 +72,6 @@ int main( void ) init(); initVariant(); -#ifdef USE_TINYUSB - Adafruit_TinyUSB_Core_init(); -#endif - #if CFG_SYSVIEW SEGGER_SYSVIEW_Conf(); #endif @@ -86,6 +82,10 @@ int main( void ) // Initialize callback task ada_callback_init(CALLBACK_STACK_SZ); +#ifdef USE_TINYUSB + Adafruit_TinyUSB_Core_init(); +#endif + // Start FreeRTOS scheduler. vTaskStartScheduler(); diff --git a/platform.txt b/platform.txt index 358ade4d..f8f47382 100644 --- a/platform.txt +++ b/platform.txt @@ -60,7 +60,7 @@ nordic.path={build.core.path}/nordic # build.logger_flags and build.sysview_flags and intentionally empty, # to allow modification via a user's own boards.local.txt or platform.local.txt files. -build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 -Ofast {build.debug_flags} {build.logger_flags} {build.sysview_flags} "-I{build.core.path}/cmsis/Core/Include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src" +build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 -Ofast {build.debug_flags} {build.logger_flags} {build.sysview_flags} "-I{build.core.path}/cmsis/Core/Include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include/nrf52" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src" # usb flags build.flags.usb= -DUSBCON -DUSE_TINYUSB -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' diff --git a/tools/build_all.py b/tools/build_all.py index 62f46757..b9f99262 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -10,7 +10,7 @@ success_count = 0 fail_count = 0 skip_count = 0 -build_format = '| {:20} | {:35} | {:9} ' +build_format = '| {:20} | {:35} | {:9} | {:6} |' build_separator = '-' * 83 default_boards = [ 'cluenrf52840', 'cplaynrf52840', 'feather52832', 'feather52840', 'feather52840sense', 'itsybitsy52840' ] @@ -39,7 +39,7 @@ def build_examples(variant): print(build_separator) print('| {:^79} |'.format('Board ' + variant)) print(build_separator) - print((build_format + '| {:6} |').format('Library', 'Example', 'Result', 'Time')) + print(build_format.format('Library', 'Example', 'Result', 'Time')) print(build_separator) fqbn = "adafruit:nrf52:{}:softdevice={},debug=l0".format(variant, 's140v6' if variant != 'feather52832' else 's132v6') @@ -83,7 +83,7 @@ def build_examples(variant): build_duration = time.monotonic() - start_time - print((build_format + '| {:5.2f}s |').format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, build_duration)) + print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration))) if success != "\033[33mskipped\033[0m ": if build_result.returncode != 0: From 9a2f1384ad96a49a6ec0e5bc5b2c258b3c937fa1 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 22 Jul 2020 22:25:20 +0700 Subject: [PATCH 20/22] move Adafruit_TinyUSB_Core_init() inside loop() task --- cores/nRF5/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index c3ac0894..81eb60e3 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -44,6 +44,10 @@ static void loop_task(void* arg) { (void) arg; +#ifdef USE_TINYUSB + Adafruit_TinyUSB_Core_init(); +#endif + #if CFG_DEBUG // If Serial is not begin(), call it to avoid hard fault if(!Serial) Serial.begin(115200); @@ -82,10 +86,6 @@ int main( void ) // Initialize callback task ada_callback_init(CALLBACK_STACK_SZ); -#ifdef USE_TINYUSB - Adafruit_TinyUSB_Core_init(); -#endif - // Start FreeRTOS scheduler. vTaskStartScheduler(); From ca4f2bcbb4f93f3f1e294c51f9a884c1deaf9eb3 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Jul 2020 07:07:22 +0700 Subject: [PATCH 21/22] sync with Adafruit_TinyUSB_ArduinoCore commit 238a5c0b95fcd402d24524c7bebbdd822168a51e --- cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore index 11d669b4..238a5c0b 160000 --- a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore +++ b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore @@ -1 +1 @@ -Subproject commit 11d669b4d2a40eb2fc5e51b2a9707a6de9d42363 +Subproject commit 238a5c0b95fcd402d24524c7bebbdd822168a51e From cb6d216c9ce9f498c430959c0c4a779cfb1f688e Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Jul 2020 07:45:09 +0700 Subject: [PATCH 22/22] move usb hardware init and tud_init into usb device thread help to prevent USB IRQ when scheduler is not started yet --- cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp | 50 ++++++++++----------- cores/nRF5/main.cpp | 8 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp index 1873e3fc..e4f50237 100644 --- a/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp +++ b/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp @@ -30,6 +30,16 @@ #include "Arduino.h" #include "Adafruit_TinyUSB_Core.h" +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + +#define USBD_STACK_SZ (200) + +// tinyusb function that handles power event (detected, ready, removed) +// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. +extern "C" void tusb_hal_nrf_power_event(uint32_t event); + //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler //--------------------------------------------------------------------+ @@ -46,30 +56,6 @@ extern "C" void USBD_IRQHandler(void) #endif } -//--------------------------------------------------------------------+ -// MACRO TYPEDEF CONSTANT ENUM DECLARATION -//--------------------------------------------------------------------+ - -#define USBD_STACK_SZ (200) - -// tinyusb function that handles power event (detected, ready, removed) -// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. -extern "C" void tusb_hal_nrf_power_event(uint32_t event); - -// USB Device Driver task -// This top level thread process all usb events and invoke callbacks -static void usb_device_task(void* param) -{ - (void) param; - - // RTOS forever loop - while (1) - { - // tinyusb device task - tud_task(); - } -} - //--------------------------------------------------------------------+ // Core Init & Touch1200 //--------------------------------------------------------------------+ @@ -99,8 +85,12 @@ static void usb_hardware_init(void) if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY); } -void Adafruit_TinyUSB_Core_init(void) +// USB Device Driver task +// This top level thread process all usb events and invoke callbacks +static void usb_device_task(void* param) { + (void) param; + USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial); USBDevice.setID(USB_VID, USB_PID); USBDevice.begin(); @@ -110,6 +100,16 @@ void Adafruit_TinyUSB_Core_init(void) // Init tinyusb stack tusb_init(); + // RTOS forever loop + while (1) + { + // tinyusb device task + tud_task(); + } +} + +void Adafruit_TinyUSB_Core_init(void) +{ // Create a task for tinyusb device stack xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL); } diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 81eb60e3..98e3a291 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -44,10 +44,6 @@ static void loop_task(void* arg) { (void) arg; -#ifdef USE_TINYUSB - Adafruit_TinyUSB_Core_init(); -#endif - #if CFG_DEBUG // If Serial is not begin(), call it to avoid hard fault if(!Serial) Serial.begin(115200); @@ -80,6 +76,10 @@ int main( void ) SEGGER_SYSVIEW_Conf(); #endif +#ifdef USE_TINYUSB + Adafruit_TinyUSB_Core_init(); +#endif + // Create a task for loop() xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);