Skip to content

Commit

Permalink
stm32f7nucleo: Add ADC support
Browse files Browse the repository at this point in the history
Aligned to configuration of NuttX: GPIO_ADC1_IN3
nuttx/configs/nucleo-144/src/stm32_adc.c
(nuttx-7.21-298-gc67b807f43)

More pins/channels may be configured later.

Also handle difference per processors
(this could be aligned in NuttX codebase).

Change-Id: I5407e6b9b91eaa8570713d0331f786441ce0c649
Relate-to: rzr/webthing-iotjs#3
Forwarded: #1894
IoT.js-DCO-1.0-Signed-off-by: Philippe Coval p.coval@samsung.com
  • Loading branch information
rzr committed Jun 20, 2019
1 parent b266bf9 commit f3679c9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/nuttx/stm32f7nucleo/nuttx.profile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ENABLE_MODULE_IOTJS_BASIC_MODULES
ENABLE_MODULE_IOTJS_CORE_MODULES
ENABLE_MODULE_ADC
ENABLE_MODULE_GPIO
ENABLE_MODULE_PWM
ENABLE_MODULE_STM32F7NUCLEO
24 changes: 24 additions & 0 deletions src/modules/nuttx/iotjs_module_stm32f7nucleo-nuttx.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
#include "iotjs_def.h"
#include "modules/iotjs_module_stm32f7nucleo.h"

#if ENABLE_MODULE_ADC
static void iotjs_pin_initialize_adc(jerry_value_t jobj) {
unsigned int number_bit;

// ADC pin name is "ADC(number)_(timer)".
#define SET_ADC_CONSTANT(number, timer) \
number_bit = (GPIO_ADC##number##_IN##timer); \
number_bit |= (ADC_NUMBER(number)); \
number_bit |= (SYSIO_TIMER_NUMBER(timer)); \
iotjs_jval_set_property_number(jobj, "ADC" #number "_" #timer, number_bit);

#define SET_ADC_CONSTANT_NUMBER(number) SET_ADC_CONSTANT(number, 3);

SET_ADC_CONSTANT_NUMBER(1);

#undef SET_ADC_CONSTANT_NUMBER
#undef SET_ADC_CONSTANT
}
#endif /* ENABLE_MODULE_ADC */

#if ENABLE_MODULE_GPIO

static void iotjs_pin_initialize_gpio(jerry_value_t jobj) {
Expand Down Expand Up @@ -115,6 +135,10 @@ void iotjs_stm32f7nucleo_pin_initialize(jerry_value_t jobj) {
jerry_value_t jpin = jerry_create_object();
iotjs_jval_set_property_jval(jobj, "pin", jpin);

#if ENABLE_MODULE_ADC
iotjs_pin_initialize_adc(jpin);
#endif /* ENABLE_MODULE_ADC */

#if ENABLE_MODULE_GPIO
iotjs_pin_initialize_gpio(jpin);
#endif /* ENABLE_MODULE_GPIO */
Expand Down
4 changes: 4 additions & 0 deletions src/platform/nuttx/iotjs_systemio-nuttx.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ struct adc_dev_s* iotjs_adc_config_nuttx(int number, int timer, uint32_t pin) {
stm32_configgpio(pin);

uint8_t channel_list[1] = { timer };
#if defined(TARGET_BOARD_STM32F4DIS)
return stm32_adcinitialize(number, channel_list, 1);
#elif defined(TARGET_BOARD_STM32F7NUCLEO)
return stm32_adc_initialize(number, channel_list, 1);
#endif
}

#endif /* ENABLE_MODULE_ADC */
Expand Down

0 comments on commit f3679c9

Please sign in to comment.