Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Add a downgrade mechanism so GPIOs and Timers can be stored in arrays #66

Open
@D1plo1d

Description

@D1plo1d

This is a feature request to add a function similar to https://docs.rs/stm32f1xx-hal/0.7.0/stm32f1xx_hal/gpio/gpioa/struct.PA1.html#method.downgrade to allow users to create arrays of structs that include GPIO pins and Timers in their type on the stack / without needing to move those structs to the heap via alloc and Box.

For example this doesn't work at present due to the pins having different types (and therefore Rust assumes possibly different sizes):

let pin2 = pins.gpio2.into_push_pull_output();
let pin4 = pins.gpio4.into_push_pull_output();

let ws2812s = [ // <= error here because ws2812s doesn't contain structs of the same type
  ws2812_timer_delay::Ws2812::new(timer0, pin27),
  ws2812_timer_delay::Ws2812::new(timer1, pin27),
];

ws2812s.iter_mut().for_each(|ws| ws.write(data));

Currently this workaround might work but requires alloc to be enabled:

let pin2 = pins.gpio2.into_push_pull_output();
let pin4 = pins.gpio4.into_push_pull_output();

let ws2812s = [
  Box::new(ws2812_timer_delay::Ws2812::new(timer0, pin27)),
  Box::new(ws2812_timer_delay::Ws2812::new(timer1, pin27)),
];

ws2812s.iter_mut().for_each(|ws| ws.write(data));

However ideally with a downgrade function something like this could conceivably compile without any need for alloc:

let pin2 = pins.gpio2.into_push_pull_output().downgrade();
let pin4 = pins.gpio4.into_push_pull_output().downgrade();

let ws2812s = [ // <= both gpios and timers are downgraded to less specific types so the compiler is happy here
  ws2812_timer_delay::Ws2812::new(timer0.downgrade(), pin27),
  ws2812_timer_delay::Ws2812::new(timer1.downgrade(), pin27),
];

ws2812s.iter_mut().for_each(|ws| ws.write(data));

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions