Skip to content

Split pulseio.PWMOut into pwmio #3299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ports/atmel-samd/boards/pycubed/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "shared-bindings/nvm/ByteArray.h"
#include "common-hal/microcontroller/Pin.h"
#include "hal/include/hal_gpio.h"
#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-bindings/pwmio/PWMOut.h"

nvm_bytearray_obj_t bootcnt = {
.base = {
Expand All @@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = {


void board_init(void) {
pulseio_pwmout_obj_t pwm;
common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pulseio_pwmout_never_reset(&pwm);
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

bool board_requests_safe_mode(void) {
Expand Down
8 changes: 4 additions & 4 deletions ports/atmel-samd/boards/pycubed_mram/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "shared-bindings/nvm/ByteArray.h"
#include "common-hal/microcontroller/Pin.h"
#include "hal/include/hal_gpio.h"
#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-bindings/pwmio/PWMOut.h"

nvm_bytearray_obj_t bootcnt = {
.base = {
Expand All @@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = {


void board_init(void) {
pulseio_pwmout_obj_t pwm;
common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pulseio_pwmout_never_reset(&pwm);
pwmio_pwmout_obj_t pwm;
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
common_hal_pwmio_pwmout_never_reset(&pwm);
}

bool board_requests_safe_mode(void) {
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/common-hal/pulseio/PulseOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void pulseout_reset() {
}

void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
const pulseio_pwmout_obj_t* carrier,
const pwmio_pwmout_obj_t* carrier,
const mcu_pin_obj_t* pin,
uint32_t frequency,
uint16_t duty_cycle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <stdint.h>

#include "py/runtime.h"
#include "common-hal/pulseio/PWMOut.h"
#include "shared-bindings/pulseio/PWMOut.h"
#include "common-hal/pwmio/PWMOut.h"
#include "shared-bindings/pwmio/PWMOut.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "timer_handler.h"

Expand Down Expand Up @@ -78,13 +78,13 @@ void timer_reset_ok(int index, bool is_tc) {
}


void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
timer_never_reset(self->timer->index, self->timer->is_tc);

never_reset_pin_number(self->pin->number);
}

void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
timer_reset_ok(self->timer->index, self->timer->is_tc);
}

Expand Down Expand Up @@ -137,7 +137,7 @@ bool channel_ok(const pin_timer_t* t) {
t->is_tc;
}

pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
const mcu_pin_obj_t* pin,
uint16_t duty,
uint32_t frequency,
Expand Down Expand Up @@ -296,16 +296,16 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,

gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_E + mux_position);

common_hal_pulseio_pwmout_set_duty_cycle(self, duty);
common_hal_pwmio_pwmout_set_duty_cycle(self, duty);
return PWMOUT_OK;
}

bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) {
return self->pin == NULL;
}

void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
if (common_hal_pulseio_pwmout_deinited(self)) {
void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
if (common_hal_pwmio_pwmout_deinited(self)) {
return;
}
const pin_timer_t* t = self->timer;
Expand All @@ -331,7 +331,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
self->pin = NULL;
}

extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {
// Store the unadjusted duty cycle. It turns out the the process of adjusting and calculating
// the duty cycle here and reading it back is lossy - the value will decay over time.
// Track it here so that if frequency is changed we can use this value to recalculate the
Expand Down Expand Up @@ -373,7 +373,7 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self,
}
}

uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) {
const pin_timer_t* t = self->timer;
if (t->is_tc) {
Tc* tc = tc_insts[t->index];
Expand Down Expand Up @@ -411,7 +411,7 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
}


void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self,
void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self,
uint32_t frequency) {
if (frequency == 0 || frequency > 6000000) {
mp_raise_ValueError(translate("Invalid PWM frequency"));
Expand Down Expand Up @@ -466,10 +466,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self,
#endif
}

common_hal_pulseio_pwmout_set_duty_cycle(self, self->duty_cycle);
common_hal_pwmio_pwmout_set_duty_cycle(self, self->duty_cycle);
}

uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) {
uint32_t system_clock = common_hal_mcu_processor_get_frequency();
const pin_timer_t* t = self->timer;
uint8_t divisor;
Expand All @@ -484,6 +484,6 @@ uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
return (system_clock / prescaler[divisor]) / (top + 1);
}

bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self) {
bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t* self) {
return self->variable_frequency;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H

#include "common-hal/microcontroller/Pin.h"

Expand All @@ -37,8 +37,8 @@ typedef struct {
const pin_timer_t* timer;
bool variable_frequency;
uint16_t duty_cycle;
} pulseio_pwmout_obj_t;
} pwmio_pwmout_obj_t;

