Retract pin resets, revert to HAL, QOL changes

This commit is contained in:
Hierophect 2019-09-17 15:05:23 -04:00
parent 55eb8dcfa0
commit 168823e096
3 changed files with 67 additions and 46 deletions

View File

@ -80,11 +80,24 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_PC08) }, { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_PC08) },
{ MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) },
{ MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) },
//Names //ST LED names
{ MP_ROM_QSTR(MP_QSTR_LD3), MP_ROM_PTR(&pin_PD13) }, { MP_ROM_QSTR(MP_QSTR_LD3), MP_ROM_PTR(&pin_PD13) },
{ MP_ROM_QSTR(MP_QSTR_LD4), MP_ROM_PTR(&pin_PD12) }, { MP_ROM_QSTR(MP_QSTR_LD4), MP_ROM_PTR(&pin_PD12) },
{ MP_ROM_QSTR(MP_QSTR_LD5), MP_ROM_PTR(&pin_PD14) }, { MP_ROM_QSTR(MP_QSTR_LD5), MP_ROM_PTR(&pin_PD14) },
{ MP_ROM_QSTR(MP_QSTR_LD6), MP_ROM_PTR(&pin_PD15) }, { MP_ROM_QSTR(MP_QSTR_LD6), MP_ROM_PTR(&pin_PD15) },
//more useful LED names
{ MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_PD13) },
{ MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_PD12) },
{ MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_PD14) },
{ MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_PD15) },
//AnalogIO names
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA05) },
//actual LED names
{ MP_ROM_QSTR(MP_QSTR_LED_ORANGE), MP_ROM_PTR(&pin_PD13) }, { MP_ROM_QSTR(MP_QSTR_LED_ORANGE), MP_ROM_PTR(&pin_PD13) },
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_PD12) }, { MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_PD12) },
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_PD14) }, { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_PD14) },

View File

