8000 Fix up nrf so that it is initialized properly. Also, do not reset · losingrose/circuitpython@5610e05 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5610e05

Browse files
committed
Fix up nrf so that it is initialized properly. Also, do not reset
it's pins.
1 parent 9de46f3 commit 5610e05

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

ports/nrf/boards/particle_xenon/mpconfigboard.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535

3636
#define MICROPY_HW_LED_STATUS (&pin_P1_12)
3737

38-
#define MICROPY_HW_RGB_LED_RED (&pin_P0_13)
39-
#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14)
40-
#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15)
38+
#define CP_RGB_STATUS_R (&pin_P0_13)
39+
#define CP_RGB_STATUS_G (&pin_P0_14)
40+
#define CP_RGB_STATUS_B (&pin_P0_15)
4141

4242
#if QSPI_FLASH_FILESYSTEM
4343
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)

ports/nrf/common-hal/pulseio/PWMOut.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,37 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
7777
}
7878
}
7979

80+
void reset_single_pwmout(uint8_t i) {
81+
NRF_PWM_Type* pwm = pwms[i];
82+
83+
pwm->ENABLE = 0;
84+
pwm->MODE = PWM_MODE_UPDOWN_Up;
85+
pwm->DECODER = PWM_DECODER_LOAD_Individual;
86+
pwm->LOOP = 0;
87+
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz
88+
pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz
89+
90+
pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i];
91+
pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4
92+
pwm->SEQ[0].REFRESH = 0;
93+
pwm->SEQ[0].ENDDELAY = 0;
94+
95+
pwm->SEQ[1].PTR = 0;
96+
pwm->SEQ[1].CNT = 0;
97+
pwm->SEQ[1].REFRESH = 0;
98+
pwm->SEQ[1].ENDDELAY = 0;
99+
100+
for(int ch =0; ch < CHANNELS_PER_PWM; ch++) {
101+
pwm_seq[i][ch] = (1 << 15); // polarity = 0
102+
}
103+
}
104+
80105
void pwmout_reset(void) {
81106
for(size_t i=0; i < MP_ARRAY_SIZE(pwms); i++) {
82107
if (never_reset_pwm[i] > 0) {
83108
continue;
84109
}
85-
NRF_PWM_Type* pwm = pwms[i];
86-
87-
pwm->ENABLE = 0;
88-
pwm->MODE = PWM_MODE_UPDOWN_Up;
89-
pwm->DECODER = PWM_DECODER_LOAD_Individual;
90-
pwm->LOOP = 0;
91-
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz
92-
pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz
93-
94-
pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i];
95-
pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4
96-
pwm->SEQ[0].REFRESH = 0;
97-
pwm->SEQ[0].ENDDELAY = 0;
98-
99-
pwm->SEQ[1].PTR = 0;
100-
pwm->SEQ[1].CNT = 0;
101-
pwm->SEQ[1].REFRESH = 0;
102-
pwm->SEQ[1].ENDDELAY = 0;
103-
104-
for(int ch =0; ch < CHANNELS_PER_PWM; ch++) {
105-
pwm_seq[i][ch] = (1 << 15); // polarity = 0
106-
}
110+
reset_single_pwmout(i);
107111
}
108112
}
109113

@@ -148,9 +152,9 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
148152
self->channel = CHANNELS_PER_PWM; // out-of-range value.
149153
bool pwm_already_in_use;
150154
NRF_PWM_Type* pwm;
151-
152-
for (size_t i = 0 ; i < MP_ARRAY_SIZE(pwms); i++) {
153-
pwm = pwms[i];
155+
size_t pwm_index = 0;
156+
for (; pwm_index < MP_ARRAY_SIZE(pwms); pwm_index++) {
157+
pwm = pwms[pwm_index];
154158
pwm_already_in_use = pwm->ENABLE & SPIM_ENABLE_ENABLE_Msk;
155159
if (pwm_already_in_use) {
156160
if (variable_frequency) {
@@ -199,6 +203,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
199203
nrf_pwm_disable(pwm);
200204

201205
if (!pwm_already_in_use) {
206+
reset_single_pwmout(pwm_index);
202207
nrf_pwm_configure(pwm, base_clock, NRF_PWM_MODE_UP, countertop);
203208
}
204209

supervisor/shared/rgb_led_status.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ void reset_status_led() {
155155
reset_pin_number(MICROPY_HW_APA102_SCK->number);
156156
#endif
157157
#if defined(CP_RGB_STATUS_LED)
158-
reset_pin_number(CP_RGB_STATUS_R->number);
159-
reset_pin_number(CP_RGB_STATUS_G->number);
160-
reset_pin_number(CP_RGB_STATUS_B->number);
158+
// TODO: Support sharing status LED with user.
161159
#endif
162160
}
163161

@@ -199,9 +197,9 @@ void new_status_color(uint32_t rgb) {
199197
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
200198
uint8_t blue_u8 = rgb_adjusted & 0xFF;
201199

202-
status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8;
203-
status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8;
204-
status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
200+
status_rgb_color[0] = (1<<16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
201+
status_rgb_color[1] = (1<<16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
202+
status_rgb_color[2] = (1<<16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8);
205203

206204
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]);
207205
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) {
237235
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
238236
uint8_t blue_u8 = rgb_adjusted & 0xFF;
239237

240-
status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8;
241-
status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8;
242-
status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
238+
uint16_t temp_status_color_rgb[3];
239+
temp_status_color_rgb[0] = (uint16_t) (red_u8 << 8) + red_u8;
240+
temp_status_color_rgb[1] = (uint16_t) (green_u8 << 8) + green_u8;
241+
temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
243242

244-
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]);
245-
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]);
246-
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]);
243+
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]);
244+
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]);
245+
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]);
247246
#endif
248247
}
249248

0 commit comments

Comments
 (0)
0