---
tags: 活動共筆
---
# 20211108 Intro to MicroPython (MP) - The porting guide #2


- **amebad_tool**
- toolchain
- **tools**: runs on desktop OS to reduce the size of the firmware
- **amebad_vendor**
- **ARCHIVE_LIB**: compiled source code has been placed here
- **linker_script**: script that illustrate how to allocate memory space during
- **sdk**: sdk header files (.h) for ameba RTL8722DM, note that all the source files (.c) will not be compiled.
:question: **Is linker_script written by Simon?**
taken out from SDK, modify a bit, put into PSRAM

the name is not necessary to follow the screenshot above
root folder
- main.c: initialisation MP
- pins.c: pins initialisation
- mpconfigport.h: MP macros
- Makefile: include MP's Makefile to compile MP & Port related codes
- mphal.c: realise basic hw control such as UART Delay (hal: Hardware Abstraction Layer)
:question: **Is RTL8720DN able to be ported with MP?**
size limitation, 512KB,
sol: build firmware code, macro on/off with what we need,
:question: **mpconfigport.h non-numerical macro?**

- init MP correctly
- init UART and config "mp_hal_stdout_tx/mp_hal_stdin_rx"
when there is `>>>` shown in the command prompt, which means the import of MP is successful

# how to import API to MicroPython


pointer ---> QSTR (can be controlled in REPL)
there is no class in C language
:question: ** why so many mappings?**
CPython vs Python, cause using c to release OOP

/// demo for accomdemy ////
STATIC my_obj_t gpio_irp_test (mp_obj_t self_in, mp_obj_t irq_mode){
pin_obj_t *self = self_in;
int _irq_mode = mp_obj_get_init(irq_mdoe);
gpio_irp_t gpio_btn;
gpio_init(&gpio_led, GPIO_LED_PIN);
gpio_dir(&gpio_led, PIN_OUTPUT);
gpio_mode(&gpio_led, PullNone);
gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler,(uint32_t)(&gpio_led));
gpio_irq_set(&gpio_btn, _irq_mode, 1);
gpio_irq_enable(&gpio_btn);
return mp_const_none;
}
STATIC MP_DEGINE_CONST_FN_OBJ_2(pin_irq_test_obj, gpio_irq_test);