Quite clever, I like this idea. This will allow us to simplify all peripheral structures for STM32s a bit.
> On May 14, 2018, at 2:32 PM, Fabio Utzig <[email protected]> wrote: > > I like the proposed changes! > > Fabio > > On Sun, May 13, 2018, at 1:02 AM, markus wrote: >> For the pwm driver I took a stab at a more holistic pin descriptor and >> wanted to solicit feedback and opinions. >> >> The core is in mcu.h: >> https://github.com/mlampert/mynewt-core/blob/feature/stm32-pwm-enabled/hw/mcu/stm/stm32f7xx/include/mcu/mcu.h >> >> Instead of using a struct data type I decided to go with bit >> encoding and macros, for the sole reason of API compatibility. A pin >> descriptor with an AF assignment can be passed to any API that accepts >> a pin (as long as the type is at least a uint16_t). >> >> For instance, it allows us to fold the functionality of >> hal_gpio_init_af into hal_gpio_init_in and hal_gpio_init_out and >> eliminate the stm specific api additions. >> >> Assuming the API allows a 32-bit pin type the encoding can be expanded >> to pin speed, strength, logic standard (although I haven't seen that in >> any of the ARMs - yet).... >> >> The other advantage of a bit encoding is that the entire pin descriptor >> can be defined in a single constant: >> >> /* AF=2 of PB7 */ >> #define PWM_PIN 0x2017 >> And if the GPIO pin is already defined: >> https://github.com/mlampert/mynewt-core/blob/feature/stm32-pwm-enabled/apps/pwm_test/src/main.c#L27 >> >> Internal use currently looks something like this: >> https://github.com/mlampert/mynewt-core/blob/feature/stm32-pwm-enabled/hw/drivers/pwm/pwm_stm32/src/pwm_stm32.c#L289 >> >> with the (stm) hal_gpio refactoring mentioned above that line would >> simple become: >> if (hal_gpio_init_out(cfg->pin, 0)) { >> >> I've only implemented this for the stm32f7 in order to reduce the >> refactoring effort if we want to go a different direction. >> >> Thoughts? Comments? ...
