I believe I could not fully understand the benefits of writing device drivers in embedded systems for some specific devices, such as GPIO, when there are alternative ways of doing the same job.
You can access the GPIOs via sysfs and device tree.
- Write a new device tree overlay and enable it
- Go to the /sys/class/gpio
- Export required pin and start using it (via simple shell calls or inside the c/c++ app)
Write your own driver.
- Code the real functionalities.
- Expose the driver to a node (like /dev/tty) in userspace.
- Write another c/c++ code to access the driver (also it can be accessed via simple shell calls)
- If you need any new functionalities, first change the driver then your code. (Why?)
Use directly /dev/mem;
- Include mman.h and use /dev/mem object to set or get the GPIO status.
- 1 -> is going to be deprecated and slow. (Ok, absolutely beneficial for fast prototyping)
- 2 -> How is that faster than 1? 1st one is also another GPIO driver, isn't it?
- 3 -> Isn't it best and fastest way?
I asked several questions above but here is my biggest question; why shouldn't I go straight with the 3rd solution?