Fix formatting.

This commit is contained in:
jgillick 2020-11-22 01:15:05 -08:00
parent 63b0bf9075
commit 0b858440b0

View File

@ -41,69 +41,63 @@ bool apa102_mosi_in_use;
#endif
#if defined(TFBGA216)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK};
GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK};
#elif defined(LQFP144)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG};
GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG};
#elif defined(LQFP100_f4) || (LQFP100_x7)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE};
GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE};
#elif defined(LQFP64)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD};
GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC, GPIOD};
#elif defined(UFQFPN48)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC};
GPIO_TypeDef * ports[] = {GPIOA, GPIOB, GPIOC};
#endif
#define GPIO_PORT_COUNT (MP_ARRAY_SIZE(ports))
STATIC uint16_t claimed_pins[GPIO_PORT_COUNT];
STATIC uint16_t __ALIGNED(4) never_reset_pins[GPIO_PORT_COUNT];
void reset_all_pins(void)
{
void reset_all_pins(void) {
// Reset claimed pins
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++)
{
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++) {
claimed_pins[i] = never_reset_pins[i];
}
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++)
{
for (uint8_t i = 0; i < GPIO_PORT_COUNT; i++) {
HAL_GPIO_DeInit(ports[i], ~never_reset_pins[i]);
}
#ifdef MICROPY_HW_NEOPIXEL
#ifdef MICROPY_HW_NEOPIXEL
neopixel_in_use = false;
#endif
#ifdef MICROPY_HW_APA102_MOSI
#endif
#ifdef MICROPY_HW_APA102_MOSI
apa102_sck_in_use = false;
apa102_mosi_in_use = false;
#endif
#endif
}
// Mark pin as free and return it to a quiescent state.
void reset_pin_number(uint8_t pin_port, uint8_t pin_number)
{
if (pin_number == NO_PIN)
{
void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
if ( pin_number == NO_PIN ) {
return;
}
if (pin_port == 0x0F)
{
if (pin_port == 0x0F) {
return;
}
// Clear claimed bit & reset
claimed_pins[pin_port] &= ~(1 << pin_number);
never_reset_pins[pin_port] &= ~(1 << pin_number);
HAL_GPIO_DeInit(ports[pin_port], 1 << pin_number);
claimed_pins[pin_port] &= ~(1<<pin_number);
never_reset_pins[pin_port] &= ~(1<<pin_number);
HAL_GPIO_DeInit(ports[pin_port], 1<<pin_number);
#ifdef MICROPY_HW_NEOPIXEL
if (pin_port == MICROPY_HW_NEOPIXEL->port && pin_number == MICROPY_HW_NEOPIXEL->number)
{
#ifdef MICROPY_HW_NEOPIXEL
if (pin_port == MICROPY_HW_NEOPIXEL->port && pin_number == MICROPY_HW_NEOPIXEL->number) {
neopixel_in_use = false;
rgb_led_status_init();
return;
}
#endif
#ifdef MICROPY_HW_APA102_MOSI
#endif
#ifdef MICROPY_HW_APA102_MOSI
if ((pin_port == MICROPY_HW_APA102_MOSI->port && pin_number == MICROPY_HW_APA102_MOSI->number) || (pin_port == MICROPY_HW_APA102_SCK->port && pin_number == MICROPY_HW_APA102_MOSI->number))
{
apa102_mosi_in_use = false;
@ -111,50 +105,42 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number)
rgb_led_status_init();
return;
}
#endif
#endif
}
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number)
{
if (pin_number == NO_PIN)
{
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
if ( pin_number == NO_PIN ) {
return;
}
never_reset_pins[pin_port] |= 1 << pin_number;
never_reset_pins[pin_port] |= 1<<pin_number;
// Make sure never reset pins are also always claimed
claimed_pins[pin_port] |= 1 << pin_number;
claimed_pins[pin_port] |= 1<<pin_number;
}
void common_hal_never_reset_pin(const mcu_pin_obj_t *pin)
{
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
never_reset_pin_number(pin->port, pin->number);
}
void common_hal_reset_pin(const mcu_pin_obj_t *pin)
{
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
reset_pin_number(pin->port, pin->number);
}
void claim_pin(uint8_t pin_port, uint8_t pin_number)
{
void claim_pin(uint8_t pin_port, uint8_t pin_number) {
// Set bit in claimed_pins bitmask.
claimed_pins[pin_port] |= 1 << pin_number;
claimed_pins[pin_port] |= 1<<pin_number;
}
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number)
{
return !(claimed_pins[pin_port] & 1 << pin_number);
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
return !(claimed_pins[pin_port] & 1<<pin_number);
}
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin)
{
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL)
{
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
return !neopixel_in_use;
}
#endif
#ifdef MICROPY_HW_APA102_MOSI
#endif
#ifdef MICROPY_HW_APA102_MOSI
if (pin == MICROPY_HW_APA102_MOSI)
{
return !apa102_mosi_in_use;
@ -163,36 +149,31 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin)
{
return !apa102_sck_in_use;
}
#endif
#endif
return pin_number_is_free(pin->port, pin->number);
}
GPIO_TypeDef *pin_port(uint8_t pin_port)
{
GPIO_TypeDef * pin_port(uint8_t pin_port) {
return ports[pin_port];
}
uint16_t pin_mask(uint8_t pin_number)
{
return 1 << pin_number;
uint16_t pin_mask(uint8_t pin_number) {
return 1<<pin_number;
}
uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin)
{
uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t* pin) {
return pin->port * 16 + pin->number;
}
void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin)
{
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
claim_pin(pin->port, pin->number);
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL)
{
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
neopixel_in_use = true;
}
#endif
#ifdef MICROPY_HW_APA102_MOSI
#endif
#ifdef MICROPY_HW_APA102_MOSI
if (pin == MICROPY_HW_APA102_MOSI)
{
apa102_mosi_in_use = true;
@ -201,10 +182,9 @@ void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin)
{
apa102_sck_in_use = true;
}
#endif
#endif
}
void common_hal_mcu_pin_reset_number(uint8_t pin_no)
{
void common_hal_mcu_pin_reset_number(uint8_t pin_no) {
reset_pin_number(pin_no / 16, pin_no % 16);
}