Skip to content

Commit 2529c0a

Browse files
authored
Merge pull request #3299 from tannewt/add_pwmio
Split pulseio.PWMOut into pwmio
2 parents 5b1a1c7 + 2b470b1 commit 2529c0a

File tree

50 files changed

+425
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+425
-287
lines changed

ports/atmel-samd/boards/pycubed/board.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "shared-bindings/nvm/ByteArray.h"
3333
#include "common-hal/microcontroller/Pin.h"
3434
#include "hal/include/hal_gpio.h"
35-
#include "shared-bindings/pulseio/PWMOut.h"
35+
#include "shared-bindings/pwmio/PWMOut.h"
3636

3737
nvm_bytearray_obj_t bootcnt = {
3838
.base = {
@@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = {
4444

4545

4646
void board_init(void) {
47-
pulseio_pwmout_obj_t pwm;
48-
common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
49-
common_hal_pulseio_pwmout_never_reset(&pwm);
47+
pwmio_pwmout_obj_t pwm;
48+
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
49+
common_hal_pwmio_pwmout_never_reset(&pwm);
5050
}
5151

5252
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pycubed_mram/board.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "shared-bindings/nvm/ByteArray.h"
3333
#include "common-hal/microcontroller/Pin.h"
3434
#include "hal/include/hal_gpio.h"
35-
#include "shared-bindings/pulseio/PWMOut.h"
35+
#include "shared-bindings/pwmio/PWMOut.h"
3636

3737
nvm_bytearray_obj_t bootcnt = {
3838
.base = {
@@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = {
4444

4545

4646
void board_init(void) {
47-
pulseio_pwmout_obj_t pwm;
48-
common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
49-
common_hal_pulseio_pwmout_never_reset(&pwm);
47+
pwmio_pwmout_obj_t pwm;
48+
common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false);
49+
common_hal_pwmio_pwmout_never_reset(&pwm);
5050
}
5151

5252
bool board_requests_safe_mode(void) {

ports/atmel-samd/common-hal/pulseio/PulseOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void pulseout_reset() {
9696
}
9797

9898
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
99-
const pulseio_pwmout_obj_t* carrier,
99+
const pwmio_pwmout_obj_t* carrier,
100100
const mcu_pin_obj_t* pin,
101101
uint32_t frequency,
102102
uint16_t duty_cycle) {

ports/atmel-samd/common-hal/pulseio/PWMOut.c renamed to ports/atmel-samd/common-hal/pwmio/PWMOut.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <stdint.h>
2929

3030
#include "py/runtime.h"
31-
#include "common-hal/pulseio/PWMOut.h"
32-
#include "shared-bindings/pulseio/PWMOut.h"
31+
#include "common-hal/pwmio/PWMOut.h"
32+
#include "shared-bindings/pwmio/PWMOut.h"
3333
#include "shared-bindings/microcontroller/Processor.h"
3434
#include "timer_handler.h"
3535

@@ -78,13 +78,13 @@ void timer_reset_ok(int index, bool is_tc) {
7878
}
7979

8080

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

8484
never_reset_pin_number(self->pin->number);
8585
}
8686

87-
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
87+
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
8888
timer_reset_ok(self->timer->index, self->timer->is_tc);
8989
}
9090

@@ -137,7 +137,7 @@ bool channel_ok(const pin_timer_t* t) {
137137
t->is_tc;
138138
}
139139

140-
pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
140+
pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
141141
const mcu_pin_obj_t* pin,
142142
uint16_t duty,
143143
uint32_t frequency,
@@ -296,16 +296,16 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
296296

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

299-
common_hal_pulseio_pwmout_set_duty_cycle(self, duty);
299+
common_hal_pwmio_pwmout_set_duty_cycle(self, duty);
300300
return PWMOUT_OK;
301301
}
302302

303-
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
303+
bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) {
304304
return self->pin == NULL;
305305
}
306306

307-
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
308-
if (common_hal_pulseio_pwmout_deinited(self)) {
307+
void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
308+
if (common_hal_pwmio_pwmout_deinited(self)) {
309309
return;
310310
}
311311
const pin_timer_t* t = self->timer;
@@ -331,7 +331,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
331331
self->pin = NULL;
332332
}
333333

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

376-
uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
376+
uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) {
377377
const pin_timer_t* t = self->timer;
378378
if (t->is_tc) {
379379
Tc* tc = tc_insts[t->index];
@@ -411,7 +411,7 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
411411
}
412412

413413

414-
void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self,
414+
void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self,
415415
uint32_t frequency) {
416416
if (frequency == 0 || frequency > 6000000) {
417417
mp_raise_ValueError(translate("Invalid PWM frequency"));
@@ -466,10 +466,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self,
466466
#endif
467467
}
468468

469-
common_hal_pulseio_pwmout_set_duty_cycle(self, self->duty_cycle);
469+
common_hal_pwmio_pwmout_set_duty_cycle(self, self->duty_cycle);
470470
}
471471

472-
uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
472+
uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) {
473473
uint32_t system_clock = common_hal_mcu_processor_get_frequency();
474474
const pin_timer_t* t = self->timer;
475475
uint8_t divisor;
@@ -484,6 +484,6 @@ uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
484484
return (system_clock / prescaler[divisor]) / (top + 1);
485485
}
486486

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

