Fix up nrf so that it is initialized properly. Also, do not reset

it's pins.
This commit is contained in:
Scott Shawcroft 2019-07-06 12:48:16 -07:00
parent 9de46f3edd
commit 5610e05b8c
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
3 changed files with 44 additions and 40 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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
}