stm32/adc: Allow mboot to use basic ADC functions.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-04-28 16:12:07 +10:00
parent ef2896bdea
commit fd01b6c779
4 changed files with 17 additions and 2 deletions

View File

@ -26,8 +26,13 @@
#ifndef MICROPY_INCLUDED_STM32_ADC_H
#define MICROPY_INCLUDED_STM32_ADC_H
#if !BUILDING_MBOOT
extern const mp_obj_type_t pyb_adc_type;
extern const mp_obj_type_t pyb_adc_all_type;
#endif
void adc_config(ADC_TypeDef *adc, uint32_t bits);
uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time);
#if defined(ADC_CHANNEL_VBAT)

View File

@ -96,7 +96,7 @@ STATIC const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8};
STATIC const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6};
#endif
STATIC void adc_config(ADC_TypeDef *adc, uint32_t bits) {
void adc_config(ADC_TypeDef *adc, uint32_t bits) {
// Configure ADC clock source and enable ADC clock
#if defined(STM32L4) || defined(STM32WB)
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
@ -331,7 +331,7 @@ STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) {
return value;
}
STATIC uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
if (channel == ADC_CHANNEL_VREF) {
return 0xffff;
}
@ -357,6 +357,8 @@ STATIC uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint
/******************************************************************************/
// MicroPython bindings for machine.ADC
#if !BUILDING_MBOOT
const mp_obj_type_t machine_adc_type;
typedef struct _machine_adc_obj_t {
@ -462,3 +464,5 @@ const mp_obj_type_t machine_adc_type = {
.make_new = machine_adc_make_new,
.locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict,
};
#endif

View File

@ -128,6 +128,7 @@ SRC_C += \
ports/stm32/flash.c \
ports/stm32/flashbdev.c \
ports/stm32/i2cslave.c \
ports/stm32/machine_adc.c \
ports/stm32/powerctrlboot.c \
ports/stm32/qspi.c \
ports/stm32/spibdev.c \

View File

@ -39,6 +39,11 @@ static inline int mp_hal_status_to_neg_errno(HAL_StatusTypeDef status) {
#define MP_HAL_PIN_MODE_OUTPUT (1)
#define MP_HAL_PIN_MODE_ALT (2)
#define MP_HAL_PIN_MODE_ANALOG (3)
#if defined(GPIO_ASCR_ASC0)
#define MP_HAL_PIN_MODE_ADC (11)
#else
#define MP_HAL_PIN_MODE_ADC (3)
#endif
#define MP_HAL_PIN_MODE_OPEN_DRAIN (5)
#define MP_HAL_PIN_MODE_ALT_OPEN_DRAIN (6)
#define MP_HAL_PIN_PULL_NONE (GPIO_NOPULL)