The difference between gpio_api and port_api HAL layers

Hi,

I have a question. There seem to be two similar looking HAL layers in Mbed-OS.


Why do we have two similar layers there and which is the one the target driver should implement?

Thanks,

I would like to post the answer I found from searching the code.

port HAL is using the pin with the groups of port while gpio HAL is using the pin in non-group of numeric pins.
For example, if there are 4 groups of pin ports then a port can be presented as (3, 5) while gpio pin should be just a number.

Also interesting part is where PortIn/PortOut/PortInOut can set the group of pins as an object. Instead of N gpio operations, you can just set 1 PortIn/Out operation.

That’s why there is port HAL because hardware driver can optimize the performance instead of port HAL SW implemented on top of gpio HAL layer.

Reference: https://os.mbed.com/handbook/PortIn

If I am wrong, please let me know.