Skip to content

Commit ad7cd03

Browse files
author
microbuilder
committed
Added 'mp_raise_NotImplementedError(NULL)'
1 parent b9e229f commit ad7cd03

File tree

1 file changed

+1
-145
lines changed

1 file changed

+1
-145
lines changed

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

+1-145
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void pulseout_reset() {
4646
}
4747

4848
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, const pulseio_pwmout_obj_t* carrier) {
49-
49+
mp_raise_NotImplementedError(NULL);
5050
}
5151

5252
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self) {
@@ -60,147 +60,3 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
6060
void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) {
6161

6262
}
63-
64-
#if 0
65-
// This timer is shared amongst all PulseOut objects under the assumption that
66-
// the code is single threaded. Its stored in MICROPY_PORT_ROOT_POINTERS so it
67-
// doesn't get garbage collected.
68-
static uint8_t refcount = 0;
69-
70-
static __IO PORT_PINCFG_Type *active_pincfg = NULL;
71-
static uint16_t *pulse_buffer = NULL;
72-
static volatile uint16_t pulse_index = 0;
73-
static uint16_t pulse_length;
74-
static volatile uint32_t current_compare = 0;
75-
76-
static void turn_on(__IO PORT_PINCFG_Type * pincfg) {
77-
pincfg->reg = PORT_PINCFG_PMUXEN;
78-
}
79-
80-
static void turn_off(__IO PORT_PINCFG_Type * pincfg) {
81-
pincfg->reg = PORT_PINCFG_RESETVALUE;
82-
}
83-
84-
void pulse_finish(struct tc_module *const module) {
85-
pulse_index++;
86-
87-
if (active_pincfg == NULL) {
88-
return;
89-
}
90-
// Always turn it off.
91-
turn_off(active_pincfg);
92-
if (pulse_index >= pulse_length) {
93-
return;
94-
}
95-
current_compare = (current_compare + pulse_buffer[pulse_index] * 3 / 4) & 0xffff;
96-
tc_set_compare_value(MP_STATE_VM(pulseout_tc_instance), TC_COMPARE_CAPTURE_CHANNEL_0, current_compare);
97-
if (pulse_index % 2 == 0) {
98-
turn_on(active_pincfg);
99-
}
100-
}
101-
102-
void pulseout_reset() {
103-
refcount = 0;
104-
MP_STATE_VM(pulseout_tc_instance) = NULL;
105-
active_pincfg = NULL;
106-
}
107-
108-
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
109-
const pulseio_pwmout_obj_t* carrier) {
110-
if (refcount == 0) {
111-
// Find a spare timer.
112-
Tc *t = NULL;
113-
Tc *tcs[TC_INST_NUM] = TC_INSTS;
114-
for (uint8_t i = TC_INST_NUM; i > 0; i--) {
115-
if (tcs[i - 1]->COUNT16.CTRLA.bit.ENABLE == 0) {
116-
t = tcs[i - 1];
117-
break;
118-
}
119-
}
120-
if (t == NULL) {
121-
mp_raise_RuntimeError("All timers in use");
122-
}
123-
MP_STATE_VM(pulseout_tc_instance) = gc_alloc(sizeof(struct tc_module), false);
124-
if (t == NULL) {
125-
mp_raise_msg(&mp_type_MemoryError, "");
126-
}
127-
128-
struct tc_config config_tc;
129-
tc_get_config_defaults(&config_tc);
130-
131-
config_tc.counter_size = TC_COUNTER_SIZE_16BIT;
132-
config_tc.clock_prescaler = TC_CTRLA_PRESCALER_DIV64;
133-
config_tc.wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
134-
135-
tc_init(MP_STATE_VM(pulseout_tc_instance), t, &config_tc);
136-
tc_register_callback(MP_STATE_VM(pulseout_tc_instance), pulse_finish, TC_CALLBACK_CC_CHANNEL0);
137-
tc_enable(MP_STATE_VM(pulseout_tc_instance));
138-
tc_stop_counter(MP_STATE_VM(pulseout_tc_instance));
139-
}
140-
refcount++;
141-
142-
self->pin = carrier->pin->pin;
143-
144-
PortGroup *const port_base = port_get_group_from_gpio_pin(self->pin);
145-
self->pincfg = &port_base->PINCFG[self->pin % 32];
146-
147-
// Set the port to output a zero.
148-
port_base->OUTCLR.reg = 1 << (self->pin % 32);
149-
port_base->DIRSET.reg = 1 << (self->pin % 32);
150-
151-
// Turn off the pinmux which should connect the port output.
152-
turn_off(self->pincfg);
153-
}
154-
155-
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self) {
156-
return self->pin == NO_PIN;
157-
}
158-
159-
void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
160-
if (common_hal_pulseio_pulseout_deinited(self)) {
161-
return;
162-
}
163-
PortGroup *const port_base = port_get_group_from_gpio_pin(self->pin);
164-
port_base->DIRCLR.reg = 1 << (self->pin % 32);
165-
166-
turn_on(self->pincfg);
167-
168-
refcount--;
169-
if (refcount == 0) {
170-
tc_reset(MP_STATE_VM(pulseout_tc_instance));
171-
gc_free(MP_STATE_VM(pulseout_tc_instance));
172-
MP_STATE_VM(pulseout_tc_instance) = NULL;
173-
}
174-
self->pin = NO_PIN;
175-
}
176-
177-
void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) {
178-
if (active_pincfg != NULL) {
179-
mp_raise_RuntimeError("Another send is already active");
180-
}
181-
active_pincfg = self->pincfg;
182-
pulse_buffer = pulses;
183-
pulse_index = 0;
184-
pulse_length = length;
185-
186-
current_compare = pulses[0] * 3 / 4;
187-
tc_set_compare_value(MP_STATE_VM(pulseout_tc_instance), TC_COMPARE_CAPTURE_CHANNEL_0, current_compare);
188-
189-
tc_enable_callback(MP_STATE_VM(pulseout_tc_instance), TC_CALLBACK_CC_CHANNEL0);
190-
turn_on(active_pincfg);
191-
tc_start_counter(MP_STATE_VM(pulseout_tc_instance));
192-
193-
while(pulse_index < length) {
194-
// Do other things while we wait. The interrupts will handle sending the
195-
// signal.
196-
#ifdef MICROPY_VM_HOOK_LOOP
197-
MICROPY_VM_HOOK_LOOP
198-
#endif
199-
}
200-
201-
tc_stop_counter(MP_STATE_VM(pulseout_tc_instance));
202-
tc_disable_callback(MP_STATE_VM(pulseout_tc_instance), TC_CALLBACK_CC_CHANNEL0);
203-
active_pincfg = NULL;
204-
}
205-
#endif
206-

0 commit comments

Comments
 (0)