summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2019-07-09 10:31:34 -0700
committerGitHub <noreply@github.com>2019-07-09 10:31:34 -0700
commit6fad383367164cca5e9e92b95eaea31b088d6df0 (patch)
tree9979866cc93eab3066a0443af14f0b07969d05f4 /ports
parentf0cf9a4e75c3033371c4385b8533bb39dba7c9c4 (diff)
parent40fbac13cdf3743d2a9f218fa067399a88ad164a (diff)
Merge pull request #1925 from C47D/rgb_status
Initial support for RGB led as Status indicator, fixes #1382
Diffstat (limited to 'ports')
-rw-r--r--ports/nrf/boards/particle_xenon/mpconfigboard.h6
-rw-r--r--ports/nrf/common-hal/pulseio/PWMOut.c55
2 files changed, 33 insertions, 28 deletions
diff --git a/ports/nrf/boards/particle_xenon/mpconfigboard.h b/ports/nrf/boards/particle_xenon/mpconfigboard.h
index 41551d2e1..c8da66736 100644
--- a/ports/nrf/boards/particle_xenon/mpconfigboard.h
+++ b/ports/nrf/boards/particle_xenon/mpconfigboard.h
@@ -35,9 +35,9 @@
#define MICROPY_HW_LED_STATUS (&pin_P1_12)
-#define MICROPY_HW_RGB_LED_RED (&pin_P0_13)
-#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14)
-#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15)
+#define CP_RGB_STATUS_R (&pin_P0_13)
+#define CP_RGB_STATUS_G (&pin_P0_14)
+#define CP_RGB_STATUS_B (&pin_P0_15)
#if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
diff --git a/ports/nrf/common-hal/pulseio/PWMOut.c b/ports/nrf/common-hal/pulseio/PWMOut.c
index 5485a75d0..5233c9adc 100644
--- a/ports/nrf/common-hal/pulseio/PWMOut.c
+++ b/ports/nrf/common-hal/pulseio/PWMOut.c
@@ -77,33 +77,37 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
}
}
+void reset_single_pwmout(uint8_t i) {
+ NRF_PWM_Type* pwm = pwms[i];
+
+ pwm->ENABLE = 0;
+ pwm->MODE = PWM_MODE_UPDOWN_Up;
+ pwm->DECODER = PWM_DECODER_LOAD_Individual;
+ pwm->LOOP = 0;
+ pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz
+ pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz
+
+ pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i];
+ pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4
+ pwm->SEQ[0].REFRESH = 0;
+ pwm->SEQ[0].ENDDELAY = 0;
+
+ pwm->SEQ[1].PTR = 0;
+ pwm->SEQ[1].CNT = 0;
+ pwm->SEQ[1].REFRESH = 0;
+ pwm->SEQ[1].ENDDELAY = 0;
+
+ for(int ch =0; ch < CHANNELS_PER_PWM; ch++) {
+ pwm_seq[i][ch] = (1 << 15); // polarity = 0
+ }
+}
+
void pwmout_reset(void) {
for(size_t i=0; i < MP_ARRAY_SIZE(pwms); i++) {
if (never_reset_pwm[i] > 0) {
continue;
}
- NRF_PWM_Type* pwm = pwms[i];
-
- pwm->ENABLE = 0;
- pwm->MODE = PWM_MODE_UPDOWN_Up;
- pwm->DECODER = PWM_DECODER_LOAD_Individual;
- pwm->LOOP = 0;
- pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz
- pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz
-
- pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i];
- pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4
- pwm->SEQ[0].REFRESH = 0;
- pwm->SEQ[0].ENDDELAY = 0;
-
- pwm->SEQ[1].PTR = 0;
- pwm->SEQ[1].CNT = 0;
- pwm->SEQ[1].REFRESH = 0;
- pwm->SEQ[1].ENDDELAY = 0;
-
- for(int ch =0; ch < CHANNELS_PER_PWM; ch++) {
- pwm_seq[i][ch] = (1 << 15); // polarity = 0
- }
+ reset_single_pwmout(i);
}
}
@@ -148,9 +152,9 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
self->channel = CHANNELS_PER_PWM; // out-of-range value.
bool pwm_already_in_use;
NRF_PWM_Type* pwm;
-
- for (size_t i = 0 ; i < MP_ARRAY_SIZE(pwms); i++) {
- pwm = pwms[i];
+ size_t pwm_index = 0;
+ for (; pwm_index < MP_ARRAY_SIZE(pwms); pwm_index++) {
+ pwm = pwms[pwm_index];
pwm_already_in_use = pwm->ENABLE & SPIM_ENABLE_ENABLE_Msk;
if (pwm_already_in_use) {
if (variable_frequency) {
@@ -199,6 +203,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
nrf_pwm_disable(pwm);
if (!pwm_already_in_use) {
+ reset_single_pwmout(pwm_index);
nrf_pwm_configure(pwm, base_clock, NRF_PWM_MODE_UP, countertop);
}