Skip to content

Commit

Permalink
ports/psoc6: Removed psoc6_pwm driver.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx committed Sep 7, 2023
1 parent 499cded commit 8b9c468
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 63 deletions.
1 change: 0 additions & 1 deletion ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ DRIVERS_SRC_C += $(addprefix drivers/,\
DRIVERS_SRC_C += $(addprefix drivers/,\
machine/psoc6_gpio.c \
machine/psoc6_i2c.c \
machine/psoc6_pwm.c \
machine/psoc6_system.c \
)

Expand Down
29 changes: 0 additions & 29 deletions ports/psoc6/drivers/machine/psoc6_pwm.c

This file was deleted.

28 changes: 0 additions & 28 deletions ports/psoc6/drivers/machine/psoc6_pwm.h

This file was deleted.

33 changes: 28 additions & 5 deletions ports/psoc6/modules/machine/machine_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

// port-specific includes
#include "drivers/machine/psoc6_gpio.h"
#include "drivers/machine/psoc6_pwm.h"
#include "mplogger.h"
#include "pins.h"

extern mp_hal_pin_obj_t mp_hal_get_pin_obj(mp_obj_t obj);

typedef struct _machine_pwm_obj_t {
mp_obj_base_t base;
cyhal_pwm_t pwm_obj;
bool active;
uint8_t pin;
uint32_t fz;
uint8_t duty_type;
mp_float_t duty;
bool invert;
} machine_pwm_obj_t;

enum {
VALUE_NOT_SET = -1,
DUTY_NOT_SET = 0,
Expand All @@ -21,6 +31,19 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq);
STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_float_t duty_u16);
STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_float_t duty_ns);

STATIC cy_rslt_t pwm_freq_duty_set(cyhal_pwm_t *pwm_obj, uint32_t fz, float duty_cycle) {
return cyhal_pwm_set_duty_cycle(pwm_obj, duty_cycle * 100, fz); // duty_cycle in percentage
}

STATIC cy_rslt_t pwm_duty_set_ns(cyhal_pwm_t *pwm_obj, uint32_t fz, uint32_t pulse_width) {
return cyhal_pwm_set_period(pwm_obj, 1000000 / fz, pulse_width * 1000);
}

STATIC cy_rslt_t pwm_advanced_init(machine_pwm_obj_t *machine_pwm_obj) {
return cyhal_pwm_init_adv(&machine_pwm_obj->pwm_obj, machine_pwm_obj->pin, NC, CYHAL_PWM_LEFT_ALIGN, true, 0, true, NULL); // complimentary pin set as not connected
}


// To check whether the PWM is active
STATIC void pwm_is_active(machine_pwm_obj_t *self) {
if (self->active == 0) {
Expand Down Expand Up @@ -71,7 +94,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
if (args[ARG_invert].u_int != VALUE_NOT_SET) {
self->invert = args[ARG_invert].u_int;
if (self->invert == 1) {
pwm_deinit(&self->pwm_obj);
cyhal_pwm_free(&self->pwm_obj);
cy_rslt_t result = pwm_advanced_init(self);
if (result != CY_RSLT_SUCCESS) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("PWM initialisation failed with return code %lx ! and invert output is not available"), result);
Expand All @@ -80,7 +103,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self,
self->duty = ((1) - ((self->duty) / 65535)) * 65535;
}
}
pwm_start(&self->pwm_obj);
cyhal_pwm_start(&self->pwm_obj);
}

STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
Expand All @@ -100,7 +123,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
self->invert = -1;

// Initialize PWM
cy_rslt_t result = pwm_init(self);
cy_rslt_t result = cyhal_pwm_init(&self->pwm_obj, self->pin, NULL);

// To check whether PWM init is successful
if (result != CY_RSLT_SUCCESS) {
Expand All @@ -116,7 +139,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
}

STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
pwm_deinit(&self->pwm_obj);
cyhal_pwm_free(&self->pwm_obj);
self->active = 0;
}

Expand Down

0 comments on commit 8b9c468

Please sign in to comment.