void pwmout_reset(void);

#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
1 change: 1 addition & 0 deletions ports/atmel-samd/common-hal/pwmio/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// No pwmio module functions.
4 changes: 3 additions & 1 deletion ports/atmel-samd/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PulseIn.h"
#include "common-hal/pulseio/PulseOut.h"
#include "common-hal/pulseio/PWMOut.h"
#include "common-hal/pwmio/PWMOut.h"
#include "common-hal/ps2io/Ps2.h"
#include "common-hal/rtc/RTC.h"

Expand Down Expand Up @@ -335,6 +335,8 @@ void reset_port(void) {
#if CIRCUITPY_PULSEIO
pulsein_reset();
pulseout_reset();
#endif
#if CIRCUITPY_PWMIO
pwmout_reset();
#endif

Expand Down
2 changes: 1 addition & 1 deletion ports/cxd56/common-hal/pulseio/PulseOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static bool pulseout_timer_handler(unsigned int *next_interval_us, void *arg)
}

void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
const pulseio_pwmout_obj_t* carrier,
const pwmio_pwmout_obj_t* carrier,
const mcu_pin_obj_t* pin,
uint32_t frequency,
uint16_t duty_cycle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "py/runtime.h"

#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-bindings/pwmio/PWMOut.h"

typedef struct {
const char* devpath;
Expand All @@ -46,7 +46,7 @@ STATIC pwmout_dev_t pwmout_dev[] = {
{"/dev/pwm3", &pin_PWM3, -1, true}
};

pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency,
bool variable_frequency) {
self->number = -1;
Expand Down Expand Up @@ -85,8 +85,8 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
return PWMOUT_OK;
}

void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
if (common_hal_pulseio_pwmout_deinited(self)) {
void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
if (common_hal_pwmio_pwmout_deinited(self)) {
return;
}

Expand All @@ -98,43 +98,43 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
self->pin = NULL;
}

bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) {
bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) {
return pwmout_dev[self->number].fd < 0;
}

void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) {
void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uint16_t duty) {
self->info.duty = duty;

ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info));
}

uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t *self) {
uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) {
return self->info.duty;
}

void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t *self, uint32_t frequency) {
void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t frequency) {
self->info.frequency = frequency;

if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) {
mp_raise_ValueError(translate("Invalid PWM frequency"));
}
}

uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t *self) {
uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) {
return self->info.frequency;
}

bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self) {
bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) {
return self->variable_frequency;
}

void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
never_reset_pin_number(self->pin->number);

pwmout_dev[self->number].reset = false;
}

void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
pwmout_dev[self->number].reset = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H

#include <nuttx/timers/pwm.h>

Expand All @@ -39,10 +39,10 @@ typedef struct {
struct pwm_info_s info;
bool variable_frequency;
int8_t number;
} pulseio_pwmout_obj_t;
} pwmio_pwmout_obj_t;

void pwmout_reset(void);
void pwmout_start(uint8_t pwm_num);
void pwmout_stop(uint8_t pwm_num);

#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H
1 change: 1 addition & 0 deletions ports/cxd56/common-hal/pwmio/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// No pwmio module functions.
4 changes: 3 additions & 1 deletion ports/cxd56/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogIn.h"
#include "common-hal/pulseio/PulseOut.h"
#include "common-hal/pulseio/PWMOut.h"
#include "common-hal/pwmio/PWMOut.h"
#include "common-hal/busio/UART.h"

safe_mode_t port_init(void) {
Expand All @@ -69,6 +69,8 @@ void reset_port(void) {
#endif
#if CIRCUITPY_PULSEIO
pulseout_reset();
#endif
#if CIRCUITPY_PWMIO
pwmout_reset();
#endif
#if CIRCUITPY_BUSIO
Expand Down
4 changes: 2 additions & 2 deletions ports/esp32s2/common-hal/pulseio/PulseOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

#include "common-hal/pulseio/PulseOut.h"

#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-bindings/pwmio/PWMOut.h"
#include "py/runtime.h"

// Requires rmt.c void esp32s2_peripherals_reset_all(void) to reset

void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
const pulseio_pwmout_obj_t* carrier,
const pwmio_pwmout_obj_t* carrier,
const mcu_pin_obj_t* pin,
uint32_t frequency,
uint16_t duty_cycle) {
Expand Down
1 change: 0 additions & 1 deletion ports/esp32s2/common-hal/pulseio/PulseOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEOUT_H

#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PWMOut.h"
#include "driver/rmt.h"
#include "rmt.h"

Expand Down
Loading