Hi,
I'm writing a typeshed for the PyBoard and have hit a problem, I can't find where PinAF is defined. The documentation implies that it is in `pyb` but if I `dir(pyb)` on the REPL it doesn't show up!
Anyone know where it is?
Thanks for any help,
Howard.
Where is PinAF?
Re: Where is PinAF?
What's a typeshed?
You can't construct a PinAF directly, but there are instances of PinAF defined on pyb.Pin (and returned by the af_list() method on Pin).
https://docs.micropython.org/en/latest/ ... -functions
(This applies to both machine.Pin and pyb.Pin, they're actually the same type, unlike machine.I2C vs pyb.I2C which are different)
Re: Where is PinAF?
A typeshed or `.pyi` file is adding optional type hinting to Python in a seperate file, e.g. the typesheds for the standard Python library. Whilst a typeshed isn't useful for MicroPython itself, it is for IDEs like PyCharm (i.e. in this case for the MicroPython plugin).
The problem I have is that the REPL tells me that there are PinAF objects, as you say. EG `type(pyb.Pin.board.X3.af_list()[0])` gives `<class 'PinAF'>`. But I can't tell if `PinAF` is in `pyb`, i.e. `pyb.PinAF`, or somewhere else since you cannot extract module names from MicroPython.
Do you know its module?
I guess the fact that you can't instantiate the class makes this moot, but I might as well put it in the correct place. I can make the class either abstract or a Protocol to tell PyCharm that it can't be instantiated.
Thanks for any help.
Re: Where is PinAF?
The Pin and PinAF (for the pyboard) are both found in the pin.c file:
https://github.com/micropython/micropyt ... pin.c#L592
https://github.com/micropython/micropyt ... pin.c#L669
Currently there isn't anyway to construct a PinAF object from Python. They only exist as objects in the flash. The source files for creating the PinAF objects is generated, for example: in ports/stm32/build-PYBV11/pins_PYBV11.c. Each line with the AF macro is generating one PinAF object.
Here's a snippet from the pins_PYBV11.c file:
https://github.com/micropython/micropyt ... pin.c#L592
https://github.com/micropython/micropyt ... pin.c#L669
Currently there isn't anyway to construct a PinAF object from Python. They only exist as objects in the flash. The source files for creating the PinAF objects is generated, for example: in ports/stm32/build-PYBV11/pins_PYBV11.c. Each line with the AF macro is generating one PinAF object.
Here's a snippet from the pins_PYBV11.c file:
Code: Select all
const pin_af_obj_t pin_A0_af[] = {
AF( 1, TIM , 2, CH1 , TIM2 ), // TIM2_CH1
AF( 1, TIM , 2, ETR , TIM2 ), // TIM2_ETR
AF( 2, TIM , 5, CH1 , TIM5 ), // TIM5_CH1
AF( 3, TIM , 8, ETR , TIM8 ), // TIM8_ETR
#if defined(MICROPY_HW_UART2_TX)
AF( 7, USART , 2, CTS , USART2 ), // USART2_CTS
#endif
#if defined(MICROPY_HW_UART4_TX)
AF( 8, UART , 4, TX , UART4 ), // UART4_TX
#endif
//(11, ETH , 0, MII_CRS , ETH ), // ETH_MII_CRS
//(15, EVENTOUT, 0, , EVENTOUT), // EVENTOUT
};