【Feiling OK113i-C Allwinner T113-i Development Board】GPIO Control
[Copy link]
My first control: LED lights up
Now that the development environment has been built, you can try other simple methods. Run the onboard external resources. Controlling the on and off of an LED (usually called the light experiment) is one of the more common onboard resource test functions. Let's try to control the following user's LED light on the board. As
can be seen from the figure, the D1 LED light is connected to the PG11 pin, connected to the VCC power supply through the R1 resistor for current limiting, and controlled by the CQA34N00 N-channel MOS tube, while the control pin PG11 is connected to a 2K resistor for pull-up. When the factory-made board is powered on, this LED remains on.
Next, we will control this LED light through file operation
. First, we will calculate the pin number.
According to #define PIN_NO(port, line) (((port) - 'A') * 0x20 + (line)), we will calculate
where port is the gpio port, line is the corresponding pin of the gpio, and ((port)-'A') represents the subtraction of ASCII codes.
For example, the pin number corresponding to the pin PG11 of this LED is IN_NO('G',11)=(0x47-0x41)*0x20+11=(71-65)*32+11=107.
In other words, the actual pin number of this LED is 203.
Then log in to the system of the board, view the file GPIO through the following command, and also enter the GPIO folder to facilitate subsequent test operations.
You can see that there are already export and unexport
Next, use the command
Echo 203 > /sys/class/gpio/export
to export the pins, and you will see an additional gpio203 folder.
Enter the gpio203 folder and look at the files contained in it
Among them, direction is the input and output direction configuration of gpio, and value is the input and output value. You can configure the former as output, and the latter as 1 and 0 to control the on and off of the LED respectively.
Use
echo "out" > /sys/class/gpio/gpio203/direction
to set the direction of the pin to output, and use
cat /sys/class/gpio/gpio203/direction
to check whether the above setting output is successful and correct.
At this time, the onboard LED status is off, because the default value should be 0.
Next, you can control the LED light on and off by writing the content of the value file to 1 and 0 respectively.
The device tree also defines an onboard LED on the T113-i core board. This LED is used as the "heartbeat" function of the Linux core board by default.
Under sys/class
You can find a heartbeat folder and the following files in it:
By controlling the brightness file content, you can control the on and off state of the LED. That is, writing 1 and 0 can control its on and off state respectively.
You can also find the corresponding pin definition from the leds in the specific file of the specific folder of the board device tree. You can secretly know that the pin to be used is PG16, and GPIO_ACTIVE_HIGH specifies that its lighting level is a high level.
The above is the function of controlling the on and off status of the LEDs on the core board and baseboard through the gpio and leds in the device tree.
Confirm the permissions of the executable file and update it
Then use sftp to transfer it to the home/my_test path of the development board and confirm it with the ls command
Execute, enter the corresponding pin number and you can see it flip three times.
Its main implementation code is
Input pin number
Export pins to file
Set the direction to out
Flip three times
Finally, you need to unexport
|