ports/atmel-samd/common-hal/pulseio/PWMOut.h renamed to ports/atmel-samd/common-hal/pwmio/PWMOut.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
28-
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
27+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
28+
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
2929

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

@@ -37,8 +37,8 @@ typedef struct {
3737
const pin_timer_t* timer;
3838
bool variable_frequency;
3939
uint16_t duty_cycle;
40-
} pulseio_pwmout_obj_t;
40+
} pwmio_pwmout_obj_t;
4141

4242
void pwmout_reset(void);
4343

44-
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
44+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// No pwmio module functions.

ports/atmel-samd/supervisor/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include "common-hal/microcontroller/Pin.h"
6060
#include "common-hal/pulseio/PulseIn.h"
6161
#include "common-hal/pulseio/PulseOut.h"
62-
#include "common-hal/pulseio/PWMOut.h"
62+
#include "common-hal/pwmio/PWMOut.h"
6363
#include "common-hal/ps2io/Ps2.h"
6464
#include "common-hal/rtc/RTC.h"
6565

@@ -335,6 +335,8 @@ void reset_port(void) {
335335
#if CIRCUITPY_PULSEIO
336336
pulsein_reset();
337337
pulseout_reset();
338+
#endif
339+
#if CIRCUITPY_PWMIO
338340
pwmout_reset();
339341
#endif
340342

ports/cxd56/common-hal/pulseio/PulseOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static bool pulseout_timer_handler(unsigned int *next_interval_us, void *arg)
5959
}
6060

6161
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
62-
const pulseio_pwmout_obj_t* carrier,
62+
const pwmio_pwmout_obj_t* carrier,
6363
const mcu_pin_obj_t* pin,
6464
uint32_t frequency,
6565
uint16_t duty_cycle) {

ports/cxd56/common-hal/pulseio/PWMOut.c renamed to ports/cxd56/common-hal/pwmio/PWMOut.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include "py/runtime.h"
3232

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

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

49-
pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
49+
pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
5050
const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency,
5151
bool variable_frequency) {
5252
self->number = -1;
@@ -85,8 +85,8 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
8585
return PWMOUT_OK;
8686
}
8787

88-
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
89-
if (common_hal_pulseio_pwmout_deinited(self)) {
88+
void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
89+
if (common_hal_pwmio_pwmout_deinited(self)) {
9090
return;
9191
}
9292

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

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

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

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

111-
uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t *self) {
111+
uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) {
112112
return self->info.duty;
113113
}
114114

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

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

123-
uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t *self) {
123+
uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) {
124124
return self->info.frequency;
125125
}
126126

127-
bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self) {
127+
bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) {
128128
return self->variable_frequency;
129129
}
130130

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

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

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

ports/cxd56/common-hal/pulseio/PWMOut.h renamed to ports/cxd56/common-hal/pwmio/PWMOut.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
28-
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
27+
#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H
28+
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H
2929

3030
#include <nuttx/timers/pwm.h>
3131

@@ -39,10 +39,10 @@ typedef struct {
3939
struct pwm_info_s info;
4040
bool variable_frequency;
4141
int8_t number;
42-
} pulseio_pwmout_obj_t;
42+
} pwmio_pwmout_obj_t;
4343

4444
void pwmout_reset(void);
4545
void pwmout_start(uint8_t pwm_num);
4646
void pwmout_stop(uint8_t pwm_num);
4747

48-
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H
48+
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H

0 commit comments

Comments
 (0)