Code Portability From Device to Device
Source code utilizing MPLAB® Harmony libraries for one PIC32 device can be easily reused for another PIC32 device. Harmony is based on Microchip peripherals and designed around those peripherals. These abstracted libraries make the peripherals easier to use. So, regardless of which part you’re using, these libraries use the same (or very nearly the same) interface.
This code portability dramatically reduces the time it takes to migrate code from one device to another. This lowers NRE (non-recurring engineering) charges for code development and shortens time to market.
The way MPLAB® Harmony libraries provide portability is by providing a consistent, well defined and well documented set of interface functions that do not change from part to part as long as the same feature is supported by both parts.
The following graphic shows a section of the Harmony help file that describes and defines the Harmony timer peripheral library (PLIB). Notice the contents tree on the left describes the library’s abstraction model and provides sections on how to use the library and manage different timer configurations (synchronous, asynchronous, gated, and others). This is vital information that would be missing if MPLAB Harmony only provided a header file to document the library.
The “Library Interface” topic, shown on the right, provides a nice hyperlinked table that breaks down and lists all of the functions and data types (and other elements) that make up the interface to the timer peripheral library. This provides a handy programmer’s reference when you’re using a library and you just want a reminder of what functions it supports and what their parameters are.
This code is an example of what a simple “blinky light” demo might look like when using a peripheral library. Notice the clear and consistent naming convention. The inversion of verb and object may seem a little odd at first, but it groups the functions alphabetically and helps make the library easier to understand. Also, notice that you can easily tell what the program is doing because the function names describe what they do.
This code example is exactly the same as the previous example, but it was written for a different PIC32 device. Note the peripheral library function names stay the same.
The function definitions for these peripheral libraries may change slightly from part to part, but you don't have to worry about this. Just include Harmony's device specific library file in your project. This file frees you from dealing with the peripheral configuration details for a specific device. For example, you will not have to know the name of the Timer0 enable bit and which register it lives in.