27d9b7c27aeef473303574fa616c088460082045
[platform/upstream/iotjs.git] / tools / src / platform / arm-nuttx / iotjs_systemio-arm-nuttx-stm32.c
1 /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #if defined(__NUTTX__) && TARGET_BOARD == STM32F4DIS
17
18
19 #include "iotjs_systemio-arm-nuttx.h"
20 #include "stm32_gpio.h"
21
22
23 void iotjs_gpio_unconfig_nuttx(int pin) {
24   stm32_unconfiggpio(pin);
25 }
26
27
28 #if ENABLE_MODULE_ADC
29
30 #include "stm32_adc.h"
31
32 struct adc_dev_s* iotjs_adc_config_nuttx(int number, int timer, int pin) {
33   stm32_configgpio(pin);
34
35   uint8_t channel_list[1] = { timer };
36   return stm32_adcinitialize(number, channel_list, 1);
37 }
38
39 #endif /* ENABLE_MODULE_ADC */
40
41
42 #if ENABLE_MODULE_I2C
43
44 #include "stm32_i2c.h"
45
46 struct i2c_master_s* iotjs_i2c_config_nuttx(int port) {
47   return stm32_i2cbus_initialize(port);
48 }
49
50
51 int iotjs_i2c_unconfig_nuttx(struct i2c_master_s* i2c) {
52   return stm32_i2cbus_uninitialize(i2c);
53 }
54
55 #endif /* ENABLE_MODULE_I2C */
56
57
58 #if ENABLE_MODULE_PWM
59
60 #include "stm32_pwm.h"
61
62 struct pwm_lowerhalf_s* iotjs_pwm_config_nuttx(int timer, int pin) {
63   // Set alternative function
64   stm32_configgpio(pin);
65
66   // PWM initialize
67   return stm32_pwminitialize(timer);
68 }
69
70 #endif /* ENABLE_MODULE_PWM */
71
72
73 #endif // __NUTTX__