42
42
uint32_t target_slice_frequencies [NUM_PWM_SLICES ];
43
43
uint32_t slice_variable_frequency ;
44
44
45
- #define CHANNELS_PER_SLICE 2
45
+ #define AB_CHANNELS_PER_SLICE 2
46
46
static uint32_t channel_use ;
47
47
static uint32_t never_reset_channel ;
48
48
@@ -58,11 +58,11 @@ static uint32_t never_reset_channel;
58
58
// So 65534 should be the maximum top value, and we'll set CC to be TOP+1 as appropriate.
59
59
#define MAX_TOP 65534
60
60
61
- static uint32_t _mask (uint8_t slice , uint8_t channel ) {
62
- return 1 << (slice * CHANNELS_PER_SLICE + channel );
61
+ static uint32_t _mask (uint8_t slice , uint8_t ab_channel ) {
62
+ return 1 << (slice * AB_CHANNELS_PER_SLICE + ab_channel );
63
63
}
64
64
65
- bool pwmio_claim_slice_channels (uint8_t slice ) {
65
+ bool pwmio_claim_slice_ab_channels (uint8_t slice ) {
66
66
uint32_t channel_use_mask_a = _mask (slice , 0 );
67
67
uint32_t channel_use_mask_b = _mask (slice , 1 );
68
68
@@ -78,37 +78,37 @@ bool pwmio_claim_slice_channels(uint8_t slice) {
78
78
return true;
79
79
}
80
80
81
- void pwmio_release_slice_channels (uint8_t slice ) {
81
+ void pwmio_release_slice_ab_channels (uint8_t slice ) {
82
82
uint32_t channel_mask = _mask (slice , 0 );
83
83
channel_use &= ~channel_mask ;
84
84
channel_mask = _mask (slice , 1 );
85
85
channel_use &= ~channel_mask ;
86
86
}
87
87
88
- void pwmout_never_reset (uint8_t slice , uint8_t channel ) {
89
- never_reset_channel |= _mask (slice , channel );
88
+ void pwmout_never_reset (uint8_t slice , uint8_t ab_channel ) {
89
+ never_reset_channel |= _mask (slice , ab_channel );
90
90
}
91
91
92
- void pwmout_reset_ok (uint8_t slice , uint8_t channel ) {
93
- never_reset_channel &= ~_mask (slice , channel );
92
+ void pwmout_reset_ok (uint8_t slice , uint8_t ab_channel ) {
93
+ never_reset_channel &= ~_mask (slice , ab_channel );
94
94
}
95
95
96
96
void common_hal_pwmio_pwmout_never_reset (pwmio_pwmout_obj_t * self ) {
97
- pwmout_never_reset (self -> slice , self -> channel );
97
+ pwmout_never_reset (self -> slice , self -> ab_channel );
98
98
99
99
never_reset_pin_number (self -> pin -> number );
100
100
}
101
101
102
102
void common_hal_pwmio_pwmout_reset_ok (pwmio_pwmout_obj_t * self ) {
103
- pwmout_reset_ok (self -> slice , self -> channel );
103
+ pwmout_reset_ok (self -> slice , self -> ab_channel );
104
104
}
105
105
106
106
void pwmout_reset (void ) {
107
107
// Reset all slices
108
108
for (size_t slice = 0 ; slice < NUM_PWM_SLICES ; slice ++ ) {
109
109
bool reset = true;
110
- for (size_t channel = 0 ; channel < CHANNELS_PER_SLICE ; channel ++ ) {
111
- uint32_t channel_use_mask = _mask (slice , channel );
110
+ for (size_t ab_channel = 0 ; ab_channel < AB_CHANNELS_PER_SLICE ; ab_channel ++ ) {
111
+ uint32_t channel_use_mask = _mask (slice , ab_channel );
112
112
if ((never_reset_channel & channel_use_mask ) != 0 ) {
113
113
reset = false;
114
114
continue ;
@@ -124,8 +124,8 @@ void pwmout_reset(void) {
124
124
}
125
125
}
126
126
127
- pwmout_result_t pwmout_allocate (uint8_t slice , uint8_t channel , bool variable_frequency , uint32_t frequency ) {
128
- uint32_t channel_use_mask = _mask (slice , channel );
127
+ pwmout_result_t pwmout_allocate (uint8_t slice , uint8_t ab_channel , bool variable_frequency , uint32_t frequency ) {
128
+ uint32_t channel_use_mask = _mask (slice , ab_channel );
129
129
130
130
// Check the channel first.
131
131
if ((channel_use & channel_use_mask ) != 0 ) {
@@ -171,15 +171,15 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
171
171
}
172
172
173
173
uint8_t slice = pwm_gpio_to_slice_num (pin -> number );
174
- uint8_t channel = pwm_gpio_to_channel (pin -> number );
174
+ uint8_t ab_channel = pwm_gpio_to_channel (pin -> number );
175
175
176
- int r = pwmout_allocate (slice , channel , variable_frequency , frequency );
176
+ int r = pwmout_allocate (slice , ab_channel , variable_frequency , frequency );
177
177
if (r != PWMOUT_OK ) {
178
178
return r ;
179
179
}
180
180
181
181
self -> slice = slice ;
182
- self -> channel = channel ;
182
+ self -> ab_channel = ab_channel ;
183
183
184
184
if (target_slice_frequencies [slice ] != frequency ) {
185
185
// Reset the counter and compare values.
@@ -202,11 +202,11 @@ bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) {
202
202
return self -> pin == NULL ;
203
203
}
204
204
205
- void pwmout_free (uint8_t slice , uint8_t channel ) {
206
- uint32_t channel_mask = _mask (slice , channel );
205
+ void pwmout_free (uint8_t slice , uint8_t ab_channel ) {
206
+ uint32_t channel_mask = _mask (slice , ab_channel );
207
207
channel_use &= ~channel_mask ;
208
208
never_reset_channel &= ~channel_mask ;
209
- uint32_t slice_mask = ((1 << CHANNELS_PER_SLICE ) - 1 ) << (slice * CHANNELS_PER_SLICE );
209
+ uint32_t slice_mask = ((1 << AB_CHANNELS_PER_SLICE ) - 1 ) << (slice * AB_CHANNELS_PER_SLICE );
210
210
if ((channel_use & slice_mask ) == 0 ) {
211
211
target_slice_frequencies [slice ] = 0 ;
212
212
slice_variable_frequency &= ~(1 << slice );
@@ -218,7 +218,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
218
218
if (common_hal_pwmio_pwmout_deinited (self )) {
219
219
return ;
220
220
}
221
- pwmout_free (self -> slice , self -> channel );
221
+ pwmout_free (self -> slice , self -> ab_channel );
222
222
reset_pin_number (self -> pin -> number );
223
223
self -> pin = NULL ;
224
224
}
@@ -235,13 +235,13 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uin
235
235
compare_count = ((uint32_t )duty * self -> top + MAX_TOP / 2 ) / MAX_TOP ;
236
236
}
237
237
// compare_count is the CC register value, which should be TOP+1 for 100% duty cycle.
238
- pwm_set_chan_level (self -> slice , self -> channel , compare_count );
238
+ pwm_set_chan_level (self -> slice , self -> ab_channel , compare_count );
239
239
// Wait for wrap so that we know our new cc value has been applied. Clear
240
240
// the internal interrupt and then wait for it to be set. Worst case, we
241
241
// wait a full cycle.
242
- pwm_hw -> intr = 1 << self -> channel ;
243
- while ((pwm_hw -> en & (1 << self -> channel )) != 0 &&
244
- (pwm_hw -> intr & (1 << self -> channel )) == 0 &&
242
+ pwm_hw -> intr = 1 << self -> slice ;
243
+ while ((pwm_hw -> en & (1 << self -> slice )) != 0 &&
244
+ (pwm_hw -> intr & (1 << self -> slice )) == 0 &&
245
245
!mp_hal_is_interrupted ()) {
246
246
}
247
247
}
0 commit comments