My task for the week was to write a GPIO driver that is compatible to Arduino using C++ language. Although I have learnt the basics ways of coding in C++, I was asked to go through a C++ tutorial again, which indeed helped me quite a lot when writing the GPIO driver. Basically, this task can be separated into two main parts. The first one was to implement 3 simple functions (setGPIO, getGPIO and cfgGPIO), where I had to use pointers to read from and write to the DATA and CONTROL registers of the GPIO accordingly. Implementing this task has enabled me to learn how to use a structure that is inherited by a class, how to read the assembly codes to check if my codes were working correctly or not and how to write codes in such a way that efficiency is something that I should consider, instead of just focusing on achieving the functionalities. Later, I worked on how to make the class to be compatible to Arduino by including 3 other functions (pinMode, digitalWrite and digitalRead). This part was slightly more challenging as I had to deal with a single bit instead of a whole set of 32 bits and this was where bit-masking came to be useful. It enabled me to write to a particular bit of a specific register by AND-ing or OR-ing the 32 bits with a correct mask. A mistake that I have made was shifting a 0 leftwards, which was quite a stupid act as it would return me a 0 anyhow. So, instead of shifting a 0, I could shift a 1 and then invert the result, which is called an inverted mask. Another useful codes that I have learnt was to use the ‘==’ (a Boolean expression) so that it will return me either a TRUE  or a FALSE (1 or 0).

Writing a GPIO driver is not a particularly difficult task, yet, understanding what a GPIO does is way more important, especially for someone like me, who has previously no background knowledge of this device. After knowing what it is and how it works, coding will be fairly easy and could be done in a short time. Thanks to my supervisor for being patient enough to explain everything to me and answer all the doubts that I had. My next task will be writing a MSPI driver and I hope that I could finish it in the week, like what I did for the GPIO driver.