From 3e66f7491bb7f3bd36b85329dad45500aecbe51e Mon Sep 17 00:00:00 2001 From: Nishanth Samala Date: Wed, 5 Feb 2020 15:42:00 -0500 Subject: [PATCH] added led helper methods. Added boards.txt --- README.md | 15 ++++++++++++++ variants/particle_xenon/variant.cpp | 32 +++++++++++++++++++++++++++++ variants/particle_xenon/variant.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 6ceaaa3a..9e34f4d3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series: Following boards are also included but are not officially supported: - [Nordic nRF52840DK PCA10056](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK) +- [Particle Xenon](https://store.particle.io/products/xenon) ## BSP Installation @@ -103,6 +104,20 @@ $ nrfjprog --program feather_nrf52832_bootloader.hex -f nrf52 $ nrfjprog --reset -f nrf52 ``` +## Particle Xenon Specific +```c++ +// Swap between the internal antenna and external u.FL antenna +switchAntenna(bool useExternal); + +// Control RGB led / primary LED individually +ledWrite(LED_RGB_RED, 255); +ledWrite(LED_PRIMARY, 127); + +// Control RGB leds in one shot +rgbLedWrite(50, 100, 150); + +``` + ## Credits This core is based on [Arduino-nRF5](https://github.com/sandeepmistry/arduino-nRF5) by Sandeep Mistry, diff --git a/variants/particle_xenon/variant.cpp b/variants/particle_xenon/variant.cpp index d3919ae7..f546d731 100644 --- a/variants/particle_xenon/variant.cpp +++ b/variants/particle_xenon/variant.cpp @@ -56,6 +56,11 @@ const uint32_t g_ADigitalPinMap[] = void initVariant() { switch_antenna(false); + + led_pwm_init(LED_PRIMARY_IDX, LED_PRIMARY_PIN); + led_pwm_init(LED_RGB_RED_IDX, LED_RGB_RED_PIN); + led_pwm_init(LED_RGB_BLUE_IDX, LED_RGB_BLUE_PIN); + led_pwm_init(LED_RGB_GREEN_IDX, LED_RGB_GREEN_PIN); } void switch_antenna(bool useExternal) { @@ -106,6 +111,33 @@ void led_pwm_duty_cycle(uint32_t led_index, uint16_t duty_cycle) { nrf_pwm_task_trigger(NRF_PWM0, NRF_PWM_TASK_SEQSTART0); } +void ledWrite(uint32_t led_pin, uint8_t value) { + uint32_t index = -1; + switch (led_pin) { + case LED_PRIMARY_PIN: + index = LED_PRIMARY_IDX; + break; + case LED_RGB_RED_PIN: + index = LED_RGB_RED_IDX; + break; + case LED_RGB_GREEN_PIN: + index = LED_RGB_GREEN_IDX; + break; + case LED_RGB_BLUE_PIN: + index = LED_RGB_BLUE_IDX; + break; + } + + if (index != -1) + led_pwm_duty_cycle(index, value); +} + +void rgbLedWrite(uint8_t red, uint8_t green, uint8_t blue) { + led_pwm_duty_cycle(LED_RGB_RED_IDX, red); + led_pwm_duty_cycle(LED_RGB_GREEN_IDX, green); + led_pwm_duty_cycle(LED_RGB_BLUE_IDX, blue); +} + void pwm_teardown(NRF_PWM_Type* pwm) { pwm->TASKS_SEQSTART[0] = 0; pwm->ENABLE = 0; diff --git a/variants/particle_xenon/variant.h b/variants/particle_xenon/variant.h index 39c6a2e0..f01c9cd5 100644 --- a/variants/particle_xenon/variant.h +++ b/variants/particle_xenon/variant.h @@ -197,6 +197,8 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin); void led_pwm_teardown(void); void led_pwm_duty_cycle(uint32_t led_index, uint16_t duty_cycle); void pwm_teardown(NRF_PWM_Type* pwm); +void ledWrite(uint32_t led_pin, uint8_t value); +void rgbLedWrite(uint8_t red, uint8_t green, uint8_t blue); static uint16_t led_duty_cycles[PWM0_CH_NUM] = { 0 }; #ifdef __cplusplus