Develop hardware-independent parts on PC-s

Crucial part of embedded programming is interaction with hardware. That is why all provided examples are hardware-specific. However, in embedded programs there are also hardware-independent parts Since developing programs on embedded system is harder than developement on PC-s hardware-independent parts should be developed on PC-s. Only when all parts work independently they should be integrated into final program.

Start from simplest hardware driver

Drivers for various devices should be developed independently starting from simplest possible driver. For example shift1.c used bit-banging to control shift register. That is simple and easy to get right. Then shift2.c transfers whole bytes to shift register -- this is incremental modification. Once this worked we could switch to use SPI hardware. In shift3.c we added initialization of SPI hardware and a polled transfer routine. Again, polled transfer is easy to get right. Concerning initialization, one can use debugger to read control registers of SPI hardware, to check that indeed all control bits are set correctly. Also, reading status register gives information about errors. Once polled driver works one can move towards interrupt driver. We do not provide example of interrupt driven SPI transfer, but first version of UART driver in ser1.c is a polling driver while the second one in ser2.c uses interrupts.

Integrate known-working routines into a program

Once driver routines are available we can use them to write bigger programs. For example, the first version of program handling Nokia5110 display, nokia_lcd.ino was developed in Energia environment and the main point was to collect constants and find out proper sequence of commands to control display. Once this was done the example after small modification nokia_lcd1.cpp could be used with libmaple. Also, we could extend functionality providing a mini font nokia_lcd2.cpp. This was combined with hardware SPI routines provided by libmaple to get much fater version using hardware SPI nokia_lcd3a.cpp. Finally combining this with DMA gave more efficient version nokia_lcd3b.cpp. Similarly, the FO lcd_i2c example combines I2C routine for FO from i2c1.c with libmaple file for handling character LCD display. More precisely, routines specific for libmable were removed from LCD driver and replaced by routine based on i2c1.c. And the main program is just a variation of libmaple example program for character LCD display via I2C.