So you can think of a module as a dictionary of stuff.
That stuff can be functions, constants, classes, or any other python object.
The module is pyb, which is defined in the modpyb.c file, and the module definition is here:
https://github.com/micropython/micropyt ... #L605-L609
If you do:
Code: Select all
>>> import pyb
>>> dir(pyb)
['__name__', 'bootloader', 'hard_reset', 'info', 'unique_id', 'freq', 'repl_info', 'wfi', 'disable_irq', 'enable_irq', 'stop', 'standby', 'main', 'repl_uart', 'usb_mode', 'hid_mouse', 'hid_keyboard', 'USB_VCP', 'USB_HID', 'have_cdc', 'hid', 'millis', 'elapsed_millis', 'micros', 'elapsed_micros', 'delay', 'udelay', 'sync', 'mount', 'Timer', 'rng', 'RTC', 'Pin', 'ExtInt', 'pwm', 'servo', 'Servo', 'Switch', 'SD', 'LED', 'I2C', 'SPI', 'UART', 'CAN', 'ADC', 'ADCAll', 'DAC', 'Accel', 'LCD']
then you'll see that each thing reported by dir comes from the globals table for the module:
https://github.com/micropython/micropyt ... #L513-L601
Now, one of the entries in pyb is UART:
https://github.com/micropython/micropyt ... pyb.c#L582
If you query the type of pyb.UART, you'll see that its a type, and if you dir on it you'll see the methods, constants, etc:
Code: Select all
>>> type(pyb.UART)
<class 'type'>
>>> dir(pyb.UART)
['init', 'deinit', 'any', 'read', 'readall', 'readline', 'readinto', 'write', 'writechar', 'readchar', 'sendbreak', 'RTS', 'CTS']
pyb_uart_type is defined in uart.c:
https://github.com/micropython/micropyt ... #L814-L823
The .make_new "slot" is what instantiates a new object. So when you do uart = pyb.UART(args) then the function registered against .make_new will be called.
The pyb_uart_make_new function:
https://github.com/micropython/micropyt ... #L523-L586 allocates a new pyb_uart_obj_t instance:
https://github.com/micropython/micropyt ... art.c#L569 or refers to a previously allocated one (a few lines later).
Only the methods registered against a type will have a self argument. So, for example, in python, you would do:
Code: Select all
>>> my_uart = pyb.UART(6, 115200)
>>> my_uart.writechar('x')
my_uart will be assigned the object that pyb_uart_make_new returned, and uart.writechar will call pyb_uart_writechar
https://github.com/micropython/micropyt ... #L656-L671 with self equal to the my_uart instance. Class members will take a self argument and whatever additional arguments are required. In Python, you would do something like this:
Code: Select all
class UART(object):
def writechar(self, char):
...do something...
so writechar takes 2 arguments, self, and char.
Modules can also contain plain old functions. So lets go back to modpyb.c and look at pyb.millis():
https://github.com/micropython/micropyt ... #L342-L354
pyb.millis is just a function, not a class method, so it gets no self argument, and it has no additional arguments, so its declared as a function with no arguments.
So, if what you're to do is to create an FSMC object with methods (so that you could instantiate more than one), then you want to create a type, not a module.
And then the self argument will be required.
Feel free to ask further questions or ask for clarification.