@ -41,13 +41,15 @@
void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self, void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
//No ADC function on pin // No ADC function on pin
if (pin->adc_unit == 0x00) { if (pin->adc_unit == 0x00) {
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
} }
//TODO: add ADC traits to structure? // TODO: add ADC traits to structure?
LL_GPIO_SetPinMode(pin_port(pin->port), pin_mask(pin->number), LL_GPIO_MODE_ANALOG); // Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only
// for dual conversion. For this basic application it is never used.
LL_GPIO_SetPinMode(pin_port(pin->port), (uint32_t)pin_mask(pin->number), LL_GPIO_MODE_ANALOG);
if (pin->adc_unit & 0x01) { if (pin->adc_unit & 0x01) {
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
} else if (pin->adc_unit == 0x04) { } else if (pin->adc_unit == 0x04) {
@ -88,55 +90,58 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
mp_raise_ValueError(translate("Invalid ADC Unit value")); mp_raise_ValueError(translate("Invalid ADC Unit value"));
} }
LL_GPIO_SetPinMode(pin_port(self->pin->port), (uint32_t)pin_mask(self->pin->number), LL_GPIO_MODE_ANALOG);
//LL_GPIO_PIN_0
//HAL Implementation //HAL Implementation
// ADC_HandleTypeDef AdcHandle; ADC_HandleTypeDef AdcHandle;
// ADC_ChannelConfTypeDef sConfig; ADC_ChannelConfTypeDef sConfig;
// AdcHandle.Instance = ADC1; AdcHandle.Instance = ADCx;
// AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
// AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
// AdcHandle.Init.ScanConvMode = DISABLE; AdcHandle.Init.ScanConvMode = DISABLE;
// AdcHandle.Init.ContinuousConvMode = ENABLE; AdcHandle.Init.ContinuousConvMode = DISABLE;
// AdcHandle.Init.DiscontinuousConvMode = DISABLE; AdcHandle.Init.DiscontinuousConvMode = DISABLE;
// AdcHandle.Init.NbrOfDiscConversion = 0; AdcHandle.Init.NbrOfDiscConversion = 0;
// AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
// AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
// AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
// AdcHandle.Init.NbrOfConversion = 1; AdcHandle.Init.NbrOfConversion = 1;
// AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.DMAContinuousRequests = ENABLE;
// AdcHandle.Init.EOCSelection = DISABLE; AdcHandle.Init.EOCSelection = DISABLE;
// sConfig.Channel = self->pin->adc_channel; sConfig.Channel = (uint32_t)self->pin->adc_channel; //ADC_CHANNEL_0 <-normal iteration, not mask
// sConfig.Rank = 1; sConfig.Rank = 1;
// sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
// sConfig.Offset = 0; sConfig.Offset = 0;
// HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
// HAL_ADC_Start(&AdcHandle); HAL_ADC_Start(&AdcHandle);
// HAL_ADC_PollForConversion(&AdcHandle,1); //timeout in ms HAL_ADC_PollForConversion(&AdcHandle,1); //timeout in ms
// uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle); uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
// HAL_ADC_Stop(&AdcHandle); HAL_ADC_Stop(&AdcHandle);
//LL Implementation //LL Implementation
if (LL_ADC_IsEnabled(ADCx) == 0) // if (LL_ADC_IsEnabled(ADCx) == 0)
{ // {
LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE); // LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
LL_ADC_REG_SetContinuousMode(ADCx, LL_ADC_REG_CONV_SINGLE); // LL_ADC_REG_SetContinuousMode(ADCx, LL_ADC_REG_CONV_SINGLE);
LL_ADC_REG_SetSequencerLength(ADCx, LL_ADC_REG_SEQ_SCAN_DISABLE); // LL_ADC_REG_SetSequencerLength(ADCx, LL_ADC_REG_SEQ_SCAN_DISABLE);
LL_ADC_REG_SetSequencerRanks(ADCx, LL_ADC_REG_RANK_1, self->pin->adc_channel); // //LL_ADC_REG_SetSequencerRanks(ADCx, LL_ADC_REG_RANK_1, self->pin->adc_channel);
//LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_4); // //^ Above is WRONG: channel value requires inserted channel information. Hard to iterate through.
// LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_4);
LL_ADC_SetChannelSamplingTime(ADCx, self->pin->adc_channel, LL_ADC_SAMPLINGTIME_56CYCLES); // LL_ADC_SetChannelSamplingTime(ADCx, self->pin->adc_channel, LL_ADC_SAMPLINGTIME_56CYCLES);
LL_ADC_EnableIT_OVR(ADCx); // LL_ADC_EnableIT_OVR(ADCx);
} // }
LL_ADC_Enable(ADCx); // LL_ADC_Enable(ADCx);
uint16_t uhADCxConvertedData = (__LL_ADC_DIGITAL_SCALE(LL_ADC_RESOLUTION_12B) + 1); // uint16_t uhADCxConvertedData = (__LL_ADC_DIGITAL_SCALE(LL_ADC_RESOLUTION_12B) + 1);
LL_ADC_REG_StartConversionSWStart(ADCx); // LL_ADC_REG_StartConversionSWStart(ADCx);
while (LL_ADC_IsActiveFlag_EOCS(ADCx) == 0) {} // while (LL_ADC_IsActiveFlag_EOCS(ADCx) == 0) {}
/* Retrieve ADC conversion data */ // /* Retrieve ADC conversion data */
/* (data scale corresponds to ADC resolution: 12 bits) */ // /* (data scale corresponds to ADC resolution: 12 bits) */
uhADCxConvertedData = LL_ADC_REG_ReadConversionData12(ADCx); // uhADCxConvertedData = LL_ADC_REG_ReadConversionData12(ADCx);
// // Shift the value to be 16 bit. // // Shift the value to be 16 bit.
return uhADCxConvertedData << 4; return uhADCxConvertedData << 4;

View File

@ -50,7 +50,10 @@ safe_mode_t port_init(void) {
} }
void reset_port(void) { void reset_port(void) {
reset_all_pins(); //reset_all_pins();
//reset_pin_number(uint8_t pin_port, uint8_t pin_number)
for(int i=0;i<8;i++) reset_pin_number(0,i); //PA (analog)
for(int i=12;i<16;i++) reset_pin_number(3,i); //PD (leds)
} }
void reset_to_bootloader(void) { void reset_to_bootloader(void) {