API: DriverLIB

A device driver is a computer program that allows communication between hardware devices by using a software interface. A device driver is a specific form of API that hides the details of the hardware from a higher-level software.

For example, consider a drawing application that likes to use the input from a stylus to draw on the display. In a typical design, this application talks to the device driver rather than the stylus itself. The driver for the stylus gets the necessary information from the hardware and passes that to the drawing application. Almost all peripherals on a computer interact with the operating system or other applications through device drivers. These include a hard drive, speaker, mouse, stylus, etc. 

(Learn more here: https://en.wikipedia.org/wiki/Device_driver)

In our course, we are interested in the interactions between the CPU and its peripherals on MSP432 chip. Since there is a long list of peripherals on MSP432, there are many device drivers to support them. All these device drivers are put together in a package that is called DriverLib.

The DriverLib, short for driver library, is a library of functions provided by Texas Instruments to hide away the cumbersome interactions with memory-mapped registers of the peripherals. The DriverLib manual even states DriverLib is "meant to provide a "software" layer to the programmer to facilitate a higher level of programming compared to direct register accesses." 

The biggest advantage of using DriverLib is that it consolidates code into a simpler, easier-to-understand form. The library contains a plethora of useful functions and macros to facilitate readability so that a programmer can easily tell what is going on at a glance. For example, suppose we wanted to configure Port 1, Pin 1 (button S1 on the Launchpad) as an input. Traditionally, we would have to go through each of the GPIO registers and configure them appropriately.

#define BIT1 1 << 1


P1DIR &= ~BIT1; // set Bit 1 to 0 -- input

P1REN |= BIT1; // set resistor enable to 1

P1OUT |= BIT1; // set to 1 -- pull-up resistor

With the help of comments, we can decipher what’s happening here. Using DriverLib, however, simplifies this process.

#include <ti/devices/msp432p4xx/driverlib/driverlib.h>


GPIO_setAsInputPinWithPullUpResistor (GPIO_PORT_P1, GPIO_PIN1);

Not only does the DriverLib function save us lines of code, but the function's name tells the programmer what it does at a glance, without having to worry about the details. There are many functions in the library that you may find useful, so explore the library to your heart's content! You can get easy access to some of the header files containing DriverLib functions by using Ctrl + click on the #include statement, as well as on other DriverLib functions you may encounter in sample code.