stm32/adc: Add basic support for ADC on a pin on STM32H7 MCUs.

This commit is contained in:
Damien George 2019-02-06 13:35:28 +11:00
parent b367c425e4
commit 43a894fb48
1 changed files with 10 additions and 4 deletions

View File

@ -51,11 +51,17 @@
/// val = adc.read_core_vref() # read MCU VREF
/* ADC defintions */
#if defined(STM32H7)
#define ADCx (ADC3)
#define PIN_ADC_MASK PIN_ADC3
#define pin_adc_table pin_adc3
#else
#define ADCx (ADC1)
#define PIN_ADC_MASK PIN_ADC1
#define pin_adc_table pin_adc1
#endif
#define ADCx_CLK_ENABLE __HAL_RCC_ADC1_CLK_ENABLE
#define ADC_NUM_CHANNELS (19)
@ -280,7 +286,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
if (ADC_FIRST_GPIO_CHANNEL <= adc_obj->channel && adc_obj->channel <= ADC_LAST_GPIO_CHANNEL) {
// Channels 0-16 correspond to real pins. Configure the GPIO pin in ADC mode.
const pin_obj_t *pin = pin_adc1[adc_obj->channel];
const pin_obj_t *pin = pin_adc_table[adc_obj->channel];
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
@ -393,7 +399,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
channel = adc_get_internal_channel(mp_obj_get_int(pin_obj));
} else {
const pin_obj_t *pin = pin_find(pin_obj);
if ((pin->adc_num & PIN_ADC1) == 0) {
if ((pin->adc_num & PIN_ADC_MASK) == 0) {
// No ADC1 function on that pin
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "pin %q does not have ADC capabilities", pin->name));
}
@ -407,7 +413,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
if (ADC_FIRST_GPIO_CHANNEL <= channel && channel <= ADC_LAST_GPIO_CHANNEL) {
// these channels correspond to physical GPIO ports so make sure they exist
if (pin_adc1[channel] == NULL) {
if (pin_adc_table[channel] == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"channel %d not available on this board", channel));
}
@ -690,7 +696,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
if (en_mask & (1 << channel)) {
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// ADC mode.
const pin_obj_t *pin = pin_adc1[channel];
const pin_obj_t *pin = pin_adc_table[channel];
if (pin) {
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}