Merge pull request #1110 from pjsg/pwm_module
Omit all the PWM code if the PWM module is not included
This commit is contained in:
commit
cfe358059b
|
@ -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[] = {
|
||||||
{ LNILKEY, LNILVAL }
|
{ LNILKEY, LNILVAL }
|
||||||
};
|
};
|
||||||
|
|
||||||
NODEMCU_MODULE(PWM, "pwm", pwm_map, NULL);
|
NODEMCU_MODULE(PWM, "pwm", pwm_map, lpwm_open);
|
||||||
|
|
|
@ -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 )
|
||||||
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 )
|
||||||
|
|
||||||
static uint16_t pwms_duty[NUM_PWM] = {0};
|
static uint16_t pwms_duty[NUM_PWM] = {0};
|
||||||
|
|
||||||
static void pwms_init()
|
void platform_pwm_init()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<NUM_PWM;i++){
|
for(i=0;i<NUM_PWM;i++){
|
||||||
|
|
|
@ -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 );
|
||||||
#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 );
|
||||||
|
|
Loading…
Reference in New Issue