mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-01 21:42:05 +00:00
i2c fallback: add onekey scanner keymap
i2c scanner clone, configured for the fallback driver. ChibiOS only
This commit is contained in:
parent
9014b516f2
commit
aac5d52008
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Default configuration using 100kHz on I2CD1
|
||||||
|
#define SW_I2C_USE_I2C1 TRUE
|
||||||
|
//#define I2C_CLOCK_FREQUENCY 100000
|
||||||
|
//#define SW_I2C_USE_OSAL_DELAY TRUE
|
||||||
|
//#define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
|
||||||
|
//#define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
|
@ -0,0 +1,74 @@
|
|||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
#include "i2c_master.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
#define TIMEOUT 50
|
||||||
|
|
||||||
|
// TODO: remove patch
|
||||||
|
#ifdef PROTOCOL_CHIBIOS
|
||||||
|
# pragma message("ChibiOS is currently 'best effort' and might not report accurate results")
|
||||||
|
|
||||||
|
# if(SW_I2C_USE_OSAL_DELAY == FALSE)
|
||||||
|
void i2c_sw_delay(void) {
|
||||||
|
// custom delay goes here
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
i2c_status_t i2c_start_bodge(uint8_t address, uint16_t timeout) {
|
||||||
|
i2c_start(address);
|
||||||
|
|
||||||
|
// except on ChibiOS where the only way is do do "something"
|
||||||
|
uint8_t data = 0;
|
||||||
|
return i2c_readReg(address, 0, &data, sizeof(data), TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
# define i2c_start i2c_start_bodge
|
||||||
|
#else
|
||||||
|
# pragma message("ChibiOS is currently the only supported platform")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
LAYOUT_ortho_1x1(KC_A)
|
||||||
|
};
|
||||||
|
|
||||||
|
void do_scan(void) {
|
||||||
|
uint8_t nDevices = 0;
|
||||||
|
|
||||||
|
dprintf("Scanning...\n");
|
||||||
|
|
||||||
|
for (uint8_t address = 1; address < 127; address++) {
|
||||||
|
// The i2c_scanner uses the return value of
|
||||||
|
// i2c_start to see if a device did acknowledge to the address.
|
||||||
|
i2c_status_t error = i2c_start(address << 1, TIMEOUT);
|
||||||
|
if (error == I2C_STATUS_SUCCESS) {
|
||||||
|
i2c_stop();
|
||||||
|
dprintf(" I2C device found at address 0x%02X\n", address);
|
||||||
|
nDevices++;
|
||||||
|
} else {
|
||||||
|
// dprintf(" Unknown error (%u) at address 0x%02X\n", error, address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nDevices == 0)
|
||||||
|
dprintf("No I2C devices found\n");
|
||||||
|
else
|
||||||
|
dprintf("done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t scan_timer = 0;
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
if (timer_elapsed(scan_timer) > 5000) {
|
||||||
|
do_scan();
|
||||||
|
scan_timer = timer_read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyboard_post_init_user(void) {
|
||||||
|
debug_enable = true;
|
||||||
|
debug_matrix = true;
|
||||||
|
|
||||||
|
i2c_init();
|
||||||
|
scan_timer = timer_read();
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
# i2c_scanner_fallback
|
||||||
|
|
||||||
|
Aiming to provide a more qmk friendly version of <https://playground.arduino.cc/Main/I2cScanner/>
|
||||||
|
|
||||||
|
> This very simple ~~sketch~~ keymap scans the I2C-bus for devices. If a device is found, it is reported to the ~~Arduino serial monitor~~ console.
|
||||||
|
|
||||||
|
ChibiOS only software bitbang using the I2C Fallback driver.
|
||||||
|
|
||||||
|
## Flashing
|
||||||
|
|
||||||
|
Pick a target that is aligned to the MCU you want to test:
|
||||||
|
|
||||||
|
```console
|
||||||
|
# ChibiOS is currently the only supported platform
|
||||||
|
make handwired/onekey/proton_c:i2c_scanner:flash
|
||||||
|
```
|
||||||
|
|
||||||
|
others might work with additional configuration.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Output is viewable through a compatible tool <https://docs.qmk.fm/#/newbs_testing_debugging?id=debugging-tools>.
|
||||||
|
|
||||||
|
You can change the wires, and plug-in I2C devices while the i2c_scanner is running.
|
||||||
|
|
||||||
|
The output of the console will look like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
Listening:
|
||||||
|
Scanning...
|
||||||
|
I2C device found at address 0x20
|
||||||
|
done
|
||||||
|
```
|
@ -0,0 +1,4 @@
|
|||||||
|
CONSOLE_ENABLE = yes
|
||||||
|
|
||||||
|
I2C_DRIVER_REQUIRED = yes
|
||||||
|
USE_HAL_I2C_FALLBACK = yes
|
Loading…
Reference in New Issue
Block a user