Linux driver under CH452 LED chip debugging (GPIO analog I2C)

1. The device is connected
project to the processor MPU uses Cortex A5 processor core 4.9.0 series.
CH452 MPU and the pin definitions are shown in Table 2.1.
Table 2.1 MPU and the pin definitions CH452

No. CH452 pin definitions MPU pin definitions
1 SDA PB29
2 SCL PB30
3 RESET PB26

2. Drive commissioning
CH452 LED chip I2C compatible communication, but its timing different standard I2C timing, Linux can not apply a common framework I2C write drivers. Therefore, considering digital control through analog display timing mode. CH452 chip reading manuals -5.6 Section 2-wire serial interface, the microcontroller can know how to communicate with the interface 2 through line CH452. 2-wire interface LED is lit, must ensure correct timing simulation. The following were lit LED kernel space from user space and timing simulation.

2.1 Linux user space debugging
in user space, using GPIO port simulation I2C timing. GPIO application layer interface is / sys / class / gpio. File directory structure and file operations as follows:
1) the file directory structure of the application layer of the interface GPIO
/ SYS / class / GPIO
┣ Export application # pin interface
┣ unexport # cancellation request pin interface
┣ pioA15 # single pin device
┣ direction # input / output control
┣ value # level
┗ ...
2) using the method of the file operation
 setting input
is provided as an input pin B22 and read the value, for example:
CD / SYS / class / GPIO
echo 54 is> # export GPIOa Bank of port numbers 0, B * = 54 is 22 is 32 +
CD pioB22
echo in> # string direction "in"
CAT # character value '0' or '1'
if the GPIO read and write files in the application, cat then read function can be replaced, echo can be replaced write function.
 set the output
provided to the output pins C1 and set level:
CD / SYS / class / GPIO
echo 65> Export
CD pioC1
echo OUT> direction
an echo> value
echo 0> value
in user space using timing simulation I2C GPIO port, the LED lighting commissioning idea, as follows:
1) Initialization GPIO port configuration pins PB29 (SDA), PB30 (SCL ), the direction and level of ;
2) chip in accordance with the timing requirements of the manual control pin level, timing simulation;
3) according to a display request, sends a corresponding command to CH452.
The following figure shows the timing caught by the 2-wire interface to the oscilloscope, the data transmission is 0,111,111,000,000,001.
(Company documents and pictures encryption, can not pass ...)

Users of source space to achieve a lit LED cyclic shifts, it can display any characters (numbers, letters, special characters), the temperature control board real-time display and alarm codes.

2.2 Linux kernel space debugger
driver: misc registered as the CH452 device (like a character registration apparatus), called the kernel of the operating GPIO function, using analog GPIO I2C timing, MPU implemented using 2-wire interface to communicate with the CH452. When debugging, the driver source code is compiled into ko file, the application layer insmod manner by adding to the core, to facilitate debugging.
Test Procedure: After writing the application layer testing program, to be driven successfully added, run the test program, lit LED.

3. driver code
if necessary, a small partner can leave a message.

Guess you like

Origin blog.csdn.net/weixin_40407893/article/details/84747392