stmhal: Make ADC channel 16 available on L4 MCUs.

pull/2348/merge
Matt Brejza 2016-08-23 23:13:03 +01:00 zatwierdzone przez Damien George
rodzic c428367543
commit 5af6184e72
2 zmienionych plików z 25 dodań i 6 usunięć

Wyświetl plik

@ -54,7 +54,16 @@
#define ADCx (ADC1)
#define ADCx_CLK_ENABLE __ADC1_CLK_ENABLE
#define ADC_NUM_CHANNELS (19)
#define ADC_NUM_GPIO_CHANNELS (16)
#if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (15)
#elif defined(MCU_SERIES_L4)
#define ADC_FIRST_GPIO_CHANNEL (1)
#define ADC_LAST_GPIO_CHANNEL (16)
#else
#error Unsupported processor
#endif
#if defined(STM32F405xx) || defined(STM32F415xx) || \
defined(STM32F407xx) || defined(STM32F417xx) || \
@ -124,7 +133,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
return;
}
if (adc_obj->channel < ADC_NUM_GPIO_CHANNELS) {
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];
@ -253,8 +262,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin
if (!is_adcx_channel(channel)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "not a valid ADC Channel: %d", channel));
}
if (pin_adc1[channel] == NULL) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "channel %d not available on this board", channel));
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) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
"channel %d not available on this board", channel));
}
}
pyb_obj_adc_t *o = m_new_obj(pyb_obj_adc_t);
@ -423,7 +438,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution) {
"resolution %d not supported", resolution));
}
for (uint32_t channel = 0; channel < ADC_NUM_GPIO_CHANNELS; channel++) {
for (uint32_t channel = ADC_FIRST_GPIO_CHANNEL; channel <= ADC_LAST_GPIO_CHANNEL; ++channel) {
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// ADC mode.
const pin_obj_t *pin = pin_adc1[channel];

Wyświetl plik

@ -303,7 +303,9 @@ class Pins(object):
def print_adc(self, adc_num):
print('');
print('const pin_obj_t * const pin_adc{:d}[] = {{'.format(adc_num))
for channel in range(16):
for channel in range(17):
if channel == 16:
print('#if defined(MCU_SERIES_L4)')
adc_found = False
for named_pin in self.cpu_pins:
pin = named_pin.pin()
@ -314,6 +316,8 @@ class Pins(object):
break
if not adc_found:
print(' NULL, // {:d}'.format(channel))
if channel == 16:
print('#endif')
print('};')