Take an Arduino,
you can use different hardware devices by buying an Arduino shield, stick it on top.
And then, you call in library functions, right?
But in order to use a hardware device in an Arduino, you have to write code.
You as a programmer have to write a program that invokes certain library
functions and uses the hardware device, okay?
So, you can do it, but you have to write code to do it.
Where with an operating system, you're allowed to use these
different hardware devices to plug in, and you don't have to write code to do it.
That's really the difference.
You don't have to write code.
Now if you're comfortable writing code, as I am, then I can write some code and
I don't need that.
But most users don't want to write code for every little thing they want to do.
They want to just be able to plug in a device, and use that device.
And so operating systems allow that, so
this picture here is trying to give you a bit of an idea
about how an operating system, let's say Linux, accomplishes that.
Specifically Linux, but other operating system's are similar.
So, at the top you got a user application, right up there.
So that user application, just some program you wrote, or
some program you bought.
Maybe you bought some application and you're running that, right?
So, that's the program.
Now, say that program wants to use a hardware device.
And by hardware device, maybe I'm talking about a webcam I plugged into USB, right?
So, that program wants to use that webcam.
So, what does it do?
What it does is it accesses a file.
Now that's the next level down.
See it says slash dev slash XXX, that slash notation,
that's the directory notation.
Path notation, right?
So slash dev.
Dev is short for device.
If you look in a Linux box under slash dev, you see a bunch of sub-directories,
a bunch of files and XXX is one them.
It's not one of them, but xx is just a generic term for a file.
And you got a file in there for every device that's connected to your machine.
So, if you've got a web cam plugged into USB,
there will be some file in that slash dev directory just devoted to that web cam.
Okay.
So that file is associated with the hardware device that you plugged in.
Then, from the user point of view, from the user application or user point of
view, all you need to, say you wanna read data from the webcam, you read the file.
You read the file context.
You read data at the file content.
And that data would be the image data, for instance, from the video And
if was another type of device, say it was a disc drive or something like that or
whatever it was, say you want to write to the disc drive.
Then, if you want to write to it, you write to the file and
that will go into the drive, okay?
So what Linux and a lot of operating systems do is they say look let's,
they give you this uniform interface to all these devices.
They say look, all these devices, how you access a disc drive, and a web cam, and
a microphone is all different But a user doesn't want to see that,
that's way too complicated.
So they say look we're just going to give you a set of files.
You write to the file and read from the file and
that allows you to access every device in the same way.
I want to read from a microphone I want to see what the microphone is hearing.
I read from the appropriate file.
If I want to write to a drive I write to the appropriate file.
So it gives you this nice easy interface.
To access all your hardware devices.
So, there's a file and underneath that, or behind that,
inside the operating system, there's a device driver which I've highlighted here.
And that's a bunch of code.
And what the device driver does is it translates these file accesses into actual
hardware device accesses So that's where the real rubber hits the road.
If you, say it's a disk drive.
You write to the disk drive by writing to a file, so then the device driver has to
say, look, they wanna put this data into this disk drive, I'm gonna have to spin
this disk drive and move the head this way and write the data in this fashion.
The details, the physical details Of how you actually
access the hardware components, the microphone, disk drive,
whatever the hardware component is, that is understood by the device driver.
The device driver handles all those details for you.
So that's why if you ever take let's say a windows machine and
you plug in new device, sometimes in the lower right a little pop up will say
downloading device drivers, searching for device driver and so on.
It's looking for the appropriate device driver.
For that component, to know how to access that particular component.
And once it finds that then it can use that and it makes it very easy for
a user to access any hardware device
without having to write code explicitly for that purpose.
So that's what a device driver is and
there are a set of them, libraries of them.
And then underneath that is the hardware device,
whatever the hardware device is, that is controlled by the device driver code.