Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
6efbf13e
Commit
6efbf13e
authored
Mar 01, 2016
by
philip
Browse files
Omit all the PWM code if the PWM module is not included
parent
ebb0c333
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/modules/pwm.c
View file @
6efbf13e
...
@@ -122,6 +122,11 @@ static int lpwm_getduty( lua_State* L )
...
@@ -122,6 +122,11 @@ static int lpwm_getduty( lua_State* L )
return
1
;
return
1
;
}
}
int
lpwm_open
(
lua_State
*
L
)
{
platform_pwm_init
();
return
0
;
}
// Module function map
// Module function map
static
const
LUA_REG_TYPE
pwm_map
[]
=
{
static
const
LUA_REG_TYPE
pwm_map
[]
=
{
{
LSTRKEY
(
"setup"
),
LFUNCVAL
(
lpwm_setup
)
},
{
LSTRKEY
(
"setup"
),
LFUNCVAL
(
lpwm_setup
)
},
...
@@ -135,4 +140,4 @@ static const LUA_REG_TYPE pwm_map[] = {
...
@@ -135,4 +140,4 @@ static const LUA_REG_TYPE pwm_map[] = {
{
LNILKEY
,
LNILVAL
}
{
LNILKEY
,
LNILVAL
}
};
};
NODEMCU_MODULE
(
PWM
,
"pwm"
,
pwm_map
,
NULL
);
NODEMCU_MODULE
(
PWM
,
"pwm"
,
pwm_map
,
lpwm_open
);
app/platform/platform.c
View file @
6efbf13e
...
@@ -32,16 +32,11 @@ static struct gpio_hook platform_gpio_hook;
...
@@ -32,16 +32,11 @@ static struct gpio_hook platform_gpio_hook;
#endif
#endif
#endif
#endif
static
void
pwms_init
();
int
platform_init
()
int
platform_init
()
{
{
// Setup the various forward and reverse mappings for the pins
// Setup the various forward and reverse mappings for the pins
get_pin_map
();
get_pin_map
();
// Setup PWMs
pwms_init
();
cmn_platform_init
();
cmn_platform_init
();
// All done
// All done
return
PLATFORM_OK
;
return
PLATFORM_OK
;
...
@@ -113,7 +108,9 @@ int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
...
@@ -113,7 +108,9 @@ int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull )
return
1
;
return
1
;
}
}
#ifdef LUA_USE_MODULES_PWM
platform_pwm_close
(
pin
);
// closed from pwm module, if it is used in pwm
platform_pwm_close
(
pin
);
// closed from pwm module, if it is used in pwm
#endif
if
(
pull
==
PLATFORM_GPIO_PULLUP
)
{
if
(
pull
==
PLATFORM_GPIO_PULLUP
)
{
PIN_PULLUP_EN
(
pin_mux
[
pin
]);
PIN_PULLUP_EN
(
pin_mux
[
pin
]);
...
@@ -421,7 +418,7 @@ void platform_uart_send( unsigned id, u8 data )
...
@@ -421,7 +418,7 @@ void platform_uart_send( unsigned id, u8 data )
static
uint16_t
pwms_duty
[
NUM_PWM
]
=
{
0
};
static
uint16_t
pwms_duty
[
NUM_PWM
]
=
{
0
};
static
void
pwm
s
_init
()
void
platform_
pwm_init
()
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
NUM_PWM
;
i
++
){
for
(
i
=
0
;
i
<
NUM_PWM
;
i
++
){
...
...
app/platform/platform.h
View file @
6efbf13e
...
@@ -70,7 +70,7 @@ enum
...
@@ -70,7 +70,7 @@ enum
ELUA_CAN_ID_EXT
ELUA_CAN_ID_EXT
};
};
static
inline
int
platform_can_exists
(
unsigned
id
)
{
return
id
<
NUM_CAN
;
}
static
inline
int
platform_can_exists
(
unsigned
id
)
{
return
NUM_CAN
&&
(
id
<
NUM_CAN
)
;
}
uint32_t
platform_can_setup
(
unsigned
id
,
uint32_t
clock
);
uint32_t
platform_can_setup
(
unsigned
id
,
uint32_t
clock
);
int
platform_can_send
(
unsigned
id
,
uint32_t
canid
,
uint8_t
idtype
,
uint8_t
len
,
const
uint8_t
*
data
);
int
platform_can_send
(
unsigned
id
,
uint32_t
canid
,
uint8_t
idtype
,
uint8_t
len
,
const
uint8_t
*
data
);
int
platform_can_recv
(
unsigned
id
,
uint32_t
*
canid
,
uint8_t
*
idtype
,
uint8_t
*
len
,
uint8_t
*
data
);
int
platform_can_recv
(
unsigned
id
,
uint32_t
*
canid
,
uint8_t
*
idtype
,
uint8_t
*
len
,
uint8_t
*
data
);
...
@@ -171,6 +171,7 @@ void platform_uart_alt( int set );
...
@@ -171,6 +171,7 @@ void platform_uart_alt( int set );
#define DUTY(d) ((uint16_t)( ((unsigned)(d)*PWM_DEPTH) / NORMAL_PWM_DEPTH) )
#define DUTY(d) ((uint16_t)( ((unsigned)(d)*PWM_DEPTH) / NORMAL_PWM_DEPTH) )
// The platform PWM functions
// The platform PWM functions
void
platform_pwm_init
(
void
);
static
inline
int
platform_pwm_exists
(
unsigned
id
)
{
return
((
id
<
NUM_PWM
)
&&
(
id
>
0
));
}
static
inline
int
platform_pwm_exists
(
unsigned
id
)
{
return
((
id
<
NUM_PWM
)
&&
(
id
>
0
));
}
uint32_t
platform_pwm_setup
(
unsigned
id
,
uint32_t
frequency
,
unsigned
duty
);
uint32_t
platform_pwm_setup
(
unsigned
id
,
uint32_t
frequency
,
unsigned
duty
);
void
platform_pwm_close
(
unsigned
id
);
void
platform_pwm_close
(
unsigned
id
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment