8000 cc3200: Code clean-up on pybpin. · micropython/micropython@7c1c9af · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c1c9af

Browse files

Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@
9292
/******************************************************************************
9393
DECLARE PRIVATE FUNCTIONS
9494
******************************************************************************/
95+
STATIC void pin_obj_configure (const pin_obj_t *self);
96+
STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx);
97+
STATIC void pin_extint_enable (mp_obj_t self_in);
98+
STATIC void pin_extint_disable (mp_obj_t self_in);
99+
STATIC void pin_verify_af (uint af);
100+
STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority);
95101
STATIC void GPIOA0IntHandler (void);
96102
STATIC void GPIOA1IntHandler (void);
97103
STATIC void GPIOA2IntHandler (void);
98104
STATIC void GPIOA3IntHandler (void);
99105
STATIC void EXTI_Handler(uint port);
100-
STATIC void pin_obj_configure (const pin_obj_t *self);
101-
STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx);
102-
STATIC void pin_extint_enable (mp_obj_t self_in);
103-
STATIC void pin_extint_disable (mp_obj_t self_in);
104106

105107
/******************************************************************************
106108
DEFINE CONSTANTS
@@ -159,12 +161,6 @@ pin_obj_t *pin_find(mp_obj_t user_obj) {
159161
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
160162
}
161163

162-
void pin_verify_af (uint af) {
163-
if (af > PIN_MODE_15) {
164-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
165-
}
166-
}
167-
168164
void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
169165
// configure the pin in analog mode
170166
self->af = af, self->mode = mode, self->type = type, self->strength = strength;
@@ -175,37 +171,6 @@ void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength)
175171
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
176172
}
177173

178-
void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) {
179-
void *handler;
180-
uint32_t intnum;
181-
182-
// configure the interrupt type
183-
MAP_GPIOIntTypeSet(self->port, self->bit, intmode);
184-
switch (self->port) {
185-
case GPIOA0_BASE:
186-
handler = GPIOA0IntHandler;
187-
intnum = INT_GPIOA0;
188-
break;
189-
case GPIOA1_BASE:
190-
handler = GPIOA1IntHandler;
191-
intnum = INT_GPIOA1;
192-
break;
193-
case GPIOA2_BASE:
194-
handler = GPIOA2IntHandler;
195-
intnum = INT_GPIOA2;
196-
break;
197-
case GPIOA3_BASE:
198-
default:
199-
handler = GPIOA3IntHandler;
200-
intnum = INT_GPIOA3;
201-
break;
202-
}
203-
MAP_GPIOIntRegister(self->port, handler);
204-
// set the interrupt to the lowest priority, to make sure that
205-
// no other ISRs will be preemted by this one
206-
MAP_IntPrioritySet(intnum, priority);
207-
}
208-
209174
/******************************************************************************
210175
DEFINE PRIVATE FUNCTIONS
211176
******************************************************************************/
@@ -326,6 +291,77 @@ STATIC void pin_extint_disable (mp_obj_t self_in) {
326291
MAP_GPIOIntDisable(self->port, self->bit);
327292
}
328293

294+
STATIC void pin_verify_af (uint af) {
295+
if (af > PIN_MODE_15) {
296+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
297+
}
298+
}
299+
300+
STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) {
301+
void *handler;
302+
uint32_t intnum;
303+
304+
// configure the interrupt type
305+
MAP_GPIOIntTypeSet(self->port, self->bit, intmode);
306+
switch (self->port) {
307+
case GPIOA0_BASE:
308+
handler = GPIOA0IntHandler;
309+
intnum = INT_GPIOA0;
310+
break;
311+
case GPIOA1_BASE:
312+
handler = GPIOA1IntHandler;
313+
intnum = INT_GPIOA1;
314+
break;
315+
case GPIOA2_BASE:
316+
handler = GPIOA2IntHandler;
317+
intnum = INT_GPIOA2;
318+
break;
319+
case GPIOA3_BASE:
320+
default:
321+
handler = GPIOA3IntHandler;
322+
intnum = INT_GPIOA3;
323+
break;
324+
}
325+
MAP_GPIOIntRegister(self->port, handler);
326+
// set the interrupt to the lowest priority, to make sure that
327+
// no other ISRs will be preemted by this one
328+
MAP_IntPrioritySet(intnum, priority);
329+
}
330+
331+
STATIC void GPIOA0IntHandler (void) {
332+
EXTI_Handler(GPIOA0_BASE);
333+
}
334+
335+
STATIC void GPIOA1IntHandler (void) {
336+
EXTI_Handler(GPIOA1_BASE);
337+
}
338+
339+
STATIC void GPIOA2IntHandler (void) {
340+
EXTI_Handler(GPIOA2_BASE);
341+
}
342+
343+
STATIC void GPIOA3IntHandler (void) {
344+
EXTI_Handler(GPIOA3_BASE);
345+
}
346+
347+
// common interrupt handler
348+
STATIC void EXTI_Handler(uint port) {
349+
uint32_t bits = MAP_GPIOIntStatus(port, true);
350+
MAP_GPIOIntClear(port, bits);
351+
352+
// might be that we have more than one Pin interrupt pending
353+
// therefore we must loop through all of the 8 possible bits
354+
for (int i = 0; i < 8; i++) {
355+
uint32_t bit = (1 << i);
356+
if (bit & bits) {
357+
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
358+
mp_obj_t _callback = mpcallback_find(self);
359+
mpcallback_handler(_callback);
360+
}
361+
}
362+
}
363+
364+
329365
/******************************************************************************/
330366
// Micro Python bindings
331367

@@ -747,36 +783,3 @@ STATIC const mp_cb_methods_t pin_cb_methods = {
747783
.disable = pin_extint_disable,
748784
};
749785

750-
STATIC void GPIOA0IntHandler (void) {
751-
EXTI_Handler(GPIOA0_BASE);
752-
}
753-
754-
STATIC void GPIOA1IntHandler (void) {
755-
EXTI_Handler(GPIOA1_BASE);
756-
}
757-
758-
STATIC void GPIOA2IntHandler (void) {
759-
EXTI_Handler(GPIOA2_BASE);
760-
}
761-
762-
STATIC void GPIOA3IntHandler (void) {
763-
EXTI_Handler(GPIOA3_BASE);
764-
}
765-
766-
// common interrupt handler
767-
STATIC void EXTI_Handler(uint port) {
768-
uint32_t bits = MAP_GPIOIntStatus(port, true);
769-
MAP_GPIOIntClear(port, bits);
770-
771-
// might be that we have more than one Pin interrupt pending
772-
// therefore we must loop through all of the 8 possible bits
773-
for (int i = 0; i < 8; i++) {
774-
uint32_t bit = (1 << i);
775-
if (bit & bits) {
776-
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
777-
mp_obj_t _callback = mpcallback_find(self);
778-
mpcallback_handler(_callback);
779-
}
780-
}
781-
}
782-
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ extern const mp_obj_type_t pin_cpu_pins_obj_type;
6767
extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
6868

6969
void pin_init0(void);
70-
void pin_verify_af (uint af);
7170
void pin_config(pin_obj_t *self, uint af, uint mode, uint type, uint strength);
72-
void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority);
7371
pin_obj_t *pin_find(mp_obj_t user_obj);
7472
pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
7573
pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit);
76-
uint32_t pin_get_mode(const pin_obj_t *self);
77-
uint32_t pin_get_type(const pin_obj_t *self);
78-
uint32_t pin_get_strenght(const pin_obj_t *self);
7974

8075
#endif // PYBPIN_H_