This article is based on a week CC2541 notes summary
Suitable for overview and quick index of knowledge--
Intermediate Tutorial-osal Operating system \osal operating system-a preliminary study of experimental osal
"Insert" sourceinsight-Engineering Establishment method
Intermediate Tutorial-osal Operating System (Osal System solution basic routines)
Intermediate Tutorial-osal Operating system (learn more about-oled && normal keys and 5-directional buttons-interrupts!!!) This system drive layer is not the same as the application layer ~
Intermediate Tutorial-osal Operating system (adc-photoresistors)
Osal Operating System-experiment 16 serial port baud rate extension
Osal operating system-experimental at command preliminary
Osal operating System-experimental 20 simulated IIC communication + hardware IIC (Mpu6050)
Osal operating system-experimental PWM output (change duty duty)
Osal Operating System-Lab 24 watchdog Wachdog
Osal operating System-experimental SNV internal flash data Read and write
Osal Operating System-experimental 29 system sleep level study
Osal Operating System-experiment 31 slave broadcast power modification
Second, osal operating system-Experiment 11 Normal button
The key interrupt code and the use method P01 is the cc2054x p0.1, through the 10k resistance ground, therefore p0.1 as the input time, the normal is the low level, when S1, presses, the p0.1 becomes the high level.
In Hal_key.c (BLE-CC254X-1.3.2-OSAL\COMPONENTS\HAL\TARGET\CC2540EB),
, is mainly to achieveinitialization of keystrokes and interrupt service functions, which also contains
, 5 to
The key is more than one ADC sample compared to the S1 button, and the 5-to-key button actually triggers a key interrupt, then
After the ADC is sampled, the keys in each direction are pressed and the ADC values are different due to the different voltage differential.
This makes it possible to distinguish between different keys.
More complex, the use of the relatively simple hal_key.c (BLE-CC254X-1.3.2-OSAL\COMPONENTS\HAL\TARGET\CC2540EB) S1 key IO definition is as follows: Rising edge trigger P01 pin
(with a lot of macro definitions!) Easy to transplant)
The default is the rising edge interrupt 279-281 is the P01 port interrupt configuration interrupt function for Halprocesskeyinterrupt () detects the interrupt flag bit in the interrupt handler function and, if the interrupt is triggered, uses the delay to shake (pure delay).
- The above is the key event detection
- Here is the key event transfer to the Application layer processing
HAL_DRIVERS.C (Ble-cc254x-1.3.2-osal\components\hal\common) This is in charge of
Handling Interrupt Events
216 line, is the key interrupt and delay to jitter after the query function call this
In the HAL_KEY.C query to the key press 435 lines, execute a callback function, the
is directly in our application layer.
at the same time notice a little
(the code below); Used to mark whether the current key state is changing when the interrupt is not used, and to set it according to the value of keys when using interruptsThe
callback technique used above is set in the following @!!
The 105 row defines the
, as to where this function is not assigned value, etc., I can point here, do not make in-depth analysis.
, now know that as long as there is a button pressed, will execute simplebletest_processevent this letter
Number, in fact, the press release when also have a button message sent up, convenient for us to determine the key state. and
Simplebletest_processevent This function is in our application layer. At this point, the key process analysis
- Initializing registration Key events
This will trigger the UInt16 simplebletest_processevent (uint8 task_id, uint16 events) function to enter into the static void Simpleblecentral_ Once a key break occurs. Handlekeys (uint8 shift, uint8 keys)
three, Osal operating system-experiment 125 to key
Above, P20 is the p2.0 of cc2054x, as
And P06 is P0.6, as
Sample input, 5-way key compared to the S1 button, an ADC sampling, 5 to the key, in fact, the first trigger a key interrupt, and then the ADC sampling, each direction of the key is pressed, because of different voltage, so the ADC value is not the same, so that the difference between the keys can be distinguished.
hal_key.cp2.0 defines the key as a falling edge along the trigger P0.6 for the ADC sample input set Gpio (in the initialization function) Halkeyconfig set the interrupt 299~301 line, which is the p2.0 IO interrupt enable, where the break function is in: HAL_ISR_ The function of Halprocesskeyinterrupt () is similar to the use of key1 in the functions, to determine whether the key is pressed and delayed to shake (pure delay to shake)
where did the program go after shaking and delaying???
In the hal_proccessevent of HAL_DRIVERS.C!
When a key press event is detected, Halkeypoll is called for processing, as follows: There is a callback function in Halkeypoll, which is in the application layer, thus implementing the
key-pressed messaging to the application layer's business logic
here is the definition of this callback function ~
The callback function is defined in the application layer by the osal_simplebletest.c:104 row, or, as to where the function is not assigned, and so on, I can point here, without further analysis.
, as long as there is a button pressed, will execute simplebletest_processevent this function, in fact, the press release when also have a button message sent up, convenient for us to make a judgment on the key state. and simplebletest_processevent This function is in our application layer. At this point, the key process analysis is complete.
Application layer similar to Key1, registration + event handling (see above)
not finished ~ Follow my cc2541 categories
2, CC2541 chip Intermediate tutorial-osal operating system (learn more about-oled && normal keys and 5-directional keys-interrupt!!!) This system driver layer is not the same as the application layer ~