● Principle of magnetic axis button detection
The core of a magnetic axis keyboard is Hall effect detection. Each button contains a shaft core, permanent magnet, spring, and Hall sensor. When the button is pressed, the magnet moves downward with the axis and gradually approaches the Hall sensor on the PCB. The proximity of the magnet causes a change in the magnetic flux density at the position of the Hall sensor, resulting in a linear change in the output voltage of the Hall sensor.
The MCU's built-in 12 bit ADC continuously collects the analog output voltage of each Hall sensor. By comparing the collected voltage values with the preset trigger threshold, the current state of the button can be accurately determined, including not triggered, triggered, and specific travel position.
● IO dual end direct drive Hall matrix scanning mechanism
This solution utilizes the abundant GPIO resources of MCU and adopts the architecture of "GPIO time-sharing power supply+dual terminal power control". Each Hall sensor does not require an independent power line, but is shared by row:
Column and row division: Divide the keys into M rows x N columns (e.g. 6 rows x 10 columns=60 keys, or 8 rows x 8 columns=64 keys).
Dual ended IO connection: All Hall sensors in each row have their VCC pins connected to one GPIO (row VCC control) and their GND pins connected to another GPIO (row GND control). The output terminal of each Hall sensor is independently connected to the ADC input channel (or further expanded through an analog switch, but this solution does not require it).
Scanning process:
When scanning a certain row, the MCU pulls up the GPIO corresponding to VCC in that row (outputs a high level), while pulling down the GPIO corresponding to GND in that row (outputs a low level). The Hall sensor in that row receives normal power supply (VCC-GND voltage difference ≈ VDD), starts working, and outputs an analog voltage proportional to the magnetic flux.
For the remaining unscanned rows, the MCU simultaneously configures their GPIO corresponding to VCC and GND as high impedance inputs, so that the voltage difference between the two ends of the Hall sensor in that row is 0V, and the sensor is completely turned off without consuming current or generating any output crosstalk.
The ADC of the MCU (in conjunction with DMA) sequentially reads the output values of each column of the current power supply row, completing the collection of stroke data for all buttons in that row.
Turn off the current row power supply (VCC/GND both pulled low), switch to the next row, repeat the above process, and complete the full keyboard scan.