Skip to content

Commit 3e66f74

Browse files
committed
added led helper methods. Added boards.txt
1 parent f92c0b7 commit 3e66f74

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
99
Following boards are also included but are not officially supported:
1010

1111
- [Nordic nRF52840DK PCA10056](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK)
12+
- [Particle Xenon](https://store.particle.io/products/xenon)
1213

1314
## BSP Installation
1415

@@ -103,6 +104,20 @@ $ nrfjprog --program feather_nrf52832_bootloader.hex -f nrf52
103104
$ nrfjprog --reset -f nrf52
104105
```
105106
107+
## Particle Xenon Specific
108+
```c++
109+
// Swap between the internal antenna and external u.FL antenna
110+
switchAntenna(bool useExternal);
111+
112+
// Control RGB led / primary LED individually
113+
ledWrite(LED_RGB_RED, 255);
114+
ledWrite(LED_PRIMARY, 127);
115+
116+
// Control RGB leds in one shot
117+
rgbLedWrite(50, 100, 150);
118+
119+
```
120+
106121
## Credits
107122

108123
This core is based on [Arduino-nRF5](https://github.com/sandeepmistry/arduino-nRF5) by Sandeep Mistry,

variants/particle_xenon/variant.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ const uint32_t g_ADigitalPinMap[] =
5656
void initVariant()
5757
{
5858
switch_antenna(false);
59+
60+
led_pwm_init(LED_PRIMARY_IDX, LED_PRIMARY_PIN);
61+
led_pwm_init(LED_RGB_RED_IDX, LED_RGB_RED_PIN);
62+
led_pwm_init(LED_RGB_BLUE_IDX, LED_RGB_BLUE_PIN);
63+
led_pwm_init(LED_RGB_GREEN_IDX, LED_RGB_GREEN_PIN);
5964
}
6065

6166
void switch_antenna(bool useExternal) {
@@ -106,6 +111,33 @@ void led_pwm_duty_cycle(uint32_t led_index, uint16_t duty_cycle) {
106111
nrf_pwm_task_trigger(NRF_PWM0, NRF_PWM_TASK_SEQSTART0);
107112
}
108113

114+
void ledWrite(uint32_t led_pin, uint8_t value) {
115+
uint32_t index = -1;
116+
switch (led_pin) {
117+
case LED_PRIMARY_PIN:
118+
index = LED_PRIMARY_IDX;
119+
break;
120+
case LED_RGB_RED_PIN:
121+
index = LED_RGB_RED_IDX;
122+
break;
123+
case LED_RGB_GREEN_PIN:
124+
index = LED_RGB_GREEN_IDX;
125+
break;
126+
case LED_RGB_BLUE_PIN:
127+
index = LED_RGB_BLUE_IDX;
128+
break;
129+
}
130+
131+
if (index != -1)
132+
led_pwm_duty_cycle(index, value);
133+
}
134+
135+
void rgbLedWrite(uint8_t red, uint8_t green, uint8_t blue) {
136+
led_pwm_duty_cycle(LED_RGB_RED_IDX, red);
137+
led_pwm_duty_cycle(LED_RGB_GREEN_IDX, green);
138+
led_pwm_duty_cycle(LED_RGB_BLUE_IDX, blue);
139+
}
140+
109141
void pwm_teardown(NRF_PWM_Type* pwm) {
110142
pwm->TASKS_SEQSTART[0] = 0;
111143
pwm->ENABLE = 0;

variants/particle_xenon/variant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin);
197197
void led_pwm_teardown(void);
198198
void led_pwm_duty_cycle(uint32_t led_index, uint16_t duty_cycle);
199199
void pwm_teardown(NRF_PWM_Type* pwm);
200+
void ledWrite(uint32_t led_pin, uint8_t value);
201+
void rgbLedWrite(uint8_t red, uint8_t green, uint8_t blue);
200202
static uint16_t led_duty_cycles[PWM0_CH_NUM] = { 0 };
201203

202204
#ifdef __cplusplus

0 commit comments

Comments
 (0)