added led helper methods. Added boards.txt

This commit is contained in:
Nishanth Samala committed 2020-02-05 15:42:00 -05:00
1 parent f92c0b7c14
commit 3e66f7491b
3 files changed
+49

No files matched your search

+15
View File
@@ -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,
+32
View File
@@ -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;
+2
View File
@@ -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