summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-07-06 12:48:16 -0700
committerScott Shawcroft <scott@tannewt.org>2019-07-06 12:48:16 -0700
commit5610e05b8c19c3892dfe9bfced719307a95f365e (patch)
treeb01e5401dfbd86e341e4cd5b0216879327853f3b
parent9de46f3edd9bd6a827ba92ef4978143b109e912c (diff)
Fix up nrf so that it is initialized properly. Also, do not reset
it's pins.
-rw-r--r--ports/nrf/boards/particle_xenon/mpconfigboard.h6
-rw-r--r--ports/nrf/common-hal/pulseio/PWMOut.c55
-rw-r--r--supervisor/shared/rgb_led_status.c23
3 files changed, 44 insertions, 40 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);
}
diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c
index 2d7bb067e..3146cc686 100644
--- a/supervisor/shared/rgb_led_status.c
+++ b/supervisor/shared/rgb_led_status.c
@@ -155,9 +155,7 @@ void reset_status_led() {
reset_pin_number(MICROPY_HW_APA102_SCK->number);
#endif
#if defined(CP_RGB_STATUS_LED)
- reset_pin_number(CP_RGB_STATUS_R->number);
- reset_pin_number(CP_RGB_STATUS_G->number);
- reset_pin_number(CP_RGB_STATUS_B->number);
+ // TODO: Support sharing status LED with user.
#endif
}
@@ -199,9 +197,9 @@ void new_status_color(uint32_t rgb) {
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
uint8_t blue_u8 = rgb_adjusted & 0xFF;
- status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8;
- status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8;
- status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
+ status_rgb_color[0] = (1<<16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
+ status_rgb_color[1] = (1<<16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
+ status_rgb_color[2] = (1<<16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8);
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]);
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]);
@@ -237,13 +235,14 @@ void temp_status_color(uint32_t rgb) {
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
uint8_t blue_u8 = rgb_adjusted & 0xFF;
- status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8;
- status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8;
- status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
+ uint16_t temp_status_color_rgb[3];
+ temp_status_color_rgb[0] = (uint16_t) (red_u8 << 8) + red_u8;
+ temp_status_color_rgb[1] = (uint16_t) (green_u8 << 8) + green_u8;
+ temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
- common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]);
- common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]);
- common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]);
+ common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]);
+ common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]);
+ common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]);
#endif
}